blob: 80741c0d87660446e5ae21d0c1f140608dd45dcf [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Andres More3eaca0d2013-02-25 20:32:52 -050067const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Andres More3eaca0d2013-02-25 20:32:52 -050072const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Andres More3eaca0d2013-02-25 20:32:52 -050076const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000099static void *s_vGetFreeContext(struct vnt_private *pDevice);
100
101static void s_vGenerateTxParameter(struct vnt_private *pDevice,
102 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
103 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500104 struct ethhdr *psEthHeader);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
106static u32 s_uFillDataHead(struct vnt_private *pDevice,
107 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100108 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000110static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500111 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000112 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
115 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100116 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static void s_vSWencryption(struct vnt_private *pDevice,
119 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000121static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
122 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100124static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000125 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000127static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
128 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
129 int bDisCRC, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400130
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000131static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
132 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500133 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100135static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100136 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400137
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100138static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000139 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
140 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400141
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000142static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400143{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000144 PUSB_SEND_CONTEXT pContext = NULL;
145 PUSB_SEND_CONTEXT pReturnContext = NULL;
146 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400147
148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
149
150 for (ii = 0; ii < pDevice->cbTD; ii++) {
151 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500152 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500153 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100154 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400155 pReturnContext = pContext;
156 break;
157 }
158 }
159 if ( ii == pDevice->cbTD ) {
160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
161 }
Andres More8611a292010-05-01 14:25:00 -0300162 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400163}
164
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000165static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
166 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400167{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000168 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400169
Andres More4b50fb42010-06-22 21:57:42 -0300170 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400171 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300172 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
174 else
175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
176
177 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
178 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300179 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
180 pbyDestAddr,
181 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400182}
183
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000184static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
185 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100186 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400187{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000188 u32 *pdwIV = (u32 *)pbyIVHead;
189 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500190 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000191 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400192
Forest Bond92b96792009-06-13 07:38:31 -0400193 //Fill TXKEY
194 if (pTransmitKey == NULL)
195 return;
196
197 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
198 *pdwIV = pDevice->dwIVCounter;
199 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
200
201 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
202 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
Andres Moreb902fbf2013-02-25 20:32:51 -0500203 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700204 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400205 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500206 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700207 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400208 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500209 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700210 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400211 }
Jim Lieb3e362592009-08-12 14:54:11 -0700212 memcpy(pDevice->abyPRNG, pbyBuf, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400213 }
214 // Append IV after Mac Header
215 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
Malcolm Priestleyd5bbef72012-11-11 15:53:14 +0000216 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
Forest Bond92b96792009-06-13 07:38:31 -0400217 *pdwIV = cpu_to_le32(*pdwIV);
218 pDevice->dwIVCounter++;
219 if (pDevice->dwIVCounter > WEP_IV_MASK) {
220 pDevice->dwIVCounter = 0;
221 }
222 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
223 pTransmitKey->wTSC15_0++;
224 if (pTransmitKey->wTSC15_0 == 0) {
225 pTransmitKey->dwTSC47_16++;
226 }
227 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
228 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
Jim Lieb3e362592009-08-12 14:54:11 -0700229 memcpy(pbyBuf, pDevice->abyPRNG, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400230 // Make IV
Jim Lieb3e362592009-08-12 14:54:11 -0700231 memcpy(pdwIV, pDevice->abyPRNG, 3);
Forest Bond92b96792009-06-13 07:38:31 -0400232
Andres Moreb902fbf2013-02-25 20:32:51 -0500233 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Forest Bond92b96792009-06-13 07:38:31 -0400234 // Append IV&ExtIV after Mac Header
235 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +0000236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
237 *pdwExtIV);
Forest Bond92b96792009-06-13 07:38:31 -0400238
239 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
240 pTransmitKey->wTSC15_0++;
241 if (pTransmitKey->wTSC15_0 == 0) {
242 pTransmitKey->dwTSC47_16++;
243 }
Jim Lieb3e362592009-08-12 14:54:11 -0700244 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400245
246 // Make IV
247 *pdwIV = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -0500248 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Andres More3eaca0d2013-02-25 20:32:52 -0500249 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
Forest Bond92b96792009-06-13 07:38:31 -0400250 //Append IV&ExtIV after Mac Header
251 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
252
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100253 if (!mic_hdr)
254 return;
Forest Bond92b96792009-06-13 07:38:31 -0400255
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100256 /* MICHDR0 */
257 mic_hdr->id = 0x59;
258 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
259 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400260
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100261 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
262 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
263
264 /* MICHDR1 */
265 if (pDevice->bLongHeader)
266 mic_hdr->hlen = cpu_to_be16(28);
267 else
268 mic_hdr->hlen = cpu_to_be16(22);
269
270 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
271 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
272
273 /* MICHDR2 */
274 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
275 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
276 & 0xc78f);
277 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
278
279 if (pDevice->bLongHeader)
280 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400281 }
282}
283
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000284static void s_vSWencryption(struct vnt_private *pDevice,
285 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400286{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000287 u32 cbICVlen = 4;
288 u32 dwICV = 0xffffffff;
289 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400290
291 if (pTransmitKey == NULL)
292 return;
293
294 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
295 //=======================================================================
296 // Append ICV after payload
297 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500298 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400299 // finally, we must invert dwCRC to get the correct answer
300 *pdwICV = cpu_to_le32(~dwICV);
301 // RC4 encryption
302 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
303 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
304 //=======================================================================
305 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
306 //=======================================================================
307 //Append ICV after payload
308 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500309 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400310 // finally, we must invert dwCRC to get the correct answer
311 *pdwICV = cpu_to_le32(~dwICV);
312 // RC4 encryption
313 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 }
317}
318
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100319static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
320{
321 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
322 [rate % MAX_RATE]);
323}
324
Forest Bond92b96792009-06-13 07:38:31 -0400325/*byPktType : PK_TYPE_11A 0
326 PK_TYPE_11B 1
327 PK_TYPE_11GB 2
328 PK_TYPE_11GA 3
329*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000330static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
331 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400332{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000333 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400334
335 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
336 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500337 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400338 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500339 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400340 }
341
342 if (bNeedAck) {
343 return (uDataTime + pDevice->uSIFS + uAckTime);
344 }
345 else {
346 return uDataTime;
347 }
348}
349
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100350static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
351 u32 frame_length, u16 rate, int need_ack)
352{
353 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
354 frame_length, rate, need_ack));
355}
356
Forest Bond92b96792009-06-13 07:38:31 -0400357//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100358static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000359 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400360{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000361 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400362
363 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
364
Forest Bond92b96792009-06-13 07:38:31 -0400365 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
366 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
367 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
368 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
369 }
370 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
371 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
372 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
373 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
374 }
375 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
376 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
377 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
378 }
379 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
380 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
381 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
382 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
383 return uRrvTime;
384 }
385
386 //RTSRrvTime
387 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100388 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400389}
390
391//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100392static u16 s_uGetDataDuration(struct vnt_private *pDevice,
393 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400394{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100395 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400396
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100397 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100398 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100399 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
400 byPktType, 14, pDevice->byTopCCKBasicRate);
401 else
402 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
403 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100404 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100405 }
Forest Bond92b96792009-06-13 07:38:31 -0400406
Forest Bond92b96792009-06-13 07:38:31 -0400407 return 0;
408}
409
Forest Bond92b96792009-06-13 07:38:31 -0400410//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100411static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000412 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
413 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400414{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000415 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400416
Forest Bond92b96792009-06-13 07:38:31 -0400417 switch (byDurType) {
418
419 case RTSDUR_BB: //RTSDuration_bb
420 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
421 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
422 break;
423
424 case RTSDUR_BA: //RTSDuration_ba
425 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
426 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
427 break;
428
429 case RTSDUR_AA: //RTSDuration_aa
430 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
431 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
432 break;
433
434 case CTSDUR_BA: //CTSDuration_ba
435 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
436 break;
437
438 case RTSDUR_BA_F0: //RTSDuration_ba_f0
439 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
440 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
441 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
442 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
443 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
444 }
445 break;
446
447 case RTSDUR_AA_F0: //RTSDuration_aa_f0
448 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
449 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
450 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
451 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
452 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
453 }
454 break;
455
456 case RTSDUR_BA_F1: //RTSDuration_ba_f1
457 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
458 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
459 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
460 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
461 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
462 }
463 break;
464
465 case RTSDUR_AA_F1: //RTSDuration_aa_f1
466 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
467 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
468 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
469 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
470 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
471 }
472 break;
473
474 case CTSDUR_BA_F0: //CTSDuration_ba_f0
475 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
476 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
477 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
478 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
479 }
480 break;
481
482 case CTSDUR_BA_F1: //CTSDuration_ba_f1
483 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
484 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
485 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
486 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
487 }
488 break;
489
490 default:
491 break;
492 }
493
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100494 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400495}
496
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000497static u32 s_uFillDataHead(struct vnt_private *pDevice,
498 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100499 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400500{
501
502 if (pTxDataHead == NULL) {
503 return 0;
504 }
505
506 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Forest Bond92b96792009-06-13 07:38:31 -0400507 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100508 struct vnt_tx_datahead_g *pBuf =
509 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400510 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100511 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
512 byPktType, &pBuf->a);
513 BBvCalculateParameter(pDevice, cbFrameLength,
514 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400515 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100516 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100517 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100518 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100519 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400520
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100521 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
522 wCurrentRate);
523 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
524 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400525 return (pBuf->wDuration_a);
526 } else {
527 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100528 struct vnt_tx_datahead_g_fb *pBuf =
529 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400530 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100531 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
532 byPktType, &pBuf->a);
533 BBvCalculateParameter(pDevice, cbFrameLength,
534 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400535 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100536 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100537 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100538 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100539 PK_TYPE_11B, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100540 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100541 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100542 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100543 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100544 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
545 wCurrentRate);
546 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
547 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400548 return (pBuf->wDuration_a);
549 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400550 }
551 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100552 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100553 struct vnt_tx_datahead_a_fb *pBuf =
554 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400555 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100556 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
557 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400558 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100559 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100560 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100561 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100562 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100563 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100564 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100565 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
566 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400567 return (pBuf->wDuration);
568 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100569 struct vnt_tx_datahead_ab *pBuf =
570 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400571 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100572 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
573 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400574 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100575 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100576 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100577 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
578 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400579 return (pBuf->wDuration);
580 }
581 }
582 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100583 struct vnt_tx_datahead_ab *pBuf =
584 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400585 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100586 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
587 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400588 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100589 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100590 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100591 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
592 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400593 return (pBuf->wDuration);
594 }
595 return 0;
596}
597
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000598static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
599 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500600 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400601{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000602 u32 uRTSFrameLen = 20;
Forest Bond92b96792009-06-13 07:38:31 -0400603
Forest Bond92b96792009-06-13 07:38:31 -0400604 if (pvRTS == NULL)
605 return;
606
607 if (bDisCRC) {
608 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
609 // in this case we need to decrease its length by 4.
610 uRTSFrameLen -= 4;
611 }
612
Masanari Iida93184692012-08-13 21:21:50 +0900613 // Note: So far RTSHead doesn't appear in ATIM & Beacom DMA, so we don't need to take them into account.
Forest Bond92b96792009-06-13 07:38:31 -0400614 // Otherwise, we need to modified codes for them.
615 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
616 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100617 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400618 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100619 BBvCalculateParameter(pDevice, uRTSFrameLen,
620 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
621 BBvCalculateParameter(pDevice, uRTSFrameLen,
622 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400623 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100624 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
625 cbFrameLength, PK_TYPE_11B,
626 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
627 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
628 cbFrameLength, byPktType,
629 wCurrentRate, bNeedAck, byFBOption);
630 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
631 cbFrameLength, byPktType,
632 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100633 pBuf->data.duration = pBuf->wDuration_aa;
634 /*Get RTS Frame body */
635 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400636
Malcolm Priestley07738932013-08-05 22:08:05 +0100637 if (pDevice->eOPMode == OP_MODE_ADHOC ||
638 pDevice->eOPMode == OP_MODE_AP)
639 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
640 else
641 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300642
Malcolm Priestley07738932013-08-05 22:08:05 +0100643 if (pDevice->eOPMode == OP_MODE_AP)
644 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
645 else
646 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400647 }
648 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100649 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400650 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100651 BBvCalculateParameter(pDevice, uRTSFrameLen,
652 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
653 BBvCalculateParameter(pDevice, uRTSFrameLen,
654 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400655 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100656 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
657 cbFrameLength, PK_TYPE_11B,
658 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
659 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
660 cbFrameLength, byPktType,
661 wCurrentRate, bNeedAck, byFBOption);
662 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
663 cbFrameLength, byPktType,
664 wCurrentRate, bNeedAck, byFBOption);
665 pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
666 RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
667 bNeedAck, byFBOption);
668 pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
669 RTSDUR_AA_F0, cbFrameLength, byPktType,
670 wCurrentRate, bNeedAck, byFBOption);
671 pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
672 RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
673 bNeedAck, byFBOption);
674 pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
675 RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
676 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100677 pBuf->data.duration = pBuf->wDuration_aa;
678 /*Get RTS Frame body*/
679 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400680
Malcolm Priestley07738932013-08-05 22:08:05 +0100681 if (pDevice->eOPMode == OP_MODE_ADHOC ||
682 pDevice->eOPMode == OP_MODE_AP)
683 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
684 else
685 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400686
Malcolm Priestley07738932013-08-05 22:08:05 +0100687 if (pDevice->eOPMode == OP_MODE_AP)
688 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
689 else
690 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400691 } // if (byFBOption == AUTO_FB_NONE)
692 }
693 else if (byPktType == PK_TYPE_11A) {
694 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100695 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400696 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100697 BBvCalculateParameter(pDevice, uRTSFrameLen,
698 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400699 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100700 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
701 cbFrameLength, byPktType, wCurrentRate,
702 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100703 pBuf->data.duration = pBuf->wDuration;
704 /* Get RTS Frame body */
705 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400706
Malcolm Priestley07738932013-08-05 22:08:05 +0100707 if (pDevice->eOPMode == OP_MODE_ADHOC ||
708 pDevice->eOPMode == OP_MODE_AP)
709 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
710 else
711 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400712
Malcolm Priestley07738932013-08-05 22:08:05 +0100713 if (pDevice->eOPMode == OP_MODE_AP)
714 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
715 else
716 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400717 }
718 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100719 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400720 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100721 BBvCalculateParameter(pDevice, uRTSFrameLen,
722 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400723 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100724 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
725 cbFrameLength, byPktType, wCurrentRate,
726 bNeedAck, byFBOption);
727 pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
728 RTSDUR_AA_F0, cbFrameLength, byPktType,
729 wCurrentRate, bNeedAck, byFBOption);
730 pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
731 RTSDUR_AA_F1, cbFrameLength, byPktType,
732 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100733 pBuf->data.duration = pBuf->wDuration;
734 /* Get RTS Frame body */
735 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400736
Malcolm Priestley07738932013-08-05 22:08:05 +0100737 if (pDevice->eOPMode == OP_MODE_ADHOC ||
738 pDevice->eOPMode == OP_MODE_AP)
739 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
740 else
741 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
742
743 if (pDevice->eOPMode == OP_MODE_AP)
744 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
745 else
746 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400747 }
748 }
749 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100750 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400751 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100752 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate,
753 PK_TYPE_11B, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400754 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100755 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
756 cbFrameLength, byPktType, wCurrentRate,
757 bNeedAck, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400758
Malcolm Priestley07738932013-08-05 22:08:05 +0100759 pBuf->data.duration = pBuf->wDuration;
760 /* Get RTS Frame body */
761 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400762
Malcolm Priestley07738932013-08-05 22:08:05 +0100763 if (pDevice->eOPMode == OP_MODE_ADHOC ||
764 pDevice->eOPMode == OP_MODE_AP)
765 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
766 else
767 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
768
769 if (pDevice->eOPMode == OP_MODE_AP)
770 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
771 else
772 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400773 }
774}
775
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000776static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
777 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
778 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400779{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000780 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400781
782 if (pvCTS == NULL) {
783 return;
784 }
785
786 if (bDisCRC) {
787 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
788 // in this case we need to decrease its length by 4.
789 uCTSFrameLen -= 4;
790 }
791
792 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100793 if (byFBOption != AUTO_FB_NONE) {
794 /* Auto Fall back */
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100795 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100796 /* Get SignalField,ServiceField,Length */
797 BBvCalculateParameter(pDevice, uCTSFrameLen,
798 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100799 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
800 cbFrameLength, byPktType,
801 wCurrentRate, bNeedAck, byFBOption);
802 /* Get CTSDuration_ba_f0 */
803 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
804 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
805 bNeedAck, byFBOption);
806 /* Get CTSDuration_ba_f1 */
807 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
808 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
809 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100810 /* Get CTS Frame body */
811 pBuf->data.duration = pBuf->wDuration_ba;
812 pBuf->data.frame_control = TYPE_CTL_CTS;
813 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100814 } else {
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100815 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100816 /* Get SignalField,ServiceField,Length */
817 BBvCalculateParameter(pDevice, uCTSFrameLen,
818 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100819 /* Get CTSDuration_ba */
820 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
821 CTSDUR_BA, cbFrameLength, byPktType,
822 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100823 /*Get CTS Frame body*/
824 pBuf->data.duration = pBuf->wDuration_ba;
825 pBuf->data.frame_control = TYPE_CTL_CTS;
826 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400827 }
828 }
829}
830
Forest Bond92b96792009-06-13 07:38:31 -0400831/*+
832 *
833 * Description:
834 * Generate FIFO control for MAC & Baseband controller
835 *
836 * Parameters:
837 * In:
838 * pDevice - Pointer to adpater
839 * pTxDataHead - Transmit Data Buffer
840 * pTxBufHead - pTxBufHead
841 * pvRrvTime - pvRrvTime
842 * pvRTS - RTS Buffer
843 * pCTS - CTS Buffer
844 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
845 * bNeedACK - If need ACK
846 * uDMAIdx - DMA Index
847 * Out:
848 * none
849 *
850 * Return Value: none
851 *
852-*/
Andres Morecc856e62010-05-17 21:34:01 -0300853
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000854static void s_vGenerateTxParameter(struct vnt_private *pDevice,
855 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
856 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500857 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400858{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000859 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
860 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -0500861 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000862 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400863
864 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
865 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
866 pFifoHead->wReserved = wCurrentRate;
867 wFifoCtl = pFifoHead->wFIFOCtl;
868
869 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -0500870 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -0400871 }
872
873 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
874 byFBOption = AUTO_FB_0;
875 }
876 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
877 byFBOption = AUTO_FB_1;
878 }
879
880 if (pDevice->bLongHeader)
881 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
882
883 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
884
885 if (pvRTS != NULL) { //RTS_need
886 //Fill RsvTime
887 if (pvRrvTime) {
Malcolm Priestley6398a592013-08-16 21:26:55 +0100888 struct vnt_rrv_time_rts *pBuf =
889 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100890 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
891 byPktType, cbFrameSize, wCurrentRate);
892 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
893 byPktType, cbFrameSize, wCurrentRate);
894 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
895 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100896 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
897 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
898 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
899 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
900 bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400901 }
902 //Fill RTS
903 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
904 }
905 else {//RTS_needless, PCF mode
906
907 //Fill RsvTime
908 if (pvRrvTime) {
Malcolm Priestley4f990052013-08-16 23:38:57 +0100909 struct vnt_rrv_time_cts *pBuf =
910 (struct vnt_rrv_time_cts *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100911 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
912 cbFrameSize, wCurrentRate, bNeedACK);
913 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
914 PK_TYPE_11B, cbFrameSize,
915 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100916 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
917 byPktType, cbFrameSize, wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400918 }
919 //Fill CTS
920 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
921 }
922 }
923 else if (byPktType == PK_TYPE_11A) {
924
925 if (pvRTS != NULL) {//RTS_need, non PCF mode
926 //Fill RsvTime
927 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100928 struct vnt_rrv_time_ab *pBuf =
929 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100930 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
931 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100932 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
933 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400934 }
935 //Fill RTS
936 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
937 }
938 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
939 //Fill RsvTime
940 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100941 struct vnt_rrv_time_ab *pBuf =
942 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100943 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
944 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400945 }
946 }
947 }
948 else if (byPktType == PK_TYPE_11B) {
949
950 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
951 //Fill RsvTime
952 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100953 struct vnt_rrv_time_ab *pBuf =
954 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100955 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
956 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100957 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
958 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400959 }
960 //Fill RTS
961 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
962 }
963 else { //RTS_needless, non PCF mode
964 //Fill RsvTime
965 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100966 struct vnt_rrv_time_ab *pBuf =
967 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100968 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
969 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400970 }
971 }
972 }
973 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
974}
975/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500976 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500977 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300978 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400979*/
980
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000981static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100982 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
983 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
984 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
985 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400986{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000987 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
988 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000989 u32 cb802_1_H_len;
990 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
991 u32 cbFCSlen = 4, cbMICHDR = 0;
992 int bNeedACK, bRTS;
993 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
994 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
995 u8 abySNAP_Bridgetunnel[ETH_ALEN]
996 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
997 u32 uDuration;
998 u32 cbHeaderLength = 0, uPadding = 0;
999 void *pvRrvTime;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001000 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001001 void *pvRTS;
1002 void *pvCTS;
1003 void *pvTxDataHd;
1004 u8 byFBOption = AUTO_FB_NONE, byFragType;
1005 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +01001006 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001007 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001008 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -04001009
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001010 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001011
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001012 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001013 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1014 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001015 }
Forest Bond92b96792009-06-13 07:38:31 -04001016
Forest Bond92b96792009-06-13 07:38:31 -04001017 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001018 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001019 if (pDevice->dwDiagRefCount == 0) {
1020 cb802_1_H_len = 8;
1021 } else {
1022 cb802_1_H_len = 2;
1023 }
1024 } else {
1025 cb802_1_H_len = 0;
1026 }
1027
Charles Clément21ec51f2010-05-18 10:08:14 -07001028 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001029
1030 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001031 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001032
1033 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001034 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001035 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1036 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001037 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1038 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001039 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001040 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001041 pTxBufHead->wFIFOCtl =
1042 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1043 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001044 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001045 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1046 }
Forest Bond92b96792009-06-13 07:38:31 -04001047 }
1048 else {
1049 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001050 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001051 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1052 }
1053 } //if (pDevice->dwDiagRefCount != 0) {
1054
1055 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1056
1057 //Set FIFOCTL_LHEAD
1058 if (pDevice->bLongHeader)
1059 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1060
Forest Bond92b96792009-06-13 07:38:31 -04001061 //Set FRAGCTL_MACHDCNT
1062 if (pDevice->bLongHeader) {
1063 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1064 } else {
1065 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1066 }
Andres More3eaca0d2013-02-25 20:32:52 -05001067 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001068
1069 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001070 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001071 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1072 }
1073
1074 //Set Auto Fallback Ctl
1075 if (wCurrentRate >= RATE_18M) {
1076 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1077 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1078 byFBOption = AUTO_FB_0;
1079 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1080 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1081 byFBOption = AUTO_FB_1;
1082 }
1083 }
1084
Andres More4e9b5e22013-02-12 20:36:30 -05001085 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001086 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1087 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1088 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1089 }
1090 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1091 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1092 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1093 }
1094 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1095 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1096 }
1097 }
1098 }
1099
Forest Bond92b96792009-06-13 07:38:31 -04001100 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1101 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1102 cbIVlen = 4;
1103 cbICVlen = 4;
1104 }
1105 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1106 cbIVlen = 8;//IV+ExtIV
1107 cbMIClen = 8;
1108 cbICVlen = 4;
1109 }
1110 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1111 cbIVlen = 8;//RSN Header
1112 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001113 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001114 }
Andres Moree269fc22013-02-12 20:36:29 -05001115 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001116 //MAC Header should be padding 0 to DW alignment.
1117 uPadding = 4 - (cbMACHdLen%4);
1118 uPadding %= 4;
1119 }
1120 }
1121
1122 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1123
Andres Moree269fc22013-02-12 20:36:29 -05001124 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1125 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001126 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001127 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001128 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1129 }
1130
Andres Moreb902fbf2013-02-25 20:32:51 -05001131 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001132 wTxBufSize = sizeof(STxBufHead);
1133 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1134 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001135 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001136 pvRrvTime = (struct vnt_rrv_time_rts *)
1137 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001138 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001139 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001140 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001141 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001142 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001143 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1144 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1145 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001146 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001147 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001148 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001149 }
1150 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001151 pvRrvTime = (struct vnt_rrv_time_cts *)
1152 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001153 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001154 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001155 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001156 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001157 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001158 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1159 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1160 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001161 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1162 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001163 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001164 }
1165 } else {
1166 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001167 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001168 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1169 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001170 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001171 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001172 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001173 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001174 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001175 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1176 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1177 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001178 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1179 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001180 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001181 }
Andres Moree269fc22013-02-12 20:36:29 -05001182 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001183 pvRrvTime = (struct vnt_rrv_time_cts *)
1184 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001185 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001186 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001187 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001188 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001189 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001190 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001191 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1192 cbMICHDR + sizeof(struct vnt_cts_fb));
1193 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001194 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001195 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001196 }
1197 } // Auto Fall Back
1198 }
1199 else {//802.11a/b packet
1200 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001201 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001202 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1203 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001204 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001205 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001206 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001207 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001208 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001209 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1210 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001211 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001212 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1213 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001214 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001215 }
Andres Moree269fc22013-02-12 20:36:29 -05001216 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001217 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1218 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001219 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001220 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001221 pvRTS = NULL;
1222 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001223 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1224 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001225 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001226 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001227 }
1228 } else {
1229 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001230 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001231 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1232 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001233 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001234 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001235 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001236 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001237 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001238 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1239 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001240 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001241 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1242 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001243 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001244 }
Andres Moree269fc22013-02-12 20:36:29 -05001245 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001246 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1247 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001248 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001249 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001250 pvRTS = NULL;
1251 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001252 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1253 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001254 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001255 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001256 }
1257 } // Auto Fall Back
1258 }
1259
Andres Moreb902fbf2013-02-25 20:32:51 -05001260 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1261 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1262 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001263
Forest Bond92b96792009-06-13 07:38:31 -04001264 //=========================
1265 // No Fragmentation
1266 //=========================
1267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1268 byFragType = FRAGCTL_NONFRAG;
1269 //uDMAIdx = TYPE_AC0DMA;
1270 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1271
Forest Bond92b96792009-06-13 07:38:31 -04001272 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001273 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1274 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001275 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1276 //Fill DataHead
1277 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001278 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001279 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001280 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001281 byFragType, uDMAIdx, 0);
1282
Andres More4e9b5e22013-02-12 20:36:30 -05001283 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001284 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001285 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001286 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001287
1288 if (pDevice->bEnableHostWEP) {
1289 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1290 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1291 }
1292 }
1293
1294 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001295 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001296 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001297 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1298 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001299 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001300 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001301 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001302 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001303 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001304 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001305 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001306 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001307 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001308
1309 }
1310
1311 }
1312
Forest Bond92b96792009-06-13 07:38:31 -04001313 if (pPacket != NULL) {
1314 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001315 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001316 (pPacket + ETH_HLEN),
1317 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001318 );
1319
1320 } else {
1321 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001322 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001323 }
1324
Andres More4e9b5e22013-02-12 20:36:30 -05001325 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001326
1327 ///////////////////////////////////////////////////////////////////
1328
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001329 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1330 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1331 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1332 }
Forest Bond92b96792009-06-13 07:38:31 -04001333 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001334 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1335 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001336 }
1337 else {
Andres More52a7e642013-02-25 20:32:53 -05001338 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1339 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001340 }
1341 // DO Software Michael
1342 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001343 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001344 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001345 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001346 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1347 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001348
1349 ///////////////////////////////////////////////////////////////////
1350
1351 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1352 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001353 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001354 //}
1355 //DBG_PRN_GRP12(("\n\n\n"));
1356
1357 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1358
Andres More52a7e642013-02-25 20:32:53 -05001359 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1360 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001361
1362 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1363 MIC_vUnInit();
1364
Andres More4e9b5e22013-02-12 20:36:30 -05001365 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001366 *pdwMIC_L = 0;
1367 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001368 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001369 }
1370 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1371 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1372 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1373 }
1374
Andres More4e9b5e22013-02-12 20:36:30 -05001375 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001376
Andres More3eaca0d2013-02-25 20:32:52 -05001377 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001378
Andres More4e9b5e22013-02-12 20:36:30 -05001379 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1380 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1381 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001382 cbFrameSize -= cbICVlen;
1383 }
1384
Forest Bond92b96792009-06-13 07:38:31 -04001385 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001386
1387 *pcbHeaderLen = cbHeaderLength;
1388 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1389
Forest Bond92b96792009-06-13 07:38:31 -04001390 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001391 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001392
Andres More4e9b5e22013-02-12 20:36:30 -05001393 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001394
1395}
1396
Forest Bond92b96792009-06-13 07:38:31 -04001397/*+
1398 *
1399 * Description:
1400 * Translate 802.3 to 802.11 header
1401 *
1402 * Parameters:
1403 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001404 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001405 * dwTxBufferAddr - Transmit Buffer
1406 * pPacket - Packet from upper layer
1407 * cbPacketSize - Transmit Data Length
1408 * Out:
1409 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1410 * pcbAppendPayload - size of append payload for 802.1H translation
1411 *
1412 * Return Value: none
1413 *
1414-*/
1415
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001416static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001417 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001418 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001419{
Andres More1cac4a42013-03-18 20:33:50 -05001420 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001421
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001422 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001423
1424 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001425 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001426 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001427 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001428 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1429 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001430 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001431 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001432 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001433 } else {
1434 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001435 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001436 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001437 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001438 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001439 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001440 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001441 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001442 &(pDevice->abyBSSID[0]),
1443 ETH_ALEN);
1444 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001445 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001446 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001447 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001448 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001449 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001450 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001451 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001452 &(pDevice->abyBSSID[0]),
1453 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001454 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001455 }
1456 }
1457
1458 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001459 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001460
Andres More1cac4a42013-03-18 20:33:50 -05001461 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001462
1463 if (pDevice->bLongHeader) {
1464 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001465 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001466 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001467 }
Andres More1cac4a42013-03-18 20:33:50 -05001468 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001469
1470 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001471 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001472
1473 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1474 pDevice->wSeqCounter++;
1475 if (pDevice->wSeqCounter > 0x0fff)
1476 pDevice->wSeqCounter = 0;
1477 }
1478
1479 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001480 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001481 }
1482}
1483
Forest Bond92b96792009-06-13 07:38:31 -04001484/*+
1485 *
1486 * Description:
1487 * Request instructs a MAC to transmit a 802.11 management packet through
1488 * the adapter onto the medium.
1489 *
1490 * Parameters:
1491 * In:
1492 * hDeviceContext - Pointer to the adapter
1493 * pPacket - A pointer to a descriptor for the packet to transmit
1494 * Out:
1495 * none
1496 *
Andres Moree269fc22013-02-12 20:36:29 -05001497 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001498 *
1499-*/
1500
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001501CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1502 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001503{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001504 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001505 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001506 PSTxBufHead pTxBufHead;
1507 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001508 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001509 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001510 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001511 u8 byPktType, *pbyTxBufferAddr;
1512 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1513 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001514 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001515 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1516 u32 uPadding = 0;
1517 u16 wTxBufSize;
1518 u32 cbMacHdLen;
1519 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001520
Forest Bond92b96792009-06-13 07:38:31 -04001521 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1522
1523 if (NULL == pContext) {
1524 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1525 return CMD_STATUS_RESOURCES;
1526 }
1527
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001528 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001529 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001530 cbFrameBodySize = pPacket->cbPayloadLen;
1531 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1532 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001533
1534 if (pDevice->byBBType == BB_TYPE_11A) {
1535 wCurrentRate = RATE_6M;
1536 byPktType = PK_TYPE_11A;
1537 } else {
1538 wCurrentRate = RATE_1M;
1539 byPktType = PK_TYPE_11B;
1540 }
1541
1542 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1543 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1544 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1545 // to set power here.
1546 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1547 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1548 } else {
1549 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1550 }
1551 pDevice->wCurrentRate = wCurrentRate;
1552
Forest Bond92b96792009-06-13 07:38:31 -04001553 //Set packet type
1554 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1555 pTxBufHead->wFIFOCtl = 0;
1556 }
1557 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1558 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1559 }
1560 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1561 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1562 }
1563 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1564 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1565 }
1566
1567 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1568 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1569
Andres More22040bb2010-08-02 20:21:44 -03001570 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001571 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001572 }
1573 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001574 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001575 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1576 };
1577
1578 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1579 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1580
1581 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1582 //Set Preamble type always long
1583 //pDevice->byPreambleType = PREAMBLE_LONG;
1584 // probe-response don't retry
1585 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001586 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001587 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1588 //}
1589 }
1590
1591 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1592
1593 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001594 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001595 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1596 } else {
1597 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1598 }
1599
1600 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001601 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001602
1603 // Notes:
1604 // Although spec says MMPDU can be fragmented; In most case,
1605 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001606 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001607
1608 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1609 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1610 cbIVlen = 4;
1611 cbICVlen = 4;
1612 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1613 }
1614 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1615 cbIVlen = 8;//IV+ExtIV
1616 cbMIClen = 8;
1617 cbICVlen = 4;
1618 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1619 //We need to get seed here for filling TxKey entry.
1620 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1621 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1622 }
1623 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1624 cbIVlen = 8;//RSN Header
1625 cbICVlen = 8;//MIC
1626 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001627 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001628 }
1629 //MAC Header should be padding 0 to DW alignment.
1630 uPadding = 4 - (cbMacHdLen%4);
1631 uPadding %= 4;
1632 }
1633
1634 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1635
1636 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001637 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001638 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1639 }
1640 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1641
1642 //Set RrvTime/RTS/CTS Buffer
1643 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1644
Malcolm Priestley4f990052013-08-16 23:38:57 +01001645 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001646 pMICHDR = NULL;
1647 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001648 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001649 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001650 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001651 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1652 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001653 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001654 }
1655 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001656 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001657 pMICHDR = NULL;
1658 pvRTS = NULL;
1659 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001660 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1661 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001662 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001663 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001664 }
1665
Andres Moreceb8c5d2013-03-18 20:33:49 -05001666 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001667 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1668 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001669 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001670 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1671 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001672 //=========================
1673 // No Fragmentation
1674 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001675 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001676
Forest Bond92b96792009-06-13 07:38:31 -04001677 //Fill FIFO,RrvTime,RTS,and CTS
1678 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1679 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1680
1681 //Fill DataHead
1682 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001683 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001684
Andres More1cac4a42013-03-18 20:33:50 -05001685 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001686
1687 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1688
1689 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001690 u8 * pbyIVHead;
1691 u8 * pbyPayloadHead;
1692 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001693 PSKeyItem pTransmitKey = NULL;
1694
Andres Moreb902fbf2013-02-25 20:32:51 -05001695 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1696 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001697 do {
1698 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001699 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001700 pbyBSSID = pDevice->abyBSSID;
1701 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001702 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001703 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001704 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001705 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1706 break;
1707 }
1708 } else {
1709 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1710 break;
1711 }
1712 }
1713 // get group key
1714 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001715 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001716 pTransmitKey = NULL;
1717 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1718 } else {
1719 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1720 }
Andres Moree269fc22013-02-12 20:36:29 -05001721 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001722 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001723 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001724 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001725
Jim Lieb3e362592009-08-12 14:54:11 -07001726 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001727 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001728 cbFrameBodySize);
1729 }
1730 else {
1731 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001732 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001733 }
1734
Andres More1cac4a42013-03-18 20:33:50 -05001735 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001736 pDevice->wSeqCounter++ ;
1737 if (pDevice->wSeqCounter > 0x0fff)
1738 pDevice->wSeqCounter = 0;
1739
1740 if (bIsPSPOLL) {
1741 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001742 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001743 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1744 // in the same place of other packet's Duration-field).
1745 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001746 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1747 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1748 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1749 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1750 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1751 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001752 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1753 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1754 }
Forest Bond92b96792009-06-13 07:38:31 -04001755 }
1756
Andres More3eaca0d2013-02-25 20:32:52 -05001757 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001758 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001759 pTX_Buffer->byType = 0x00;
1760
1761 pContext->pPacket = NULL;
1762 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001763 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001764
Andres More1cac4a42013-03-18 20:33:50 -05001765 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1766 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001767 }
1768 else {
Andres More1cac4a42013-03-18 20:33:50 -05001769 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001770 }
1771
1772 PIPEnsSendBulkOut(pDevice,pContext);
1773 return CMD_STATUS_PENDING;
1774}
1775
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001776CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1777 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001778{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001779 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001780 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1781 u32 cbHeaderSize = 0;
1782 u16 wTxBufSize = sizeof(STxShortBufHead);
1783 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001784 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001785 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001786 u16 wCurrentRate;
1787 u32 cbFrameBodySize;
1788 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001789 u8 *pbyTxBufferAddr;
1790 PUSB_SEND_CONTEXT pContext;
1791 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001792
Forest Bond92b96792009-06-13 07:38:31 -04001793 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1794 if (NULL == pContext) {
1795 status = CMD_STATUS_RESOURCES;
1796 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1797 return status ;
1798 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001799
1800 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001801 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001802
1803 cbFrameBodySize = pPacket->cbPayloadLen;
1804
1805 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1806 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001807
1808 if (pDevice->byBBType == BB_TYPE_11A) {
1809 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001810 pTxDataHead = (struct vnt_tx_datahead_ab *)
1811 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001812 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001813 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1814 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001815 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001816 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001817 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001818 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001819 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001820 } else {
1821 wCurrentRate = RATE_1M;
1822 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001823 pTxDataHead = (struct vnt_tx_datahead_ab *)
1824 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001825 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001826 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1827 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001828 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001829 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001830 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001831 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001832 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001833 }
1834
1835 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001836 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001837 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001838
Andres More1cac4a42013-03-18 20:33:50 -05001839 pMACHeader->duration_id = 0;
1840 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001841 pDevice->wSeqCounter++ ;
1842 if (pDevice->wSeqCounter > 0x0fff)
1843 pDevice->wSeqCounter = 0;
1844
1845 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1846
Andres More3eaca0d2013-02-25 20:32:52 -05001847 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001848 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001849 pTX_Buffer->byType = 0x01;
1850
1851 pContext->pPacket = NULL;
1852 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001853 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001854
1855 PIPEnsSendBulkOut(pDevice,pContext);
1856 return CMD_STATUS_PENDING;
1857
1858}
1859
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001860void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1861{
1862 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001863 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001864 u8 byPktType;
1865 u8 *pbyTxBufferAddr;
1866 void *pvRTS, *pvCTS, *pvTxDataHd;
1867 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001868 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001869 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001870 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001871 PSTxBufHead pTxBufHead;
1872 u32 cbFrameSize;
1873 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1874 u32 uPadding = 0;
1875 u32 cbMICHDR = 0, uLength = 0;
1876 u32 dwMICKey0, dwMICKey1;
1877 u32 dwMIC_Priority;
1878 u32 *pdwMIC_L, *pdwMIC_R;
1879 u16 wTxBufSize;
1880 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001881 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001882 void *pvRrvTime, *pMICHDR;
1883 u32 wCurrentRate = RATE_1M;
1884 PUWLAN_80211HDR p80211Header;
1885 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001886 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001887 SKeyItem STempKey;
1888 PSKeyItem pTransmitKey = NULL;
1889 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1890 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001891 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001892
Forest Bond92b96792009-06-13 07:38:31 -04001893 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1894
1895 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1896 cbFrameBodySize = 0;
1897 }
1898 else {
1899 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1900 }
1901 p80211Header = (PUWLAN_80211HDR)skb->data;
1902
1903 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1904
1905 if (NULL == pContext) {
1906 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1907 dev_kfree_skb_irq(skb);
1908 return ;
1909 }
1910
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001911 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001912 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001913 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1914 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001915
1916 if (pDevice->byBBType == BB_TYPE_11A) {
1917 wCurrentRate = RATE_6M;
1918 byPktType = PK_TYPE_11A;
1919 } else {
1920 wCurrentRate = RATE_1M;
1921 byPktType = PK_TYPE_11B;
1922 }
1923
1924 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1925 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1926 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1927 // to set power here.
1928 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1929 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1930 } else {
1931 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1932 }
1933
1934 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1935
1936 //Set packet type
1937 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1938 pTxBufHead->wFIFOCtl = 0;
1939 }
1940 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1941 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1942 }
1943 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1944 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1945 }
1946 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1947 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1948 }
1949
1950 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1951 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1952
Andres More22040bb2010-08-02 20:21:44 -03001953 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001954 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001955 if (pDevice->bEnableHostWEP) {
1956 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001957 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001958 }
Forest Bond92b96792009-06-13 07:38:31 -04001959 }
1960 else {
1961 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001962 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001963 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001964 }
Andres More4e9b5e22013-02-12 20:36:30 -05001965 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001966 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1967 };
1968
1969 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1970 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1971
1972 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1973 //Set Preamble type always long
1974 //pDevice->byPreambleType = PREAMBLE_LONG;
1975
1976 // probe-response don't retry
1977 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001978 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001979 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1980 //}
1981 }
1982
1983 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1984
1985 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001986 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001987 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1988 } else {
1989 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1990 }
1991
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001992 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001993 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1994
1995 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1996 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1997 }
1998
1999 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2000 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2001 }
2002
2003 if (cbExtSuppRate >0) {
2004 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2005 }
2006 }
2007
Forest Bond92b96792009-06-13 07:38:31 -04002008 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002009 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002010
2011 // Notes:
2012 // Although spec says MMPDU can be fragmented; In most case,
2013 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002014 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002015
Forest Bond92b96792009-06-13 07:38:31 -04002016 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2017 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2018 cbIVlen = 4;
2019 cbICVlen = 4;
2020 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2021 }
2022 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2023 cbIVlen = 8;//IV+ExtIV
2024 cbMIClen = 8;
2025 cbICVlen = 4;
2026 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2027 //We need to get seed here for filling TxKey entry.
2028 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2029 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2030 }
2031 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2032 cbIVlen = 8;//RSN Header
2033 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002034 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04002035 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002036 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002037 }
2038 //MAC Header should be padding 0 to DW alignment.
2039 uPadding = 4 - (cbMacHdLen%4);
2040 uPadding %= 4;
2041 }
2042
2043 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2044
2045 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002046 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002047 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2048 }
2049 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2050
Forest Bond92b96792009-06-13 07:38:31 -04002051 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002052 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002053 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002054 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002055 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002056 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002057 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002058 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2059 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002060 sizeof(struct vnt_cts));
2061 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002062 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002063
2064 }
2065 else {//802.11a/b packet
2066
Malcolm Priestley976467d2013-08-16 23:44:04 +01002067 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002068 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002069 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002070 pvRTS = NULL;
2071 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002072 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2073 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002074 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002075 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002076 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002077 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002078 &(p80211Header->sA3.abyAddr1[0]),
2079 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002080 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002081 &(p80211Header->sA3.abyAddr2[0]),
2082 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002083 //=========================
2084 // No Fragmentation
2085 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002086 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002087
Forest Bond92b96792009-06-13 07:38:31 -04002088 //Fill FIFO,RrvTime,RTS,and CTS
2089 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2090 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2091
2092 //Fill DataHead
2093 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002094 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002095
Andres More1cac4a42013-03-18 20:33:50 -05002096 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002097
2098 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2099
Andres Moreb902fbf2013-02-25 20:32:51 -05002100 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2101 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2102 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002103
2104 // Copy the Packet into a tx Buffer
2105 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2106
2107 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002108 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002109 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2110
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002111 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002112 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2113 if (cbExtSuppRate != 0) {
2114 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2115 memcpy((pbyPayloadHead + cbFrameBodySize),
2116 pMgmt->abyCurrSuppRates,
2117 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2118 );
2119 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2120 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2121 pMgmt->abyCurrExtSuppRates,
2122 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2123 );
2124 }
2125 }
2126
2127 // Set wep
2128 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2129
2130 if (pDevice->bEnableHostWEP) {
2131 pTransmitKey = &STempKey;
2132 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2133 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2134 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2135 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2136 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2137 memcpy(pTransmitKey->abyKey,
2138 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2139 pTransmitKey->uKeyLength
2140 );
2141 }
2142
2143 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2144
Andres More52a7e642013-02-25 20:32:53 -05002145 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2146 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002147
2148 // DO Software Michael
2149 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002150 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002151 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002152 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002153 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2154 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002155
2156 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2157
2158 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2159
Andres More52a7e642013-02-25 20:32:53 -05002160 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2161 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002162
2163 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2164 MIC_vUnInit();
2165
Andres More4e9b5e22013-02-12 20:36:30 -05002166 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002167 *pdwMIC_L = 0;
2168 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002169 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002170 }
2171
2172 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2173 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002174 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2175 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002176
2177 }
2178
Andres Moreb902fbf2013-02-25 20:32:51 -05002179 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002180 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002181
2182 if (pDevice->bEnableHostWEP) {
2183 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2184 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2185 }
2186
2187 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002188 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002189 }
2190 }
2191
Andres More1cac4a42013-03-18 20:33:50 -05002192 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002193 pDevice->wSeqCounter++ ;
2194 if (pDevice->wSeqCounter > 0x0fff)
2195 pDevice->wSeqCounter = 0;
2196
Forest Bond92b96792009-06-13 07:38:31 -04002197 if (bIsPSPOLL) {
2198 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2199 // of FIFO control header.
2200 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2201 // in the same place of other packet's Duration-field).
2202 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002203 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2204 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2205 cpu_to_le16(p80211Header->sA2.wDurationID);
2206 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2207 cpu_to_le16(p80211Header->sA2.wDurationID);
2208 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002209 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2210 cpu_to_le16(p80211Header->sA2.wDurationID);
2211 }
Forest Bond92b96792009-06-13 07:38:31 -04002212 }
2213
Andres More3eaca0d2013-02-25 20:32:52 -05002214 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002215 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002216 pTX_Buffer->byType = 0x00;
2217
2218 pContext->pPacket = skb;
2219 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002220 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002221
Andres More1cac4a42013-03-18 20:33:50 -05002222 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2223 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002224 }
2225 else {
Andres More1cac4a42013-03-18 20:33:50 -05002226 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002227 }
2228 PIPEnsSendBulkOut(pDevice,pContext);
2229 return ;
2230
2231}
2232
Forest Bond92b96792009-06-13 07:38:31 -04002233//TYPE_AC0DMA data tx
2234/*
2235 * Description:
2236 * Tx packet via AC0DMA(DMA1)
2237 *
2238 * Parameters:
2239 * In:
2240 * pDevice - Pointer to the adapter
2241 * skb - Pointer to tx skb packet
2242 * Out:
2243 * void
2244 *
2245 * Return Value: NULL
2246 */
2247
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002248int nsDMA_tx_packet(struct vnt_private *pDevice,
2249 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002250{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002251 struct net_device_stats *pStats = &pDevice->stats;
2252 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002253 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002254 u32 BytesToWrite = 0, uHeaderLen = 0;
2255 u32 uNodeIndex = 0;
2256 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2257 u16 wAID;
2258 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002259 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002260 PSKeyItem pTransmitKey = NULL;
2261 SKeyItem STempKey;
2262 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002263 int bTKIP_UseGTK = false;
2264 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002265 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002266 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002267 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002268 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002269 u32 status;
2270 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002271 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002272
Forest Bond92b96792009-06-13 07:38:31 -04002273 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2274
2275 if (pDevice->uAssocCount == 0) {
2276 dev_kfree_skb_irq(skb);
2277 return 0;
2278 }
2279
Andres Moreb902fbf2013-02-25 20:32:51 -05002280 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002281 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002282 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002283 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2284
2285 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2286 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2287 // set tx map
2288 pMgmt->abyPSTxMap[0] |= byMask[0];
2289 return 0;
2290 }
Masanari Iida93184692012-08-13 21:21:50 +09002291 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002292
2293 if (pDevice->byBBType != BB_TYPE_11A)
2294 pDevice->wCurrentRate = RATE_2M;
2295 else
2296 pDevice->wCurrentRate = RATE_24M;
2297 // long preamble type
2298 pDevice->byPreambleType = PREAMBLE_SHORT;
2299
2300 }else {
2301
Andres Moreb902fbf2013-02-25 20:32:51 -05002302 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002303
2304 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2305
2306 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2307
2308 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2309 // set tx map
2310 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2311 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2312 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2313 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2314
2315 return 0;
2316 }
2317 // AP rate decided from node
2318 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2319 // tx preamble decided from node
2320
2321 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2322 pDevice->byPreambleType = pDevice->byShortPreamble;
2323
2324 }else {
2325 pDevice->byPreambleType = PREAMBLE_LONG;
2326 }
Andres More4e9b5e22013-02-12 20:36:30 -05002327 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002328 }
2329 }
2330
Andres Moree269fc22013-02-12 20:36:29 -05002331 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002332 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2333 dev_kfree_skb_irq(skb);
2334 return 0;
2335 }
2336 }
2337
2338 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2339
2340 if (pContext == NULL) {
2341 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2342 dev_kfree_skb_irq(skb);
2343 return STATUS_RESOURCES;
2344 }
2345
Andres Moreceb8c5d2013-03-18 20:33:49 -05002346 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002347
2348//mike add:station mode check eapol-key challenge--->
2349{
Andres Moreb902fbf2013-02-25 20:32:51 -05002350 u8 Protocol_Version; //802.1x Authentication
2351 u8 Packet_Type; //802.1x Authentication
2352 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002353 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002354
Charles Clément21ec51f2010-05-18 10:08:14 -07002355 Protocol_Version = skb->data[ETH_HLEN];
2356 Packet_Type = skb->data[ETH_HLEN+1];
2357 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2358 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 -05002359 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002360 /* 802.1x OR eapol-key challenge frame transfer */
2361 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2362 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002363 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002364 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2365 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2366 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002367 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002368 PRINT_K("WPA ");
2369 }
2370 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002371 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002372 PRINT_K("WPA2(re-keying) ");
2373 }
2374 PRINT_K("Authentication completed!!\n");
2375 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002376 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002377 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002378 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002379 PRINT_K("WPA2 Authentication completed!!\n");
2380 }
2381 }
2382 }
2383}
2384//mike add:station mode check eapol-key challenge<---
2385
Andres More4e9b5e22013-02-12 20:36:30 -05002386 if (pDevice->bEncryptionEnable == true) {
2387 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002388 // get Transmit key
2389 do {
2390 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2391 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2392 pbyBSSID = pDevice->abyBSSID;
2393 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002394 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002395 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002396 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2397 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002398 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2399 break;
2400 }
2401 } else {
2402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2403 break;
2404 }
2405 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002406 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2407 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2409 for (ii = 0; ii< 6; ii++)
2410 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2412
2413 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002414 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002415 break;
2416 }
2417 // get group key
2418 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002419 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002420 pTransmitKey = NULL;
2421 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2422 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2423 }
2424 else
2425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2426 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002427 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002428 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2429 }
Andres Moree269fc22013-02-12 20:36:29 -05002430 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002431 }
2432
2433 if (pDevice->bEnableHostWEP) {
2434 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002435 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002436 pTransmitKey = &STempKey;
2437 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2438 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2439 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2440 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2441 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2442 memcpy(pTransmitKey->abyKey,
2443 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2444 pTransmitKey->uKeyLength
2445 );
2446 }
2447 }
2448
Andres Moreb902fbf2013-02-25 20:32:51 -05002449 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002450
2451 if (pDevice->bFixRate) {
2452 if (pDevice->byBBType == BB_TYPE_11B) {
2453 if (pDevice->uConnectionRate >= RATE_11M) {
2454 pDevice->wCurrentRate = RATE_11M;
2455 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002456 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002457 }
2458 } else {
2459 if ((pDevice->byBBType == BB_TYPE_11A) &&
2460 (pDevice->uConnectionRate <= RATE_6M)) {
2461 pDevice->wCurrentRate = RATE_6M;
2462 } else {
2463 if (pDevice->uConnectionRate >= RATE_54M)
2464 pDevice->wCurrentRate = RATE_54M;
2465 else
Andres More3eaca0d2013-02-25 20:32:52 -05002466 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002467 }
2468 }
2469 }
2470 else {
2471 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2472 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002473 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002474 // Multicast use highest data rate
2475 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2476 // preamble type
2477 pDevice->byPreambleType = pDevice->byShortPreamble;
2478 }
2479 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002480 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002481 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2482 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2483 pDevice->byPreambleType = pDevice->byShortPreamble;
2484
2485 }
2486 else {
2487 pDevice->byPreambleType = PREAMBLE_LONG;
2488 }
2489 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2490 }
2491 else {
2492 if (pDevice->byBBType != BB_TYPE_11A)
2493 pDevice->wCurrentRate = RATE_2M;
2494 else
2495 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2496 // abyCurrExtSuppRates[]
2497 pDevice->byPreambleType = PREAMBLE_SHORT;
2498 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2499 }
2500 }
2501 }
2502 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2503 // Infra STA rate decided from AP Node, index = 0
2504 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2505 }
2506 }
2507
Andres Moreceb8c5d2013-03-18 20:33:49 -05002508 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002509 if (pDevice->byBBType != BB_TYPE_11A) {
2510 pDevice->wCurrentRate = RATE_1M;
2511 pDevice->byACKRate = RATE_1M;
2512 pDevice->byTopCCKBasicRate = RATE_1M;
2513 pDevice->byTopOFDMBasicRate = RATE_6M;
2514 } else {
2515 pDevice->wCurrentRate = RATE_6M;
2516 pDevice->byACKRate = RATE_6M;
2517 pDevice->byTopCCKBasicRate = RATE_1M;
2518 pDevice->byTopOFDMBasicRate = RATE_6M;
2519 }
2520 }
Forest Bond92b96792009-06-13 07:38:31 -04002521
Andres More0cbd8d92010-05-06 20:34:29 -03002522 DBG_PRT(MSG_LEVEL_DEBUG,
2523 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2524 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002525
2526 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002527 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002528 }
2529
2530 if (pDevice->wCurrentRate <= RATE_11M) {
2531 byPktType = PK_TYPE_11B;
2532 }
2533
Andres More4e9b5e22013-02-12 20:36:30 -05002534 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002535 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2536 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002537 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002538 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002539 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2540 if (pTransmitKey == NULL) {
2541 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2542 }
2543 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002544 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2546 }
2547 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002548 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2549 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002550 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002551 }
2552 }
2553 }
2554
Forest Bond92b96792009-06-13 07:38:31 -04002555 if (pDevice->bEnableHostWEP) {
2556 if ((uNodeIndex != 0) &&
2557 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002558 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2559 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002560 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002561 }
2562 }
2563 }
2564 else {
2565
Forest Bond92b96792009-06-13 07:38:31 -04002566 if (pTransmitKey == NULL) {
2567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002568 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002569 dev_kfree_skb_irq(skb);
2570 pStats->tx_dropped++;
2571 return STATUS_FAILURE;
2572 }
Forest Bond92b96792009-06-13 07:38:31 -04002573 }
2574 }
2575
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002576 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2577
Forest Bond92b96792009-06-13 07:38:31 -04002578 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002579 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002580 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002581 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002582 pDevice->wCurrentRate,
2583 &uHeaderLen, &BytesToWrite
2584 );
2585
Andres Moree269fc22013-02-12 20:36:29 -05002586 if (fConvertedPacket == false) {
2587 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002588 dev_kfree_skb_irq(skb);
2589 return STATUS_FAILURE;
2590 }
2591
Andres More4e9b5e22013-02-12 20:36:30 -05002592 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002593 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002594 bScheduleCommand((void *) pDevice,
2595 WLAN_CMD_MAC_DISPOWERSAVING,
2596 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002597 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002598 }
2599 }
2600
Andres Moreb902fbf2013-02-25 20:32:51 -05002601 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002602 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002603
2604 pContext->pPacket = skb;
2605 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002606 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002607
Andres Moreceb8c5d2013-03-18 20:33:49 -05002608 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 -04002609
2610 status = PIPEnsSendBulkOut(pDevice,pContext);
2611
Andres More4e9b5e22013-02-12 20:36:30 -05002612 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002613 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002614
Andres Moreb902fbf2013-02-25 20:32:51 -05002615 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002616 }
2617
2618 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002619 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002620 dev_kfree_skb_irq(skb);
2621 return STATUS_FAILURE;
2622 }
2623 else
2624 return 0;
2625
2626}
2627
Forest Bond92b96792009-06-13 07:38:31 -04002628/*
2629 * Description:
2630 * Relay packet send (AC1DMA) from rx dpc.
2631 *
2632 * Parameters:
2633 * In:
2634 * pDevice - Pointer to the adapter
2635 * pPacket - Pointer to rx packet
2636 * cbPacketSize - rx ethernet frame size
2637 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002638 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002639 *
Andres More4e9b5e22013-02-12 20:36:30 -05002640 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002641 */
2642
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002643int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2644 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002645{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002646 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002647 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002648 u32 BytesToWrite = 0, uHeaderLen = 0;
2649 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002650 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002651 SKeyItem STempKey;
2652 PSKeyItem pTransmitKey = NULL;
2653 u8 *pbyBSSID;
2654 PUSB_SEND_CONTEXT pContext;
2655 u8 byPktTyp;
2656 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002657 u32 status;
2658 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002659
Forest Bond92b96792009-06-13 07:38:31 -04002660 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2661
2662 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002663 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002664 }
2665
Andres Moreceb8c5d2013-03-18 20:33:49 -05002666 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002667
Andres More4e9b5e22013-02-12 20:36:30 -05002668 if (pDevice->bEncryptionEnable == true) {
2669 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002670 // get group key
2671 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002672 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002673 pTransmitKey = NULL;
2674 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2675 } else {
2676 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2677 }
2678 }
2679
2680 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002681 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002682 pTransmitKey = &STempKey;
2683 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2684 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2685 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2686 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2687 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2688 memcpy(pTransmitKey->abyKey,
2689 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2690 pTransmitKey->uKeyLength
2691 );
2692 }
2693 }
2694
2695 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002696 pContext->bBoolInUse = false;
2697 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002698 }
2699
Andres Moreb902fbf2013-02-25 20:32:51 -05002700 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002701
2702 if (pDevice->bFixRate) {
2703 if (pDevice->byBBType == BB_TYPE_11B) {
2704 if (pDevice->uConnectionRate >= RATE_11M) {
2705 pDevice->wCurrentRate = RATE_11M;
2706 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002707 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002708 }
2709 } else {
2710 if ((pDevice->byBBType == BB_TYPE_11A) &&
2711 (pDevice->uConnectionRate <= RATE_6M)) {
2712 pDevice->wCurrentRate = RATE_6M;
2713 } else {
2714 if (pDevice->uConnectionRate >= RATE_54M)
2715 pDevice->wCurrentRate = RATE_54M;
2716 else
Andres More3eaca0d2013-02-25 20:32:52 -05002717 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002718 }
2719 }
2720 }
2721 else {
2722 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2723 }
2724
Forest Bond92b96792009-06-13 07:38:31 -04002725 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002726 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002727 }
2728
2729 if (pDevice->wCurrentRate <= RATE_11M)
2730 byPktType = PK_TYPE_11B;
2731
Andres Moreabad19d2010-07-12 16:28:32 -03002732 BytesToWrite = uDataLen + ETH_FCS_LEN;
2733
Forest Bond92b96792009-06-13 07:38:31 -04002734 // Convert the packet to an usb frame and copy into our buffer
2735 // and send the irp.
2736
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002737 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2738
Forest Bond92b96792009-06-13 07:38:31 -04002739 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002740 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002741 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2742 pbySkbData, pTransmitKey, uNodeIndex,
2743 pDevice->wCurrentRate,
2744 &uHeaderLen, &BytesToWrite
2745 );
2746
Andres Moree269fc22013-02-12 20:36:29 -05002747 if (fConvertedPacket == false) {
2748 pContext->bBoolInUse = false;
2749 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002750 }
2751
Andres Moreb902fbf2013-02-25 20:32:51 -05002752 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002753 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002754
2755 pContext->pPacket = NULL;
2756 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002757 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002758
Andres Moreceb8c5d2013-03-18 20:33:49 -05002759 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 -04002760
2761 status = PIPEnsSendBulkOut(pDevice,pContext);
2762
Andres More4e9b5e22013-02-12 20:36:30 -05002763 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002764}
2765