blob: a45cc9f27eec13486f8279963c01a0d1b7073ffc [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Andres More3eaca0d2013-02-25 20:32:52 -050067const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Andres More3eaca0d2013-02-25 20:32:52 -050072const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Andres More3eaca0d2013-02-25 20:32:52 -050076const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000099static void *s_vGetFreeContext(struct vnt_private *pDevice);
100
101static void s_vGenerateTxParameter(struct vnt_private *pDevice,
102 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
103 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500104 struct ethhdr *psEthHeader);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
106static u32 s_uFillDataHead(struct vnt_private *pDevice,
107 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100108 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000110static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500111 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000112 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
115 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100116 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static void s_vSWencryption(struct vnt_private *pDevice,
119 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000121static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
122 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100124static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000125 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000127static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
128 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100129 u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400130
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000131static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100132 void *pvRTS, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500133 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100135static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100136 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400137
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100138static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000139 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
140 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400141
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000142static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400143{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000144 PUSB_SEND_CONTEXT pContext = NULL;
145 PUSB_SEND_CONTEXT pReturnContext = NULL;
146 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400147
148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
149
150 for (ii = 0; ii < pDevice->cbTD; ii++) {
151 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500152 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500153 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100154 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400155 pReturnContext = pContext;
156 break;
157 }
158 }
159 if ( ii == pDevice->cbTD ) {
160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
161 }
Andres More8611a292010-05-01 14:25:00 -0300162 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400163}
164
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000165static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
166 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400167{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000168 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400169
Andres More4b50fb42010-06-22 21:57:42 -0300170 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400171 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300172 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
174 else
175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
176
177 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
178 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300179 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
180 pbyDestAddr,
181 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400182}
183
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000184static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
185 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100186 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400187{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000188 u32 *pdwIV = (u32 *)pbyIVHead;
189 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500190 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000191 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400192
Forest Bond92b96792009-06-13 07:38:31 -0400193 //Fill TXKEY
194 if (pTransmitKey == NULL)
195 return;
196
197 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
198 *pdwIV = pDevice->dwIVCounter;
199 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
200
201 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
202 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
Andres Moreb902fbf2013-02-25 20:32:51 -0500203 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700204 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400205 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500206 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700207 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400208 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500209 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700210 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400211 }
Jim Lieb3e362592009-08-12 14:54:11 -0700212 memcpy(pDevice->abyPRNG, pbyBuf, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400213 }
214 // Append IV after Mac Header
215 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
Malcolm Priestleyd5bbef72012-11-11 15:53:14 +0000216 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
Forest Bond92b96792009-06-13 07:38:31 -0400217 *pdwIV = cpu_to_le32(*pdwIV);
218 pDevice->dwIVCounter++;
219 if (pDevice->dwIVCounter > WEP_IV_MASK) {
220 pDevice->dwIVCounter = 0;
221 }
222 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
223 pTransmitKey->wTSC15_0++;
224 if (pTransmitKey->wTSC15_0 == 0) {
225 pTransmitKey->dwTSC47_16++;
226 }
227 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
228 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
Jim Lieb3e362592009-08-12 14:54:11 -0700229 memcpy(pbyBuf, pDevice->abyPRNG, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400230 // Make IV
Jim Lieb3e362592009-08-12 14:54:11 -0700231 memcpy(pdwIV, pDevice->abyPRNG, 3);
Forest Bond92b96792009-06-13 07:38:31 -0400232
Andres Moreb902fbf2013-02-25 20:32:51 -0500233 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Forest Bond92b96792009-06-13 07:38:31 -0400234 // Append IV&ExtIV after Mac Header
235 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +0000236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
237 *pdwExtIV);
Forest Bond92b96792009-06-13 07:38:31 -0400238
239 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
240 pTransmitKey->wTSC15_0++;
241 if (pTransmitKey->wTSC15_0 == 0) {
242 pTransmitKey->dwTSC47_16++;
243 }
Jim Lieb3e362592009-08-12 14:54:11 -0700244 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400245
246 // Make IV
247 *pdwIV = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -0500248 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Andres More3eaca0d2013-02-25 20:32:52 -0500249 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
Forest Bond92b96792009-06-13 07:38:31 -0400250 //Append IV&ExtIV after Mac Header
251 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
252
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100253 if (!mic_hdr)
254 return;
Forest Bond92b96792009-06-13 07:38:31 -0400255
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100256 /* MICHDR0 */
257 mic_hdr->id = 0x59;
258 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
259 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400260
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100261 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
262 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
263
264 /* MICHDR1 */
265 if (pDevice->bLongHeader)
266 mic_hdr->hlen = cpu_to_be16(28);
267 else
268 mic_hdr->hlen = cpu_to_be16(22);
269
270 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
271 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
272
273 /* MICHDR2 */
274 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
275 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
276 & 0xc78f);
277 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
278
279 if (pDevice->bLongHeader)
280 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400281 }
282}
283
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000284static void s_vSWencryption(struct vnt_private *pDevice,
285 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400286{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000287 u32 cbICVlen = 4;
288 u32 dwICV = 0xffffffff;
289 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400290
291 if (pTransmitKey == NULL)
292 return;
293
294 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
295 //=======================================================================
296 // Append ICV after payload
297 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500298 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400299 // finally, we must invert dwCRC to get the correct answer
300 *pdwICV = cpu_to_le32(~dwICV);
301 // RC4 encryption
302 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
303 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
304 //=======================================================================
305 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
306 //=======================================================================
307 //Append ICV after payload
308 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500309 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400310 // finally, we must invert dwCRC to get the correct answer
311 *pdwICV = cpu_to_le32(~dwICV);
312 // RC4 encryption
313 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 }
317}
318
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100319static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
320{
321 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
322 [rate % MAX_RATE]);
323}
324
Forest Bond92b96792009-06-13 07:38:31 -0400325/*byPktType : PK_TYPE_11A 0
326 PK_TYPE_11B 1
327 PK_TYPE_11GB 2
328 PK_TYPE_11GA 3
329*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000330static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
331 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400332{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000333 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400334
335 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
336 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500337 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400338 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500339 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400340 }
341
342 if (bNeedAck) {
343 return (uDataTime + pDevice->uSIFS + uAckTime);
344 }
345 else {
346 return uDataTime;
347 }
348}
349
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100350static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
351 u32 frame_length, u16 rate, int need_ack)
352{
353 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
354 frame_length, rate, need_ack));
355}
356
Forest Bond92b96792009-06-13 07:38:31 -0400357//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100358static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000359 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400360{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000361 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400362
363 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
364
Forest Bond92b96792009-06-13 07:38:31 -0400365 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
366 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
367 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
368 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
369 }
370 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
371 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
372 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
373 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
374 }
375 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
376 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
377 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
378 }
379 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
380 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
381 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
382 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
383 return uRrvTime;
384 }
385
386 //RTSRrvTime
387 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100388 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400389}
390
391//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100392static u16 s_uGetDataDuration(struct vnt_private *pDevice,
393 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400394{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100395 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400396
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100397 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100398 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100399 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
400 byPktType, 14, pDevice->byTopCCKBasicRate);
401 else
402 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
403 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100404 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100405 }
Forest Bond92b96792009-06-13 07:38:31 -0400406
Forest Bond92b96792009-06-13 07:38:31 -0400407 return 0;
408}
409
Forest Bond92b96792009-06-13 07:38:31 -0400410//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100411static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000412 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
413 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400414{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000415 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400416
Forest Bond92b96792009-06-13 07:38:31 -0400417 switch (byDurType) {
418
419 case RTSDUR_BB: //RTSDuration_bb
420 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
421 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
422 break;
423
424 case RTSDUR_BA: //RTSDuration_ba
425 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
426 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
427 break;
428
429 case RTSDUR_AA: //RTSDuration_aa
430 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
431 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
432 break;
433
434 case CTSDUR_BA: //CTSDuration_ba
435 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
436 break;
437
438 case RTSDUR_BA_F0: //RTSDuration_ba_f0
439 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
440 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
441 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
442 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
443 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
444 }
445 break;
446
447 case RTSDUR_AA_F0: //RTSDuration_aa_f0
448 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
449 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
450 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
451 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
452 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
453 }
454 break;
455
456 case RTSDUR_BA_F1: //RTSDuration_ba_f1
457 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
458 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
459 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
460 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
461 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
462 }
463 break;
464
465 case RTSDUR_AA_F1: //RTSDuration_aa_f1
466 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
467 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
468 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
469 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
470 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
471 }
472 break;
473
474 case CTSDUR_BA_F0: //CTSDuration_ba_f0
475 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
476 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
477 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
478 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
479 }
480 break;
481
482 case CTSDUR_BA_F1: //CTSDuration_ba_f1
483 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
484 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
485 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
486 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
487 }
488 break;
489
490 default:
491 break;
492 }
493
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100494 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400495}
496
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000497static u32 s_uFillDataHead(struct vnt_private *pDevice,
498 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100499 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400500{
501
502 if (pTxDataHead == NULL) {
503 return 0;
504 }
505
506 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Forest Bond92b96792009-06-13 07:38:31 -0400507 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100508 struct vnt_tx_datahead_g *pBuf =
509 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400510 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100511 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
512 byPktType, &pBuf->a);
513 BBvCalculateParameter(pDevice, cbFrameLength,
514 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400515 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100516 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100517 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100518 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100519 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400520
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100521 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
522 wCurrentRate);
523 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
524 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400525 return (pBuf->wDuration_a);
526 } else {
527 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100528 struct vnt_tx_datahead_g_fb *pBuf =
529 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400530 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100531 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
532 byPktType, &pBuf->a);
533 BBvCalculateParameter(pDevice, cbFrameLength,
534 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400535 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100536 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100537 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100538 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100539 PK_TYPE_11B, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100540 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100541 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100542 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100543 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100544 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
545 wCurrentRate);
546 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
547 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400548 return (pBuf->wDuration_a);
549 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400550 }
551 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100552 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100553 struct vnt_tx_datahead_a_fb *pBuf =
554 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400555 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100556 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
557 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400558 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100559 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100560 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100561 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100562 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100563 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100564 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100565 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
566 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400567 return (pBuf->wDuration);
568 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100569 struct vnt_tx_datahead_ab *pBuf =
570 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400571 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100572 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
573 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400574 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100575 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100576 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100577 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
578 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400579 return (pBuf->wDuration);
580 }
581 }
582 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100583 struct vnt_tx_datahead_ab *pBuf =
584 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400585 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100586 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
587 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400588 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100589 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100590 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100591 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
592 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400593 return (pBuf->wDuration);
594 }
595 return 0;
596}
597
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100598static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
599 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
600 u16 duration)
601{
602 rts->duration = duration;
603 rts->frame_control = TYPE_CTL_RTS;
604
605 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
606 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
607 else
608 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
609
610 if (priv->eOPMode == OP_MODE_AP)
611 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
612 else
613 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
614
615 return 0;
616}
617
618static int vnt_rxtx_rts_g_head(struct vnt_private *priv,
619 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
620 u8 pkt_type, u32 frame_len, int need_ack,
621 u16 current_rate, u8 fb_option)
622{
623 u16 rts_frame_len = 20;
624
625 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
626 PK_TYPE_11B, &buf->b);
627 BBvCalculateParameter(priv, rts_frame_len,
628 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
629
630 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
631 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
632 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
633 pkt_type, current_rate, need_ack, fb_option);
634 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
635 pkt_type, current_rate, need_ack, fb_option);
636
637 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
638
639 return 0;
640}
641
Malcolm Priestleyec917132013-08-26 11:07:46 +0100642static int vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
643 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
644 u8 pkt_type, u32 frame_len, int need_ack,
645 u16 current_rate, u8 fb_option)
646{
647 u16 rts_frame_len = 20;
648
649 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
650 PK_TYPE_11B, &buf->b);
651 BBvCalculateParameter(priv, rts_frame_len,
652 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
653
654
655 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
656 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
657 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
658 pkt_type, current_rate, need_ack, fb_option);
659 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
660 pkt_type, current_rate, need_ack, fb_option);
661
662
663 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
664 frame_len, pkt_type, current_rate, need_ack, fb_option);
665 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
666 frame_len, pkt_type, current_rate, need_ack, fb_option);
667 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
668 frame_len, pkt_type, current_rate, need_ack, fb_option);
669 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
670 frame_len, pkt_type, current_rate, need_ack, fb_option);
671
672 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
673
674 return 0;
675}
676
Malcolm Priestley17126332013-08-26 11:09:38 +0100677static int vnt_rxtx_rts_ab_head(struct vnt_private *priv,
678 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
679 u8 pkt_type, u32 frame_len, int need_ack,
680 u16 current_rate, u8 fb_option)
681{
682 u16 rts_frame_len = 20;
683
684 BBvCalculateParameter(priv, rts_frame_len,
685 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
686
687 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
688 pkt_type, current_rate, need_ack, fb_option);
689
690 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
691
692 return 0;
693}
694
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100695static int vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
696 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
697 u8 pkt_type, u32 frame_len, int need_ack,
698 u16 current_rate, u8 fb_option)
699{
700 u16 rts_frame_len = 20;
701
702 BBvCalculateParameter(priv, rts_frame_len,
703 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
704
705 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
706 pkt_type, current_rate, need_ack, fb_option);
707
708 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
709 frame_len, pkt_type, current_rate, need_ack, fb_option);
710
711 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
712 frame_len, pkt_type, current_rate, need_ack, fb_option);
713
714 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
715
716 return 0;
717}
718
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000719static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100720 void *pvRTS, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500721 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400722{
Forest Bond92b96792009-06-13 07:38:31 -0400723
Forest Bond92b96792009-06-13 07:38:31 -0400724 if (pvRTS == NULL)
725 return;
726
Masanari Iida93184692012-08-13 21:21:50 +0900727 // 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 -0400728 // Otherwise, we need to modified codes for them.
729 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
730 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100731 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400732
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100733 vnt_rxtx_rts_g_head(pDevice, pBuf,
734 psEthHeader, byPktType, cbFrameLength,
735 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400736 }
737 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100738 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400739
Malcolm Priestleyec917132013-08-26 11:07:46 +0100740 vnt_rxtx_rts_g_fb_head(pDevice, pBuf,
741 psEthHeader, byPktType, cbFrameLength,
742 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400743 } // if (byFBOption == AUTO_FB_NONE)
744 }
745 else if (byPktType == PK_TYPE_11A) {
746 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100747 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400748
Malcolm Priestley17126332013-08-26 11:09:38 +0100749 vnt_rxtx_rts_ab_head(pDevice, pBuf,
750 psEthHeader, byPktType, cbFrameLength,
751 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400752 }
753 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100754 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400755
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100756 vnt_rxtx_rts_a_fb_head(pDevice, pBuf,
757 psEthHeader, byPktType, cbFrameLength,
758 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400759 }
760 }
761 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100762 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400763
Malcolm Priestley17126332013-08-26 11:09:38 +0100764 vnt_rxtx_rts_ab_head(pDevice, pBuf,
765 psEthHeader, byPktType, cbFrameLength,
766 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400767 }
768}
769
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000770static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
771 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100772 u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400773{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000774 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400775
776 if (pvCTS == NULL) {
777 return;
778 }
779
Forest Bond92b96792009-06-13 07:38:31 -0400780 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100781 if (byFBOption != AUTO_FB_NONE) {
782 /* Auto Fall back */
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100783 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100784 /* Get SignalField,ServiceField,Length */
785 BBvCalculateParameter(pDevice, uCTSFrameLen,
786 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100787 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
788 cbFrameLength, byPktType,
789 wCurrentRate, bNeedAck, byFBOption);
790 /* Get CTSDuration_ba_f0 */
791 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
792 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
793 bNeedAck, byFBOption);
794 /* Get CTSDuration_ba_f1 */
795 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
796 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
797 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100798 /* Get CTS Frame body */
799 pBuf->data.duration = pBuf->wDuration_ba;
800 pBuf->data.frame_control = TYPE_CTL_CTS;
801 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100802 } else {
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100803 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100804 /* Get SignalField,ServiceField,Length */
805 BBvCalculateParameter(pDevice, uCTSFrameLen,
806 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100807 /* Get CTSDuration_ba */
808 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
809 CTSDUR_BA, cbFrameLength, byPktType,
810 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100811 /*Get CTS Frame body*/
812 pBuf->data.duration = pBuf->wDuration_ba;
813 pBuf->data.frame_control = TYPE_CTL_CTS;
814 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400815 }
816 }
817}
818
Forest Bond92b96792009-06-13 07:38:31 -0400819/*+
820 *
821 * Description:
822 * Generate FIFO control for MAC & Baseband controller
823 *
824 * Parameters:
825 * In:
826 * pDevice - Pointer to adpater
827 * pTxDataHead - Transmit Data Buffer
828 * pTxBufHead - pTxBufHead
829 * pvRrvTime - pvRrvTime
830 * pvRTS - RTS Buffer
831 * pCTS - CTS Buffer
832 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
833 * bNeedACK - If need ACK
834 * uDMAIdx - DMA Index
835 * Out:
836 * none
837 *
838 * Return Value: none
839 *
840-*/
Andres Morecc856e62010-05-17 21:34:01 -0300841
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000842static void s_vGenerateTxParameter(struct vnt_private *pDevice,
843 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
844 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500845 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400846{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000847 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
848 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000849 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400850
851 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
852 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
853 pFifoHead->wReserved = wCurrentRate;
854 wFifoCtl = pFifoHead->wFIFOCtl;
855
Forest Bond92b96792009-06-13 07:38:31 -0400856 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
857 byFBOption = AUTO_FB_0;
858 }
859 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
860 byFBOption = AUTO_FB_1;
861 }
862
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100863 if (!pvRrvTime)
864 return;
865
Forest Bond92b96792009-06-13 07:38:31 -0400866 if (pDevice->bLongHeader)
867 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
868
869 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
870
871 if (pvRTS != NULL) { //RTS_need
872 //Fill RsvTime
Malcolm Priestley6398a592013-08-16 21:26:55 +0100873 struct vnt_rrv_time_rts *pBuf =
874 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100875 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
876 byPktType, cbFrameSize, wCurrentRate);
877 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
878 byPktType, cbFrameSize, wCurrentRate);
879 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
880 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100881 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
882 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
883 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
884 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
885 bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400886 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100887 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
888 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400889 }
890 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400891 //Fill RsvTime
Malcolm Priestley4f990052013-08-16 23:38:57 +0100892 struct vnt_rrv_time_cts *pBuf =
893 (struct vnt_rrv_time_cts *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100894 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
895 cbFrameSize, wCurrentRate, bNeedACK);
896 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
897 PK_TYPE_11B, cbFrameSize,
898 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100899 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
900 byPktType, cbFrameSize, wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400901 //Fill CTS
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100902 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize,
903 bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400904 }
905 }
906 else if (byPktType == PK_TYPE_11A) {
907
908 if (pvRTS != NULL) {//RTS_need, non PCF mode
909 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100910 struct vnt_rrv_time_ab *pBuf =
911 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100912 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
913 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100914 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
915 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400916 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100917 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
918 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400919 }
920 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
921 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100922 struct vnt_rrv_time_ab *pBuf =
923 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100924 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
925 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400926 }
927 }
928 else if (byPktType == PK_TYPE_11B) {
929
930 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
931 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100932 struct vnt_rrv_time_ab *pBuf =
933 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100934 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
935 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100936 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
937 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400938 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100939 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
940 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400941 }
942 else { //RTS_needless, non PCF mode
943 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100944 struct vnt_rrv_time_ab *pBuf =
945 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100946 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
947 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400948 }
949 }
950 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
951}
952/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500953 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500954 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300955 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400956*/
957
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000958static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100959 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
960 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
961 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
962 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400963{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000964 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
965 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000966 u32 cb802_1_H_len;
967 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
968 u32 cbFCSlen = 4, cbMICHDR = 0;
969 int bNeedACK, bRTS;
970 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
971 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
972 u8 abySNAP_Bridgetunnel[ETH_ALEN]
973 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
974 u32 uDuration;
975 u32 cbHeaderLength = 0, uPadding = 0;
976 void *pvRrvTime;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100977 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000978 void *pvRTS;
979 void *pvCTS;
980 void *pvTxDataHd;
981 u8 byFBOption = AUTO_FB_NONE, byFragType;
982 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100983 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000984 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500985 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -0400986
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000987 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400988
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000989 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500990 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
991 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000992 }
Forest Bond92b96792009-06-13 07:38:31 -0400993
Forest Bond92b96792009-06-13 07:38:31 -0400994 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -0500995 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -0400996 if (pDevice->dwDiagRefCount == 0) {
997 cb802_1_H_len = 8;
998 } else {
999 cb802_1_H_len = 2;
1000 }
1001 } else {
1002 cb802_1_H_len = 0;
1003 }
1004
Charles Clément21ec51f2010-05-18 10:08:14 -07001005 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001006
1007 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001008 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001009
1010 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001011 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001012 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1013 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001014 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1015 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001016 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001017 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001018 pTxBufHead->wFIFOCtl =
1019 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1020 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001021 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001022 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1023 }
Forest Bond92b96792009-06-13 07:38:31 -04001024 }
1025 else {
1026 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001027 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001028 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1029 }
1030 } //if (pDevice->dwDiagRefCount != 0) {
1031
1032 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1033
1034 //Set FIFOCTL_LHEAD
1035 if (pDevice->bLongHeader)
1036 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1037
Forest Bond92b96792009-06-13 07:38:31 -04001038 //Set FRAGCTL_MACHDCNT
1039 if (pDevice->bLongHeader) {
1040 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1041 } else {
1042 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1043 }
Andres More3eaca0d2013-02-25 20:32:52 -05001044 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001045
1046 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001047 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001048 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1049 }
1050
1051 //Set Auto Fallback Ctl
1052 if (wCurrentRate >= RATE_18M) {
1053 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1054 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1055 byFBOption = AUTO_FB_0;
1056 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1057 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1058 byFBOption = AUTO_FB_1;
1059 }
1060 }
1061
Andres More4e9b5e22013-02-12 20:36:30 -05001062 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001063 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1064 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1065 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1066 }
1067 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1068 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1069 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1070 }
1071 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1072 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1073 }
1074 }
1075 }
1076
Forest Bond92b96792009-06-13 07:38:31 -04001077 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1078 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1079 cbIVlen = 4;
1080 cbICVlen = 4;
1081 }
1082 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1083 cbIVlen = 8;//IV+ExtIV
1084 cbMIClen = 8;
1085 cbICVlen = 4;
1086 }
1087 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1088 cbIVlen = 8;//RSN Header
1089 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001090 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001091 }
Andres Moree269fc22013-02-12 20:36:29 -05001092 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001093 //MAC Header should be padding 0 to DW alignment.
1094 uPadding = 4 - (cbMACHdLen%4);
1095 uPadding %= 4;
1096 }
1097 }
1098
1099 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1100
Andres Moree269fc22013-02-12 20:36:29 -05001101 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1102 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001103 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001104 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001105 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1106 }
1107
Andres Moreb902fbf2013-02-25 20:32:51 -05001108 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001109 wTxBufSize = sizeof(STxBufHead);
1110 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1111 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001112 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001113 pvRrvTime = (struct vnt_rrv_time_rts *)
1114 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001115 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001116 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001117 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001118 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001119 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001120 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1121 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1122 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001123 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001124 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001125 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001126 }
1127 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001128 pvRrvTime = (struct vnt_rrv_time_cts *)
1129 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001130 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001131 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001132 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001133 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001134 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001135 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1136 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1137 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001138 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1139 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001140 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001141 }
1142 } else {
1143 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001144 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001145 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1146 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001147 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001148 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001149 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001150 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001151 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001152 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1153 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1154 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001155 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1156 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001157 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001158 }
Andres Moree269fc22013-02-12 20:36:29 -05001159 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001160 pvRrvTime = (struct vnt_rrv_time_cts *)
1161 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001162 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001163 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001164 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001165 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001166 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001167 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001168 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1169 cbMICHDR + sizeof(struct vnt_cts_fb));
1170 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001171 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001172 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001173 }
1174 } // Auto Fall Back
1175 }
1176 else {//802.11a/b packet
1177 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001178 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001179 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1180 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001181 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001182 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001183 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001184 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001185 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001186 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1187 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001188 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001189 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1190 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001191 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001192 }
Andres Moree269fc22013-02-12 20:36:29 -05001193 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001194 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1195 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001196 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001197 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001198 pvRTS = NULL;
1199 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001200 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1201 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001202 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001203 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001204 }
1205 } else {
1206 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001207 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001208 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1209 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001210 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001211 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001212 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001213 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001214 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001215 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1216 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001217 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001218 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1219 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001220 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001221 }
Andres Moree269fc22013-02-12 20:36:29 -05001222 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001223 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1224 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001225 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001226 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001227 pvRTS = NULL;
1228 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001229 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1230 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001231 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001232 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001233 }
1234 } // Auto Fall Back
1235 }
1236
Andres Moreb902fbf2013-02-25 20:32:51 -05001237 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1238 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1239 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001240
Forest Bond92b96792009-06-13 07:38:31 -04001241 //=========================
1242 // No Fragmentation
1243 //=========================
1244 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1245 byFragType = FRAGCTL_NONFRAG;
1246 //uDMAIdx = TYPE_AC0DMA;
1247 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1248
Forest Bond92b96792009-06-13 07:38:31 -04001249 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001250 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1251 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001252 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1253 //Fill DataHead
1254 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001255 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001256 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001257 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001258 byFragType, uDMAIdx, 0);
1259
Andres More4e9b5e22013-02-12 20:36:30 -05001260 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001261 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001262 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001263 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001264
1265 if (pDevice->bEnableHostWEP) {
1266 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1267 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1268 }
1269 }
1270
1271 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001272 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001273 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001274 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1275 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001276 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001277 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001278 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001279 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001280 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001281 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001282 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001283 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001284 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001285
1286 }
1287
1288 }
1289
Forest Bond92b96792009-06-13 07:38:31 -04001290 if (pPacket != NULL) {
1291 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001292 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001293 (pPacket + ETH_HLEN),
1294 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001295 );
1296
1297 } else {
1298 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001299 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001300 }
1301
Andres More4e9b5e22013-02-12 20:36:30 -05001302 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001303
1304 ///////////////////////////////////////////////////////////////////
1305
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001306 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1307 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1308 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1309 }
Forest Bond92b96792009-06-13 07:38:31 -04001310 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001311 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1312 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001313 }
1314 else {
Andres More52a7e642013-02-25 20:32:53 -05001315 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1316 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001317 }
1318 // DO Software Michael
1319 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001320 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001321 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001322 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001323 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1324 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001325
1326 ///////////////////////////////////////////////////////////////////
1327
1328 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1329 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001330 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001331 //}
1332 //DBG_PRN_GRP12(("\n\n\n"));
1333
1334 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1335
Andres More52a7e642013-02-25 20:32:53 -05001336 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1337 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001338
1339 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1340 MIC_vUnInit();
1341
Andres More4e9b5e22013-02-12 20:36:30 -05001342 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001343 *pdwMIC_L = 0;
1344 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001345 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001346 }
1347 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1348 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1349 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1350 }
1351
Andres More4e9b5e22013-02-12 20:36:30 -05001352 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001353
Andres More3eaca0d2013-02-25 20:32:52 -05001354 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001355
Andres More4e9b5e22013-02-12 20:36:30 -05001356 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1357 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1358 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001359 cbFrameSize -= cbICVlen;
1360 }
1361
Forest Bond92b96792009-06-13 07:38:31 -04001362 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001363
1364 *pcbHeaderLen = cbHeaderLength;
1365 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1366
Forest Bond92b96792009-06-13 07:38:31 -04001367 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001368 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001369
Andres More4e9b5e22013-02-12 20:36:30 -05001370 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001371
1372}
1373
Forest Bond92b96792009-06-13 07:38:31 -04001374/*+
1375 *
1376 * Description:
1377 * Translate 802.3 to 802.11 header
1378 *
1379 * Parameters:
1380 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001381 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001382 * dwTxBufferAddr - Transmit Buffer
1383 * pPacket - Packet from upper layer
1384 * cbPacketSize - Transmit Data Length
1385 * Out:
1386 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1387 * pcbAppendPayload - size of append payload for 802.1H translation
1388 *
1389 * Return Value: none
1390 *
1391-*/
1392
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001393static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001394 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001395 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001396{
Andres More1cac4a42013-03-18 20:33:50 -05001397 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001398
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001399 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001400
1401 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001402 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001403 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001404 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001405 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1406 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001407 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001408 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001409 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001410 } else {
1411 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001412 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001413 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001414 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001415 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001416 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001417 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001418 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001419 &(pDevice->abyBSSID[0]),
1420 ETH_ALEN);
1421 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001422 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001423 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001424 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001425 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001426 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001427 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001428 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001429 &(pDevice->abyBSSID[0]),
1430 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001431 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001432 }
1433 }
1434
1435 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001436 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001437
Andres More1cac4a42013-03-18 20:33:50 -05001438 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001439
1440 if (pDevice->bLongHeader) {
1441 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001442 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001443 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001444 }
Andres More1cac4a42013-03-18 20:33:50 -05001445 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001446
1447 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001448 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001449
1450 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1451 pDevice->wSeqCounter++;
1452 if (pDevice->wSeqCounter > 0x0fff)
1453 pDevice->wSeqCounter = 0;
1454 }
1455
1456 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001457 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001458 }
1459}
1460
Forest Bond92b96792009-06-13 07:38:31 -04001461/*+
1462 *
1463 * Description:
1464 * Request instructs a MAC to transmit a 802.11 management packet through
1465 * the adapter onto the medium.
1466 *
1467 * Parameters:
1468 * In:
1469 * hDeviceContext - Pointer to the adapter
1470 * pPacket - A pointer to a descriptor for the packet to transmit
1471 * Out:
1472 * none
1473 *
Andres Moree269fc22013-02-12 20:36:29 -05001474 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001475 *
1476-*/
1477
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001478CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1479 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001480{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001481 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001482 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001483 PSTxBufHead pTxBufHead;
1484 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001485 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001486 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001487 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001488 u8 byPktType, *pbyTxBufferAddr;
1489 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1490 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001491 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001492 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1493 u32 uPadding = 0;
1494 u16 wTxBufSize;
1495 u32 cbMacHdLen;
1496 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001497
Forest Bond92b96792009-06-13 07:38:31 -04001498 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1499
1500 if (NULL == pContext) {
1501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1502 return CMD_STATUS_RESOURCES;
1503 }
1504
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001505 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001506 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001507 cbFrameBodySize = pPacket->cbPayloadLen;
1508 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1509 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001510
1511 if (pDevice->byBBType == BB_TYPE_11A) {
1512 wCurrentRate = RATE_6M;
1513 byPktType = PK_TYPE_11A;
1514 } else {
1515 wCurrentRate = RATE_1M;
1516 byPktType = PK_TYPE_11B;
1517 }
1518
1519 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1520 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1521 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1522 // to set power here.
1523 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1524 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1525 } else {
1526 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1527 }
1528 pDevice->wCurrentRate = wCurrentRate;
1529
Forest Bond92b96792009-06-13 07:38:31 -04001530 //Set packet type
1531 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1532 pTxBufHead->wFIFOCtl = 0;
1533 }
1534 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1535 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1536 }
1537 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1538 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1539 }
1540 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1541 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1542 }
1543
1544 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1545 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1546
Andres More22040bb2010-08-02 20:21:44 -03001547 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001548 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001549 }
1550 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001551 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001552 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1553 };
1554
1555 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1556 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1557
1558 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1559 //Set Preamble type always long
1560 //pDevice->byPreambleType = PREAMBLE_LONG;
1561 // probe-response don't retry
1562 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001563 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001564 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1565 //}
1566 }
1567
1568 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1569
1570 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001571 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001572 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1573 } else {
1574 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1575 }
1576
1577 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001578 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001579
1580 // Notes:
1581 // Although spec says MMPDU can be fragmented; In most case,
1582 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001583 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001584
1585 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1586 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1587 cbIVlen = 4;
1588 cbICVlen = 4;
1589 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1590 }
1591 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1592 cbIVlen = 8;//IV+ExtIV
1593 cbMIClen = 8;
1594 cbICVlen = 4;
1595 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1596 //We need to get seed here for filling TxKey entry.
1597 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1598 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1599 }
1600 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1601 cbIVlen = 8;//RSN Header
1602 cbICVlen = 8;//MIC
1603 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001604 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001605 }
1606 //MAC Header should be padding 0 to DW alignment.
1607 uPadding = 4 - (cbMacHdLen%4);
1608 uPadding %= 4;
1609 }
1610
1611 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1612
1613 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001614 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001615 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1616 }
1617 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1618
1619 //Set RrvTime/RTS/CTS Buffer
1620 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1621
Malcolm Priestley4f990052013-08-16 23:38:57 +01001622 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001623 pMICHDR = NULL;
1624 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001625 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001626 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001627 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001628 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1629 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001630 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001631 }
1632 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001633 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001634 pMICHDR = NULL;
1635 pvRTS = NULL;
1636 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001637 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1638 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001639 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001640 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001641 }
1642
Andres Moreceb8c5d2013-03-18 20:33:49 -05001643 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001644 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1645 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001646 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001647 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1648 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001649 //=========================
1650 // No Fragmentation
1651 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001652 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001653
Forest Bond92b96792009-06-13 07:38:31 -04001654 //Fill FIFO,RrvTime,RTS,and CTS
1655 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1656 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1657
1658 //Fill DataHead
1659 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001660 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001661
Andres More1cac4a42013-03-18 20:33:50 -05001662 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001663
1664 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1665
1666 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001667 u8 * pbyIVHead;
1668 u8 * pbyPayloadHead;
1669 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001670 PSKeyItem pTransmitKey = NULL;
1671
Andres Moreb902fbf2013-02-25 20:32:51 -05001672 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1673 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001674 do {
1675 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001676 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001677 pbyBSSID = pDevice->abyBSSID;
1678 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001679 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001680 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001681 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001682 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1683 break;
1684 }
1685 } else {
1686 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1687 break;
1688 }
1689 }
1690 // get group key
1691 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001692 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001693 pTransmitKey = NULL;
1694 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1695 } else {
1696 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1697 }
Andres Moree269fc22013-02-12 20:36:29 -05001698 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001699 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001700 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001701 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001702
Jim Lieb3e362592009-08-12 14:54:11 -07001703 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001704 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001705 cbFrameBodySize);
1706 }
1707 else {
1708 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001709 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001710 }
1711
Andres More1cac4a42013-03-18 20:33:50 -05001712 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001713 pDevice->wSeqCounter++ ;
1714 if (pDevice->wSeqCounter > 0x0fff)
1715 pDevice->wSeqCounter = 0;
1716
1717 if (bIsPSPOLL) {
1718 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001719 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001720 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1721 // in the same place of other packet's Duration-field).
1722 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001723 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1724 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1725 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1726 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1727 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1728 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001729 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1730 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1731 }
Forest Bond92b96792009-06-13 07:38:31 -04001732 }
1733
Andres More3eaca0d2013-02-25 20:32:52 -05001734 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001735 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001736 pTX_Buffer->byType = 0x00;
1737
1738 pContext->pPacket = NULL;
1739 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001740 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001741
Andres More1cac4a42013-03-18 20:33:50 -05001742 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1743 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001744 }
1745 else {
Andres More1cac4a42013-03-18 20:33:50 -05001746 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001747 }
1748
1749 PIPEnsSendBulkOut(pDevice,pContext);
1750 return CMD_STATUS_PENDING;
1751}
1752
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001753CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1754 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001755{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001756 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001757 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1758 u32 cbHeaderSize = 0;
1759 u16 wTxBufSize = sizeof(STxShortBufHead);
1760 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001761 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001762 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001763 u16 wCurrentRate;
1764 u32 cbFrameBodySize;
1765 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001766 u8 *pbyTxBufferAddr;
1767 PUSB_SEND_CONTEXT pContext;
1768 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001769
Forest Bond92b96792009-06-13 07:38:31 -04001770 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1771 if (NULL == pContext) {
1772 status = CMD_STATUS_RESOURCES;
1773 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1774 return status ;
1775 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001776
1777 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001778 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001779
1780 cbFrameBodySize = pPacket->cbPayloadLen;
1781
1782 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1783 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001784
1785 if (pDevice->byBBType == BB_TYPE_11A) {
1786 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001787 pTxDataHead = (struct vnt_tx_datahead_ab *)
1788 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001789 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001790 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1791 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001792 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001793 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001794 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001795 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001796 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001797 } else {
1798 wCurrentRate = RATE_1M;
1799 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001800 pTxDataHead = (struct vnt_tx_datahead_ab *)
1801 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001802 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001803 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1804 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001805 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001806 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001807 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001808 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001809 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001810 }
1811
1812 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001813 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001814 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001815
Andres More1cac4a42013-03-18 20:33:50 -05001816 pMACHeader->duration_id = 0;
1817 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001818 pDevice->wSeqCounter++ ;
1819 if (pDevice->wSeqCounter > 0x0fff)
1820 pDevice->wSeqCounter = 0;
1821
1822 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1823
Andres More3eaca0d2013-02-25 20:32:52 -05001824 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001825 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001826 pTX_Buffer->byType = 0x01;
1827
1828 pContext->pPacket = NULL;
1829 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001830 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001831
1832 PIPEnsSendBulkOut(pDevice,pContext);
1833 return CMD_STATUS_PENDING;
1834
1835}
1836
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001837void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1838{
1839 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001840 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001841 u8 byPktType;
1842 u8 *pbyTxBufferAddr;
1843 void *pvRTS, *pvCTS, *pvTxDataHd;
1844 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001845 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001846 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001847 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001848 PSTxBufHead pTxBufHead;
1849 u32 cbFrameSize;
1850 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1851 u32 uPadding = 0;
1852 u32 cbMICHDR = 0, uLength = 0;
1853 u32 dwMICKey0, dwMICKey1;
1854 u32 dwMIC_Priority;
1855 u32 *pdwMIC_L, *pdwMIC_R;
1856 u16 wTxBufSize;
1857 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001858 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001859 void *pvRrvTime, *pMICHDR;
1860 u32 wCurrentRate = RATE_1M;
1861 PUWLAN_80211HDR p80211Header;
1862 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001863 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001864 SKeyItem STempKey;
1865 PSKeyItem pTransmitKey = NULL;
1866 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1867 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001868 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001869
Forest Bond92b96792009-06-13 07:38:31 -04001870 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1871
1872 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1873 cbFrameBodySize = 0;
1874 }
1875 else {
1876 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1877 }
1878 p80211Header = (PUWLAN_80211HDR)skb->data;
1879
1880 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1881
1882 if (NULL == pContext) {
1883 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1884 dev_kfree_skb_irq(skb);
1885 return ;
1886 }
1887
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001888 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001889 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001890 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1891 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001892
1893 if (pDevice->byBBType == BB_TYPE_11A) {
1894 wCurrentRate = RATE_6M;
1895 byPktType = PK_TYPE_11A;
1896 } else {
1897 wCurrentRate = RATE_1M;
1898 byPktType = PK_TYPE_11B;
1899 }
1900
1901 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1902 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1903 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1904 // to set power here.
1905 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1906 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1907 } else {
1908 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1909 }
1910
1911 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1912
1913 //Set packet type
1914 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1915 pTxBufHead->wFIFOCtl = 0;
1916 }
1917 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1918 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1919 }
1920 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1921 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1922 }
1923 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1924 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1925 }
1926
1927 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1928 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1929
Andres More22040bb2010-08-02 20:21:44 -03001930 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001931 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001932 if (pDevice->bEnableHostWEP) {
1933 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001934 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001935 }
Forest Bond92b96792009-06-13 07:38:31 -04001936 }
1937 else {
1938 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001939 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001940 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001941 }
Andres More4e9b5e22013-02-12 20:36:30 -05001942 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001943 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1944 };
1945
1946 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1947 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1948
1949 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1950 //Set Preamble type always long
1951 //pDevice->byPreambleType = PREAMBLE_LONG;
1952
1953 // probe-response don't retry
1954 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001955 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001956 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1957 //}
1958 }
1959
1960 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1961
1962 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001963 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001964 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1965 } else {
1966 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1967 }
1968
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001969 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001970 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1971
1972 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1973 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1974 }
1975
1976 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1977 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1978 }
1979
1980 if (cbExtSuppRate >0) {
1981 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1982 }
1983 }
1984
Forest Bond92b96792009-06-13 07:38:31 -04001985 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001986 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001987
1988 // Notes:
1989 // Although spec says MMPDU can be fragmented; In most case,
1990 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001991 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001992
Forest Bond92b96792009-06-13 07:38:31 -04001993 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1994 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1995 cbIVlen = 4;
1996 cbICVlen = 4;
1997 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1998 }
1999 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2000 cbIVlen = 8;//IV+ExtIV
2001 cbMIClen = 8;
2002 cbICVlen = 4;
2003 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2004 //We need to get seed here for filling TxKey entry.
2005 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2006 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2007 }
2008 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2009 cbIVlen = 8;//RSN Header
2010 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002011 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04002012 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002013 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002014 }
2015 //MAC Header should be padding 0 to DW alignment.
2016 uPadding = 4 - (cbMacHdLen%4);
2017 uPadding %= 4;
2018 }
2019
2020 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2021
2022 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002023 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002024 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2025 }
2026 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2027
Forest Bond92b96792009-06-13 07:38:31 -04002028 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002029 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002030 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002031 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002032 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002033 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002034 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002035 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2036 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002037 sizeof(struct vnt_cts));
2038 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002039 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002040
2041 }
2042 else {//802.11a/b packet
2043
Malcolm Priestley976467d2013-08-16 23:44:04 +01002044 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002045 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002046 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002047 pvRTS = NULL;
2048 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002049 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2050 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002051 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002052 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002053 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002054 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002055 &(p80211Header->sA3.abyAddr1[0]),
2056 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002057 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002058 &(p80211Header->sA3.abyAddr2[0]),
2059 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002060 //=========================
2061 // No Fragmentation
2062 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002063 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002064
Forest Bond92b96792009-06-13 07:38:31 -04002065 //Fill FIFO,RrvTime,RTS,and CTS
2066 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2067 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2068
2069 //Fill DataHead
2070 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002071 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002072
Andres More1cac4a42013-03-18 20:33:50 -05002073 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002074
2075 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2076
Andres Moreb902fbf2013-02-25 20:32:51 -05002077 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2078 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2079 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002080
2081 // Copy the Packet into a tx Buffer
2082 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2083
2084 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002085 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002086 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2087
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002088 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002089 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2090 if (cbExtSuppRate != 0) {
2091 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2092 memcpy((pbyPayloadHead + cbFrameBodySize),
2093 pMgmt->abyCurrSuppRates,
2094 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2095 );
2096 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2097 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2098 pMgmt->abyCurrExtSuppRates,
2099 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2100 );
2101 }
2102 }
2103
2104 // Set wep
2105 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2106
2107 if (pDevice->bEnableHostWEP) {
2108 pTransmitKey = &STempKey;
2109 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2110 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2111 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2112 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2113 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2114 memcpy(pTransmitKey->abyKey,
2115 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2116 pTransmitKey->uKeyLength
2117 );
2118 }
2119
2120 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2121
Andres More52a7e642013-02-25 20:32:53 -05002122 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2123 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002124
2125 // DO Software Michael
2126 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002127 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002128 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002129 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002130 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2131 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002132
2133 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2134
2135 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2136
Andres More52a7e642013-02-25 20:32:53 -05002137 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2138 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002139
2140 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2141 MIC_vUnInit();
2142
Andres More4e9b5e22013-02-12 20:36:30 -05002143 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002144 *pdwMIC_L = 0;
2145 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002146 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002147 }
2148
2149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2150 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002151 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2152 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002153
2154 }
2155
Andres Moreb902fbf2013-02-25 20:32:51 -05002156 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002157 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002158
2159 if (pDevice->bEnableHostWEP) {
2160 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2161 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2162 }
2163
2164 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002165 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002166 }
2167 }
2168
Andres More1cac4a42013-03-18 20:33:50 -05002169 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002170 pDevice->wSeqCounter++ ;
2171 if (pDevice->wSeqCounter > 0x0fff)
2172 pDevice->wSeqCounter = 0;
2173
Forest Bond92b96792009-06-13 07:38:31 -04002174 if (bIsPSPOLL) {
2175 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2176 // of FIFO control header.
2177 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2178 // in the same place of other packet's Duration-field).
2179 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002180 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2181 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2182 cpu_to_le16(p80211Header->sA2.wDurationID);
2183 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2184 cpu_to_le16(p80211Header->sA2.wDurationID);
2185 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002186 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2187 cpu_to_le16(p80211Header->sA2.wDurationID);
2188 }
Forest Bond92b96792009-06-13 07:38:31 -04002189 }
2190
Andres More3eaca0d2013-02-25 20:32:52 -05002191 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002192 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002193 pTX_Buffer->byType = 0x00;
2194
2195 pContext->pPacket = skb;
2196 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002197 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002198
Andres More1cac4a42013-03-18 20:33:50 -05002199 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2200 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002201 }
2202 else {
Andres More1cac4a42013-03-18 20:33:50 -05002203 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002204 }
2205 PIPEnsSendBulkOut(pDevice,pContext);
2206 return ;
2207
2208}
2209
Forest Bond92b96792009-06-13 07:38:31 -04002210//TYPE_AC0DMA data tx
2211/*
2212 * Description:
2213 * Tx packet via AC0DMA(DMA1)
2214 *
2215 * Parameters:
2216 * In:
2217 * pDevice - Pointer to the adapter
2218 * skb - Pointer to tx skb packet
2219 * Out:
2220 * void
2221 *
2222 * Return Value: NULL
2223 */
2224
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002225int nsDMA_tx_packet(struct vnt_private *pDevice,
2226 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002227{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002228 struct net_device_stats *pStats = &pDevice->stats;
2229 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002230 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002231 u32 BytesToWrite = 0, uHeaderLen = 0;
2232 u32 uNodeIndex = 0;
2233 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2234 u16 wAID;
2235 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002236 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002237 PSKeyItem pTransmitKey = NULL;
2238 SKeyItem STempKey;
2239 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002240 int bTKIP_UseGTK = false;
2241 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002242 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002243 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002244 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002245 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002246 u32 status;
2247 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002248 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002249
Forest Bond92b96792009-06-13 07:38:31 -04002250 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2251
2252 if (pDevice->uAssocCount == 0) {
2253 dev_kfree_skb_irq(skb);
2254 return 0;
2255 }
2256
Andres Moreb902fbf2013-02-25 20:32:51 -05002257 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002258 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002259 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002260 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2261
2262 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2263 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2264 // set tx map
2265 pMgmt->abyPSTxMap[0] |= byMask[0];
2266 return 0;
2267 }
Masanari Iida93184692012-08-13 21:21:50 +09002268 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002269
2270 if (pDevice->byBBType != BB_TYPE_11A)
2271 pDevice->wCurrentRate = RATE_2M;
2272 else
2273 pDevice->wCurrentRate = RATE_24M;
2274 // long preamble type
2275 pDevice->byPreambleType = PREAMBLE_SHORT;
2276
2277 }else {
2278
Andres Moreb902fbf2013-02-25 20:32:51 -05002279 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002280
2281 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2282
2283 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2284
2285 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2286 // set tx map
2287 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2288 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2289 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2290 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2291
2292 return 0;
2293 }
2294 // AP rate decided from node
2295 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2296 // tx preamble decided from node
2297
2298 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2299 pDevice->byPreambleType = pDevice->byShortPreamble;
2300
2301 }else {
2302 pDevice->byPreambleType = PREAMBLE_LONG;
2303 }
Andres More4e9b5e22013-02-12 20:36:30 -05002304 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002305 }
2306 }
2307
Andres Moree269fc22013-02-12 20:36:29 -05002308 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002309 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2310 dev_kfree_skb_irq(skb);
2311 return 0;
2312 }
2313 }
2314
2315 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2316
2317 if (pContext == NULL) {
2318 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2319 dev_kfree_skb_irq(skb);
2320 return STATUS_RESOURCES;
2321 }
2322
Andres Moreceb8c5d2013-03-18 20:33:49 -05002323 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002324
2325//mike add:station mode check eapol-key challenge--->
2326{
Andres Moreb902fbf2013-02-25 20:32:51 -05002327 u8 Protocol_Version; //802.1x Authentication
2328 u8 Packet_Type; //802.1x Authentication
2329 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002330 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002331
Charles Clément21ec51f2010-05-18 10:08:14 -07002332 Protocol_Version = skb->data[ETH_HLEN];
2333 Packet_Type = skb->data[ETH_HLEN+1];
2334 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2335 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 -05002336 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002337 /* 802.1x OR eapol-key challenge frame transfer */
2338 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2339 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002340 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002341 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2342 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2343 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002344 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002345 PRINT_K("WPA ");
2346 }
2347 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002348 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002349 PRINT_K("WPA2(re-keying) ");
2350 }
2351 PRINT_K("Authentication completed!!\n");
2352 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002353 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002354 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002355 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002356 PRINT_K("WPA2 Authentication completed!!\n");
2357 }
2358 }
2359 }
2360}
2361//mike add:station mode check eapol-key challenge<---
2362
Andres More4e9b5e22013-02-12 20:36:30 -05002363 if (pDevice->bEncryptionEnable == true) {
2364 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002365 // get Transmit key
2366 do {
2367 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2368 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2369 pbyBSSID = pDevice->abyBSSID;
2370 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002371 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002372 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002373 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2374 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2376 break;
2377 }
2378 } else {
2379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2380 break;
2381 }
2382 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002383 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2384 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2386 for (ii = 0; ii< 6; ii++)
2387 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2389
2390 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002391 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002392 break;
2393 }
2394 // get group key
2395 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002396 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002397 pTransmitKey = NULL;
2398 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2400 }
2401 else
2402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2403 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002404 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2406 }
Andres Moree269fc22013-02-12 20:36:29 -05002407 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002408 }
2409
2410 if (pDevice->bEnableHostWEP) {
2411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002412 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002413 pTransmitKey = &STempKey;
2414 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2415 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2416 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2417 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2418 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2419 memcpy(pTransmitKey->abyKey,
2420 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2421 pTransmitKey->uKeyLength
2422 );
2423 }
2424 }
2425
Andres Moreb902fbf2013-02-25 20:32:51 -05002426 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002427
2428 if (pDevice->bFixRate) {
2429 if (pDevice->byBBType == BB_TYPE_11B) {
2430 if (pDevice->uConnectionRate >= RATE_11M) {
2431 pDevice->wCurrentRate = RATE_11M;
2432 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002433 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002434 }
2435 } else {
2436 if ((pDevice->byBBType == BB_TYPE_11A) &&
2437 (pDevice->uConnectionRate <= RATE_6M)) {
2438 pDevice->wCurrentRate = RATE_6M;
2439 } else {
2440 if (pDevice->uConnectionRate >= RATE_54M)
2441 pDevice->wCurrentRate = RATE_54M;
2442 else
Andres More3eaca0d2013-02-25 20:32:52 -05002443 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002444 }
2445 }
2446 }
2447 else {
2448 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2449 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002450 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002451 // Multicast use highest data rate
2452 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2453 // preamble type
2454 pDevice->byPreambleType = pDevice->byShortPreamble;
2455 }
2456 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002457 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002458 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2459 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2460 pDevice->byPreambleType = pDevice->byShortPreamble;
2461
2462 }
2463 else {
2464 pDevice->byPreambleType = PREAMBLE_LONG;
2465 }
2466 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2467 }
2468 else {
2469 if (pDevice->byBBType != BB_TYPE_11A)
2470 pDevice->wCurrentRate = RATE_2M;
2471 else
2472 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2473 // abyCurrExtSuppRates[]
2474 pDevice->byPreambleType = PREAMBLE_SHORT;
2475 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2476 }
2477 }
2478 }
2479 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2480 // Infra STA rate decided from AP Node, index = 0
2481 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2482 }
2483 }
2484
Andres Moreceb8c5d2013-03-18 20:33:49 -05002485 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002486 if (pDevice->byBBType != BB_TYPE_11A) {
2487 pDevice->wCurrentRate = RATE_1M;
2488 pDevice->byACKRate = RATE_1M;
2489 pDevice->byTopCCKBasicRate = RATE_1M;
2490 pDevice->byTopOFDMBasicRate = RATE_6M;
2491 } else {
2492 pDevice->wCurrentRate = RATE_6M;
2493 pDevice->byACKRate = RATE_6M;
2494 pDevice->byTopCCKBasicRate = RATE_1M;
2495 pDevice->byTopOFDMBasicRate = RATE_6M;
2496 }
2497 }
Forest Bond92b96792009-06-13 07:38:31 -04002498
Andres More0cbd8d92010-05-06 20:34:29 -03002499 DBG_PRT(MSG_LEVEL_DEBUG,
2500 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2501 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002502
2503 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002504 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002505 }
2506
2507 if (pDevice->wCurrentRate <= RATE_11M) {
2508 byPktType = PK_TYPE_11B;
2509 }
2510
Andres More4e9b5e22013-02-12 20:36:30 -05002511 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002512 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2513 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002514 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002515 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002516 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2517 if (pTransmitKey == NULL) {
2518 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2519 }
2520 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002521 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002522 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2523 }
2524 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002525 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2526 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002527 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002528 }
2529 }
2530 }
2531
Forest Bond92b96792009-06-13 07:38:31 -04002532 if (pDevice->bEnableHostWEP) {
2533 if ((uNodeIndex != 0) &&
2534 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002535 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2536 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002537 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002538 }
2539 }
2540 }
2541 else {
2542
Forest Bond92b96792009-06-13 07:38:31 -04002543 if (pTransmitKey == NULL) {
2544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002545 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002546 dev_kfree_skb_irq(skb);
2547 pStats->tx_dropped++;
2548 return STATUS_FAILURE;
2549 }
Forest Bond92b96792009-06-13 07:38:31 -04002550 }
2551 }
2552
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002553 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2554
Forest Bond92b96792009-06-13 07:38:31 -04002555 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002556 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002557 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002558 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002559 pDevice->wCurrentRate,
2560 &uHeaderLen, &BytesToWrite
2561 );
2562
Andres Moree269fc22013-02-12 20:36:29 -05002563 if (fConvertedPacket == false) {
2564 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002565 dev_kfree_skb_irq(skb);
2566 return STATUS_FAILURE;
2567 }
2568
Andres More4e9b5e22013-02-12 20:36:30 -05002569 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002570 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002571 bScheduleCommand((void *) pDevice,
2572 WLAN_CMD_MAC_DISPOWERSAVING,
2573 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002574 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002575 }
2576 }
2577
Andres Moreb902fbf2013-02-25 20:32:51 -05002578 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002579 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002580
2581 pContext->pPacket = skb;
2582 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002583 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002584
Andres Moreceb8c5d2013-03-18 20:33:49 -05002585 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 -04002586
2587 status = PIPEnsSendBulkOut(pDevice,pContext);
2588
Andres More4e9b5e22013-02-12 20:36:30 -05002589 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002590 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002591
Andres Moreb902fbf2013-02-25 20:32:51 -05002592 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002593 }
2594
2595 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002596 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002597 dev_kfree_skb_irq(skb);
2598 return STATUS_FAILURE;
2599 }
2600 else
2601 return 0;
2602
2603}
2604
Forest Bond92b96792009-06-13 07:38:31 -04002605/*
2606 * Description:
2607 * Relay packet send (AC1DMA) from rx dpc.
2608 *
2609 * Parameters:
2610 * In:
2611 * pDevice - Pointer to the adapter
2612 * pPacket - Pointer to rx packet
2613 * cbPacketSize - rx ethernet frame size
2614 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002615 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002616 *
Andres More4e9b5e22013-02-12 20:36:30 -05002617 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002618 */
2619
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002620int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2621 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002622{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002623 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002624 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002625 u32 BytesToWrite = 0, uHeaderLen = 0;
2626 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002627 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002628 SKeyItem STempKey;
2629 PSKeyItem pTransmitKey = NULL;
2630 u8 *pbyBSSID;
2631 PUSB_SEND_CONTEXT pContext;
2632 u8 byPktTyp;
2633 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002634 u32 status;
2635 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002636
Forest Bond92b96792009-06-13 07:38:31 -04002637 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2638
2639 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002640 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002641 }
2642
Andres Moreceb8c5d2013-03-18 20:33:49 -05002643 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002644
Andres More4e9b5e22013-02-12 20:36:30 -05002645 if (pDevice->bEncryptionEnable == true) {
2646 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002647 // get group key
2648 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002649 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002650 pTransmitKey = NULL;
2651 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2652 } else {
2653 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2654 }
2655 }
2656
2657 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002658 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002659 pTransmitKey = &STempKey;
2660 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2661 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2662 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2663 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2664 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2665 memcpy(pTransmitKey->abyKey,
2666 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2667 pTransmitKey->uKeyLength
2668 );
2669 }
2670 }
2671
2672 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002673 pContext->bBoolInUse = false;
2674 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002675 }
2676
Andres Moreb902fbf2013-02-25 20:32:51 -05002677 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002678
2679 if (pDevice->bFixRate) {
2680 if (pDevice->byBBType == BB_TYPE_11B) {
2681 if (pDevice->uConnectionRate >= RATE_11M) {
2682 pDevice->wCurrentRate = RATE_11M;
2683 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002684 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002685 }
2686 } else {
2687 if ((pDevice->byBBType == BB_TYPE_11A) &&
2688 (pDevice->uConnectionRate <= RATE_6M)) {
2689 pDevice->wCurrentRate = RATE_6M;
2690 } else {
2691 if (pDevice->uConnectionRate >= RATE_54M)
2692 pDevice->wCurrentRate = RATE_54M;
2693 else
Andres More3eaca0d2013-02-25 20:32:52 -05002694 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002695 }
2696 }
2697 }
2698 else {
2699 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2700 }
2701
Forest Bond92b96792009-06-13 07:38:31 -04002702 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002703 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002704 }
2705
2706 if (pDevice->wCurrentRate <= RATE_11M)
2707 byPktType = PK_TYPE_11B;
2708
Andres Moreabad19d2010-07-12 16:28:32 -03002709 BytesToWrite = uDataLen + ETH_FCS_LEN;
2710
Forest Bond92b96792009-06-13 07:38:31 -04002711 // Convert the packet to an usb frame and copy into our buffer
2712 // and send the irp.
2713
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002714 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2715
Forest Bond92b96792009-06-13 07:38:31 -04002716 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002717 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002718 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2719 pbySkbData, pTransmitKey, uNodeIndex,
2720 pDevice->wCurrentRate,
2721 &uHeaderLen, &BytesToWrite
2722 );
2723
Andres Moree269fc22013-02-12 20:36:29 -05002724 if (fConvertedPacket == false) {
2725 pContext->bBoolInUse = false;
2726 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002727 }
2728
Andres Moreb902fbf2013-02-25 20:32:51 -05002729 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002730 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002731
2732 pContext->pPacket = NULL;
2733 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002734 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002735
Andres Moreceb8c5d2013-03-18 20:33:49 -05002736 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 -04002737
2738 status = PIPEnsSendBulkOut(pDevice,pContext);
2739
Andres More4e9b5e22013-02-12 20:36:30 -05002740 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002741}
2742