blob: 54aa5763410433b54f433884ffb12d9fa773e132 [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,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100103 void *rts_cts, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100104 struct ethhdr *psEthHeader, bool need_rts);
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,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100128 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
129 int bNeedAck, 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 Priestley5fb8e412013-08-27 12:07:58 +0100132 union vnt_tx_data_head *head, 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
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100193 /* Fill TXKEY */
194 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100195 return;
Forest Bond92b96792009-06-13 07:38:31 -0400196
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100197 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
198 *pdwIV = pDevice->dwIVCounter;
199 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400200
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100201 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
202 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
203 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
204 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
205 pTransmitKey->uKeyLength);
206 } else {
207 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
208 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
209 pTransmitKey->uKeyLength);
210 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
211 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
212 memcpy(pbyBuf+11, pTransmitKey->abyKey,
213 pTransmitKey->uKeyLength);
214 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100215
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100216 memcpy(pDevice->abyPRNG, pbyBuf, 16);
217 }
218 /* Append IV after Mac Header */
219 *pdwIV &= WEP_IV_MASK;
220 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
221 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100222
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100223 pDevice->dwIVCounter++;
224 if (pDevice->dwIVCounter > WEP_IV_MASK)
225 pDevice->dwIVCounter = 0;
226 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
227 pTransmitKey->wTSC15_0++;
228 if (pTransmitKey->wTSC15_0 == 0)
229 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100230
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100231 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
232 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
233 pDevice->abyPRNG);
234 memcpy(pbyBuf, pDevice->abyPRNG, 16);
235
236 /* Make IV */
237 memcpy(pdwIV, pDevice->abyPRNG, 3);
238
239 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
240 0xc0) | 0x20);
241 /* Append IV&ExtIV after Mac Header */
242 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
243
244 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
245 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
246
247 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
248 pTransmitKey->wTSC15_0++;
249 if (pTransmitKey->wTSC15_0 == 0)
250 pTransmitKey->dwTSC47_16++;
251
252 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
253
254 /* Make IV */
255 *pdwIV = 0;
256 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
257 0xc0) | 0x20);
258
259 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
260
261 /* Append IV&ExtIV after Mac Header */
262 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
263
264 if (!mic_hdr)
265 return;
266
267 /* MICHDR0 */
268 mic_hdr->id = 0x59;
269 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
270 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
271
272 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
273 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
274
275 /* MICHDR1 */
276 if (pDevice->bLongHeader)
277 mic_hdr->hlen = cpu_to_be16(28);
278 else
279 mic_hdr->hlen = cpu_to_be16(22);
280
281 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
282 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
283
284 /* MICHDR2 */
285 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
286 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100287 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100288 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100289
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100290 if (pDevice->bLongHeader)
291 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
292 }
Forest Bond92b96792009-06-13 07:38:31 -0400293}
294
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000295static void s_vSWencryption(struct vnt_private *pDevice,
296 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400297{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000298 u32 cbICVlen = 4;
299 u32 dwICV = 0xffffffff;
300 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400301
302 if (pTransmitKey == NULL)
303 return;
304
305 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
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, pTransmitKey->uKeyLength + 3);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
317 //=======================================================================
318 //Append ICV after payload
319 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500320 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400321 // finally, we must invert dwCRC to get the correct answer
322 *pdwICV = cpu_to_le32(~dwICV);
323 // RC4 encryption
324 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
325 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
326 //=======================================================================
327 }
328}
329
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100330static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
331{
332 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
333 [rate % MAX_RATE]);
334}
335
Forest Bond92b96792009-06-13 07:38:31 -0400336/*byPktType : PK_TYPE_11A 0
337 PK_TYPE_11B 1
338 PK_TYPE_11GB 2
339 PK_TYPE_11GA 3
340*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000341static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
342 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400343{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000344 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400345
346 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
347 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500348 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400349 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500350 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400351 }
352
353 if (bNeedAck) {
354 return (uDataTime + pDevice->uSIFS + uAckTime);
355 }
356 else {
357 return uDataTime;
358 }
359}
360
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100361static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
362 u32 frame_length, u16 rate, int need_ack)
363{
364 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
365 frame_length, rate, need_ack));
366}
367
Forest Bond92b96792009-06-13 07:38:31 -0400368//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100369static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000370 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400371{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000372 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400373
374 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
375
Forest Bond92b96792009-06-13 07:38:31 -0400376 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
377 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
378 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
379 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
380 }
381 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
382 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
383 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
384 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
385 }
386 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
387 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
388 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
389 }
390 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
391 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
392 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
393 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
394 return uRrvTime;
395 }
396
397 //RTSRrvTime
398 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100399 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400400}
401
402//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100403static u16 s_uGetDataDuration(struct vnt_private *pDevice,
404 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400405{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100406 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400407
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100408 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100409 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100410 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
411 byPktType, 14, pDevice->byTopCCKBasicRate);
412 else
413 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
414 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100415 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100416 }
Forest Bond92b96792009-06-13 07:38:31 -0400417
Forest Bond92b96792009-06-13 07:38:31 -0400418 return 0;
419}
420
Forest Bond92b96792009-06-13 07:38:31 -0400421//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100422static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000423 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
424 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400425{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000426 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400427
Forest Bond92b96792009-06-13 07:38:31 -0400428 switch (byDurType) {
429
430 case RTSDUR_BB: //RTSDuration_bb
431 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
432 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
433 break;
434
435 case RTSDUR_BA: //RTSDuration_ba
436 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
437 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
438 break;
439
440 case RTSDUR_AA: //RTSDuration_aa
441 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
442 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
443 break;
444
445 case CTSDUR_BA: //CTSDuration_ba
446 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
447 break;
448
449 case RTSDUR_BA_F0: //RTSDuration_ba_f0
450 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
451 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
452 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
453 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
454 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
455 }
456 break;
457
458 case RTSDUR_AA_F0: //RTSDuration_aa_f0
459 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
460 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
461 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
462 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
463 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
464 }
465 break;
466
467 case RTSDUR_BA_F1: //RTSDuration_ba_f1
468 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
469 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
470 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
471 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
472 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
473 }
474 break;
475
476 case RTSDUR_AA_F1: //RTSDuration_aa_f1
477 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
478 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
479 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
480 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
481 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
482 }
483 break;
484
485 case CTSDUR_BA_F0: //CTSDuration_ba_f0
486 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
487 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
488 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
489 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
490 }
491 break;
492
493 case CTSDUR_BA_F1: //CTSDuration_ba_f1
494 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
495 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
496 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
497 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
498 }
499 break;
500
501 default:
502 break;
503 }
504
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100505 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400506}
507
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000508static u32 s_uFillDataHead(struct vnt_private *pDevice,
509 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100510 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400511{
512
513 if (pTxDataHead == NULL) {
514 return 0;
515 }
516
517 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Forest Bond92b96792009-06-13 07:38:31 -0400518 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100519 struct vnt_tx_datahead_g *pBuf =
520 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400521 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100522 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
523 byPktType, &pBuf->a);
524 BBvCalculateParameter(pDevice, cbFrameLength,
525 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400526 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100527 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100528 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100529 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100530 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400531
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100532 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
533 wCurrentRate);
534 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
535 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400536 return (pBuf->wDuration_a);
537 } else {
538 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100539 struct vnt_tx_datahead_g_fb *pBuf =
540 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400541 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100542 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
543 byPktType, &pBuf->a);
544 BBvCalculateParameter(pDevice, cbFrameLength,
545 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400546 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100547 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100548 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100549 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100550 PK_TYPE_11B, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100551 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100552 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100553 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100554 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100555 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
556 wCurrentRate);
557 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
558 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400559 return (pBuf->wDuration_a);
560 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400561 }
562 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100563 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100564 struct vnt_tx_datahead_a_fb *pBuf =
565 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400566 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100567 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
568 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400569 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100570 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100571 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100572 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100573 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100574 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100575 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100576 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
577 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400578 return (pBuf->wDuration);
579 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100580 struct vnt_tx_datahead_ab *pBuf =
581 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400582 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100583 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
584 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400585 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100586 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100587 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100588 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
589 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400590 return (pBuf->wDuration);
591 }
592 }
593 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100594 struct vnt_tx_datahead_ab *pBuf =
595 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400596 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100597 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
598 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400599 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100600 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100601 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100602 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
603 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400604 return (pBuf->wDuration);
605 }
606 return 0;
607}
608
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100609static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
610 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
611 u16 duration)
612{
613 rts->duration = duration;
614 rts->frame_control = TYPE_CTL_RTS;
615
616 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
617 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
618 else
619 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
620
621 if (priv->eOPMode == OP_MODE_AP)
622 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
623 else
624 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
625
626 return 0;
627}
628
629static int vnt_rxtx_rts_g_head(struct vnt_private *priv,
630 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
631 u8 pkt_type, u32 frame_len, int need_ack,
632 u16 current_rate, u8 fb_option)
633{
634 u16 rts_frame_len = 20;
635
636 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
637 PK_TYPE_11B, &buf->b);
638 BBvCalculateParameter(priv, rts_frame_len,
639 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
640
641 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
642 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
643 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
644 pkt_type, current_rate, need_ack, fb_option);
645 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
646 pkt_type, current_rate, need_ack, fb_option);
647
648 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
649
650 return 0;
651}
652
Malcolm Priestleyec917132013-08-26 11:07:46 +0100653static int vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
654 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
655 u8 pkt_type, u32 frame_len, int need_ack,
656 u16 current_rate, u8 fb_option)
657{
658 u16 rts_frame_len = 20;
659
660 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
661 PK_TYPE_11B, &buf->b);
662 BBvCalculateParameter(priv, rts_frame_len,
663 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
664
665
666 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
667 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
668 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
669 pkt_type, current_rate, need_ack, fb_option);
670 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
671 pkt_type, current_rate, need_ack, fb_option);
672
673
674 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
675 frame_len, pkt_type, current_rate, need_ack, fb_option);
676 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
677 frame_len, pkt_type, current_rate, need_ack, fb_option);
678 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
679 frame_len, pkt_type, current_rate, need_ack, fb_option);
680 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
681 frame_len, pkt_type, current_rate, need_ack, fb_option);
682
683 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
684
685 return 0;
686}
687
Malcolm Priestley17126332013-08-26 11:09:38 +0100688static int vnt_rxtx_rts_ab_head(struct vnt_private *priv,
689 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
690 u8 pkt_type, u32 frame_len, int need_ack,
691 u16 current_rate, u8 fb_option)
692{
693 u16 rts_frame_len = 20;
694
695 BBvCalculateParameter(priv, rts_frame_len,
696 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
697
698 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
699 pkt_type, current_rate, need_ack, fb_option);
700
701 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
702
703 return 0;
704}
705
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100706static int vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
707 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
708 u8 pkt_type, u32 frame_len, int need_ack,
709 u16 current_rate, u8 fb_option)
710{
711 u16 rts_frame_len = 20;
712
713 BBvCalculateParameter(priv, rts_frame_len,
714 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
715
716 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
717 pkt_type, current_rate, need_ack, fb_option);
718
719 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
720 frame_len, pkt_type, current_rate, need_ack, fb_option);
721
722 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
723 frame_len, pkt_type, current_rate, need_ack, fb_option);
724
725 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
726
727 return 0;
728}
729
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000730static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100731 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500732 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400733{
Forest Bond92b96792009-06-13 07:38:31 -0400734
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100735 if (!head)
736 return;
Forest Bond92b96792009-06-13 07:38:31 -0400737
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100738 /* Note: So far RTSHead doesn't appear in ATIM
739 * & Beacom DMA, so we don't need to take them
740 * into account.
741 * Otherwise, we need to modified codes for them.
742 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100743 switch (byPktType) {
744 case PK_TYPE_11GB:
745 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100746 if (byFBOption == AUTO_FB_NONE)
747 vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100748 psEthHeader, byPktType, cbFrameLength,
749 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100750 else
751 vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100752 psEthHeader, byPktType, cbFrameLength,
753 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100754 break;
755 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100756 if (byFBOption) {
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100757 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
758 psEthHeader, byPktType, cbFrameLength,
759 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100760 break;
761 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100762 case PK_TYPE_11B:
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100763 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100764 psEthHeader, byPktType, cbFrameLength,
765 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100766 }
Forest Bond92b96792009-06-13 07:38:31 -0400767}
768
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000769static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100770 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
771 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400772{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000773 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400774
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100775 if (!head)
776 return;
Forest Bond92b96792009-06-13 07:38:31 -0400777
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100778 if (byFBOption != AUTO_FB_NONE) {
779 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100780 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100781 /* Get SignalField,ServiceField,Length */
782 BBvCalculateParameter(pDevice, uCTSFrameLen,
783 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100784 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
785 cbFrameLength, byPktType,
786 wCurrentRate, bNeedAck, byFBOption);
787 /* Get CTSDuration_ba_f0 */
788 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
789 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
790 bNeedAck, byFBOption);
791 /* Get CTSDuration_ba_f1 */
792 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
793 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
794 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100795 /* Get CTS Frame body */
796 pBuf->data.duration = pBuf->wDuration_ba;
797 pBuf->data.frame_control = TYPE_CTL_CTS;
798 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100799 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100800 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100801 /* Get SignalField,ServiceField,Length */
802 BBvCalculateParameter(pDevice, uCTSFrameLen,
803 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100804 /* Get CTSDuration_ba */
805 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
806 CTSDUR_BA, cbFrameLength, byPktType,
807 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100808 /*Get CTS Frame body*/
809 pBuf->data.duration = pBuf->wDuration_ba;
810 pBuf->data.frame_control = TYPE_CTL_CTS;
811 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400812 }
Forest Bond92b96792009-06-13 07:38:31 -0400813}
814
Forest Bond92b96792009-06-13 07:38:31 -0400815/*+
816 *
817 * Description:
818 * Generate FIFO control for MAC & Baseband controller
819 *
820 * Parameters:
821 * In:
822 * pDevice - Pointer to adpater
823 * pTxDataHead - Transmit Data Buffer
824 * pTxBufHead - pTxBufHead
825 * pvRrvTime - pvRrvTime
826 * pvRTS - RTS Buffer
827 * pCTS - CTS Buffer
828 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
829 * bNeedACK - If need ACK
830 * uDMAIdx - DMA Index
831 * Out:
832 * none
833 *
834 * Return Value: none
835 *
836-*/
Andres Morecc856e62010-05-17 21:34:01 -0300837
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000838static void s_vGenerateTxParameter(struct vnt_private *pDevice,
839 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100840 void *rts_cts, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100841 struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400842{
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100843 union vnt_tx_data_head *head = rts_cts;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000844 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
845 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000846 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400847
848 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
849 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
850 pFifoHead->wReserved = wCurrentRate;
851 wFifoCtl = pFifoHead->wFIFOCtl;
852
Forest Bond92b96792009-06-13 07:38:31 -0400853 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
854 byFBOption = AUTO_FB_0;
855 }
856 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
857 byFBOption = AUTO_FB_1;
858 }
859
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100860 if (!pvRrvTime)
861 return;
862
Forest Bond92b96792009-06-13 07:38:31 -0400863 if (pDevice->bLongHeader)
864 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
865
866 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100867 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400868 //Fill RsvTime
Malcolm Priestley6398a592013-08-16 21:26:55 +0100869 struct vnt_rrv_time_rts *pBuf =
870 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100871 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
872 byPktType, cbFrameSize, wCurrentRate);
873 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
874 byPktType, cbFrameSize, wCurrentRate);
875 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
876 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100877 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
878 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
879 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
880 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
881 bNeedACK);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100882 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100883 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100884 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400885 }
886 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400887 //Fill RsvTime
Malcolm Priestley4f990052013-08-16 23:38:57 +0100888 struct vnt_rrv_time_cts *pBuf =
889 (struct vnt_rrv_time_cts *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100890 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
891 cbFrameSize, wCurrentRate, bNeedACK);
892 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
893 PK_TYPE_11B, cbFrameSize,
894 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100895 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
896 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100897 /* Fill CTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100898 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, head,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100899 cbFrameSize, bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400900 }
901 }
902 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100903 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400904 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100905 struct vnt_rrv_time_ab *pBuf =
906 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100907 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
908 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100909 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
910 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100911 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100912 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100913 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100914 } else {
Forest Bond92b96792009-06-13 07:38:31 -0400915 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100916 struct vnt_rrv_time_ab *pBuf =
917 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100918 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
919 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400920 }
921 }
922 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100923 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400924 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100925 struct vnt_rrv_time_ab *pBuf =
926 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100927 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
928 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100929 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
930 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100931 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100932 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100933 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400934 }
935 else { //RTS_needless, non PCF mode
936 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100937 struct vnt_rrv_time_ab *pBuf =
938 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100939 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
940 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400941 }
942 }
943 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
944}
945/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500946 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500947 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300948 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400949*/
950
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000951static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100952 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
953 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
954 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
955 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400956{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000957 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
958 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000959 u32 cb802_1_H_len;
960 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
961 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100962 int bNeedACK;
963 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000964 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
965 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
966 u8 abySNAP_Bridgetunnel[ETH_ALEN]
967 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
968 u32 uDuration;
969 u32 cbHeaderLength = 0, uPadding = 0;
970 void *pvRrvTime;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100971 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100972 void *rts_cts = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000973 void *pvTxDataHd;
974 u8 byFBOption = AUTO_FB_NONE, byFragType;
975 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100976 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000977 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500978 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -0400979
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100980 pvRrvTime = pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400981
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000982 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500983 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
984 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000985 }
Forest Bond92b96792009-06-13 07:38:31 -0400986
Forest Bond92b96792009-06-13 07:38:31 -0400987 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -0500988 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -0400989 if (pDevice->dwDiagRefCount == 0) {
990 cb802_1_H_len = 8;
991 } else {
992 cb802_1_H_len = 2;
993 }
994 } else {
995 cb802_1_H_len = 0;
996 }
997
Charles Clément21ec51f2010-05-18 10:08:14 -0700998 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400999
1000 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001001 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001002
1003 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001004 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001005 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1006 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001007 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1008 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001009 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001010 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001011 pTxBufHead->wFIFOCtl =
1012 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1013 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001014 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001015 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1016 }
Forest Bond92b96792009-06-13 07:38:31 -04001017 }
1018 else {
1019 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001020 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001021 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1022 }
1023 } //if (pDevice->dwDiagRefCount != 0) {
1024
1025 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1026
1027 //Set FIFOCTL_LHEAD
1028 if (pDevice->bLongHeader)
1029 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1030
Forest Bond92b96792009-06-13 07:38:31 -04001031 //Set FRAGCTL_MACHDCNT
1032 if (pDevice->bLongHeader) {
1033 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1034 } else {
1035 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1036 }
Andres More3eaca0d2013-02-25 20:32:52 -05001037 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001038
1039 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001040 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001041 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1042 }
1043
1044 //Set Auto Fallback Ctl
1045 if (wCurrentRate >= RATE_18M) {
1046 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1047 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1048 byFBOption = AUTO_FB_0;
1049 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1050 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1051 byFBOption = AUTO_FB_1;
1052 }
1053 }
1054
Andres More4e9b5e22013-02-12 20:36:30 -05001055 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001056 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1057 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1058 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1059 }
1060 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1061 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1062 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1063 }
1064 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1065 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1066 }
1067 }
1068 }
1069
Forest Bond92b96792009-06-13 07:38:31 -04001070 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1071 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1072 cbIVlen = 4;
1073 cbICVlen = 4;
1074 }
1075 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1076 cbIVlen = 8;//IV+ExtIV
1077 cbMIClen = 8;
1078 cbICVlen = 4;
1079 }
1080 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1081 cbIVlen = 8;//RSN Header
1082 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001083 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001084 }
Andres Moree269fc22013-02-12 20:36:29 -05001085 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001086 //MAC Header should be padding 0 to DW alignment.
1087 uPadding = 4 - (cbMACHdLen%4);
1088 uPadding %= 4;
1089 }
1090 }
1091
1092 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1093
Andres Moree269fc22013-02-12 20:36:29 -05001094 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1095 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001096 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001097 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001098 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1099 }
1100
Andres Moreb902fbf2013-02-25 20:32:51 -05001101 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001102 wTxBufSize = sizeof(STxBufHead);
1103 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1104 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001105 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001106 pvRrvTime = (struct vnt_rrv_time_rts *)
1107 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001108 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001109 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001110 rts_cts = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001111 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001112 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1113 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1114 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001115 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001116 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001117 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001118 }
1119 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001120 pvRrvTime = (struct vnt_rrv_time_cts *)
1121 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001122 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001123 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001124 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001125 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001126 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1127 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1128 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001129 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1130 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001131 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001132 }
1133 } else {
1134 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001135 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001136 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1137 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001138 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001139 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001140 rts_cts = (struct vnt_rts_g_fb *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001141 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001142 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1143 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1144 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001145 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1146 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001147 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001148 }
Andres Moree269fc22013-02-12 20:36:29 -05001149 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001150 pvRrvTime = (struct vnt_rrv_time_cts *)
1151 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001152 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001153 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001154 rts_cts = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001155 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001156 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001157 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1158 cbMICHDR + sizeof(struct vnt_cts_fb));
1159 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001160 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001161 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001162 }
1163 } // Auto Fall Back
1164 }
1165 else {//802.11a/b packet
1166 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001167 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001168 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1169 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001170 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001171 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001172 rts_cts = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001173 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001174 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1175 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001176 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001177 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1178 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001179 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001180 }
Andres Moree269fc22013-02-12 20:36:29 -05001181 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001182 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1183 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001184 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001185 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley558becf2013-08-16 23:50:32 +01001186 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1187 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001188 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001189 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001190 }
1191 } else {
1192 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001193 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001194 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1195 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001196 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001197 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001198 rts_cts = (struct vnt_rts_a_fb *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001199 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001200 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1201 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001202 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001203 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1204 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001205 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001206 }
Andres Moree269fc22013-02-12 20:36:29 -05001207 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001208 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1209 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001210 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001211 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001212 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1213 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001214 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001215 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001216 }
1217 } // Auto Fall Back
1218 }
1219
Andres Moreb902fbf2013-02-25 20:32:51 -05001220 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1221 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1222 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001223
Forest Bond92b96792009-06-13 07:38:31 -04001224 //=========================
1225 // No Fragmentation
1226 //=========================
1227 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1228 byFragType = FRAGCTL_NONFRAG;
1229 //uDMAIdx = TYPE_AC0DMA;
1230 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1231
Forest Bond92b96792009-06-13 07:38:31 -04001232 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001233 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001234 (void *)pbyTxBufferAddr, pvRrvTime, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001235 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Forest Bond92b96792009-06-13 07:38:31 -04001236 //Fill DataHead
1237 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001238 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001239 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001240 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001241 byFragType, uDMAIdx, 0);
1242
Andres More4e9b5e22013-02-12 20:36:30 -05001243 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001244 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001245 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001246 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001247
1248 if (pDevice->bEnableHostWEP) {
1249 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1250 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1251 }
1252 }
1253
1254 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001255 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001256 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001257 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1258 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001259 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001260 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001261 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001262 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001263 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001264 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001265 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001266 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001267 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001268
1269 }
1270
1271 }
1272
Forest Bond92b96792009-06-13 07:38:31 -04001273 if (pPacket != NULL) {
1274 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001275 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001276 (pPacket + ETH_HLEN),
1277 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001278 );
1279
1280 } else {
1281 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001282 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001283 }
1284
Andres More4e9b5e22013-02-12 20:36:30 -05001285 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001286
1287 ///////////////////////////////////////////////////////////////////
1288
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001289 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1290 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1291 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1292 }
Forest Bond92b96792009-06-13 07:38:31 -04001293 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001294 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1295 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001296 }
1297 else {
Andres More52a7e642013-02-25 20:32:53 -05001298 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1299 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001300 }
1301 // DO Software Michael
1302 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001303 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001304 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001305 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001306 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1307 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001308
1309 ///////////////////////////////////////////////////////////////////
1310
1311 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1312 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001313 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001314 //}
1315 //DBG_PRN_GRP12(("\n\n\n"));
1316
1317 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1318
Andres More52a7e642013-02-25 20:32:53 -05001319 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1320 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001321
1322 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1323 MIC_vUnInit();
1324
Andres More4e9b5e22013-02-12 20:36:30 -05001325 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001326 *pdwMIC_L = 0;
1327 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001328 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001329 }
1330 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1331 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1332 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1333 }
1334
Andres More4e9b5e22013-02-12 20:36:30 -05001335 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001336
Andres More3eaca0d2013-02-25 20:32:52 -05001337 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001338
Andres More4e9b5e22013-02-12 20:36:30 -05001339 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1340 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1341 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001342 cbFrameSize -= cbICVlen;
1343 }
1344
Forest Bond92b96792009-06-13 07:38:31 -04001345 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001346
1347 *pcbHeaderLen = cbHeaderLength;
1348 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1349
Forest Bond92b96792009-06-13 07:38:31 -04001350 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001351 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001352
Andres More4e9b5e22013-02-12 20:36:30 -05001353 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001354
1355}
1356
Forest Bond92b96792009-06-13 07:38:31 -04001357/*+
1358 *
1359 * Description:
1360 * Translate 802.3 to 802.11 header
1361 *
1362 * Parameters:
1363 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001364 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001365 * dwTxBufferAddr - Transmit Buffer
1366 * pPacket - Packet from upper layer
1367 * cbPacketSize - Transmit Data Length
1368 * Out:
1369 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1370 * pcbAppendPayload - size of append payload for 802.1H translation
1371 *
1372 * Return Value: none
1373 *
1374-*/
1375
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001376static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001377 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001378 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001379{
Andres More1cac4a42013-03-18 20:33:50 -05001380 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001381
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001382 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001383
1384 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001385 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001386 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001387 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001388 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1389 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001390 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001391 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001392 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001393 } else {
1394 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001395 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001396 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001397 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001398 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001399 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001400 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001401 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001402 &(pDevice->abyBSSID[0]),
1403 ETH_ALEN);
1404 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001405 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001406 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001407 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001408 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001409 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001410 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001411 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001412 &(pDevice->abyBSSID[0]),
1413 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001414 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001415 }
1416 }
1417
1418 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001419 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001420
Andres More1cac4a42013-03-18 20:33:50 -05001421 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001422
1423 if (pDevice->bLongHeader) {
1424 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001425 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001426 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001427 }
Andres More1cac4a42013-03-18 20:33:50 -05001428 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001429
1430 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001431 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001432
1433 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1434 pDevice->wSeqCounter++;
1435 if (pDevice->wSeqCounter > 0x0fff)
1436 pDevice->wSeqCounter = 0;
1437 }
1438
1439 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001440 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001441 }
1442}
1443
Forest Bond92b96792009-06-13 07:38:31 -04001444/*+
1445 *
1446 * Description:
1447 * Request instructs a MAC to transmit a 802.11 management packet through
1448 * the adapter onto the medium.
1449 *
1450 * Parameters:
1451 * In:
1452 * hDeviceContext - Pointer to the adapter
1453 * pPacket - A pointer to a descriptor for the packet to transmit
1454 * Out:
1455 * none
1456 *
Andres Moree269fc22013-02-12 20:36:29 -05001457 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001458 *
1459-*/
1460
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001461CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1462 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001463{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001464 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001465 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001466 PSTxBufHead pTxBufHead;
1467 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001468 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001469 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001470 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001471 void *rts_cts = NULL;
1472 void *pvTxDataHd, *pvRrvTime, *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001473 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001474 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001475 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1476 u32 uPadding = 0;
1477 u16 wTxBufSize;
1478 u32 cbMacHdLen;
1479 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001480
Forest Bond92b96792009-06-13 07:38:31 -04001481 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1482
1483 if (NULL == pContext) {
1484 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1485 return CMD_STATUS_RESOURCES;
1486 }
1487
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001488 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001489 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001490 cbFrameBodySize = pPacket->cbPayloadLen;
1491 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1492 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001493
1494 if (pDevice->byBBType == BB_TYPE_11A) {
1495 wCurrentRate = RATE_6M;
1496 byPktType = PK_TYPE_11A;
1497 } else {
1498 wCurrentRate = RATE_1M;
1499 byPktType = PK_TYPE_11B;
1500 }
1501
1502 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1503 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1504 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1505 // to set power here.
1506 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1507 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1508 } else {
1509 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1510 }
1511 pDevice->wCurrentRate = wCurrentRate;
1512
Forest Bond92b96792009-06-13 07:38:31 -04001513 //Set packet type
1514 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1515 pTxBufHead->wFIFOCtl = 0;
1516 }
1517 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1518 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1519 }
1520 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1521 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1522 }
1523 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1524 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1525 }
1526
1527 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1528 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1529
Andres More22040bb2010-08-02 20:21:44 -03001530 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001531 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001532 }
1533 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001534 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001535 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1536 };
1537
1538 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1539 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1540
1541 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1542 //Set Preamble type always long
1543 //pDevice->byPreambleType = PREAMBLE_LONG;
1544 // probe-response don't retry
1545 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001546 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001547 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1548 //}
1549 }
1550
1551 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1552
1553 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001554 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001555 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1556 } else {
1557 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1558 }
1559
1560 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001561 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001562
1563 // Notes:
1564 // Although spec says MMPDU can be fragmented; In most case,
1565 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001566 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001567
1568 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1569 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1570 cbIVlen = 4;
1571 cbICVlen = 4;
1572 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1573 }
1574 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1575 cbIVlen = 8;//IV+ExtIV
1576 cbMIClen = 8;
1577 cbICVlen = 4;
1578 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1579 //We need to get seed here for filling TxKey entry.
1580 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1581 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1582 }
1583 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1584 cbIVlen = 8;//RSN Header
1585 cbICVlen = 8;//MIC
1586 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001587 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001588 }
1589 //MAC Header should be padding 0 to DW alignment.
1590 uPadding = 4 - (cbMacHdLen%4);
1591 uPadding %= 4;
1592 }
1593
1594 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1595
1596 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001597 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001598 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1599 }
1600 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1601
1602 //Set RrvTime/RTS/CTS Buffer
1603 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1604
Malcolm Priestley4f990052013-08-16 23:38:57 +01001605 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001606 pMICHDR = NULL;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001607 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001608 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001609 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001610 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1611 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001612 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001613 }
1614 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001615 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001616 pMICHDR = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001617 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1618 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001619 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001620 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001621 }
1622
Andres Moreceb8c5d2013-03-18 20:33:49 -05001623 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001624 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1625 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001626 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001627 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1628 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001629 //=========================
1630 // No Fragmentation
1631 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001632 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001633
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001634 /* Fill FIFO,RrvTime,RTS,and CTS */
1635 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1636 pbyTxBufferAddr, pvRrvTime, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001637 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001638
1639 //Fill DataHead
1640 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001641 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001642
Andres More1cac4a42013-03-18 20:33:50 -05001643 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001644
1645 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1646
1647 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001648 u8 * pbyIVHead;
1649 u8 * pbyPayloadHead;
1650 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001651 PSKeyItem pTransmitKey = NULL;
1652
Andres Moreb902fbf2013-02-25 20:32:51 -05001653 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1654 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001655 do {
1656 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001657 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001658 pbyBSSID = pDevice->abyBSSID;
1659 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001660 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001661 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001662 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001663 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1664 break;
1665 }
1666 } else {
1667 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1668 break;
1669 }
1670 }
1671 // get group key
1672 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001673 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001674 pTransmitKey = NULL;
1675 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1676 } else {
1677 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1678 }
Andres Moree269fc22013-02-12 20:36:29 -05001679 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001680 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001681 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001682 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001683
Jim Lieb3e362592009-08-12 14:54:11 -07001684 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001685 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001686 cbFrameBodySize);
1687 }
1688 else {
1689 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001690 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001691 }
1692
Andres More1cac4a42013-03-18 20:33:50 -05001693 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001694 pDevice->wSeqCounter++ ;
1695 if (pDevice->wSeqCounter > 0x0fff)
1696 pDevice->wSeqCounter = 0;
1697
1698 if (bIsPSPOLL) {
1699 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001700 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001701 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1702 // in the same place of other packet's Duration-field).
1703 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001704 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1705 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1706 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1707 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1708 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1709 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001710 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1711 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1712 }
Forest Bond92b96792009-06-13 07:38:31 -04001713 }
1714
Andres More3eaca0d2013-02-25 20:32:52 -05001715 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001716 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001717 pTX_Buffer->byType = 0x00;
1718
1719 pContext->pPacket = NULL;
1720 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001721 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001722
Andres More1cac4a42013-03-18 20:33:50 -05001723 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1724 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001725 }
1726 else {
Andres More1cac4a42013-03-18 20:33:50 -05001727 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001728 }
1729
1730 PIPEnsSendBulkOut(pDevice,pContext);
1731 return CMD_STATUS_PENDING;
1732}
1733
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001734CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1735 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001736{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001737 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001738 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1739 u32 cbHeaderSize = 0;
1740 u16 wTxBufSize = sizeof(STxShortBufHead);
1741 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001742 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001743 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001744 u16 wCurrentRate;
1745 u32 cbFrameBodySize;
1746 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001747 u8 *pbyTxBufferAddr;
1748 PUSB_SEND_CONTEXT pContext;
1749 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001750
Forest Bond92b96792009-06-13 07:38:31 -04001751 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1752 if (NULL == pContext) {
1753 status = CMD_STATUS_RESOURCES;
1754 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1755 return status ;
1756 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001757
1758 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001759 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001760
1761 cbFrameBodySize = pPacket->cbPayloadLen;
1762
1763 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1764 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001765
1766 if (pDevice->byBBType == BB_TYPE_11A) {
1767 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001768 pTxDataHead = (struct vnt_tx_datahead_ab *)
1769 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001770 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001771 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1772 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001773 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001774 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001775 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001776 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001777 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001778 } else {
1779 wCurrentRate = RATE_1M;
1780 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001781 pTxDataHead = (struct vnt_tx_datahead_ab *)
1782 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001783 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001784 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1785 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001786 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001787 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001788 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001789 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001790 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001791 }
1792
1793 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001794 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001795 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001796
Andres More1cac4a42013-03-18 20:33:50 -05001797 pMACHeader->duration_id = 0;
1798 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001799 pDevice->wSeqCounter++ ;
1800 if (pDevice->wSeqCounter > 0x0fff)
1801 pDevice->wSeqCounter = 0;
1802
1803 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1804
Andres More3eaca0d2013-02-25 20:32:52 -05001805 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001806 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001807 pTX_Buffer->byType = 0x01;
1808
1809 pContext->pPacket = NULL;
1810 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001811 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001812
1813 PIPEnsSendBulkOut(pDevice,pContext);
1814 return CMD_STATUS_PENDING;
1815
1816}
1817
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001818void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1819{
1820 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001821 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001822 u8 byPktType;
1823 u8 *pbyTxBufferAddr;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001824 void *rts_cts = NULL;
1825 void *pvTxDataHd;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001826 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001827 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001828 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001829 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001830 PSTxBufHead pTxBufHead;
1831 u32 cbFrameSize;
1832 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1833 u32 uPadding = 0;
1834 u32 cbMICHDR = 0, uLength = 0;
1835 u32 dwMICKey0, dwMICKey1;
1836 u32 dwMIC_Priority;
1837 u32 *pdwMIC_L, *pdwMIC_R;
1838 u16 wTxBufSize;
1839 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001840 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001841 void *pvRrvTime, *pMICHDR;
1842 u32 wCurrentRate = RATE_1M;
1843 PUWLAN_80211HDR p80211Header;
1844 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001845 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001846 SKeyItem STempKey;
1847 PSKeyItem pTransmitKey = NULL;
1848 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1849 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001850 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001851
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001852 pvRrvTime = pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001853
1854 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1855 cbFrameBodySize = 0;
1856 }
1857 else {
1858 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1859 }
1860 p80211Header = (PUWLAN_80211HDR)skb->data;
1861
1862 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1863
1864 if (NULL == pContext) {
1865 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1866 dev_kfree_skb_irq(skb);
1867 return ;
1868 }
1869
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001870 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001871 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001872 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1873 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001874
1875 if (pDevice->byBBType == BB_TYPE_11A) {
1876 wCurrentRate = RATE_6M;
1877 byPktType = PK_TYPE_11A;
1878 } else {
1879 wCurrentRate = RATE_1M;
1880 byPktType = PK_TYPE_11B;
1881 }
1882
1883 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1884 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1885 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1886 // to set power here.
1887 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1888 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1889 } else {
1890 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1891 }
1892
1893 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1894
1895 //Set packet type
1896 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1897 pTxBufHead->wFIFOCtl = 0;
1898 }
1899 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1900 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1901 }
1902 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1903 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1904 }
1905 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1906 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1907 }
1908
1909 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1910 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1911
Andres More22040bb2010-08-02 20:21:44 -03001912 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001913 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001914 if (pDevice->bEnableHostWEP) {
1915 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001916 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001917 }
Forest Bond92b96792009-06-13 07:38:31 -04001918 }
1919 else {
1920 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001921 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001922 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001923 }
Andres More4e9b5e22013-02-12 20:36:30 -05001924 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001925 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1926 };
1927
1928 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1929 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1930
1931 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1932 //Set Preamble type always long
1933 //pDevice->byPreambleType = PREAMBLE_LONG;
1934
1935 // probe-response don't retry
1936 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001937 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001938 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1939 //}
1940 }
1941
1942 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1943
1944 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001945 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001946 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1947 } else {
1948 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1949 }
1950
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001951 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001952 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1953
1954 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1955 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1956 }
1957
1958 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1959 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1960 }
1961
1962 if (cbExtSuppRate >0) {
1963 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1964 }
1965 }
1966
Forest Bond92b96792009-06-13 07:38:31 -04001967 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001968 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001969
1970 // Notes:
1971 // Although spec says MMPDU can be fragmented; In most case,
1972 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001973 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001974
Forest Bond92b96792009-06-13 07:38:31 -04001975 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1976 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1977 cbIVlen = 4;
1978 cbICVlen = 4;
1979 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1980 }
1981 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1982 cbIVlen = 8;//IV+ExtIV
1983 cbMIClen = 8;
1984 cbICVlen = 4;
1985 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1986 //We need to get seed here for filling TxKey entry.
1987 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1988 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1989 }
1990 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1991 cbIVlen = 8;//RSN Header
1992 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001993 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001994 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001995 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001996 }
1997 //MAC Header should be padding 0 to DW alignment.
1998 uPadding = 4 - (cbMacHdLen%4);
1999 uPadding %= 4;
2000 }
2001
2002 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2003
2004 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002005 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002006 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2007 }
2008 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2009
Forest Bond92b96792009-06-13 07:38:31 -04002010 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002011 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002012 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002013 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01002014 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002015 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002016 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2017 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002018 sizeof(struct vnt_cts));
2019 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002020 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002021
2022 }
2023 else {//802.11a/b packet
2024
Malcolm Priestley976467d2013-08-16 23:44:04 +01002025 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002026 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002027 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley558becf2013-08-16 23:50:32 +01002028 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2029 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002030 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002031 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002032 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002033 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002034 &(p80211Header->sA3.abyAddr1[0]),
2035 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002036 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002037 &(p80211Header->sA3.abyAddr2[0]),
2038 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002039 //=========================
2040 // No Fragmentation
2041 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002042 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002043
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01002044 /* Fill FIFO,RrvTime,RTS,and CTS */
2045 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
2046 pbyTxBufferAddr, pvRrvTime, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01002047 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04002048
2049 //Fill DataHead
2050 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002051 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002052
Andres More1cac4a42013-03-18 20:33:50 -05002053 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002054
2055 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2056
Andres Moreb902fbf2013-02-25 20:32:51 -05002057 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2058 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2059 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002060
2061 // Copy the Packet into a tx Buffer
2062 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2063
2064 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002065 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002066 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2067
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002068 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002069 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2070 if (cbExtSuppRate != 0) {
2071 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2072 memcpy((pbyPayloadHead + cbFrameBodySize),
2073 pMgmt->abyCurrSuppRates,
2074 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2075 );
2076 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2077 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2078 pMgmt->abyCurrExtSuppRates,
2079 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2080 );
2081 }
2082 }
2083
2084 // Set wep
2085 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2086
2087 if (pDevice->bEnableHostWEP) {
2088 pTransmitKey = &STempKey;
2089 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2090 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2091 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2092 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2093 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2094 memcpy(pTransmitKey->abyKey,
2095 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2096 pTransmitKey->uKeyLength
2097 );
2098 }
2099
2100 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2101
Andres More52a7e642013-02-25 20:32:53 -05002102 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2103 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002104
2105 // DO Software Michael
2106 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002107 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002108 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002109 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002110 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2111 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002112
2113 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2114
2115 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2116
Andres More52a7e642013-02-25 20:32:53 -05002117 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2118 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002119
2120 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2121 MIC_vUnInit();
2122
Andres More4e9b5e22013-02-12 20:36:30 -05002123 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002124 *pdwMIC_L = 0;
2125 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002126 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002127 }
2128
2129 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2130 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002131 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2132 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002133
2134 }
2135
Andres Moreb902fbf2013-02-25 20:32:51 -05002136 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002137 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002138
2139 if (pDevice->bEnableHostWEP) {
2140 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2141 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2142 }
2143
2144 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002145 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002146 }
2147 }
2148
Andres More1cac4a42013-03-18 20:33:50 -05002149 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002150 pDevice->wSeqCounter++ ;
2151 if (pDevice->wSeqCounter > 0x0fff)
2152 pDevice->wSeqCounter = 0;
2153
Forest Bond92b96792009-06-13 07:38:31 -04002154 if (bIsPSPOLL) {
2155 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2156 // of FIFO control header.
2157 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2158 // in the same place of other packet's Duration-field).
2159 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002160 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2161 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2162 cpu_to_le16(p80211Header->sA2.wDurationID);
2163 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2164 cpu_to_le16(p80211Header->sA2.wDurationID);
2165 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002166 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2167 cpu_to_le16(p80211Header->sA2.wDurationID);
2168 }
Forest Bond92b96792009-06-13 07:38:31 -04002169 }
2170
Andres More3eaca0d2013-02-25 20:32:52 -05002171 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002172 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002173 pTX_Buffer->byType = 0x00;
2174
2175 pContext->pPacket = skb;
2176 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002177 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002178
Andres More1cac4a42013-03-18 20:33:50 -05002179 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2180 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002181 }
2182 else {
Andres More1cac4a42013-03-18 20:33:50 -05002183 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002184 }
2185 PIPEnsSendBulkOut(pDevice,pContext);
2186 return ;
2187
2188}
2189
Forest Bond92b96792009-06-13 07:38:31 -04002190//TYPE_AC0DMA data tx
2191/*
2192 * Description:
2193 * Tx packet via AC0DMA(DMA1)
2194 *
2195 * Parameters:
2196 * In:
2197 * pDevice - Pointer to the adapter
2198 * skb - Pointer to tx skb packet
2199 * Out:
2200 * void
2201 *
2202 * Return Value: NULL
2203 */
2204
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002205int nsDMA_tx_packet(struct vnt_private *pDevice,
2206 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002207{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002208 struct net_device_stats *pStats = &pDevice->stats;
2209 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002210 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002211 u32 BytesToWrite = 0, uHeaderLen = 0;
2212 u32 uNodeIndex = 0;
2213 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2214 u16 wAID;
2215 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002216 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002217 PSKeyItem pTransmitKey = NULL;
2218 SKeyItem STempKey;
2219 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002220 int bTKIP_UseGTK = false;
2221 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002222 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002223 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002224 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002225 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002226 u32 status;
2227 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002228 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002229
Forest Bond92b96792009-06-13 07:38:31 -04002230 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2231
2232 if (pDevice->uAssocCount == 0) {
2233 dev_kfree_skb_irq(skb);
2234 return 0;
2235 }
2236
Andres Moreb902fbf2013-02-25 20:32:51 -05002237 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002238 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002239 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002240 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2241
2242 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2243 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2244 // set tx map
2245 pMgmt->abyPSTxMap[0] |= byMask[0];
2246 return 0;
2247 }
Masanari Iida93184692012-08-13 21:21:50 +09002248 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002249
2250 if (pDevice->byBBType != BB_TYPE_11A)
2251 pDevice->wCurrentRate = RATE_2M;
2252 else
2253 pDevice->wCurrentRate = RATE_24M;
2254 // long preamble type
2255 pDevice->byPreambleType = PREAMBLE_SHORT;
2256
2257 }else {
2258
Andres Moreb902fbf2013-02-25 20:32:51 -05002259 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002260
2261 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2262
2263 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2264
2265 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2266 // set tx map
2267 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2268 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2269 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2270 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2271
2272 return 0;
2273 }
2274 // AP rate decided from node
2275 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2276 // tx preamble decided from node
2277
2278 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2279 pDevice->byPreambleType = pDevice->byShortPreamble;
2280
2281 }else {
2282 pDevice->byPreambleType = PREAMBLE_LONG;
2283 }
Andres More4e9b5e22013-02-12 20:36:30 -05002284 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002285 }
2286 }
2287
Andres Moree269fc22013-02-12 20:36:29 -05002288 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002289 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2290 dev_kfree_skb_irq(skb);
2291 return 0;
2292 }
2293 }
2294
2295 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2296
2297 if (pContext == NULL) {
2298 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2299 dev_kfree_skb_irq(skb);
2300 return STATUS_RESOURCES;
2301 }
2302
Andres Moreceb8c5d2013-03-18 20:33:49 -05002303 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002304
2305//mike add:station mode check eapol-key challenge--->
2306{
Andres Moreb902fbf2013-02-25 20:32:51 -05002307 u8 Protocol_Version; //802.1x Authentication
2308 u8 Packet_Type; //802.1x Authentication
2309 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002310 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002311
Charles Clément21ec51f2010-05-18 10:08:14 -07002312 Protocol_Version = skb->data[ETH_HLEN];
2313 Packet_Type = skb->data[ETH_HLEN+1];
2314 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2315 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 -05002316 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002317 /* 802.1x OR eapol-key challenge frame transfer */
2318 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2319 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002320 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002321 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2322 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2323 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002324 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002325 PRINT_K("WPA ");
2326 }
2327 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002328 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002329 PRINT_K("WPA2(re-keying) ");
2330 }
2331 PRINT_K("Authentication completed!!\n");
2332 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002333 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002334 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002335 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002336 PRINT_K("WPA2 Authentication completed!!\n");
2337 }
2338 }
2339 }
2340}
2341//mike add:station mode check eapol-key challenge<---
2342
Andres More4e9b5e22013-02-12 20:36:30 -05002343 if (pDevice->bEncryptionEnable == true) {
2344 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002345 // get Transmit key
2346 do {
2347 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2348 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2349 pbyBSSID = pDevice->abyBSSID;
2350 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002351 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002352 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002353 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2354 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2356 break;
2357 }
2358 } else {
2359 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2360 break;
2361 }
2362 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002363 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2364 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2366 for (ii = 0; ii< 6; ii++)
2367 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2369
2370 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002371 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002372 break;
2373 }
2374 // get group key
2375 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002376 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002377 pTransmitKey = NULL;
2378 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2380 }
2381 else
2382 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2383 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002384 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2386 }
Andres Moree269fc22013-02-12 20:36:29 -05002387 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002388 }
2389
2390 if (pDevice->bEnableHostWEP) {
2391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002392 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002393 pTransmitKey = &STempKey;
2394 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2395 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2396 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2397 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2398 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2399 memcpy(pTransmitKey->abyKey,
2400 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2401 pTransmitKey->uKeyLength
2402 );
2403 }
2404 }
2405
Andres Moreb902fbf2013-02-25 20:32:51 -05002406 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002407
2408 if (pDevice->bFixRate) {
2409 if (pDevice->byBBType == BB_TYPE_11B) {
2410 if (pDevice->uConnectionRate >= RATE_11M) {
2411 pDevice->wCurrentRate = RATE_11M;
2412 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002413 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002414 }
2415 } else {
2416 if ((pDevice->byBBType == BB_TYPE_11A) &&
2417 (pDevice->uConnectionRate <= RATE_6M)) {
2418 pDevice->wCurrentRate = RATE_6M;
2419 } else {
2420 if (pDevice->uConnectionRate >= RATE_54M)
2421 pDevice->wCurrentRate = RATE_54M;
2422 else
Andres More3eaca0d2013-02-25 20:32:52 -05002423 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002424 }
2425 }
2426 }
2427 else {
2428 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2429 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002430 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002431 // Multicast use highest data rate
2432 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2433 // preamble type
2434 pDevice->byPreambleType = pDevice->byShortPreamble;
2435 }
2436 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002437 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002438 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2439 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2440 pDevice->byPreambleType = pDevice->byShortPreamble;
2441
2442 }
2443 else {
2444 pDevice->byPreambleType = PREAMBLE_LONG;
2445 }
2446 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2447 }
2448 else {
2449 if (pDevice->byBBType != BB_TYPE_11A)
2450 pDevice->wCurrentRate = RATE_2M;
2451 else
2452 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2453 // abyCurrExtSuppRates[]
2454 pDevice->byPreambleType = PREAMBLE_SHORT;
2455 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2456 }
2457 }
2458 }
2459 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2460 // Infra STA rate decided from AP Node, index = 0
2461 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2462 }
2463 }
2464
Andres Moreceb8c5d2013-03-18 20:33:49 -05002465 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002466 if (pDevice->byBBType != BB_TYPE_11A) {
2467 pDevice->wCurrentRate = RATE_1M;
2468 pDevice->byACKRate = RATE_1M;
2469 pDevice->byTopCCKBasicRate = RATE_1M;
2470 pDevice->byTopOFDMBasicRate = RATE_6M;
2471 } else {
2472 pDevice->wCurrentRate = RATE_6M;
2473 pDevice->byACKRate = RATE_6M;
2474 pDevice->byTopCCKBasicRate = RATE_1M;
2475 pDevice->byTopOFDMBasicRate = RATE_6M;
2476 }
2477 }
Forest Bond92b96792009-06-13 07:38:31 -04002478
Andres More0cbd8d92010-05-06 20:34:29 -03002479 DBG_PRT(MSG_LEVEL_DEBUG,
2480 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2481 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002482
2483 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002484 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002485 }
2486
2487 if (pDevice->wCurrentRate <= RATE_11M) {
2488 byPktType = PK_TYPE_11B;
2489 }
2490
Andres More4e9b5e22013-02-12 20:36:30 -05002491 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002492 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2493 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002494 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002495 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002496 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2497 if (pTransmitKey == NULL) {
2498 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2499 }
2500 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002501 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002502 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2503 }
2504 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002505 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2506 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002507 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002508 }
2509 }
2510 }
2511
Forest Bond92b96792009-06-13 07:38:31 -04002512 if (pDevice->bEnableHostWEP) {
2513 if ((uNodeIndex != 0) &&
2514 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002515 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2516 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002517 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002518 }
2519 }
2520 }
2521 else {
2522
Forest Bond92b96792009-06-13 07:38:31 -04002523 if (pTransmitKey == NULL) {
2524 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002525 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002526 dev_kfree_skb_irq(skb);
2527 pStats->tx_dropped++;
2528 return STATUS_FAILURE;
2529 }
Forest Bond92b96792009-06-13 07:38:31 -04002530 }
2531 }
2532
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002533 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2534
Forest Bond92b96792009-06-13 07:38:31 -04002535 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002536 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002537 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002538 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002539 pDevice->wCurrentRate,
2540 &uHeaderLen, &BytesToWrite
2541 );
2542
Andres Moree269fc22013-02-12 20:36:29 -05002543 if (fConvertedPacket == false) {
2544 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002545 dev_kfree_skb_irq(skb);
2546 return STATUS_FAILURE;
2547 }
2548
Andres More4e9b5e22013-02-12 20:36:30 -05002549 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002550 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002551 bScheduleCommand((void *) pDevice,
2552 WLAN_CMD_MAC_DISPOWERSAVING,
2553 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002554 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002555 }
2556 }
2557
Andres Moreb902fbf2013-02-25 20:32:51 -05002558 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002559 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002560
2561 pContext->pPacket = skb;
2562 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002563 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002564
Andres Moreceb8c5d2013-03-18 20:33:49 -05002565 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 -04002566
2567 status = PIPEnsSendBulkOut(pDevice,pContext);
2568
Andres More4e9b5e22013-02-12 20:36:30 -05002569 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002570 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002571
Andres Moreb902fbf2013-02-25 20:32:51 -05002572 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002573 }
2574
2575 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002576 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002577 dev_kfree_skb_irq(skb);
2578 return STATUS_FAILURE;
2579 }
2580 else
2581 return 0;
2582
2583}
2584
Forest Bond92b96792009-06-13 07:38:31 -04002585/*
2586 * Description:
2587 * Relay packet send (AC1DMA) from rx dpc.
2588 *
2589 * Parameters:
2590 * In:
2591 * pDevice - Pointer to the adapter
2592 * pPacket - Pointer to rx packet
2593 * cbPacketSize - rx ethernet frame size
2594 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002595 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002596 *
Andres More4e9b5e22013-02-12 20:36:30 -05002597 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002598 */
2599
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002600int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2601 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002602{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002603 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002604 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002605 u32 BytesToWrite = 0, uHeaderLen = 0;
2606 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002607 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002608 SKeyItem STempKey;
2609 PSKeyItem pTransmitKey = NULL;
2610 u8 *pbyBSSID;
2611 PUSB_SEND_CONTEXT pContext;
2612 u8 byPktTyp;
2613 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002614 u32 status;
2615 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002616
Forest Bond92b96792009-06-13 07:38:31 -04002617 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2618
2619 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002620 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002621 }
2622
Andres Moreceb8c5d2013-03-18 20:33:49 -05002623 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002624
Andres More4e9b5e22013-02-12 20:36:30 -05002625 if (pDevice->bEncryptionEnable == true) {
2626 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002627 // get group key
2628 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002629 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002630 pTransmitKey = NULL;
2631 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2632 } else {
2633 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2634 }
2635 }
2636
2637 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002638 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002639 pTransmitKey = &STempKey;
2640 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2641 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2642 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2643 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2644 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2645 memcpy(pTransmitKey->abyKey,
2646 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2647 pTransmitKey->uKeyLength
2648 );
2649 }
2650 }
2651
2652 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002653 pContext->bBoolInUse = false;
2654 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002655 }
2656
Andres Moreb902fbf2013-02-25 20:32:51 -05002657 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002658
2659 if (pDevice->bFixRate) {
2660 if (pDevice->byBBType == BB_TYPE_11B) {
2661 if (pDevice->uConnectionRate >= RATE_11M) {
2662 pDevice->wCurrentRate = RATE_11M;
2663 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002664 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002665 }
2666 } else {
2667 if ((pDevice->byBBType == BB_TYPE_11A) &&
2668 (pDevice->uConnectionRate <= RATE_6M)) {
2669 pDevice->wCurrentRate = RATE_6M;
2670 } else {
2671 if (pDevice->uConnectionRate >= RATE_54M)
2672 pDevice->wCurrentRate = RATE_54M;
2673 else
Andres More3eaca0d2013-02-25 20:32:52 -05002674 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002675 }
2676 }
2677 }
2678 else {
2679 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2680 }
2681
Forest Bond92b96792009-06-13 07:38:31 -04002682 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002683 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002684 }
2685
2686 if (pDevice->wCurrentRate <= RATE_11M)
2687 byPktType = PK_TYPE_11B;
2688
Andres Moreabad19d2010-07-12 16:28:32 -03002689 BytesToWrite = uDataLen + ETH_FCS_LEN;
2690
Forest Bond92b96792009-06-13 07:38:31 -04002691 // Convert the packet to an usb frame and copy into our buffer
2692 // and send the irp.
2693
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002694 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2695
Forest Bond92b96792009-06-13 07:38:31 -04002696 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002697 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002698 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2699 pbySkbData, pTransmitKey, uNodeIndex,
2700 pDevice->wCurrentRate,
2701 &uHeaderLen, &BytesToWrite
2702 );
2703
Andres Moree269fc22013-02-12 20:36:29 -05002704 if (fConvertedPacket == false) {
2705 pContext->bBoolInUse = false;
2706 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002707 }
2708
Andres Moreb902fbf2013-02-25 20:32:51 -05002709 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002710 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002711
2712 pContext->pPacket = NULL;
2713 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002714 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002715
Andres Moreceb8c5d2013-03-18 20:33:49 -05002716 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 -04002717
2718 status = PIPEnsSendBulkOut(pDevice,pContext);
2719
Andres More4e9b5e22013-02-12 20:36:30 -05002720 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002721}
2722