blob: a95575fdd408fabe967fad869577bbd2a62ea634 [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 */
281 if (pDevice->bLongHeader)
282 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 Priestley95bfb1a2013-08-27 12:29:10 +0100295 if (pDevice->bLongHeader)
296 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 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
794 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000795 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400796
Malcolm Priestley92928f12013-10-07 20:14:01 +0100797 pFifoHead->wReserved = wCurrentRate;
798 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400799
Malcolm Priestley92928f12013-10-07 20:14:01 +0100800 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
801 byFBOption = AUTO_FB_0;
802 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
803 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400804
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100805 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100806 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100807
Malcolm Priestley92928f12013-10-07 20:14:01 +0100808 if (pDevice->bLongHeader)
809 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
Forest Bond92b96792009-06-13 07:38:31 -0400810
Malcolm Priestley92928f12013-10-07 20:14:01 +0100811 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
812 if (need_rts) {
813 struct vnt_rrv_time_rts *pBuf =
814 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100815
Malcolm Priestley92928f12013-10-07 20:14:01 +0100816 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
817 byPktType, cbFrameSize, wCurrentRate);
818 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
819 byPktType, cbFrameSize, wCurrentRate);
820 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100821 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100822
Malcolm Priestley92928f12013-10-07 20:14:01 +0100823 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
824 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
825 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
826 PK_TYPE_11B, cbFrameSize,
827 pDevice->byTopCCKBasicRate, bNeedACK);
828
829 if (need_mic) {
830 *mic_hdr = &tx_buffer->
831 tx_head.tx_rts.tx.mic.hdr;
832 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
833 } else {
834 head = &tx_buffer->tx_head.tx_rts.tx.head;
835 }
836
837 /* Fill RTS */
838 return s_vFillRTSHead(pDevice, byPktType, head,
839 cbFrameSize, bNeedACK, psEthHeader,
840 wCurrentRate, byFBOption);
841
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100842 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100843 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
844 tx_head.tx_cts.cts;
845
846 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
847 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
848 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
849 PK_TYPE_11B, cbFrameSize,
850 pDevice->byTopCCKBasicRate, bNeedACK);
851
852 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
853 byPktType, cbFrameSize, wCurrentRate);
854
855 if (need_mic) {
856 *mic_hdr = &tx_buffer->
857 tx_head.tx_cts.tx.mic.hdr;
858 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
859 } else {
860 head = &tx_buffer->tx_head.tx_cts.tx.head;
861 }
862
863 /* Fill CTS */
864 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
865 head, cbFrameSize, bNeedACK, wCurrentRate,
866 byFBOption);
867 }
868 } else if (byPktType == PK_TYPE_11A) {
869 if (need_mic) {
870 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
871 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
872 } else {
873 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100874 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100875
Malcolm Priestley92928f12013-10-07 20:14:01 +0100876 if (need_rts) {
877 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
878 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100879
Malcolm Priestley92928f12013-10-07 20:14:01 +0100880 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100881 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100882
Malcolm Priestley92928f12013-10-07 20:14:01 +0100883 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
884 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
885
886 /* Fill RTS */
887 return s_vFillRTSHead(pDevice, byPktType, head,
888 cbFrameSize, bNeedACK, psEthHeader,
889 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100890 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100891 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
892 tx_head.tx_ab.ab;
893
894 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
895 PK_TYPE_11A, cbFrameSize,
896 wCurrentRate, bNeedACK);
897
898 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
899 wCurrentRate, &head->data_head_a_fb,
900 cbFrameSize, bNeedACK);
901 }
902 } else if (byPktType == PK_TYPE_11B) {
903 if (need_mic) {
904 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
905 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
906 } else {
907 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100908 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100909
Malcolm Priestley92928f12013-10-07 20:14:01 +0100910 if (need_rts) {
911 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
912 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100913
Malcolm Priestley92928f12013-10-07 20:14:01 +0100914 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100915 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100916
Malcolm Priestley92928f12013-10-07 20:14:01 +0100917 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
918 PK_TYPE_11B, cbFrameSize, wCurrentRate,
919 bNeedACK);
920
921 /* Fill RTS */
922 return s_vFillRTSHead(pDevice, byPktType, head,
923 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100924 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100925 } else {
926 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
927 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100928
Malcolm Priestley92928f12013-10-07 20:14:01 +0100929 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
930 PK_TYPE_11B, cbFrameSize,
931 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100932
Malcolm Priestley92928f12013-10-07 20:14:01 +0100933 return vnt_rxtx_datahead_ab(pDevice, byPktType,
934 wCurrentRate, &head->data_head_ab,
935 cbFrameSize, bNeedACK);
936 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100937 }
938
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100939 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400940}
941/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500942 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500943 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300944 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400945*/
946
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000947static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100948 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100949 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
950 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
951 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400952{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100953 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000954 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
955 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000956 u32 cb802_1_H_len;
957 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
958 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100959 int bNeedACK;
960 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000961 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
962 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
963 u8 abySNAP_Bridgetunnel[ETH_ALEN]
964 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
965 u32 uDuration;
966 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100967 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000968 u8 byFBOption = AUTO_FB_NONE, byFragType;
969 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100970 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000971 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500972 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100973
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100974 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400975
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000976 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500977 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
978 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000979 }
Forest Bond92b96792009-06-13 07:38:31 -0400980
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000981 /* Get pkt type */
982 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
983 cb802_1_H_len = 8;
984 else
985 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400986
Charles Clément21ec51f2010-05-18 10:08:14 -0700987 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400988
989 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500990 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400991
Andres More22040bb2010-08-02 20:21:44 -0300992 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000993 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500994 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500995 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -0300996 pTxBufHead->wFIFOCtl =
997 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
998 } else {
Andres More4e9b5e22013-02-12 20:36:30 -0500999 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001000 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1001 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001002 } else {
1003 /* MSDUs in Infra mode always need ACK */
1004 bNeedACK = true;
1005 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1006 }
Forest Bond92b96792009-06-13 07:38:31 -04001007
1008 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1009
1010 //Set FIFOCTL_LHEAD
1011 if (pDevice->bLongHeader)
1012 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1013
Forest Bond92b96792009-06-13 07:38:31 -04001014 //Set FRAGCTL_MACHDCNT
1015 if (pDevice->bLongHeader) {
1016 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1017 } else {
1018 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1019 }
Andres More3eaca0d2013-02-25 20:32:52 -05001020 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001021
1022 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001023 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001024 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1025 }
1026
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001027 /* Set Auto Fallback Ctl */
1028 if (wCurrentRate >= RATE_18M) {
1029 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1030 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1031
1032 pDevice->tx_rate_fb0 =
1033 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1034 pDevice->tx_rate_fb1 =
1035 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1036
1037 byFBOption = AUTO_FB_0;
1038 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1039 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1040 pDevice->tx_rate_fb0 =
1041 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1042 pDevice->tx_rate_fb1 =
1043 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1044
1045 byFBOption = AUTO_FB_1;
1046 }
1047 }
Forest Bond92b96792009-06-13 07:38:31 -04001048
Andres More4e9b5e22013-02-12 20:36:30 -05001049 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001050 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1051 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1052 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1053 }
1054 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1055 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1056 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1057 }
1058 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1059 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1060 }
1061 }
1062 }
1063
Forest Bond92b96792009-06-13 07:38:31 -04001064 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1065 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1066 cbIVlen = 4;
1067 cbICVlen = 4;
1068 }
1069 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1070 cbIVlen = 8;//IV+ExtIV
1071 cbMIClen = 8;
1072 cbICVlen = 4;
1073 }
1074 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1075 cbIVlen = 8;//RSN Header
1076 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001077 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001078 }
Andres Moree269fc22013-02-12 20:36:29 -05001079 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001080 //MAC Header should be padding 0 to DW alignment.
1081 uPadding = 4 - (cbMACHdLen%4);
1082 uPadding %= 4;
1083 }
1084 }
1085
1086 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1087
Andres Moree269fc22013-02-12 20:36:29 -05001088 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1089 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001090 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001091 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001092 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1093 }
1094
Andres Moreb902fbf2013-02-25 20:32:51 -05001095 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001096 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1097
Forest Bond92b96792009-06-13 07:38:31 -04001098 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1099 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001100 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001101 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001102 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001103 }
1104 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001105 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001106 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001107 }
1108 } else {
1109 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001110 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001111 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001112 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001113 }
Andres Moree269fc22013-02-12 20:36:29 -05001114 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001115 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001116 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001117 }
1118 } // Auto Fall Back
1119 }
1120 else {//802.11a/b packet
1121 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001122 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001123 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001124 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001125 }
Andres Moree269fc22013-02-12 20:36:29 -05001126 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001127 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001128 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001129 }
1130 } else {
1131 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001132 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001133 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001134 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001135 }
Andres Moree269fc22013-02-12 20:36:29 -05001136 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001137 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001138 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001139 }
1140 } // Auto Fall Back
1141 }
1142
Andres Moreb902fbf2013-02-25 20:32:51 -05001143 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1144 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1145 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001146
Forest Bond92b96792009-06-13 07:38:31 -04001147 //=========================
1148 // No Fragmentation
1149 //=========================
1150 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1151 byFragType = FRAGCTL_NONFRAG;
1152 //uDMAIdx = TYPE_AC0DMA;
1153 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1154
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001155 /* Fill FIFO, RrvTime, RTS and CTS */
1156 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1157 tx_buffer, &pMICHDR, cbMICHDR,
1158 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001159
Forest Bond92b96792009-06-13 07:38:31 -04001160 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001161 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001162 byFragType, uDMAIdx, 0);
1163
Andres More4e9b5e22013-02-12 20:36:30 -05001164 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001165 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001166 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001167 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001168
1169 if (pDevice->bEnableHostWEP) {
1170 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1171 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1172 }
1173 }
1174
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001175 /* 802.1H */
1176 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001177 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001178 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001179 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001180 abySNAP_Bridgetunnel, 6);
1181 else
1182 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001183
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001184 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001185
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001186 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1187 }
Forest Bond92b96792009-06-13 07:38:31 -04001188
Forest Bond92b96792009-06-13 07:38:31 -04001189 if (pPacket != NULL) {
1190 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001191 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001192 (pPacket + ETH_HLEN),
1193 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001194 );
1195
1196 } else {
1197 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001198 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001199 }
1200
Andres More4e9b5e22013-02-12 20:36:30 -05001201 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001202
1203 ///////////////////////////////////////////////////////////////////
1204
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001205 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1206 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1207 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1208 }
Forest Bond92b96792009-06-13 07:38:31 -04001209 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001210 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1211 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001212 }
1213 else {
Andres More52a7e642013-02-25 20:32:53 -05001214 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1215 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001216 }
1217 // DO Software Michael
1218 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001219 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001220 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001221 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001222 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1223 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001224
1225 ///////////////////////////////////////////////////////////////////
1226
1227 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1228 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001229 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001230 //}
1231 //DBG_PRN_GRP12(("\n\n\n"));
1232
1233 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1234
Andres More52a7e642013-02-25 20:32:53 -05001235 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1236 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001237
1238 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1239 MIC_vUnInit();
1240
Andres More4e9b5e22013-02-12 20:36:30 -05001241 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001242 *pdwMIC_L = 0;
1243 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001244 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001245 }
1246 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1247 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1248 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1249 }
1250
Andres More4e9b5e22013-02-12 20:36:30 -05001251 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001252
Andres More3eaca0d2013-02-25 20:32:52 -05001253 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001254
Andres More4e9b5e22013-02-12 20:36:30 -05001255 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1256 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1257 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001258 cbFrameSize -= cbICVlen;
1259 }
1260
Forest Bond92b96792009-06-13 07:38:31 -04001261 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001262
1263 *pcbHeaderLen = cbHeaderLength;
1264 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1265
Forest Bond92b96792009-06-13 07:38:31 -04001266 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001267 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001268
Andres More4e9b5e22013-02-12 20:36:30 -05001269 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001270
1271}
1272
Forest Bond92b96792009-06-13 07:38:31 -04001273/*+
1274 *
1275 * Description:
1276 * Translate 802.3 to 802.11 header
1277 *
1278 * Parameters:
1279 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001280 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001281 * dwTxBufferAddr - Transmit Buffer
1282 * pPacket - Packet from upper layer
1283 * cbPacketSize - Transmit Data Length
1284 * Out:
1285 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1286 * pcbAppendPayload - size of append payload for 802.1H translation
1287 *
1288 * Return Value: none
1289 *
1290-*/
1291
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001292static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001293 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001294 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001295{
Andres More1cac4a42013-03-18 20:33:50 -05001296 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001297
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001298 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001299
1300 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001301 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001302 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001303 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001304 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1305 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001306 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001307 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001308 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001309 } else {
1310 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001311 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001312 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001313 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001314 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001315 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001316 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001317 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001318 &(pDevice->abyBSSID[0]),
1319 ETH_ALEN);
1320 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001321 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001322 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001323 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001324 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001325 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001326 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001327 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001328 &(pDevice->abyBSSID[0]),
1329 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001330 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001331 }
1332 }
1333
1334 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001335 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001336
Andres More1cac4a42013-03-18 20:33:50 -05001337 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001338
1339 if (pDevice->bLongHeader) {
1340 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001341 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001342 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001343 }
Andres More1cac4a42013-03-18 20:33:50 -05001344 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001345
1346 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001347 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001348
1349 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1350 pDevice->wSeqCounter++;
1351 if (pDevice->wSeqCounter > 0x0fff)
1352 pDevice->wSeqCounter = 0;
1353 }
1354
1355 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001356 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001357 }
1358}
1359
Forest Bond92b96792009-06-13 07:38:31 -04001360/*+
1361 *
1362 * Description:
1363 * Request instructs a MAC to transmit a 802.11 management packet through
1364 * the adapter onto the medium.
1365 *
1366 * Parameters:
1367 * In:
1368 * hDeviceContext - Pointer to the adapter
1369 * pPacket - A pointer to a descriptor for the packet to transmit
1370 * Out:
1371 * none
1372 *
Andres Moree269fc22013-02-12 20:36:29 -05001373 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001374 *
1375-*/
1376
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001377CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1378 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001379{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001380 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001381 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001382 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001383 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001384 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001385 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001386 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001387 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001388 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001389 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001390 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1391 u32 uPadding = 0;
1392 u16 wTxBufSize;
1393 u32 cbMacHdLen;
1394 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001395
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001396 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001397
1398 if (NULL == pContext) {
1399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1400 return CMD_STATUS_RESOURCES;
1401 }
1402
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001403 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001404 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001405 pTxBufHead = &pTX_Buffer->fifo_head;
1406 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1407 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001408
1409 if (pDevice->byBBType == BB_TYPE_11A) {
1410 wCurrentRate = RATE_6M;
1411 byPktType = PK_TYPE_11A;
1412 } else {
1413 wCurrentRate = RATE_1M;
1414 byPktType = PK_TYPE_11B;
1415 }
1416
1417 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1418 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1419 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1420 // to set power here.
1421 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1422 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1423 } else {
1424 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1425 }
1426 pDevice->wCurrentRate = wCurrentRate;
1427
Forest Bond92b96792009-06-13 07:38:31 -04001428 //Set packet type
1429 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1430 pTxBufHead->wFIFOCtl = 0;
1431 }
1432 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1433 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1434 }
1435 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1436 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1437 }
1438 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1439 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1440 }
1441
1442 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1443 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1444
Andres More22040bb2010-08-02 20:21:44 -03001445 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001446 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001447 }
1448 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001449 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001450 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1451 };
1452
1453 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1454 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1455
1456 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1457 //Set Preamble type always long
1458 //pDevice->byPreambleType = PREAMBLE_LONG;
1459 // probe-response don't retry
1460 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001461 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001462 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1463 //}
1464 }
1465
1466 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1467
1468 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001469 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001470 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1471 } else {
1472 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1473 }
1474
1475 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001476 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001477
1478 // Notes:
1479 // Although spec says MMPDU can be fragmented; In most case,
1480 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001481 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001482
1483 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1484 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1485 cbIVlen = 4;
1486 cbICVlen = 4;
1487 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1488 }
1489 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1490 cbIVlen = 8;//IV+ExtIV
1491 cbMIClen = 8;
1492 cbICVlen = 4;
1493 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1494 //We need to get seed here for filling TxKey entry.
1495 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1496 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1497 }
1498 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1499 cbIVlen = 8;//RSN Header
1500 cbICVlen = 8;//MIC
1501 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001502 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001503 }
1504 //MAC Header should be padding 0 to DW alignment.
1505 uPadding = 4 - (cbMacHdLen%4);
1506 uPadding %= 4;
1507 }
1508
1509 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1510
1511 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001512 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001513 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1514 }
1515 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1516
1517 //Set RrvTime/RTS/CTS Buffer
1518 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001519 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001520 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001521 }
1522 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001523 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001524 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001525 }
1526
Andres Moreceb8c5d2013-03-18 20:33:49 -05001527 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001528 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1529 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001530 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001531 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1532 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001533 //=========================
1534 // No Fragmentation
1535 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001536 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001537
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001538 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001539 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001540 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001541 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001542
Andres More1cac4a42013-03-18 20:33:50 -05001543 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001544
1545 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1546
1547 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001548 u8 * pbyIVHead;
1549 u8 * pbyPayloadHead;
1550 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001551 PSKeyItem pTransmitKey = NULL;
1552
Andres Moreb902fbf2013-02-25 20:32:51 -05001553 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1554 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001555 do {
1556 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001557 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001558 pbyBSSID = pDevice->abyBSSID;
1559 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001560 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001561 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001562 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001563 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1564 break;
1565 }
1566 } else {
1567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1568 break;
1569 }
1570 }
1571 // get group key
1572 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001573 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001574 pTransmitKey = NULL;
1575 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1576 } else {
1577 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1578 }
Andres Moree269fc22013-02-12 20:36:29 -05001579 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001580 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001581 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001582 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001583
Jim Lieb3e362592009-08-12 14:54:11 -07001584 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001585 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001586 cbFrameBodySize);
1587 }
1588 else {
1589 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001590 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001591 }
1592
Andres More1cac4a42013-03-18 20:33:50 -05001593 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001594 pDevice->wSeqCounter++ ;
1595 if (pDevice->wSeqCounter > 0x0fff)
1596 pDevice->wSeqCounter = 0;
1597
1598 if (bIsPSPOLL) {
1599 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001600 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001601 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1602 // in the same place of other packet's Duration-field).
1603 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001604 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001605 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1606 tx_cts.tx.head.cts_g.data_head;
1607 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001608 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001609 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001610 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1611 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001612 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1613 tx_ab.tx.head.data_head_ab;
1614 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001615 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1616 }
Forest Bond92b96792009-06-13 07:38:31 -04001617 }
1618
Andres More3eaca0d2013-02-25 20:32:52 -05001619 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001620 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001621 pTX_Buffer->byType = 0x00;
1622
1623 pContext->pPacket = NULL;
1624 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001625 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001626
Andres More1cac4a42013-03-18 20:33:50 -05001627 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001628 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1629 &pMACHeader->addr1[0], (u16)cbFrameSize,
1630 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001631 }
1632 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001633 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1634 &pMACHeader->addr3[0], (u16)cbFrameSize,
1635 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001636 }
1637
1638 PIPEnsSendBulkOut(pDevice,pContext);
1639 return CMD_STATUS_PENDING;
1640}
1641
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001642CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1643 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001644{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001645 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001646 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1647 u32 cbHeaderSize = 0;
1648 u16 wTxBufSize = sizeof(STxShortBufHead);
1649 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001650 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001651 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001652 u16 wCurrentRate;
1653 u32 cbFrameBodySize;
1654 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001655 u8 *pbyTxBufferAddr;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001656 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001657 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001658
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001659 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001660 if (NULL == pContext) {
1661 status = CMD_STATUS_RESOURCES;
1662 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1663 return status ;
1664 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001665
1666 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001667 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001668
1669 cbFrameBodySize = pPacket->cbPayloadLen;
1670
1671 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1672 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001673
1674 if (pDevice->byBBType == BB_TYPE_11A) {
1675 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001676 pTxDataHead = (struct vnt_tx_datahead_ab *)
1677 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001678 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001679 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1680 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001681 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001682 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001683 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001684 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001685 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001686 } else {
1687 wCurrentRate = RATE_1M;
1688 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001689 pTxDataHead = (struct vnt_tx_datahead_ab *)
1690 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001691 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001692 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1693 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001694 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001695 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001696 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001697 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001698 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001699 }
1700
1701 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001702 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001703 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001704
Andres More1cac4a42013-03-18 20:33:50 -05001705 pMACHeader->duration_id = 0;
1706 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001707 pDevice->wSeqCounter++ ;
1708 if (pDevice->wSeqCounter > 0x0fff)
1709 pDevice->wSeqCounter = 0;
1710
1711 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1712
Andres More3eaca0d2013-02-25 20:32:52 -05001713 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001714 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001715 pTX_Buffer->byType = 0x01;
1716
1717 pContext->pPacket = NULL;
1718 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001719 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001720
1721 PIPEnsSendBulkOut(pDevice,pContext);
1722 return CMD_STATUS_PENDING;
1723
1724}
1725
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001726void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1727{
1728 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001729 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001730 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001731 u8 byPktType;
1732 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001733 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001734 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001735 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001736 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001737 u32 cbFrameSize;
1738 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1739 u32 uPadding = 0;
1740 u32 cbMICHDR = 0, uLength = 0;
1741 u32 dwMICKey0, dwMICKey1;
1742 u32 dwMIC_Priority;
1743 u32 *pdwMIC_L, *pdwMIC_R;
1744 u16 wTxBufSize;
1745 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001746 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001747 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001748 u32 wCurrentRate = RATE_1M;
1749 PUWLAN_80211HDR p80211Header;
1750 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001751 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001752 SKeyItem STempKey;
1753 PSKeyItem pTransmitKey = NULL;
1754 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1755 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001756 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001757
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001758 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001759
1760 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1761 cbFrameBodySize = 0;
1762 }
1763 else {
1764 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1765 }
1766 p80211Header = (PUWLAN_80211HDR)skb->data;
1767
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001768 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001769
1770 if (NULL == pContext) {
1771 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1772 dev_kfree_skb_irq(skb);
1773 return ;
1774 }
1775
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001776 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001777 pTxBufHead = &pTX_Buffer->fifo_head;
1778 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1779 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001780
1781 if (pDevice->byBBType == BB_TYPE_11A) {
1782 wCurrentRate = RATE_6M;
1783 byPktType = PK_TYPE_11A;
1784 } else {
1785 wCurrentRate = RATE_1M;
1786 byPktType = PK_TYPE_11B;
1787 }
1788
1789 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1790 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1791 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1792 // to set power here.
1793 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1794 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1795 } else {
1796 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1797 }
1798
1799 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1800
1801 //Set packet type
1802 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1803 pTxBufHead->wFIFOCtl = 0;
1804 }
1805 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1806 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1807 }
1808 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1809 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1810 }
1811 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1812 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1813 }
1814
1815 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1816 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1817
Andres More22040bb2010-08-02 20:21:44 -03001818 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001819 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001820 if (pDevice->bEnableHostWEP) {
1821 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001822 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001823 }
Forest Bond92b96792009-06-13 07:38:31 -04001824 }
1825 else {
1826 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001827 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001828 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001829 }
Andres More4e9b5e22013-02-12 20:36:30 -05001830 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001831 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1832 };
1833
1834 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1835 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1836
1837 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1838 //Set Preamble type always long
1839 //pDevice->byPreambleType = PREAMBLE_LONG;
1840
1841 // probe-response don't retry
1842 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001843 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001844 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1845 //}
1846 }
1847
1848 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1849
1850 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001851 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001852 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1853 } else {
1854 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1855 }
1856
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001857 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001858 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1859
1860 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1861 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1862 }
1863
1864 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1865 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1866 }
1867
1868 if (cbExtSuppRate >0) {
1869 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1870 }
1871 }
1872
Forest Bond92b96792009-06-13 07:38:31 -04001873 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001874 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001875
1876 // Notes:
1877 // Although spec says MMPDU can be fragmented; In most case,
1878 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001879 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001880
Forest Bond92b96792009-06-13 07:38:31 -04001881 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1882 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1883 cbIVlen = 4;
1884 cbICVlen = 4;
1885 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1886 }
1887 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1888 cbIVlen = 8;//IV+ExtIV
1889 cbMIClen = 8;
1890 cbICVlen = 4;
1891 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1892 //We need to get seed here for filling TxKey entry.
1893 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1894 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1895 }
1896 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1897 cbIVlen = 8;//RSN Header
1898 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001899 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001900 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001901 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001902 }
1903 //MAC Header should be padding 0 to DW alignment.
1904 uPadding = 4 - (cbMacHdLen%4);
1905 uPadding %= 4;
1906 }
1907
1908 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1909
1910 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001911 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001912 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1913 }
1914 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1915
Forest Bond92b96792009-06-13 07:38:31 -04001916 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001917 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001918 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001919
1920 }
1921 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001922 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001923 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001924 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001925 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001926 &(p80211Header->sA3.abyAddr1[0]),
1927 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001928 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001929 &(p80211Header->sA3.abyAddr2[0]),
1930 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001931 //=========================
1932 // No Fragmentation
1933 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001934 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001935
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001936 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001937 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001938 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001939 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001940
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001941 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001942
1943 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1944
Andres Moreb902fbf2013-02-25 20:32:51 -05001945 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1946 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1947 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001948
1949 // Copy the Packet into a tx Buffer
1950 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1951
1952 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001953 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001954 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1955
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001956 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001957 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1958 if (cbExtSuppRate != 0) {
1959 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1960 memcpy((pbyPayloadHead + cbFrameBodySize),
1961 pMgmt->abyCurrSuppRates,
1962 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1963 );
1964 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1965 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1966 pMgmt->abyCurrExtSuppRates,
1967 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1968 );
1969 }
1970 }
1971
1972 // Set wep
1973 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1974
1975 if (pDevice->bEnableHostWEP) {
1976 pTransmitKey = &STempKey;
1977 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1978 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1979 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1980 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1981 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1982 memcpy(pTransmitKey->abyKey,
1983 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1984 pTransmitKey->uKeyLength
1985 );
1986 }
1987
1988 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1989
Andres More52a7e642013-02-25 20:32:53 -05001990 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1991 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001992
1993 // DO Software Michael
1994 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001995 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001996 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001997 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001998 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1999 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002000
2001 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2002
2003 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2004
Andres More52a7e642013-02-25 20:32:53 -05002005 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2006 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002007
2008 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2009 MIC_vUnInit();
2010
Andres More4e9b5e22013-02-12 20:36:30 -05002011 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002012 *pdwMIC_L = 0;
2013 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002014 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002015 }
2016
2017 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2018 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2020 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002021
2022 }
2023
Malcolm Priestley3ba09382013-10-15 21:41:38 +01002024 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002025 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002026
2027 if (pDevice->bEnableHostWEP) {
2028 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2029 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2030 }
2031
2032 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002033 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002034 }
2035 }
2036
Andres More1cac4a42013-03-18 20:33:50 -05002037 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002038 pDevice->wSeqCounter++ ;
2039 if (pDevice->wSeqCounter > 0x0fff)
2040 pDevice->wSeqCounter = 0;
2041
Forest Bond92b96792009-06-13 07:38:31 -04002042 if (bIsPSPOLL) {
2043 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2044 // of FIFO control header.
2045 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2046 // in the same place of other packet's Duration-field).
2047 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002048 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002049 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2050 tx_cts.tx.head.cts_g.data_head;
2051 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002052 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002053 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002054 cpu_to_le16(p80211Header->sA2.wDurationID);
2055 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002056 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2057 tx_ab.tx.head.data_head_ab;
2058 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002059 cpu_to_le16(p80211Header->sA2.wDurationID);
2060 }
Forest Bond92b96792009-06-13 07:38:31 -04002061 }
2062
Andres More3eaca0d2013-02-25 20:32:52 -05002063 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002064 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002065 pTX_Buffer->byType = 0x00;
2066
2067 pContext->pPacket = skb;
2068 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002069 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002070
Andres More1cac4a42013-03-18 20:33:50 -05002071 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002072 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2073 &pMACHeader->addr1[0], (u16)cbFrameSize,
2074 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002075 }
2076 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002077 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2078 &pMACHeader->addr3[0], (u16)cbFrameSize,
2079 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002080 }
2081 PIPEnsSendBulkOut(pDevice,pContext);
2082 return ;
2083
2084}
2085
Forest Bond92b96792009-06-13 07:38:31 -04002086//TYPE_AC0DMA data tx
2087/*
2088 * Description:
2089 * Tx packet via AC0DMA(DMA1)
2090 *
2091 * Parameters:
2092 * In:
2093 * pDevice - Pointer to the adapter
2094 * skb - Pointer to tx skb packet
2095 * Out:
2096 * void
2097 *
2098 * Return Value: NULL
2099 */
2100
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002101int nsDMA_tx_packet(struct vnt_private *pDevice,
2102 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002103{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002104 struct net_device_stats *pStats = &pDevice->stats;
2105 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002106 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002107 u32 BytesToWrite = 0, uHeaderLen = 0;
2108 u32 uNodeIndex = 0;
2109 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2110 u16 wAID;
2111 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002112 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002113 PSKeyItem pTransmitKey = NULL;
2114 SKeyItem STempKey;
2115 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002116 int bTKIP_UseGTK = false;
2117 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002118 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002119 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002120 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002121 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002122 u32 status;
2123 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002124 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002125
Forest Bond92b96792009-06-13 07:38:31 -04002126 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2127
2128 if (pDevice->uAssocCount == 0) {
2129 dev_kfree_skb_irq(skb);
2130 return 0;
2131 }
2132
Andres Moreb902fbf2013-02-25 20:32:51 -05002133 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002134 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002135 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002136 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2137
2138 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2139 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2140 // set tx map
2141 pMgmt->abyPSTxMap[0] |= byMask[0];
2142 return 0;
2143 }
Masanari Iida93184692012-08-13 21:21:50 +09002144 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002145
2146 if (pDevice->byBBType != BB_TYPE_11A)
2147 pDevice->wCurrentRate = RATE_2M;
2148 else
2149 pDevice->wCurrentRate = RATE_24M;
2150 // long preamble type
2151 pDevice->byPreambleType = PREAMBLE_SHORT;
2152
2153 }else {
2154
Andres Moreb902fbf2013-02-25 20:32:51 -05002155 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002156
2157 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2158
2159 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2160
2161 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2162 // set tx map
2163 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2164 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2165 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2166 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2167
2168 return 0;
2169 }
2170 // AP rate decided from node
2171 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2172 // tx preamble decided from node
2173
2174 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2175 pDevice->byPreambleType = pDevice->byShortPreamble;
2176
2177 }else {
2178 pDevice->byPreambleType = PREAMBLE_LONG;
2179 }
Andres More4e9b5e22013-02-12 20:36:30 -05002180 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002181 }
2182 }
2183
Andres Moree269fc22013-02-12 20:36:29 -05002184 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002185 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2186 dev_kfree_skb_irq(skb);
2187 return 0;
2188 }
2189 }
2190
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002191 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002192
2193 if (pContext == NULL) {
2194 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2195 dev_kfree_skb_irq(skb);
2196 return STATUS_RESOURCES;
2197 }
2198
Andres Moreceb8c5d2013-03-18 20:33:49 -05002199 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002200
2201//mike add:station mode check eapol-key challenge--->
2202{
Andres Moreb902fbf2013-02-25 20:32:51 -05002203 u8 Protocol_Version; //802.1x Authentication
2204 u8 Packet_Type; //802.1x Authentication
2205 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002206 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002207
Charles Clément21ec51f2010-05-18 10:08:14 -07002208 Protocol_Version = skb->data[ETH_HLEN];
2209 Packet_Type = skb->data[ETH_HLEN+1];
2210 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2211 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 -05002212 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002213 /* 802.1x OR eapol-key challenge frame transfer */
2214 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2215 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002216 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002217 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2218 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2219 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002220 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002221 PRINT_K("WPA ");
2222 }
2223 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002224 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002225 PRINT_K("WPA2(re-keying) ");
2226 }
2227 PRINT_K("Authentication completed!!\n");
2228 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002229 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002230 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002231 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002232 PRINT_K("WPA2 Authentication completed!!\n");
2233 }
2234 }
2235 }
2236}
2237//mike add:station mode check eapol-key challenge<---
2238
Andres More4e9b5e22013-02-12 20:36:30 -05002239 if (pDevice->bEncryptionEnable == true) {
2240 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002241 // get Transmit key
2242 do {
2243 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2244 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2245 pbyBSSID = pDevice->abyBSSID;
2246 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002247 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002248 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002249 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2250 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002251 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2252 break;
2253 }
2254 } else {
2255 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2256 break;
2257 }
2258 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002259 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2260 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2262 for (ii = 0; ii< 6; ii++)
2263 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2264 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2265
2266 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002267 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002268 break;
2269 }
2270 // get group key
2271 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002272 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002273 pTransmitKey = NULL;
2274 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2275 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2276 }
2277 else
2278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2279 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002280 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002281 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2282 }
Andres Moree269fc22013-02-12 20:36:29 -05002283 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002284 }
2285
2286 if (pDevice->bEnableHostWEP) {
2287 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002288 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002289 pTransmitKey = &STempKey;
2290 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2291 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2292 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2293 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2294 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2295 memcpy(pTransmitKey->abyKey,
2296 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2297 pTransmitKey->uKeyLength
2298 );
2299 }
2300 }
2301
Andres Moreb902fbf2013-02-25 20:32:51 -05002302 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002303
2304 if (pDevice->bFixRate) {
2305 if (pDevice->byBBType == BB_TYPE_11B) {
2306 if (pDevice->uConnectionRate >= RATE_11M) {
2307 pDevice->wCurrentRate = RATE_11M;
2308 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002309 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002310 }
2311 } else {
2312 if ((pDevice->byBBType == BB_TYPE_11A) &&
2313 (pDevice->uConnectionRate <= RATE_6M)) {
2314 pDevice->wCurrentRate = RATE_6M;
2315 } else {
2316 if (pDevice->uConnectionRate >= RATE_54M)
2317 pDevice->wCurrentRate = RATE_54M;
2318 else
Andres More3eaca0d2013-02-25 20:32:52 -05002319 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002320 }
2321 }
2322 }
2323 else {
2324 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2325 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002326 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002327 // Multicast use highest data rate
2328 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2329 // preamble type
2330 pDevice->byPreambleType = pDevice->byShortPreamble;
2331 }
2332 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002333 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002334 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2335 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2336 pDevice->byPreambleType = pDevice->byShortPreamble;
2337
2338 }
2339 else {
2340 pDevice->byPreambleType = PREAMBLE_LONG;
2341 }
2342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2343 }
2344 else {
2345 if (pDevice->byBBType != BB_TYPE_11A)
2346 pDevice->wCurrentRate = RATE_2M;
2347 else
2348 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2349 // abyCurrExtSuppRates[]
2350 pDevice->byPreambleType = PREAMBLE_SHORT;
2351 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2352 }
2353 }
2354 }
2355 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2356 // Infra STA rate decided from AP Node, index = 0
2357 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2358 }
2359 }
2360
Andres Moreceb8c5d2013-03-18 20:33:49 -05002361 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002362 if (pDevice->byBBType != BB_TYPE_11A) {
2363 pDevice->wCurrentRate = RATE_1M;
2364 pDevice->byACKRate = RATE_1M;
2365 pDevice->byTopCCKBasicRate = RATE_1M;
2366 pDevice->byTopOFDMBasicRate = RATE_6M;
2367 } else {
2368 pDevice->wCurrentRate = RATE_6M;
2369 pDevice->byACKRate = RATE_6M;
2370 pDevice->byTopCCKBasicRate = RATE_1M;
2371 pDevice->byTopOFDMBasicRate = RATE_6M;
2372 }
2373 }
Forest Bond92b96792009-06-13 07:38:31 -04002374
Andres More0cbd8d92010-05-06 20:34:29 -03002375 DBG_PRT(MSG_LEVEL_DEBUG,
2376 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2377 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002378
2379 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002380 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002381 }
2382
2383 if (pDevice->wCurrentRate <= RATE_11M) {
2384 byPktType = PK_TYPE_11B;
2385 }
2386
Andres More4e9b5e22013-02-12 20:36:30 -05002387 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2389 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002390 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002392 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2393 if (pTransmitKey == NULL) {
2394 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2395 }
2396 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002397 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002398 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2399 }
2400 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002401 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2402 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002403 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002404 }
2405 }
2406 }
2407
Forest Bond92b96792009-06-13 07:38:31 -04002408 if (pDevice->bEnableHostWEP) {
2409 if ((uNodeIndex != 0) &&
2410 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2412 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002413 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002414 }
2415 }
2416 }
2417 else {
2418
Forest Bond92b96792009-06-13 07:38:31 -04002419 if (pTransmitKey == NULL) {
2420 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002421 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002422 dev_kfree_skb_irq(skb);
2423 pStats->tx_dropped++;
2424 return STATUS_FAILURE;
2425 }
Forest Bond92b96792009-06-13 07:38:31 -04002426 }
2427 }
2428
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002429 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2430
Forest Bond92b96792009-06-13 07:38:31 -04002431 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002432 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002433 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002434 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002435 pDevice->wCurrentRate,
2436 &uHeaderLen, &BytesToWrite
2437 );
2438
Andres Moree269fc22013-02-12 20:36:29 -05002439 if (fConvertedPacket == false) {
2440 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002441 dev_kfree_skb_irq(skb);
2442 return STATUS_FAILURE;
2443 }
2444
Andres More4e9b5e22013-02-12 20:36:30 -05002445 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002446 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002447 bScheduleCommand((void *) pDevice,
2448 WLAN_CMD_MAC_DISPOWERSAVING,
2449 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002450 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002451 }
2452 }
2453
Andres Moreb902fbf2013-02-25 20:32:51 -05002454 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002455 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002456
2457 pContext->pPacket = skb;
2458 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002459 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002460
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002461 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2462 &pContext->sEthHeader.h_dest[0],
2463 (u16)(BytesToWrite-uHeaderLen),
2464 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002465
2466 status = PIPEnsSendBulkOut(pDevice,pContext);
2467
Andres More4e9b5e22013-02-12 20:36:30 -05002468 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002469 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002470
Andres Moreb902fbf2013-02-25 20:32:51 -05002471 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002472 }
2473
2474 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002475 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002476 dev_kfree_skb_irq(skb);
2477 return STATUS_FAILURE;
2478 }
2479 else
2480 return 0;
2481
2482}
2483
Forest Bond92b96792009-06-13 07:38:31 -04002484/*
2485 * Description:
2486 * Relay packet send (AC1DMA) from rx dpc.
2487 *
2488 * Parameters:
2489 * In:
2490 * pDevice - Pointer to the adapter
2491 * pPacket - Pointer to rx packet
2492 * cbPacketSize - rx ethernet frame size
2493 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002494 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002495 *
Andres More4e9b5e22013-02-12 20:36:30 -05002496 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002497 */
2498
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002499int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2500 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002501{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002502 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002503 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002504 u32 BytesToWrite = 0, uHeaderLen = 0;
2505 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002506 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002507 SKeyItem STempKey;
2508 PSKeyItem pTransmitKey = NULL;
2509 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002510 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002511 u8 byPktTyp;
2512 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002513 u32 status;
2514 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002515
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002516 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002517
2518 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002519 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002520 }
2521
Andres Moreceb8c5d2013-03-18 20:33:49 -05002522 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002523
Andres More4e9b5e22013-02-12 20:36:30 -05002524 if (pDevice->bEncryptionEnable == true) {
2525 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002526 // get group key
2527 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002528 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002529 pTransmitKey = NULL;
2530 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2531 } else {
2532 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2533 }
2534 }
2535
2536 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002537 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002538 pTransmitKey = &STempKey;
2539 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2540 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2541 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2542 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2543 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2544 memcpy(pTransmitKey->abyKey,
2545 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2546 pTransmitKey->uKeyLength
2547 );
2548 }
2549 }
2550
2551 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002552 pContext->bBoolInUse = false;
2553 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002554 }
2555
Andres Moreb902fbf2013-02-25 20:32:51 -05002556 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002557
2558 if (pDevice->bFixRate) {
2559 if (pDevice->byBBType == BB_TYPE_11B) {
2560 if (pDevice->uConnectionRate >= RATE_11M) {
2561 pDevice->wCurrentRate = RATE_11M;
2562 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002563 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002564 }
2565 } else {
2566 if ((pDevice->byBBType == BB_TYPE_11A) &&
2567 (pDevice->uConnectionRate <= RATE_6M)) {
2568 pDevice->wCurrentRate = RATE_6M;
2569 } else {
2570 if (pDevice->uConnectionRate >= RATE_54M)
2571 pDevice->wCurrentRate = RATE_54M;
2572 else
Andres More3eaca0d2013-02-25 20:32:52 -05002573 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002574 }
2575 }
2576 }
2577 else {
2578 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2579 }
2580
Forest Bond92b96792009-06-13 07:38:31 -04002581 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002582 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002583 }
2584
2585 if (pDevice->wCurrentRate <= RATE_11M)
2586 byPktType = PK_TYPE_11B;
2587
Andres Moreabad19d2010-07-12 16:28:32 -03002588 BytesToWrite = uDataLen + ETH_FCS_LEN;
2589
Forest Bond92b96792009-06-13 07:38:31 -04002590 // Convert the packet to an usb frame and copy into our buffer
2591 // and send the irp.
2592
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002593 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2594
Forest Bond92b96792009-06-13 07:38:31 -04002595 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002596 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002597 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2598 pbySkbData, pTransmitKey, uNodeIndex,
2599 pDevice->wCurrentRate,
2600 &uHeaderLen, &BytesToWrite
2601 );
2602
Andres Moree269fc22013-02-12 20:36:29 -05002603 if (fConvertedPacket == false) {
2604 pContext->bBoolInUse = false;
2605 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002606 }
2607
Andres Moreb902fbf2013-02-25 20:32:51 -05002608 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002609 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002610
2611 pContext->pPacket = NULL;
2612 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002613 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002614
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002615 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2616 &pContext->sEthHeader.h_dest[0],
2617 (u16)(BytesToWrite - uHeaderLen),
2618 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002619
2620 status = PIPEnsSendBulkOut(pDevice,pContext);
2621
Andres More4e9b5e22013-02-12 20:36:30 -05002622 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002623}
2624