blob: cc2302900989c4827f02489f5b5ba18be4a320b6 [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
Valentina Manea3b138852013-11-04 10:44:02 +020067static const 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
Valentina Manea3b138852013-11-04 10:44:02 +020072static const 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 };
Valentina Manea3b138852013-11-04 10:44:02 +020076static const 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 Priestley3ba09382013-10-15 21:41:38 +0100110static void s_vFillTxKey(struct vnt_private *pDevice,
111 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
112 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100113 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400114
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000115static void s_vSWencryption(struct vnt_private *pDevice,
116 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
119 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100121static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000122 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100124static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100125 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
126 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400127
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100128static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100129 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500130 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400131
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100132static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100133 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100135static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000136 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
137 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400138
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000139static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400140{
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +0100141 struct vnt_usb_send_context *pContext = NULL;
142 struct vnt_usb_send_context *pReturnContext = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000143 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400144
145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
146
147 for (ii = 0; ii < pDevice->cbTD; ii++) {
Malcolm Priestley18e35e082013-09-22 20:15:58 +0100148 if (!pDevice->apTD[ii])
149 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400150 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500151 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500152 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100153 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400154 pReturnContext = pContext;
155 break;
156 }
157 }
158 if ( ii == pDevice->cbTD ) {
159 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
160 }
Andres More8611a292010-05-01 14:25:00 -0300161 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400162}
163
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000164static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
165 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400166{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000167 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400168
Andres More4b50fb42010-06-22 21:57:42 -0300169 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400170 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300171 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400172 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
173 else
174 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
175
176 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
177 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300178 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
179 pbyDestAddr,
180 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400181}
182
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100183static void s_vFillTxKey(struct vnt_private *pDevice,
184 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
185 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
186 struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400187{
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100188 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000189 u32 *pdwIV = (u32 *)pbyIVHead;
190 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500191 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000192 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400193
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100194 /* Fill TXKEY */
195 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100196 return;
Forest Bond92b96792009-06-13 07:38:31 -0400197
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100198 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
199 *pdwIV = pDevice->dwIVCounter;
200 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400201
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100202 switch (pTransmitKey->byCipherSuite) {
203 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100204 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
205 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
206 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
207 pTransmitKey->uKeyLength);
208 } else {
209 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
210 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
211 pTransmitKey->uKeyLength);
212 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
213 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
214 memcpy(pbyBuf+11, pTransmitKey->abyKey,
215 pTransmitKey->uKeyLength);
216 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100217
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100218 memcpy(pDevice->abyPRNG, pbyBuf, 16);
219 }
220 /* Append IV after Mac Header */
221 *pdwIV &= WEP_IV_MASK;
222 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
223 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100224
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100225 pDevice->dwIVCounter++;
226 if (pDevice->dwIVCounter > WEP_IV_MASK)
227 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100228
229 break;
230 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100231 pTransmitKey->wTSC15_0++;
232 if (pTransmitKey->wTSC15_0 == 0)
233 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100234
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100235 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
236 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
237 pDevice->abyPRNG);
238 memcpy(pbyBuf, pDevice->abyPRNG, 16);
239
240 /* Make IV */
241 memcpy(pdwIV, pDevice->abyPRNG, 3);
242
243 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
244 0xc0) | 0x20);
245 /* Append IV&ExtIV after Mac Header */
246 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
247
248 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
249 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
250
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100251 break;
252 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100253 pTransmitKey->wTSC15_0++;
254 if (pTransmitKey->wTSC15_0 == 0)
255 pTransmitKey->dwTSC47_16++;
256
257 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
258
259 /* Make IV */
260 *pdwIV = 0;
261 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
262 0xc0) | 0x20);
263
264 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
265
266 /* Append IV&ExtIV after Mac Header */
267 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
268
269 if (!mic_hdr)
270 return;
271
272 /* MICHDR0 */
273 mic_hdr->id = 0x59;
274 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
275 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
276
277 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
278 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
279
280 /* MICHDR1 */
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000281 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100282 mic_hdr->hlen = cpu_to_be16(28);
283 else
284 mic_hdr->hlen = cpu_to_be16(22);
285
286 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
287 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
288
289 /* MICHDR2 */
290 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
291 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100292 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100293 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100294
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000295 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100296 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
297 }
Forest Bond92b96792009-06-13 07:38:31 -0400298}
299
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000300static void s_vSWencryption(struct vnt_private *pDevice,
301 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400302{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000303 u32 cbICVlen = 4;
304 u32 dwICV = 0xffffffff;
305 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400306
307 if (pTransmitKey == NULL)
308 return;
309
310 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
311 //=======================================================================
312 // Append ICV after payload
313 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500314 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400315 // finally, we must invert dwCRC to get the correct answer
316 *pdwICV = cpu_to_le32(~dwICV);
317 // RC4 encryption
318 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
319 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
320 //=======================================================================
321 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
322 //=======================================================================
323 //Append ICV after payload
324 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500325 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400326 // finally, we must invert dwCRC to get the correct answer
327 *pdwICV = cpu_to_le32(~dwICV);
328 // RC4 encryption
329 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
330 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
331 //=======================================================================
332 }
333}
334
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100335static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
336{
337 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
338 [rate % MAX_RATE]);
339}
340
Forest Bond92b96792009-06-13 07:38:31 -0400341/*byPktType : PK_TYPE_11A 0
342 PK_TYPE_11B 1
343 PK_TYPE_11GB 2
344 PK_TYPE_11GA 3
345*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000346static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
347 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400348{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000349 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400350
351 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
352 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500353 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400354 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500355 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400356 }
357
358 if (bNeedAck) {
359 return (uDataTime + pDevice->uSIFS + uAckTime);
360 }
361 else {
362 return uDataTime;
363 }
364}
365
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100366static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
367 u32 frame_length, u16 rate, int need_ack)
368{
369 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
370 frame_length, rate, need_ack));
371}
372
Forest Bond92b96792009-06-13 07:38:31 -0400373//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100374static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000375 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400376{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000377 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400378
379 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
380
Forest Bond92b96792009-06-13 07:38:31 -0400381 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
382 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
383 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
384 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
385 }
386 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
387 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
388 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
389 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
390 }
391 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
392 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
393 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
394 }
395 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
396 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
397 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
398 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
399 return uRrvTime;
400 }
401
402 //RTSRrvTime
403 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100404 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400405}
406
407//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100408static u16 s_uGetDataDuration(struct vnt_private *pDevice,
409 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400410{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100411 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400412
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100413 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100414 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100415 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
416 byPktType, 14, pDevice->byTopCCKBasicRate);
417 else
418 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
419 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100420 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100421 }
Forest Bond92b96792009-06-13 07:38:31 -0400422
Forest Bond92b96792009-06-13 07:38:31 -0400423 return 0;
424}
425
Forest Bond92b96792009-06-13 07:38:31 -0400426//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100427static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000428 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
429 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400430{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000431 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400432
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100433 switch (byDurType) {
434 case RTSDUR_BB:
435 case RTSDUR_BA:
436 case RTSDUR_BA_F0:
437 case RTSDUR_BA_F1:
438 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
439 14, pDevice->byTopCCKBasicRate);
440 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
441 s_uGetTxRsvTime(pDevice, byPktType,
442 cbFrameLength, wRate, bNeedAck);
443 break;
Forest Bond92b96792009-06-13 07:38:31 -0400444
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100445 case RTSDUR_AA:
446 case RTSDUR_AA_F0:
447 case RTSDUR_AA_F1:
448 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
449 14, pDevice->byTopOFDMBasicRate);
450 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
451 s_uGetTxRsvTime(pDevice, byPktType,
452 cbFrameLength, wRate, bNeedAck);
453 break;
Forest Bond92b96792009-06-13 07:38:31 -0400454
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100455 case CTSDUR_BA:
456 case CTSDUR_BA_F0:
457 case CTSDUR_BA_F1:
458 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100459 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100460 break;
Forest Bond92b96792009-06-13 07:38:31 -0400461
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100462 default:
463 break;
464 }
Forest Bond92b96792009-06-13 07:38:31 -0400465
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100466 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400467}
468
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100469static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
470 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
471{
472 /* Get SignalField,ServiceField,Length */
473 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
474 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
475 PK_TYPE_11B, &buf->b);
476
477 /* Get Duration and TimeStamp */
478 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
479 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
480
481 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
482 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
483 priv->byTopCCKBasicRate);
484
485 return buf->wDuration_a;
486}
487
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100488static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
489 u16 rate, struct vnt_tx_datahead_g_fb *buf,
490 u32 frame_len, int need_ack)
491{
492 /* Get SignalField,ServiceField,Length */
493 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
494
495 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
496 PK_TYPE_11B, &buf->b);
497
498 /* Get Duration and TimeStamp */
499 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
500 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
501
502 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
503 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
504
505 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
506 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
507 priv->byTopCCKBasicRate);
508
509 return buf->wDuration_a;
510}
511
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100512static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
513 u16 rate, struct vnt_tx_datahead_a_fb *buf,
514 u32 frame_len, int need_ack)
515{
516 /* Get SignalField,ServiceField,Length */
517 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
518 /* Get Duration and TimeStampOff */
519 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
520
521 buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
522 buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
523
524 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
525
526 return buf->wDuration;
527}
528
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100529static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
530 u16 rate, struct vnt_tx_datahead_ab *buf,
531 u32 frame_len, int need_ack)
532{
533 /* Get SignalField,ServiceField,Length */
534 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
535 /* Get Duration and TimeStampOff */
536 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
537
538 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
539
540 return buf->wDuration;
541}
542
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100543static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
544 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
545 u16 duration)
546{
547 rts->duration = duration;
548 rts->frame_control = TYPE_CTL_RTS;
549
550 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
551 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
552 else
553 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
554
555 if (priv->eOPMode == OP_MODE_AP)
556 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
557 else
558 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
559
560 return 0;
561}
562
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100563static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100564 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
565 u8 pkt_type, u32 frame_len, int need_ack,
566 u16 current_rate, u8 fb_option)
567{
568 u16 rts_frame_len = 20;
569
570 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
571 PK_TYPE_11B, &buf->b);
572 BBvCalculateParameter(priv, rts_frame_len,
573 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
574
575 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
576 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
577 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
578 pkt_type, current_rate, need_ack, fb_option);
579 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
580 pkt_type, current_rate, need_ack, fb_option);
581
582 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
583
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100584 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
585 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100586}
587
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100588static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100589 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
590 u8 pkt_type, u32 frame_len, int need_ack,
591 u16 current_rate, u8 fb_option)
592{
593 u16 rts_frame_len = 20;
594
595 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
596 PK_TYPE_11B, &buf->b);
597 BBvCalculateParameter(priv, rts_frame_len,
598 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
599
600
601 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
602 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
603 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
604 pkt_type, current_rate, need_ack, fb_option);
605 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
606 pkt_type, current_rate, need_ack, fb_option);
607
608
609 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100610 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100611 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100612 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100613 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100614 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100615 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100616 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100617
618 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
619
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100620 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
621 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100622}
623
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100624static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100625 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
626 u8 pkt_type, u32 frame_len, int need_ack,
627 u16 current_rate, u8 fb_option)
628{
629 u16 rts_frame_len = 20;
630
631 BBvCalculateParameter(priv, rts_frame_len,
632 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
633
634 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
635 pkt_type, current_rate, need_ack, fb_option);
636
637 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
638
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100639 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
640 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100641}
642
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100643static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100644 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
645 u8 pkt_type, u32 frame_len, int need_ack,
646 u16 current_rate, u8 fb_option)
647{
648 u16 rts_frame_len = 20;
649
650 BBvCalculateParameter(priv, rts_frame_len,
651 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
652
653 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
654 pkt_type, current_rate, need_ack, fb_option);
655
656 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100657 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100658
659 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100660 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100661
662 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
663
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100664 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
665 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100666}
667
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100668static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100669 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500670 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400671{
Forest Bond92b96792009-06-13 07:38:31 -0400672
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100673 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100674 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400675
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100676 /* Note: So far RTSHead doesn't appear in ATIM
677 * & Beacom DMA, so we don't need to take them
678 * into account.
679 * Otherwise, we need to modified codes for them.
680 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100681 switch (byPktType) {
682 case PK_TYPE_11GB:
683 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100684 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100685 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100686 psEthHeader, byPktType, cbFrameLength,
687 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100688 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100689 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100690 psEthHeader, byPktType, cbFrameLength,
691 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100692 break;
693 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100694 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100695 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100696 psEthHeader, byPktType, cbFrameLength,
697 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100698 break;
699 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100700 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100701 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100702 psEthHeader, byPktType, cbFrameLength,
703 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100704 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100705
706 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400707}
708
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100709static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100710 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
711 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400712{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000713 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400714
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100715 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100716 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400717
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100718 if (byFBOption != AUTO_FB_NONE) {
719 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100720 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100721 /* Get SignalField,ServiceField,Length */
722 BBvCalculateParameter(pDevice, uCTSFrameLen,
723 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100724 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
725 cbFrameLength, byPktType,
726 wCurrentRate, bNeedAck, byFBOption);
727 /* Get CTSDuration_ba_f0 */
728 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100729 CTSDUR_BA_F0, cbFrameLength, byPktType,
730 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100731 /* Get CTSDuration_ba_f1 */
732 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100733 CTSDUR_BA_F1, cbFrameLength, byPktType,
734 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100735 /* Get CTS Frame body */
736 pBuf->data.duration = pBuf->wDuration_ba;
737 pBuf->data.frame_control = TYPE_CTL_CTS;
738 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100739
740 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
741 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100742 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100743 struct vnt_cts *pBuf = &head->cts_g;
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 /* Get CTSDuration_ba */
748 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
749 CTSDUR_BA, cbFrameLength, byPktType,
750 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100751 /*Get CTS Frame body*/
752 pBuf->data.duration = pBuf->wDuration_ba;
753 pBuf->data.frame_control = TYPE_CTL_CTS;
754 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100755
756 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
757 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400758 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100759
760 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400761}
762
Forest Bond92b96792009-06-13 07:38:31 -0400763/*+
764 *
765 * Description:
766 * Generate FIFO control for MAC & Baseband controller
767 *
768 * Parameters:
769 * In:
770 * pDevice - Pointer to adpater
771 * pTxDataHead - Transmit Data Buffer
772 * pTxBufHead - pTxBufHead
773 * pvRrvTime - pvRrvTime
774 * pvRTS - RTS Buffer
775 * pCTS - CTS Buffer
776 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
777 * bNeedACK - If need ACK
778 * uDMAIdx - DMA Index
779 * Out:
780 * none
781 *
782 * Return Value: none
783 *
784-*/
Andres Morecc856e62010-05-17 21:34:01 -0300785
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100786static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100787 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100788 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
789 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400790{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100791 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100792 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000793 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000794 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400795
Malcolm Priestley92928f12013-10-07 20:14:01 +0100796 pFifoHead->wReserved = wCurrentRate;
797 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400798
Malcolm Priestley92928f12013-10-07 20:14:01 +0100799 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
800 byFBOption = AUTO_FB_0;
801 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
802 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400803
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100804 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100805 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100806
Malcolm Priestley92928f12013-10-07 20:14:01 +0100807 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
808 if (need_rts) {
809 struct vnt_rrv_time_rts *pBuf =
810 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100811
Malcolm Priestley92928f12013-10-07 20:14:01 +0100812 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
813 byPktType, cbFrameSize, wCurrentRate);
814 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
815 byPktType, cbFrameSize, wCurrentRate);
816 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100817 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100818
Malcolm Priestley92928f12013-10-07 20:14:01 +0100819 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
820 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
821 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
822 PK_TYPE_11B, cbFrameSize,
823 pDevice->byTopCCKBasicRate, bNeedACK);
824
825 if (need_mic) {
826 *mic_hdr = &tx_buffer->
827 tx_head.tx_rts.tx.mic.hdr;
828 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
829 } else {
830 head = &tx_buffer->tx_head.tx_rts.tx.head;
831 }
832
833 /* Fill RTS */
834 return s_vFillRTSHead(pDevice, byPktType, head,
835 cbFrameSize, bNeedACK, psEthHeader,
836 wCurrentRate, byFBOption);
837
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100838 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100839 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
840 tx_head.tx_cts.cts;
841
842 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
843 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
844 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
845 PK_TYPE_11B, cbFrameSize,
846 pDevice->byTopCCKBasicRate, bNeedACK);
847
848 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
849 byPktType, cbFrameSize, wCurrentRate);
850
851 if (need_mic) {
852 *mic_hdr = &tx_buffer->
853 tx_head.tx_cts.tx.mic.hdr;
854 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
855 } else {
856 head = &tx_buffer->tx_head.tx_cts.tx.head;
857 }
858
859 /* Fill CTS */
860 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
861 head, cbFrameSize, bNeedACK, wCurrentRate,
862 byFBOption);
863 }
864 } else if (byPktType == PK_TYPE_11A) {
865 if (need_mic) {
866 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
867 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
868 } else {
869 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100870 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100871
Malcolm Priestley92928f12013-10-07 20:14:01 +0100872 if (need_rts) {
873 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
874 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100875
Malcolm Priestley92928f12013-10-07 20:14:01 +0100876 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100877 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100878
Malcolm Priestley92928f12013-10-07 20:14:01 +0100879 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
880 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
881
882 /* Fill RTS */
883 return s_vFillRTSHead(pDevice, byPktType, head,
884 cbFrameSize, bNeedACK, psEthHeader,
885 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100886 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100887 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
888 tx_head.tx_ab.ab;
889
890 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
891 PK_TYPE_11A, cbFrameSize,
892 wCurrentRate, bNeedACK);
893
894 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
895 wCurrentRate, &head->data_head_a_fb,
896 cbFrameSize, bNeedACK);
897 }
898 } else if (byPktType == PK_TYPE_11B) {
899 if (need_mic) {
900 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
901 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
902 } else {
903 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100904 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100905
Malcolm Priestley92928f12013-10-07 20:14:01 +0100906 if (need_rts) {
907 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
908 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100909
Malcolm Priestley92928f12013-10-07 20:14:01 +0100910 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100911 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100912
Malcolm Priestley92928f12013-10-07 20:14:01 +0100913 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
914 PK_TYPE_11B, cbFrameSize, wCurrentRate,
915 bNeedACK);
916
917 /* Fill RTS */
918 return s_vFillRTSHead(pDevice, byPktType, head,
919 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100920 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100921 } else {
922 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
923 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100924
Malcolm Priestley92928f12013-10-07 20:14:01 +0100925 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
926 PK_TYPE_11B, cbFrameSize,
927 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100928
Malcolm Priestley92928f12013-10-07 20:14:01 +0100929 return vnt_rxtx_datahead_ab(pDevice, byPktType,
930 wCurrentRate, &head->data_head_ab,
931 cbFrameSize, bNeedACK);
932 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100933 }
934
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100935 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400936}
937/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500938 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500939 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300940 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400941*/
942
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000943static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100944 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100945 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
946 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
947 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400948{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100949 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000950 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
951 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000952 u32 cb802_1_H_len;
953 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
954 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100955 int bNeedACK;
956 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000957 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
958 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
959 u8 abySNAP_Bridgetunnel[ETH_ALEN]
960 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
961 u32 uDuration;
962 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100963 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000964 u8 byFBOption = AUTO_FB_NONE, byFragType;
965 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100966 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000967 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500968 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100969
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100970 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400971
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000972 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500973 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
974 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000975 }
Forest Bond92b96792009-06-13 07:38:31 -0400976
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000977 /* Get pkt type */
978 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
979 cb802_1_H_len = 8;
980 else
981 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400982
Charles Clément21ec51f2010-05-18 10:08:14 -0700983 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400984
985 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500986 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400987
Andres More22040bb2010-08-02 20:21:44 -0300988 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000989 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500990 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500991 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -0300992 pTxBufHead->wFIFOCtl =
993 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
994 } else {
Andres More4e9b5e22013-02-12 20:36:30 -0500995 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -0300996 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
997 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000998 } else {
999 /* MSDUs in Infra mode always need ACK */
1000 bNeedACK = true;
1001 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1002 }
Forest Bond92b96792009-06-13 07:38:31 -04001003
1004 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1005
Forest Bond92b96792009-06-13 07:38:31 -04001006 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001007 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1008
Andres More3eaca0d2013-02-25 20:32:52 -05001009 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001010
1011 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001012 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001013 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1014 }
1015
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001016 /* Set Auto Fallback Ctl */
1017 if (wCurrentRate >= RATE_18M) {
1018 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1019 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1020
1021 pDevice->tx_rate_fb0 =
1022 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1023 pDevice->tx_rate_fb1 =
1024 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1025
1026 byFBOption = AUTO_FB_0;
1027 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1028 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1029 pDevice->tx_rate_fb0 =
1030 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1031 pDevice->tx_rate_fb1 =
1032 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1033
1034 byFBOption = AUTO_FB_1;
1035 }
1036 }
Forest Bond92b96792009-06-13 07:38:31 -04001037
Andres More4e9b5e22013-02-12 20:36:30 -05001038 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001039 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1040 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1041 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1042 }
1043 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1044 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1045 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1046 }
1047 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1048 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1049 }
1050 }
1051 }
1052
Forest Bond92b96792009-06-13 07:38:31 -04001053 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1054 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1055 cbIVlen = 4;
1056 cbICVlen = 4;
1057 }
1058 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1059 cbIVlen = 8;//IV+ExtIV
1060 cbMIClen = 8;
1061 cbICVlen = 4;
1062 }
1063 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1064 cbIVlen = 8;//RSN Header
1065 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001066 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001067 }
Andres Moree269fc22013-02-12 20:36:29 -05001068 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001069 //MAC Header should be padding 0 to DW alignment.
1070 uPadding = 4 - (cbMACHdLen%4);
1071 uPadding %= 4;
1072 }
1073 }
1074
1075 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1076
Andres Moree269fc22013-02-12 20:36:29 -05001077 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1078 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001079 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001080 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001081 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1082 }
1083
Andres Moreb902fbf2013-02-25 20:32:51 -05001084 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001085 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1086
Forest Bond92b96792009-06-13 07:38:31 -04001087 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1088 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001089 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001090 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001091 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001092 }
1093 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001094 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001095 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001096 }
1097 } else {
1098 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001099 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001100 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001101 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001102 }
Andres Moree269fc22013-02-12 20:36:29 -05001103 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001104 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001105 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001106 }
1107 } // Auto Fall Back
1108 }
1109 else {//802.11a/b packet
1110 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001111 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001112 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001113 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001114 }
Andres Moree269fc22013-02-12 20:36:29 -05001115 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001116 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001117 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001118 }
1119 } else {
1120 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001121 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001122 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001123 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001124 }
Andres Moree269fc22013-02-12 20:36:29 -05001125 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001126 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001127 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001128 }
1129 } // Auto Fall Back
1130 }
1131
Andres Moreb902fbf2013-02-25 20:32:51 -05001132 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1133 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1134 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001135
Forest Bond92b96792009-06-13 07:38:31 -04001136 //=========================
1137 // No Fragmentation
1138 //=========================
1139 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1140 byFragType = FRAGCTL_NONFRAG;
1141 //uDMAIdx = TYPE_AC0DMA;
1142 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1143
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001144 /* Fill FIFO, RrvTime, RTS and CTS */
1145 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1146 tx_buffer, &pMICHDR, cbMICHDR,
1147 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001148
Forest Bond92b96792009-06-13 07:38:31 -04001149 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001150 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001151 byFragType, uDMAIdx, 0);
1152
Andres More4e9b5e22013-02-12 20:36:30 -05001153 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001154 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001155 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001156 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001157
1158 if (pDevice->bEnableHostWEP) {
1159 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1160 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1161 }
1162 }
1163
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001164 /* 802.1H */
1165 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001166 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001167 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001168 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001169 abySNAP_Bridgetunnel, 6);
1170 else
1171 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001172
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001173 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001174
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001175 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1176 }
Forest Bond92b96792009-06-13 07:38:31 -04001177
Forest Bond92b96792009-06-13 07:38:31 -04001178 if (pPacket != NULL) {
1179 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001180 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001181 (pPacket + ETH_HLEN),
1182 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001183 );
1184
1185 } else {
1186 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001187 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001188 }
1189
Andres More4e9b5e22013-02-12 20:36:30 -05001190 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001191
1192 ///////////////////////////////////////////////////////////////////
1193
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001194 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1195 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1196 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1197 }
Forest Bond92b96792009-06-13 07:38:31 -04001198 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001199 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1200 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001201 }
1202 else {
Andres More52a7e642013-02-25 20:32:53 -05001203 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1204 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001205 }
1206 // DO Software Michael
1207 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001208 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001209 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001210 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1212 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001213
1214 ///////////////////////////////////////////////////////////////////
1215
1216 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1217 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001218 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001219 //}
1220 //DBG_PRN_GRP12(("\n\n\n"));
1221
1222 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1223
Andres More52a7e642013-02-25 20:32:53 -05001224 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1225 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001226
1227 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1228 MIC_vUnInit();
1229
Andres More4e9b5e22013-02-12 20:36:30 -05001230 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001231 *pdwMIC_L = 0;
1232 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001233 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001234 }
1235 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1236 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1237 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1238 }
1239
Andres More4e9b5e22013-02-12 20:36:30 -05001240 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001241
Andres More3eaca0d2013-02-25 20:32:52 -05001242 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001243
Andres More4e9b5e22013-02-12 20:36:30 -05001244 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1245 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1246 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001247 cbFrameSize -= cbICVlen;
1248 }
1249
Forest Bond92b96792009-06-13 07:38:31 -04001250 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001251
1252 *pcbHeaderLen = cbHeaderLength;
1253 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1254
Forest Bond92b96792009-06-13 07:38:31 -04001255 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001256 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001257
Andres More4e9b5e22013-02-12 20:36:30 -05001258 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001259
1260}
1261
Forest Bond92b96792009-06-13 07:38:31 -04001262/*+
1263 *
1264 * Description:
1265 * Translate 802.3 to 802.11 header
1266 *
1267 * Parameters:
1268 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001269 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001270 * dwTxBufferAddr - Transmit Buffer
1271 * pPacket - Packet from upper layer
1272 * cbPacketSize - Transmit Data Length
1273 * Out:
1274 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1275 * pcbAppendPayload - size of append payload for 802.1H translation
1276 *
1277 * Return Value: none
1278 *
1279-*/
1280
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001281static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001282 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001283 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001284{
Andres More1cac4a42013-03-18 20:33:50 -05001285 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001286
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001287 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001288
1289 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001290 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001291 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001292 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001293 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1294 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001295 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001296 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001297 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001298 } else {
1299 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001300 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001301 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001302 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001303 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001304 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001305 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001306 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001307 &(pDevice->abyBSSID[0]),
1308 ETH_ALEN);
1309 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001310 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001311 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001312 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001313 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001314 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001315 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001316 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001317 &(pDevice->abyBSSID[0]),
1318 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001319 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001320 }
1321 }
1322
1323 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001324 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001325
Andres More1cac4a42013-03-18 20:33:50 -05001326 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001327
Andres More1cac4a42013-03-18 20:33:50 -05001328 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001329
1330 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001331 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001332
1333 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1334 pDevice->wSeqCounter++;
1335 if (pDevice->wSeqCounter > 0x0fff)
1336 pDevice->wSeqCounter = 0;
1337 }
1338
1339 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001340 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001341 }
1342}
1343
Forest Bond92b96792009-06-13 07:38:31 -04001344/*+
1345 *
1346 * Description:
1347 * Request instructs a MAC to transmit a 802.11 management packet through
1348 * the adapter onto the medium.
1349 *
1350 * Parameters:
1351 * In:
1352 * hDeviceContext - Pointer to the adapter
1353 * pPacket - A pointer to a descriptor for the packet to transmit
1354 * Out:
1355 * none
1356 *
Andres Moree269fc22013-02-12 20:36:29 -05001357 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001358 *
1359-*/
1360
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001361CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1362 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001363{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001364 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001365 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001366 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001367 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001368 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001369 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001370 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001371 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001372 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001373 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001374 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1375 u32 uPadding = 0;
1376 u16 wTxBufSize;
1377 u32 cbMacHdLen;
1378 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001379
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001380 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001381
1382 if (NULL == pContext) {
1383 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1384 return CMD_STATUS_RESOURCES;
1385 }
1386
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001387 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001388 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001389 pTxBufHead = &pTX_Buffer->fifo_head;
1390 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1391 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001392
1393 if (pDevice->byBBType == BB_TYPE_11A) {
1394 wCurrentRate = RATE_6M;
1395 byPktType = PK_TYPE_11A;
1396 } else {
1397 wCurrentRate = RATE_1M;
1398 byPktType = PK_TYPE_11B;
1399 }
1400
1401 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1402 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1403 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1404 // to set power here.
1405 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1406 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1407 } else {
1408 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1409 }
1410 pDevice->wCurrentRate = wCurrentRate;
1411
Forest Bond92b96792009-06-13 07:38:31 -04001412 //Set packet type
1413 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1414 pTxBufHead->wFIFOCtl = 0;
1415 }
1416 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1417 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1418 }
1419 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1420 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1421 }
1422 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1423 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1424 }
1425
1426 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1427 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1428
Andres More22040bb2010-08-02 20:21:44 -03001429 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001430 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001431 }
1432 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001433 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001434 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1435 };
1436
1437 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1438 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1439
1440 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1441 //Set Preamble type always long
1442 //pDevice->byPreambleType = PREAMBLE_LONG;
1443 // probe-response don't retry
1444 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001445 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001446 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1447 //}
1448 }
1449
1450 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1451
1452 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001453 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001454 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1455 } else {
1456 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1457 }
1458
1459 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001460 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001461
1462 // Notes:
1463 // Although spec says MMPDU can be fragmented; In most case,
1464 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001465
1466 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1467 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1468 cbIVlen = 4;
1469 cbICVlen = 4;
1470 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1471 }
1472 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1473 cbIVlen = 8;//IV+ExtIV
1474 cbMIClen = 8;
1475 cbICVlen = 4;
1476 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1477 //We need to get seed here for filling TxKey entry.
1478 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1479 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1480 }
1481 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1482 cbIVlen = 8;//RSN Header
1483 cbICVlen = 8;//MIC
1484 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001485 }
1486 //MAC Header should be padding 0 to DW alignment.
1487 uPadding = 4 - (cbMacHdLen%4);
1488 uPadding %= 4;
1489 }
1490
1491 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1492
1493 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001494 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001495 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1496 }
1497 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1498
1499 //Set RrvTime/RTS/CTS Buffer
1500 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001501 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001502 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001503 }
1504 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001505 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001506 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001507 }
1508
Andres Moreceb8c5d2013-03-18 20:33:49 -05001509 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001510 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1511 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001512 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001513 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1514 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001515 //=========================
1516 // No Fragmentation
1517 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001518 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001519
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001520 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001521 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001522 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001523 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001524
Andres More1cac4a42013-03-18 20:33:50 -05001525 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001526
1527 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1528
1529 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001530 u8 * pbyIVHead;
1531 u8 * pbyPayloadHead;
1532 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001533 PSKeyItem pTransmitKey = NULL;
1534
Andres Moreb902fbf2013-02-25 20:32:51 -05001535 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1536 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001537 do {
1538 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001539 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001540 pbyBSSID = pDevice->abyBSSID;
1541 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001542 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001543 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001544 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1546 break;
1547 }
1548 } else {
1549 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1550 break;
1551 }
1552 }
1553 // get group key
1554 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001555 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001556 pTransmitKey = NULL;
1557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1558 } else {
1559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1560 }
Andres Moree269fc22013-02-12 20:36:29 -05001561 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001562 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001563 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001564 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001565
Jim Lieb3e362592009-08-12 14:54:11 -07001566 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001567 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001568 cbFrameBodySize);
1569 }
1570 else {
1571 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001572 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001573 }
1574
Andres More1cac4a42013-03-18 20:33:50 -05001575 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001576 pDevice->wSeqCounter++ ;
1577 if (pDevice->wSeqCounter > 0x0fff)
1578 pDevice->wSeqCounter = 0;
1579
1580 if (bIsPSPOLL) {
1581 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001582 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001583 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1584 // in the same place of other packet's Duration-field).
1585 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001586 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001587 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1588 tx_cts.tx.head.cts_g.data_head;
1589 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001590 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001591 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001592 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1593 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001594 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1595 tx_ab.tx.head.data_head_ab;
1596 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001597 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1598 }
Forest Bond92b96792009-06-13 07:38:31 -04001599 }
1600
Andres More3eaca0d2013-02-25 20:32:52 -05001601 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001602 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001603 pTX_Buffer->byType = 0x00;
1604
1605 pContext->pPacket = NULL;
1606 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001607 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001608
Andres More1cac4a42013-03-18 20:33:50 -05001609 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001610 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1611 &pMACHeader->addr1[0], (u16)cbFrameSize,
1612 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001613 }
1614 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001615 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1616 &pMACHeader->addr3[0], (u16)cbFrameSize,
1617 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001618 }
1619
1620 PIPEnsSendBulkOut(pDevice,pContext);
1621 return CMD_STATUS_PENDING;
1622}
1623
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001624CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1625 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001626{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001627 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001628 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001629 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1630 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001631 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001632 u16 wCurrentRate;
1633 u32 cbFrameBodySize;
1634 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001635 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001636 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001637
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001638 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001639 if (NULL == pContext) {
1640 status = CMD_STATUS_RESOURCES;
1641 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1642 return status ;
1643 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001644
1645 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001646 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001647
1648 cbFrameBodySize = pPacket->cbPayloadLen;
1649
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001650 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001651
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001652 if (pDevice->byBBType == BB_TYPE_11A) {
1653 wCurrentRate = RATE_6M;
1654
1655 /* Get SignalField,ServiceField,Length */
1656 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1657 PK_TYPE_11A, &short_head->ab);
1658
1659 /* Get Duration and TimeStampOff */
1660 short_head->duration = s_uGetDataDuration(pDevice,
1661 PK_TYPE_11A, false);
1662 short_head->time_stamp_off =
1663 vnt_time_stamp_off(pDevice, wCurrentRate);
1664 } else {
1665 wCurrentRate = RATE_1M;
1666 short_head->fifo_ctl |= FIFOCTL_11B;
1667
1668 /* Get SignalField,ServiceField,Length */
1669 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1670 PK_TYPE_11B, &short_head->ab);
1671
1672 /* Get Duration and TimeStampOff */
1673 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001674 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001675 short_head->time_stamp_off =
1676 vnt_time_stamp_off(pDevice, wCurrentRate);
1677 }
1678
Forest Bond92b96792009-06-13 07:38:31 -04001679
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001680 /* Generate Beacon Header */
1681 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001682
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001683 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1684
1685 pMACHeader->duration_id = 0;
1686 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1687 pDevice->wSeqCounter++;
1688 if (pDevice->wSeqCounter > 0x0fff)
1689 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001690
1691 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1692
Andres More3eaca0d2013-02-25 20:32:52 -05001693 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001694 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001695 pTX_Buffer->byType = 0x01;
1696
1697 pContext->pPacket = NULL;
1698 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001699 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001700
1701 PIPEnsSendBulkOut(pDevice,pContext);
1702 return CMD_STATUS_PENDING;
1703
1704}
1705
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001706void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1707{
1708 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001709 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001710 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001711 u8 byPktType;
1712 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001713 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001714 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001715 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001716 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001717 u32 cbFrameSize;
1718 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1719 u32 uPadding = 0;
1720 u32 cbMICHDR = 0, uLength = 0;
1721 u32 dwMICKey0, dwMICKey1;
1722 u32 dwMIC_Priority;
1723 u32 *pdwMIC_L, *pdwMIC_R;
1724 u16 wTxBufSize;
1725 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001726 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001727 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001728 u32 wCurrentRate = RATE_1M;
1729 PUWLAN_80211HDR p80211Header;
1730 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001731 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001732 SKeyItem STempKey;
1733 PSKeyItem pTransmitKey = NULL;
1734 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1735 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001736 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001737
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001738 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001739
1740 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1741 cbFrameBodySize = 0;
1742 }
1743 else {
1744 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1745 }
1746 p80211Header = (PUWLAN_80211HDR)skb->data;
1747
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001748 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001749
1750 if (NULL == pContext) {
1751 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1752 dev_kfree_skb_irq(skb);
1753 return ;
1754 }
1755
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001756 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001757 pTxBufHead = &pTX_Buffer->fifo_head;
1758 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1759 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001760
1761 if (pDevice->byBBType == BB_TYPE_11A) {
1762 wCurrentRate = RATE_6M;
1763 byPktType = PK_TYPE_11A;
1764 } else {
1765 wCurrentRate = RATE_1M;
1766 byPktType = PK_TYPE_11B;
1767 }
1768
1769 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1770 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1771 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1772 // to set power here.
1773 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1774 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1775 } else {
1776 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1777 }
1778
1779 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1780
1781 //Set packet type
1782 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1783 pTxBufHead->wFIFOCtl = 0;
1784 }
1785 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1786 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1787 }
1788 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1789 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1790 }
1791 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1792 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1793 }
1794
1795 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1796 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1797
Andres More22040bb2010-08-02 20:21:44 -03001798 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001799 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001800 if (pDevice->bEnableHostWEP) {
1801 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001802 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001803 }
Forest Bond92b96792009-06-13 07:38:31 -04001804 }
1805 else {
1806 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001807 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001808 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001809 }
Andres More4e9b5e22013-02-12 20:36:30 -05001810 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001811 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1812 };
1813
1814 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1815 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1816
1817 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1818 //Set Preamble type always long
1819 //pDevice->byPreambleType = PREAMBLE_LONG;
1820
1821 // probe-response don't retry
1822 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001823 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001824 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1825 //}
1826 }
1827
1828 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1829
1830 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001831 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001832 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1833 } else {
1834 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1835 }
1836
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001837 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001838 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1839
1840 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1841 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1842 }
1843
1844 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1845 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1846 }
1847
1848 if (cbExtSuppRate >0) {
1849 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1850 }
1851 }
1852
Forest Bond92b96792009-06-13 07:38:31 -04001853 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001854 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001855
1856 // Notes:
1857 // Although spec says MMPDU can be fragmented; In most case,
1858 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001859
Forest Bond92b96792009-06-13 07:38:31 -04001860 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1861 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1862 cbIVlen = 4;
1863 cbICVlen = 4;
1864 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1865 }
1866 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1867 cbIVlen = 8;//IV+ExtIV
1868 cbMIClen = 8;
1869 cbICVlen = 4;
1870 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1871 //We need to get seed here for filling TxKey entry.
1872 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1873 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1874 }
1875 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1876 cbIVlen = 8;//RSN Header
1877 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001878 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001879 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001880 }
1881 //MAC Header should be padding 0 to DW alignment.
1882 uPadding = 4 - (cbMacHdLen%4);
1883 uPadding %= 4;
1884 }
1885
1886 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1887
1888 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001889 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001890 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1891 }
1892 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1893
Forest Bond92b96792009-06-13 07:38:31 -04001894 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001895 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001896 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001897
1898 }
1899 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001900 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001901 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001902 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001903 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001904 &(p80211Header->sA3.abyAddr1[0]),
1905 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001906 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001907 &(p80211Header->sA3.abyAddr2[0]),
1908 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001909 //=========================
1910 // No Fragmentation
1911 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001912 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001913
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001914 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001915 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001916 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001917 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001918
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001919 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001920
1921 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1922
Andres Moreb902fbf2013-02-25 20:32:51 -05001923 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1924 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1925 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001926
1927 // Copy the Packet into a tx Buffer
1928 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1929
1930 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001931 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001932 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1933
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001934 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001935 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1936 if (cbExtSuppRate != 0) {
1937 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1938 memcpy((pbyPayloadHead + cbFrameBodySize),
1939 pMgmt->abyCurrSuppRates,
1940 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1941 );
1942 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1943 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1944 pMgmt->abyCurrExtSuppRates,
1945 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1946 );
1947 }
1948 }
1949
1950 // Set wep
1951 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1952
1953 if (pDevice->bEnableHostWEP) {
1954 pTransmitKey = &STempKey;
1955 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1956 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1957 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1958 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1959 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1960 memcpy(pTransmitKey->abyKey,
1961 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1962 pTransmitKey->uKeyLength
1963 );
1964 }
1965
1966 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1967
Andres More52a7e642013-02-25 20:32:53 -05001968 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1969 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001970
1971 // DO Software Michael
1972 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001973 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001974 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001975 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001976 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1977 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001978
1979 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1980
1981 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1982
Andres More52a7e642013-02-25 20:32:53 -05001983 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1984 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001985
1986 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1987 MIC_vUnInit();
1988
Andres More4e9b5e22013-02-12 20:36:30 -05001989 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001990 *pdwMIC_L = 0;
1991 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001992 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001993 }
1994
1995 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1996 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001997 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
1998 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04001999
2000 }
2001
Malcolm Priestley3ba09382013-10-15 21:41:38 +01002002 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002003 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002004
2005 if (pDevice->bEnableHostWEP) {
2006 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2007 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2008 }
2009
2010 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002011 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002012 }
2013 }
2014
Andres More1cac4a42013-03-18 20:33:50 -05002015 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002016 pDevice->wSeqCounter++ ;
2017 if (pDevice->wSeqCounter > 0x0fff)
2018 pDevice->wSeqCounter = 0;
2019
Forest Bond92b96792009-06-13 07:38:31 -04002020 if (bIsPSPOLL) {
2021 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2022 // of FIFO control header.
2023 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2024 // in the same place of other packet's Duration-field).
2025 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002026 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002027 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2028 tx_cts.tx.head.cts_g.data_head;
2029 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002030 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002031 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002032 cpu_to_le16(p80211Header->sA2.wDurationID);
2033 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002034 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2035 tx_ab.tx.head.data_head_ab;
2036 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002037 cpu_to_le16(p80211Header->sA2.wDurationID);
2038 }
Forest Bond92b96792009-06-13 07:38:31 -04002039 }
2040
Andres More3eaca0d2013-02-25 20:32:52 -05002041 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002042 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002043 pTX_Buffer->byType = 0x00;
2044
2045 pContext->pPacket = skb;
2046 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002047 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002048
Andres More1cac4a42013-03-18 20:33:50 -05002049 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002050 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2051 &pMACHeader->addr1[0], (u16)cbFrameSize,
2052 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002053 }
2054 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002055 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2056 &pMACHeader->addr3[0], (u16)cbFrameSize,
2057 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002058 }
2059 PIPEnsSendBulkOut(pDevice,pContext);
2060 return ;
2061
2062}
2063
Forest Bond92b96792009-06-13 07:38:31 -04002064//TYPE_AC0DMA data tx
2065/*
2066 * Description:
2067 * Tx packet via AC0DMA(DMA1)
2068 *
2069 * Parameters:
2070 * In:
2071 * pDevice - Pointer to the adapter
2072 * skb - Pointer to tx skb packet
2073 * Out:
2074 * void
2075 *
2076 * Return Value: NULL
2077 */
2078
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002079int nsDMA_tx_packet(struct vnt_private *pDevice,
2080 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002081{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002082 struct net_device_stats *pStats = &pDevice->stats;
2083 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002084 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002085 u32 BytesToWrite = 0, uHeaderLen = 0;
2086 u32 uNodeIndex = 0;
2087 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2088 u16 wAID;
2089 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002090 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002091 PSKeyItem pTransmitKey = NULL;
2092 SKeyItem STempKey;
2093 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002094 int bTKIP_UseGTK = false;
2095 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002096 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002097 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002098 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002099 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002100 u32 status;
2101 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002102 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002103
Forest Bond92b96792009-06-13 07:38:31 -04002104 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2105
2106 if (pDevice->uAssocCount == 0) {
2107 dev_kfree_skb_irq(skb);
2108 return 0;
2109 }
2110
Andres Moreb902fbf2013-02-25 20:32:51 -05002111 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002112 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002113 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002114 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2115
2116 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2117 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2118 // set tx map
2119 pMgmt->abyPSTxMap[0] |= byMask[0];
2120 return 0;
2121 }
Masanari Iida93184692012-08-13 21:21:50 +09002122 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002123
2124 if (pDevice->byBBType != BB_TYPE_11A)
2125 pDevice->wCurrentRate = RATE_2M;
2126 else
2127 pDevice->wCurrentRate = RATE_24M;
2128 // long preamble type
2129 pDevice->byPreambleType = PREAMBLE_SHORT;
2130
2131 }else {
2132
Andres Moreb902fbf2013-02-25 20:32:51 -05002133 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002134
2135 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2136
2137 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2138
2139 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2140 // set tx map
2141 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2142 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2143 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2144 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2145
2146 return 0;
2147 }
2148 // AP rate decided from node
2149 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2150 // tx preamble decided from node
2151
2152 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2153 pDevice->byPreambleType = pDevice->byShortPreamble;
2154
2155 }else {
2156 pDevice->byPreambleType = PREAMBLE_LONG;
2157 }
Andres More4e9b5e22013-02-12 20:36:30 -05002158 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002159 }
2160 }
2161
Andres Moree269fc22013-02-12 20:36:29 -05002162 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002163 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2164 dev_kfree_skb_irq(skb);
2165 return 0;
2166 }
2167 }
2168
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002169 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002170
2171 if (pContext == NULL) {
2172 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2173 dev_kfree_skb_irq(skb);
2174 return STATUS_RESOURCES;
2175 }
2176
Andres Moreceb8c5d2013-03-18 20:33:49 -05002177 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002178
2179//mike add:station mode check eapol-key challenge--->
2180{
Andres Moreb902fbf2013-02-25 20:32:51 -05002181 u8 Protocol_Version; //802.1x Authentication
2182 u8 Packet_Type; //802.1x Authentication
2183 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002184 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002185
Charles Clément21ec51f2010-05-18 10:08:14 -07002186 Protocol_Version = skb->data[ETH_HLEN];
2187 Packet_Type = skb->data[ETH_HLEN+1];
2188 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2189 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 -05002190 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002191 /* 802.1x OR eapol-key challenge frame transfer */
2192 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2193 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002194 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002195 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2196 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2197 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002198 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002199 PRINT_K("WPA ");
2200 }
2201 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002202 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002203 PRINT_K("WPA2(re-keying) ");
2204 }
2205 PRINT_K("Authentication completed!!\n");
2206 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002207 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002208 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002209 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002210 PRINT_K("WPA2 Authentication completed!!\n");
2211 }
2212 }
2213 }
2214}
2215//mike add:station mode check eapol-key challenge<---
2216
Andres More4e9b5e22013-02-12 20:36:30 -05002217 if (pDevice->bEncryptionEnable == true) {
2218 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002219 // get Transmit key
2220 do {
2221 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2222 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2223 pbyBSSID = pDevice->abyBSSID;
2224 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002225 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002226 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002227 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2228 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002229 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2230 break;
2231 }
2232 } else {
2233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2234 break;
2235 }
2236 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002237 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2238 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002239 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2240 for (ii = 0; ii< 6; ii++)
2241 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2242 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2243
2244 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002245 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002246 break;
2247 }
2248 // get group key
2249 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002250 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002251 pTransmitKey = NULL;
2252 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2253 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2254 }
2255 else
2256 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2257 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002258 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002259 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2260 }
Andres Moree269fc22013-02-12 20:36:29 -05002261 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002262 }
2263
2264 if (pDevice->bEnableHostWEP) {
2265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002266 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002267 pTransmitKey = &STempKey;
2268 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2269 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2270 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2271 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2272 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2273 memcpy(pTransmitKey->abyKey,
2274 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2275 pTransmitKey->uKeyLength
2276 );
2277 }
2278 }
2279
Andres Moreb902fbf2013-02-25 20:32:51 -05002280 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002281
2282 if (pDevice->bFixRate) {
2283 if (pDevice->byBBType == BB_TYPE_11B) {
2284 if (pDevice->uConnectionRate >= RATE_11M) {
2285 pDevice->wCurrentRate = RATE_11M;
2286 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002287 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002288 }
2289 } else {
2290 if ((pDevice->byBBType == BB_TYPE_11A) &&
2291 (pDevice->uConnectionRate <= RATE_6M)) {
2292 pDevice->wCurrentRate = RATE_6M;
2293 } else {
2294 if (pDevice->uConnectionRate >= RATE_54M)
2295 pDevice->wCurrentRate = RATE_54M;
2296 else
Andres More3eaca0d2013-02-25 20:32:52 -05002297 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002298 }
2299 }
2300 }
2301 else {
2302 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2303 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002304 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002305 // Multicast use highest data rate
2306 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2307 // preamble type
2308 pDevice->byPreambleType = pDevice->byShortPreamble;
2309 }
2310 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002311 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002312 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2313 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2314 pDevice->byPreambleType = pDevice->byShortPreamble;
2315
2316 }
2317 else {
2318 pDevice->byPreambleType = PREAMBLE_LONG;
2319 }
2320 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2321 }
2322 else {
2323 if (pDevice->byBBType != BB_TYPE_11A)
2324 pDevice->wCurrentRate = RATE_2M;
2325 else
2326 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2327 // abyCurrExtSuppRates[]
2328 pDevice->byPreambleType = PREAMBLE_SHORT;
2329 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2330 }
2331 }
2332 }
2333 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2334 // Infra STA rate decided from AP Node, index = 0
2335 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2336 }
2337 }
2338
Andres Moreceb8c5d2013-03-18 20:33:49 -05002339 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002340 if (pDevice->byBBType != BB_TYPE_11A) {
2341 pDevice->wCurrentRate = RATE_1M;
2342 pDevice->byACKRate = RATE_1M;
2343 pDevice->byTopCCKBasicRate = RATE_1M;
2344 pDevice->byTopOFDMBasicRate = RATE_6M;
2345 } else {
2346 pDevice->wCurrentRate = RATE_6M;
2347 pDevice->byACKRate = RATE_6M;
2348 pDevice->byTopCCKBasicRate = RATE_1M;
2349 pDevice->byTopOFDMBasicRate = RATE_6M;
2350 }
2351 }
Forest Bond92b96792009-06-13 07:38:31 -04002352
Andres More0cbd8d92010-05-06 20:34:29 -03002353 DBG_PRT(MSG_LEVEL_DEBUG,
2354 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2355 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002356
2357 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002358 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002359 }
2360
2361 if (pDevice->wCurrentRate <= RATE_11M) {
2362 byPktType = PK_TYPE_11B;
2363 }
2364
Andres More4e9b5e22013-02-12 20:36:30 -05002365 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002366 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2367 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002368 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002369 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002370 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2371 if (pTransmitKey == NULL) {
2372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2373 }
2374 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002375 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2377 }
2378 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2380 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002381 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002382 }
2383 }
2384 }
2385
Forest Bond92b96792009-06-13 07:38:31 -04002386 if (pDevice->bEnableHostWEP) {
2387 if ((uNodeIndex != 0) &&
2388 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002389 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2390 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002391 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002392 }
2393 }
2394 }
2395 else {
2396
Forest Bond92b96792009-06-13 07:38:31 -04002397 if (pTransmitKey == NULL) {
2398 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002399 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002400 dev_kfree_skb_irq(skb);
2401 pStats->tx_dropped++;
2402 return STATUS_FAILURE;
2403 }
Forest Bond92b96792009-06-13 07:38:31 -04002404 }
2405 }
2406
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002407 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2408
Forest Bond92b96792009-06-13 07:38:31 -04002409 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002410 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002411 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002412 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002413 pDevice->wCurrentRate,
2414 &uHeaderLen, &BytesToWrite
2415 );
2416
Andres Moree269fc22013-02-12 20:36:29 -05002417 if (fConvertedPacket == false) {
2418 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002419 dev_kfree_skb_irq(skb);
2420 return STATUS_FAILURE;
2421 }
2422
Andres More4e9b5e22013-02-12 20:36:30 -05002423 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002424 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002425 bScheduleCommand((void *) pDevice,
2426 WLAN_CMD_MAC_DISPOWERSAVING,
2427 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002428 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002429 }
2430 }
2431
Andres Moreb902fbf2013-02-25 20:32:51 -05002432 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002433 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002434
2435 pContext->pPacket = skb;
2436 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002437 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002438
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002439 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2440 &pContext->sEthHeader.h_dest[0],
2441 (u16)(BytesToWrite-uHeaderLen),
2442 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002443
2444 status = PIPEnsSendBulkOut(pDevice,pContext);
2445
Andres More4e9b5e22013-02-12 20:36:30 -05002446 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002447 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002448
Andres Moreb902fbf2013-02-25 20:32:51 -05002449 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002450 }
2451
2452 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002453 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002454 dev_kfree_skb_irq(skb);
2455 return STATUS_FAILURE;
2456 }
2457 else
2458 return 0;
2459
2460}
2461
Forest Bond92b96792009-06-13 07:38:31 -04002462/*
2463 * Description:
2464 * Relay packet send (AC1DMA) from rx dpc.
2465 *
2466 * Parameters:
2467 * In:
2468 * pDevice - Pointer to the adapter
2469 * pPacket - Pointer to rx packet
2470 * cbPacketSize - rx ethernet frame size
2471 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002472 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002473 *
Andres More4e9b5e22013-02-12 20:36:30 -05002474 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002475 */
2476
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002477int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2478 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002479{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002480 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002481 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002482 u32 BytesToWrite = 0, uHeaderLen = 0;
2483 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002484 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002485 SKeyItem STempKey;
2486 PSKeyItem pTransmitKey = NULL;
2487 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002488 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002489 u8 byPktTyp;
2490 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002491 u32 status;
2492 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002493
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002494 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002495
2496 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002497 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002498 }
2499
Andres Moreceb8c5d2013-03-18 20:33:49 -05002500 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002501
Andres More4e9b5e22013-02-12 20:36:30 -05002502 if (pDevice->bEncryptionEnable == true) {
2503 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002504 // get group key
2505 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002506 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002507 pTransmitKey = NULL;
2508 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2509 } else {
2510 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2511 }
2512 }
2513
2514 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002515 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002516 pTransmitKey = &STempKey;
2517 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2518 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2519 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2520 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2521 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2522 memcpy(pTransmitKey->abyKey,
2523 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2524 pTransmitKey->uKeyLength
2525 );
2526 }
2527 }
2528
2529 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002530 pContext->bBoolInUse = false;
2531 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002532 }
2533
Andres Moreb902fbf2013-02-25 20:32:51 -05002534 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002535
2536 if (pDevice->bFixRate) {
2537 if (pDevice->byBBType == BB_TYPE_11B) {
2538 if (pDevice->uConnectionRate >= RATE_11M) {
2539 pDevice->wCurrentRate = RATE_11M;
2540 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002541 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002542 }
2543 } else {
2544 if ((pDevice->byBBType == BB_TYPE_11A) &&
2545 (pDevice->uConnectionRate <= RATE_6M)) {
2546 pDevice->wCurrentRate = RATE_6M;
2547 } else {
2548 if (pDevice->uConnectionRate >= RATE_54M)
2549 pDevice->wCurrentRate = RATE_54M;
2550 else
Andres More3eaca0d2013-02-25 20:32:52 -05002551 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002552 }
2553 }
2554 }
2555 else {
2556 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2557 }
2558
Forest Bond92b96792009-06-13 07:38:31 -04002559 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002560 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002561 }
2562
2563 if (pDevice->wCurrentRate <= RATE_11M)
2564 byPktType = PK_TYPE_11B;
2565
Andres Moreabad19d2010-07-12 16:28:32 -03002566 BytesToWrite = uDataLen + ETH_FCS_LEN;
2567
Forest Bond92b96792009-06-13 07:38:31 -04002568 // Convert the packet to an usb frame and copy into our buffer
2569 // and send the irp.
2570
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002571 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2572
Forest Bond92b96792009-06-13 07:38:31 -04002573 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002574 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002575 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2576 pbySkbData, pTransmitKey, uNodeIndex,
2577 pDevice->wCurrentRate,
2578 &uHeaderLen, &BytesToWrite
2579 );
2580
Andres Moree269fc22013-02-12 20:36:29 -05002581 if (fConvertedPacket == false) {
2582 pContext->bBoolInUse = false;
2583 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002584 }
2585
Andres Moreb902fbf2013-02-25 20:32:51 -05002586 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002587 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002588
2589 pContext->pPacket = NULL;
2590 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002591 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002592
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002593 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2594 &pContext->sEthHeader.h_dest[0],
2595 (u16)(BytesToWrite - uHeaderLen),
2596 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002597
2598 status = PIPEnsSendBulkOut(pDevice,pContext);
2599
Andres More4e9b5e22013-02-12 20:36:30 -05002600 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002601}
2602