blob: 93eba18a1b9952076c912da68a71848f6e5f7ae3 [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
838 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
Forest Bond92b96792009-06-13 07:38:31 -0400839 pFifoHead->wReserved = wCurrentRate;
840 wFifoCtl = pFifoHead->wFIFOCtl;
841
Forest Bond92b96792009-06-13 07:38:31 -0400842 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
843 byFBOption = AUTO_FB_0;
844 }
845 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
846 byFBOption = AUTO_FB_1;
847 }
848
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100849 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100850 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100851
Forest Bond92b96792009-06-13 07:38:31 -0400852 if (pDevice->bLongHeader)
853 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
854
855 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100856 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400857 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100858 struct vnt_rrv_time_rts *pBuf = &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100859
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100860 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
861 byPktType, cbFrameSize, wCurrentRate);
862 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
863 byPktType, cbFrameSize, wCurrentRate);
864 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
865 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100866 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
867 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
868 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
869 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
870 bNeedACK);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100871
872 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100873 *mic_hdr = &tx_buffer->tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100874 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
875 } else {
876 head = &tx_buffer->tx_head.tx_rts.tx.head;
877 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100878
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100879 /* Fill RTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100880 return s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100881 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400882 }
883 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400884 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100885 struct vnt_rrv_time_cts *pBuf = &tx_buffer->tx_head.tx_cts.cts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100886
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100887 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
888 cbFrameSize, wCurrentRate, bNeedACK);
889 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
890 PK_TYPE_11B, cbFrameSize,
891 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100892 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
893 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100894
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100895 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100896 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100897 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
898 } else {
899 head = &tx_buffer->tx_head.tx_cts.tx.head;
900 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100901
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100902 /* Fill CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100903 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType, head,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100904 cbFrameSize, bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400905 }
906 }
907 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100908 if (need_mic) {
909 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
910 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
911 } else {
912 head = &tx_buffer->tx_head.tx_ab.tx.head;
913 }
914
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100915 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400916 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100917 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100918
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100919 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
920 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100921 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
922 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100923
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100924 /* Fill RTS */
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100925 return s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100926 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100927 } else {
Forest Bond92b96792009-06-13 07:38:31 -0400928 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100929 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100930
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100931 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
932 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100933
934 return vnt_rxtx_datahead_a_fb(pDevice, byPktType, wCurrentRate,
935 &head->data_head_a_fb, cbFrameSize, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400936 }
937 }
938 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100939 if (need_mic) {
940 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
941 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
942 } else {
943 head = &tx_buffer->tx_head.tx_ab.tx.head;
944 }
945
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100946 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400947 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100948 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100949
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100950 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
951 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100952 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
953 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100954
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100955 /* Fill RTS */
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100956 return s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100957 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400958 }
959 else { //RTS_needless, non PCF mode
960 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100961 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100962
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100963 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
964 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100965
966 return vnt_rxtx_datahead_ab(pDevice, byPktType, wCurrentRate,
967 &head->data_head_ab, cbFrameSize, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400968 }
969 }
970 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100971
972 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400973}
974/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500975 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500976 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300977 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400978*/
979
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000980static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100981 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100982 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
983 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
984 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400985{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100986 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000987 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
988 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000989 u32 cb802_1_H_len;
990 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
991 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100992 int bNeedACK;
993 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000994 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
995 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
996 u8 abySNAP_Bridgetunnel[ETH_ALEN]
997 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
998 u32 uDuration;
999 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001000 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001001 u8 byFBOption = AUTO_FB_NONE, byFragType;
1002 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +01001003 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001004 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001005 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001006
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001007 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001008
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001009 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001010 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1011 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001012 }
Forest Bond92b96792009-06-13 07:38:31 -04001013
Forest Bond92b96792009-06-13 07:38:31 -04001014 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001015 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001016 if (pDevice->dwDiagRefCount == 0) {
1017 cb802_1_H_len = 8;
1018 } else {
1019 cb802_1_H_len = 2;
1020 }
1021 } else {
1022 cb802_1_H_len = 0;
1023 }
1024
Charles Clément21ec51f2010-05-18 10:08:14 -07001025 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001026
1027 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001028 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001029
1030 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001031 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001032 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1033 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001034 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1035 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001036 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001037 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001038 pTxBufHead->wFIFOCtl =
1039 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1040 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001041 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001042 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1043 }
Forest Bond92b96792009-06-13 07:38:31 -04001044 }
1045 else {
1046 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001047 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001048 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1049 }
1050 } //if (pDevice->dwDiagRefCount != 0) {
1051
1052 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1053
1054 //Set FIFOCTL_LHEAD
1055 if (pDevice->bLongHeader)
1056 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1057
Forest Bond92b96792009-06-13 07:38:31 -04001058 //Set FRAGCTL_MACHDCNT
1059 if (pDevice->bLongHeader) {
1060 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1061 } else {
1062 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1063 }
Andres More3eaca0d2013-02-25 20:32:52 -05001064 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001065
1066 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001067 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001068 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1069 }
1070
1071 //Set Auto Fallback Ctl
1072 if (wCurrentRate >= RATE_18M) {
1073 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1074 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1075 byFBOption = AUTO_FB_0;
1076 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1077 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1078 byFBOption = AUTO_FB_1;
1079 }
1080 }
1081
Andres More4e9b5e22013-02-12 20:36:30 -05001082 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001083 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1084 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1085 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1086 }
1087 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1088 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1089 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1090 }
1091 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1092 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1093 }
1094 }
1095 }
1096
Forest Bond92b96792009-06-13 07:38:31 -04001097 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1098 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1099 cbIVlen = 4;
1100 cbICVlen = 4;
1101 }
1102 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1103 cbIVlen = 8;//IV+ExtIV
1104 cbMIClen = 8;
1105 cbICVlen = 4;
1106 }
1107 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1108 cbIVlen = 8;//RSN Header
1109 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001110 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001111 }
Andres Moree269fc22013-02-12 20:36:29 -05001112 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001113 //MAC Header should be padding 0 to DW alignment.
1114 uPadding = 4 - (cbMACHdLen%4);
1115 uPadding %= 4;
1116 }
1117 }
1118
1119 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1120
Andres Moree269fc22013-02-12 20:36:29 -05001121 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1122 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001123 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001124 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001125 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1126 }
1127
Andres Moreb902fbf2013-02-25 20:32:51 -05001128 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001129 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1130
Forest Bond92b96792009-06-13 07:38:31 -04001131 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1132 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001133 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001134 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001135 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001136 }
1137 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001138 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001139 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001140 }
1141 } else {
1142 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001143 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001144 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001145 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001146 }
Andres Moree269fc22013-02-12 20:36:29 -05001147 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001148 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001149 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001150 }
1151 } // Auto Fall Back
1152 }
1153 else {//802.11a/b packet
1154 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001155 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001156 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001157 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001158 }
Andres Moree269fc22013-02-12 20:36:29 -05001159 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001160 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001161 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001162 }
1163 } else {
1164 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001165 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001166 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001167 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001168 }
Andres Moree269fc22013-02-12 20:36:29 -05001169 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001170 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001171 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001172 }
1173 } // Auto Fall Back
1174 }
1175
Andres Moreb902fbf2013-02-25 20:32:51 -05001176 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1177 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1178 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001179
Forest Bond92b96792009-06-13 07:38:31 -04001180 //=========================
1181 // No Fragmentation
1182 //=========================
1183 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1184 byFragType = FRAGCTL_NONFRAG;
1185 //uDMAIdx = TYPE_AC0DMA;
1186 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1187
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001188 /* Fill FIFO, RrvTime, RTS and CTS */
1189 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1190 tx_buffer, &pMICHDR, cbMICHDR,
1191 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001192
Forest Bond92b96792009-06-13 07:38:31 -04001193 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001194 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001195 byFragType, uDMAIdx, 0);
1196
Andres More4e9b5e22013-02-12 20:36:30 -05001197 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001198 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001199 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001200 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001201
1202 if (pDevice->bEnableHostWEP) {
1203 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1204 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1205 }
1206 }
1207
1208 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001209 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001210 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001211 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1212 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001213 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001214 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001215 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001216 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001217 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001218 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001219 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001220 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001221 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001222
1223 }
1224
1225 }
1226
Forest Bond92b96792009-06-13 07:38:31 -04001227 if (pPacket != NULL) {
1228 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001229 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001230 (pPacket + ETH_HLEN),
1231 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001232 );
1233
1234 } else {
1235 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001236 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001237 }
1238
Andres More4e9b5e22013-02-12 20:36:30 -05001239 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001240
1241 ///////////////////////////////////////////////////////////////////
1242
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001243 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1244 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1245 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1246 }
Forest Bond92b96792009-06-13 07:38:31 -04001247 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001248 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1249 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001250 }
1251 else {
Andres More52a7e642013-02-25 20:32:53 -05001252 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1253 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001254 }
1255 // DO Software Michael
1256 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001257 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001258 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001259 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001260 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1261 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001262
1263 ///////////////////////////////////////////////////////////////////
1264
1265 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1266 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001267 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001268 //}
1269 //DBG_PRN_GRP12(("\n\n\n"));
1270
1271 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1272
Andres More52a7e642013-02-25 20:32:53 -05001273 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1274 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001275
1276 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1277 MIC_vUnInit();
1278
Andres More4e9b5e22013-02-12 20:36:30 -05001279 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001280 *pdwMIC_L = 0;
1281 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001282 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001283 }
1284 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1285 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1286 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1287 }
1288
Andres More4e9b5e22013-02-12 20:36:30 -05001289 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001290
Andres More3eaca0d2013-02-25 20:32:52 -05001291 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001292
Andres More4e9b5e22013-02-12 20:36:30 -05001293 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1294 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1295 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001296 cbFrameSize -= cbICVlen;
1297 }
1298
Forest Bond92b96792009-06-13 07:38:31 -04001299 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001300
1301 *pcbHeaderLen = cbHeaderLength;
1302 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1303
Forest Bond92b96792009-06-13 07:38:31 -04001304 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001305 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001306
Andres More4e9b5e22013-02-12 20:36:30 -05001307 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001308
1309}
1310
Forest Bond92b96792009-06-13 07:38:31 -04001311/*+
1312 *
1313 * Description:
1314 * Translate 802.3 to 802.11 header
1315 *
1316 * Parameters:
1317 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001318 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001319 * dwTxBufferAddr - Transmit Buffer
1320 * pPacket - Packet from upper layer
1321 * cbPacketSize - Transmit Data Length
1322 * Out:
1323 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1324 * pcbAppendPayload - size of append payload for 802.1H translation
1325 *
1326 * Return Value: none
1327 *
1328-*/
1329
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001330static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001331 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001332 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001333{
Andres More1cac4a42013-03-18 20:33:50 -05001334 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001335
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001336 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001337
1338 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001339 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001340 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001341 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001342 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1343 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001344 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001345 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001346 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001347 } else {
1348 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001349 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001350 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001351 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001352 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001353 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001354 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001355 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001356 &(pDevice->abyBSSID[0]),
1357 ETH_ALEN);
1358 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001359 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001360 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001361 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001362 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001363 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001364 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001365 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001366 &(pDevice->abyBSSID[0]),
1367 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001368 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001369 }
1370 }
1371
1372 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001373 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001374
Andres More1cac4a42013-03-18 20:33:50 -05001375 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001376
1377 if (pDevice->bLongHeader) {
1378 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001379 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001380 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001381 }
Andres More1cac4a42013-03-18 20:33:50 -05001382 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001383
1384 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001385 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001386
1387 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1388 pDevice->wSeqCounter++;
1389 if (pDevice->wSeqCounter > 0x0fff)
1390 pDevice->wSeqCounter = 0;
1391 }
1392
1393 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001394 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001395 }
1396}
1397
Forest Bond92b96792009-06-13 07:38:31 -04001398/*+
1399 *
1400 * Description:
1401 * Request instructs a MAC to transmit a 802.11 management packet through
1402 * the adapter onto the medium.
1403 *
1404 * Parameters:
1405 * In:
1406 * hDeviceContext - Pointer to the adapter
1407 * pPacket - A pointer to a descriptor for the packet to transmit
1408 * Out:
1409 * none
1410 *
Andres Moree269fc22013-02-12 20:36:29 -05001411 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001412 *
1413-*/
1414
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001415CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1416 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001417{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001418 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001419 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001420 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001421 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001422 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001423 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001424 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001425 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001426 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001427 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001428 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1429 u32 uPadding = 0;
1430 u16 wTxBufSize;
1431 u32 cbMacHdLen;
1432 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001433
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001434 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001435
1436 if (NULL == pContext) {
1437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1438 return CMD_STATUS_RESOURCES;
1439 }
1440
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001441 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001442 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001443 pTxBufHead = &pTX_Buffer->fifo_head;
1444 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1445 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001446
1447 if (pDevice->byBBType == BB_TYPE_11A) {
1448 wCurrentRate = RATE_6M;
1449 byPktType = PK_TYPE_11A;
1450 } else {
1451 wCurrentRate = RATE_1M;
1452 byPktType = PK_TYPE_11B;
1453 }
1454
1455 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1456 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1457 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1458 // to set power here.
1459 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1460 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1461 } else {
1462 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1463 }
1464 pDevice->wCurrentRate = wCurrentRate;
1465
Forest Bond92b96792009-06-13 07:38:31 -04001466 //Set packet type
1467 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1468 pTxBufHead->wFIFOCtl = 0;
1469 }
1470 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1471 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1472 }
1473 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1474 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1475 }
1476 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1477 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1478 }
1479
1480 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1481 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1482
Andres More22040bb2010-08-02 20:21:44 -03001483 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001484 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001485 }
1486 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001487 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001488 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1489 };
1490
1491 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1492 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1493
1494 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1495 //Set Preamble type always long
1496 //pDevice->byPreambleType = PREAMBLE_LONG;
1497 // probe-response don't retry
1498 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001499 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001500 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1501 //}
1502 }
1503
1504 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1505
1506 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001507 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001508 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1509 } else {
1510 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1511 }
1512
1513 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001514 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001515
1516 // Notes:
1517 // Although spec says MMPDU can be fragmented; In most case,
1518 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001519 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001520
1521 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1522 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1523 cbIVlen = 4;
1524 cbICVlen = 4;
1525 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1526 }
1527 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1528 cbIVlen = 8;//IV+ExtIV
1529 cbMIClen = 8;
1530 cbICVlen = 4;
1531 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1532 //We need to get seed here for filling TxKey entry.
1533 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1534 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1535 }
1536 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1537 cbIVlen = 8;//RSN Header
1538 cbICVlen = 8;//MIC
1539 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001540 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001541 }
1542 //MAC Header should be padding 0 to DW alignment.
1543 uPadding = 4 - (cbMacHdLen%4);
1544 uPadding %= 4;
1545 }
1546
1547 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1548
1549 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001550 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001551 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1552 }
1553 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1554
1555 //Set RrvTime/RTS/CTS Buffer
1556 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001557 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001558 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001559 }
1560 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001561 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001562 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001563 }
1564
Andres Moreceb8c5d2013-03-18 20:33:49 -05001565 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001566 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1567 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001568 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001569 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1570 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001571 //=========================
1572 // No Fragmentation
1573 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001574 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001575
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001576 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001577 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001578 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001579 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001580
Andres More1cac4a42013-03-18 20:33:50 -05001581 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001582
1583 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1584
1585 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001586 u8 * pbyIVHead;
1587 u8 * pbyPayloadHead;
1588 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001589 PSKeyItem pTransmitKey = NULL;
1590
Andres Moreb902fbf2013-02-25 20:32:51 -05001591 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1592 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001593 do {
1594 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001595 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001596 pbyBSSID = pDevice->abyBSSID;
1597 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001598 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001599 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001600 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001601 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1602 break;
1603 }
1604 } else {
1605 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1606 break;
1607 }
1608 }
1609 // get group key
1610 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001611 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001612 pTransmitKey = NULL;
1613 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1614 } else {
1615 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1616 }
Andres Moree269fc22013-02-12 20:36:29 -05001617 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001618 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001619 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001620 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001621
Jim Lieb3e362592009-08-12 14:54:11 -07001622 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001623 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001624 cbFrameBodySize);
1625 }
1626 else {
1627 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001628 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001629 }
1630
Andres More1cac4a42013-03-18 20:33:50 -05001631 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001632 pDevice->wSeqCounter++ ;
1633 if (pDevice->wSeqCounter > 0x0fff)
1634 pDevice->wSeqCounter = 0;
1635
1636 if (bIsPSPOLL) {
1637 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001638 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001639 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1640 // in the same place of other packet's Duration-field).
1641 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001642 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001643 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1644 tx_cts.tx.head.cts_g.data_head;
1645 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001646 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001647 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001648 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1649 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001650 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1651 tx_ab.tx.head.data_head_ab;
1652 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001653 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1654 }
Forest Bond92b96792009-06-13 07:38:31 -04001655 }
1656
Andres More3eaca0d2013-02-25 20:32:52 -05001657 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001658 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001659 pTX_Buffer->byType = 0x00;
1660
1661 pContext->pPacket = NULL;
1662 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001663 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001664
Andres More1cac4a42013-03-18 20:33:50 -05001665 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001666 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1667 &pMACHeader->addr1[0], (u16)cbFrameSize,
1668 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001669 }
1670 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001671 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1672 &pMACHeader->addr3[0], (u16)cbFrameSize,
1673 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001674 }
1675
1676 PIPEnsSendBulkOut(pDevice,pContext);
1677 return CMD_STATUS_PENDING;
1678}
1679
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001680CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1681 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001682{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001683 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001684 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1685 u32 cbHeaderSize = 0;
1686 u16 wTxBufSize = sizeof(STxShortBufHead);
1687 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001688 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001689 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001690 u16 wCurrentRate;
1691 u32 cbFrameBodySize;
1692 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001693 u8 *pbyTxBufferAddr;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001694 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001695 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001696
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001697 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001698 if (NULL == pContext) {
1699 status = CMD_STATUS_RESOURCES;
1700 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1701 return status ;
1702 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001703
1704 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001705 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001706
1707 cbFrameBodySize = pPacket->cbPayloadLen;
1708
1709 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1710 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001711
1712 if (pDevice->byBBType == BB_TYPE_11A) {
1713 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001714 pTxDataHead = (struct vnt_tx_datahead_ab *)
1715 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001716 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001717 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1718 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001719 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001720 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001721 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001722 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001723 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001724 } else {
1725 wCurrentRate = RATE_1M;
1726 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001727 pTxDataHead = (struct vnt_tx_datahead_ab *)
1728 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001729 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001730 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1731 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001732 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001733 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001734 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001735 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001736 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001737 }
1738
1739 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001740 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001741 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001742
Andres More1cac4a42013-03-18 20:33:50 -05001743 pMACHeader->duration_id = 0;
1744 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001745 pDevice->wSeqCounter++ ;
1746 if (pDevice->wSeqCounter > 0x0fff)
1747 pDevice->wSeqCounter = 0;
1748
1749 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1750
Andres More3eaca0d2013-02-25 20:32:52 -05001751 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001752 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001753 pTX_Buffer->byType = 0x01;
1754
1755 pContext->pPacket = NULL;
1756 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001757 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001758
1759 PIPEnsSendBulkOut(pDevice,pContext);
1760 return CMD_STATUS_PENDING;
1761
1762}
1763
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001764void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1765{
1766 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001767 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001768 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001769 u8 byPktType;
1770 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001771 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001772 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001773 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001774 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001775 u32 cbFrameSize;
1776 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1777 u32 uPadding = 0;
1778 u32 cbMICHDR = 0, uLength = 0;
1779 u32 dwMICKey0, dwMICKey1;
1780 u32 dwMIC_Priority;
1781 u32 *pdwMIC_L, *pdwMIC_R;
1782 u16 wTxBufSize;
1783 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001784 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001785 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001786 u32 wCurrentRate = RATE_1M;
1787 PUWLAN_80211HDR p80211Header;
1788 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001789 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001790 SKeyItem STempKey;
1791 PSKeyItem pTransmitKey = NULL;
1792 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1793 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001794 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001795
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001796 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001797
1798 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1799 cbFrameBodySize = 0;
1800 }
1801 else {
1802 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1803 }
1804 p80211Header = (PUWLAN_80211HDR)skb->data;
1805
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001806 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001807
1808 if (NULL == pContext) {
1809 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1810 dev_kfree_skb_irq(skb);
1811 return ;
1812 }
1813
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001814 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001815 pTxBufHead = &pTX_Buffer->fifo_head;
1816 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1817 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001818
1819 if (pDevice->byBBType == BB_TYPE_11A) {
1820 wCurrentRate = RATE_6M;
1821 byPktType = PK_TYPE_11A;
1822 } else {
1823 wCurrentRate = RATE_1M;
1824 byPktType = PK_TYPE_11B;
1825 }
1826
1827 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1828 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1829 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1830 // to set power here.
1831 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1832 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1833 } else {
1834 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1835 }
1836
1837 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1838
1839 //Set packet type
1840 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1841 pTxBufHead->wFIFOCtl = 0;
1842 }
1843 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1844 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1845 }
1846 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1847 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1848 }
1849 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1850 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1851 }
1852
1853 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1854 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1855
Andres More22040bb2010-08-02 20:21:44 -03001856 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001857 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001858 if (pDevice->bEnableHostWEP) {
1859 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001860 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001861 }
Forest Bond92b96792009-06-13 07:38:31 -04001862 }
1863 else {
1864 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001865 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001866 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001867 }
Andres More4e9b5e22013-02-12 20:36:30 -05001868 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001869 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1870 };
1871
1872 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1873 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1874
1875 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1876 //Set Preamble type always long
1877 //pDevice->byPreambleType = PREAMBLE_LONG;
1878
1879 // probe-response don't retry
1880 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001881 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001882 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1883 //}
1884 }
1885
1886 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1887
1888 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001889 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001890 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1891 } else {
1892 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1893 }
1894
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001895 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001896 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1897
1898 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1899 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1900 }
1901
1902 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1903 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1904 }
1905
1906 if (cbExtSuppRate >0) {
1907 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1908 }
1909 }
1910
Forest Bond92b96792009-06-13 07:38:31 -04001911 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001912 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001913
1914 // Notes:
1915 // Although spec says MMPDU can be fragmented; In most case,
1916 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001917 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001918
Forest Bond92b96792009-06-13 07:38:31 -04001919 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1920 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1921 cbIVlen = 4;
1922 cbICVlen = 4;
1923 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1924 }
1925 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1926 cbIVlen = 8;//IV+ExtIV
1927 cbMIClen = 8;
1928 cbICVlen = 4;
1929 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1930 //We need to get seed here for filling TxKey entry.
1931 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1932 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1933 }
1934 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1935 cbIVlen = 8;//RSN Header
1936 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001937 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001938 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001939 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001940 }
1941 //MAC Header should be padding 0 to DW alignment.
1942 uPadding = 4 - (cbMacHdLen%4);
1943 uPadding %= 4;
1944 }
1945
1946 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1947
1948 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001949 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001950 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1951 }
1952 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1953
Forest Bond92b96792009-06-13 07:38:31 -04001954 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001955 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001956 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001957
1958 }
1959 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001960 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001961 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001962 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001963 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001964 &(p80211Header->sA3.abyAddr1[0]),
1965 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001966 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001967 &(p80211Header->sA3.abyAddr2[0]),
1968 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001969 //=========================
1970 // No Fragmentation
1971 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001972 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001973
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001974 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001975 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001976 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001977 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001978
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001979 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001980
1981 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1982
Andres Moreb902fbf2013-02-25 20:32:51 -05001983 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1984 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1985 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001986
1987 // Copy the Packet into a tx Buffer
1988 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1989
1990 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001991 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001992 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1993
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001994 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001995 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1996 if (cbExtSuppRate != 0) {
1997 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1998 memcpy((pbyPayloadHead + cbFrameBodySize),
1999 pMgmt->abyCurrSuppRates,
2000 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2001 );
2002 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2003 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2004 pMgmt->abyCurrExtSuppRates,
2005 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2006 );
2007 }
2008 }
2009
2010 // Set wep
2011 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2012
2013 if (pDevice->bEnableHostWEP) {
2014 pTransmitKey = &STempKey;
2015 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2016 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2017 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2018 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2019 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2020 memcpy(pTransmitKey->abyKey,
2021 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2022 pTransmitKey->uKeyLength
2023 );
2024 }
2025
2026 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2027
Andres More52a7e642013-02-25 20:32:53 -05002028 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2029 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002030
2031 // DO Software Michael
2032 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002033 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002034 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002035 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002036 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2037 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002038
2039 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2040
2041 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2042
Andres More52a7e642013-02-25 20:32:53 -05002043 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2044 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002045
2046 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2047 MIC_vUnInit();
2048
Andres More4e9b5e22013-02-12 20:36:30 -05002049 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002050 *pdwMIC_L = 0;
2051 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002052 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002053 }
2054
2055 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2056 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002057 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2058 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002059
2060 }
2061
Andres Moreb902fbf2013-02-25 20:32:51 -05002062 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002063 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002064
2065 if (pDevice->bEnableHostWEP) {
2066 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2067 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2068 }
2069
2070 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002071 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002072 }
2073 }
2074
Andres More1cac4a42013-03-18 20:33:50 -05002075 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002076 pDevice->wSeqCounter++ ;
2077 if (pDevice->wSeqCounter > 0x0fff)
2078 pDevice->wSeqCounter = 0;
2079
Forest Bond92b96792009-06-13 07:38:31 -04002080 if (bIsPSPOLL) {
2081 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2082 // of FIFO control header.
2083 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2084 // in the same place of other packet's Duration-field).
2085 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002086 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002087 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2088 tx_cts.tx.head.cts_g.data_head;
2089 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002090 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002091 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002092 cpu_to_le16(p80211Header->sA2.wDurationID);
2093 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002094 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2095 tx_ab.tx.head.data_head_ab;
2096 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002097 cpu_to_le16(p80211Header->sA2.wDurationID);
2098 }
Forest Bond92b96792009-06-13 07:38:31 -04002099 }
2100
Andres More3eaca0d2013-02-25 20:32:52 -05002101 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002102 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002103 pTX_Buffer->byType = 0x00;
2104
2105 pContext->pPacket = skb;
2106 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002107 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002108
Andres More1cac4a42013-03-18 20:33:50 -05002109 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002110 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2111 &pMACHeader->addr1[0], (u16)cbFrameSize,
2112 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002113 }
2114 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002115 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2116 &pMACHeader->addr3[0], (u16)cbFrameSize,
2117 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002118 }
2119 PIPEnsSendBulkOut(pDevice,pContext);
2120 return ;
2121
2122}
2123
Forest Bond92b96792009-06-13 07:38:31 -04002124//TYPE_AC0DMA data tx
2125/*
2126 * Description:
2127 * Tx packet via AC0DMA(DMA1)
2128 *
2129 * Parameters:
2130 * In:
2131 * pDevice - Pointer to the adapter
2132 * skb - Pointer to tx skb packet
2133 * Out:
2134 * void
2135 *
2136 * Return Value: NULL
2137 */
2138
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002139int nsDMA_tx_packet(struct vnt_private *pDevice,
2140 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002141{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002142 struct net_device_stats *pStats = &pDevice->stats;
2143 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002144 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002145 u32 BytesToWrite = 0, uHeaderLen = 0;
2146 u32 uNodeIndex = 0;
2147 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2148 u16 wAID;
2149 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002150 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002151 PSKeyItem pTransmitKey = NULL;
2152 SKeyItem STempKey;
2153 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002154 int bTKIP_UseGTK = false;
2155 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002156 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002157 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002158 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002159 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002160 u32 status;
2161 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002162 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002163
Forest Bond92b96792009-06-13 07:38:31 -04002164 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2165
2166 if (pDevice->uAssocCount == 0) {
2167 dev_kfree_skb_irq(skb);
2168 return 0;
2169 }
2170
Andres Moreb902fbf2013-02-25 20:32:51 -05002171 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002172 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002173 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002174 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2175
2176 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2177 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2178 // set tx map
2179 pMgmt->abyPSTxMap[0] |= byMask[0];
2180 return 0;
2181 }
Masanari Iida93184692012-08-13 21:21:50 +09002182 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002183
2184 if (pDevice->byBBType != BB_TYPE_11A)
2185 pDevice->wCurrentRate = RATE_2M;
2186 else
2187 pDevice->wCurrentRate = RATE_24M;
2188 // long preamble type
2189 pDevice->byPreambleType = PREAMBLE_SHORT;
2190
2191 }else {
2192
Andres Moreb902fbf2013-02-25 20:32:51 -05002193 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002194
2195 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2196
2197 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2198
2199 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2200 // set tx map
2201 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2202 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2203 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2204 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2205
2206 return 0;
2207 }
2208 // AP rate decided from node
2209 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2210 // tx preamble decided from node
2211
2212 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2213 pDevice->byPreambleType = pDevice->byShortPreamble;
2214
2215 }else {
2216 pDevice->byPreambleType = PREAMBLE_LONG;
2217 }
Andres More4e9b5e22013-02-12 20:36:30 -05002218 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002219 }
2220 }
2221
Andres Moree269fc22013-02-12 20:36:29 -05002222 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002223 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2224 dev_kfree_skb_irq(skb);
2225 return 0;
2226 }
2227 }
2228
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002229 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002230
2231 if (pContext == NULL) {
2232 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2233 dev_kfree_skb_irq(skb);
2234 return STATUS_RESOURCES;
2235 }
2236
Andres Moreceb8c5d2013-03-18 20:33:49 -05002237 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002238
2239//mike add:station mode check eapol-key challenge--->
2240{
Andres Moreb902fbf2013-02-25 20:32:51 -05002241 u8 Protocol_Version; //802.1x Authentication
2242 u8 Packet_Type; //802.1x Authentication
2243 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002244 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002245
Charles Clément21ec51f2010-05-18 10:08:14 -07002246 Protocol_Version = skb->data[ETH_HLEN];
2247 Packet_Type = skb->data[ETH_HLEN+1];
2248 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2249 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 -05002250 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002251 /* 802.1x OR eapol-key challenge frame transfer */
2252 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2253 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002254 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002255 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2256 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2257 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002258 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002259 PRINT_K("WPA ");
2260 }
2261 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002262 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002263 PRINT_K("WPA2(re-keying) ");
2264 }
2265 PRINT_K("Authentication completed!!\n");
2266 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002267 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002268 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002269 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002270 PRINT_K("WPA2 Authentication completed!!\n");
2271 }
2272 }
2273 }
2274}
2275//mike add:station mode check eapol-key challenge<---
2276
Andres More4e9b5e22013-02-12 20:36:30 -05002277 if (pDevice->bEncryptionEnable == true) {
2278 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002279 // get Transmit key
2280 do {
2281 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2282 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2283 pbyBSSID = pDevice->abyBSSID;
2284 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002285 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002286 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002287 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2288 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002289 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2290 break;
2291 }
2292 } else {
2293 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2294 break;
2295 }
2296 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002297 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2298 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002299 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2300 for (ii = 0; ii< 6; ii++)
2301 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2303
2304 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002305 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002306 break;
2307 }
2308 // get group key
2309 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002310 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002311 pTransmitKey = NULL;
2312 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2313 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2314 }
2315 else
2316 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2317 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002318 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002319 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2320 }
Andres Moree269fc22013-02-12 20:36:29 -05002321 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002322 }
2323
2324 if (pDevice->bEnableHostWEP) {
2325 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002326 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002327 pTransmitKey = &STempKey;
2328 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2329 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2330 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2331 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2332 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2333 memcpy(pTransmitKey->abyKey,
2334 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2335 pTransmitKey->uKeyLength
2336 );
2337 }
2338 }
2339
Andres Moreb902fbf2013-02-25 20:32:51 -05002340 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002341
2342 if (pDevice->bFixRate) {
2343 if (pDevice->byBBType == BB_TYPE_11B) {
2344 if (pDevice->uConnectionRate >= RATE_11M) {
2345 pDevice->wCurrentRate = RATE_11M;
2346 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002347 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002348 }
2349 } else {
2350 if ((pDevice->byBBType == BB_TYPE_11A) &&
2351 (pDevice->uConnectionRate <= RATE_6M)) {
2352 pDevice->wCurrentRate = RATE_6M;
2353 } else {
2354 if (pDevice->uConnectionRate >= RATE_54M)
2355 pDevice->wCurrentRate = RATE_54M;
2356 else
Andres More3eaca0d2013-02-25 20:32:52 -05002357 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002358 }
2359 }
2360 }
2361 else {
2362 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2363 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002364 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002365 // Multicast use highest data rate
2366 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2367 // preamble type
2368 pDevice->byPreambleType = pDevice->byShortPreamble;
2369 }
2370 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002371 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002372 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2373 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2374 pDevice->byPreambleType = pDevice->byShortPreamble;
2375
2376 }
2377 else {
2378 pDevice->byPreambleType = PREAMBLE_LONG;
2379 }
2380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2381 }
2382 else {
2383 if (pDevice->byBBType != BB_TYPE_11A)
2384 pDevice->wCurrentRate = RATE_2M;
2385 else
2386 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2387 // abyCurrExtSuppRates[]
2388 pDevice->byPreambleType = PREAMBLE_SHORT;
2389 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2390 }
2391 }
2392 }
2393 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2394 // Infra STA rate decided from AP Node, index = 0
2395 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2396 }
2397 }
2398
Andres Moreceb8c5d2013-03-18 20:33:49 -05002399 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002400 if (pDevice->byBBType != BB_TYPE_11A) {
2401 pDevice->wCurrentRate = RATE_1M;
2402 pDevice->byACKRate = RATE_1M;
2403 pDevice->byTopCCKBasicRate = RATE_1M;
2404 pDevice->byTopOFDMBasicRate = RATE_6M;
2405 } else {
2406 pDevice->wCurrentRate = RATE_6M;
2407 pDevice->byACKRate = RATE_6M;
2408 pDevice->byTopCCKBasicRate = RATE_1M;
2409 pDevice->byTopOFDMBasicRate = RATE_6M;
2410 }
2411 }
Forest Bond92b96792009-06-13 07:38:31 -04002412
Andres More0cbd8d92010-05-06 20:34:29 -03002413 DBG_PRT(MSG_LEVEL_DEBUG,
2414 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2415 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002416
2417 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002418 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002419 }
2420
2421 if (pDevice->wCurrentRate <= RATE_11M) {
2422 byPktType = PK_TYPE_11B;
2423 }
2424
Andres More4e9b5e22013-02-12 20:36:30 -05002425 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002426 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2427 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002428 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002429 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002430 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2431 if (pTransmitKey == NULL) {
2432 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2433 }
2434 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002435 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002436 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2437 }
2438 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002439 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2440 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002441 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002442 }
2443 }
2444 }
2445
Forest Bond92b96792009-06-13 07:38:31 -04002446 if (pDevice->bEnableHostWEP) {
2447 if ((uNodeIndex != 0) &&
2448 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002449 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2450 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002451 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002452 }
2453 }
2454 }
2455 else {
2456
Forest Bond92b96792009-06-13 07:38:31 -04002457 if (pTransmitKey == NULL) {
2458 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002459 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002460 dev_kfree_skb_irq(skb);
2461 pStats->tx_dropped++;
2462 return STATUS_FAILURE;
2463 }
Forest Bond92b96792009-06-13 07:38:31 -04002464 }
2465 }
2466
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002467 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2468
Forest Bond92b96792009-06-13 07:38:31 -04002469 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002470 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002471 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002472 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002473 pDevice->wCurrentRate,
2474 &uHeaderLen, &BytesToWrite
2475 );
2476
Andres Moree269fc22013-02-12 20:36:29 -05002477 if (fConvertedPacket == false) {
2478 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002479 dev_kfree_skb_irq(skb);
2480 return STATUS_FAILURE;
2481 }
2482
Andres More4e9b5e22013-02-12 20:36:30 -05002483 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002484 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002485 bScheduleCommand((void *) pDevice,
2486 WLAN_CMD_MAC_DISPOWERSAVING,
2487 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002488 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002489 }
2490 }
2491
Andres Moreb902fbf2013-02-25 20:32:51 -05002492 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002493 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002494
2495 pContext->pPacket = skb;
2496 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002497 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002498
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002499 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2500 &pContext->sEthHeader.h_dest[0],
2501 (u16)(BytesToWrite-uHeaderLen),
2502 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002503
2504 status = PIPEnsSendBulkOut(pDevice,pContext);
2505
Andres More4e9b5e22013-02-12 20:36:30 -05002506 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002507 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002508
Andres Moreb902fbf2013-02-25 20:32:51 -05002509 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002510 }
2511
2512 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002513 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002514 dev_kfree_skb_irq(skb);
2515 return STATUS_FAILURE;
2516 }
2517 else
2518 return 0;
2519
2520}
2521
Forest Bond92b96792009-06-13 07:38:31 -04002522/*
2523 * Description:
2524 * Relay packet send (AC1DMA) from rx dpc.
2525 *
2526 * Parameters:
2527 * In:
2528 * pDevice - Pointer to the adapter
2529 * pPacket - Pointer to rx packet
2530 * cbPacketSize - rx ethernet frame size
2531 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002532 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002533 *
Andres More4e9b5e22013-02-12 20:36:30 -05002534 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002535 */
2536
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002537int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2538 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002539{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002540 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002541 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002542 u32 BytesToWrite = 0, uHeaderLen = 0;
2543 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002544 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002545 SKeyItem STempKey;
2546 PSKeyItem pTransmitKey = NULL;
2547 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002548 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002549 u8 byPktTyp;
2550 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002551 u32 status;
2552 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002553
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002554 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002555
2556 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002557 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002558 }
2559
Andres Moreceb8c5d2013-03-18 20:33:49 -05002560 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002561
Andres More4e9b5e22013-02-12 20:36:30 -05002562 if (pDevice->bEncryptionEnable == true) {
2563 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002564 // get group key
2565 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002566 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002567 pTransmitKey = NULL;
2568 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2569 } else {
2570 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2571 }
2572 }
2573
2574 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002575 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002576 pTransmitKey = &STempKey;
2577 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2578 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2579 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2580 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2581 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2582 memcpy(pTransmitKey->abyKey,
2583 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2584 pTransmitKey->uKeyLength
2585 );
2586 }
2587 }
2588
2589 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002590 pContext->bBoolInUse = false;
2591 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002592 }
2593
Andres Moreb902fbf2013-02-25 20:32:51 -05002594 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002595
2596 if (pDevice->bFixRate) {
2597 if (pDevice->byBBType == BB_TYPE_11B) {
2598 if (pDevice->uConnectionRate >= RATE_11M) {
2599 pDevice->wCurrentRate = RATE_11M;
2600 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002601 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002602 }
2603 } else {
2604 if ((pDevice->byBBType == BB_TYPE_11A) &&
2605 (pDevice->uConnectionRate <= RATE_6M)) {
2606 pDevice->wCurrentRate = RATE_6M;
2607 } else {
2608 if (pDevice->uConnectionRate >= RATE_54M)
2609 pDevice->wCurrentRate = RATE_54M;
2610 else
Andres More3eaca0d2013-02-25 20:32:52 -05002611 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002612 }
2613 }
2614 }
2615 else {
2616 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2617 }
2618
Forest Bond92b96792009-06-13 07:38:31 -04002619 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002620 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002621 }
2622
2623 if (pDevice->wCurrentRate <= RATE_11M)
2624 byPktType = PK_TYPE_11B;
2625
Andres Moreabad19d2010-07-12 16:28:32 -03002626 BytesToWrite = uDataLen + ETH_FCS_LEN;
2627
Forest Bond92b96792009-06-13 07:38:31 -04002628 // Convert the packet to an usb frame and copy into our buffer
2629 // and send the irp.
2630
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002631 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2632
Forest Bond92b96792009-06-13 07:38:31 -04002633 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002634 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002635 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2636 pbySkbData, pTransmitKey, uNodeIndex,
2637 pDevice->wCurrentRate,
2638 &uHeaderLen, &BytesToWrite
2639 );
2640
Andres Moree269fc22013-02-12 20:36:29 -05002641 if (fConvertedPacket == false) {
2642 pContext->bBoolInUse = false;
2643 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002644 }
2645
Andres Moreb902fbf2013-02-25 20:32:51 -05002646 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002647 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002648
2649 pContext->pPacket = NULL;
2650 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002651 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002652
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002653 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2654 &pContext->sEthHeader.h_dest[0],
2655 (u16)(BytesToWrite - uHeaderLen),
2656 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002657
2658 status = PIPEnsSendBulkOut(pDevice,pContext);
2659
Andres More4e9b5e22013-02-12 20:36:30 -05002660 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002661}
2662