blob: 370d588a849037c44d0e092ded2f69d8ccb2ba0c [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Andres More3eaca0d2013-02-25 20:32:52 -050067const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Andres More3eaca0d2013-02-25 20:32:52 -050072const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Andres More3eaca0d2013-02-25 20:32:52 -050076const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000099static void *s_vGetFreeContext(struct vnt_private *pDevice);
100
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100101static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100102 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100103 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
104 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
106static u32 s_uFillDataHead(struct vnt_private *pDevice,
107 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100108 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000110static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500111 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000112 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
115 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100116 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static void s_vSWencryption(struct vnt_private *pDevice,
119 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000121static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
122 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100124static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000125 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100127static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100128 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
129 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400130
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100131static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100132 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500133 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100135static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100136 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400137
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100138static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000139 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
140 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400141
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000142static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400143{
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +0100144 struct vnt_usb_send_context *pContext = NULL;
145 struct vnt_usb_send_context *pReturnContext = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000146 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400147
148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
149
150 for (ii = 0; ii < pDevice->cbTD; ii++) {
Malcolm Priestley18e35e082013-09-22 20:15:58 +0100151 if (!pDevice->apTD[ii])
152 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400153 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500154 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500155 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100156 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400157 pReturnContext = pContext;
158 break;
159 }
160 }
161 if ( ii == pDevice->cbTD ) {
162 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
163 }
Andres More8611a292010-05-01 14:25:00 -0300164 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400165}
166
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000167static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
168 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400169{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000170 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400171
Andres More4b50fb42010-06-22 21:57:42 -0300172 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300174 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
176 else
177 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
178
179 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
180 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300181 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
182 pbyDestAddr,
183 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400184}
185
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000186static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
187 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100188 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400189{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000190 u32 *pdwIV = (u32 *)pbyIVHead;
191 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500192 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000193 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400194
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100195 /* Fill TXKEY */
196 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100197 return;
Forest Bond92b96792009-06-13 07:38:31 -0400198
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100199 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
200 *pdwIV = pDevice->dwIVCounter;
201 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400202
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100203 switch (pTransmitKey->byCipherSuite) {
204 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100205 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
206 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
207 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
208 pTransmitKey->uKeyLength);
209 } else {
210 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
211 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
212 pTransmitKey->uKeyLength);
213 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
214 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
215 memcpy(pbyBuf+11, pTransmitKey->abyKey,
216 pTransmitKey->uKeyLength);
217 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100218
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100219 memcpy(pDevice->abyPRNG, pbyBuf, 16);
220 }
221 /* Append IV after Mac Header */
222 *pdwIV &= WEP_IV_MASK;
223 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
224 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100225
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100226 pDevice->dwIVCounter++;
227 if (pDevice->dwIVCounter > WEP_IV_MASK)
228 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100229
230 break;
231 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100232 pTransmitKey->wTSC15_0++;
233 if (pTransmitKey->wTSC15_0 == 0)
234 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100235
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100236 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
237 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
238 pDevice->abyPRNG);
239 memcpy(pbyBuf, pDevice->abyPRNG, 16);
240
241 /* Make IV */
242 memcpy(pdwIV, pDevice->abyPRNG, 3);
243
244 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
245 0xc0) | 0x20);
246 /* Append IV&ExtIV after Mac Header */
247 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
248
249 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
250 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
251
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100252 break;
253 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100254 pTransmitKey->wTSC15_0++;
255 if (pTransmitKey->wTSC15_0 == 0)
256 pTransmitKey->dwTSC47_16++;
257
258 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
259
260 /* Make IV */
261 *pdwIV = 0;
262 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
263 0xc0) | 0x20);
264
265 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
266
267 /* Append IV&ExtIV after Mac Header */
268 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
269
270 if (!mic_hdr)
271 return;
272
273 /* MICHDR0 */
274 mic_hdr->id = 0x59;
275 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
276 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
277
278 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
279 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
280
281 /* MICHDR1 */
282 if (pDevice->bLongHeader)
283 mic_hdr->hlen = cpu_to_be16(28);
284 else
285 mic_hdr->hlen = cpu_to_be16(22);
286
287 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
288 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
289
290 /* MICHDR2 */
291 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
292 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100293 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100294 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100295
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100296 if (pDevice->bLongHeader)
297 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
298 }
Forest Bond92b96792009-06-13 07:38:31 -0400299}
300
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000301static void s_vSWencryption(struct vnt_private *pDevice,
302 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400303{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000304 u32 cbICVlen = 4;
305 u32 dwICV = 0xffffffff;
306 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400307
308 if (pTransmitKey == NULL)
309 return;
310
311 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
312 //=======================================================================
313 // Append ICV after payload
314 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500315 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400316 // finally, we must invert dwCRC to get the correct answer
317 *pdwICV = cpu_to_le32(~dwICV);
318 // RC4 encryption
319 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
320 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
321 //=======================================================================
322 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
323 //=======================================================================
324 //Append ICV after payload
325 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500326 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400327 // finally, we must invert dwCRC to get the correct answer
328 *pdwICV = cpu_to_le32(~dwICV);
329 // RC4 encryption
330 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
331 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
332 //=======================================================================
333 }
334}
335
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100336static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
337{
338 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
339 [rate % MAX_RATE]);
340}
341
Forest Bond92b96792009-06-13 07:38:31 -0400342/*byPktType : PK_TYPE_11A 0
343 PK_TYPE_11B 1
344 PK_TYPE_11GB 2
345 PK_TYPE_11GA 3
346*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000347static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
348 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400349{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000350 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400351
352 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
353 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500354 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400355 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500356 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400357 }
358
359 if (bNeedAck) {
360 return (uDataTime + pDevice->uSIFS + uAckTime);
361 }
362 else {
363 return uDataTime;
364 }
365}
366
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100367static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
368 u32 frame_length, u16 rate, int need_ack)
369{
370 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
371 frame_length, rate, need_ack));
372}
373
Forest Bond92b96792009-06-13 07:38:31 -0400374//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100375static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000376 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400377{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000378 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400379
380 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
381
Forest Bond92b96792009-06-13 07:38:31 -0400382 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
383 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
384 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
385 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
386 }
387 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
388 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
389 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
390 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
391 }
392 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
393 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
394 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
395 }
396 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
397 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
398 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
399 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
400 return uRrvTime;
401 }
402
403 //RTSRrvTime
404 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100405 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400406}
407
408//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100409static u16 s_uGetDataDuration(struct vnt_private *pDevice,
410 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400411{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100412 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400413
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100414 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100415 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100416 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
417 byPktType, 14, pDevice->byTopCCKBasicRate);
418 else
419 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
420 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100421 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100422 }
Forest Bond92b96792009-06-13 07:38:31 -0400423
Forest Bond92b96792009-06-13 07:38:31 -0400424 return 0;
425}
426
Forest Bond92b96792009-06-13 07:38:31 -0400427//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100428static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000429 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
430 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400431{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000432 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400433
Forest Bond92b96792009-06-13 07:38:31 -0400434 switch (byDurType) {
435
436 case RTSDUR_BB: //RTSDuration_bb
437 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
438 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
439 break;
440
441 case RTSDUR_BA: //RTSDuration_ba
442 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
443 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
444 break;
445
446 case RTSDUR_AA: //RTSDuration_aa
447 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
448 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
449 break;
450
451 case CTSDUR_BA: //CTSDuration_ba
452 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
453 break;
454
455 case RTSDUR_BA_F0: //RTSDuration_ba_f0
456 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
457 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
458 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
459 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
460 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
461 }
462 break;
463
464 case RTSDUR_AA_F0: //RTSDuration_aa_f0
465 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
466 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
467 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
468 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
469 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
470 }
471 break;
472
473 case RTSDUR_BA_F1: //RTSDuration_ba_f1
474 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
475 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
476 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
477 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
478 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
479 }
480 break;
481
482 case RTSDUR_AA_F1: //RTSDuration_aa_f1
483 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
484 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
485 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
486 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
487 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
488 }
489 break;
490
491 case CTSDUR_BA_F0: //CTSDuration_ba_f0
492 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
493 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
494 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
495 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
496 }
497 break;
498
499 case CTSDUR_BA_F1: //CTSDuration_ba_f1
500 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
501 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
502 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
503 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
504 }
505 break;
506
507 default:
508 break;
509 }
510
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100511 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400512}
513
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100514static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
515 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
516{
517 /* Get SignalField,ServiceField,Length */
518 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
519 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
520 PK_TYPE_11B, &buf->b);
521
522 /* Get Duration and TimeStamp */
523 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
524 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
525
526 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
527 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
528 priv->byTopCCKBasicRate);
529
530 return buf->wDuration_a;
531}
532
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100533static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
534 u16 rate, struct vnt_tx_datahead_g_fb *buf,
535 u32 frame_len, int need_ack)
536{
537 /* Get SignalField,ServiceField,Length */
538 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
539
540 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
541 PK_TYPE_11B, &buf->b);
542
543 /* Get Duration and TimeStamp */
544 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
545 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
546
547 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
548 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
549
550 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
551 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
552 priv->byTopCCKBasicRate);
553
554 return buf->wDuration_a;
555}
556
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000557static u32 s_uFillDataHead(struct vnt_private *pDevice,
558 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100559 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400560{
561
562 if (pTxDataHead == NULL) {
563 return 0;
564 }
565
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100566 if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100567 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100568 struct vnt_tx_datahead_a_fb *pBuf =
569 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400570 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100571 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
572 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400573 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100574 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100575 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100576 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100577 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100578 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100579 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100580 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
581 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400582 return (pBuf->wDuration);
583 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100584 struct vnt_tx_datahead_ab *pBuf =
585 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400586 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100587 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
588 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400589 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100590 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100591 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100592 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
593 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400594 return (pBuf->wDuration);
595 }
596 }
597 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100598 struct vnt_tx_datahead_ab *pBuf =
599 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400600 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100601 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
602 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400603 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100604 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100605 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100606 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
607 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400608 return (pBuf->wDuration);
609 }
610 return 0;
611}
612
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100613static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
614 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
615 u16 duration)
616{
617 rts->duration = duration;
618 rts->frame_control = TYPE_CTL_RTS;
619
620 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
621 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
622 else
623 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
624
625 if (priv->eOPMode == OP_MODE_AP)
626 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
627 else
628 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
629
630 return 0;
631}
632
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100633static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100634 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
635 u8 pkt_type, u32 frame_len, int need_ack,
636 u16 current_rate, u8 fb_option)
637{
638 u16 rts_frame_len = 20;
639
640 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
641 PK_TYPE_11B, &buf->b);
642 BBvCalculateParameter(priv, rts_frame_len,
643 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
644
645 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
646 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
647 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
648 pkt_type, current_rate, need_ack, fb_option);
649 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
650 pkt_type, current_rate, need_ack, fb_option);
651
652 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
653
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100654 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
655 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100656}
657
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100658static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100659 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
660 u8 pkt_type, u32 frame_len, int need_ack,
661 u16 current_rate, u8 fb_option)
662{
663 u16 rts_frame_len = 20;
664
665 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
666 PK_TYPE_11B, &buf->b);
667 BBvCalculateParameter(priv, rts_frame_len,
668 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
669
670
671 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
672 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
673 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
674 pkt_type, current_rate, need_ack, fb_option);
675 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
676 pkt_type, current_rate, need_ack, fb_option);
677
678
679 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
680 frame_len, pkt_type, current_rate, need_ack, fb_option);
681 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
682 frame_len, pkt_type, current_rate, need_ack, fb_option);
683 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
684 frame_len, pkt_type, current_rate, need_ack, fb_option);
685 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
686 frame_len, pkt_type, current_rate, need_ack, fb_option);
687
688 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
689
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100690 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
691 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100692}
693
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100694static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100695 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
696 u8 pkt_type, u32 frame_len, int need_ack,
697 u16 current_rate, u8 fb_option)
698{
699 u16 rts_frame_len = 20;
700
701 BBvCalculateParameter(priv, rts_frame_len,
702 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
703
704 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
705 pkt_type, current_rate, need_ack, fb_option);
706
707 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
708
709 return 0;
710}
711
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100712static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100713 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
714 u8 pkt_type, u32 frame_len, int need_ack,
715 u16 current_rate, u8 fb_option)
716{
717 u16 rts_frame_len = 20;
718
719 BBvCalculateParameter(priv, rts_frame_len,
720 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
721
722 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
723 pkt_type, current_rate, need_ack, fb_option);
724
725 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
726 frame_len, pkt_type, current_rate, need_ack, fb_option);
727
728 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
729 frame_len, pkt_type, current_rate, need_ack, fb_option);
730
731 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
732
733 return 0;
734}
735
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100736static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100737 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500738 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400739{
Forest Bond92b96792009-06-13 07:38:31 -0400740
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100741 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100742 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400743
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100744 /* Note: So far RTSHead doesn't appear in ATIM
745 * & Beacom DMA, so we don't need to take them
746 * into account.
747 * Otherwise, we need to modified codes for them.
748 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100749 switch (byPktType) {
750 case PK_TYPE_11GB:
751 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100752 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100753 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100754 psEthHeader, byPktType, cbFrameLength,
755 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100756 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100757 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100758 psEthHeader, byPktType, cbFrameLength,
759 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100760 break;
761 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100762 if (byFBOption) {
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100763 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
764 psEthHeader, byPktType, cbFrameLength,
765 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100766 break;
767 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100768 case PK_TYPE_11B:
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100769 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100770 psEthHeader, byPktType, cbFrameLength,
771 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100772 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100773
774 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400775}
776
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100777static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100778 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
779 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400780{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000781 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400782
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100783 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100784 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400785
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100786 if (byFBOption != AUTO_FB_NONE) {
787 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100788 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100789 /* Get SignalField,ServiceField,Length */
790 BBvCalculateParameter(pDevice, uCTSFrameLen,
791 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100792 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
793 cbFrameLength, byPktType,
794 wCurrentRate, bNeedAck, byFBOption);
795 /* Get CTSDuration_ba_f0 */
796 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
797 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
798 bNeedAck, byFBOption);
799 /* Get CTSDuration_ba_f1 */
800 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
801 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
802 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100803 /* Get CTS Frame body */
804 pBuf->data.duration = pBuf->wDuration_ba;
805 pBuf->data.frame_control = TYPE_CTL_CTS;
806 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100807
808 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
809 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100810 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100811 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100812 /* Get SignalField,ServiceField,Length */
813 BBvCalculateParameter(pDevice, uCTSFrameLen,
814 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100815 /* Get CTSDuration_ba */
816 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
817 CTSDUR_BA, cbFrameLength, byPktType,
818 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100819 /*Get CTS Frame body*/
820 pBuf->data.duration = pBuf->wDuration_ba;
821 pBuf->data.frame_control = TYPE_CTL_CTS;
822 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100823
824 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
825 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400826 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100827
828 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400829}
830
Forest Bond92b96792009-06-13 07:38:31 -0400831/*+
832 *
833 * Description:
834 * Generate FIFO control for MAC & Baseband controller
835 *
836 * Parameters:
837 * In:
838 * pDevice - Pointer to adpater
839 * pTxDataHead - Transmit Data Buffer
840 * pTxBufHead - pTxBufHead
841 * pvRrvTime - pvRrvTime
842 * pvRTS - RTS Buffer
843 * pCTS - CTS Buffer
844 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
845 * bNeedACK - If need ACK
846 * uDMAIdx - DMA Index
847 * Out:
848 * none
849 *
850 * Return Value: none
851 *
852-*/
Andres Morecc856e62010-05-17 21:34:01 -0300853
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100854static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100855 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100856 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
857 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400858{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100859 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100860 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000861 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
862 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000863 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400864
865 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
Forest Bond92b96792009-06-13 07:38:31 -0400866 pFifoHead->wReserved = wCurrentRate;
867 wFifoCtl = pFifoHead->wFIFOCtl;
868
Forest Bond92b96792009-06-13 07:38:31 -0400869 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
870 byFBOption = AUTO_FB_0;
871 }
872 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
873 byFBOption = AUTO_FB_1;
874 }
875
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100876 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100877 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100878
Forest Bond92b96792009-06-13 07:38:31 -0400879 if (pDevice->bLongHeader)
880 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
881
882 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100883 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400884 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100885 struct vnt_rrv_time_rts *pBuf = &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100886
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100887 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
888 byPktType, cbFrameSize, wCurrentRate);
889 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
890 byPktType, cbFrameSize, wCurrentRate);
891 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
892 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100893 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
894 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
895 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
896 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
897 bNeedACK);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100898
899 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100900 *mic_hdr = &tx_buffer->tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100901 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
902 } else {
903 head = &tx_buffer->tx_head.tx_rts.tx.head;
904 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100905
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100906 /* Fill RTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100907 return s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100908 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400909 }
910 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400911 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100912 struct vnt_rrv_time_cts *pBuf = &tx_buffer->tx_head.tx_cts.cts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100913
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100914 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
915 cbFrameSize, wCurrentRate, bNeedACK);
916 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
917 PK_TYPE_11B, cbFrameSize,
918 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100919 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
920 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100921
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100922 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100923 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100924 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
925 } else {
926 head = &tx_buffer->tx_head.tx_cts.tx.head;
927 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100928
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100929 /* Fill CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100930 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType, head,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100931 cbFrameSize, bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400932 }
933 }
934 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100935 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400936 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100937 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100938
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100939 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
940 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100941 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
942 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100943
944 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100945 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100946 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
947 } else {
948 head = &tx_buffer->tx_head.tx_ab.tx.head;
949 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100950
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100951 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100952 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100953 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100954 } else {
Forest Bond92b96792009-06-13 07:38:31 -0400955 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100956 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100957
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100958 if (need_mic)
959 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
960
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100961 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
962 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400963 }
964 }
965 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100966 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400967 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100968 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100969
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100970 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
971 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100972 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
973 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100974
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100975 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100976 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100977 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
978 } else {
979 head = &tx_buffer->tx_head.tx_ab.tx.head;
980 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100981
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100982 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100983 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100984 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400985 }
986 else { //RTS_needless, non PCF mode
987 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100988 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100989
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100990 if (need_mic)
991 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
992
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100993 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
994 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400995 }
996 }
997 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100998
999 return 0;
Forest Bond92b96792009-06-13 07:38:31 -04001000}
1001/*
Andres Moreb902fbf2013-02-25 20:32:51 -05001002 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -05001003 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -03001004 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -04001005*/
1006
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001007static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001008 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01001009 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
1010 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
1011 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -04001012{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001013 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001014 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1015 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001016 u32 cb802_1_H_len;
1017 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1018 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001019 int bNeedACK;
1020 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001021 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1022 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1023 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1024 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1025 u32 uDuration;
1026 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001027 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001028 void *pvTxDataHd;
1029 u8 byFBOption = AUTO_FB_NONE, byFragType;
1030 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +01001031 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001032 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001033 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001034
1035 pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001036
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001037 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001038 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1039 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001040 }
Forest Bond92b96792009-06-13 07:38:31 -04001041
Forest Bond92b96792009-06-13 07:38:31 -04001042 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001043 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001044 if (pDevice->dwDiagRefCount == 0) {
1045 cb802_1_H_len = 8;
1046 } else {
1047 cb802_1_H_len = 2;
1048 }
1049 } else {
1050 cb802_1_H_len = 0;
1051 }
1052
Charles Clément21ec51f2010-05-18 10:08:14 -07001053 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001054
1055 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001056 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001057
1058 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001059 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001060 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1061 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001062 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1063 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001064 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001065 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001066 pTxBufHead->wFIFOCtl =
1067 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1068 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001069 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001070 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1071 }
Forest Bond92b96792009-06-13 07:38:31 -04001072 }
1073 else {
1074 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001075 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001076 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1077 }
1078 } //if (pDevice->dwDiagRefCount != 0) {
1079
1080 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1081
1082 //Set FIFOCTL_LHEAD
1083 if (pDevice->bLongHeader)
1084 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1085
Forest Bond92b96792009-06-13 07:38:31 -04001086 //Set FRAGCTL_MACHDCNT
1087 if (pDevice->bLongHeader) {
1088 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1089 } else {
1090 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1091 }
Andres More3eaca0d2013-02-25 20:32:52 -05001092 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001093
1094 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001095 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001096 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1097 }
1098
1099 //Set Auto Fallback Ctl
1100 if (wCurrentRate >= RATE_18M) {
1101 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1102 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1103 byFBOption = AUTO_FB_0;
1104 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1105 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1106 byFBOption = AUTO_FB_1;
1107 }
1108 }
1109
Andres More4e9b5e22013-02-12 20:36:30 -05001110 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001111 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1112 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1113 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1114 }
1115 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1116 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1117 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1118 }
1119 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1120 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1121 }
1122 }
1123 }
1124
Forest Bond92b96792009-06-13 07:38:31 -04001125 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1126 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1127 cbIVlen = 4;
1128 cbICVlen = 4;
1129 }
1130 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1131 cbIVlen = 8;//IV+ExtIV
1132 cbMIClen = 8;
1133 cbICVlen = 4;
1134 }
1135 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1136 cbIVlen = 8;//RSN Header
1137 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001138 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001139 }
Andres Moree269fc22013-02-12 20:36:29 -05001140 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001141 //MAC Header should be padding 0 to DW alignment.
1142 uPadding = 4 - (cbMACHdLen%4);
1143 uPadding %= 4;
1144 }
1145 }
1146
1147 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1148
Andres Moree269fc22013-02-12 20:36:29 -05001149 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1150 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001151 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001152 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001153 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1154 }
1155
Andres Moreb902fbf2013-02-25 20:32:51 -05001156 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001157 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1158
Forest Bond92b96792009-06-13 07:38:31 -04001159 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1160 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001161 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001162 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001163 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001164 }
1165 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001166 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001167 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001168 }
1169 } else {
1170 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001171 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001172 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001173 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001174 }
Andres Moree269fc22013-02-12 20:36:29 -05001175 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001176 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001177 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001178 }
1179 } // Auto Fall Back
1180 }
1181 else {//802.11a/b packet
1182 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001183 if (bRTS == true) {//RTS_need
Malcolm Priestley558becf2013-08-16 23:50:32 +01001184 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1185 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001186 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001187 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1188 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001189 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001190 }
Andres Moree269fc22013-02-12 20:36:29 -05001191 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley558becf2013-08-16 23:50:32 +01001192 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1193 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001194 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001195 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001196 }
1197 } else {
1198 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001199 if (bRTS == true) {//RTS_need
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001200 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1201 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001202 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001203 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1204 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001205 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001206 }
Andres Moree269fc22013-02-12 20:36:29 -05001207 else if (bRTS == false) { //RTS_needless
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001208 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1209 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001210 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001211 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001212 }
1213 } // Auto Fall Back
1214 }
1215
Andres Moreb902fbf2013-02-25 20:32:51 -05001216 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1217 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1218 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001219
Forest Bond92b96792009-06-13 07:38:31 -04001220 //=========================
1221 // No Fragmentation
1222 //=========================
1223 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1224 byFragType = FRAGCTL_NONFRAG;
1225 //uDMAIdx = TYPE_AC0DMA;
1226 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1227
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001228 /* Fill FIFO, RrvTime, RTS and CTS */
1229 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1230 tx_buffer, &pMICHDR, cbMICHDR,
1231 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Forest Bond92b96792009-06-13 07:38:31 -04001232 //Fill DataHead
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001233 uDuration |= s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd,
1234 cbFrameSize, uDMAIdx, bNeedACK, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001235 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001236 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001237 byFragType, uDMAIdx, 0);
1238
Andres More4e9b5e22013-02-12 20:36:30 -05001239 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001240 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001241 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001242 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001243
1244 if (pDevice->bEnableHostWEP) {
1245 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1246 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1247 }
1248 }
1249
1250 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001251 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001252 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001253 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1254 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001255 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001256 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001257 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001258 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001259 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001260 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001261 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001262 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001263 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001264
1265 }
1266
1267 }
1268
Forest Bond92b96792009-06-13 07:38:31 -04001269 if (pPacket != NULL) {
1270 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001271 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001272 (pPacket + ETH_HLEN),
1273 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001274 );
1275
1276 } else {
1277 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001278 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001279 }
1280
Andres More4e9b5e22013-02-12 20:36:30 -05001281 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001282
1283 ///////////////////////////////////////////////////////////////////
1284
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001285 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1286 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1287 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1288 }
Forest Bond92b96792009-06-13 07:38:31 -04001289 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001290 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1291 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001292 }
1293 else {
Andres More52a7e642013-02-25 20:32:53 -05001294 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1295 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001296 }
1297 // DO Software Michael
1298 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001299 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001300 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001301 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1303 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001304
1305 ///////////////////////////////////////////////////////////////////
1306
1307 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1308 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001309 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001310 //}
1311 //DBG_PRN_GRP12(("\n\n\n"));
1312
1313 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1314
Andres More52a7e642013-02-25 20:32:53 -05001315 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1316 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001317
1318 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1319 MIC_vUnInit();
1320
Andres More4e9b5e22013-02-12 20:36:30 -05001321 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001322 *pdwMIC_L = 0;
1323 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001324 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001325 }
1326 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1327 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1328 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1329 }
1330
Andres More4e9b5e22013-02-12 20:36:30 -05001331 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001332
Andres More3eaca0d2013-02-25 20:32:52 -05001333 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001334
Andres More4e9b5e22013-02-12 20:36:30 -05001335 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1336 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1337 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001338 cbFrameSize -= cbICVlen;
1339 }
1340
Forest Bond92b96792009-06-13 07:38:31 -04001341 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001342
1343 *pcbHeaderLen = cbHeaderLength;
1344 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1345
Forest Bond92b96792009-06-13 07:38:31 -04001346 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001347 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001348
Andres More4e9b5e22013-02-12 20:36:30 -05001349 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001350
1351}
1352
Forest Bond92b96792009-06-13 07:38:31 -04001353/*+
1354 *
1355 * Description:
1356 * Translate 802.3 to 802.11 header
1357 *
1358 * Parameters:
1359 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001360 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001361 * dwTxBufferAddr - Transmit Buffer
1362 * pPacket - Packet from upper layer
1363 * cbPacketSize - Transmit Data Length
1364 * Out:
1365 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1366 * pcbAppendPayload - size of append payload for 802.1H translation
1367 *
1368 * Return Value: none
1369 *
1370-*/
1371
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001372static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001373 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001374 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001375{
Andres More1cac4a42013-03-18 20:33:50 -05001376 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001377
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001378 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001379
1380 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001381 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001382 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001383 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001384 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1385 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001386 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001387 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001388 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001389 } else {
1390 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001391 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001392 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001393 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001394 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001395 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001396 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001397 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001398 &(pDevice->abyBSSID[0]),
1399 ETH_ALEN);
1400 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001401 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001402 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001403 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001404 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001405 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001406 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001407 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001408 &(pDevice->abyBSSID[0]),
1409 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001410 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001411 }
1412 }
1413
1414 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001415 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001416
Andres More1cac4a42013-03-18 20:33:50 -05001417 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001418
1419 if (pDevice->bLongHeader) {
1420 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001421 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001422 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001423 }
Andres More1cac4a42013-03-18 20:33:50 -05001424 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001425
1426 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001427 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001428
1429 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1430 pDevice->wSeqCounter++;
1431 if (pDevice->wSeqCounter > 0x0fff)
1432 pDevice->wSeqCounter = 0;
1433 }
1434
1435 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001436 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001437 }
1438}
1439
Forest Bond92b96792009-06-13 07:38:31 -04001440/*+
1441 *
1442 * Description:
1443 * Request instructs a MAC to transmit a 802.11 management packet through
1444 * the adapter onto the medium.
1445 *
1446 * Parameters:
1447 * In:
1448 * hDeviceContext - Pointer to the adapter
1449 * pPacket - A pointer to a descriptor for the packet to transmit
1450 * Out:
1451 * none
1452 *
Andres Moree269fc22013-02-12 20:36:29 -05001453 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001454 *
1455-*/
1456
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001457CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1458 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001459{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001460 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001461 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001462 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001463 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001464 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001465 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001466 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001467 void *pvTxDataHd;
1468 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001469 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001470 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001471 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1472 u32 uPadding = 0;
1473 u16 wTxBufSize;
1474 u32 cbMacHdLen;
1475 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001476
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001477 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001478
1479 if (NULL == pContext) {
1480 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1481 return CMD_STATUS_RESOURCES;
1482 }
1483
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001484 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001485 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001486 pTxBufHead = &pTX_Buffer->fifo_head;
1487 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1488 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001489
1490 if (pDevice->byBBType == BB_TYPE_11A) {
1491 wCurrentRate = RATE_6M;
1492 byPktType = PK_TYPE_11A;
1493 } else {
1494 wCurrentRate = RATE_1M;
1495 byPktType = PK_TYPE_11B;
1496 }
1497
1498 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1499 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1500 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1501 // to set power here.
1502 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1503 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1504 } else {
1505 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1506 }
1507 pDevice->wCurrentRate = wCurrentRate;
1508
Forest Bond92b96792009-06-13 07:38:31 -04001509 //Set packet type
1510 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1511 pTxBufHead->wFIFOCtl = 0;
1512 }
1513 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1514 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1515 }
1516 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1517 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1518 }
1519 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1520 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1521 }
1522
1523 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1524 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1525
Andres More22040bb2010-08-02 20:21:44 -03001526 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001527 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001528 }
1529 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001530 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001531 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1532 };
1533
1534 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1535 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1536
1537 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1538 //Set Preamble type always long
1539 //pDevice->byPreambleType = PREAMBLE_LONG;
1540 // probe-response don't retry
1541 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001542 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001543 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1544 //}
1545 }
1546
1547 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1548
1549 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001550 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001551 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1552 } else {
1553 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1554 }
1555
1556 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001557 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001558
1559 // Notes:
1560 // Although spec says MMPDU can be fragmented; In most case,
1561 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001562 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001563
1564 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1565 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1566 cbIVlen = 4;
1567 cbICVlen = 4;
1568 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1569 }
1570 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1571 cbIVlen = 8;//IV+ExtIV
1572 cbMIClen = 8;
1573 cbICVlen = 4;
1574 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1575 //We need to get seed here for filling TxKey entry.
1576 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1577 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1578 }
1579 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1580 cbIVlen = 8;//RSN Header
1581 cbICVlen = 8;//MIC
1582 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001583 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001584 }
1585 //MAC Header should be padding 0 to DW alignment.
1586 uPadding = 4 - (cbMacHdLen%4);
1587 uPadding %= 4;
1588 }
1589
1590 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1591
1592 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001593 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001594 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1595 }
1596 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1597
1598 //Set RrvTime/RTS/CTS Buffer
1599 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001600 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001601 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001602 }
1603 else { // 802.11a/b packet
Malcolm Priestley558becf2013-08-16 23:50:32 +01001604 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1605 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001606 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001607 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001608 }
1609
Andres Moreceb8c5d2013-03-18 20:33:49 -05001610 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001611 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1612 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001613 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001614 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1615 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001616 //=========================
1617 // No Fragmentation
1618 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001619 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001620
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001621 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001622 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001623 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001624 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001625
1626 //Fill DataHead
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001627 uDuration |= s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd,
1628 cbFrameSize, TYPE_TXDMA0, bNeedACK, AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001629
Andres More1cac4a42013-03-18 20:33:50 -05001630 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001631
1632 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1633
1634 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001635 u8 * pbyIVHead;
1636 u8 * pbyPayloadHead;
1637 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001638 PSKeyItem pTransmitKey = NULL;
1639
Andres Moreb902fbf2013-02-25 20:32:51 -05001640 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1641 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001642 do {
1643 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001644 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001645 pbyBSSID = pDevice->abyBSSID;
1646 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001647 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001648 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001649 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001650 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1651 break;
1652 }
1653 } else {
1654 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1655 break;
1656 }
1657 }
1658 // get group key
1659 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001660 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001661 pTransmitKey = NULL;
1662 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1663 } else {
1664 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1665 }
Andres Moree269fc22013-02-12 20:36:29 -05001666 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001667 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001668 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001669 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001670
Jim Lieb3e362592009-08-12 14:54:11 -07001671 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001672 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001673 cbFrameBodySize);
1674 }
1675 else {
1676 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001677 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001678 }
1679
Andres More1cac4a42013-03-18 20:33:50 -05001680 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001681 pDevice->wSeqCounter++ ;
1682 if (pDevice->wSeqCounter > 0x0fff)
1683 pDevice->wSeqCounter = 0;
1684
1685 if (bIsPSPOLL) {
1686 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001687 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001688 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1689 // in the same place of other packet's Duration-field).
1690 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001691 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001692 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1693 tx_cts.tx.head.cts_g.data_head;
1694 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001695 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001696 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001697 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1698 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001699 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1700 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1701 }
Forest Bond92b96792009-06-13 07:38:31 -04001702 }
1703
Andres More3eaca0d2013-02-25 20:32:52 -05001704 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001705 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001706 pTX_Buffer->byType = 0x00;
1707
1708 pContext->pPacket = NULL;
1709 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001710 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001711
Andres More1cac4a42013-03-18 20:33:50 -05001712 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001713 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1714 &pMACHeader->addr1[0], (u16)cbFrameSize,
1715 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001716 }
1717 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001718 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1719 &pMACHeader->addr3[0], (u16)cbFrameSize,
1720 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001721 }
1722
1723 PIPEnsSendBulkOut(pDevice,pContext);
1724 return CMD_STATUS_PENDING;
1725}
1726
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001727CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1728 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001729{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001730 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001731 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1732 u32 cbHeaderSize = 0;
1733 u16 wTxBufSize = sizeof(STxShortBufHead);
1734 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001735 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001736 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001737 u16 wCurrentRate;
1738 u32 cbFrameBodySize;
1739 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001740 u8 *pbyTxBufferAddr;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001741 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001742 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001743
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001744 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001745 if (NULL == pContext) {
1746 status = CMD_STATUS_RESOURCES;
1747 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1748 return status ;
1749 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001750
1751 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001752 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001753
1754 cbFrameBodySize = pPacket->cbPayloadLen;
1755
1756 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1757 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001758
1759 if (pDevice->byBBType == BB_TYPE_11A) {
1760 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001761 pTxDataHead = (struct vnt_tx_datahead_ab *)
1762 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001763 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001764 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1765 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001766 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001767 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001768 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001769 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001770 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001771 } else {
1772 wCurrentRate = RATE_1M;
1773 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001774 pTxDataHead = (struct vnt_tx_datahead_ab *)
1775 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001776 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001777 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1778 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001779 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001780 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001781 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001782 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001783 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001784 }
1785
1786 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001787 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001788 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001789
Andres More1cac4a42013-03-18 20:33:50 -05001790 pMACHeader->duration_id = 0;
1791 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001792 pDevice->wSeqCounter++ ;
1793 if (pDevice->wSeqCounter > 0x0fff)
1794 pDevice->wSeqCounter = 0;
1795
1796 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1797
Andres More3eaca0d2013-02-25 20:32:52 -05001798 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001799 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001800 pTX_Buffer->byType = 0x01;
1801
1802 pContext->pPacket = NULL;
1803 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001804 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001805
1806 PIPEnsSendBulkOut(pDevice,pContext);
1807 return CMD_STATUS_PENDING;
1808
1809}
1810
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001811void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1812{
1813 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001814 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001815 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001816 u8 byPktType;
1817 u8 *pbyTxBufferAddr;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001818 void *pvTxDataHd;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001819 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001820 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001821 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001822 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001823 u32 cbFrameSize;
1824 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1825 u32 uPadding = 0;
1826 u32 cbMICHDR = 0, uLength = 0;
1827 u32 dwMICKey0, dwMICKey1;
1828 u32 dwMIC_Priority;
1829 u32 *pdwMIC_L, *pdwMIC_R;
1830 u16 wTxBufSize;
1831 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001832 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001833 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001834 u32 wCurrentRate = RATE_1M;
1835 PUWLAN_80211HDR p80211Header;
1836 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001837 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001838 SKeyItem STempKey;
1839 PSKeyItem pTransmitKey = NULL;
1840 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1841 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001842 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001843
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001844 pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001845
1846 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1847 cbFrameBodySize = 0;
1848 }
1849 else {
1850 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1851 }
1852 p80211Header = (PUWLAN_80211HDR)skb->data;
1853
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001854 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001855
1856 if (NULL == pContext) {
1857 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1858 dev_kfree_skb_irq(skb);
1859 return ;
1860 }
1861
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001862 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001863 pTxBufHead = &pTX_Buffer->fifo_head;
1864 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1865 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001866
1867 if (pDevice->byBBType == BB_TYPE_11A) {
1868 wCurrentRate = RATE_6M;
1869 byPktType = PK_TYPE_11A;
1870 } else {
1871 wCurrentRate = RATE_1M;
1872 byPktType = PK_TYPE_11B;
1873 }
1874
1875 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1876 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1877 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1878 // to set power here.
1879 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1880 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1881 } else {
1882 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1883 }
1884
1885 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1886
1887 //Set packet type
1888 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1889 pTxBufHead->wFIFOCtl = 0;
1890 }
1891 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1892 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1893 }
1894 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1895 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1896 }
1897 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1898 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1899 }
1900
1901 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1902 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1903
Andres More22040bb2010-08-02 20:21:44 -03001904 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001905 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001906 if (pDevice->bEnableHostWEP) {
1907 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001908 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001909 }
Forest Bond92b96792009-06-13 07:38:31 -04001910 }
1911 else {
1912 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001913 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001914 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001915 }
Andres More4e9b5e22013-02-12 20:36:30 -05001916 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001917 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1918 };
1919
1920 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1921 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1922
1923 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1924 //Set Preamble type always long
1925 //pDevice->byPreambleType = PREAMBLE_LONG;
1926
1927 // probe-response don't retry
1928 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001929 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001930 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1931 //}
1932 }
1933
1934 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1935
1936 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001937 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001938 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1939 } else {
1940 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1941 }
1942
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001943 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001944 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1945
1946 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1947 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1948 }
1949
1950 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1951 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1952 }
1953
1954 if (cbExtSuppRate >0) {
1955 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1956 }
1957 }
1958
Forest Bond92b96792009-06-13 07:38:31 -04001959 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001960 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001961
1962 // Notes:
1963 // Although spec says MMPDU can be fragmented; In most case,
1964 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001965 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001966
Forest Bond92b96792009-06-13 07:38:31 -04001967 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1968 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1969 cbIVlen = 4;
1970 cbICVlen = 4;
1971 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1972 }
1973 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1974 cbIVlen = 8;//IV+ExtIV
1975 cbMIClen = 8;
1976 cbICVlen = 4;
1977 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1978 //We need to get seed here for filling TxKey entry.
1979 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1980 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1981 }
1982 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1983 cbIVlen = 8;//RSN Header
1984 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001985 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001986 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001987 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001988 }
1989 //MAC Header should be padding 0 to DW alignment.
1990 uPadding = 4 - (cbMacHdLen%4);
1991 uPadding %= 4;
1992 }
1993
1994 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1995
1996 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001997 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001998 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1999 }
2000 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2001
Forest Bond92b96792009-06-13 07:38:31 -04002002 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002003 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002004 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04002005
2006 }
2007 else {//802.11a/b packet
Malcolm Priestley558becf2013-08-16 23:50:32 +01002008 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2009 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002010 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002011 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002012 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002013 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002014 &(p80211Header->sA3.abyAddr1[0]),
2015 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002016 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002017 &(p80211Header->sA3.abyAddr2[0]),
2018 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002019 //=========================
2020 // No Fragmentation
2021 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002022 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002023
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01002024 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002025 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01002026 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01002027 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04002028
2029 //Fill DataHead
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002030 uDuration |= s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd,
2031 cbFrameSize, TYPE_TXDMA0, bNeedACK, AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002032
Andres More1cac4a42013-03-18 20:33:50 -05002033 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002034
2035 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2036
Andres Moreb902fbf2013-02-25 20:32:51 -05002037 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2038 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2039 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002040
2041 // Copy the Packet into a tx Buffer
2042 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2043
2044 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002045 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002046 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2047
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002048 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002049 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2050 if (cbExtSuppRate != 0) {
2051 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2052 memcpy((pbyPayloadHead + cbFrameBodySize),
2053 pMgmt->abyCurrSuppRates,
2054 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2055 );
2056 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2057 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2058 pMgmt->abyCurrExtSuppRates,
2059 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2060 );
2061 }
2062 }
2063
2064 // Set wep
2065 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2066
2067 if (pDevice->bEnableHostWEP) {
2068 pTransmitKey = &STempKey;
2069 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2070 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2071 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2072 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2073 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2074 memcpy(pTransmitKey->abyKey,
2075 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2076 pTransmitKey->uKeyLength
2077 );
2078 }
2079
2080 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2081
Andres More52a7e642013-02-25 20:32:53 -05002082 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2083 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002084
2085 // DO Software Michael
2086 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002087 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002088 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002089 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002090 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2091 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002092
2093 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2094
2095 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2096
Andres More52a7e642013-02-25 20:32:53 -05002097 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2098 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002099
2100 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2101 MIC_vUnInit();
2102
Andres More4e9b5e22013-02-12 20:36:30 -05002103 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002104 *pdwMIC_L = 0;
2105 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002106 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002107 }
2108
2109 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2110 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002111 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2112 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002113
2114 }
2115
Andres Moreb902fbf2013-02-25 20:32:51 -05002116 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002117 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002118
2119 if (pDevice->bEnableHostWEP) {
2120 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2121 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2122 }
2123
2124 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002125 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002126 }
2127 }
2128
Andres More1cac4a42013-03-18 20:33:50 -05002129 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002130 pDevice->wSeqCounter++ ;
2131 if (pDevice->wSeqCounter > 0x0fff)
2132 pDevice->wSeqCounter = 0;
2133
Forest Bond92b96792009-06-13 07:38:31 -04002134 if (bIsPSPOLL) {
2135 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2136 // of FIFO control header.
2137 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2138 // in the same place of other packet's Duration-field).
2139 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002140 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002141 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2142 tx_cts.tx.head.cts_g.data_head;
2143 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002144 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002145 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002146 cpu_to_le16(p80211Header->sA2.wDurationID);
2147 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002148 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2149 cpu_to_le16(p80211Header->sA2.wDurationID);
2150 }
Forest Bond92b96792009-06-13 07:38:31 -04002151 }
2152
Andres More3eaca0d2013-02-25 20:32:52 -05002153 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002154 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002155 pTX_Buffer->byType = 0x00;
2156
2157 pContext->pPacket = skb;
2158 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002159 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002160
Andres More1cac4a42013-03-18 20:33:50 -05002161 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002162 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2163 &pMACHeader->addr1[0], (u16)cbFrameSize,
2164 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002165 }
2166 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002167 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2168 &pMACHeader->addr3[0], (u16)cbFrameSize,
2169 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002170 }
2171 PIPEnsSendBulkOut(pDevice,pContext);
2172 return ;
2173
2174}
2175
Forest Bond92b96792009-06-13 07:38:31 -04002176//TYPE_AC0DMA data tx
2177/*
2178 * Description:
2179 * Tx packet via AC0DMA(DMA1)
2180 *
2181 * Parameters:
2182 * In:
2183 * pDevice - Pointer to the adapter
2184 * skb - Pointer to tx skb packet
2185 * Out:
2186 * void
2187 *
2188 * Return Value: NULL
2189 */
2190
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002191int nsDMA_tx_packet(struct vnt_private *pDevice,
2192 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002193{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002194 struct net_device_stats *pStats = &pDevice->stats;
2195 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002196 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002197 u32 BytesToWrite = 0, uHeaderLen = 0;
2198 u32 uNodeIndex = 0;
2199 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2200 u16 wAID;
2201 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002202 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002203 PSKeyItem pTransmitKey = NULL;
2204 SKeyItem STempKey;
2205 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002206 int bTKIP_UseGTK = false;
2207 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002208 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002209 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002210 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002211 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002212 u32 status;
2213 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002214 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002215
Forest Bond92b96792009-06-13 07:38:31 -04002216 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2217
2218 if (pDevice->uAssocCount == 0) {
2219 dev_kfree_skb_irq(skb);
2220 return 0;
2221 }
2222
Andres Moreb902fbf2013-02-25 20:32:51 -05002223 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002224 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002225 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002226 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2227
2228 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2229 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2230 // set tx map
2231 pMgmt->abyPSTxMap[0] |= byMask[0];
2232 return 0;
2233 }
Masanari Iida93184692012-08-13 21:21:50 +09002234 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002235
2236 if (pDevice->byBBType != BB_TYPE_11A)
2237 pDevice->wCurrentRate = RATE_2M;
2238 else
2239 pDevice->wCurrentRate = RATE_24M;
2240 // long preamble type
2241 pDevice->byPreambleType = PREAMBLE_SHORT;
2242
2243 }else {
2244
Andres Moreb902fbf2013-02-25 20:32:51 -05002245 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002246
2247 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2248
2249 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2250
2251 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2252 // set tx map
2253 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2254 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2255 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2256 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2257
2258 return 0;
2259 }
2260 // AP rate decided from node
2261 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2262 // tx preamble decided from node
2263
2264 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2265 pDevice->byPreambleType = pDevice->byShortPreamble;
2266
2267 }else {
2268 pDevice->byPreambleType = PREAMBLE_LONG;
2269 }
Andres More4e9b5e22013-02-12 20:36:30 -05002270 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002271 }
2272 }
2273
Andres Moree269fc22013-02-12 20:36:29 -05002274 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002275 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2276 dev_kfree_skb_irq(skb);
2277 return 0;
2278 }
2279 }
2280
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002281 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002282
2283 if (pContext == NULL) {
2284 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2285 dev_kfree_skb_irq(skb);
2286 return STATUS_RESOURCES;
2287 }
2288
Andres Moreceb8c5d2013-03-18 20:33:49 -05002289 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002290
2291//mike add:station mode check eapol-key challenge--->
2292{
Andres Moreb902fbf2013-02-25 20:32:51 -05002293 u8 Protocol_Version; //802.1x Authentication
2294 u8 Packet_Type; //802.1x Authentication
2295 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002296 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002297
Charles Clément21ec51f2010-05-18 10:08:14 -07002298 Protocol_Version = skb->data[ETH_HLEN];
2299 Packet_Type = skb->data[ETH_HLEN+1];
2300 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2301 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 -05002302 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002303 /* 802.1x OR eapol-key challenge frame transfer */
2304 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2305 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002306 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002307 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2308 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2309 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002310 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002311 PRINT_K("WPA ");
2312 }
2313 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002314 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002315 PRINT_K("WPA2(re-keying) ");
2316 }
2317 PRINT_K("Authentication completed!!\n");
2318 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002319 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002320 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002321 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002322 PRINT_K("WPA2 Authentication completed!!\n");
2323 }
2324 }
2325 }
2326}
2327//mike add:station mode check eapol-key challenge<---
2328
Andres More4e9b5e22013-02-12 20:36:30 -05002329 if (pDevice->bEncryptionEnable == true) {
2330 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002331 // get Transmit key
2332 do {
2333 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2334 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2335 pbyBSSID = pDevice->abyBSSID;
2336 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002337 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002338 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002339 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2340 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002341 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2342 break;
2343 }
2344 } else {
2345 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2346 break;
2347 }
2348 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002349 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2350 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002351 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2352 for (ii = 0; ii< 6; ii++)
2353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2355
2356 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002357 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002358 break;
2359 }
2360 // get group key
2361 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002362 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002363 pTransmitKey = NULL;
2364 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2366 }
2367 else
2368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2369 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002370 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2372 }
Andres Moree269fc22013-02-12 20:36:29 -05002373 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002374 }
2375
2376 if (pDevice->bEnableHostWEP) {
2377 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002378 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002379 pTransmitKey = &STempKey;
2380 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2381 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2382 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2383 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2384 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2385 memcpy(pTransmitKey->abyKey,
2386 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2387 pTransmitKey->uKeyLength
2388 );
2389 }
2390 }
2391
Andres Moreb902fbf2013-02-25 20:32:51 -05002392 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002393
2394 if (pDevice->bFixRate) {
2395 if (pDevice->byBBType == BB_TYPE_11B) {
2396 if (pDevice->uConnectionRate >= RATE_11M) {
2397 pDevice->wCurrentRate = RATE_11M;
2398 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002399 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002400 }
2401 } else {
2402 if ((pDevice->byBBType == BB_TYPE_11A) &&
2403 (pDevice->uConnectionRate <= RATE_6M)) {
2404 pDevice->wCurrentRate = RATE_6M;
2405 } else {
2406 if (pDevice->uConnectionRate >= RATE_54M)
2407 pDevice->wCurrentRate = RATE_54M;
2408 else
Andres More3eaca0d2013-02-25 20:32:52 -05002409 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002410 }
2411 }
2412 }
2413 else {
2414 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2415 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002416 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002417 // Multicast use highest data rate
2418 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2419 // preamble type
2420 pDevice->byPreambleType = pDevice->byShortPreamble;
2421 }
2422 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002423 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002424 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2425 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2426 pDevice->byPreambleType = pDevice->byShortPreamble;
2427
2428 }
2429 else {
2430 pDevice->byPreambleType = PREAMBLE_LONG;
2431 }
2432 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2433 }
2434 else {
2435 if (pDevice->byBBType != BB_TYPE_11A)
2436 pDevice->wCurrentRate = RATE_2M;
2437 else
2438 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2439 // abyCurrExtSuppRates[]
2440 pDevice->byPreambleType = PREAMBLE_SHORT;
2441 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2442 }
2443 }
2444 }
2445 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2446 // Infra STA rate decided from AP Node, index = 0
2447 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2448 }
2449 }
2450
Andres Moreceb8c5d2013-03-18 20:33:49 -05002451 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002452 if (pDevice->byBBType != BB_TYPE_11A) {
2453 pDevice->wCurrentRate = RATE_1M;
2454 pDevice->byACKRate = RATE_1M;
2455 pDevice->byTopCCKBasicRate = RATE_1M;
2456 pDevice->byTopOFDMBasicRate = RATE_6M;
2457 } else {
2458 pDevice->wCurrentRate = RATE_6M;
2459 pDevice->byACKRate = RATE_6M;
2460 pDevice->byTopCCKBasicRate = RATE_1M;
2461 pDevice->byTopOFDMBasicRate = RATE_6M;
2462 }
2463 }
Forest Bond92b96792009-06-13 07:38:31 -04002464
Andres More0cbd8d92010-05-06 20:34:29 -03002465 DBG_PRT(MSG_LEVEL_DEBUG,
2466 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2467 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002468
2469 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002470 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002471 }
2472
2473 if (pDevice->wCurrentRate <= RATE_11M) {
2474 byPktType = PK_TYPE_11B;
2475 }
2476
Andres More4e9b5e22013-02-12 20:36:30 -05002477 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002478 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2479 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002480 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002481 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002482 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2483 if (pTransmitKey == NULL) {
2484 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2485 }
2486 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002487 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002488 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2489 }
2490 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002491 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2492 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002493 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002494 }
2495 }
2496 }
2497
Forest Bond92b96792009-06-13 07:38:31 -04002498 if (pDevice->bEnableHostWEP) {
2499 if ((uNodeIndex != 0) &&
2500 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2502 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002503 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002504 }
2505 }
2506 }
2507 else {
2508
Forest Bond92b96792009-06-13 07:38:31 -04002509 if (pTransmitKey == NULL) {
2510 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002511 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002512 dev_kfree_skb_irq(skb);
2513 pStats->tx_dropped++;
2514 return STATUS_FAILURE;
2515 }
Forest Bond92b96792009-06-13 07:38:31 -04002516 }
2517 }
2518
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002519 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2520
Forest Bond92b96792009-06-13 07:38:31 -04002521 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002522 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002523 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002524 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002525 pDevice->wCurrentRate,
2526 &uHeaderLen, &BytesToWrite
2527 );
2528
Andres Moree269fc22013-02-12 20:36:29 -05002529 if (fConvertedPacket == false) {
2530 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002531 dev_kfree_skb_irq(skb);
2532 return STATUS_FAILURE;
2533 }
2534
Andres More4e9b5e22013-02-12 20:36:30 -05002535 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002536 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002537 bScheduleCommand((void *) pDevice,
2538 WLAN_CMD_MAC_DISPOWERSAVING,
2539 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002540 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002541 }
2542 }
2543
Andres Moreb902fbf2013-02-25 20:32:51 -05002544 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002545 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002546
2547 pContext->pPacket = skb;
2548 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002549 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002550
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002551 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2552 &pContext->sEthHeader.h_dest[0],
2553 (u16)(BytesToWrite-uHeaderLen),
2554 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002555
2556 status = PIPEnsSendBulkOut(pDevice,pContext);
2557
Andres More4e9b5e22013-02-12 20:36:30 -05002558 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002559 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002560
Andres Moreb902fbf2013-02-25 20:32:51 -05002561 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002562 }
2563
2564 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002565 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002566 dev_kfree_skb_irq(skb);
2567 return STATUS_FAILURE;
2568 }
2569 else
2570 return 0;
2571
2572}
2573
Forest Bond92b96792009-06-13 07:38:31 -04002574/*
2575 * Description:
2576 * Relay packet send (AC1DMA) from rx dpc.
2577 *
2578 * Parameters:
2579 * In:
2580 * pDevice - Pointer to the adapter
2581 * pPacket - Pointer to rx packet
2582 * cbPacketSize - rx ethernet frame size
2583 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002584 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002585 *
Andres More4e9b5e22013-02-12 20:36:30 -05002586 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002587 */
2588
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002589int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2590 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002591{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002592 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002593 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002594 u32 BytesToWrite = 0, uHeaderLen = 0;
2595 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002596 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002597 SKeyItem STempKey;
2598 PSKeyItem pTransmitKey = NULL;
2599 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002600 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002601 u8 byPktTyp;
2602 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002603 u32 status;
2604 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002605
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002606 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002607
2608 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002609 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002610 }
2611
Andres Moreceb8c5d2013-03-18 20:33:49 -05002612 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002613
Andres More4e9b5e22013-02-12 20:36:30 -05002614 if (pDevice->bEncryptionEnable == true) {
2615 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002616 // get group key
2617 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002618 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002619 pTransmitKey = NULL;
2620 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2621 } else {
2622 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2623 }
2624 }
2625
2626 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002627 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002628 pTransmitKey = &STempKey;
2629 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2630 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2631 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2632 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2633 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2634 memcpy(pTransmitKey->abyKey,
2635 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2636 pTransmitKey->uKeyLength
2637 );
2638 }
2639 }
2640
2641 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002642 pContext->bBoolInUse = false;
2643 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002644 }
2645
Andres Moreb902fbf2013-02-25 20:32:51 -05002646 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002647
2648 if (pDevice->bFixRate) {
2649 if (pDevice->byBBType == BB_TYPE_11B) {
2650 if (pDevice->uConnectionRate >= RATE_11M) {
2651 pDevice->wCurrentRate = RATE_11M;
2652 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002653 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002654 }
2655 } else {
2656 if ((pDevice->byBBType == BB_TYPE_11A) &&
2657 (pDevice->uConnectionRate <= RATE_6M)) {
2658 pDevice->wCurrentRate = RATE_6M;
2659 } else {
2660 if (pDevice->uConnectionRate >= RATE_54M)
2661 pDevice->wCurrentRate = RATE_54M;
2662 else
Andres More3eaca0d2013-02-25 20:32:52 -05002663 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002664 }
2665 }
2666 }
2667 else {
2668 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2669 }
2670
Forest Bond92b96792009-06-13 07:38:31 -04002671 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002672 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002673 }
2674
2675 if (pDevice->wCurrentRate <= RATE_11M)
2676 byPktType = PK_TYPE_11B;
2677
Andres Moreabad19d2010-07-12 16:28:32 -03002678 BytesToWrite = uDataLen + ETH_FCS_LEN;
2679
Forest Bond92b96792009-06-13 07:38:31 -04002680 // Convert the packet to an usb frame and copy into our buffer
2681 // and send the irp.
2682
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002683 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2684
Forest Bond92b96792009-06-13 07:38:31 -04002685 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002686 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002687 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2688 pbySkbData, pTransmitKey, uNodeIndex,
2689 pDevice->wCurrentRate,
2690 &uHeaderLen, &BytesToWrite
2691 );
2692
Andres Moree269fc22013-02-12 20:36:29 -05002693 if (fConvertedPacket == false) {
2694 pContext->bBoolInUse = false;
2695 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002696 }
2697
Andres Moreb902fbf2013-02-25 20:32:51 -05002698 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002699 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002700
2701 pContext->pPacket = NULL;
2702 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002703 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002704
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002705 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2706 &pContext->sEthHeader.h_dest[0],
2707 (u16)(BytesToWrite - uHeaderLen),
2708 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002709
2710 status = PIPEnsSendBulkOut(pDevice,pContext);
2711
Andres More4e9b5e22013-02-12 20:36:30 -05002712 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002713}
2714