blob: 57af55b391d0cb24adbff83f69bb52bc9fd1ef55 [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 Priestleyd56131d2013-01-17 23:15:22 +0000642static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100643 void *pvRTS, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500644 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400645{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000646 u32 uRTSFrameLen = 20;
Forest Bond92b96792009-06-13 07:38:31 -0400647
Forest Bond92b96792009-06-13 07:38:31 -0400648 if (pvRTS == NULL)
649 return;
650
Masanari Iida93184692012-08-13 21:21:50 +0900651 // 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 -0400652 // Otherwise, we need to modified codes for them.
653 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
654 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100655 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400656
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100657 vnt_rxtx_rts_g_head(pDevice, pBuf,
658 psEthHeader, byPktType, cbFrameLength,
659 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400660 }
661 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100662 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400663 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100664 BBvCalculateParameter(pDevice, uRTSFrameLen,
665 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
666 BBvCalculateParameter(pDevice, uRTSFrameLen,
667 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400668 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100669 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
670 cbFrameLength, PK_TYPE_11B,
671 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
672 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
673 cbFrameLength, byPktType,
674 wCurrentRate, bNeedAck, byFBOption);
675 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
676 cbFrameLength, byPktType,
677 wCurrentRate, bNeedAck, byFBOption);
678 pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
679 RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
680 bNeedAck, byFBOption);
681 pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
682 RTSDUR_AA_F0, cbFrameLength, byPktType,
683 wCurrentRate, bNeedAck, byFBOption);
684 pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
685 RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
686 bNeedAck, byFBOption);
687 pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
688 RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
689 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100690 pBuf->data.duration = pBuf->wDuration_aa;
691 /*Get RTS Frame body*/
692 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400693
Malcolm Priestley07738932013-08-05 22:08:05 +0100694 if (pDevice->eOPMode == OP_MODE_ADHOC ||
695 pDevice->eOPMode == OP_MODE_AP)
696 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
697 else
698 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400699
Malcolm Priestley07738932013-08-05 22:08:05 +0100700 if (pDevice->eOPMode == OP_MODE_AP)
701 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
702 else
703 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400704 } // if (byFBOption == AUTO_FB_NONE)
705 }
706 else if (byPktType == PK_TYPE_11A) {
707 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100708 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400709 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100710 BBvCalculateParameter(pDevice, uRTSFrameLen,
711 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400712 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100713 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
714 cbFrameLength, byPktType, wCurrentRate,
715 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100716 pBuf->data.duration = pBuf->wDuration;
717 /* Get RTS Frame body */
718 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400719
Malcolm Priestley07738932013-08-05 22:08:05 +0100720 if (pDevice->eOPMode == OP_MODE_ADHOC ||
721 pDevice->eOPMode == OP_MODE_AP)
722 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
723 else
724 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400725
Malcolm Priestley07738932013-08-05 22:08:05 +0100726 if (pDevice->eOPMode == OP_MODE_AP)
727 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
728 else
729 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400730 }
731 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100732 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400733 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100734 BBvCalculateParameter(pDevice, uRTSFrameLen,
735 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400736 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100737 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
738 cbFrameLength, byPktType, wCurrentRate,
739 bNeedAck, byFBOption);
740 pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
741 RTSDUR_AA_F0, cbFrameLength, byPktType,
742 wCurrentRate, bNeedAck, byFBOption);
743 pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
744 RTSDUR_AA_F1, cbFrameLength, byPktType,
745 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100746 pBuf->data.duration = pBuf->wDuration;
747 /* Get RTS Frame body */
748 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400749
Malcolm Priestley07738932013-08-05 22:08:05 +0100750 if (pDevice->eOPMode == OP_MODE_ADHOC ||
751 pDevice->eOPMode == OP_MODE_AP)
752 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
753 else
754 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
755
756 if (pDevice->eOPMode == OP_MODE_AP)
757 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
758 else
759 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400760 }
761 }
762 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100763 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400764 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100765 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate,
766 PK_TYPE_11B, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400767 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100768 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
769 cbFrameLength, byPktType, wCurrentRate,
770 bNeedAck, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400771
Malcolm Priestley07738932013-08-05 22:08:05 +0100772 pBuf->data.duration = pBuf->wDuration;
773 /* Get RTS Frame body */
774 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400775
Malcolm Priestley07738932013-08-05 22:08:05 +0100776 if (pDevice->eOPMode == OP_MODE_ADHOC ||
777 pDevice->eOPMode == OP_MODE_AP)
778 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
779 else
780 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
781
782 if (pDevice->eOPMode == OP_MODE_AP)
783 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
784 else
785 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400786 }
787}
788
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000789static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
790 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100791 u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400792{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000793 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400794
795 if (pvCTS == NULL) {
796 return;
797 }
798
Forest Bond92b96792009-06-13 07:38:31 -0400799 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100800 if (byFBOption != AUTO_FB_NONE) {
801 /* Auto Fall back */
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100802 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100803 /* Get SignalField,ServiceField,Length */
804 BBvCalculateParameter(pDevice, uCTSFrameLen,
805 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100806 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
807 cbFrameLength, byPktType,
808 wCurrentRate, bNeedAck, byFBOption);
809 /* Get CTSDuration_ba_f0 */
810 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
811 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
812 bNeedAck, byFBOption);
813 /* Get CTSDuration_ba_f1 */
814 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
815 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
816 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100817 /* Get CTS Frame body */
818 pBuf->data.duration = pBuf->wDuration_ba;
819 pBuf->data.frame_control = TYPE_CTL_CTS;
820 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100821 } else {
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100822 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100823 /* Get SignalField,ServiceField,Length */
824 BBvCalculateParameter(pDevice, uCTSFrameLen,
825 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100826 /* Get CTSDuration_ba */
827 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
828 CTSDUR_BA, cbFrameLength, byPktType,
829 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100830 /*Get CTS Frame body*/
831 pBuf->data.duration = pBuf->wDuration_ba;
832 pBuf->data.frame_control = TYPE_CTL_CTS;
833 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400834 }
835 }
836}
837
Forest Bond92b96792009-06-13 07:38:31 -0400838/*+
839 *
840 * Description:
841 * Generate FIFO control for MAC & Baseband controller
842 *
843 * Parameters:
844 * In:
845 * pDevice - Pointer to adpater
846 * pTxDataHead - Transmit Data Buffer
847 * pTxBufHead - pTxBufHead
848 * pvRrvTime - pvRrvTime
849 * pvRTS - RTS Buffer
850 * pCTS - CTS Buffer
851 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
852 * bNeedACK - If need ACK
853 * uDMAIdx - DMA Index
854 * Out:
855 * none
856 *
857 * Return Value: none
858 *
859-*/
Andres Morecc856e62010-05-17 21:34:01 -0300860
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000861static void s_vGenerateTxParameter(struct vnt_private *pDevice,
862 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
863 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500864 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400865{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000866 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
867 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000868 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400869
870 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
871 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
872 pFifoHead->wReserved = wCurrentRate;
873 wFifoCtl = pFifoHead->wFIFOCtl;
874
Forest Bond92b96792009-06-13 07:38:31 -0400875 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
876 byFBOption = AUTO_FB_0;
877 }
878 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
879 byFBOption = AUTO_FB_1;
880 }
881
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100882 if (!pvRrvTime)
883 return;
884
Forest Bond92b96792009-06-13 07:38:31 -0400885 if (pDevice->bLongHeader)
886 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
887
888 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
889
890 if (pvRTS != NULL) { //RTS_need
891 //Fill RsvTime
Malcolm Priestley6398a592013-08-16 21:26:55 +0100892 struct vnt_rrv_time_rts *pBuf =
893 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100894 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
895 byPktType, cbFrameSize, wCurrentRate);
896 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
897 byPktType, cbFrameSize, wCurrentRate);
898 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
899 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100900 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
901 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
902 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
903 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
904 bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400905 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100906 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
907 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400908 }
909 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400910 //Fill RsvTime
Malcolm Priestley4f990052013-08-16 23:38:57 +0100911 struct vnt_rrv_time_cts *pBuf =
912 (struct vnt_rrv_time_cts *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100913 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
914 cbFrameSize, wCurrentRate, bNeedACK);
915 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
916 PK_TYPE_11B, cbFrameSize,
917 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100918 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
919 byPktType, cbFrameSize, wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400920 //Fill CTS
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100921 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize,
922 bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400923 }
924 }
925 else if (byPktType == PK_TYPE_11A) {
926
927 if (pvRTS != NULL) {//RTS_need, non PCF mode
928 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100929 struct vnt_rrv_time_ab *pBuf =
930 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100931 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
932 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100933 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
934 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400935 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100936 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
937 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400938 }
939 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
940 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100941 struct vnt_rrv_time_ab *pBuf =
942 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100943 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
944 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400945 }
946 }
947 else if (byPktType == PK_TYPE_11B) {
948
949 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
950 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100951 struct vnt_rrv_time_ab *pBuf =
952 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100953 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
954 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100955 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
956 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400957 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100958 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
959 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400960 }
961 else { //RTS_needless, non PCF mode
962 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100963 struct vnt_rrv_time_ab *pBuf =
964 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100965 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
966 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400967 }
968 }
969 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
970}
971/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500972 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500973 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300974 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400975*/
976
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000977static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100978 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
979 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
980 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
981 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400982{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000983 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
984 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000985 u32 cb802_1_H_len;
986 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
987 u32 cbFCSlen = 4, cbMICHDR = 0;
988 int bNeedACK, bRTS;
989 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
990 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
991 u8 abySNAP_Bridgetunnel[ETH_ALEN]
992 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
993 u32 uDuration;
994 u32 cbHeaderLength = 0, uPadding = 0;
995 void *pvRrvTime;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100996 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000997 void *pvRTS;
998 void *pvCTS;
999 void *pvTxDataHd;
1000 u8 byFBOption = AUTO_FB_NONE, byFragType;
1001 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +01001002 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001003 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001004 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -04001005
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001006 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001007
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001008 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001009 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1010 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001011 }
Forest Bond92b96792009-06-13 07:38:31 -04001012
Forest Bond92b96792009-06-13 07:38:31 -04001013 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001014 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001015 if (pDevice->dwDiagRefCount == 0) {
1016 cb802_1_H_len = 8;
1017 } else {
1018 cb802_1_H_len = 2;
1019 }
1020 } else {
1021 cb802_1_H_len = 0;
1022 }
1023
Charles Clément21ec51f2010-05-18 10:08:14 -07001024 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001025
1026 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001027 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001028
1029 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001030 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001031 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1032 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001033 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1034 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001035 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001036 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001037 pTxBufHead->wFIFOCtl =
1038 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1039 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001040 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001041 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1042 }
Forest Bond92b96792009-06-13 07:38:31 -04001043 }
1044 else {
1045 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001046 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001047 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1048 }
1049 } //if (pDevice->dwDiagRefCount != 0) {
1050
1051 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1052
1053 //Set FIFOCTL_LHEAD
1054 if (pDevice->bLongHeader)
1055 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1056
Forest Bond92b96792009-06-13 07:38:31 -04001057 //Set FRAGCTL_MACHDCNT
1058 if (pDevice->bLongHeader) {
1059 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1060 } else {
1061 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1062 }
Andres More3eaca0d2013-02-25 20:32:52 -05001063 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001064
1065 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001066 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001067 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1068 }
1069
1070 //Set Auto Fallback Ctl
1071 if (wCurrentRate >= RATE_18M) {
1072 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1073 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1074 byFBOption = AUTO_FB_0;
1075 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1076 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1077 byFBOption = AUTO_FB_1;
1078 }
1079 }
1080
Andres More4e9b5e22013-02-12 20:36:30 -05001081 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001082 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1083 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1084 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1085 }
1086 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1087 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1088 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1089 }
1090 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1091 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1092 }
1093 }
1094 }
1095
Forest Bond92b96792009-06-13 07:38:31 -04001096 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1097 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1098 cbIVlen = 4;
1099 cbICVlen = 4;
1100 }
1101 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1102 cbIVlen = 8;//IV+ExtIV
1103 cbMIClen = 8;
1104 cbICVlen = 4;
1105 }
1106 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1107 cbIVlen = 8;//RSN Header
1108 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001109 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001110 }
Andres Moree269fc22013-02-12 20:36:29 -05001111 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001112 //MAC Header should be padding 0 to DW alignment.
1113 uPadding = 4 - (cbMACHdLen%4);
1114 uPadding %= 4;
1115 }
1116 }
1117
1118 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1119
Andres Moree269fc22013-02-12 20:36:29 -05001120 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1121 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001122 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001123 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001124 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1125 }
1126
Andres Moreb902fbf2013-02-25 20:32:51 -05001127 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001128 wTxBufSize = sizeof(STxBufHead);
1129 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1130 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001131 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001132 pvRrvTime = (struct vnt_rrv_time_rts *)
1133 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001134 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001135 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001136 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001137 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001138 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001139 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1140 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1141 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001142 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001143 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001144 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001145 }
1146 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001147 pvRrvTime = (struct vnt_rrv_time_cts *)
1148 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001149 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001150 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001151 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001152 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001153 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001154 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1155 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1156 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001157 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1158 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001159 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001160 }
1161 } else {
1162 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001163 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001164 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1165 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001166 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001167 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001168 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001169 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001170 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001171 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1172 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1173 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001174 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1175 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001176 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001177 }
Andres Moree269fc22013-02-12 20:36:29 -05001178 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001179 pvRrvTime = (struct vnt_rrv_time_cts *)
1180 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001181 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001182 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001183 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001184 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001185 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001186 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001187 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1188 cbMICHDR + sizeof(struct vnt_cts_fb));
1189 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001190 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001191 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001192 }
1193 } // Auto Fall Back
1194 }
1195 else {//802.11a/b packet
1196 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001197 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001198 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1199 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001200 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001201 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001202 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001203 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001204 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001205 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1206 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001207 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001208 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1209 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001210 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001211 }
Andres Moree269fc22013-02-12 20:36:29 -05001212 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001213 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1214 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001215 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001216 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001217 pvRTS = NULL;
1218 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001219 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1220 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001221 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001222 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001223 }
1224 } else {
1225 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001226 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001227 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1228 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001229 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001230 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001231 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001232 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001233 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001234 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1235 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001236 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001237 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1238 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001239 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001240 }
Andres Moree269fc22013-02-12 20:36:29 -05001241 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001242 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1243 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001244 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001245 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001246 pvRTS = NULL;
1247 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001248 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1249 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001250 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001251 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001252 }
1253 } // Auto Fall Back
1254 }
1255
Andres Moreb902fbf2013-02-25 20:32:51 -05001256 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1257 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1258 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001259
Forest Bond92b96792009-06-13 07:38:31 -04001260 //=========================
1261 // No Fragmentation
1262 //=========================
1263 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1264 byFragType = FRAGCTL_NONFRAG;
1265 //uDMAIdx = TYPE_AC0DMA;
1266 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1267
Forest Bond92b96792009-06-13 07:38:31 -04001268 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001269 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1270 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001271 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1272 //Fill DataHead
1273 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001274 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001275 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001276 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001277 byFragType, uDMAIdx, 0);
1278
Andres More4e9b5e22013-02-12 20:36:30 -05001279 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001280 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001281 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001282 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001283
1284 if (pDevice->bEnableHostWEP) {
1285 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1286 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1287 }
1288 }
1289
1290 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001291 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001292 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001293 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1294 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001295 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001296 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001297 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001298 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001299 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001300 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001301 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001302 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001303 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001304
1305 }
1306
1307 }
1308
Forest Bond92b96792009-06-13 07:38:31 -04001309 if (pPacket != NULL) {
1310 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001311 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001312 (pPacket + ETH_HLEN),
1313 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001314 );
1315
1316 } else {
1317 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001318 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001319 }
1320
Andres More4e9b5e22013-02-12 20:36:30 -05001321 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001322
1323 ///////////////////////////////////////////////////////////////////
1324
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001325 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1326 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1327 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1328 }
Forest Bond92b96792009-06-13 07:38:31 -04001329 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001330 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1331 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001332 }
1333 else {
Andres More52a7e642013-02-25 20:32:53 -05001334 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1335 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001336 }
1337 // DO Software Michael
1338 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001339 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001340 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001341 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1343 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001344
1345 ///////////////////////////////////////////////////////////////////
1346
1347 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1348 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001349 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001350 //}
1351 //DBG_PRN_GRP12(("\n\n\n"));
1352
1353 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1354
Andres More52a7e642013-02-25 20:32:53 -05001355 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1356 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001357
1358 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1359 MIC_vUnInit();
1360
Andres More4e9b5e22013-02-12 20:36:30 -05001361 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001362 *pdwMIC_L = 0;
1363 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001364 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001365 }
1366 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1367 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1368 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1369 }
1370
Andres More4e9b5e22013-02-12 20:36:30 -05001371 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001372
Andres More3eaca0d2013-02-25 20:32:52 -05001373 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001374
Andres More4e9b5e22013-02-12 20:36:30 -05001375 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1376 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1377 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001378 cbFrameSize -= cbICVlen;
1379 }
1380
Forest Bond92b96792009-06-13 07:38:31 -04001381 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001382
1383 *pcbHeaderLen = cbHeaderLength;
1384 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1385
Forest Bond92b96792009-06-13 07:38:31 -04001386 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001387 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001388
Andres More4e9b5e22013-02-12 20:36:30 -05001389 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001390
1391}
1392
Forest Bond92b96792009-06-13 07:38:31 -04001393/*+
1394 *
1395 * Description:
1396 * Translate 802.3 to 802.11 header
1397 *
1398 * Parameters:
1399 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001400 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001401 * dwTxBufferAddr - Transmit Buffer
1402 * pPacket - Packet from upper layer
1403 * cbPacketSize - Transmit Data Length
1404 * Out:
1405 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1406 * pcbAppendPayload - size of append payload for 802.1H translation
1407 *
1408 * Return Value: none
1409 *
1410-*/
1411
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001412static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001413 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001414 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001415{
Andres More1cac4a42013-03-18 20:33:50 -05001416 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001417
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001418 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001419
1420 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001421 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001422 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001423 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001424 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1425 memcpy(&(pMACHeader->addr3[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 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001429 } else {
1430 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001431 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001432 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001433 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001434 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001435 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001436 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001437 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001438 &(pDevice->abyBSSID[0]),
1439 ETH_ALEN);
1440 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001441 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001442 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001443 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001444 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001445 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001446 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001447 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001448 &(pDevice->abyBSSID[0]),
1449 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001450 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001451 }
1452 }
1453
1454 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001455 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001456
Andres More1cac4a42013-03-18 20:33:50 -05001457 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001458
1459 if (pDevice->bLongHeader) {
1460 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001461 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001462 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001463 }
Andres More1cac4a42013-03-18 20:33:50 -05001464 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001465
1466 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001467 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001468
1469 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1470 pDevice->wSeqCounter++;
1471 if (pDevice->wSeqCounter > 0x0fff)
1472 pDevice->wSeqCounter = 0;
1473 }
1474
1475 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001476 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001477 }
1478}
1479
Forest Bond92b96792009-06-13 07:38:31 -04001480/*+
1481 *
1482 * Description:
1483 * Request instructs a MAC to transmit a 802.11 management packet through
1484 * the adapter onto the medium.
1485 *
1486 * Parameters:
1487 * In:
1488 * hDeviceContext - Pointer to the adapter
1489 * pPacket - A pointer to a descriptor for the packet to transmit
1490 * Out:
1491 * none
1492 *
Andres Moree269fc22013-02-12 20:36:29 -05001493 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001494 *
1495-*/
1496
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001497CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1498 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001499{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001500 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001501 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001502 PSTxBufHead pTxBufHead;
1503 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001504 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001505 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001506 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001507 u8 byPktType, *pbyTxBufferAddr;
1508 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1509 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001510 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001511 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1512 u32 uPadding = 0;
1513 u16 wTxBufSize;
1514 u32 cbMacHdLen;
1515 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001516
Forest Bond92b96792009-06-13 07:38:31 -04001517 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1518
1519 if (NULL == pContext) {
1520 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1521 return CMD_STATUS_RESOURCES;
1522 }
1523
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001524 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001525 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001526 cbFrameBodySize = pPacket->cbPayloadLen;
1527 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1528 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001529
1530 if (pDevice->byBBType == BB_TYPE_11A) {
1531 wCurrentRate = RATE_6M;
1532 byPktType = PK_TYPE_11A;
1533 } else {
1534 wCurrentRate = RATE_1M;
1535 byPktType = PK_TYPE_11B;
1536 }
1537
1538 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1539 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1540 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1541 // to set power here.
1542 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1543 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1544 } else {
1545 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1546 }
1547 pDevice->wCurrentRate = wCurrentRate;
1548
Forest Bond92b96792009-06-13 07:38:31 -04001549 //Set packet type
1550 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1551 pTxBufHead->wFIFOCtl = 0;
1552 }
1553 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1554 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1555 }
1556 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1557 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1558 }
1559 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1560 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1561 }
1562
1563 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1564 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1565
Andres More22040bb2010-08-02 20:21:44 -03001566 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001567 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001568 }
1569 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001570 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001571 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1572 };
1573
1574 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1575 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1576
1577 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1578 //Set Preamble type always long
1579 //pDevice->byPreambleType = PREAMBLE_LONG;
1580 // probe-response don't retry
1581 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001582 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001583 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1584 //}
1585 }
1586
1587 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1588
1589 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001590 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001591 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1592 } else {
1593 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1594 }
1595
1596 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001597 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001598
1599 // Notes:
1600 // Although spec says MMPDU can be fragmented; In most case,
1601 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001602 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001603
1604 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1605 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1606 cbIVlen = 4;
1607 cbICVlen = 4;
1608 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1609 }
1610 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1611 cbIVlen = 8;//IV+ExtIV
1612 cbMIClen = 8;
1613 cbICVlen = 4;
1614 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1615 //We need to get seed here for filling TxKey entry.
1616 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1617 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1618 }
1619 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1620 cbIVlen = 8;//RSN Header
1621 cbICVlen = 8;//MIC
1622 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001623 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001624 }
1625 //MAC Header should be padding 0 to DW alignment.
1626 uPadding = 4 - (cbMacHdLen%4);
1627 uPadding %= 4;
1628 }
1629
1630 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1631
1632 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001633 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001634 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1635 }
1636 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1637
1638 //Set RrvTime/RTS/CTS Buffer
1639 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1640
Malcolm Priestley4f990052013-08-16 23:38:57 +01001641 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001642 pMICHDR = NULL;
1643 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001644 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001645 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001646 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001647 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1648 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001649 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001650 }
1651 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001652 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001653 pMICHDR = NULL;
1654 pvRTS = NULL;
1655 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001656 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1657 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001658 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001659 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001660 }
1661
Andres Moreceb8c5d2013-03-18 20:33:49 -05001662 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001663 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1664 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001665 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001666 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1667 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001668 //=========================
1669 // No Fragmentation
1670 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001671 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001672
Forest Bond92b96792009-06-13 07:38:31 -04001673 //Fill FIFO,RrvTime,RTS,and CTS
1674 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1675 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1676
1677 //Fill DataHead
1678 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001679 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001680
Andres More1cac4a42013-03-18 20:33:50 -05001681 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001682
1683 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1684
1685 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001686 u8 * pbyIVHead;
1687 u8 * pbyPayloadHead;
1688 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001689 PSKeyItem pTransmitKey = NULL;
1690
Andres Moreb902fbf2013-02-25 20:32:51 -05001691 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1692 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001693 do {
1694 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001695 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001696 pbyBSSID = pDevice->abyBSSID;
1697 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001698 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001699 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001700 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001701 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1702 break;
1703 }
1704 } else {
1705 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1706 break;
1707 }
1708 }
1709 // get group key
1710 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001711 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001712 pTransmitKey = NULL;
1713 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1714 } else {
1715 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1716 }
Andres Moree269fc22013-02-12 20:36:29 -05001717 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001718 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001719 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001720 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001721
Jim Lieb3e362592009-08-12 14:54:11 -07001722 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001723 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001724 cbFrameBodySize);
1725 }
1726 else {
1727 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001728 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001729 }
1730
Andres More1cac4a42013-03-18 20:33:50 -05001731 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001732 pDevice->wSeqCounter++ ;
1733 if (pDevice->wSeqCounter > 0x0fff)
1734 pDevice->wSeqCounter = 0;
1735
1736 if (bIsPSPOLL) {
1737 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001738 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001739 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1740 // in the same place of other packet's Duration-field).
1741 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001742 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1743 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1744 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1745 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1746 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1747 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001748 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1749 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1750 }
Forest Bond92b96792009-06-13 07:38:31 -04001751 }
1752
Andres More3eaca0d2013-02-25 20:32:52 -05001753 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001754 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001755 pTX_Buffer->byType = 0x00;
1756
1757 pContext->pPacket = NULL;
1758 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001759 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001760
Andres More1cac4a42013-03-18 20:33:50 -05001761 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1762 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001763 }
1764 else {
Andres More1cac4a42013-03-18 20:33:50 -05001765 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001766 }
1767
1768 PIPEnsSendBulkOut(pDevice,pContext);
1769 return CMD_STATUS_PENDING;
1770}
1771
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001772CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1773 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001774{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001775 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001776 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1777 u32 cbHeaderSize = 0;
1778 u16 wTxBufSize = sizeof(STxShortBufHead);
1779 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001780 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001781 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001782 u16 wCurrentRate;
1783 u32 cbFrameBodySize;
1784 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001785 u8 *pbyTxBufferAddr;
1786 PUSB_SEND_CONTEXT pContext;
1787 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001788
Forest Bond92b96792009-06-13 07:38:31 -04001789 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1790 if (NULL == pContext) {
1791 status = CMD_STATUS_RESOURCES;
1792 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1793 return status ;
1794 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001795
1796 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001797 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001798
1799 cbFrameBodySize = pPacket->cbPayloadLen;
1800
1801 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1802 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001803
1804 if (pDevice->byBBType == BB_TYPE_11A) {
1805 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001806 pTxDataHead = (struct vnt_tx_datahead_ab *)
1807 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001808 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001809 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1810 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001811 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001812 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001813 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001814 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001815 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001816 } else {
1817 wCurrentRate = RATE_1M;
1818 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001819 pTxDataHead = (struct vnt_tx_datahead_ab *)
1820 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001821 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001822 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1823 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001824 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001825 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001826 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001827 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001828 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001829 }
1830
1831 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001832 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001833 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001834
Andres More1cac4a42013-03-18 20:33:50 -05001835 pMACHeader->duration_id = 0;
1836 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001837 pDevice->wSeqCounter++ ;
1838 if (pDevice->wSeqCounter > 0x0fff)
1839 pDevice->wSeqCounter = 0;
1840
1841 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1842
Andres More3eaca0d2013-02-25 20:32:52 -05001843 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001844 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001845 pTX_Buffer->byType = 0x01;
1846
1847 pContext->pPacket = NULL;
1848 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001849 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001850
1851 PIPEnsSendBulkOut(pDevice,pContext);
1852 return CMD_STATUS_PENDING;
1853
1854}
1855
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001856void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1857{
1858 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001859 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001860 u8 byPktType;
1861 u8 *pbyTxBufferAddr;
1862 void *pvRTS, *pvCTS, *pvTxDataHd;
1863 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001864 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001865 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001866 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001867 PSTxBufHead pTxBufHead;
1868 u32 cbFrameSize;
1869 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1870 u32 uPadding = 0;
1871 u32 cbMICHDR = 0, uLength = 0;
1872 u32 dwMICKey0, dwMICKey1;
1873 u32 dwMIC_Priority;
1874 u32 *pdwMIC_L, *pdwMIC_R;
1875 u16 wTxBufSize;
1876 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001877 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001878 void *pvRrvTime, *pMICHDR;
1879 u32 wCurrentRate = RATE_1M;
1880 PUWLAN_80211HDR p80211Header;
1881 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001882 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001883 SKeyItem STempKey;
1884 PSKeyItem pTransmitKey = NULL;
1885 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1886 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001887 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001888
Forest Bond92b96792009-06-13 07:38:31 -04001889 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1890
1891 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1892 cbFrameBodySize = 0;
1893 }
1894 else {
1895 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1896 }
1897 p80211Header = (PUWLAN_80211HDR)skb->data;
1898
1899 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1900
1901 if (NULL == pContext) {
1902 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1903 dev_kfree_skb_irq(skb);
1904 return ;
1905 }
1906
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001907 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001908 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001909 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1910 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001911
1912 if (pDevice->byBBType == BB_TYPE_11A) {
1913 wCurrentRate = RATE_6M;
1914 byPktType = PK_TYPE_11A;
1915 } else {
1916 wCurrentRate = RATE_1M;
1917 byPktType = PK_TYPE_11B;
1918 }
1919
1920 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1921 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1922 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1923 // to set power here.
1924 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1925 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1926 } else {
1927 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1928 }
1929
1930 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1931
1932 //Set packet type
1933 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1934 pTxBufHead->wFIFOCtl = 0;
1935 }
1936 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1937 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1938 }
1939 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1940 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1941 }
1942 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1943 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1944 }
1945
1946 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1947 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1948
Andres More22040bb2010-08-02 20:21:44 -03001949 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001950 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001951 if (pDevice->bEnableHostWEP) {
1952 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001953 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001954 }
Forest Bond92b96792009-06-13 07:38:31 -04001955 }
1956 else {
1957 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001958 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001959 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001960 }
Andres More4e9b5e22013-02-12 20:36:30 -05001961 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001962 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1963 };
1964
1965 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1966 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1967
1968 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1969 //Set Preamble type always long
1970 //pDevice->byPreambleType = PREAMBLE_LONG;
1971
1972 // probe-response don't retry
1973 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001974 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001975 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1976 //}
1977 }
1978
1979 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1980
1981 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001982 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001983 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1984 } else {
1985 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1986 }
1987
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001988 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001989 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1990
1991 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1992 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1993 }
1994
1995 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1996 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1997 }
1998
1999 if (cbExtSuppRate >0) {
2000 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2001 }
2002 }
2003
Forest Bond92b96792009-06-13 07:38:31 -04002004 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002005 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002006
2007 // Notes:
2008 // Although spec says MMPDU can be fragmented; In most case,
2009 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002010 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002011
Forest Bond92b96792009-06-13 07:38:31 -04002012 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2013 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2014 cbIVlen = 4;
2015 cbICVlen = 4;
2016 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2017 }
2018 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2019 cbIVlen = 8;//IV+ExtIV
2020 cbMIClen = 8;
2021 cbICVlen = 4;
2022 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2023 //We need to get seed here for filling TxKey entry.
2024 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2025 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2026 }
2027 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2028 cbIVlen = 8;//RSN Header
2029 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002030 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04002031 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002032 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002033 }
2034 //MAC Header should be padding 0 to DW alignment.
2035 uPadding = 4 - (cbMacHdLen%4);
2036 uPadding %= 4;
2037 }
2038
2039 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2040
2041 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002042 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002043 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2044 }
2045 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2046
Forest Bond92b96792009-06-13 07:38:31 -04002047 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002048 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002049 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002050 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002051 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002052 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002053 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002054 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2055 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002056 sizeof(struct vnt_cts));
2057 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002058 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002059
2060 }
2061 else {//802.11a/b packet
2062
Malcolm Priestley976467d2013-08-16 23:44:04 +01002063 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002064 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002065 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002066 pvRTS = NULL;
2067 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002068 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2069 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002070 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002071 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002072 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002073 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002074 &(p80211Header->sA3.abyAddr1[0]),
2075 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002076 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002077 &(p80211Header->sA3.abyAddr2[0]),
2078 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002079 //=========================
2080 // No Fragmentation
2081 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002082 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002083
Forest Bond92b96792009-06-13 07:38:31 -04002084 //Fill FIFO,RrvTime,RTS,and CTS
2085 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2086 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2087
2088 //Fill DataHead
2089 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002090 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002091
Andres More1cac4a42013-03-18 20:33:50 -05002092 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002093
2094 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2095
Andres Moreb902fbf2013-02-25 20:32:51 -05002096 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2097 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2098 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002099
2100 // Copy the Packet into a tx Buffer
2101 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2102
2103 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002104 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002105 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2106
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002107 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002108 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2109 if (cbExtSuppRate != 0) {
2110 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2111 memcpy((pbyPayloadHead + cbFrameBodySize),
2112 pMgmt->abyCurrSuppRates,
2113 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2114 );
2115 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2116 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2117 pMgmt->abyCurrExtSuppRates,
2118 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2119 );
2120 }
2121 }
2122
2123 // Set wep
2124 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2125
2126 if (pDevice->bEnableHostWEP) {
2127 pTransmitKey = &STempKey;
2128 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2129 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2130 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2131 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2132 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2133 memcpy(pTransmitKey->abyKey,
2134 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2135 pTransmitKey->uKeyLength
2136 );
2137 }
2138
2139 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2140
Andres More52a7e642013-02-25 20:32:53 -05002141 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2142 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002143
2144 // DO Software Michael
2145 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002146 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002147 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002148 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2150 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002151
2152 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2153
2154 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2155
Andres More52a7e642013-02-25 20:32:53 -05002156 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2157 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002158
2159 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2160 MIC_vUnInit();
2161
Andres More4e9b5e22013-02-12 20:36:30 -05002162 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002163 *pdwMIC_L = 0;
2164 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002165 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002166 }
2167
2168 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002170 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2171 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002172
2173 }
2174
Andres Moreb902fbf2013-02-25 20:32:51 -05002175 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002176 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002177
2178 if (pDevice->bEnableHostWEP) {
2179 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2180 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2181 }
2182
2183 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002184 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002185 }
2186 }
2187
Andres More1cac4a42013-03-18 20:33:50 -05002188 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002189 pDevice->wSeqCounter++ ;
2190 if (pDevice->wSeqCounter > 0x0fff)
2191 pDevice->wSeqCounter = 0;
2192
Forest Bond92b96792009-06-13 07:38:31 -04002193 if (bIsPSPOLL) {
2194 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2195 // of FIFO control header.
2196 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2197 // in the same place of other packet's Duration-field).
2198 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002199 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2200 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2201 cpu_to_le16(p80211Header->sA2.wDurationID);
2202 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2203 cpu_to_le16(p80211Header->sA2.wDurationID);
2204 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002205 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2206 cpu_to_le16(p80211Header->sA2.wDurationID);
2207 }
Forest Bond92b96792009-06-13 07:38:31 -04002208 }
2209
Andres More3eaca0d2013-02-25 20:32:52 -05002210 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002211 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002212 pTX_Buffer->byType = 0x00;
2213
2214 pContext->pPacket = skb;
2215 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002216 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002217
Andres More1cac4a42013-03-18 20:33:50 -05002218 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2219 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002220 }
2221 else {
Andres More1cac4a42013-03-18 20:33:50 -05002222 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002223 }
2224 PIPEnsSendBulkOut(pDevice,pContext);
2225 return ;
2226
2227}
2228
Forest Bond92b96792009-06-13 07:38:31 -04002229//TYPE_AC0DMA data tx
2230/*
2231 * Description:
2232 * Tx packet via AC0DMA(DMA1)
2233 *
2234 * Parameters:
2235 * In:
2236 * pDevice - Pointer to the adapter
2237 * skb - Pointer to tx skb packet
2238 * Out:
2239 * void
2240 *
2241 * Return Value: NULL
2242 */
2243
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002244int nsDMA_tx_packet(struct vnt_private *pDevice,
2245 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002246{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002247 struct net_device_stats *pStats = &pDevice->stats;
2248 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002249 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002250 u32 BytesToWrite = 0, uHeaderLen = 0;
2251 u32 uNodeIndex = 0;
2252 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2253 u16 wAID;
2254 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002255 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002256 PSKeyItem pTransmitKey = NULL;
2257 SKeyItem STempKey;
2258 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002259 int bTKIP_UseGTK = false;
2260 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002261 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002262 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002263 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002264 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002265 u32 status;
2266 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002267 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002268
Forest Bond92b96792009-06-13 07:38:31 -04002269 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2270
2271 if (pDevice->uAssocCount == 0) {
2272 dev_kfree_skb_irq(skb);
2273 return 0;
2274 }
2275
Andres Moreb902fbf2013-02-25 20:32:51 -05002276 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002277 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002278 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002279 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2280
2281 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2282 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2283 // set tx map
2284 pMgmt->abyPSTxMap[0] |= byMask[0];
2285 return 0;
2286 }
Masanari Iida93184692012-08-13 21:21:50 +09002287 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002288
2289 if (pDevice->byBBType != BB_TYPE_11A)
2290 pDevice->wCurrentRate = RATE_2M;
2291 else
2292 pDevice->wCurrentRate = RATE_24M;
2293 // long preamble type
2294 pDevice->byPreambleType = PREAMBLE_SHORT;
2295
2296 }else {
2297
Andres Moreb902fbf2013-02-25 20:32:51 -05002298 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002299
2300 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2301
2302 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2303
2304 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2305 // set tx map
2306 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2307 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2308 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2309 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2310
2311 return 0;
2312 }
2313 // AP rate decided from node
2314 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2315 // tx preamble decided from node
2316
2317 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2318 pDevice->byPreambleType = pDevice->byShortPreamble;
2319
2320 }else {
2321 pDevice->byPreambleType = PREAMBLE_LONG;
2322 }
Andres More4e9b5e22013-02-12 20:36:30 -05002323 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002324 }
2325 }
2326
Andres Moree269fc22013-02-12 20:36:29 -05002327 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002328 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2329 dev_kfree_skb_irq(skb);
2330 return 0;
2331 }
2332 }
2333
2334 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2335
2336 if (pContext == NULL) {
2337 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2338 dev_kfree_skb_irq(skb);
2339 return STATUS_RESOURCES;
2340 }
2341
Andres Moreceb8c5d2013-03-18 20:33:49 -05002342 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002343
2344//mike add:station mode check eapol-key challenge--->
2345{
Andres Moreb902fbf2013-02-25 20:32:51 -05002346 u8 Protocol_Version; //802.1x Authentication
2347 u8 Packet_Type; //802.1x Authentication
2348 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002349 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002350
Charles Clément21ec51f2010-05-18 10:08:14 -07002351 Protocol_Version = skb->data[ETH_HLEN];
2352 Packet_Type = skb->data[ETH_HLEN+1];
2353 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2354 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 -05002355 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002356 /* 802.1x OR eapol-key challenge frame transfer */
2357 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2358 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002359 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002360 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2361 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2362 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002363 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002364 PRINT_K("WPA ");
2365 }
2366 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002367 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002368 PRINT_K("WPA2(re-keying) ");
2369 }
2370 PRINT_K("Authentication completed!!\n");
2371 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002372 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002373 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002374 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002375 PRINT_K("WPA2 Authentication completed!!\n");
2376 }
2377 }
2378 }
2379}
2380//mike add:station mode check eapol-key challenge<---
2381
Andres More4e9b5e22013-02-12 20:36:30 -05002382 if (pDevice->bEncryptionEnable == true) {
2383 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002384 // get Transmit key
2385 do {
2386 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2387 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2388 pbyBSSID = pDevice->abyBSSID;
2389 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002390 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002391 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002392 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2393 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002394 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2395 break;
2396 }
2397 } else {
2398 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2399 break;
2400 }
2401 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002402 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2403 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2405 for (ii = 0; ii< 6; ii++)
2406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2407 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2408
2409 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002410 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002411 break;
2412 }
2413 // get group key
2414 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002415 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002416 pTransmitKey = NULL;
2417 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2418 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2419 }
2420 else
2421 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2422 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002423 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002424 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2425 }
Andres Moree269fc22013-02-12 20:36:29 -05002426 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002427 }
2428
2429 if (pDevice->bEnableHostWEP) {
2430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002431 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002432 pTransmitKey = &STempKey;
2433 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2434 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2435 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2436 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2437 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2438 memcpy(pTransmitKey->abyKey,
2439 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2440 pTransmitKey->uKeyLength
2441 );
2442 }
2443 }
2444
Andres Moreb902fbf2013-02-25 20:32:51 -05002445 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002446
2447 if (pDevice->bFixRate) {
2448 if (pDevice->byBBType == BB_TYPE_11B) {
2449 if (pDevice->uConnectionRate >= RATE_11M) {
2450 pDevice->wCurrentRate = RATE_11M;
2451 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002452 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002453 }
2454 } else {
2455 if ((pDevice->byBBType == BB_TYPE_11A) &&
2456 (pDevice->uConnectionRate <= RATE_6M)) {
2457 pDevice->wCurrentRate = RATE_6M;
2458 } else {
2459 if (pDevice->uConnectionRate >= RATE_54M)
2460 pDevice->wCurrentRate = RATE_54M;
2461 else
Andres More3eaca0d2013-02-25 20:32:52 -05002462 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002463 }
2464 }
2465 }
2466 else {
2467 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2468 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002469 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002470 // Multicast use highest data rate
2471 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2472 // preamble type
2473 pDevice->byPreambleType = pDevice->byShortPreamble;
2474 }
2475 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002476 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002477 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2478 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2479 pDevice->byPreambleType = pDevice->byShortPreamble;
2480
2481 }
2482 else {
2483 pDevice->byPreambleType = PREAMBLE_LONG;
2484 }
2485 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2486 }
2487 else {
2488 if (pDevice->byBBType != BB_TYPE_11A)
2489 pDevice->wCurrentRate = RATE_2M;
2490 else
2491 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2492 // abyCurrExtSuppRates[]
2493 pDevice->byPreambleType = PREAMBLE_SHORT;
2494 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2495 }
2496 }
2497 }
2498 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2499 // Infra STA rate decided from AP Node, index = 0
2500 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2501 }
2502 }
2503
Andres Moreceb8c5d2013-03-18 20:33:49 -05002504 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002505 if (pDevice->byBBType != BB_TYPE_11A) {
2506 pDevice->wCurrentRate = RATE_1M;
2507 pDevice->byACKRate = RATE_1M;
2508 pDevice->byTopCCKBasicRate = RATE_1M;
2509 pDevice->byTopOFDMBasicRate = RATE_6M;
2510 } else {
2511 pDevice->wCurrentRate = RATE_6M;
2512 pDevice->byACKRate = RATE_6M;
2513 pDevice->byTopCCKBasicRate = RATE_1M;
2514 pDevice->byTopOFDMBasicRate = RATE_6M;
2515 }
2516 }
Forest Bond92b96792009-06-13 07:38:31 -04002517
Andres More0cbd8d92010-05-06 20:34:29 -03002518 DBG_PRT(MSG_LEVEL_DEBUG,
2519 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2520 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002521
2522 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002523 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002524 }
2525
2526 if (pDevice->wCurrentRate <= RATE_11M) {
2527 byPktType = PK_TYPE_11B;
2528 }
2529
Andres More4e9b5e22013-02-12 20:36:30 -05002530 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002531 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2532 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002533 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002534 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002535 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2536 if (pTransmitKey == NULL) {
2537 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2538 }
2539 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002540 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002541 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2542 }
2543 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2545 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002546 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002547 }
2548 }
2549 }
2550
Forest Bond92b96792009-06-13 07:38:31 -04002551 if (pDevice->bEnableHostWEP) {
2552 if ((uNodeIndex != 0) &&
2553 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002554 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2555 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002556 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002557 }
2558 }
2559 }
2560 else {
2561
Forest Bond92b96792009-06-13 07:38:31 -04002562 if (pTransmitKey == NULL) {
2563 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002564 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002565 dev_kfree_skb_irq(skb);
2566 pStats->tx_dropped++;
2567 return STATUS_FAILURE;
2568 }
Forest Bond92b96792009-06-13 07:38:31 -04002569 }
2570 }
2571
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002572 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2573
Forest Bond92b96792009-06-13 07:38:31 -04002574 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002575 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002576 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002577 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002578 pDevice->wCurrentRate,
2579 &uHeaderLen, &BytesToWrite
2580 );
2581
Andres Moree269fc22013-02-12 20:36:29 -05002582 if (fConvertedPacket == false) {
2583 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002584 dev_kfree_skb_irq(skb);
2585 return STATUS_FAILURE;
2586 }
2587
Andres More4e9b5e22013-02-12 20:36:30 -05002588 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002589 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002590 bScheduleCommand((void *) pDevice,
2591 WLAN_CMD_MAC_DISPOWERSAVING,
2592 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002593 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002594 }
2595 }
2596
Andres Moreb902fbf2013-02-25 20:32:51 -05002597 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002598 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002599
2600 pContext->pPacket = skb;
2601 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002602 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002603
Andres Moreceb8c5d2013-03-18 20:33:49 -05002604 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 -04002605
2606 status = PIPEnsSendBulkOut(pDevice,pContext);
2607
Andres More4e9b5e22013-02-12 20:36:30 -05002608 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002609 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002610
Andres Moreb902fbf2013-02-25 20:32:51 -05002611 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002612 }
2613
2614 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002615 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002616 dev_kfree_skb_irq(skb);
2617 return STATUS_FAILURE;
2618 }
2619 else
2620 return 0;
2621
2622}
2623
Forest Bond92b96792009-06-13 07:38:31 -04002624/*
2625 * Description:
2626 * Relay packet send (AC1DMA) from rx dpc.
2627 *
2628 * Parameters:
2629 * In:
2630 * pDevice - Pointer to the adapter
2631 * pPacket - Pointer to rx packet
2632 * cbPacketSize - rx ethernet frame size
2633 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002634 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002635 *
Andres More4e9b5e22013-02-12 20:36:30 -05002636 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002637 */
2638
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002639int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2640 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002641{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002642 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002643 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002644 u32 BytesToWrite = 0, uHeaderLen = 0;
2645 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002646 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002647 SKeyItem STempKey;
2648 PSKeyItem pTransmitKey = NULL;
2649 u8 *pbyBSSID;
2650 PUSB_SEND_CONTEXT pContext;
2651 u8 byPktTyp;
2652 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002653 u32 status;
2654 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002655
Forest Bond92b96792009-06-13 07:38:31 -04002656 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2657
2658 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002659 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002660 }
2661
Andres Moreceb8c5d2013-03-18 20:33:49 -05002662 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002663
Andres More4e9b5e22013-02-12 20:36:30 -05002664 if (pDevice->bEncryptionEnable == true) {
2665 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002666 // get group key
2667 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002668 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002669 pTransmitKey = NULL;
2670 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2671 } else {
2672 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2673 }
2674 }
2675
2676 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002677 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002678 pTransmitKey = &STempKey;
2679 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2680 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2681 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2682 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2683 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2684 memcpy(pTransmitKey->abyKey,
2685 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2686 pTransmitKey->uKeyLength
2687 );
2688 }
2689 }
2690
2691 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002692 pContext->bBoolInUse = false;
2693 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002694 }
2695
Andres Moreb902fbf2013-02-25 20:32:51 -05002696 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002697
2698 if (pDevice->bFixRate) {
2699 if (pDevice->byBBType == BB_TYPE_11B) {
2700 if (pDevice->uConnectionRate >= RATE_11M) {
2701 pDevice->wCurrentRate = RATE_11M;
2702 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002703 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002704 }
2705 } else {
2706 if ((pDevice->byBBType == BB_TYPE_11A) &&
2707 (pDevice->uConnectionRate <= RATE_6M)) {
2708 pDevice->wCurrentRate = RATE_6M;
2709 } else {
2710 if (pDevice->uConnectionRate >= RATE_54M)
2711 pDevice->wCurrentRate = RATE_54M;
2712 else
Andres More3eaca0d2013-02-25 20:32:52 -05002713 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002714 }
2715 }
2716 }
2717 else {
2718 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2719 }
2720
Forest Bond92b96792009-06-13 07:38:31 -04002721 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002722 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002723 }
2724
2725 if (pDevice->wCurrentRate <= RATE_11M)
2726 byPktType = PK_TYPE_11B;
2727
Andres Moreabad19d2010-07-12 16:28:32 -03002728 BytesToWrite = uDataLen + ETH_FCS_LEN;
2729
Forest Bond92b96792009-06-13 07:38:31 -04002730 // Convert the packet to an usb frame and copy into our buffer
2731 // and send the irp.
2732
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002733 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2734
Forest Bond92b96792009-06-13 07:38:31 -04002735 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002736 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002737 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2738 pbySkbData, pTransmitKey, uNodeIndex,
2739 pDevice->wCurrentRate,
2740 &uHeaderLen, &BytesToWrite
2741 );
2742
Andres Moree269fc22013-02-12 20:36:29 -05002743 if (fConvertedPacket == false) {
2744 pContext->bBoolInUse = false;
2745 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002746 }
2747
Andres Moreb902fbf2013-02-25 20:32:51 -05002748 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002749 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002750
2751 pContext->pPacket = NULL;
2752 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002753 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002754
Andres Moreceb8c5d2013-03-18 20:33:49 -05002755 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 -04002756
2757 status = PIPEnsSendBulkOut(pDevice,pContext);
2758
Andres More4e9b5e22013-02-12 20:36:30 -05002759 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002760}
2761