blob: 14f3e852215da5fb27702b4b91687047b9a290c2 [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 Priestleydcdf1d02013-08-27 12:41:50 +0100144 struct vnt_usb_send_context *pContext = NULL;
145 struct vnt_usb_send_context *pReturnContext = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000146 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++) {
Malcolm Priestley18e35e082013-09-22 20:15:58 +0100151 if (!pDevice->apTD[ii])
152 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400153 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500154 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500155 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100156 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400157 pReturnContext = pContext;
158 break;
159 }
160 }
161 if ( ii == pDevice->cbTD ) {
162 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
163 }
Andres More8611a292010-05-01 14:25:00 -0300164 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400165}
166
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000167static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
168 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400169{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000170 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400171
Andres More4b50fb42010-06-22 21:57:42 -0300172 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300174 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
176 else
177 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
178
179 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
180 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300181 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
182 pbyDestAddr,
183 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400184}
185
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000186static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
187 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100188 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400189{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000190 u32 *pdwIV = (u32 *)pbyIVHead;
191 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500192 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000193 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400194
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100195 /* Fill TXKEY */
196 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100197 return;
Forest Bond92b96792009-06-13 07:38:31 -0400198
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100199 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
200 *pdwIV = pDevice->dwIVCounter;
201 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400202
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100203 switch (pTransmitKey->byCipherSuite) {
204 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100205 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
206 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
207 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
208 pTransmitKey->uKeyLength);
209 } else {
210 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
211 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
212 pTransmitKey->uKeyLength);
213 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
214 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
215 memcpy(pbyBuf+11, pTransmitKey->abyKey,
216 pTransmitKey->uKeyLength);
217 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100218
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100219 memcpy(pDevice->abyPRNG, pbyBuf, 16);
220 }
221 /* Append IV after Mac Header */
222 *pdwIV &= WEP_IV_MASK;
223 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
224 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100225
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100226 pDevice->dwIVCounter++;
227 if (pDevice->dwIVCounter > WEP_IV_MASK)
228 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100229
230 break;
231 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100232 pTransmitKey->wTSC15_0++;
233 if (pTransmitKey->wTSC15_0 == 0)
234 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100235
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100236 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
237 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
238 pDevice->abyPRNG);
239 memcpy(pbyBuf, pDevice->abyPRNG, 16);
240
241 /* Make IV */
242 memcpy(pdwIV, pDevice->abyPRNG, 3);
243
244 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
245 0xc0) | 0x20);
246 /* Append IV&ExtIV after Mac Header */
247 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
248
249 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
250 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
251
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100252 break;
253 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100254 pTransmitKey->wTSC15_0++;
255 if (pTransmitKey->wTSC15_0 == 0)
256 pTransmitKey->dwTSC47_16++;
257
258 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
259
260 /* Make IV */
261 *pdwIV = 0;
262 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
263 0xc0) | 0x20);
264
265 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
266
267 /* Append IV&ExtIV after Mac Header */
268 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
269
270 if (!mic_hdr)
271 return;
272
273 /* MICHDR0 */
274 mic_hdr->id = 0x59;
275 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
276 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
277
278 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
279 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
280
281 /* MICHDR1 */
282 if (pDevice->bLongHeader)
283 mic_hdr->hlen = cpu_to_be16(28);
284 else
285 mic_hdr->hlen = cpu_to_be16(22);
286
287 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
288 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
289
290 /* MICHDR2 */
291 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
292 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100293 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100294 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100295
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100296 if (pDevice->bLongHeader)
297 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
298 }
Forest Bond92b96792009-06-13 07:38:31 -0400299}
300
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000301static void s_vSWencryption(struct vnt_private *pDevice,
302 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400303{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000304 u32 cbICVlen = 4;
305 u32 dwICV = 0xffffffff;
306 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400307
308 if (pTransmitKey == NULL)
309 return;
310
311 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
312 //=======================================================================
313 // Append ICV after payload
314 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500315 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400316 // finally, we must invert dwCRC to get the correct answer
317 *pdwICV = cpu_to_le32(~dwICV);
318 // RC4 encryption
319 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
320 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
321 //=======================================================================
322 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
323 //=======================================================================
324 //Append ICV after payload
325 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500326 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400327 // finally, we must invert dwCRC to get the correct answer
328 *pdwICV = cpu_to_le32(~dwICV);
329 // RC4 encryption
330 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
331 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
332 //=======================================================================
333 }
334}
335
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100336static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
337{
338 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
339 [rate % MAX_RATE]);
340}
341
Forest Bond92b96792009-06-13 07:38:31 -0400342/*byPktType : PK_TYPE_11A 0
343 PK_TYPE_11B 1
344 PK_TYPE_11GB 2
345 PK_TYPE_11GA 3
346*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000347static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
348 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400349{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000350 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400351
352 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
353 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500354 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400355 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500356 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400357 }
358
359 if (bNeedAck) {
360 return (uDataTime + pDevice->uSIFS + uAckTime);
361 }
362 else {
363 return uDataTime;
364 }
365}
366
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100367static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
368 u32 frame_length, u16 rate, int need_ack)
369{
370 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
371 frame_length, rate, need_ack));
372}
373
Forest Bond92b96792009-06-13 07:38:31 -0400374//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100375static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000376 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400377{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000378 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400379
380 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
381
Forest Bond92b96792009-06-13 07:38:31 -0400382 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
383 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
384 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
385 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
386 }
387 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
388 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
389 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
390 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
391 }
392 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
393 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
394 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
395 }
396 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
397 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
398 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
399 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
400 return uRrvTime;
401 }
402
403 //RTSRrvTime
404 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100405 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400406}
407
408//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100409static u16 s_uGetDataDuration(struct vnt_private *pDevice,
410 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400411{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100412 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400413
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100414 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100415 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100416 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
417 byPktType, 14, pDevice->byTopCCKBasicRate);
418 else
419 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
420 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100421 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100422 }
Forest Bond92b96792009-06-13 07:38:31 -0400423
Forest Bond92b96792009-06-13 07:38:31 -0400424 return 0;
425}
426
Forest Bond92b96792009-06-13 07:38:31 -0400427//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100428static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000429 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
430 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400431{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000432 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400433
Forest Bond92b96792009-06-13 07:38:31 -0400434 switch (byDurType) {
435
436 case RTSDUR_BB: //RTSDuration_bb
437 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
438 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
439 break;
440
441 case RTSDUR_BA: //RTSDuration_ba
442 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
443 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
444 break;
445
446 case RTSDUR_AA: //RTSDuration_aa
447 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
448 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
449 break;
450
451 case CTSDUR_BA: //CTSDuration_ba
452 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
453 break;
454
455 case RTSDUR_BA_F0: //RTSDuration_ba_f0
456 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
457 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
458 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
459 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
460 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
461 }
462 break;
463
464 case RTSDUR_AA_F0: //RTSDuration_aa_f0
465 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
466 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
467 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
468 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
469 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
470 }
471 break;
472
473 case RTSDUR_BA_F1: //RTSDuration_ba_f1
474 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
475 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
476 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
477 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
478 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
479 }
480 break;
481
482 case RTSDUR_AA_F1: //RTSDuration_aa_f1
483 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
484 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
485 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
486 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
487 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
488 }
489 break;
490
491 case CTSDUR_BA_F0: //CTSDuration_ba_f0
492 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
493 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
494 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
495 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
496 }
497 break;
498
499 case CTSDUR_BA_F1: //CTSDuration_ba_f1
500 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
501 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
502 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
503 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
504 }
505 break;
506
507 default:
508 break;
509 }
510
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100511 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400512}
513
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000514static u32 s_uFillDataHead(struct vnt_private *pDevice,
515 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100516 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400517{
518
519 if (pTxDataHead == NULL) {
520 return 0;
521 }
522
523 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Forest Bond92b96792009-06-13 07:38:31 -0400524 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100525 struct vnt_tx_datahead_g *pBuf =
526 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400527 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100528 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
529 byPktType, &pBuf->a);
530 BBvCalculateParameter(pDevice, cbFrameLength,
531 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400532 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100533 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100534 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100535 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100536 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400537
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100538 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
539 wCurrentRate);
540 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
541 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400542 return (pBuf->wDuration_a);
543 } else {
544 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100545 struct vnt_tx_datahead_g_fb *pBuf =
546 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400547 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100548 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
549 byPktType, &pBuf->a);
550 BBvCalculateParameter(pDevice, cbFrameLength,
551 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400552 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100553 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100554 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100555 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100556 PK_TYPE_11B, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100557 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100558 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100559 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100560 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100561 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
562 wCurrentRate);
563 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
564 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400565 return (pBuf->wDuration_a);
566 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400567 }
568 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100569 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100570 struct vnt_tx_datahead_a_fb *pBuf =
571 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400572 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100573 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
574 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400575 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100576 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100577 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100578 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100579 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100580 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100581 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100582 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
583 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400584 return (pBuf->wDuration);
585 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100586 struct vnt_tx_datahead_ab *pBuf =
587 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400588 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100589 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
590 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400591 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100592 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100593 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100594 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
595 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400596 return (pBuf->wDuration);
597 }
598 }
599 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100600 struct vnt_tx_datahead_ab *pBuf =
601 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400602 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100603 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
604 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400605 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100606 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100607 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100608 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
609 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400610 return (pBuf->wDuration);
611 }
612 return 0;
613}
614
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100615static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
616 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
617 u16 duration)
618{
619 rts->duration = duration;
620 rts->frame_control = TYPE_CTL_RTS;
621
622 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
623 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
624 else
625 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
626
627 if (priv->eOPMode == OP_MODE_AP)
628 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
629 else
630 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
631
632 return 0;
633}
634
635static int vnt_rxtx_rts_g_head(struct vnt_private *priv,
636 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
637 u8 pkt_type, u32 frame_len, int need_ack,
638 u16 current_rate, u8 fb_option)
639{
640 u16 rts_frame_len = 20;
641
642 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
643 PK_TYPE_11B, &buf->b);
644 BBvCalculateParameter(priv, rts_frame_len,
645 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
646
647 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
648 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
649 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
650 pkt_type, current_rate, need_ack, fb_option);
651 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
652 pkt_type, current_rate, need_ack, fb_option);
653
654 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
655
656 return 0;
657}
658
Malcolm Priestleyec917132013-08-26 11:07:46 +0100659static int vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
660 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
661 u8 pkt_type, u32 frame_len, int need_ack,
662 u16 current_rate, u8 fb_option)
663{
664 u16 rts_frame_len = 20;
665
666 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
667 PK_TYPE_11B, &buf->b);
668 BBvCalculateParameter(priv, rts_frame_len,
669 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
670
671
672 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
673 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
674 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
675 pkt_type, current_rate, need_ack, fb_option);
676 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
677 pkt_type, current_rate, need_ack, fb_option);
678
679
680 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
681 frame_len, pkt_type, current_rate, need_ack, fb_option);
682 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
683 frame_len, pkt_type, current_rate, need_ack, fb_option);
684 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
685 frame_len, pkt_type, current_rate, need_ack, fb_option);
686 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
687 frame_len, pkt_type, current_rate, need_ack, fb_option);
688
689 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
690
691 return 0;
692}
693
Malcolm Priestley17126332013-08-26 11:09:38 +0100694static int vnt_rxtx_rts_ab_head(struct vnt_private *priv,
695 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
696 u8 pkt_type, u32 frame_len, int need_ack,
697 u16 current_rate, u8 fb_option)
698{
699 u16 rts_frame_len = 20;
700
701 BBvCalculateParameter(priv, rts_frame_len,
702 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
703
704 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
705 pkt_type, current_rate, need_ack, fb_option);
706
707 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
708
709 return 0;
710}
711
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100712static int vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
713 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
714 u8 pkt_type, u32 frame_len, int need_ack,
715 u16 current_rate, u8 fb_option)
716{
717 u16 rts_frame_len = 20;
718
719 BBvCalculateParameter(priv, rts_frame_len,
720 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
721
722 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
723 pkt_type, current_rate, need_ack, fb_option);
724
725 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
726 frame_len, pkt_type, current_rate, need_ack, fb_option);
727
728 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
729 frame_len, pkt_type, current_rate, need_ack, fb_option);
730
731 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
732
733 return 0;
734}
735
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000736static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100737 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500738 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400739{
Forest Bond92b96792009-06-13 07:38:31 -0400740
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100741 if (!head)
742 return;
Forest Bond92b96792009-06-13 07:38:31 -0400743
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100744 /* Note: So far RTSHead doesn't appear in ATIM
745 * & Beacom DMA, so we don't need to take them
746 * into account.
747 * Otherwise, we need to modified codes for them.
748 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100749 switch (byPktType) {
750 case PK_TYPE_11GB:
751 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100752 if (byFBOption == AUTO_FB_NONE)
753 vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100754 psEthHeader, byPktType, cbFrameLength,
755 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100756 else
757 vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100758 psEthHeader, byPktType, cbFrameLength,
759 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100760 break;
761 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100762 if (byFBOption) {
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100763 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
764 psEthHeader, byPktType, cbFrameLength,
765 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100766 break;
767 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100768 case PK_TYPE_11B:
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100769 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100770 psEthHeader, byPktType, cbFrameLength,
771 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100772 }
Forest Bond92b96792009-06-13 07:38:31 -0400773}
774
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000775static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100776 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
777 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400778{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000779 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400780
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100781 if (!head)
782 return;
Forest Bond92b96792009-06-13 07:38:31 -0400783
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100784 if (byFBOption != AUTO_FB_NONE) {
785 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100786 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100787 /* Get SignalField,ServiceField,Length */
788 BBvCalculateParameter(pDevice, uCTSFrameLen,
789 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100790 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
791 cbFrameLength, byPktType,
792 wCurrentRate, bNeedAck, byFBOption);
793 /* Get CTSDuration_ba_f0 */
794 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
795 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
796 bNeedAck, byFBOption);
797 /* Get CTSDuration_ba_f1 */
798 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
799 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
800 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100801 /* Get CTS Frame body */
802 pBuf->data.duration = pBuf->wDuration_ba;
803 pBuf->data.frame_control = TYPE_CTL_CTS;
804 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100805 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100806 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100807 /* Get SignalField,ServiceField,Length */
808 BBvCalculateParameter(pDevice, uCTSFrameLen,
809 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100810 /* Get CTSDuration_ba */
811 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
812 CTSDUR_BA, cbFrameLength, byPktType,
813 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100814 /*Get CTS Frame body*/
815 pBuf->data.duration = pBuf->wDuration_ba;
816 pBuf->data.frame_control = TYPE_CTL_CTS;
817 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400818 }
Forest Bond92b96792009-06-13 07:38:31 -0400819}
820
Forest Bond92b96792009-06-13 07:38:31 -0400821/*+
822 *
823 * Description:
824 * Generate FIFO control for MAC & Baseband controller
825 *
826 * Parameters:
827 * In:
828 * pDevice - Pointer to adpater
829 * pTxDataHead - Transmit Data Buffer
830 * pTxBufHead - pTxBufHead
831 * pvRrvTime - pvRrvTime
832 * pvRTS - RTS Buffer
833 * pCTS - CTS Buffer
834 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
835 * bNeedACK - If need ACK
836 * uDMAIdx - DMA Index
837 * Out:
838 * none
839 *
840 * Return Value: none
841 *
842-*/
Andres Morecc856e62010-05-17 21:34:01 -0300843
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000844static void s_vGenerateTxParameter(struct vnt_private *pDevice,
845 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100846 void *rts_cts, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100847 struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400848{
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100849 union vnt_tx_data_head *head = rts_cts;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000850 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
851 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000852 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400853
854 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
855 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
856 pFifoHead->wReserved = wCurrentRate;
857 wFifoCtl = pFifoHead->wFIFOCtl;
858
Forest Bond92b96792009-06-13 07:38:31 -0400859 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
860 byFBOption = AUTO_FB_0;
861 }
862 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
863 byFBOption = AUTO_FB_1;
864 }
865
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100866 if (!pvRrvTime)
867 return;
868
Forest Bond92b96792009-06-13 07:38:31 -0400869 if (pDevice->bLongHeader)
870 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
871
872 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100873 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400874 //Fill RsvTime
Malcolm Priestley6398a592013-08-16 21:26:55 +0100875 struct vnt_rrv_time_rts *pBuf =
876 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100877 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
878 byPktType, cbFrameSize, wCurrentRate);
879 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
880 byPktType, cbFrameSize, wCurrentRate);
881 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
882 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100883 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
884 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
885 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
886 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
887 bNeedACK);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100888 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100889 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100890 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400891 }
892 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400893 //Fill RsvTime
Malcolm Priestley4f990052013-08-16 23:38:57 +0100894 struct vnt_rrv_time_cts *pBuf =
895 (struct vnt_rrv_time_cts *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100896 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
897 cbFrameSize, wCurrentRate, bNeedACK);
898 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
899 PK_TYPE_11B, cbFrameSize,
900 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100901 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
902 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100903 /* Fill CTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100904 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, head,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100905 cbFrameSize, bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400906 }
907 }
908 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100909 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400910 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100911 struct vnt_rrv_time_ab *pBuf =
912 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100913 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
914 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100915 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
916 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100917 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100918 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100919 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100920 } else {
Forest Bond92b96792009-06-13 07:38:31 -0400921 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100922 struct vnt_rrv_time_ab *pBuf =
923 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100924 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
925 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400926 }
927 }
928 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100929 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400930 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100931 struct vnt_rrv_time_ab *pBuf =
932 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100933 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
934 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100935 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
936 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100937 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100938 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100939 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400940 }
941 else { //RTS_needless, non PCF mode
942 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100943 struct vnt_rrv_time_ab *pBuf =
944 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100945 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
946 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400947 }
948 }
949 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
950}
951/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500952 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500953 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300954 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400955*/
956
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000957static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100958 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
959 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
960 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
961 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400962{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000963 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
964 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000965 u32 cb802_1_H_len;
966 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
967 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100968 int bNeedACK;
969 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000970 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
971 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
972 u8 abySNAP_Bridgetunnel[ETH_ALEN]
973 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
974 u32 uDuration;
975 u32 cbHeaderLength = 0, uPadding = 0;
976 void *pvRrvTime;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100977 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100978 void *rts_cts = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000979 void *pvTxDataHd;
980 u8 byFBOption = AUTO_FB_NONE, byFragType;
981 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100982 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000983 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500984 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -0400985
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100986 pvRrvTime = pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400987
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000988 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500989 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
990 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000991 }
Forest Bond92b96792009-06-13 07:38:31 -0400992
Forest Bond92b96792009-06-13 07:38:31 -0400993 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -0500994 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -0400995 if (pDevice->dwDiagRefCount == 0) {
996 cb802_1_H_len = 8;
997 } else {
998 cb802_1_H_len = 2;
999 }
1000 } else {
1001 cb802_1_H_len = 0;
1002 }
1003
Charles Clément21ec51f2010-05-18 10:08:14 -07001004 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001005
1006 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001007 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001008
1009 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001010 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001011 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1012 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001013 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1014 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001015 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001016 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001017 pTxBufHead->wFIFOCtl =
1018 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1019 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001020 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001021 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1022 }
Forest Bond92b96792009-06-13 07:38:31 -04001023 }
1024 else {
1025 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001026 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001027 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1028 }
1029 } //if (pDevice->dwDiagRefCount != 0) {
1030
1031 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1032
1033 //Set FIFOCTL_LHEAD
1034 if (pDevice->bLongHeader)
1035 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1036
Forest Bond92b96792009-06-13 07:38:31 -04001037 //Set FRAGCTL_MACHDCNT
1038 if (pDevice->bLongHeader) {
1039 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1040 } else {
1041 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1042 }
Andres More3eaca0d2013-02-25 20:32:52 -05001043 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001044
1045 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001046 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001047 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1048 }
1049
1050 //Set Auto Fallback Ctl
1051 if (wCurrentRate >= RATE_18M) {
1052 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1053 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1054 byFBOption = AUTO_FB_0;
1055 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1056 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1057 byFBOption = AUTO_FB_1;
1058 }
1059 }
1060
Andres More4e9b5e22013-02-12 20:36:30 -05001061 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001062 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1063 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1064 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1065 }
1066 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1067 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1068 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1069 }
1070 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1071 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1072 }
1073 }
1074 }
1075
Forest Bond92b96792009-06-13 07:38:31 -04001076 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1077 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1078 cbIVlen = 4;
1079 cbICVlen = 4;
1080 }
1081 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1082 cbIVlen = 8;//IV+ExtIV
1083 cbMIClen = 8;
1084 cbICVlen = 4;
1085 }
1086 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1087 cbIVlen = 8;//RSN Header
1088 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001089 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001090 }
Andres Moree269fc22013-02-12 20:36:29 -05001091 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001092 //MAC Header should be padding 0 to DW alignment.
1093 uPadding = 4 - (cbMACHdLen%4);
1094 uPadding %= 4;
1095 }
1096 }
1097
1098 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1099
Andres Moree269fc22013-02-12 20:36:29 -05001100 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1101 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001102 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001103 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001104 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1105 }
1106
Andres Moreb902fbf2013-02-25 20:32:51 -05001107 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001108 wTxBufSize = sizeof(STxBufHead);
1109 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1110 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001111 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001112 pvRrvTime = (struct vnt_rrv_time_rts *)
1113 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001114 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001115 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001116 rts_cts = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001117 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001118 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1119 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1120 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001121 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001122 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001123 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001124 }
1125 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001126 pvRrvTime = (struct vnt_rrv_time_cts *)
1127 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001128 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001129 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001130 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001131 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001132 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1133 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1134 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001135 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1136 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001137 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001138 }
1139 } else {
1140 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001141 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001142 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1143 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001144 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001145 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001146 rts_cts = (struct vnt_rts_g_fb *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001147 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001148 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1149 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1150 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001151 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1152 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001153 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001154 }
Andres Moree269fc22013-02-12 20:36:29 -05001155 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001156 pvRrvTime = (struct vnt_rrv_time_cts *)
1157 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001158 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001159 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001160 rts_cts = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001161 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001162 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001163 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1164 cbMICHDR + sizeof(struct vnt_cts_fb));
1165 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001166 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001167 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001168 }
1169 } // Auto Fall Back
1170 }
1171 else {//802.11a/b packet
1172 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001173 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001174 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1175 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001176 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001177 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001178 rts_cts = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001179 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001180 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1181 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001182 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001183 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1184 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001185 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001186 }
Andres Moree269fc22013-02-12 20:36:29 -05001187 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001188 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1189 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001190 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001191 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley558becf2013-08-16 23:50:32 +01001192 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1193 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001194 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001195 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001196 }
1197 } else {
1198 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001199 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001200 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1201 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001202 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001203 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001204 rts_cts = (struct vnt_rts_a_fb *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001205 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001206 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1207 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001208 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001209 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1210 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001211 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001212 }
Andres Moree269fc22013-02-12 20:36:29 -05001213 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001214 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1215 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001216 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001217 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001218 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1219 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001220 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001221 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001222 }
1223 } // Auto Fall Back
1224 }
1225
Andres Moreb902fbf2013-02-25 20:32:51 -05001226 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1227 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1228 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001229
Forest Bond92b96792009-06-13 07:38:31 -04001230 //=========================
1231 // No Fragmentation
1232 //=========================
1233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1234 byFragType = FRAGCTL_NONFRAG;
1235 //uDMAIdx = TYPE_AC0DMA;
1236 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1237
Forest Bond92b96792009-06-13 07:38:31 -04001238 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001239 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001240 (void *)pbyTxBufferAddr, pvRrvTime, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001241 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Forest Bond92b96792009-06-13 07:38:31 -04001242 //Fill DataHead
1243 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001244 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001245 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001246 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001247 byFragType, uDMAIdx, 0);
1248
Andres More4e9b5e22013-02-12 20:36:30 -05001249 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001250 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001251 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001252 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001253
1254 if (pDevice->bEnableHostWEP) {
1255 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1256 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1257 }
1258 }
1259
1260 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001261 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001262 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001263 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1264 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001265 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001266 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001267 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001268 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001269 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001270 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001271 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001272 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001273 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001274
1275 }
1276
1277 }
1278
Forest Bond92b96792009-06-13 07:38:31 -04001279 if (pPacket != NULL) {
1280 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001281 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001282 (pPacket + ETH_HLEN),
1283 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001284 );
1285
1286 } else {
1287 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001288 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001289 }
1290
Andres More4e9b5e22013-02-12 20:36:30 -05001291 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001292
1293 ///////////////////////////////////////////////////////////////////
1294
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001295 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1296 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1297 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1298 }
Forest Bond92b96792009-06-13 07:38:31 -04001299 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001300 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1301 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001302 }
1303 else {
Andres More52a7e642013-02-25 20:32:53 -05001304 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1305 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001306 }
1307 // DO Software Michael
1308 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001309 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001310 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001311 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001312 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1313 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001314
1315 ///////////////////////////////////////////////////////////////////
1316
1317 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1318 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001319 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001320 //}
1321 //DBG_PRN_GRP12(("\n\n\n"));
1322
1323 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1324
Andres More52a7e642013-02-25 20:32:53 -05001325 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1326 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001327
1328 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1329 MIC_vUnInit();
1330
Andres More4e9b5e22013-02-12 20:36:30 -05001331 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001332 *pdwMIC_L = 0;
1333 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001334 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001335 }
1336 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1337 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1338 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1339 }
1340
Andres More4e9b5e22013-02-12 20:36:30 -05001341 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001342
Andres More3eaca0d2013-02-25 20:32:52 -05001343 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001344
Andres More4e9b5e22013-02-12 20:36:30 -05001345 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1346 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1347 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001348 cbFrameSize -= cbICVlen;
1349 }
1350
Forest Bond92b96792009-06-13 07:38:31 -04001351 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001352
1353 *pcbHeaderLen = cbHeaderLength;
1354 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1355
Forest Bond92b96792009-06-13 07:38:31 -04001356 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001357 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001358
Andres More4e9b5e22013-02-12 20:36:30 -05001359 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001360
1361}
1362
Forest Bond92b96792009-06-13 07:38:31 -04001363/*+
1364 *
1365 * Description:
1366 * Translate 802.3 to 802.11 header
1367 *
1368 * Parameters:
1369 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001370 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001371 * dwTxBufferAddr - Transmit Buffer
1372 * pPacket - Packet from upper layer
1373 * cbPacketSize - Transmit Data Length
1374 * Out:
1375 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1376 * pcbAppendPayload - size of append payload for 802.1H translation
1377 *
1378 * Return Value: none
1379 *
1380-*/
1381
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001382static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001383 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001384 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001385{
Andres More1cac4a42013-03-18 20:33:50 -05001386 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001387
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001388 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001389
1390 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001391 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001392 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001393 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001394 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1395 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001396 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001397 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001398 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001399 } else {
1400 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001401 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001402 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001403 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001404 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001405 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001406 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001407 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001408 &(pDevice->abyBSSID[0]),
1409 ETH_ALEN);
1410 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001411 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001412 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001413 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001414 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001415 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001416 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001417 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001418 &(pDevice->abyBSSID[0]),
1419 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001420 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001421 }
1422 }
1423
1424 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001425 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001426
Andres More1cac4a42013-03-18 20:33:50 -05001427 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001428
1429 if (pDevice->bLongHeader) {
1430 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001431 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001432 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001433 }
Andres More1cac4a42013-03-18 20:33:50 -05001434 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001435
1436 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001437 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001438
1439 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1440 pDevice->wSeqCounter++;
1441 if (pDevice->wSeqCounter > 0x0fff)
1442 pDevice->wSeqCounter = 0;
1443 }
1444
1445 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001446 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001447 }
1448}
1449
Forest Bond92b96792009-06-13 07:38:31 -04001450/*+
1451 *
1452 * Description:
1453 * Request instructs a MAC to transmit a 802.11 management packet through
1454 * the adapter onto the medium.
1455 *
1456 * Parameters:
1457 * In:
1458 * hDeviceContext - Pointer to the adapter
1459 * pPacket - A pointer to a descriptor for the packet to transmit
1460 * Out:
1461 * none
1462 *
Andres Moree269fc22013-02-12 20:36:29 -05001463 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001464 *
1465-*/
1466
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001467CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1468 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001469{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001470 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001471 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001472 PSTxBufHead pTxBufHead;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001473 struct vnt_usb_send_context *pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001474 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001475 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001476 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001477 void *rts_cts = NULL;
1478 void *pvTxDataHd, *pvRrvTime, *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001479 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001480 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001481 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1482 u32 uPadding = 0;
1483 u16 wTxBufSize;
1484 u32 cbMacHdLen;
1485 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001486
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001487 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001488
1489 if (NULL == pContext) {
1490 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1491 return CMD_STATUS_RESOURCES;
1492 }
1493
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001494 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001495 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001496 cbFrameBodySize = pPacket->cbPayloadLen;
1497 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1498 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001499
1500 if (pDevice->byBBType == BB_TYPE_11A) {
1501 wCurrentRate = RATE_6M;
1502 byPktType = PK_TYPE_11A;
1503 } else {
1504 wCurrentRate = RATE_1M;
1505 byPktType = PK_TYPE_11B;
1506 }
1507
1508 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1509 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1510 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1511 // to set power here.
1512 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1513 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1514 } else {
1515 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1516 }
1517 pDevice->wCurrentRate = wCurrentRate;
1518
Forest Bond92b96792009-06-13 07:38:31 -04001519 //Set packet type
1520 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1521 pTxBufHead->wFIFOCtl = 0;
1522 }
1523 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1524 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1525 }
1526 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1527 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1528 }
1529 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1530 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1531 }
1532
1533 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1534 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1535
Andres More22040bb2010-08-02 20:21:44 -03001536 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001537 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001538 }
1539 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001540 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001541 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1542 };
1543
1544 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1545 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1546
1547 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1548 //Set Preamble type always long
1549 //pDevice->byPreambleType = PREAMBLE_LONG;
1550 // probe-response don't retry
1551 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001552 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001553 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1554 //}
1555 }
1556
1557 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1558
1559 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001560 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001561 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1562 } else {
1563 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1564 }
1565
1566 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001567 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001568
1569 // Notes:
1570 // Although spec says MMPDU can be fragmented; In most case,
1571 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001572 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001573
1574 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1575 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1576 cbIVlen = 4;
1577 cbICVlen = 4;
1578 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1579 }
1580 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1581 cbIVlen = 8;//IV+ExtIV
1582 cbMIClen = 8;
1583 cbICVlen = 4;
1584 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1585 //We need to get seed here for filling TxKey entry.
1586 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1587 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1588 }
1589 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1590 cbIVlen = 8;//RSN Header
1591 cbICVlen = 8;//MIC
1592 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001593 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001594 }
1595 //MAC Header should be padding 0 to DW alignment.
1596 uPadding = 4 - (cbMacHdLen%4);
1597 uPadding %= 4;
1598 }
1599
1600 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1601
1602 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001603 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001604 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1605 }
1606 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1607
1608 //Set RrvTime/RTS/CTS Buffer
1609 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1610
Malcolm Priestley4f990052013-08-16 23:38:57 +01001611 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001612 pMICHDR = NULL;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001613 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001614 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001615 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001616 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1617 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001618 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001619 }
1620 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001621 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001622 pMICHDR = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001623 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1624 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001625 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001626 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001627 }
1628
Andres Moreceb8c5d2013-03-18 20:33:49 -05001629 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001630 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1631 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001632 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001633 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1634 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001635 //=========================
1636 // No Fragmentation
1637 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001638 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001639
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001640 /* Fill FIFO,RrvTime,RTS,and CTS */
1641 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1642 pbyTxBufferAddr, pvRrvTime, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001643 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001644
1645 //Fill DataHead
1646 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001647 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001648
Andres More1cac4a42013-03-18 20:33:50 -05001649 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001650
1651 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1652
1653 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001654 u8 * pbyIVHead;
1655 u8 * pbyPayloadHead;
1656 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001657 PSKeyItem pTransmitKey = NULL;
1658
Andres Moreb902fbf2013-02-25 20:32:51 -05001659 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1660 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001661 do {
1662 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001663 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001664 pbyBSSID = pDevice->abyBSSID;
1665 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001666 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001667 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001668 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001669 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1670 break;
1671 }
1672 } else {
1673 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1674 break;
1675 }
1676 }
1677 // get group key
1678 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001679 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001680 pTransmitKey = NULL;
1681 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1682 } else {
1683 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1684 }
Andres Moree269fc22013-02-12 20:36:29 -05001685 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001686 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001687 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001688 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001689
Jim Lieb3e362592009-08-12 14:54:11 -07001690 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001691 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001692 cbFrameBodySize);
1693 }
1694 else {
1695 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001696 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001697 }
1698
Andres More1cac4a42013-03-18 20:33:50 -05001699 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001700 pDevice->wSeqCounter++ ;
1701 if (pDevice->wSeqCounter > 0x0fff)
1702 pDevice->wSeqCounter = 0;
1703
1704 if (bIsPSPOLL) {
1705 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001706 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001707 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1708 // in the same place of other packet's Duration-field).
1709 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001710 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1711 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1712 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1713 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1714 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1715 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001716 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1717 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1718 }
Forest Bond92b96792009-06-13 07:38:31 -04001719 }
1720
Andres More3eaca0d2013-02-25 20:32:52 -05001721 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001722 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001723 pTX_Buffer->byType = 0x00;
1724
1725 pContext->pPacket = NULL;
1726 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001727 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001728
Andres More1cac4a42013-03-18 20:33:50 -05001729 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1730 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001731 }
1732 else {
Andres More1cac4a42013-03-18 20:33:50 -05001733 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001734 }
1735
1736 PIPEnsSendBulkOut(pDevice,pContext);
1737 return CMD_STATUS_PENDING;
1738}
1739
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001740CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1741 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001742{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001743 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001744 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1745 u32 cbHeaderSize = 0;
1746 u16 wTxBufSize = sizeof(STxShortBufHead);
1747 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001748 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001749 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001750 u16 wCurrentRate;
1751 u32 cbFrameBodySize;
1752 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001753 u8 *pbyTxBufferAddr;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001754 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001755 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001756
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001757 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001758 if (NULL == pContext) {
1759 status = CMD_STATUS_RESOURCES;
1760 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1761 return status ;
1762 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001763
1764 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001765 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001766
1767 cbFrameBodySize = pPacket->cbPayloadLen;
1768
1769 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1770 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001771
1772 if (pDevice->byBBType == BB_TYPE_11A) {
1773 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001774 pTxDataHead = (struct vnt_tx_datahead_ab *)
1775 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001776 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001777 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1778 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001779 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001780 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001781 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001782 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001783 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001784 } else {
1785 wCurrentRate = RATE_1M;
1786 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001787 pTxDataHead = (struct vnt_tx_datahead_ab *)
1788 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001789 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001790 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1791 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001792 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001793 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001794 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001795 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001796 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001797 }
1798
1799 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001800 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001801 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001802
Andres More1cac4a42013-03-18 20:33:50 -05001803 pMACHeader->duration_id = 0;
1804 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001805 pDevice->wSeqCounter++ ;
1806 if (pDevice->wSeqCounter > 0x0fff)
1807 pDevice->wSeqCounter = 0;
1808
1809 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1810
Andres More3eaca0d2013-02-25 20:32:52 -05001811 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001812 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001813 pTX_Buffer->byType = 0x01;
1814
1815 pContext->pPacket = NULL;
1816 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001817 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001818
1819 PIPEnsSendBulkOut(pDevice,pContext);
1820 return CMD_STATUS_PENDING;
1821
1822}
1823
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001824void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1825{
1826 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001827 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001828 u8 byPktType;
1829 u8 *pbyTxBufferAddr;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001830 void *rts_cts = NULL;
1831 void *pvTxDataHd;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001832 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001833 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001834 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001835 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001836 PSTxBufHead pTxBufHead;
1837 u32 cbFrameSize;
1838 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1839 u32 uPadding = 0;
1840 u32 cbMICHDR = 0, uLength = 0;
1841 u32 dwMICKey0, dwMICKey1;
1842 u32 dwMIC_Priority;
1843 u32 *pdwMIC_L, *pdwMIC_R;
1844 u16 wTxBufSize;
1845 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001846 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001847 void *pvRrvTime, *pMICHDR;
1848 u32 wCurrentRate = RATE_1M;
1849 PUWLAN_80211HDR p80211Header;
1850 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001851 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001852 SKeyItem STempKey;
1853 PSKeyItem pTransmitKey = NULL;
1854 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1855 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001856 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001857
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001858 pvRrvTime = pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001859
1860 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1861 cbFrameBodySize = 0;
1862 }
1863 else {
1864 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1865 }
1866 p80211Header = (PUWLAN_80211HDR)skb->data;
1867
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001868 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001869
1870 if (NULL == pContext) {
1871 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1872 dev_kfree_skb_irq(skb);
1873 return ;
1874 }
1875
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001876 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001877 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001878 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1879 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001880
1881 if (pDevice->byBBType == BB_TYPE_11A) {
1882 wCurrentRate = RATE_6M;
1883 byPktType = PK_TYPE_11A;
1884 } else {
1885 wCurrentRate = RATE_1M;
1886 byPktType = PK_TYPE_11B;
1887 }
1888
1889 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1890 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1891 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1892 // to set power here.
1893 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1894 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1895 } else {
1896 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1897 }
1898
1899 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1900
1901 //Set packet type
1902 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1903 pTxBufHead->wFIFOCtl = 0;
1904 }
1905 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1906 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1907 }
1908 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1909 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1910 }
1911 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1912 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1913 }
1914
1915 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1916 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1917
Andres More22040bb2010-08-02 20:21:44 -03001918 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001919 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001920 if (pDevice->bEnableHostWEP) {
1921 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001922 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001923 }
Forest Bond92b96792009-06-13 07:38:31 -04001924 }
1925 else {
1926 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001927 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001928 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001929 }
Andres More4e9b5e22013-02-12 20:36:30 -05001930 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001931 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1932 };
1933
1934 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1935 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1936
1937 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1938 //Set Preamble type always long
1939 //pDevice->byPreambleType = PREAMBLE_LONG;
1940
1941 // probe-response don't retry
1942 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001943 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001944 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1945 //}
1946 }
1947
1948 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1949
1950 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001951 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001952 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1953 } else {
1954 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1955 }
1956
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001957 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001958 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1959
1960 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1961 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1962 }
1963
1964 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1965 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1966 }
1967
1968 if (cbExtSuppRate >0) {
1969 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1970 }
1971 }
1972
Forest Bond92b96792009-06-13 07:38:31 -04001973 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001974 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001975
1976 // Notes:
1977 // Although spec says MMPDU can be fragmented; In most case,
1978 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001979 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001980
Forest Bond92b96792009-06-13 07:38:31 -04001981 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1982 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1983 cbIVlen = 4;
1984 cbICVlen = 4;
1985 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1986 }
1987 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1988 cbIVlen = 8;//IV+ExtIV
1989 cbMIClen = 8;
1990 cbICVlen = 4;
1991 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1992 //We need to get seed here for filling TxKey entry.
1993 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1994 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1995 }
1996 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1997 cbIVlen = 8;//RSN Header
1998 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001999 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04002000 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002001 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002002 }
2003 //MAC Header should be padding 0 to DW alignment.
2004 uPadding = 4 - (cbMacHdLen%4);
2005 uPadding %= 4;
2006 }
2007
2008 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2009
2010 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002011 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002012 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2013 }
2014 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2015
Forest Bond92b96792009-06-13 07:38:31 -04002016 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002017 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002018 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002019 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01002020 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002021 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002022 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2023 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002024 sizeof(struct vnt_cts));
2025 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002026 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002027
2028 }
2029 else {//802.11a/b packet
2030
Malcolm Priestley976467d2013-08-16 23:44:04 +01002031 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002032 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002033 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley558becf2013-08-16 23:50:32 +01002034 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2035 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002036 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002037 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002038 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002039 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002040 &(p80211Header->sA3.abyAddr1[0]),
2041 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002042 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002043 &(p80211Header->sA3.abyAddr2[0]),
2044 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002045 //=========================
2046 // No Fragmentation
2047 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002048 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002049
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01002050 /* Fill FIFO,RrvTime,RTS,and CTS */
2051 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
2052 pbyTxBufferAddr, pvRrvTime, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01002053 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04002054
2055 //Fill DataHead
2056 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002057 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002058
Andres More1cac4a42013-03-18 20:33:50 -05002059 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002060
2061 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2062
Andres Moreb902fbf2013-02-25 20:32:51 -05002063 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2064 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2065 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002066
2067 // Copy the Packet into a tx Buffer
2068 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2069
2070 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002071 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002072 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2073
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002074 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002075 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2076 if (cbExtSuppRate != 0) {
2077 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2078 memcpy((pbyPayloadHead + cbFrameBodySize),
2079 pMgmt->abyCurrSuppRates,
2080 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2081 );
2082 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2083 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2084 pMgmt->abyCurrExtSuppRates,
2085 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2086 );
2087 }
2088 }
2089
2090 // Set wep
2091 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2092
2093 if (pDevice->bEnableHostWEP) {
2094 pTransmitKey = &STempKey;
2095 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2096 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2097 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2098 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2099 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2100 memcpy(pTransmitKey->abyKey,
2101 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2102 pTransmitKey->uKeyLength
2103 );
2104 }
2105
2106 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2107
Andres More52a7e642013-02-25 20:32:53 -05002108 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2109 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002110
2111 // DO Software Michael
2112 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002113 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002114 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002115 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002116 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2117 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002118
2119 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2120
2121 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2122
Andres More52a7e642013-02-25 20:32:53 -05002123 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2124 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002125
2126 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2127 MIC_vUnInit();
2128
Andres More4e9b5e22013-02-12 20:36:30 -05002129 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002130 *pdwMIC_L = 0;
2131 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002132 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002133 }
2134
2135 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2136 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002137 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2138 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002139
2140 }
2141
Andres Moreb902fbf2013-02-25 20:32:51 -05002142 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002143 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002144
2145 if (pDevice->bEnableHostWEP) {
2146 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2147 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2148 }
2149
2150 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002151 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002152 }
2153 }
2154
Andres More1cac4a42013-03-18 20:33:50 -05002155 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002156 pDevice->wSeqCounter++ ;
2157 if (pDevice->wSeqCounter > 0x0fff)
2158 pDevice->wSeqCounter = 0;
2159
Forest Bond92b96792009-06-13 07:38:31 -04002160 if (bIsPSPOLL) {
2161 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2162 // of FIFO control header.
2163 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2164 // in the same place of other packet's Duration-field).
2165 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002166 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2167 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2168 cpu_to_le16(p80211Header->sA2.wDurationID);
2169 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2170 cpu_to_le16(p80211Header->sA2.wDurationID);
2171 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002172 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2173 cpu_to_le16(p80211Header->sA2.wDurationID);
2174 }
Forest Bond92b96792009-06-13 07:38:31 -04002175 }
2176
Andres More3eaca0d2013-02-25 20:32:52 -05002177 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002178 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002179 pTX_Buffer->byType = 0x00;
2180
2181 pContext->pPacket = skb;
2182 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002183 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002184
Andres More1cac4a42013-03-18 20:33:50 -05002185 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2186 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002187 }
2188 else {
Andres More1cac4a42013-03-18 20:33:50 -05002189 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002190 }
2191 PIPEnsSendBulkOut(pDevice,pContext);
2192 return ;
2193
2194}
2195
Forest Bond92b96792009-06-13 07:38:31 -04002196//TYPE_AC0DMA data tx
2197/*
2198 * Description:
2199 * Tx packet via AC0DMA(DMA1)
2200 *
2201 * Parameters:
2202 * In:
2203 * pDevice - Pointer to the adapter
2204 * skb - Pointer to tx skb packet
2205 * Out:
2206 * void
2207 *
2208 * Return Value: NULL
2209 */
2210
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002211int nsDMA_tx_packet(struct vnt_private *pDevice,
2212 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002213{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002214 struct net_device_stats *pStats = &pDevice->stats;
2215 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002216 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002217 u32 BytesToWrite = 0, uHeaderLen = 0;
2218 u32 uNodeIndex = 0;
2219 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2220 u16 wAID;
2221 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002222 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002223 PSKeyItem pTransmitKey = NULL;
2224 SKeyItem STempKey;
2225 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002226 int bTKIP_UseGTK = false;
2227 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002228 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002229 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002230 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002231 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002232 u32 status;
2233 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002234 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002235
Forest Bond92b96792009-06-13 07:38:31 -04002236 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2237
2238 if (pDevice->uAssocCount == 0) {
2239 dev_kfree_skb_irq(skb);
2240 return 0;
2241 }
2242
Andres Moreb902fbf2013-02-25 20:32:51 -05002243 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002244 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002245 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002246 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2247
2248 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2249 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2250 // set tx map
2251 pMgmt->abyPSTxMap[0] |= byMask[0];
2252 return 0;
2253 }
Masanari Iida93184692012-08-13 21:21:50 +09002254 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002255
2256 if (pDevice->byBBType != BB_TYPE_11A)
2257 pDevice->wCurrentRate = RATE_2M;
2258 else
2259 pDevice->wCurrentRate = RATE_24M;
2260 // long preamble type
2261 pDevice->byPreambleType = PREAMBLE_SHORT;
2262
2263 }else {
2264
Andres Moreb902fbf2013-02-25 20:32:51 -05002265 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002266
2267 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2268
2269 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2270
2271 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2272 // set tx map
2273 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2274 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2275 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2276 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2277
2278 return 0;
2279 }
2280 // AP rate decided from node
2281 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2282 // tx preamble decided from node
2283
2284 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2285 pDevice->byPreambleType = pDevice->byShortPreamble;
2286
2287 }else {
2288 pDevice->byPreambleType = PREAMBLE_LONG;
2289 }
Andres More4e9b5e22013-02-12 20:36:30 -05002290 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002291 }
2292 }
2293
Andres Moree269fc22013-02-12 20:36:29 -05002294 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002295 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2296 dev_kfree_skb_irq(skb);
2297 return 0;
2298 }
2299 }
2300
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002301 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002302
2303 if (pContext == NULL) {
2304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2305 dev_kfree_skb_irq(skb);
2306 return STATUS_RESOURCES;
2307 }
2308
Andres Moreceb8c5d2013-03-18 20:33:49 -05002309 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002310
2311//mike add:station mode check eapol-key challenge--->
2312{
Andres Moreb902fbf2013-02-25 20:32:51 -05002313 u8 Protocol_Version; //802.1x Authentication
2314 u8 Packet_Type; //802.1x Authentication
2315 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002316 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002317
Charles Clément21ec51f2010-05-18 10:08:14 -07002318 Protocol_Version = skb->data[ETH_HLEN];
2319 Packet_Type = skb->data[ETH_HLEN+1];
2320 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2321 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 -05002322 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002323 /* 802.1x OR eapol-key challenge frame transfer */
2324 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2325 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002326 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002327 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2328 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2329 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002330 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002331 PRINT_K("WPA ");
2332 }
2333 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002334 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002335 PRINT_K("WPA2(re-keying) ");
2336 }
2337 PRINT_K("Authentication completed!!\n");
2338 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002339 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002340 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002341 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002342 PRINT_K("WPA2 Authentication completed!!\n");
2343 }
2344 }
2345 }
2346}
2347//mike add:station mode check eapol-key challenge<---
2348
Andres More4e9b5e22013-02-12 20:36:30 -05002349 if (pDevice->bEncryptionEnable == true) {
2350 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002351 // get Transmit key
2352 do {
2353 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2354 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2355 pbyBSSID = pDevice->abyBSSID;
2356 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002357 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002358 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002359 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2360 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002361 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2362 break;
2363 }
2364 } else {
2365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2366 break;
2367 }
2368 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002369 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2370 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2372 for (ii = 0; ii< 6; ii++)
2373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2374 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2375
2376 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002377 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002378 break;
2379 }
2380 // get group key
2381 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002382 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002383 pTransmitKey = NULL;
2384 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2386 }
2387 else
2388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2389 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002390 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2392 }
Andres Moree269fc22013-02-12 20:36:29 -05002393 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002394 }
2395
2396 if (pDevice->bEnableHostWEP) {
2397 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002398 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002399 pTransmitKey = &STempKey;
2400 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2401 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2402 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2403 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2404 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2405 memcpy(pTransmitKey->abyKey,
2406 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2407 pTransmitKey->uKeyLength
2408 );
2409 }
2410 }
2411
Andres Moreb902fbf2013-02-25 20:32:51 -05002412 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002413
2414 if (pDevice->bFixRate) {
2415 if (pDevice->byBBType == BB_TYPE_11B) {
2416 if (pDevice->uConnectionRate >= RATE_11M) {
2417 pDevice->wCurrentRate = RATE_11M;
2418 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002419 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002420 }
2421 } else {
2422 if ((pDevice->byBBType == BB_TYPE_11A) &&
2423 (pDevice->uConnectionRate <= RATE_6M)) {
2424 pDevice->wCurrentRate = RATE_6M;
2425 } else {
2426 if (pDevice->uConnectionRate >= RATE_54M)
2427 pDevice->wCurrentRate = RATE_54M;
2428 else
Andres More3eaca0d2013-02-25 20:32:52 -05002429 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002430 }
2431 }
2432 }
2433 else {
2434 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2435 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002436 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002437 // Multicast use highest data rate
2438 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2439 // preamble type
2440 pDevice->byPreambleType = pDevice->byShortPreamble;
2441 }
2442 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002443 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002444 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2445 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2446 pDevice->byPreambleType = pDevice->byShortPreamble;
2447
2448 }
2449 else {
2450 pDevice->byPreambleType = PREAMBLE_LONG;
2451 }
2452 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2453 }
2454 else {
2455 if (pDevice->byBBType != BB_TYPE_11A)
2456 pDevice->wCurrentRate = RATE_2M;
2457 else
2458 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2459 // abyCurrExtSuppRates[]
2460 pDevice->byPreambleType = PREAMBLE_SHORT;
2461 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2462 }
2463 }
2464 }
2465 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2466 // Infra STA rate decided from AP Node, index = 0
2467 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2468 }
2469 }
2470
Andres Moreceb8c5d2013-03-18 20:33:49 -05002471 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002472 if (pDevice->byBBType != BB_TYPE_11A) {
2473 pDevice->wCurrentRate = RATE_1M;
2474 pDevice->byACKRate = RATE_1M;
2475 pDevice->byTopCCKBasicRate = RATE_1M;
2476 pDevice->byTopOFDMBasicRate = RATE_6M;
2477 } else {
2478 pDevice->wCurrentRate = RATE_6M;
2479 pDevice->byACKRate = RATE_6M;
2480 pDevice->byTopCCKBasicRate = RATE_1M;
2481 pDevice->byTopOFDMBasicRate = RATE_6M;
2482 }
2483 }
Forest Bond92b96792009-06-13 07:38:31 -04002484
Andres More0cbd8d92010-05-06 20:34:29 -03002485 DBG_PRT(MSG_LEVEL_DEBUG,
2486 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2487 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002488
2489 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002490 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002491 }
2492
2493 if (pDevice->wCurrentRate <= RATE_11M) {
2494 byPktType = PK_TYPE_11B;
2495 }
2496
Andres More4e9b5e22013-02-12 20:36:30 -05002497 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002498 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2499 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002500 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002502 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2503 if (pTransmitKey == NULL) {
2504 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2505 }
2506 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002507 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002508 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2509 }
2510 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002511 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2512 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002513 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002514 }
2515 }
2516 }
2517
Forest Bond92b96792009-06-13 07:38:31 -04002518 if (pDevice->bEnableHostWEP) {
2519 if ((uNodeIndex != 0) &&
2520 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2522 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002523 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002524 }
2525 }
2526 }
2527 else {
2528
Forest Bond92b96792009-06-13 07:38:31 -04002529 if (pTransmitKey == NULL) {
2530 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002531 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002532 dev_kfree_skb_irq(skb);
2533 pStats->tx_dropped++;
2534 return STATUS_FAILURE;
2535 }
Forest Bond92b96792009-06-13 07:38:31 -04002536 }
2537 }
2538
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002539 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2540
Forest Bond92b96792009-06-13 07:38:31 -04002541 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002542 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002543 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002544 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002545 pDevice->wCurrentRate,
2546 &uHeaderLen, &BytesToWrite
2547 );
2548
Andres Moree269fc22013-02-12 20:36:29 -05002549 if (fConvertedPacket == false) {
2550 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002551 dev_kfree_skb_irq(skb);
2552 return STATUS_FAILURE;
2553 }
2554
Andres More4e9b5e22013-02-12 20:36:30 -05002555 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002556 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002557 bScheduleCommand((void *) pDevice,
2558 WLAN_CMD_MAC_DISPOWERSAVING,
2559 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002560 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002561 }
2562 }
2563
Andres Moreb902fbf2013-02-25 20:32:51 -05002564 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002565 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002566
2567 pContext->pPacket = skb;
2568 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002569 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002570
Andres Moreceb8c5d2013-03-18 20:33:49 -05002571 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 -04002572
2573 status = PIPEnsSendBulkOut(pDevice,pContext);
2574
Andres More4e9b5e22013-02-12 20:36:30 -05002575 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002576 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002577
Andres Moreb902fbf2013-02-25 20:32:51 -05002578 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002579 }
2580
2581 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002582 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002583 dev_kfree_skb_irq(skb);
2584 return STATUS_FAILURE;
2585 }
2586 else
2587 return 0;
2588
2589}
2590
Forest Bond92b96792009-06-13 07:38:31 -04002591/*
2592 * Description:
2593 * Relay packet send (AC1DMA) from rx dpc.
2594 *
2595 * Parameters:
2596 * In:
2597 * pDevice - Pointer to the adapter
2598 * pPacket - Pointer to rx packet
2599 * cbPacketSize - rx ethernet frame size
2600 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002601 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002602 *
Andres More4e9b5e22013-02-12 20:36:30 -05002603 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002604 */
2605
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002606int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2607 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002608{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002609 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002610 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002611 u32 BytesToWrite = 0, uHeaderLen = 0;
2612 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002613 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002614 SKeyItem STempKey;
2615 PSKeyItem pTransmitKey = NULL;
2616 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002617 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002618 u8 byPktTyp;
2619 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002620 u32 status;
2621 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002622
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002623 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002624
2625 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002626 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002627 }
2628
Andres Moreceb8c5d2013-03-18 20:33:49 -05002629 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002630
Andres More4e9b5e22013-02-12 20:36:30 -05002631 if (pDevice->bEncryptionEnable == true) {
2632 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002633 // get group key
2634 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002635 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002636 pTransmitKey = NULL;
2637 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2638 } else {
2639 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2640 }
2641 }
2642
2643 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002644 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002645 pTransmitKey = &STempKey;
2646 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2647 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2648 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2649 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2650 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2651 memcpy(pTransmitKey->abyKey,
2652 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2653 pTransmitKey->uKeyLength
2654 );
2655 }
2656 }
2657
2658 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002659 pContext->bBoolInUse = false;
2660 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002661 }
2662
Andres Moreb902fbf2013-02-25 20:32:51 -05002663 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002664
2665 if (pDevice->bFixRate) {
2666 if (pDevice->byBBType == BB_TYPE_11B) {
2667 if (pDevice->uConnectionRate >= RATE_11M) {
2668 pDevice->wCurrentRate = RATE_11M;
2669 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002670 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002671 }
2672 } else {
2673 if ((pDevice->byBBType == BB_TYPE_11A) &&
2674 (pDevice->uConnectionRate <= RATE_6M)) {
2675 pDevice->wCurrentRate = RATE_6M;
2676 } else {
2677 if (pDevice->uConnectionRate >= RATE_54M)
2678 pDevice->wCurrentRate = RATE_54M;
2679 else
Andres More3eaca0d2013-02-25 20:32:52 -05002680 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002681 }
2682 }
2683 }
2684 else {
2685 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2686 }
2687
Forest Bond92b96792009-06-13 07:38:31 -04002688 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002689 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002690 }
2691
2692 if (pDevice->wCurrentRate <= RATE_11M)
2693 byPktType = PK_TYPE_11B;
2694
Andres Moreabad19d2010-07-12 16:28:32 -03002695 BytesToWrite = uDataLen + ETH_FCS_LEN;
2696
Forest Bond92b96792009-06-13 07:38:31 -04002697 // Convert the packet to an usb frame and copy into our buffer
2698 // and send the irp.
2699
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002700 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2701
Forest Bond92b96792009-06-13 07:38:31 -04002702 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002703 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002704 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2705 pbySkbData, pTransmitKey, uNodeIndex,
2706 pDevice->wCurrentRate,
2707 &uHeaderLen, &BytesToWrite
2708 );
2709
Andres Moree269fc22013-02-12 20:36:29 -05002710 if (fConvertedPacket == false) {
2711 pContext->bBoolInUse = false;
2712 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002713 }
2714
Andres Moreb902fbf2013-02-25 20:32:51 -05002715 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002716 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002717
2718 pContext->pPacket = NULL;
2719 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002720 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002721
Andres Moreceb8c5d2013-03-18 20:33:49 -05002722 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 -04002723
2724 status = PIPEnsSendBulkOut(pDevice,pContext);
2725
Andres More4e9b5e22013-02-12 20:36:30 -05002726 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002727}
2728