blob: aa71d39b1259b2eaa1630a3ea1000fed27b4e83d [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.
Andres Moree269fc22013-02-12 20:36:29 -05001465 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001466
1467 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1468 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1469 cbIVlen = 4;
1470 cbICVlen = 4;
1471 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1472 }
1473 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1474 cbIVlen = 8;//IV+ExtIV
1475 cbMIClen = 8;
1476 cbICVlen = 4;
1477 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1478 //We need to get seed here for filling TxKey entry.
1479 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1480 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1481 }
1482 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1483 cbIVlen = 8;//RSN Header
1484 cbICVlen = 8;//MIC
1485 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001486 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001487 }
1488 //MAC Header should be padding 0 to DW alignment.
1489 uPadding = 4 - (cbMacHdLen%4);
1490 uPadding %= 4;
1491 }
1492
1493 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1494
1495 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001496 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001497 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1498 }
1499 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1500
1501 //Set RrvTime/RTS/CTS Buffer
1502 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001503 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001504 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001505 }
1506 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001507 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001508 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001509 }
1510
Andres Moreceb8c5d2013-03-18 20:33:49 -05001511 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001512 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1513 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001514 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001515 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1516 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001517 //=========================
1518 // No Fragmentation
1519 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001520 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001521
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001522 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001523 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001524 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001525 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001526
Andres More1cac4a42013-03-18 20:33:50 -05001527 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001528
1529 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1530
1531 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001532 u8 * pbyIVHead;
1533 u8 * pbyPayloadHead;
1534 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001535 PSKeyItem pTransmitKey = NULL;
1536
Andres Moreb902fbf2013-02-25 20:32:51 -05001537 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1538 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001539 do {
1540 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001541 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001542 pbyBSSID = pDevice->abyBSSID;
1543 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001544 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001545 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001546 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001547 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1548 break;
1549 }
1550 } else {
1551 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1552 break;
1553 }
1554 }
1555 // get group key
1556 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001557 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001558 pTransmitKey = NULL;
1559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1560 } else {
1561 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1562 }
Andres Moree269fc22013-02-12 20:36:29 -05001563 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001564 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001565 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001566 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001567
Jim Lieb3e362592009-08-12 14:54:11 -07001568 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001569 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001570 cbFrameBodySize);
1571 }
1572 else {
1573 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001574 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001575 }
1576
Andres More1cac4a42013-03-18 20:33:50 -05001577 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001578 pDevice->wSeqCounter++ ;
1579 if (pDevice->wSeqCounter > 0x0fff)
1580 pDevice->wSeqCounter = 0;
1581
1582 if (bIsPSPOLL) {
1583 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001584 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001585 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1586 // in the same place of other packet's Duration-field).
1587 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001588 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001589 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1590 tx_cts.tx.head.cts_g.data_head;
1591 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001592 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001593 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001594 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1595 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001596 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1597 tx_ab.tx.head.data_head_ab;
1598 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001599 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1600 }
Forest Bond92b96792009-06-13 07:38:31 -04001601 }
1602
Andres More3eaca0d2013-02-25 20:32:52 -05001603 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001604 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001605 pTX_Buffer->byType = 0x00;
1606
1607 pContext->pPacket = NULL;
1608 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001609 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001610
Andres More1cac4a42013-03-18 20:33:50 -05001611 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001612 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1613 &pMACHeader->addr1[0], (u16)cbFrameSize,
1614 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001615 }
1616 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001617 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1618 &pMACHeader->addr3[0], (u16)cbFrameSize,
1619 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001620 }
1621
1622 PIPEnsSendBulkOut(pDevice,pContext);
1623 return CMD_STATUS_PENDING;
1624}
1625
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001626CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1627 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001628{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001629 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001630 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001631 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1632 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001633 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001634 u16 wCurrentRate;
1635 u32 cbFrameBodySize;
1636 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001637 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001638 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001639
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001640 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001641 if (NULL == pContext) {
1642 status = CMD_STATUS_RESOURCES;
1643 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1644 return status ;
1645 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001646
1647 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001648 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001649
1650 cbFrameBodySize = pPacket->cbPayloadLen;
1651
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001652 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001653
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001654 if (pDevice->byBBType == BB_TYPE_11A) {
1655 wCurrentRate = RATE_6M;
1656
1657 /* Get SignalField,ServiceField,Length */
1658 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1659 PK_TYPE_11A, &short_head->ab);
1660
1661 /* Get Duration and TimeStampOff */
1662 short_head->duration = s_uGetDataDuration(pDevice,
1663 PK_TYPE_11A, false);
1664 short_head->time_stamp_off =
1665 vnt_time_stamp_off(pDevice, wCurrentRate);
1666 } else {
1667 wCurrentRate = RATE_1M;
1668 short_head->fifo_ctl |= FIFOCTL_11B;
1669
1670 /* Get SignalField,ServiceField,Length */
1671 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1672 PK_TYPE_11B, &short_head->ab);
1673
1674 /* Get Duration and TimeStampOff */
1675 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001676 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001677 short_head->time_stamp_off =
1678 vnt_time_stamp_off(pDevice, wCurrentRate);
1679 }
1680
Forest Bond92b96792009-06-13 07:38:31 -04001681
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001682 /* Generate Beacon Header */
1683 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001684
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001685 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1686
1687 pMACHeader->duration_id = 0;
1688 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1689 pDevice->wSeqCounter++;
1690 if (pDevice->wSeqCounter > 0x0fff)
1691 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001692
1693 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1694
Andres More3eaca0d2013-02-25 20:32:52 -05001695 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001696 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001697 pTX_Buffer->byType = 0x01;
1698
1699 pContext->pPacket = NULL;
1700 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001701 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001702
1703 PIPEnsSendBulkOut(pDevice,pContext);
1704 return CMD_STATUS_PENDING;
1705
1706}
1707
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001708void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1709{
1710 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001711 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001712 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001713 u8 byPktType;
1714 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001715 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001716 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001717 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001718 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001719 u32 cbFrameSize;
1720 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1721 u32 uPadding = 0;
1722 u32 cbMICHDR = 0, uLength = 0;
1723 u32 dwMICKey0, dwMICKey1;
1724 u32 dwMIC_Priority;
1725 u32 *pdwMIC_L, *pdwMIC_R;
1726 u16 wTxBufSize;
1727 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001728 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001729 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001730 u32 wCurrentRate = RATE_1M;
1731 PUWLAN_80211HDR p80211Header;
1732 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001733 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001734 SKeyItem STempKey;
1735 PSKeyItem pTransmitKey = NULL;
1736 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1737 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001738 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001739
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001740 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001741
1742 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1743 cbFrameBodySize = 0;
1744 }
1745 else {
1746 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1747 }
1748 p80211Header = (PUWLAN_80211HDR)skb->data;
1749
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001750 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001751
1752 if (NULL == pContext) {
1753 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1754 dev_kfree_skb_irq(skb);
1755 return ;
1756 }
1757
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001758 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001759 pTxBufHead = &pTX_Buffer->fifo_head;
1760 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1761 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001762
1763 if (pDevice->byBBType == BB_TYPE_11A) {
1764 wCurrentRate = RATE_6M;
1765 byPktType = PK_TYPE_11A;
1766 } else {
1767 wCurrentRate = RATE_1M;
1768 byPktType = PK_TYPE_11B;
1769 }
1770
1771 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1772 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1773 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1774 // to set power here.
1775 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1776 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1777 } else {
1778 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1779 }
1780
1781 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1782
1783 //Set packet type
1784 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1785 pTxBufHead->wFIFOCtl = 0;
1786 }
1787 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1788 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1789 }
1790 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1791 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1792 }
1793 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1794 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1795 }
1796
1797 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1798 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1799
Andres More22040bb2010-08-02 20:21:44 -03001800 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001801 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001802 if (pDevice->bEnableHostWEP) {
1803 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001804 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001805 }
Forest Bond92b96792009-06-13 07:38:31 -04001806 }
1807 else {
1808 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001809 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001810 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001811 }
Andres More4e9b5e22013-02-12 20:36:30 -05001812 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001813 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1814 };
1815
1816 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1817 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1818
1819 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1820 //Set Preamble type always long
1821 //pDevice->byPreambleType = PREAMBLE_LONG;
1822
1823 // probe-response don't retry
1824 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001825 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001826 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1827 //}
1828 }
1829
1830 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1831
1832 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001833 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001834 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1835 } else {
1836 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1837 }
1838
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001839 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001840 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1841
1842 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1843 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1844 }
1845
1846 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1847 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1848 }
1849
1850 if (cbExtSuppRate >0) {
1851 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1852 }
1853 }
1854
Forest Bond92b96792009-06-13 07:38:31 -04001855 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001856 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001857
1858 // Notes:
1859 // Although spec says MMPDU can be fragmented; In most case,
1860 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001861 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001862
Forest Bond92b96792009-06-13 07:38:31 -04001863 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1864 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1865 cbIVlen = 4;
1866 cbICVlen = 4;
1867 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1868 }
1869 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1870 cbIVlen = 8;//IV+ExtIV
1871 cbMIClen = 8;
1872 cbICVlen = 4;
1873 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1874 //We need to get seed here for filling TxKey entry.
1875 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1876 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1877 }
1878 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1879 cbIVlen = 8;//RSN Header
1880 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001881 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001882 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001883 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001884 }
1885 //MAC Header should be padding 0 to DW alignment.
1886 uPadding = 4 - (cbMacHdLen%4);
1887 uPadding %= 4;
1888 }
1889
1890 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1891
1892 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001893 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001894 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1895 }
1896 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1897
Forest Bond92b96792009-06-13 07:38:31 -04001898 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001899 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001900 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001901
1902 }
1903 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001904 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001905 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001906 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001907 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001908 &(p80211Header->sA3.abyAddr1[0]),
1909 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001910 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001911 &(p80211Header->sA3.abyAddr2[0]),
1912 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001913 //=========================
1914 // No Fragmentation
1915 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001916 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001917
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001918 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001919 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001920 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001921 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001922
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001923 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001924
1925 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1926
Andres Moreb902fbf2013-02-25 20:32:51 -05001927 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1928 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1929 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001930
1931 // Copy the Packet into a tx Buffer
1932 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1933
1934 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001935 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001936 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1937
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001938 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001939 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1940 if (cbExtSuppRate != 0) {
1941 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1942 memcpy((pbyPayloadHead + cbFrameBodySize),
1943 pMgmt->abyCurrSuppRates,
1944 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1945 );
1946 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1947 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1948 pMgmt->abyCurrExtSuppRates,
1949 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1950 );
1951 }
1952 }
1953
1954 // Set wep
1955 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1956
1957 if (pDevice->bEnableHostWEP) {
1958 pTransmitKey = &STempKey;
1959 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1960 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1961 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1962 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1963 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1964 memcpy(pTransmitKey->abyKey,
1965 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1966 pTransmitKey->uKeyLength
1967 );
1968 }
1969
1970 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1971
Andres More52a7e642013-02-25 20:32:53 -05001972 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1973 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001974
1975 // DO Software Michael
1976 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001977 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001978 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001979 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001980 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1981 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001982
1983 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1984
1985 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1986
Andres More52a7e642013-02-25 20:32:53 -05001987 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1988 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001989
1990 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1991 MIC_vUnInit();
1992
Andres More4e9b5e22013-02-12 20:36:30 -05001993 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001994 *pdwMIC_L = 0;
1995 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001996 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001997 }
1998
1999 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2000 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002001 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2002 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002003
2004 }
2005
Malcolm Priestley3ba09382013-10-15 21:41:38 +01002006 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002007 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002008
2009 if (pDevice->bEnableHostWEP) {
2010 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2011 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2012 }
2013
2014 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002015 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002016 }
2017 }
2018
Andres More1cac4a42013-03-18 20:33:50 -05002019 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002020 pDevice->wSeqCounter++ ;
2021 if (pDevice->wSeqCounter > 0x0fff)
2022 pDevice->wSeqCounter = 0;
2023
Forest Bond92b96792009-06-13 07:38:31 -04002024 if (bIsPSPOLL) {
2025 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2026 // of FIFO control header.
2027 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2028 // in the same place of other packet's Duration-field).
2029 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002030 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002031 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2032 tx_cts.tx.head.cts_g.data_head;
2033 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002034 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002035 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002036 cpu_to_le16(p80211Header->sA2.wDurationID);
2037 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002038 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2039 tx_ab.tx.head.data_head_ab;
2040 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002041 cpu_to_le16(p80211Header->sA2.wDurationID);
2042 }
Forest Bond92b96792009-06-13 07:38:31 -04002043 }
2044
Andres More3eaca0d2013-02-25 20:32:52 -05002045 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002046 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002047 pTX_Buffer->byType = 0x00;
2048
2049 pContext->pPacket = skb;
2050 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002051 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002052
Andres More1cac4a42013-03-18 20:33:50 -05002053 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002054 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2055 &pMACHeader->addr1[0], (u16)cbFrameSize,
2056 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002057 }
2058 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002059 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2060 &pMACHeader->addr3[0], (u16)cbFrameSize,
2061 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002062 }
2063 PIPEnsSendBulkOut(pDevice,pContext);
2064 return ;
2065
2066}
2067
Forest Bond92b96792009-06-13 07:38:31 -04002068//TYPE_AC0DMA data tx
2069/*
2070 * Description:
2071 * Tx packet via AC0DMA(DMA1)
2072 *
2073 * Parameters:
2074 * In:
2075 * pDevice - Pointer to the adapter
2076 * skb - Pointer to tx skb packet
2077 * Out:
2078 * void
2079 *
2080 * Return Value: NULL
2081 */
2082
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002083int nsDMA_tx_packet(struct vnt_private *pDevice,
2084 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002085{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002086 struct net_device_stats *pStats = &pDevice->stats;
2087 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002088 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002089 u32 BytesToWrite = 0, uHeaderLen = 0;
2090 u32 uNodeIndex = 0;
2091 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2092 u16 wAID;
2093 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002094 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002095 PSKeyItem pTransmitKey = NULL;
2096 SKeyItem STempKey;
2097 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002098 int bTKIP_UseGTK = false;
2099 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002100 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002101 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002102 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002103 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002104 u32 status;
2105 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002106 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002107
Forest Bond92b96792009-06-13 07:38:31 -04002108 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2109
2110 if (pDevice->uAssocCount == 0) {
2111 dev_kfree_skb_irq(skb);
2112 return 0;
2113 }
2114
Andres Moreb902fbf2013-02-25 20:32:51 -05002115 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002116 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002117 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002118 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2119
2120 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2121 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2122 // set tx map
2123 pMgmt->abyPSTxMap[0] |= byMask[0];
2124 return 0;
2125 }
Masanari Iida93184692012-08-13 21:21:50 +09002126 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002127
2128 if (pDevice->byBBType != BB_TYPE_11A)
2129 pDevice->wCurrentRate = RATE_2M;
2130 else
2131 pDevice->wCurrentRate = RATE_24M;
2132 // long preamble type
2133 pDevice->byPreambleType = PREAMBLE_SHORT;
2134
2135 }else {
2136
Andres Moreb902fbf2013-02-25 20:32:51 -05002137 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002138
2139 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2140
2141 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2142
2143 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2144 // set tx map
2145 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2146 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2147 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2148 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2149
2150 return 0;
2151 }
2152 // AP rate decided from node
2153 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2154 // tx preamble decided from node
2155
2156 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2157 pDevice->byPreambleType = pDevice->byShortPreamble;
2158
2159 }else {
2160 pDevice->byPreambleType = PREAMBLE_LONG;
2161 }
Andres More4e9b5e22013-02-12 20:36:30 -05002162 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002163 }
2164 }
2165
Andres Moree269fc22013-02-12 20:36:29 -05002166 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002167 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2168 dev_kfree_skb_irq(skb);
2169 return 0;
2170 }
2171 }
2172
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002173 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002174
2175 if (pContext == NULL) {
2176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2177 dev_kfree_skb_irq(skb);
2178 return STATUS_RESOURCES;
2179 }
2180
Andres Moreceb8c5d2013-03-18 20:33:49 -05002181 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002182
2183//mike add:station mode check eapol-key challenge--->
2184{
Andres Moreb902fbf2013-02-25 20:32:51 -05002185 u8 Protocol_Version; //802.1x Authentication
2186 u8 Packet_Type; //802.1x Authentication
2187 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002188 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002189
Charles Clément21ec51f2010-05-18 10:08:14 -07002190 Protocol_Version = skb->data[ETH_HLEN];
2191 Packet_Type = skb->data[ETH_HLEN+1];
2192 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2193 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 -05002194 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002195 /* 802.1x OR eapol-key challenge frame transfer */
2196 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2197 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002198 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002199 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2200 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2201 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002202 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002203 PRINT_K("WPA ");
2204 }
2205 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002206 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002207 PRINT_K("WPA2(re-keying) ");
2208 }
2209 PRINT_K("Authentication completed!!\n");
2210 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002211 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002212 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002213 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002214 PRINT_K("WPA2 Authentication completed!!\n");
2215 }
2216 }
2217 }
2218}
2219//mike add:station mode check eapol-key challenge<---
2220
Andres More4e9b5e22013-02-12 20:36:30 -05002221 if (pDevice->bEncryptionEnable == true) {
2222 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002223 // get Transmit key
2224 do {
2225 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2226 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2227 pbyBSSID = pDevice->abyBSSID;
2228 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002229 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002230 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002231 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2232 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2234 break;
2235 }
2236 } else {
2237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2238 break;
2239 }
2240 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002241 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2242 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2244 for (ii = 0; ii< 6; ii++)
2245 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2247
2248 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002249 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002250 break;
2251 }
2252 // get group key
2253 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002254 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002255 pTransmitKey = NULL;
2256 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2257 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2258 }
2259 else
2260 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2261 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002262 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002263 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2264 }
Andres Moree269fc22013-02-12 20:36:29 -05002265 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002266 }
2267
2268 if (pDevice->bEnableHostWEP) {
2269 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002270 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002271 pTransmitKey = &STempKey;
2272 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2273 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2274 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2275 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2276 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2277 memcpy(pTransmitKey->abyKey,
2278 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2279 pTransmitKey->uKeyLength
2280 );
2281 }
2282 }
2283
Andres Moreb902fbf2013-02-25 20:32:51 -05002284 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002285
2286 if (pDevice->bFixRate) {
2287 if (pDevice->byBBType == BB_TYPE_11B) {
2288 if (pDevice->uConnectionRate >= RATE_11M) {
2289 pDevice->wCurrentRate = RATE_11M;
2290 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002291 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002292 }
2293 } else {
2294 if ((pDevice->byBBType == BB_TYPE_11A) &&
2295 (pDevice->uConnectionRate <= RATE_6M)) {
2296 pDevice->wCurrentRate = RATE_6M;
2297 } else {
2298 if (pDevice->uConnectionRate >= RATE_54M)
2299 pDevice->wCurrentRate = RATE_54M;
2300 else
Andres More3eaca0d2013-02-25 20:32:52 -05002301 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002302 }
2303 }
2304 }
2305 else {
2306 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2307 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002308 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002309 // Multicast use highest data rate
2310 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2311 // preamble type
2312 pDevice->byPreambleType = pDevice->byShortPreamble;
2313 }
2314 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002315 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002316 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2317 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2318 pDevice->byPreambleType = pDevice->byShortPreamble;
2319
2320 }
2321 else {
2322 pDevice->byPreambleType = PREAMBLE_LONG;
2323 }
2324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2325 }
2326 else {
2327 if (pDevice->byBBType != BB_TYPE_11A)
2328 pDevice->wCurrentRate = RATE_2M;
2329 else
2330 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2331 // abyCurrExtSuppRates[]
2332 pDevice->byPreambleType = PREAMBLE_SHORT;
2333 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2334 }
2335 }
2336 }
2337 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2338 // Infra STA rate decided from AP Node, index = 0
2339 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2340 }
2341 }
2342
Andres Moreceb8c5d2013-03-18 20:33:49 -05002343 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002344 if (pDevice->byBBType != BB_TYPE_11A) {
2345 pDevice->wCurrentRate = RATE_1M;
2346 pDevice->byACKRate = RATE_1M;
2347 pDevice->byTopCCKBasicRate = RATE_1M;
2348 pDevice->byTopOFDMBasicRate = RATE_6M;
2349 } else {
2350 pDevice->wCurrentRate = RATE_6M;
2351 pDevice->byACKRate = RATE_6M;
2352 pDevice->byTopCCKBasicRate = RATE_1M;
2353 pDevice->byTopOFDMBasicRate = RATE_6M;
2354 }
2355 }
Forest Bond92b96792009-06-13 07:38:31 -04002356
Andres More0cbd8d92010-05-06 20:34:29 -03002357 DBG_PRT(MSG_LEVEL_DEBUG,
2358 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2359 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002360
2361 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002362 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002363 }
2364
2365 if (pDevice->wCurrentRate <= RATE_11M) {
2366 byPktType = PK_TYPE_11B;
2367 }
2368
Andres More4e9b5e22013-02-12 20:36:30 -05002369 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2371 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002372 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002374 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2375 if (pTransmitKey == NULL) {
2376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2377 }
2378 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002379 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2381 }
2382 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002383 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2384 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002385 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002386 }
2387 }
2388 }
2389
Forest Bond92b96792009-06-13 07:38:31 -04002390 if (pDevice->bEnableHostWEP) {
2391 if ((uNodeIndex != 0) &&
2392 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002393 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2394 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002395 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002396 }
2397 }
2398 }
2399 else {
2400
Forest Bond92b96792009-06-13 07:38:31 -04002401 if (pTransmitKey == NULL) {
2402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002403 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002404 dev_kfree_skb_irq(skb);
2405 pStats->tx_dropped++;
2406 return STATUS_FAILURE;
2407 }
Forest Bond92b96792009-06-13 07:38:31 -04002408 }
2409 }
2410
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002411 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2412
Forest Bond92b96792009-06-13 07:38:31 -04002413 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002414 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002415 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002416 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002417 pDevice->wCurrentRate,
2418 &uHeaderLen, &BytesToWrite
2419 );
2420
Andres Moree269fc22013-02-12 20:36:29 -05002421 if (fConvertedPacket == false) {
2422 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002423 dev_kfree_skb_irq(skb);
2424 return STATUS_FAILURE;
2425 }
2426
Andres More4e9b5e22013-02-12 20:36:30 -05002427 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002428 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002429 bScheduleCommand((void *) pDevice,
2430 WLAN_CMD_MAC_DISPOWERSAVING,
2431 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002432 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002433 }
2434 }
2435
Andres Moreb902fbf2013-02-25 20:32:51 -05002436 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002437 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002438
2439 pContext->pPacket = skb;
2440 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002441 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002442
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002443 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2444 &pContext->sEthHeader.h_dest[0],
2445 (u16)(BytesToWrite-uHeaderLen),
2446 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002447
2448 status = PIPEnsSendBulkOut(pDevice,pContext);
2449
Andres More4e9b5e22013-02-12 20:36:30 -05002450 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002451 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002452
Andres Moreb902fbf2013-02-25 20:32:51 -05002453 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002454 }
2455
2456 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002457 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002458 dev_kfree_skb_irq(skb);
2459 return STATUS_FAILURE;
2460 }
2461 else
2462 return 0;
2463
2464}
2465
Forest Bond92b96792009-06-13 07:38:31 -04002466/*
2467 * Description:
2468 * Relay packet send (AC1DMA) from rx dpc.
2469 *
2470 * Parameters:
2471 * In:
2472 * pDevice - Pointer to the adapter
2473 * pPacket - Pointer to rx packet
2474 * cbPacketSize - rx ethernet frame size
2475 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002476 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002477 *
Andres More4e9b5e22013-02-12 20:36:30 -05002478 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002479 */
2480
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002481int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2482 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002483{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002484 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002485 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002486 u32 BytesToWrite = 0, uHeaderLen = 0;
2487 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002488 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002489 SKeyItem STempKey;
2490 PSKeyItem pTransmitKey = NULL;
2491 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002492 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002493 u8 byPktTyp;
2494 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002495 u32 status;
2496 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002497
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002498 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002499
2500 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002501 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002502 }
2503
Andres Moreceb8c5d2013-03-18 20:33:49 -05002504 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002505
Andres More4e9b5e22013-02-12 20:36:30 -05002506 if (pDevice->bEncryptionEnable == true) {
2507 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002508 // get group key
2509 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002510 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002511 pTransmitKey = NULL;
2512 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2513 } else {
2514 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2515 }
2516 }
2517
2518 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002519 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002520 pTransmitKey = &STempKey;
2521 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2522 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2523 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2524 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2525 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2526 memcpy(pTransmitKey->abyKey,
2527 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2528 pTransmitKey->uKeyLength
2529 );
2530 }
2531 }
2532
2533 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002534 pContext->bBoolInUse = false;
2535 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002536 }
2537
Andres Moreb902fbf2013-02-25 20:32:51 -05002538 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002539
2540 if (pDevice->bFixRate) {
2541 if (pDevice->byBBType == BB_TYPE_11B) {
2542 if (pDevice->uConnectionRate >= RATE_11M) {
2543 pDevice->wCurrentRate = RATE_11M;
2544 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002545 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002546 }
2547 } else {
2548 if ((pDevice->byBBType == BB_TYPE_11A) &&
2549 (pDevice->uConnectionRate <= RATE_6M)) {
2550 pDevice->wCurrentRate = RATE_6M;
2551 } else {
2552 if (pDevice->uConnectionRate >= RATE_54M)
2553 pDevice->wCurrentRate = RATE_54M;
2554 else
Andres More3eaca0d2013-02-25 20:32:52 -05002555 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002556 }
2557 }
2558 }
2559 else {
2560 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2561 }
2562
Forest Bond92b96792009-06-13 07:38:31 -04002563 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002564 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002565 }
2566
2567 if (pDevice->wCurrentRate <= RATE_11M)
2568 byPktType = PK_TYPE_11B;
2569
Andres Moreabad19d2010-07-12 16:28:32 -03002570 BytesToWrite = uDataLen + ETH_FCS_LEN;
2571
Forest Bond92b96792009-06-13 07:38:31 -04002572 // Convert the packet to an usb frame and copy into our buffer
2573 // and send the irp.
2574
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002575 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2576
Forest Bond92b96792009-06-13 07:38:31 -04002577 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002578 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002579 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2580 pbySkbData, pTransmitKey, uNodeIndex,
2581 pDevice->wCurrentRate,
2582 &uHeaderLen, &BytesToWrite
2583 );
2584
Andres Moree269fc22013-02-12 20:36:29 -05002585 if (fConvertedPacket == false) {
2586 pContext->bBoolInUse = false;
2587 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002588 }
2589
Andres Moreb902fbf2013-02-25 20:32:51 -05002590 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002591 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002592
2593 pContext->pPacket = NULL;
2594 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002595 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002596
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002597 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2598 &pContext->sEthHeader.h_dest[0],
2599 (u16)(BytesToWrite - uHeaderLen),
2600 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002601
2602 status = PIPEnsSendBulkOut(pDevice,pContext);
2603
Andres More4e9b5e22013-02-12 20:36:30 -05002604 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002605}
2606