blob: 821b2e16b6fae3a86285934828b67beaf38fc3e3 [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
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100101static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100102 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100103 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
104 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000106static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500107 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000108 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000110static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
111 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100112 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114static void s_vSWencryption(struct vnt_private *pDevice,
115 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400116
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000117static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
118 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400119
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100120static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000121 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400122
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100123static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100124 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
125 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100127static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100128 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500129 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400130
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100131static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100132 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400133
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100134static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000135 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
136 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400137
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000138static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400139{
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +0100140 struct vnt_usb_send_context *pContext = NULL;
141 struct vnt_usb_send_context *pReturnContext = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000142 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400143
144 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
145
146 for (ii = 0; ii < pDevice->cbTD; ii++) {
Malcolm Priestley18e35e082013-09-22 20:15:58 +0100147 if (!pDevice->apTD[ii])
148 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400149 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500150 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500151 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100152 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400153 pReturnContext = pContext;
154 break;
155 }
156 }
157 if ( ii == pDevice->cbTD ) {
158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
159 }
Andres More8611a292010-05-01 14:25:00 -0300160 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400161}
162
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000163static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
164 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400165{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000166 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400167
Andres More4b50fb42010-06-22 21:57:42 -0300168 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400169 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300170 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400171 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
172 else
173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
174
175 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
176 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300177 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
178 pbyDestAddr,
179 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400180}
181
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000182static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
183 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100184 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400185{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000186 u32 *pdwIV = (u32 *)pbyIVHead;
187 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500188 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000189 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400190
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100191 /* Fill TXKEY */
192 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100193 return;
Forest Bond92b96792009-06-13 07:38:31 -0400194
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100195 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
196 *pdwIV = pDevice->dwIVCounter;
197 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400198
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100199 switch (pTransmitKey->byCipherSuite) {
200 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100201 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
202 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
203 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
204 pTransmitKey->uKeyLength);
205 } else {
206 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
207 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
208 pTransmitKey->uKeyLength);
209 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
210 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
211 memcpy(pbyBuf+11, pTransmitKey->abyKey,
212 pTransmitKey->uKeyLength);
213 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100214
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100215 memcpy(pDevice->abyPRNG, pbyBuf, 16);
216 }
217 /* Append IV after Mac Header */
218 *pdwIV &= WEP_IV_MASK;
219 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
220 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100221
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100222 pDevice->dwIVCounter++;
223 if (pDevice->dwIVCounter > WEP_IV_MASK)
224 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100225
226 break;
227 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100228 pTransmitKey->wTSC15_0++;
229 if (pTransmitKey->wTSC15_0 == 0)
230 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100231
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100232 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
233 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
234 pDevice->abyPRNG);
235 memcpy(pbyBuf, pDevice->abyPRNG, 16);
236
237 /* Make IV */
238 memcpy(pdwIV, pDevice->abyPRNG, 3);
239
240 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
241 0xc0) | 0x20);
242 /* Append IV&ExtIV after Mac Header */
243 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
244
245 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
246 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
247
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100248 break;
249 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100250 pTransmitKey->wTSC15_0++;
251 if (pTransmitKey->wTSC15_0 == 0)
252 pTransmitKey->dwTSC47_16++;
253
254 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
255
256 /* Make IV */
257 *pdwIV = 0;
258 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
259 0xc0) | 0x20);
260
261 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
262
263 /* Append IV&ExtIV after Mac Header */
264 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
265
266 if (!mic_hdr)
267 return;
268
269 /* MICHDR0 */
270 mic_hdr->id = 0x59;
271 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
272 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
273
274 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
275 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
276
277 /* MICHDR1 */
278 if (pDevice->bLongHeader)
279 mic_hdr->hlen = cpu_to_be16(28);
280 else
281 mic_hdr->hlen = cpu_to_be16(22);
282
283 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
284 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
285
286 /* MICHDR2 */
287 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
288 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100289 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100290 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100291
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100292 if (pDevice->bLongHeader)
293 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
294 }
Forest Bond92b96792009-06-13 07:38:31 -0400295}
296
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000297static void s_vSWencryption(struct vnt_private *pDevice,
298 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400299{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000300 u32 cbICVlen = 4;
301 u32 dwICV = 0xffffffff;
302 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400303
304 if (pTransmitKey == NULL)
305 return;
306
307 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
308 //=======================================================================
309 // Append ICV after payload
310 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500311 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400312 // finally, we must invert dwCRC to get the correct answer
313 *pdwICV = cpu_to_le32(~dwICV);
314 // RC4 encryption
315 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
316 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
317 //=======================================================================
318 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
319 //=======================================================================
320 //Append ICV after payload
321 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500322 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400323 // finally, we must invert dwCRC to get the correct answer
324 *pdwICV = cpu_to_le32(~dwICV);
325 // RC4 encryption
326 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
327 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
328 //=======================================================================
329 }
330}
331
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100332static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
333{
334 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
335 [rate % MAX_RATE]);
336}
337
Forest Bond92b96792009-06-13 07:38:31 -0400338/*byPktType : PK_TYPE_11A 0
339 PK_TYPE_11B 1
340 PK_TYPE_11GB 2
341 PK_TYPE_11GA 3
342*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000343static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
344 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400345{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000346 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400347
348 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
349 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500350 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400351 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500352 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400353 }
354
355 if (bNeedAck) {
356 return (uDataTime + pDevice->uSIFS + uAckTime);
357 }
358 else {
359 return uDataTime;
360 }
361}
362
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100363static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
364 u32 frame_length, u16 rate, int need_ack)
365{
366 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
367 frame_length, rate, need_ack));
368}
369
Forest Bond92b96792009-06-13 07:38:31 -0400370//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100371static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000372 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400373{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000374 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400375
376 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
377
Forest Bond92b96792009-06-13 07:38:31 -0400378 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
379 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
380 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
381 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
382 }
383 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
384 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
385 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
386 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
387 }
388 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
389 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
390 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
391 }
392 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
393 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
394 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
395 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
396 return uRrvTime;
397 }
398
399 //RTSRrvTime
400 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100401 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400402}
403
404//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100405static u16 s_uGetDataDuration(struct vnt_private *pDevice,
406 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400407{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100408 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400409
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100410 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100411 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100412 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
413 byPktType, 14, pDevice->byTopCCKBasicRate);
414 else
415 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
416 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100417 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100418 }
Forest Bond92b96792009-06-13 07:38:31 -0400419
Forest Bond92b96792009-06-13 07:38:31 -0400420 return 0;
421}
422
Forest Bond92b96792009-06-13 07:38:31 -0400423//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100424static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000425 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
426 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400427{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000428 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400429
Forest Bond92b96792009-06-13 07:38:31 -0400430 switch (byDurType) {
431
432 case RTSDUR_BB: //RTSDuration_bb
433 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
434 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
435 break;
436
437 case RTSDUR_BA: //RTSDuration_ba
438 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
439 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
440 break;
441
442 case RTSDUR_AA: //RTSDuration_aa
443 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
444 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
445 break;
446
447 case CTSDUR_BA: //CTSDuration_ba
448 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
449 break;
450
451 case RTSDUR_BA_F0: //RTSDuration_ba_f0
452 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
453 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
454 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
455 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
456 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
457 }
458 break;
459
460 case RTSDUR_AA_F0: //RTSDuration_aa_f0
461 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
462 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
463 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
464 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
465 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
466 }
467 break;
468
469 case RTSDUR_BA_F1: //RTSDuration_ba_f1
470 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
471 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
472 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
473 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
474 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
475 }
476 break;
477
478 case RTSDUR_AA_F1: //RTSDuration_aa_f1
479 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
480 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
481 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
482 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
483 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
484 }
485 break;
486
487 case CTSDUR_BA_F0: //CTSDuration_ba_f0
488 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
489 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
490 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
491 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
492 }
493 break;
494
495 case CTSDUR_BA_F1: //CTSDuration_ba_f1
496 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
497 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
498 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
499 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
500 }
501 break;
502
503 default:
504 break;
505 }
506
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100507 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400508}
509
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100510static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
511 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
512{
513 /* Get SignalField,ServiceField,Length */
514 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
515 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
516 PK_TYPE_11B, &buf->b);
517
518 /* Get Duration and TimeStamp */
519 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
520 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
521
522 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
523 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
524 priv->byTopCCKBasicRate);
525
526 return buf->wDuration_a;
527}
528
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100529static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
530 u16 rate, struct vnt_tx_datahead_g_fb *buf,
531 u32 frame_len, int need_ack)
532{
533 /* Get SignalField,ServiceField,Length */
534 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
535
536 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
537 PK_TYPE_11B, &buf->b);
538
539 /* Get Duration and TimeStamp */
540 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
541 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
542
543 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
544 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
545
546 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
547 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
548 priv->byTopCCKBasicRate);
549
550 return buf->wDuration_a;
551}
552
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100553static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
554 u16 rate, struct vnt_tx_datahead_a_fb *buf,
555 u32 frame_len, int need_ack)
556{
557 /* Get SignalField,ServiceField,Length */
558 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
559 /* Get Duration and TimeStampOff */
560 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
561
562 buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
563 buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
564
565 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
566
567 return buf->wDuration;
568}
569
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100570static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
571 u16 rate, struct vnt_tx_datahead_ab *buf,
572 u32 frame_len, int need_ack)
573{
574 /* Get SignalField,ServiceField,Length */
575 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
576 /* Get Duration and TimeStampOff */
577 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
578
579 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
580
581 return buf->wDuration;
582}
583
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100584static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
585 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
586 u16 duration)
587{
588 rts->duration = duration;
589 rts->frame_control = TYPE_CTL_RTS;
590
591 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
592 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
593 else
594 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
595
596 if (priv->eOPMode == OP_MODE_AP)
597 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
598 else
599 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
600
601 return 0;
602}
603
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100604static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100605 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
606 u8 pkt_type, u32 frame_len, int need_ack,
607 u16 current_rate, u8 fb_option)
608{
609 u16 rts_frame_len = 20;
610
611 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
612 PK_TYPE_11B, &buf->b);
613 BBvCalculateParameter(priv, rts_frame_len,
614 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
615
616 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
617 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
618 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
619 pkt_type, current_rate, need_ack, fb_option);
620 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
621 pkt_type, current_rate, need_ack, fb_option);
622
623 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
624
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100625 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
626 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100627}
628
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100629static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100630 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
631 u8 pkt_type, u32 frame_len, int need_ack,
632 u16 current_rate, u8 fb_option)
633{
634 u16 rts_frame_len = 20;
635
636 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
637 PK_TYPE_11B, &buf->b);
638 BBvCalculateParameter(priv, rts_frame_len,
639 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
640
641
642 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
643 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
644 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
645 pkt_type, current_rate, need_ack, fb_option);
646 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
647 pkt_type, current_rate, need_ack, fb_option);
648
649
650 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
651 frame_len, pkt_type, current_rate, need_ack, fb_option);
652 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
653 frame_len, pkt_type, current_rate, need_ack, fb_option);
654 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
655 frame_len, pkt_type, current_rate, need_ack, fb_option);
656 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
657 frame_len, pkt_type, current_rate, need_ack, fb_option);
658
659 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
660
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100661 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
662 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100663}
664
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100665static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100666 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
667 u8 pkt_type, u32 frame_len, int need_ack,
668 u16 current_rate, u8 fb_option)
669{
670 u16 rts_frame_len = 20;
671
672 BBvCalculateParameter(priv, rts_frame_len,
673 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
674
675 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
676 pkt_type, current_rate, need_ack, fb_option);
677
678 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
679
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100680 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
681 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100682}
683
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100684static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100685 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
686 u8 pkt_type, u32 frame_len, int need_ack,
687 u16 current_rate, u8 fb_option)
688{
689 u16 rts_frame_len = 20;
690
691 BBvCalculateParameter(priv, rts_frame_len,
692 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
693
694 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
695 pkt_type, current_rate, need_ack, fb_option);
696
697 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
698 frame_len, pkt_type, current_rate, need_ack, fb_option);
699
700 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
701 frame_len, pkt_type, current_rate, need_ack, fb_option);
702
703 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
704
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100705 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
706 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100707}
708
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100709static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100710 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500711 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400712{
Forest Bond92b96792009-06-13 07:38:31 -0400713
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100714 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100715 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400716
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100717 /* Note: So far RTSHead doesn't appear in ATIM
718 * & Beacom DMA, so we don't need to take them
719 * into account.
720 * Otherwise, we need to modified codes for them.
721 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100722 switch (byPktType) {
723 case PK_TYPE_11GB:
724 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100725 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100726 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100727 psEthHeader, byPktType, cbFrameLength,
728 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100729 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100730 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100731 psEthHeader, byPktType, cbFrameLength,
732 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100733 break;
734 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100735 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100736 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100737 psEthHeader, byPktType, cbFrameLength,
738 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100739 break;
740 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100741 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100742 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100743 psEthHeader, byPktType, cbFrameLength,
744 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100745 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100746
747 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400748}
749
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100750static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100751 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
752 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400753{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000754 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400755
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100756 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100757 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400758
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100759 if (byFBOption != AUTO_FB_NONE) {
760 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100761 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100762 /* Get SignalField,ServiceField,Length */
763 BBvCalculateParameter(pDevice, uCTSFrameLen,
764 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100765 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
766 cbFrameLength, byPktType,
767 wCurrentRate, bNeedAck, byFBOption);
768 /* Get CTSDuration_ba_f0 */
769 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
770 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
771 bNeedAck, byFBOption);
772 /* Get CTSDuration_ba_f1 */
773 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
774 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
775 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100776 /* Get CTS Frame body */
777 pBuf->data.duration = pBuf->wDuration_ba;
778 pBuf->data.frame_control = TYPE_CTL_CTS;
779 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100780
781 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
782 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100783 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100784 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100785 /* Get SignalField,ServiceField,Length */
786 BBvCalculateParameter(pDevice, uCTSFrameLen,
787 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100788 /* Get CTSDuration_ba */
789 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
790 CTSDUR_BA, cbFrameLength, byPktType,
791 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100792 /*Get CTS Frame body*/
793 pBuf->data.duration = pBuf->wDuration_ba;
794 pBuf->data.frame_control = TYPE_CTL_CTS;
795 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100796
797 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
798 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400799 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100800
801 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400802}
803
Forest Bond92b96792009-06-13 07:38:31 -0400804/*+
805 *
806 * Description:
807 * Generate FIFO control for MAC & Baseband controller
808 *
809 * Parameters:
810 * In:
811 * pDevice - Pointer to adpater
812 * pTxDataHead - Transmit Data Buffer
813 * pTxBufHead - pTxBufHead
814 * pvRrvTime - pvRrvTime
815 * pvRTS - RTS Buffer
816 * pCTS - CTS Buffer
817 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
818 * bNeedACK - If need ACK
819 * uDMAIdx - DMA Index
820 * Out:
821 * none
822 *
823 * Return Value: none
824 *
825-*/
Andres Morecc856e62010-05-17 21:34:01 -0300826
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100827static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100828 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100829 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
830 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400831{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100832 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100833 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000834 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
835 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000836 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400837
Malcolm Priestley92928f12013-10-07 20:14:01 +0100838 pFifoHead->wReserved = wCurrentRate;
839 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400840
Malcolm Priestley92928f12013-10-07 20:14:01 +0100841 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
842 byFBOption = AUTO_FB_0;
843 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
844 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400845
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100846 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100847 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100848
Malcolm Priestley92928f12013-10-07 20:14:01 +0100849 if (pDevice->bLongHeader)
850 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
Forest Bond92b96792009-06-13 07:38:31 -0400851
Malcolm Priestley92928f12013-10-07 20:14:01 +0100852 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
853 if (need_rts) {
854 struct vnt_rrv_time_rts *pBuf =
855 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100856
Malcolm Priestley92928f12013-10-07 20:14:01 +0100857 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
858 byPktType, cbFrameSize, wCurrentRate);
859 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
860 byPktType, cbFrameSize, wCurrentRate);
861 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100862 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100863
Malcolm Priestley92928f12013-10-07 20:14:01 +0100864 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
865 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
866 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
867 PK_TYPE_11B, cbFrameSize,
868 pDevice->byTopCCKBasicRate, bNeedACK);
869
870 if (need_mic) {
871 *mic_hdr = &tx_buffer->
872 tx_head.tx_rts.tx.mic.hdr;
873 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
874 } else {
875 head = &tx_buffer->tx_head.tx_rts.tx.head;
876 }
877
878 /* Fill RTS */
879 return s_vFillRTSHead(pDevice, byPktType, head,
880 cbFrameSize, bNeedACK, psEthHeader,
881 wCurrentRate, byFBOption);
882
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100883 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100884 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
885 tx_head.tx_cts.cts;
886
887 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
888 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
889 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
890 PK_TYPE_11B, cbFrameSize,
891 pDevice->byTopCCKBasicRate, bNeedACK);
892
893 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
894 byPktType, cbFrameSize, wCurrentRate);
895
896 if (need_mic) {
897 *mic_hdr = &tx_buffer->
898 tx_head.tx_cts.tx.mic.hdr;
899 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
900 } else {
901 head = &tx_buffer->tx_head.tx_cts.tx.head;
902 }
903
904 /* Fill CTS */
905 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
906 head, cbFrameSize, bNeedACK, wCurrentRate,
907 byFBOption);
908 }
909 } else if (byPktType == PK_TYPE_11A) {
910 if (need_mic) {
911 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
912 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
913 } else {
914 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100915 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100916
Malcolm Priestley92928f12013-10-07 20:14:01 +0100917 if (need_rts) {
918 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
919 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100920
Malcolm Priestley92928f12013-10-07 20:14:01 +0100921 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100922 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100923
Malcolm Priestley92928f12013-10-07 20:14:01 +0100924 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
925 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
926
927 /* Fill RTS */
928 return s_vFillRTSHead(pDevice, byPktType, head,
929 cbFrameSize, bNeedACK, psEthHeader,
930 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100931 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100932 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
933 tx_head.tx_ab.ab;
934
935 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
936 PK_TYPE_11A, cbFrameSize,
937 wCurrentRate, bNeedACK);
938
939 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
940 wCurrentRate, &head->data_head_a_fb,
941 cbFrameSize, bNeedACK);
942 }
943 } else if (byPktType == PK_TYPE_11B) {
944 if (need_mic) {
945 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
946 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
947 } else {
948 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100949 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100950
Malcolm Priestley92928f12013-10-07 20:14:01 +0100951 if (need_rts) {
952 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
953 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100954
Malcolm Priestley92928f12013-10-07 20:14:01 +0100955 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100956 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100957
Malcolm Priestley92928f12013-10-07 20:14:01 +0100958 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
959 PK_TYPE_11B, cbFrameSize, wCurrentRate,
960 bNeedACK);
961
962 /* Fill RTS */
963 return s_vFillRTSHead(pDevice, byPktType, head,
964 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100965 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100966 } else {
967 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
968 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100969
Malcolm Priestley92928f12013-10-07 20:14:01 +0100970 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
971 PK_TYPE_11B, cbFrameSize,
972 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100973
Malcolm Priestley92928f12013-10-07 20:14:01 +0100974 return vnt_rxtx_datahead_ab(pDevice, byPktType,
975 wCurrentRate, &head->data_head_ab,
976 cbFrameSize, bNeedACK);
977 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100978 }
979
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100980 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400981}
982/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500983 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500984 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300985 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400986*/
987
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000988static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100989 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100990 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
991 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
992 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400993{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100994 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000995 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
996 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000997 u32 cb802_1_H_len;
998 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
999 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001000 int bNeedACK;
1001 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001002 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1003 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1004 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1005 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1006 u32 uDuration;
1007 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001008 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001009 u8 byFBOption = AUTO_FB_NONE, byFragType;
1010 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +01001011 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001012 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001013 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001014
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001015 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001016
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001017 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001018 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1019 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001020 }
Forest Bond92b96792009-06-13 07:38:31 -04001021
Forest Bond92b96792009-06-13 07:38:31 -04001022 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001023 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001024 if (pDevice->dwDiagRefCount == 0) {
1025 cb802_1_H_len = 8;
1026 } else {
1027 cb802_1_H_len = 2;
1028 }
1029 } else {
1030 cb802_1_H_len = 0;
1031 }
1032
Charles Clément21ec51f2010-05-18 10:08:14 -07001033 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001034
1035 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001036 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001037
1038 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001039 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001040 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1041 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001042 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1043 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001044 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001045 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001046 pTxBufHead->wFIFOCtl =
1047 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1048 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001049 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001050 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1051 }
Forest Bond92b96792009-06-13 07:38:31 -04001052 }
1053 else {
1054 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001055 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001056 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1057 }
1058 } //if (pDevice->dwDiagRefCount != 0) {
1059
1060 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1061
1062 //Set FIFOCTL_LHEAD
1063 if (pDevice->bLongHeader)
1064 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1065
Forest Bond92b96792009-06-13 07:38:31 -04001066 //Set FRAGCTL_MACHDCNT
1067 if (pDevice->bLongHeader) {
1068 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1069 } else {
1070 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1071 }
Andres More3eaca0d2013-02-25 20:32:52 -05001072 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001073
1074 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001075 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001076 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1077 }
1078
1079 //Set Auto Fallback Ctl
1080 if (wCurrentRate >= RATE_18M) {
1081 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1082 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1083 byFBOption = AUTO_FB_0;
1084 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1085 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1086 byFBOption = AUTO_FB_1;
1087 }
1088 }
1089
Andres More4e9b5e22013-02-12 20:36:30 -05001090 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001091 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1092 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1093 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1094 }
1095 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1096 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1097 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1098 }
1099 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1100 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1101 }
1102 }
1103 }
1104
Forest Bond92b96792009-06-13 07:38:31 -04001105 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1106 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1107 cbIVlen = 4;
1108 cbICVlen = 4;
1109 }
1110 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1111 cbIVlen = 8;//IV+ExtIV
1112 cbMIClen = 8;
1113 cbICVlen = 4;
1114 }
1115 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1116 cbIVlen = 8;//RSN Header
1117 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001118 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001119 }
Andres Moree269fc22013-02-12 20:36:29 -05001120 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001121 //MAC Header should be padding 0 to DW alignment.
1122 uPadding = 4 - (cbMACHdLen%4);
1123 uPadding %= 4;
1124 }
1125 }
1126
1127 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1128
Andres Moree269fc22013-02-12 20:36:29 -05001129 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1130 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001131 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001132 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001133 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1134 }
1135
Andres Moreb902fbf2013-02-25 20:32:51 -05001136 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001137 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1138
Forest Bond92b96792009-06-13 07:38:31 -04001139 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1140 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001141 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001142 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001143 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001144 }
1145 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001146 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001147 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001148 }
1149 } else {
1150 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001151 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001152 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001153 cbMICHDR + sizeof(struct vnt_rts_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 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001157 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001158 }
1159 } // Auto Fall Back
1160 }
1161 else {//802.11a/b packet
1162 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001163 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001164 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001165 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001166 }
Andres Moree269fc22013-02-12 20:36:29 -05001167 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001168 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001169 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001170 }
1171 } else {
1172 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001173 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001174 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001175 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001176 }
Andres Moree269fc22013-02-12 20:36:29 -05001177 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001178 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001179 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001180 }
1181 } // Auto Fall Back
1182 }
1183
Andres Moreb902fbf2013-02-25 20:32:51 -05001184 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1185 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1186 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001187
Forest Bond92b96792009-06-13 07:38:31 -04001188 //=========================
1189 // No Fragmentation
1190 //=========================
1191 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1192 byFragType = FRAGCTL_NONFRAG;
1193 //uDMAIdx = TYPE_AC0DMA;
1194 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1195
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001196 /* Fill FIFO, RrvTime, RTS and CTS */
1197 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1198 tx_buffer, &pMICHDR, cbMICHDR,
1199 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001200
Forest Bond92b96792009-06-13 07:38:31 -04001201 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001202 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001203 byFragType, uDMAIdx, 0);
1204
Andres More4e9b5e22013-02-12 20:36:30 -05001205 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001206 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001207 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001208 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001209
1210 if (pDevice->bEnableHostWEP) {
1211 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1212 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1213 }
1214 }
1215
1216 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001217 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001218 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001219 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1220 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001221 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001222 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001223 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001224 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001225 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001226 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001227 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001228 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001229 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001230
1231 }
1232
1233 }
1234
Forest Bond92b96792009-06-13 07:38:31 -04001235 if (pPacket != NULL) {
1236 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001237 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001238 (pPacket + ETH_HLEN),
1239 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001240 );
1241
1242 } else {
1243 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001244 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001245 }
1246
Andres More4e9b5e22013-02-12 20:36:30 -05001247 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001248
1249 ///////////////////////////////////////////////////////////////////
1250
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001251 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1252 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1253 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1254 }
Forest Bond92b96792009-06-13 07:38:31 -04001255 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001256 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1257 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001258 }
1259 else {
Andres More52a7e642013-02-25 20:32:53 -05001260 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1261 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001262 }
1263 // DO Software Michael
1264 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001265 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001266 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001267 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001268 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1269 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001270
1271 ///////////////////////////////////////////////////////////////////
1272
1273 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1274 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001275 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001276 //}
1277 //DBG_PRN_GRP12(("\n\n\n"));
1278
1279 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1280
Andres More52a7e642013-02-25 20:32:53 -05001281 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1282 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001283
1284 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1285 MIC_vUnInit();
1286
Andres More4e9b5e22013-02-12 20:36:30 -05001287 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001288 *pdwMIC_L = 0;
1289 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001290 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001291 }
1292 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1293 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1294 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1295 }
1296
Andres More4e9b5e22013-02-12 20:36:30 -05001297 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001298
Andres More3eaca0d2013-02-25 20:32:52 -05001299 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001300
Andres More4e9b5e22013-02-12 20:36:30 -05001301 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1302 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1303 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001304 cbFrameSize -= cbICVlen;
1305 }
1306
Forest Bond92b96792009-06-13 07:38:31 -04001307 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001308
1309 *pcbHeaderLen = cbHeaderLength;
1310 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1311
Forest Bond92b96792009-06-13 07:38:31 -04001312 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001313 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001314
Andres More4e9b5e22013-02-12 20:36:30 -05001315 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001316
1317}
1318
Forest Bond92b96792009-06-13 07:38:31 -04001319/*+
1320 *
1321 * Description:
1322 * Translate 802.3 to 802.11 header
1323 *
1324 * Parameters:
1325 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001326 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001327 * dwTxBufferAddr - Transmit Buffer
1328 * pPacket - Packet from upper layer
1329 * cbPacketSize - Transmit Data Length
1330 * Out:
1331 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1332 * pcbAppendPayload - size of append payload for 802.1H translation
1333 *
1334 * Return Value: none
1335 *
1336-*/
1337
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001338static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001339 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001340 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001341{
Andres More1cac4a42013-03-18 20:33:50 -05001342 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001343
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001344 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001345
1346 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001347 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001348 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001349 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001350 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1351 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001352 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001353 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001354 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001355 } else {
1356 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001357 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001358 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001359 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001360 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001361 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001362 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001363 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001364 &(pDevice->abyBSSID[0]),
1365 ETH_ALEN);
1366 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001367 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001368 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001369 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001370 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001371 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001372 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001373 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001374 &(pDevice->abyBSSID[0]),
1375 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001376 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001377 }
1378 }
1379
1380 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001381 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001382
Andres More1cac4a42013-03-18 20:33:50 -05001383 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001384
1385 if (pDevice->bLongHeader) {
1386 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001387 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001388 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001389 }
Andres More1cac4a42013-03-18 20:33:50 -05001390 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001391
1392 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001393 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001394
1395 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1396 pDevice->wSeqCounter++;
1397 if (pDevice->wSeqCounter > 0x0fff)
1398 pDevice->wSeqCounter = 0;
1399 }
1400
1401 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001402 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001403 }
1404}
1405
Forest Bond92b96792009-06-13 07:38:31 -04001406/*+
1407 *
1408 * Description:
1409 * Request instructs a MAC to transmit a 802.11 management packet through
1410 * the adapter onto the medium.
1411 *
1412 * Parameters:
1413 * In:
1414 * hDeviceContext - Pointer to the adapter
1415 * pPacket - A pointer to a descriptor for the packet to transmit
1416 * Out:
1417 * none
1418 *
Andres Moree269fc22013-02-12 20:36:29 -05001419 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001420 *
1421-*/
1422
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001423CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1424 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001425{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001426 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001427 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001428 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001429 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001430 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001431 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001432 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001433 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001434 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001435 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001436 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1437 u32 uPadding = 0;
1438 u16 wTxBufSize;
1439 u32 cbMacHdLen;
1440 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001441
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001442 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001443
1444 if (NULL == pContext) {
1445 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1446 return CMD_STATUS_RESOURCES;
1447 }
1448
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001449 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001450 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001451 pTxBufHead = &pTX_Buffer->fifo_head;
1452 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1453 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001454
1455 if (pDevice->byBBType == BB_TYPE_11A) {
1456 wCurrentRate = RATE_6M;
1457 byPktType = PK_TYPE_11A;
1458 } else {
1459 wCurrentRate = RATE_1M;
1460 byPktType = PK_TYPE_11B;
1461 }
1462
1463 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1464 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1465 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1466 // to set power here.
1467 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1468 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1469 } else {
1470 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1471 }
1472 pDevice->wCurrentRate = wCurrentRate;
1473
Forest Bond92b96792009-06-13 07:38:31 -04001474 //Set packet type
1475 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1476 pTxBufHead->wFIFOCtl = 0;
1477 }
1478 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1479 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1480 }
1481 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1482 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1483 }
1484 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1485 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1486 }
1487
1488 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1489 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1490
Andres More22040bb2010-08-02 20:21:44 -03001491 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001492 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001493 }
1494 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001495 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001496 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1497 };
1498
1499 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1500 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1501
1502 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1503 //Set Preamble type always long
1504 //pDevice->byPreambleType = PREAMBLE_LONG;
1505 // probe-response don't retry
1506 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001507 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001508 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1509 //}
1510 }
1511
1512 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1513
1514 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001515 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001516 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1517 } else {
1518 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1519 }
1520
1521 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001522 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001523
1524 // Notes:
1525 // Although spec says MMPDU can be fragmented; In most case,
1526 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001527 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001528
1529 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1530 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1531 cbIVlen = 4;
1532 cbICVlen = 4;
1533 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1534 }
1535 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1536 cbIVlen = 8;//IV+ExtIV
1537 cbMIClen = 8;
1538 cbICVlen = 4;
1539 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1540 //We need to get seed here for filling TxKey entry.
1541 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1542 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1543 }
1544 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1545 cbIVlen = 8;//RSN Header
1546 cbICVlen = 8;//MIC
1547 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001548 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001549 }
1550 //MAC Header should be padding 0 to DW alignment.
1551 uPadding = 4 - (cbMacHdLen%4);
1552 uPadding %= 4;
1553 }
1554
1555 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1556
1557 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001558 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001559 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1560 }
1561 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1562
1563 //Set RrvTime/RTS/CTS Buffer
1564 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001565 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001566 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001567 }
1568 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001569 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001570 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001571 }
1572
Andres Moreceb8c5d2013-03-18 20:33:49 -05001573 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001574 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1575 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001576 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001577 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1578 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001579 //=========================
1580 // No Fragmentation
1581 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001582 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001583
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001584 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001585 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001586 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001587 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001588
Andres More1cac4a42013-03-18 20:33:50 -05001589 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001590
1591 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1592
1593 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001594 u8 * pbyIVHead;
1595 u8 * pbyPayloadHead;
1596 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001597 PSKeyItem pTransmitKey = NULL;
1598
Andres Moreb902fbf2013-02-25 20:32:51 -05001599 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1600 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001601 do {
1602 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001603 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001604 pbyBSSID = pDevice->abyBSSID;
1605 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001606 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001607 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001608 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001609 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1610 break;
1611 }
1612 } else {
1613 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1614 break;
1615 }
1616 }
1617 // get group key
1618 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001619 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001620 pTransmitKey = NULL;
1621 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1622 } else {
1623 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1624 }
Andres Moree269fc22013-02-12 20:36:29 -05001625 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001626 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001627 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001628 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001629
Jim Lieb3e362592009-08-12 14:54:11 -07001630 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001631 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001632 cbFrameBodySize);
1633 }
1634 else {
1635 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001636 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001637 }
1638
Andres More1cac4a42013-03-18 20:33:50 -05001639 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001640 pDevice->wSeqCounter++ ;
1641 if (pDevice->wSeqCounter > 0x0fff)
1642 pDevice->wSeqCounter = 0;
1643
1644 if (bIsPSPOLL) {
1645 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001646 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001647 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1648 // in the same place of other packet's Duration-field).
1649 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001650 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001651 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1652 tx_cts.tx.head.cts_g.data_head;
1653 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001654 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001655 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001656 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1657 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001658 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1659 tx_ab.tx.head.data_head_ab;
1660 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001661 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1662 }
Forest Bond92b96792009-06-13 07:38:31 -04001663 }
1664
Andres More3eaca0d2013-02-25 20:32:52 -05001665 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001666 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001667 pTX_Buffer->byType = 0x00;
1668
1669 pContext->pPacket = NULL;
1670 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001671 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001672
Andres More1cac4a42013-03-18 20:33:50 -05001673 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001674 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1675 &pMACHeader->addr1[0], (u16)cbFrameSize,
1676 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001677 }
1678 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001679 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1680 &pMACHeader->addr3[0], (u16)cbFrameSize,
1681 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001682 }
1683
1684 PIPEnsSendBulkOut(pDevice,pContext);
1685 return CMD_STATUS_PENDING;
1686}
1687
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001688CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1689 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001690{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001691 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001692 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1693 u32 cbHeaderSize = 0;
1694 u16 wTxBufSize = sizeof(STxShortBufHead);
1695 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001696 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001697 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001698 u16 wCurrentRate;
1699 u32 cbFrameBodySize;
1700 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001701 u8 *pbyTxBufferAddr;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001702 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001703 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001704
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001705 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001706 if (NULL == pContext) {
1707 status = CMD_STATUS_RESOURCES;
1708 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1709 return status ;
1710 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001711
1712 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001713 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001714
1715 cbFrameBodySize = pPacket->cbPayloadLen;
1716
1717 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1718 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001719
1720 if (pDevice->byBBType == BB_TYPE_11A) {
1721 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001722 pTxDataHead = (struct vnt_tx_datahead_ab *)
1723 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001724 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001725 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1726 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001727 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001728 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001729 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001730 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001731 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001732 } else {
1733 wCurrentRate = RATE_1M;
1734 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001735 pTxDataHead = (struct vnt_tx_datahead_ab *)
1736 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001737 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001738 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1739 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001740 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001741 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001742 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001743 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001744 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001745 }
1746
1747 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001748 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001749 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001750
Andres More1cac4a42013-03-18 20:33:50 -05001751 pMACHeader->duration_id = 0;
1752 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001753 pDevice->wSeqCounter++ ;
1754 if (pDevice->wSeqCounter > 0x0fff)
1755 pDevice->wSeqCounter = 0;
1756
1757 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1758
Andres More3eaca0d2013-02-25 20:32:52 -05001759 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001760 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001761 pTX_Buffer->byType = 0x01;
1762
1763 pContext->pPacket = NULL;
1764 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001765 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001766
1767 PIPEnsSendBulkOut(pDevice,pContext);
1768 return CMD_STATUS_PENDING;
1769
1770}
1771
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001772void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1773{
1774 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001775 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001776 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001777 u8 byPktType;
1778 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001779 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001780 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001781 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001782 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001783 u32 cbFrameSize;
1784 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1785 u32 uPadding = 0;
1786 u32 cbMICHDR = 0, uLength = 0;
1787 u32 dwMICKey0, dwMICKey1;
1788 u32 dwMIC_Priority;
1789 u32 *pdwMIC_L, *pdwMIC_R;
1790 u16 wTxBufSize;
1791 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001792 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001793 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001794 u32 wCurrentRate = RATE_1M;
1795 PUWLAN_80211HDR p80211Header;
1796 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001797 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001798 SKeyItem STempKey;
1799 PSKeyItem pTransmitKey = NULL;
1800 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1801 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001802 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001803
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001804 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001805
1806 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1807 cbFrameBodySize = 0;
1808 }
1809 else {
1810 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1811 }
1812 p80211Header = (PUWLAN_80211HDR)skb->data;
1813
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001814 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001815
1816 if (NULL == pContext) {
1817 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1818 dev_kfree_skb_irq(skb);
1819 return ;
1820 }
1821
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001822 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001823 pTxBufHead = &pTX_Buffer->fifo_head;
1824 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1825 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001826
1827 if (pDevice->byBBType == BB_TYPE_11A) {
1828 wCurrentRate = RATE_6M;
1829 byPktType = PK_TYPE_11A;
1830 } else {
1831 wCurrentRate = RATE_1M;
1832 byPktType = PK_TYPE_11B;
1833 }
1834
1835 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1836 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1837 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1838 // to set power here.
1839 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1840 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1841 } else {
1842 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1843 }
1844
1845 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1846
1847 //Set packet type
1848 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1849 pTxBufHead->wFIFOCtl = 0;
1850 }
1851 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1852 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1853 }
1854 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1855 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1856 }
1857 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1858 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1859 }
1860
1861 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1862 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1863
Andres More22040bb2010-08-02 20:21:44 -03001864 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001865 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001866 if (pDevice->bEnableHostWEP) {
1867 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001868 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001869 }
Forest Bond92b96792009-06-13 07:38:31 -04001870 }
1871 else {
1872 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001873 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001874 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001875 }
Andres More4e9b5e22013-02-12 20:36:30 -05001876 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001877 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1878 };
1879
1880 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1881 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1882
1883 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1884 //Set Preamble type always long
1885 //pDevice->byPreambleType = PREAMBLE_LONG;
1886
1887 // probe-response don't retry
1888 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001889 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001890 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1891 //}
1892 }
1893
1894 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1895
1896 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001897 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001898 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1899 } else {
1900 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1901 }
1902
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001903 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001904 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1905
1906 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1907 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1908 }
1909
1910 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1911 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1912 }
1913
1914 if (cbExtSuppRate >0) {
1915 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1916 }
1917 }
1918
Forest Bond92b96792009-06-13 07:38:31 -04001919 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001920 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001921
1922 // Notes:
1923 // Although spec says MMPDU can be fragmented; In most case,
1924 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001925 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001926
Forest Bond92b96792009-06-13 07:38:31 -04001927 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1928 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1929 cbIVlen = 4;
1930 cbICVlen = 4;
1931 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1932 }
1933 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1934 cbIVlen = 8;//IV+ExtIV
1935 cbMIClen = 8;
1936 cbICVlen = 4;
1937 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1938 //We need to get seed here for filling TxKey entry.
1939 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1940 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1941 }
1942 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1943 cbIVlen = 8;//RSN Header
1944 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001945 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001946 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001947 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001948 }
1949 //MAC Header should be padding 0 to DW alignment.
1950 uPadding = 4 - (cbMacHdLen%4);
1951 uPadding %= 4;
1952 }
1953
1954 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1955
1956 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001957 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001958 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1959 }
1960 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1961
Forest Bond92b96792009-06-13 07:38:31 -04001962 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001963 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001964 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001965
1966 }
1967 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001968 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001969 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001970 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001971 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001972 &(p80211Header->sA3.abyAddr1[0]),
1973 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001974 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001975 &(p80211Header->sA3.abyAddr2[0]),
1976 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001977 //=========================
1978 // No Fragmentation
1979 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001980 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001981
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001982 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001983 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001984 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001985 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001986
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001987 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001988
1989 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1990
Andres Moreb902fbf2013-02-25 20:32:51 -05001991 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1992 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1993 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001994
1995 // Copy the Packet into a tx Buffer
1996 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1997
1998 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001999 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002000 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2001
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002002 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002003 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2004 if (cbExtSuppRate != 0) {
2005 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2006 memcpy((pbyPayloadHead + cbFrameBodySize),
2007 pMgmt->abyCurrSuppRates,
2008 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2009 );
2010 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2011 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2012 pMgmt->abyCurrExtSuppRates,
2013 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2014 );
2015 }
2016 }
2017
2018 // Set wep
2019 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2020
2021 if (pDevice->bEnableHostWEP) {
2022 pTransmitKey = &STempKey;
2023 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2024 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2025 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2026 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2027 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2028 memcpy(pTransmitKey->abyKey,
2029 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2030 pTransmitKey->uKeyLength
2031 );
2032 }
2033
2034 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2035
Andres More52a7e642013-02-25 20:32:53 -05002036 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2037 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002038
2039 // DO Software Michael
2040 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002041 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002042 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002043 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002044 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2045 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002046
2047 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2048
2049 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2050
Andres More52a7e642013-02-25 20:32:53 -05002051 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2052 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002053
2054 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2055 MIC_vUnInit();
2056
Andres More4e9b5e22013-02-12 20:36:30 -05002057 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002058 *pdwMIC_L = 0;
2059 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002060 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002061 }
2062
2063 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2064 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002065 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2066 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002067
2068 }
2069
Andres Moreb902fbf2013-02-25 20:32:51 -05002070 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002071 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002072
2073 if (pDevice->bEnableHostWEP) {
2074 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2075 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2076 }
2077
2078 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002079 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002080 }
2081 }
2082
Andres More1cac4a42013-03-18 20:33:50 -05002083 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002084 pDevice->wSeqCounter++ ;
2085 if (pDevice->wSeqCounter > 0x0fff)
2086 pDevice->wSeqCounter = 0;
2087
Forest Bond92b96792009-06-13 07:38:31 -04002088 if (bIsPSPOLL) {
2089 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2090 // of FIFO control header.
2091 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2092 // in the same place of other packet's Duration-field).
2093 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002094 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002095 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2096 tx_cts.tx.head.cts_g.data_head;
2097 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002098 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002099 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002100 cpu_to_le16(p80211Header->sA2.wDurationID);
2101 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002102 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2103 tx_ab.tx.head.data_head_ab;
2104 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002105 cpu_to_le16(p80211Header->sA2.wDurationID);
2106 }
Forest Bond92b96792009-06-13 07:38:31 -04002107 }
2108
Andres More3eaca0d2013-02-25 20:32:52 -05002109 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002110 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002111 pTX_Buffer->byType = 0x00;
2112
2113 pContext->pPacket = skb;
2114 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002115 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002116
Andres More1cac4a42013-03-18 20:33:50 -05002117 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002118 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2119 &pMACHeader->addr1[0], (u16)cbFrameSize,
2120 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002121 }
2122 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002123 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2124 &pMACHeader->addr3[0], (u16)cbFrameSize,
2125 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002126 }
2127 PIPEnsSendBulkOut(pDevice,pContext);
2128 return ;
2129
2130}
2131
Forest Bond92b96792009-06-13 07:38:31 -04002132//TYPE_AC0DMA data tx
2133/*
2134 * Description:
2135 * Tx packet via AC0DMA(DMA1)
2136 *
2137 * Parameters:
2138 * In:
2139 * pDevice - Pointer to the adapter
2140 * skb - Pointer to tx skb packet
2141 * Out:
2142 * void
2143 *
2144 * Return Value: NULL
2145 */
2146
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002147int nsDMA_tx_packet(struct vnt_private *pDevice,
2148 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002149{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002150 struct net_device_stats *pStats = &pDevice->stats;
2151 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002152 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002153 u32 BytesToWrite = 0, uHeaderLen = 0;
2154 u32 uNodeIndex = 0;
2155 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2156 u16 wAID;
2157 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002158 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002159 PSKeyItem pTransmitKey = NULL;
2160 SKeyItem STempKey;
2161 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002162 int bTKIP_UseGTK = false;
2163 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002164 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002165 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002166 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002167 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002168 u32 status;
2169 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002170 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002171
Forest Bond92b96792009-06-13 07:38:31 -04002172 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2173
2174 if (pDevice->uAssocCount == 0) {
2175 dev_kfree_skb_irq(skb);
2176 return 0;
2177 }
2178
Andres Moreb902fbf2013-02-25 20:32:51 -05002179 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002180 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002181 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002182 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2183
2184 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2185 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2186 // set tx map
2187 pMgmt->abyPSTxMap[0] |= byMask[0];
2188 return 0;
2189 }
Masanari Iida93184692012-08-13 21:21:50 +09002190 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002191
2192 if (pDevice->byBBType != BB_TYPE_11A)
2193 pDevice->wCurrentRate = RATE_2M;
2194 else
2195 pDevice->wCurrentRate = RATE_24M;
2196 // long preamble type
2197 pDevice->byPreambleType = PREAMBLE_SHORT;
2198
2199 }else {
2200
Andres Moreb902fbf2013-02-25 20:32:51 -05002201 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002202
2203 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2204
2205 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2206
2207 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2208 // set tx map
2209 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2210 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2212 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2213
2214 return 0;
2215 }
2216 // AP rate decided from node
2217 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2218 // tx preamble decided from node
2219
2220 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2221 pDevice->byPreambleType = pDevice->byShortPreamble;
2222
2223 }else {
2224 pDevice->byPreambleType = PREAMBLE_LONG;
2225 }
Andres More4e9b5e22013-02-12 20:36:30 -05002226 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002227 }
2228 }
2229
Andres Moree269fc22013-02-12 20:36:29 -05002230 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002231 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2232 dev_kfree_skb_irq(skb);
2233 return 0;
2234 }
2235 }
2236
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002237 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002238
2239 if (pContext == NULL) {
2240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2241 dev_kfree_skb_irq(skb);
2242 return STATUS_RESOURCES;
2243 }
2244
Andres Moreceb8c5d2013-03-18 20:33:49 -05002245 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002246
2247//mike add:station mode check eapol-key challenge--->
2248{
Andres Moreb902fbf2013-02-25 20:32:51 -05002249 u8 Protocol_Version; //802.1x Authentication
2250 u8 Packet_Type; //802.1x Authentication
2251 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002252 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002253
Charles Clément21ec51f2010-05-18 10:08:14 -07002254 Protocol_Version = skb->data[ETH_HLEN];
2255 Packet_Type = skb->data[ETH_HLEN+1];
2256 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2257 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 -05002258 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002259 /* 802.1x OR eapol-key challenge frame transfer */
2260 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2261 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002262 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002263 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2264 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2265 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002266 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002267 PRINT_K("WPA ");
2268 }
2269 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002270 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002271 PRINT_K("WPA2(re-keying) ");
2272 }
2273 PRINT_K("Authentication completed!!\n");
2274 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002275 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002276 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002277 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002278 PRINT_K("WPA2 Authentication completed!!\n");
2279 }
2280 }
2281 }
2282}
2283//mike add:station mode check eapol-key challenge<---
2284
Andres More4e9b5e22013-02-12 20:36:30 -05002285 if (pDevice->bEncryptionEnable == true) {
2286 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002287 // get Transmit key
2288 do {
2289 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2290 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2291 pbyBSSID = pDevice->abyBSSID;
2292 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002293 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002294 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002295 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2296 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002297 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2298 break;
2299 }
2300 } else {
2301 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2302 break;
2303 }
2304 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002305 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2306 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002307 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2308 for (ii = 0; ii< 6; ii++)
2309 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2310 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2311
2312 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002313 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002314 break;
2315 }
2316 // get group key
2317 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002318 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002319 pTransmitKey = NULL;
2320 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2321 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2322 }
2323 else
2324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2325 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002326 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002327 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2328 }
Andres Moree269fc22013-02-12 20:36:29 -05002329 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002330 }
2331
2332 if (pDevice->bEnableHostWEP) {
2333 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002334 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002335 pTransmitKey = &STempKey;
2336 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2337 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2338 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2339 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2340 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2341 memcpy(pTransmitKey->abyKey,
2342 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2343 pTransmitKey->uKeyLength
2344 );
2345 }
2346 }
2347
Andres Moreb902fbf2013-02-25 20:32:51 -05002348 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002349
2350 if (pDevice->bFixRate) {
2351 if (pDevice->byBBType == BB_TYPE_11B) {
2352 if (pDevice->uConnectionRate >= RATE_11M) {
2353 pDevice->wCurrentRate = RATE_11M;
2354 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002355 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002356 }
2357 } else {
2358 if ((pDevice->byBBType == BB_TYPE_11A) &&
2359 (pDevice->uConnectionRate <= RATE_6M)) {
2360 pDevice->wCurrentRate = RATE_6M;
2361 } else {
2362 if (pDevice->uConnectionRate >= RATE_54M)
2363 pDevice->wCurrentRate = RATE_54M;
2364 else
Andres More3eaca0d2013-02-25 20:32:52 -05002365 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002366 }
2367 }
2368 }
2369 else {
2370 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2371 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002372 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002373 // Multicast use highest data rate
2374 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2375 // preamble type
2376 pDevice->byPreambleType = pDevice->byShortPreamble;
2377 }
2378 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002379 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002380 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2381 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2382 pDevice->byPreambleType = pDevice->byShortPreamble;
2383
2384 }
2385 else {
2386 pDevice->byPreambleType = PREAMBLE_LONG;
2387 }
2388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2389 }
2390 else {
2391 if (pDevice->byBBType != BB_TYPE_11A)
2392 pDevice->wCurrentRate = RATE_2M;
2393 else
2394 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2395 // abyCurrExtSuppRates[]
2396 pDevice->byPreambleType = PREAMBLE_SHORT;
2397 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2398 }
2399 }
2400 }
2401 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2402 // Infra STA rate decided from AP Node, index = 0
2403 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2404 }
2405 }
2406
Andres Moreceb8c5d2013-03-18 20:33:49 -05002407 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002408 if (pDevice->byBBType != BB_TYPE_11A) {
2409 pDevice->wCurrentRate = RATE_1M;
2410 pDevice->byACKRate = RATE_1M;
2411 pDevice->byTopCCKBasicRate = RATE_1M;
2412 pDevice->byTopOFDMBasicRate = RATE_6M;
2413 } else {
2414 pDevice->wCurrentRate = RATE_6M;
2415 pDevice->byACKRate = RATE_6M;
2416 pDevice->byTopCCKBasicRate = RATE_1M;
2417 pDevice->byTopOFDMBasicRate = RATE_6M;
2418 }
2419 }
Forest Bond92b96792009-06-13 07:38:31 -04002420
Andres More0cbd8d92010-05-06 20:34:29 -03002421 DBG_PRT(MSG_LEVEL_DEBUG,
2422 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2423 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002424
2425 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002426 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002427 }
2428
2429 if (pDevice->wCurrentRate <= RATE_11M) {
2430 byPktType = PK_TYPE_11B;
2431 }
2432
Andres More4e9b5e22013-02-12 20:36:30 -05002433 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002434 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2435 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002436 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002438 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2439 if (pTransmitKey == NULL) {
2440 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2441 }
2442 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002443 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002444 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2445 }
2446 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002447 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2448 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002449 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002450 }
2451 }
2452 }
2453
Forest Bond92b96792009-06-13 07:38:31 -04002454 if (pDevice->bEnableHostWEP) {
2455 if ((uNodeIndex != 0) &&
2456 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002457 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2458 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002459 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002460 }
2461 }
2462 }
2463 else {
2464
Forest Bond92b96792009-06-13 07:38:31 -04002465 if (pTransmitKey == NULL) {
2466 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002467 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002468 dev_kfree_skb_irq(skb);
2469 pStats->tx_dropped++;
2470 return STATUS_FAILURE;
2471 }
Forest Bond92b96792009-06-13 07:38:31 -04002472 }
2473 }
2474
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002475 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2476
Forest Bond92b96792009-06-13 07:38:31 -04002477 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002478 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002479 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002480 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002481 pDevice->wCurrentRate,
2482 &uHeaderLen, &BytesToWrite
2483 );
2484
Andres Moree269fc22013-02-12 20:36:29 -05002485 if (fConvertedPacket == false) {
2486 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002487 dev_kfree_skb_irq(skb);
2488 return STATUS_FAILURE;
2489 }
2490
Andres More4e9b5e22013-02-12 20:36:30 -05002491 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002492 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002493 bScheduleCommand((void *) pDevice,
2494 WLAN_CMD_MAC_DISPOWERSAVING,
2495 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002496 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002497 }
2498 }
2499
Andres Moreb902fbf2013-02-25 20:32:51 -05002500 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002501 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002502
2503 pContext->pPacket = skb;
2504 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002505 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002506
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002507 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2508 &pContext->sEthHeader.h_dest[0],
2509 (u16)(BytesToWrite-uHeaderLen),
2510 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002511
2512 status = PIPEnsSendBulkOut(pDevice,pContext);
2513
Andres More4e9b5e22013-02-12 20:36:30 -05002514 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002515 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002516
Andres Moreb902fbf2013-02-25 20:32:51 -05002517 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002518 }
2519
2520 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002521 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002522 dev_kfree_skb_irq(skb);
2523 return STATUS_FAILURE;
2524 }
2525 else
2526 return 0;
2527
2528}
2529
Forest Bond92b96792009-06-13 07:38:31 -04002530/*
2531 * Description:
2532 * Relay packet send (AC1DMA) from rx dpc.
2533 *
2534 * Parameters:
2535 * In:
2536 * pDevice - Pointer to the adapter
2537 * pPacket - Pointer to rx packet
2538 * cbPacketSize - rx ethernet frame size
2539 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002540 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002541 *
Andres More4e9b5e22013-02-12 20:36:30 -05002542 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002543 */
2544
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002545int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2546 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002547{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002548 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002549 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002550 u32 BytesToWrite = 0, uHeaderLen = 0;
2551 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002552 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002553 SKeyItem STempKey;
2554 PSKeyItem pTransmitKey = NULL;
2555 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002556 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002557 u8 byPktTyp;
2558 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002559 u32 status;
2560 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002561
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002562 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002563
2564 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002565 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002566 }
2567
Andres Moreceb8c5d2013-03-18 20:33:49 -05002568 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002569
Andres More4e9b5e22013-02-12 20:36:30 -05002570 if (pDevice->bEncryptionEnable == true) {
2571 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002572 // get group key
2573 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002574 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002575 pTransmitKey = NULL;
2576 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2577 } else {
2578 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2579 }
2580 }
2581
2582 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002583 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002584 pTransmitKey = &STempKey;
2585 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2586 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2587 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2588 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2589 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2590 memcpy(pTransmitKey->abyKey,
2591 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2592 pTransmitKey->uKeyLength
2593 );
2594 }
2595 }
2596
2597 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002598 pContext->bBoolInUse = false;
2599 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002600 }
2601
Andres Moreb902fbf2013-02-25 20:32:51 -05002602 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002603
2604 if (pDevice->bFixRate) {
2605 if (pDevice->byBBType == BB_TYPE_11B) {
2606 if (pDevice->uConnectionRate >= RATE_11M) {
2607 pDevice->wCurrentRate = RATE_11M;
2608 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002609 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002610 }
2611 } else {
2612 if ((pDevice->byBBType == BB_TYPE_11A) &&
2613 (pDevice->uConnectionRate <= RATE_6M)) {
2614 pDevice->wCurrentRate = RATE_6M;
2615 } else {
2616 if (pDevice->uConnectionRate >= RATE_54M)
2617 pDevice->wCurrentRate = RATE_54M;
2618 else
Andres More3eaca0d2013-02-25 20:32:52 -05002619 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002620 }
2621 }
2622 }
2623 else {
2624 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2625 }
2626
Forest Bond92b96792009-06-13 07:38:31 -04002627 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002628 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002629 }
2630
2631 if (pDevice->wCurrentRate <= RATE_11M)
2632 byPktType = PK_TYPE_11B;
2633
Andres Moreabad19d2010-07-12 16:28:32 -03002634 BytesToWrite = uDataLen + ETH_FCS_LEN;
2635
Forest Bond92b96792009-06-13 07:38:31 -04002636 // Convert the packet to an usb frame and copy into our buffer
2637 // and send the irp.
2638
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002639 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2640
Forest Bond92b96792009-06-13 07:38:31 -04002641 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002642 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002643 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2644 pbySkbData, pTransmitKey, uNodeIndex,
2645 pDevice->wCurrentRate,
2646 &uHeaderLen, &BytesToWrite
2647 );
2648
Andres Moree269fc22013-02-12 20:36:29 -05002649 if (fConvertedPacket == false) {
2650 pContext->bBoolInUse = false;
2651 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002652 }
2653
Andres Moreb902fbf2013-02-25 20:32:51 -05002654 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002655 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002656
2657 pContext->pPacket = NULL;
2658 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002659 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002660
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002661 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2662 &pContext->sEthHeader.h_dest[0],
2663 (u16)(BytesToWrite - uHeaderLen),
2664 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002665
2666 status = PIPEnsSendBulkOut(pDevice,pContext);
2667
Andres More4e9b5e22013-02-12 20:36:30 -05002668 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002669}
2670