blob: 340473075186ba761688e5b5f8b05d6d8ed5aab9 [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);
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100453 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
454 byPktType, cbFrameLength, wRate, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400455 break;
456
457 case RTSDUR_AA_F0: //RTSDuration_aa_f0
458 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100459 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
460 byPktType, cbFrameLength, wRate, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400461 break;
462
463 case RTSDUR_BA_F1: //RTSDuration_ba_f1
464 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100465 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
466 byPktType, cbFrameLength, wRate, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400467 break;
468
469 case RTSDUR_AA_F1: //RTSDuration_aa_f1
470 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100471 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
472 byPktType, cbFrameLength, wRate, bNeedAck);
473 break;
Forest Bond92b96792009-06-13 07:38:31 -0400474
475 case CTSDUR_BA_F0: //CTSDuration_ba_f0
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100476 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
477 byPktType, cbFrameLength, wRate, bNeedAck);
478 break;
Forest Bond92b96792009-06-13 07:38:31 -0400479
480 case CTSDUR_BA_F1: //CTSDuration_ba_f1
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100481 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
482 byPktType, cbFrameLength, wRate, bNeedAck);
483 break;
Forest Bond92b96792009-06-13 07:38:31 -0400484
485 default:
486 break;
487 }
488
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100489 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400490}
491
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100492static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
493 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
494{
495 /* Get SignalField,ServiceField,Length */
496 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
497 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
498 PK_TYPE_11B, &buf->b);
499
500 /* Get Duration and TimeStamp */
501 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
502 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
503
504 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
505 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
506 priv->byTopCCKBasicRate);
507
508 return buf->wDuration_a;
509}
510
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100511static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
512 u16 rate, struct vnt_tx_datahead_g_fb *buf,
513 u32 frame_len, int need_ack)
514{
515 /* Get SignalField,ServiceField,Length */
516 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
517
518 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
519 PK_TYPE_11B, &buf->b);
520
521 /* Get Duration and TimeStamp */
522 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
523 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
524
525 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
526 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
527
528 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
529 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
530 priv->byTopCCKBasicRate);
531
532 return buf->wDuration_a;
533}
534
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100535static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
536 u16 rate, struct vnt_tx_datahead_a_fb *buf,
537 u32 frame_len, int need_ack)
538{
539 /* Get SignalField,ServiceField,Length */
540 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
541 /* Get Duration and TimeStampOff */
542 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
543
544 buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
545 buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
546
547 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
548
549 return buf->wDuration;
550}
551
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100552static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
553 u16 rate, struct vnt_tx_datahead_ab *buf,
554 u32 frame_len, int need_ack)
555{
556 /* Get SignalField,ServiceField,Length */
557 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
558 /* Get Duration and TimeStampOff */
559 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
560
561 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
562
563 return buf->wDuration;
564}
565
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100566static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
567 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
568 u16 duration)
569{
570 rts->duration = duration;
571 rts->frame_control = TYPE_CTL_RTS;
572
573 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
574 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
575 else
576 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
577
578 if (priv->eOPMode == OP_MODE_AP)
579 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
580 else
581 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
582
583 return 0;
584}
585
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100586static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100587 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
588 u8 pkt_type, u32 frame_len, int need_ack,
589 u16 current_rate, u8 fb_option)
590{
591 u16 rts_frame_len = 20;
592
593 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
594 PK_TYPE_11B, &buf->b);
595 BBvCalculateParameter(priv, rts_frame_len,
596 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
597
598 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
599 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
600 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
601 pkt_type, current_rate, need_ack, fb_option);
602 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
603 pkt_type, current_rate, need_ack, fb_option);
604
605 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
606
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100607 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
608 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100609}
610
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100611static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100612 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
613 u8 pkt_type, u32 frame_len, int need_ack,
614 u16 current_rate, u8 fb_option)
615{
616 u16 rts_frame_len = 20;
617
618 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
619 PK_TYPE_11B, &buf->b);
620 BBvCalculateParameter(priv, rts_frame_len,
621 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
622
623
624 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
625 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
626 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
627 pkt_type, current_rate, need_ack, fb_option);
628 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
629 pkt_type, current_rate, need_ack, fb_option);
630
631
632 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100633 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100634 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100635 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100636 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100637 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100638 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100639 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100640
641 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
642
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100643 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
644 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100645}
646
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100647static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100648 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
649 u8 pkt_type, u32 frame_len, int need_ack,
650 u16 current_rate, u8 fb_option)
651{
652 u16 rts_frame_len = 20;
653
654 BBvCalculateParameter(priv, rts_frame_len,
655 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
656
657 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
658 pkt_type, current_rate, need_ack, fb_option);
659
660 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
661
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100662 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
663 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100664}
665
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100666static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100667 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
668 u8 pkt_type, u32 frame_len, int need_ack,
669 u16 current_rate, u8 fb_option)
670{
671 u16 rts_frame_len = 20;
672
673 BBvCalculateParameter(priv, rts_frame_len,
674 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
675
676 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
677 pkt_type, current_rate, need_ack, fb_option);
678
679 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100680 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100681
682 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100683 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100684
685 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
686
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100687 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
688 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100689}
690
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100691static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100692 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500693 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400694{
Forest Bond92b96792009-06-13 07:38:31 -0400695
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100696 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100697 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400698
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100699 /* Note: So far RTSHead doesn't appear in ATIM
700 * & Beacom DMA, so we don't need to take them
701 * into account.
702 * Otherwise, we need to modified codes for them.
703 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100704 switch (byPktType) {
705 case PK_TYPE_11GB:
706 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100707 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100708 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100709 psEthHeader, byPktType, cbFrameLength,
710 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100711 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100712 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100713 psEthHeader, byPktType, cbFrameLength,
714 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100715 break;
716 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100717 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100718 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100719 psEthHeader, byPktType, cbFrameLength,
720 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100721 break;
722 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100723 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100724 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100725 psEthHeader, byPktType, cbFrameLength,
726 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100727 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100728
729 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400730}
731
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100732static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100733 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
734 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400735{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000736 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400737
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100738 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100739 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400740
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100741 if (byFBOption != AUTO_FB_NONE) {
742 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100743 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100744 /* Get SignalField,ServiceField,Length */
745 BBvCalculateParameter(pDevice, uCTSFrameLen,
746 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100747 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
748 cbFrameLength, byPktType,
749 wCurrentRate, bNeedAck, byFBOption);
750 /* Get CTSDuration_ba_f0 */
751 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100752 CTSDUR_BA_F0, cbFrameLength, byPktType,
753 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100754 /* Get CTSDuration_ba_f1 */
755 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100756 CTSDUR_BA_F1, cbFrameLength, byPktType,
757 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100758 /* Get CTS Frame body */
759 pBuf->data.duration = pBuf->wDuration_ba;
760 pBuf->data.frame_control = TYPE_CTL_CTS;
761 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100762
763 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
764 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100765 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100766 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100767 /* Get SignalField,ServiceField,Length */
768 BBvCalculateParameter(pDevice, uCTSFrameLen,
769 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100770 /* Get CTSDuration_ba */
771 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
772 CTSDUR_BA, cbFrameLength, byPktType,
773 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100774 /*Get CTS Frame body*/
775 pBuf->data.duration = pBuf->wDuration_ba;
776 pBuf->data.frame_control = TYPE_CTL_CTS;
777 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100778
779 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
780 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400781 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100782
783 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400784}
785
Forest Bond92b96792009-06-13 07:38:31 -0400786/*+
787 *
788 * Description:
789 * Generate FIFO control for MAC & Baseband controller
790 *
791 * Parameters:
792 * In:
793 * pDevice - Pointer to adpater
794 * pTxDataHead - Transmit Data Buffer
795 * pTxBufHead - pTxBufHead
796 * pvRrvTime - pvRrvTime
797 * pvRTS - RTS Buffer
798 * pCTS - CTS Buffer
799 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
800 * bNeedACK - If need ACK
801 * uDMAIdx - DMA Index
802 * Out:
803 * none
804 *
805 * Return Value: none
806 *
807-*/
Andres Morecc856e62010-05-17 21:34:01 -0300808
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100809static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100810 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100811 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
812 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400813{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100814 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100815 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000816 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
817 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000818 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400819
Malcolm Priestley92928f12013-10-07 20:14:01 +0100820 pFifoHead->wReserved = wCurrentRate;
821 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400822
Malcolm Priestley92928f12013-10-07 20:14:01 +0100823 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
824 byFBOption = AUTO_FB_0;
825 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
826 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400827
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100828 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100829 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100830
Malcolm Priestley92928f12013-10-07 20:14:01 +0100831 if (pDevice->bLongHeader)
832 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
Forest Bond92b96792009-06-13 07:38:31 -0400833
Malcolm Priestley92928f12013-10-07 20:14:01 +0100834 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
835 if (need_rts) {
836 struct vnt_rrv_time_rts *pBuf =
837 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100838
Malcolm Priestley92928f12013-10-07 20:14:01 +0100839 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
840 byPktType, cbFrameSize, wCurrentRate);
841 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
842 byPktType, cbFrameSize, wCurrentRate);
843 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100844 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100845
Malcolm Priestley92928f12013-10-07 20:14:01 +0100846 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
847 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
848 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
849 PK_TYPE_11B, cbFrameSize,
850 pDevice->byTopCCKBasicRate, bNeedACK);
851
852 if (need_mic) {
853 *mic_hdr = &tx_buffer->
854 tx_head.tx_rts.tx.mic.hdr;
855 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
856 } else {
857 head = &tx_buffer->tx_head.tx_rts.tx.head;
858 }
859
860 /* Fill RTS */
861 return s_vFillRTSHead(pDevice, byPktType, head,
862 cbFrameSize, bNeedACK, psEthHeader,
863 wCurrentRate, byFBOption);
864
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100865 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100866 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
867 tx_head.tx_cts.cts;
868
869 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
870 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
871 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
872 PK_TYPE_11B, cbFrameSize,
873 pDevice->byTopCCKBasicRate, bNeedACK);
874
875 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
876 byPktType, cbFrameSize, wCurrentRate);
877
878 if (need_mic) {
879 *mic_hdr = &tx_buffer->
880 tx_head.tx_cts.tx.mic.hdr;
881 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
882 } else {
883 head = &tx_buffer->tx_head.tx_cts.tx.head;
884 }
885
886 /* Fill CTS */
887 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
888 head, cbFrameSize, bNeedACK, wCurrentRate,
889 byFBOption);
890 }
891 } else if (byPktType == PK_TYPE_11A) {
892 if (need_mic) {
893 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
894 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
895 } else {
896 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100897 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100898
Malcolm Priestley92928f12013-10-07 20:14:01 +0100899 if (need_rts) {
900 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
901 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100902
Malcolm Priestley92928f12013-10-07 20:14:01 +0100903 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100904 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100905
Malcolm Priestley92928f12013-10-07 20:14:01 +0100906 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
907 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
908
909 /* Fill RTS */
910 return s_vFillRTSHead(pDevice, byPktType, head,
911 cbFrameSize, bNeedACK, psEthHeader,
912 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100913 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100914 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
915 tx_head.tx_ab.ab;
916
917 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
918 PK_TYPE_11A, cbFrameSize,
919 wCurrentRate, bNeedACK);
920
921 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
922 wCurrentRate, &head->data_head_a_fb,
923 cbFrameSize, bNeedACK);
924 }
925 } else if (byPktType == PK_TYPE_11B) {
926 if (need_mic) {
927 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
928 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
929 } else {
930 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100931 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100932
Malcolm Priestley92928f12013-10-07 20:14:01 +0100933 if (need_rts) {
934 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
935 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100936
Malcolm Priestley92928f12013-10-07 20:14:01 +0100937 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100938 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100939
Malcolm Priestley92928f12013-10-07 20:14:01 +0100940 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
941 PK_TYPE_11B, cbFrameSize, wCurrentRate,
942 bNeedACK);
943
944 /* Fill RTS */
945 return s_vFillRTSHead(pDevice, byPktType, head,
946 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100947 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100948 } else {
949 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
950 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100951
Malcolm Priestley92928f12013-10-07 20:14:01 +0100952 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
953 PK_TYPE_11B, cbFrameSize,
954 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100955
Malcolm Priestley92928f12013-10-07 20:14:01 +0100956 return vnt_rxtx_datahead_ab(pDevice, byPktType,
957 wCurrentRate, &head->data_head_ab,
958 cbFrameSize, bNeedACK);
959 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100960 }
961
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100962 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400963}
964/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500965 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500966 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300967 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400968*/
969
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000970static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100971 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100972 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
973 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
974 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400975{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100976 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000977 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
978 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000979 u32 cb802_1_H_len;
980 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
981 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100982 int bNeedACK;
983 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000984 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
985 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
986 u8 abySNAP_Bridgetunnel[ETH_ALEN]
987 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
988 u32 uDuration;
989 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100990 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000991 u8 byFBOption = AUTO_FB_NONE, byFragType;
992 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100993 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000994 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500995 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100996
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100997 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400998
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000999 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001000 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1001 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001002 }
Forest Bond92b96792009-06-13 07:38:31 -04001003
Forest Bond92b96792009-06-13 07:38:31 -04001004 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001005 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001006 if (pDevice->dwDiagRefCount == 0) {
1007 cb802_1_H_len = 8;
1008 } else {
1009 cb802_1_H_len = 2;
1010 }
1011 } else {
1012 cb802_1_H_len = 0;
1013 }
1014
Charles Clément21ec51f2010-05-18 10:08:14 -07001015 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001016
1017 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001018 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001019
1020 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001021 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001022 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1023 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001024 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1025 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001026 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001027 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001028 pTxBufHead->wFIFOCtl =
1029 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1030 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001031 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001032 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1033 }
Forest Bond92b96792009-06-13 07:38:31 -04001034 }
1035 else {
1036 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001037 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001038 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1039 }
1040 } //if (pDevice->dwDiagRefCount != 0) {
1041
1042 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1043
1044 //Set FIFOCTL_LHEAD
1045 if (pDevice->bLongHeader)
1046 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1047
Forest Bond92b96792009-06-13 07:38:31 -04001048 //Set FRAGCTL_MACHDCNT
1049 if (pDevice->bLongHeader) {
1050 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1051 } else {
1052 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1053 }
Andres More3eaca0d2013-02-25 20:32:52 -05001054 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001055
1056 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001057 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001058 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1059 }
1060
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001061 /* Set Auto Fallback Ctl */
1062 if (wCurrentRate >= RATE_18M) {
1063 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1064 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1065
1066 pDevice->tx_rate_fb0 =
1067 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1068 pDevice->tx_rate_fb1 =
1069 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1070
1071 byFBOption = AUTO_FB_0;
1072 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1073 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1074 pDevice->tx_rate_fb0 =
1075 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1076 pDevice->tx_rate_fb1 =
1077 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1078
1079 byFBOption = AUTO_FB_1;
1080 }
1081 }
Forest Bond92b96792009-06-13 07:38:31 -04001082
Andres More4e9b5e22013-02-12 20:36:30 -05001083 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001084 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1085 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1086 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1087 }
1088 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1089 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1090 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1091 }
1092 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1093 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1094 }
1095 }
1096 }
1097
Forest Bond92b96792009-06-13 07:38:31 -04001098 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1099 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1100 cbIVlen = 4;
1101 cbICVlen = 4;
1102 }
1103 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1104 cbIVlen = 8;//IV+ExtIV
1105 cbMIClen = 8;
1106 cbICVlen = 4;
1107 }
1108 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1109 cbIVlen = 8;//RSN Header
1110 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001111 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001112 }
Andres Moree269fc22013-02-12 20:36:29 -05001113 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001114 //MAC Header should be padding 0 to DW alignment.
1115 uPadding = 4 - (cbMACHdLen%4);
1116 uPadding %= 4;
1117 }
1118 }
1119
1120 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1121
Andres Moree269fc22013-02-12 20:36:29 -05001122 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1123 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001124 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001125 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001126 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1127 }
1128
Andres Moreb902fbf2013-02-25 20:32:51 -05001129 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001130 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1131
Forest Bond92b96792009-06-13 07:38:31 -04001132 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1133 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001134 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001135 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001136 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001137 }
1138 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001139 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001140 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001141 }
1142 } else {
1143 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001144 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001145 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001146 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001147 }
Andres Moree269fc22013-02-12 20:36:29 -05001148 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001149 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001150 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001151 }
1152 } // Auto Fall Back
1153 }
1154 else {//802.11a/b packet
1155 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001156 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001157 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001158 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001159 }
Andres Moree269fc22013-02-12 20:36:29 -05001160 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001161 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001162 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001163 }
1164 } else {
1165 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001166 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001167 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001168 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001169 }
Andres Moree269fc22013-02-12 20:36:29 -05001170 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001171 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001172 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001173 }
1174 } // Auto Fall Back
1175 }
1176
Andres Moreb902fbf2013-02-25 20:32:51 -05001177 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1178 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1179 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001180
Forest Bond92b96792009-06-13 07:38:31 -04001181 //=========================
1182 // No Fragmentation
1183 //=========================
1184 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1185 byFragType = FRAGCTL_NONFRAG;
1186 //uDMAIdx = TYPE_AC0DMA;
1187 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1188
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001189 /* Fill FIFO, RrvTime, RTS and CTS */
1190 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1191 tx_buffer, &pMICHDR, cbMICHDR,
1192 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001193
Forest Bond92b96792009-06-13 07:38:31 -04001194 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001195 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001196 byFragType, uDMAIdx, 0);
1197
Andres More4e9b5e22013-02-12 20:36:30 -05001198 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001199 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001200 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001201 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001202
1203 if (pDevice->bEnableHostWEP) {
1204 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1205 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1206 }
1207 }
1208
1209 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001210 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001211 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001212 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1213 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001214 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001215 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001216 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001217 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001218 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001219 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001220 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001221 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001222 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001223
1224 }
1225
1226 }
1227
Forest Bond92b96792009-06-13 07:38:31 -04001228 if (pPacket != NULL) {
1229 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001230 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001231 (pPacket + ETH_HLEN),
1232 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001233 );
1234
1235 } else {
1236 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001237 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001238 }
1239
Andres More4e9b5e22013-02-12 20:36:30 -05001240 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001241
1242 ///////////////////////////////////////////////////////////////////
1243
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001244 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1245 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1246 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1247 }
Forest Bond92b96792009-06-13 07:38:31 -04001248 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001249 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1250 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001251 }
1252 else {
Andres More52a7e642013-02-25 20:32:53 -05001253 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1254 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001255 }
1256 // DO Software Michael
1257 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001258 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001259 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001260 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1262 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001263
1264 ///////////////////////////////////////////////////////////////////
1265
1266 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1267 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001268 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001269 //}
1270 //DBG_PRN_GRP12(("\n\n\n"));
1271
1272 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1273
Andres More52a7e642013-02-25 20:32:53 -05001274 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1275 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001276
1277 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1278 MIC_vUnInit();
1279
Andres More4e9b5e22013-02-12 20:36:30 -05001280 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001281 *pdwMIC_L = 0;
1282 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001283 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001284 }
1285 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1286 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1287 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1288 }
1289
Andres More4e9b5e22013-02-12 20:36:30 -05001290 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001291
Andres More3eaca0d2013-02-25 20:32:52 -05001292 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001293
Andres More4e9b5e22013-02-12 20:36:30 -05001294 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1295 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1296 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001297 cbFrameSize -= cbICVlen;
1298 }
1299
Forest Bond92b96792009-06-13 07:38:31 -04001300 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001301
1302 *pcbHeaderLen = cbHeaderLength;
1303 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1304
Forest Bond92b96792009-06-13 07:38:31 -04001305 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001306 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001307
Andres More4e9b5e22013-02-12 20:36:30 -05001308 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001309
1310}
1311
Forest Bond92b96792009-06-13 07:38:31 -04001312/*+
1313 *
1314 * Description:
1315 * Translate 802.3 to 802.11 header
1316 *
1317 * Parameters:
1318 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001319 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001320 * dwTxBufferAddr - Transmit Buffer
1321 * pPacket - Packet from upper layer
1322 * cbPacketSize - Transmit Data Length
1323 * Out:
1324 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1325 * pcbAppendPayload - size of append payload for 802.1H translation
1326 *
1327 * Return Value: none
1328 *
1329-*/
1330
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001331static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001332 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001333 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001334{
Andres More1cac4a42013-03-18 20:33:50 -05001335 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001336
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001337 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001338
1339 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001340 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001341 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001342 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001343 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1344 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001345 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001346 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001347 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001348 } else {
1349 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001350 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001351 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001352 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001353 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001354 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001355 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001356 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001357 &(pDevice->abyBSSID[0]),
1358 ETH_ALEN);
1359 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001360 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001361 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001362 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001363 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001364 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001365 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001366 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001367 &(pDevice->abyBSSID[0]),
1368 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001369 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001370 }
1371 }
1372
1373 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001374 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001375
Andres More1cac4a42013-03-18 20:33:50 -05001376 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001377
1378 if (pDevice->bLongHeader) {
1379 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001380 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001381 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001382 }
Andres More1cac4a42013-03-18 20:33:50 -05001383 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001384
1385 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001386 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001387
1388 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1389 pDevice->wSeqCounter++;
1390 if (pDevice->wSeqCounter > 0x0fff)
1391 pDevice->wSeqCounter = 0;
1392 }
1393
1394 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001395 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001396 }
1397}
1398
Forest Bond92b96792009-06-13 07:38:31 -04001399/*+
1400 *
1401 * Description:
1402 * Request instructs a MAC to transmit a 802.11 management packet through
1403 * the adapter onto the medium.
1404 *
1405 * Parameters:
1406 * In:
1407 * hDeviceContext - Pointer to the adapter
1408 * pPacket - A pointer to a descriptor for the packet to transmit
1409 * Out:
1410 * none
1411 *
Andres Moree269fc22013-02-12 20:36:29 -05001412 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001413 *
1414-*/
1415
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001416CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1417 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001418{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001419 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001420 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001421 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001422 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001423 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001424 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001425 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001426 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001427 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001428 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001429 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1430 u32 uPadding = 0;
1431 u16 wTxBufSize;
1432 u32 cbMacHdLen;
1433 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001434
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001435 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001436
1437 if (NULL == pContext) {
1438 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1439 return CMD_STATUS_RESOURCES;
1440 }
1441
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001442 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001443 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001444 pTxBufHead = &pTX_Buffer->fifo_head;
1445 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1446 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001447
1448 if (pDevice->byBBType == BB_TYPE_11A) {
1449 wCurrentRate = RATE_6M;
1450 byPktType = PK_TYPE_11A;
1451 } else {
1452 wCurrentRate = RATE_1M;
1453 byPktType = PK_TYPE_11B;
1454 }
1455
1456 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1457 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1458 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1459 // to set power here.
1460 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1461 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1462 } else {
1463 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1464 }
1465 pDevice->wCurrentRate = wCurrentRate;
1466
Forest Bond92b96792009-06-13 07:38:31 -04001467 //Set packet type
1468 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1469 pTxBufHead->wFIFOCtl = 0;
1470 }
1471 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1472 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1473 }
1474 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1475 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1476 }
1477 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1478 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1479 }
1480
1481 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1482 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1483
Andres More22040bb2010-08-02 20:21:44 -03001484 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001485 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001486 }
1487 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001488 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001489 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1490 };
1491
1492 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1493 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1494
1495 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1496 //Set Preamble type always long
1497 //pDevice->byPreambleType = PREAMBLE_LONG;
1498 // probe-response don't retry
1499 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001500 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001501 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1502 //}
1503 }
1504
1505 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1506
1507 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001508 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001509 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1510 } else {
1511 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1512 }
1513
1514 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001515 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001516
1517 // Notes:
1518 // Although spec says MMPDU can be fragmented; In most case,
1519 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001520 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001521
1522 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1523 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1524 cbIVlen = 4;
1525 cbICVlen = 4;
1526 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1527 }
1528 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1529 cbIVlen = 8;//IV+ExtIV
1530 cbMIClen = 8;
1531 cbICVlen = 4;
1532 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1533 //We need to get seed here for filling TxKey entry.
1534 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1535 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1536 }
1537 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1538 cbIVlen = 8;//RSN Header
1539 cbICVlen = 8;//MIC
1540 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001541 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001542 }
1543 //MAC Header should be padding 0 to DW alignment.
1544 uPadding = 4 - (cbMacHdLen%4);
1545 uPadding %= 4;
1546 }
1547
1548 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1549
1550 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001551 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001552 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1553 }
1554 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1555
1556 //Set RrvTime/RTS/CTS Buffer
1557 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001558 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001559 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001560 }
1561 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001562 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001563 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001564 }
1565
Andres Moreceb8c5d2013-03-18 20:33:49 -05001566 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001567 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1568 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001569 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001570 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1571 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001572 //=========================
1573 // No Fragmentation
1574 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001575 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001576
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001577 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001578 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001579 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001580 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001581
Andres More1cac4a42013-03-18 20:33:50 -05001582 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001583
1584 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1585
1586 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001587 u8 * pbyIVHead;
1588 u8 * pbyPayloadHead;
1589 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001590 PSKeyItem pTransmitKey = NULL;
1591
Andres Moreb902fbf2013-02-25 20:32:51 -05001592 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1593 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001594 do {
1595 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001596 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001597 pbyBSSID = pDevice->abyBSSID;
1598 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001599 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001600 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001601 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001602 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1603 break;
1604 }
1605 } else {
1606 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1607 break;
1608 }
1609 }
1610 // get group key
1611 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001612 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001613 pTransmitKey = NULL;
1614 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1615 } else {
1616 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1617 }
Andres Moree269fc22013-02-12 20:36:29 -05001618 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001619 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001620 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001621 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001622
Jim Lieb3e362592009-08-12 14:54:11 -07001623 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001624 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001625 cbFrameBodySize);
1626 }
1627 else {
1628 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001629 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001630 }
1631
Andres More1cac4a42013-03-18 20:33:50 -05001632 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001633 pDevice->wSeqCounter++ ;
1634 if (pDevice->wSeqCounter > 0x0fff)
1635 pDevice->wSeqCounter = 0;
1636
1637 if (bIsPSPOLL) {
1638 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001639 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001640 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1641 // in the same place of other packet's Duration-field).
1642 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001643 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001644 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1645 tx_cts.tx.head.cts_g.data_head;
1646 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001647 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001648 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001649 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1650 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001651 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1652 tx_ab.tx.head.data_head_ab;
1653 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001654 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1655 }
Forest Bond92b96792009-06-13 07:38:31 -04001656 }
1657
Andres More3eaca0d2013-02-25 20:32:52 -05001658 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001659 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001660 pTX_Buffer->byType = 0x00;
1661
1662 pContext->pPacket = NULL;
1663 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001664 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001665
Andres More1cac4a42013-03-18 20:33:50 -05001666 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001667 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1668 &pMACHeader->addr1[0], (u16)cbFrameSize,
1669 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001670 }
1671 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001672 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1673 &pMACHeader->addr3[0], (u16)cbFrameSize,
1674 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001675 }
1676
1677 PIPEnsSendBulkOut(pDevice,pContext);
1678 return CMD_STATUS_PENDING;
1679}
1680
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001681CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1682 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001683{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001684 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001685 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1686 u32 cbHeaderSize = 0;
1687 u16 wTxBufSize = sizeof(STxShortBufHead);
1688 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001689 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001690 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001691 u16 wCurrentRate;
1692 u32 cbFrameBodySize;
1693 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001694 u8 *pbyTxBufferAddr;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001695 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001696 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001697
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001698 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001699 if (NULL == pContext) {
1700 status = CMD_STATUS_RESOURCES;
1701 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1702 return status ;
1703 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001704
1705 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001706 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001707
1708 cbFrameBodySize = pPacket->cbPayloadLen;
1709
1710 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1711 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001712
1713 if (pDevice->byBBType == BB_TYPE_11A) {
1714 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001715 pTxDataHead = (struct vnt_tx_datahead_ab *)
1716 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001717 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001718 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1719 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001720 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001721 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001722 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001723 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001724 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001725 } else {
1726 wCurrentRate = RATE_1M;
1727 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001728 pTxDataHead = (struct vnt_tx_datahead_ab *)
1729 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001730 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001731 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1732 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001733 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001734 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001735 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001736 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001737 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001738 }
1739
1740 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001741 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001742 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001743
Andres More1cac4a42013-03-18 20:33:50 -05001744 pMACHeader->duration_id = 0;
1745 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001746 pDevice->wSeqCounter++ ;
1747 if (pDevice->wSeqCounter > 0x0fff)
1748 pDevice->wSeqCounter = 0;
1749
1750 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1751
Andres More3eaca0d2013-02-25 20:32:52 -05001752 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001753 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001754 pTX_Buffer->byType = 0x01;
1755
1756 pContext->pPacket = NULL;
1757 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001758 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001759
1760 PIPEnsSendBulkOut(pDevice,pContext);
1761 return CMD_STATUS_PENDING;
1762
1763}
1764
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001765void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1766{
1767 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001768 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001769 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001770 u8 byPktType;
1771 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001772 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001773 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001774 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001775 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001776 u32 cbFrameSize;
1777 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1778 u32 uPadding = 0;
1779 u32 cbMICHDR = 0, uLength = 0;
1780 u32 dwMICKey0, dwMICKey1;
1781 u32 dwMIC_Priority;
1782 u32 *pdwMIC_L, *pdwMIC_R;
1783 u16 wTxBufSize;
1784 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001785 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001786 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001787 u32 wCurrentRate = RATE_1M;
1788 PUWLAN_80211HDR p80211Header;
1789 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001790 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001791 SKeyItem STempKey;
1792 PSKeyItem pTransmitKey = NULL;
1793 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1794 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001795 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001796
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001797 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001798
1799 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1800 cbFrameBodySize = 0;
1801 }
1802 else {
1803 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1804 }
1805 p80211Header = (PUWLAN_80211HDR)skb->data;
1806
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001807 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001808
1809 if (NULL == pContext) {
1810 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1811 dev_kfree_skb_irq(skb);
1812 return ;
1813 }
1814
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001815 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001816 pTxBufHead = &pTX_Buffer->fifo_head;
1817 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1818 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001819
1820 if (pDevice->byBBType == BB_TYPE_11A) {
1821 wCurrentRate = RATE_6M;
1822 byPktType = PK_TYPE_11A;
1823 } else {
1824 wCurrentRate = RATE_1M;
1825 byPktType = PK_TYPE_11B;
1826 }
1827
1828 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1829 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1830 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1831 // to set power here.
1832 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1833 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1834 } else {
1835 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1836 }
1837
1838 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1839
1840 //Set packet type
1841 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1842 pTxBufHead->wFIFOCtl = 0;
1843 }
1844 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1845 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1846 }
1847 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1848 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1849 }
1850 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1851 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1852 }
1853
1854 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1855 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1856
Andres More22040bb2010-08-02 20:21:44 -03001857 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001858 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001859 if (pDevice->bEnableHostWEP) {
1860 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001861 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001862 }
Forest Bond92b96792009-06-13 07:38:31 -04001863 }
1864 else {
1865 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001866 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001867 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001868 }
Andres More4e9b5e22013-02-12 20:36:30 -05001869 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001870 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1871 };
1872
1873 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1874 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1875
1876 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1877 //Set Preamble type always long
1878 //pDevice->byPreambleType = PREAMBLE_LONG;
1879
1880 // probe-response don't retry
1881 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001882 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001883 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1884 //}
1885 }
1886
1887 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1888
1889 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001890 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001891 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1892 } else {
1893 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1894 }
1895
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001896 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001897 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1898
1899 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1900 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1901 }
1902
1903 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1904 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1905 }
1906
1907 if (cbExtSuppRate >0) {
1908 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1909 }
1910 }
1911
Forest Bond92b96792009-06-13 07:38:31 -04001912 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001913 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001914
1915 // Notes:
1916 // Although spec says MMPDU can be fragmented; In most case,
1917 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001918 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001919
Forest Bond92b96792009-06-13 07:38:31 -04001920 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1921 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1922 cbIVlen = 4;
1923 cbICVlen = 4;
1924 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1925 }
1926 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1927 cbIVlen = 8;//IV+ExtIV
1928 cbMIClen = 8;
1929 cbICVlen = 4;
1930 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1931 //We need to get seed here for filling TxKey entry.
1932 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1933 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1934 }
1935 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1936 cbIVlen = 8;//RSN Header
1937 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001938 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001939 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001940 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001941 }
1942 //MAC Header should be padding 0 to DW alignment.
1943 uPadding = 4 - (cbMacHdLen%4);
1944 uPadding %= 4;
1945 }
1946
1947 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1948
1949 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001950 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001951 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1952 }
1953 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1954
Forest Bond92b96792009-06-13 07:38:31 -04001955 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001956 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001957 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001958
1959 }
1960 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001961 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001962 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001963 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001964 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001965 &(p80211Header->sA3.abyAddr1[0]),
1966 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001967 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001968 &(p80211Header->sA3.abyAddr2[0]),
1969 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001970 //=========================
1971 // No Fragmentation
1972 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001973 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001974
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001975 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001976 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001977 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001978 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001979
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001980 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001981
1982 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1983
Andres Moreb902fbf2013-02-25 20:32:51 -05001984 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1985 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1986 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001987
1988 // Copy the Packet into a tx Buffer
1989 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1990
1991 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001992 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001993 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1994
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001995 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001996 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1997 if (cbExtSuppRate != 0) {
1998 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1999 memcpy((pbyPayloadHead + cbFrameBodySize),
2000 pMgmt->abyCurrSuppRates,
2001 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2002 );
2003 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2004 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2005 pMgmt->abyCurrExtSuppRates,
2006 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2007 );
2008 }
2009 }
2010
2011 // Set wep
2012 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2013
2014 if (pDevice->bEnableHostWEP) {
2015 pTransmitKey = &STempKey;
2016 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2017 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2018 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2019 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2020 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2021 memcpy(pTransmitKey->abyKey,
2022 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2023 pTransmitKey->uKeyLength
2024 );
2025 }
2026
2027 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2028
Andres More52a7e642013-02-25 20:32:53 -05002029 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2030 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002031
2032 // DO Software Michael
2033 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002034 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002035 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002036 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002037 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2038 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002039
2040 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2041
2042 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2043
Andres More52a7e642013-02-25 20:32:53 -05002044 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2045 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002046
2047 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2048 MIC_vUnInit();
2049
Andres More4e9b5e22013-02-12 20:36:30 -05002050 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002051 *pdwMIC_L = 0;
2052 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002053 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002054 }
2055
2056 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2057 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002058 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2059 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002060
2061 }
2062
Andres Moreb902fbf2013-02-25 20:32:51 -05002063 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002064 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002065
2066 if (pDevice->bEnableHostWEP) {
2067 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2068 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2069 }
2070
2071 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002072 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002073 }
2074 }
2075
Andres More1cac4a42013-03-18 20:33:50 -05002076 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002077 pDevice->wSeqCounter++ ;
2078 if (pDevice->wSeqCounter > 0x0fff)
2079 pDevice->wSeqCounter = 0;
2080
Forest Bond92b96792009-06-13 07:38:31 -04002081 if (bIsPSPOLL) {
2082 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2083 // of FIFO control header.
2084 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2085 // in the same place of other packet's Duration-field).
2086 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002087 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002088 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2089 tx_cts.tx.head.cts_g.data_head;
2090 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002091 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002092 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002093 cpu_to_le16(p80211Header->sA2.wDurationID);
2094 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002095 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2096 tx_ab.tx.head.data_head_ab;
2097 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002098 cpu_to_le16(p80211Header->sA2.wDurationID);
2099 }
Forest Bond92b96792009-06-13 07:38:31 -04002100 }
2101
Andres More3eaca0d2013-02-25 20:32:52 -05002102 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002103 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002104 pTX_Buffer->byType = 0x00;
2105
2106 pContext->pPacket = skb;
2107 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002108 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002109
Andres More1cac4a42013-03-18 20:33:50 -05002110 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002111 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2112 &pMACHeader->addr1[0], (u16)cbFrameSize,
2113 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002114 }
2115 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002116 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2117 &pMACHeader->addr3[0], (u16)cbFrameSize,
2118 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002119 }
2120 PIPEnsSendBulkOut(pDevice,pContext);
2121 return ;
2122
2123}
2124
Forest Bond92b96792009-06-13 07:38:31 -04002125//TYPE_AC0DMA data tx
2126/*
2127 * Description:
2128 * Tx packet via AC0DMA(DMA1)
2129 *
2130 * Parameters:
2131 * In:
2132 * pDevice - Pointer to the adapter
2133 * skb - Pointer to tx skb packet
2134 * Out:
2135 * void
2136 *
2137 * Return Value: NULL
2138 */
2139
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002140int nsDMA_tx_packet(struct vnt_private *pDevice,
2141 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002142{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002143 struct net_device_stats *pStats = &pDevice->stats;
2144 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002145 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002146 u32 BytesToWrite = 0, uHeaderLen = 0;
2147 u32 uNodeIndex = 0;
2148 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2149 u16 wAID;
2150 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002151 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002152 PSKeyItem pTransmitKey = NULL;
2153 SKeyItem STempKey;
2154 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002155 int bTKIP_UseGTK = false;
2156 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002157 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002158 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002159 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002160 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002161 u32 status;
2162 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002163 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002164
Forest Bond92b96792009-06-13 07:38:31 -04002165 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2166
2167 if (pDevice->uAssocCount == 0) {
2168 dev_kfree_skb_irq(skb);
2169 return 0;
2170 }
2171
Andres Moreb902fbf2013-02-25 20:32:51 -05002172 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002173 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002174 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002175 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2176
2177 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2178 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2179 // set tx map
2180 pMgmt->abyPSTxMap[0] |= byMask[0];
2181 return 0;
2182 }
Masanari Iida93184692012-08-13 21:21:50 +09002183 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002184
2185 if (pDevice->byBBType != BB_TYPE_11A)
2186 pDevice->wCurrentRate = RATE_2M;
2187 else
2188 pDevice->wCurrentRate = RATE_24M;
2189 // long preamble type
2190 pDevice->byPreambleType = PREAMBLE_SHORT;
2191
2192 }else {
2193
Andres Moreb902fbf2013-02-25 20:32:51 -05002194 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002195
2196 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2197
2198 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2199
2200 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2201 // set tx map
2202 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2203 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2204 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2205 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2206
2207 return 0;
2208 }
2209 // AP rate decided from node
2210 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2211 // tx preamble decided from node
2212
2213 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2214 pDevice->byPreambleType = pDevice->byShortPreamble;
2215
2216 }else {
2217 pDevice->byPreambleType = PREAMBLE_LONG;
2218 }
Andres More4e9b5e22013-02-12 20:36:30 -05002219 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002220 }
2221 }
2222
Andres Moree269fc22013-02-12 20:36:29 -05002223 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002224 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2225 dev_kfree_skb_irq(skb);
2226 return 0;
2227 }
2228 }
2229
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002230 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002231
2232 if (pContext == NULL) {
2233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2234 dev_kfree_skb_irq(skb);
2235 return STATUS_RESOURCES;
2236 }
2237
Andres Moreceb8c5d2013-03-18 20:33:49 -05002238 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002239
2240//mike add:station mode check eapol-key challenge--->
2241{
Andres Moreb902fbf2013-02-25 20:32:51 -05002242 u8 Protocol_Version; //802.1x Authentication
2243 u8 Packet_Type; //802.1x Authentication
2244 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002245 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002246
Charles Clément21ec51f2010-05-18 10:08:14 -07002247 Protocol_Version = skb->data[ETH_HLEN];
2248 Packet_Type = skb->data[ETH_HLEN+1];
2249 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2250 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 -05002251 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002252 /* 802.1x OR eapol-key challenge frame transfer */
2253 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2254 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002255 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002256 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2257 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2258 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002259 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002260 PRINT_K("WPA ");
2261 }
2262 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002263 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002264 PRINT_K("WPA2(re-keying) ");
2265 }
2266 PRINT_K("Authentication completed!!\n");
2267 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002268 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002269 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002270 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002271 PRINT_K("WPA2 Authentication completed!!\n");
2272 }
2273 }
2274 }
2275}
2276//mike add:station mode check eapol-key challenge<---
2277
Andres More4e9b5e22013-02-12 20:36:30 -05002278 if (pDevice->bEncryptionEnable == true) {
2279 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002280 // get Transmit key
2281 do {
2282 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2283 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2284 pbyBSSID = pDevice->abyBSSID;
2285 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002286 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002287 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002288 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2289 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002290 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2291 break;
2292 }
2293 } else {
2294 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2295 break;
2296 }
2297 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002298 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2299 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002300 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2301 for (ii = 0; ii< 6; ii++)
2302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2303 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2304
2305 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002306 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002307 break;
2308 }
2309 // get group key
2310 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002311 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002312 pTransmitKey = NULL;
2313 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2314 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2315 }
2316 else
2317 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2318 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002319 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002320 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2321 }
Andres Moree269fc22013-02-12 20:36:29 -05002322 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002323 }
2324
2325 if (pDevice->bEnableHostWEP) {
2326 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002327 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002328 pTransmitKey = &STempKey;
2329 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2330 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2331 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2332 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2333 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2334 memcpy(pTransmitKey->abyKey,
2335 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2336 pTransmitKey->uKeyLength
2337 );
2338 }
2339 }
2340
Andres Moreb902fbf2013-02-25 20:32:51 -05002341 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002342
2343 if (pDevice->bFixRate) {
2344 if (pDevice->byBBType == BB_TYPE_11B) {
2345 if (pDevice->uConnectionRate >= RATE_11M) {
2346 pDevice->wCurrentRate = RATE_11M;
2347 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002348 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002349 }
2350 } else {
2351 if ((pDevice->byBBType == BB_TYPE_11A) &&
2352 (pDevice->uConnectionRate <= RATE_6M)) {
2353 pDevice->wCurrentRate = RATE_6M;
2354 } else {
2355 if (pDevice->uConnectionRate >= RATE_54M)
2356 pDevice->wCurrentRate = RATE_54M;
2357 else
Andres More3eaca0d2013-02-25 20:32:52 -05002358 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002359 }
2360 }
2361 }
2362 else {
2363 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2364 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002365 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002366 // Multicast use highest data rate
2367 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2368 // preamble type
2369 pDevice->byPreambleType = pDevice->byShortPreamble;
2370 }
2371 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002372 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002373 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2374 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2375 pDevice->byPreambleType = pDevice->byShortPreamble;
2376
2377 }
2378 else {
2379 pDevice->byPreambleType = PREAMBLE_LONG;
2380 }
2381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2382 }
2383 else {
2384 if (pDevice->byBBType != BB_TYPE_11A)
2385 pDevice->wCurrentRate = RATE_2M;
2386 else
2387 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2388 // abyCurrExtSuppRates[]
2389 pDevice->byPreambleType = PREAMBLE_SHORT;
2390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2391 }
2392 }
2393 }
2394 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2395 // Infra STA rate decided from AP Node, index = 0
2396 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2397 }
2398 }
2399
Andres Moreceb8c5d2013-03-18 20:33:49 -05002400 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002401 if (pDevice->byBBType != BB_TYPE_11A) {
2402 pDevice->wCurrentRate = RATE_1M;
2403 pDevice->byACKRate = RATE_1M;
2404 pDevice->byTopCCKBasicRate = RATE_1M;
2405 pDevice->byTopOFDMBasicRate = RATE_6M;
2406 } else {
2407 pDevice->wCurrentRate = RATE_6M;
2408 pDevice->byACKRate = RATE_6M;
2409 pDevice->byTopCCKBasicRate = RATE_1M;
2410 pDevice->byTopOFDMBasicRate = RATE_6M;
2411 }
2412 }
Forest Bond92b96792009-06-13 07:38:31 -04002413
Andres More0cbd8d92010-05-06 20:34:29 -03002414 DBG_PRT(MSG_LEVEL_DEBUG,
2415 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2416 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002417
2418 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002419 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002420 }
2421
2422 if (pDevice->wCurrentRate <= RATE_11M) {
2423 byPktType = PK_TYPE_11B;
2424 }
2425
Andres More4e9b5e22013-02-12 20:36:30 -05002426 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002427 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2428 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002429 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002431 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2432 if (pTransmitKey == NULL) {
2433 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2434 }
2435 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002436 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2438 }
2439 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002440 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2441 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002442 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002443 }
2444 }
2445 }
2446
Forest Bond92b96792009-06-13 07:38:31 -04002447 if (pDevice->bEnableHostWEP) {
2448 if ((uNodeIndex != 0) &&
2449 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002450 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2451 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002452 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002453 }
2454 }
2455 }
2456 else {
2457
Forest Bond92b96792009-06-13 07:38:31 -04002458 if (pTransmitKey == NULL) {
2459 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002460 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002461 dev_kfree_skb_irq(skb);
2462 pStats->tx_dropped++;
2463 return STATUS_FAILURE;
2464 }
Forest Bond92b96792009-06-13 07:38:31 -04002465 }
2466 }
2467
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002468 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2469
Forest Bond92b96792009-06-13 07:38:31 -04002470 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002471 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002472 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002473 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002474 pDevice->wCurrentRate,
2475 &uHeaderLen, &BytesToWrite
2476 );
2477
Andres Moree269fc22013-02-12 20:36:29 -05002478 if (fConvertedPacket == false) {
2479 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002480 dev_kfree_skb_irq(skb);
2481 return STATUS_FAILURE;
2482 }
2483
Andres More4e9b5e22013-02-12 20:36:30 -05002484 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002485 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002486 bScheduleCommand((void *) pDevice,
2487 WLAN_CMD_MAC_DISPOWERSAVING,
2488 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002489 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002490 }
2491 }
2492
Andres Moreb902fbf2013-02-25 20:32:51 -05002493 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002494 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002495
2496 pContext->pPacket = skb;
2497 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002498 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002499
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002500 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2501 &pContext->sEthHeader.h_dest[0],
2502 (u16)(BytesToWrite-uHeaderLen),
2503 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002504
2505 status = PIPEnsSendBulkOut(pDevice,pContext);
2506
Andres More4e9b5e22013-02-12 20:36:30 -05002507 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002508 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002509
Andres Moreb902fbf2013-02-25 20:32:51 -05002510 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002511 }
2512
2513 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002514 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002515 dev_kfree_skb_irq(skb);
2516 return STATUS_FAILURE;
2517 }
2518 else
2519 return 0;
2520
2521}
2522
Forest Bond92b96792009-06-13 07:38:31 -04002523/*
2524 * Description:
2525 * Relay packet send (AC1DMA) from rx dpc.
2526 *
2527 * Parameters:
2528 * In:
2529 * pDevice - Pointer to the adapter
2530 * pPacket - Pointer to rx packet
2531 * cbPacketSize - rx ethernet frame size
2532 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002533 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002534 *
Andres More4e9b5e22013-02-12 20:36:30 -05002535 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002536 */
2537
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002538int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2539 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002540{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002541 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002542 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002543 u32 BytesToWrite = 0, uHeaderLen = 0;
2544 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002545 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002546 SKeyItem STempKey;
2547 PSKeyItem pTransmitKey = NULL;
2548 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002549 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002550 u8 byPktTyp;
2551 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002552 u32 status;
2553 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002554
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002555 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002556
2557 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002558 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002559 }
2560
Andres Moreceb8c5d2013-03-18 20:33:49 -05002561 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002562
Andres More4e9b5e22013-02-12 20:36:30 -05002563 if (pDevice->bEncryptionEnable == true) {
2564 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002565 // get group key
2566 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002567 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002568 pTransmitKey = NULL;
2569 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2570 } else {
2571 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2572 }
2573 }
2574
2575 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002576 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002577 pTransmitKey = &STempKey;
2578 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2579 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2580 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2581 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2582 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2583 memcpy(pTransmitKey->abyKey,
2584 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2585 pTransmitKey->uKeyLength
2586 );
2587 }
2588 }
2589
2590 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002591 pContext->bBoolInUse = false;
2592 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002593 }
2594
Andres Moreb902fbf2013-02-25 20:32:51 -05002595 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002596
2597 if (pDevice->bFixRate) {
2598 if (pDevice->byBBType == BB_TYPE_11B) {
2599 if (pDevice->uConnectionRate >= RATE_11M) {
2600 pDevice->wCurrentRate = RATE_11M;
2601 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002602 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002603 }
2604 } else {
2605 if ((pDevice->byBBType == BB_TYPE_11A) &&
2606 (pDevice->uConnectionRate <= RATE_6M)) {
2607 pDevice->wCurrentRate = RATE_6M;
2608 } else {
2609 if (pDevice->uConnectionRate >= RATE_54M)
2610 pDevice->wCurrentRate = RATE_54M;
2611 else
Andres More3eaca0d2013-02-25 20:32:52 -05002612 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002613 }
2614 }
2615 }
2616 else {
2617 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2618 }
2619
Forest Bond92b96792009-06-13 07:38:31 -04002620 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002621 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002622 }
2623
2624 if (pDevice->wCurrentRate <= RATE_11M)
2625 byPktType = PK_TYPE_11B;
2626
Andres Moreabad19d2010-07-12 16:28:32 -03002627 BytesToWrite = uDataLen + ETH_FCS_LEN;
2628
Forest Bond92b96792009-06-13 07:38:31 -04002629 // Convert the packet to an usb frame and copy into our buffer
2630 // and send the irp.
2631
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002632 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2633
Forest Bond92b96792009-06-13 07:38:31 -04002634 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002635 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002636 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2637 pbySkbData, pTransmitKey, uNodeIndex,
2638 pDevice->wCurrentRate,
2639 &uHeaderLen, &BytesToWrite
2640 );
2641
Andres Moree269fc22013-02-12 20:36:29 -05002642 if (fConvertedPacket == false) {
2643 pContext->bBoolInUse = false;
2644 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002645 }
2646
Andres Moreb902fbf2013-02-25 20:32:51 -05002647 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002648 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002649
2650 pContext->pPacket = NULL;
2651 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002652 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002653
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002654 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2655 &pContext->sEthHeader.h_dest[0],
2656 (u16)(BytesToWrite - uHeaderLen),
2657 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002658
2659 status = PIPEnsSendBulkOut(pDevice,pContext);
2660
Andres More4e9b5e22013-02-12 20:36:30 -05002661 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002662}
2663