blob: 468a78b797fb81471e496828544ba81f8568cd2a [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
101static void 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 Priestleyf0e0d502013-09-26 18:52:10 +0100103 struct vnt_mic_hdr **mic_hdr, u32 need_mic,
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100104 void *rts_cts, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
105 struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000106
107static u32 s_uFillDataHead(struct vnt_private *pDevice,
108 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100109 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400110
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000111static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500112 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000113 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400114
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000115static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
116 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100117 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400118
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000119static void s_vSWencryption(struct vnt_private *pDevice,
120 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400121
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000122static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
123 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400124
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100125static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000126 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400127
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000128static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100129 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
130 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400131
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000132static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100133 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500134 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400135
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100136static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100137 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400138
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100139static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000140 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
141 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400142
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000143static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400144{
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +0100145 struct vnt_usb_send_context *pContext = NULL;
146 struct vnt_usb_send_context *pReturnContext = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000147 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400148
149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
150
151 for (ii = 0; ii < pDevice->cbTD; ii++) {
152 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500153 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500154 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100155 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400156 pReturnContext = pContext;
157 break;
158 }
159 }
160 if ( ii == pDevice->cbTD ) {
161 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
162 }
Andres More8611a292010-05-01 14:25:00 -0300163 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400164}
165
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000166static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
167 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400168{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000169 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400170
Andres More4b50fb42010-06-22 21:57:42 -0300171 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400172 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300173 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400174 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
175 else
176 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
177
178 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
179 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300180 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
181 pbyDestAddr,
182 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400183}
184
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000185static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
186 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100187 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400188{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000189 u32 *pdwIV = (u32 *)pbyIVHead;
190 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500191 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000192 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400193
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100194 /* Fill TXKEY */
195 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100196 return;
Forest Bond92b96792009-06-13 07:38:31 -0400197
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100198 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
199 *pdwIV = pDevice->dwIVCounter;
200 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400201
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100202 switch (pTransmitKey->byCipherSuite) {
203 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100204 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
205 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
206 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
207 pTransmitKey->uKeyLength);
208 } else {
209 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
210 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
211 pTransmitKey->uKeyLength);
212 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
213 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
214 memcpy(pbyBuf+11, pTransmitKey->abyKey,
215 pTransmitKey->uKeyLength);
216 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100217
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100218 memcpy(pDevice->abyPRNG, pbyBuf, 16);
219 }
220 /* Append IV after Mac Header */
221 *pdwIV &= WEP_IV_MASK;
222 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
223 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100224
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100225 pDevice->dwIVCounter++;
226 if (pDevice->dwIVCounter > WEP_IV_MASK)
227 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100228
229 break;
230 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100231 pTransmitKey->wTSC15_0++;
232 if (pTransmitKey->wTSC15_0 == 0)
233 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100234
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100235 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
236 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
237 pDevice->abyPRNG);
238 memcpy(pbyBuf, pDevice->abyPRNG, 16);
239
240 /* Make IV */
241 memcpy(pdwIV, pDevice->abyPRNG, 3);
242
243 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
244 0xc0) | 0x20);
245 /* Append IV&ExtIV after Mac Header */
246 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
247
248 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
249 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
250
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100251 break;
252 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100253 pTransmitKey->wTSC15_0++;
254 if (pTransmitKey->wTSC15_0 == 0)
255 pTransmitKey->dwTSC47_16++;
256
257 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
258
259 /* Make IV */
260 *pdwIV = 0;
261 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
262 0xc0) | 0x20);
263
264 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
265
266 /* Append IV&ExtIV after Mac Header */
267 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
268
269 if (!mic_hdr)
270 return;
271
272 /* MICHDR0 */
273 mic_hdr->id = 0x59;
274 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
275 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
276
277 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
278 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
279
280 /* MICHDR1 */
281 if (pDevice->bLongHeader)
282 mic_hdr->hlen = cpu_to_be16(28);
283 else
284 mic_hdr->hlen = cpu_to_be16(22);
285
286 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
287 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
288
289 /* MICHDR2 */
290 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
291 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100292 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100293 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100294
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100295 if (pDevice->bLongHeader)
296 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
297 }
Forest Bond92b96792009-06-13 07:38:31 -0400298}
299
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000300static void s_vSWencryption(struct vnt_private *pDevice,
301 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400302{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000303 u32 cbICVlen = 4;
304 u32 dwICV = 0xffffffff;
305 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400306
307 if (pTransmitKey == NULL)
308 return;
309
310 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
311 //=======================================================================
312 // Append ICV after payload
313 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500314 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400315 // finally, we must invert dwCRC to get the correct answer
316 *pdwICV = cpu_to_le32(~dwICV);
317 // RC4 encryption
318 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
319 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
320 //=======================================================================
321 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
322 //=======================================================================
323 //Append ICV after payload
324 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500325 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400326 // finally, we must invert dwCRC to get the correct answer
327 *pdwICV = cpu_to_le32(~dwICV);
328 // RC4 encryption
329 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
330 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
331 //=======================================================================
332 }
333}
334
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100335static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
336{
337 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
338 [rate % MAX_RATE]);
339}
340
Forest Bond92b96792009-06-13 07:38:31 -0400341/*byPktType : PK_TYPE_11A 0
342 PK_TYPE_11B 1
343 PK_TYPE_11GB 2
344 PK_TYPE_11GA 3
345*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000346static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
347 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400348{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000349 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400350
351 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
352 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500353 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400354 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500355 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400356 }
357
358 if (bNeedAck) {
359 return (uDataTime + pDevice->uSIFS + uAckTime);
360 }
361 else {
362 return uDataTime;
363 }
364}
365
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100366static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
367 u32 frame_length, u16 rate, int need_ack)
368{
369 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
370 frame_length, rate, need_ack));
371}
372
Forest Bond92b96792009-06-13 07:38:31 -0400373//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100374static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000375 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400376{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000377 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400378
379 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
380
Forest Bond92b96792009-06-13 07:38:31 -0400381 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
382 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
383 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
384 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
385 }
386 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
387 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
388 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
389 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
390 }
391 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
392 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
393 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
394 }
395 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
396 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
397 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
398 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
399 return uRrvTime;
400 }
401
402 //RTSRrvTime
403 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100404 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400405}
406
407//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100408static u16 s_uGetDataDuration(struct vnt_private *pDevice,
409 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400410{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100411 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400412
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100413 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100414 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100415 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
416 byPktType, 14, pDevice->byTopCCKBasicRate);
417 else
418 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
419 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100420 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100421 }
Forest Bond92b96792009-06-13 07:38:31 -0400422
Forest Bond92b96792009-06-13 07:38:31 -0400423 return 0;
424}
425
Forest Bond92b96792009-06-13 07:38:31 -0400426//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100427static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000428 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
429 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400430{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000431 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400432
Forest Bond92b96792009-06-13 07:38:31 -0400433 switch (byDurType) {
434
435 case RTSDUR_BB: //RTSDuration_bb
436 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
437 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
438 break;
439
440 case RTSDUR_BA: //RTSDuration_ba
441 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
442 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
443 break;
444
445 case RTSDUR_AA: //RTSDuration_aa
446 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
447 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
448 break;
449
450 case CTSDUR_BA: //CTSDuration_ba
451 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
452 break;
453
454 case RTSDUR_BA_F0: //RTSDuration_ba_f0
455 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
456 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
457 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
458 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
459 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
460 }
461 break;
462
463 case RTSDUR_AA_F0: //RTSDuration_aa_f0
464 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
465 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
466 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
467 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
468 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
469 }
470 break;
471
472 case RTSDUR_BA_F1: //RTSDuration_ba_f1
473 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
474 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
475 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
476 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
477 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
478 }
479 break;
480
481 case RTSDUR_AA_F1: //RTSDuration_aa_f1
482 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
483 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
484 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
485 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
486 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
487 }
488 break;
489
490 case CTSDUR_BA_F0: //CTSDuration_ba_f0
491 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
492 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
493 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
494 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
495 }
496 break;
497
498 case CTSDUR_BA_F1: //CTSDuration_ba_f1
499 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
500 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
501 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
502 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
503 }
504 break;
505
506 default:
507 break;
508 }
509
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100510 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400511}
512
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000513static u32 s_uFillDataHead(struct vnt_private *pDevice,
514 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100515 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400516{
517
518 if (pTxDataHead == NULL) {
519 return 0;
520 }
521
522 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Forest Bond92b96792009-06-13 07:38:31 -0400523 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100524 struct vnt_tx_datahead_g *pBuf =
525 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400526 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100527 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
528 byPktType, &pBuf->a);
529 BBvCalculateParameter(pDevice, cbFrameLength,
530 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400531 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100532 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100533 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100534 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100535 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400536
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100537 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
538 wCurrentRate);
539 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
540 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400541 return (pBuf->wDuration_a);
542 } else {
543 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100544 struct vnt_tx_datahead_g_fb *pBuf =
545 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400546 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100547 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
548 byPktType, &pBuf->a);
549 BBvCalculateParameter(pDevice, cbFrameLength,
550 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400551 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100552 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100553 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100554 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100555 PK_TYPE_11B, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100556 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100557 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100558 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100559 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100560 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
561 wCurrentRate);
562 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
563 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400564 return (pBuf->wDuration_a);
565 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400566 }
567 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100568 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100569 struct vnt_tx_datahead_a_fb *pBuf =
570 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400571 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100572 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
573 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400574 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100575 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100576 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100577 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100578 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100579 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100580 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100581 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
582 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400583 return (pBuf->wDuration);
584 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100585 struct vnt_tx_datahead_ab *pBuf =
586 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400587 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100588 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
589 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400590 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100591 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100592 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100593 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
594 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400595 return (pBuf->wDuration);
596 }
597 }
598 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100599 struct vnt_tx_datahead_ab *pBuf =
600 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400601 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100602 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
603 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400604 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100605 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100606 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100607 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
608 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400609 return (pBuf->wDuration);
610 }
611 return 0;
612}
613
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100614static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
615 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
616 u16 duration)
617{
618 rts->duration = duration;
619 rts->frame_control = TYPE_CTL_RTS;
620
621 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
622 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
623 else
624 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
625
626 if (priv->eOPMode == OP_MODE_AP)
627 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
628 else
629 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
630
631 return 0;
632}
633
634static int vnt_rxtx_rts_g_head(struct vnt_private *priv,
635 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
636 u8 pkt_type, u32 frame_len, int need_ack,
637 u16 current_rate, u8 fb_option)
638{
639 u16 rts_frame_len = 20;
640
641 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
642 PK_TYPE_11B, &buf->b);
643 BBvCalculateParameter(priv, rts_frame_len,
644 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
645
646 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
647 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
648 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
649 pkt_type, current_rate, need_ack, fb_option);
650 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
651 pkt_type, current_rate, need_ack, fb_option);
652
653 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
654
655 return 0;
656}
657
Malcolm Priestleyec917132013-08-26 11:07:46 +0100658static int vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
659 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
690 return 0;
691}
692
Malcolm Priestley17126332013-08-26 11:09:38 +0100693static int vnt_rxtx_rts_ab_head(struct vnt_private *priv,
694 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
695 u8 pkt_type, u32 frame_len, int need_ack,
696 u16 current_rate, u8 fb_option)
697{
698 u16 rts_frame_len = 20;
699
700 BBvCalculateParameter(priv, rts_frame_len,
701 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
702
703 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
704 pkt_type, current_rate, need_ack, fb_option);
705
706 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
707
708 return 0;
709}
710
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100711static int vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
712 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
713 u8 pkt_type, u32 frame_len, int need_ack,
714 u16 current_rate, u8 fb_option)
715{
716 u16 rts_frame_len = 20;
717
718 BBvCalculateParameter(priv, rts_frame_len,
719 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
720
721 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
722 pkt_type, current_rate, need_ack, fb_option);
723
724 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
725 frame_len, pkt_type, current_rate, need_ack, fb_option);
726
727 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
728 frame_len, pkt_type, current_rate, need_ack, fb_option);
729
730 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
731
732 return 0;
733}
734
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000735static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100736 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500737 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400738{
Forest Bond92b96792009-06-13 07:38:31 -0400739
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100740 if (!head)
741 return;
Forest Bond92b96792009-06-13 07:38:31 -0400742
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100743 /* Note: So far RTSHead doesn't appear in ATIM
744 * & Beacom DMA, so we don't need to take them
745 * into account.
746 * Otherwise, we need to modified codes for them.
747 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100748 switch (byPktType) {
749 case PK_TYPE_11GB:
750 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100751 if (byFBOption == AUTO_FB_NONE)
752 vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100753 psEthHeader, byPktType, cbFrameLength,
754 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100755 else
756 vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100757 psEthHeader, byPktType, cbFrameLength,
758 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100759 break;
760 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100761 if (byFBOption) {
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100762 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
763 psEthHeader, byPktType, cbFrameLength,
764 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100765 break;
766 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100767 case PK_TYPE_11B:
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100768 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100769 psEthHeader, byPktType, cbFrameLength,
770 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100771 }
Forest Bond92b96792009-06-13 07:38:31 -0400772}
773
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000774static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100775 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
776 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400777{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000778 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400779
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100780 if (!head)
781 return;
Forest Bond92b96792009-06-13 07:38:31 -0400782
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100783 if (byFBOption != AUTO_FB_NONE) {
784 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100785 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100786 /* Get SignalField,ServiceField,Length */
787 BBvCalculateParameter(pDevice, uCTSFrameLen,
788 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100789 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
790 cbFrameLength, byPktType,
791 wCurrentRate, bNeedAck, byFBOption);
792 /* Get CTSDuration_ba_f0 */
793 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
794 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
795 bNeedAck, byFBOption);
796 /* Get CTSDuration_ba_f1 */
797 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
798 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
799 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100800 /* Get CTS Frame body */
801 pBuf->data.duration = pBuf->wDuration_ba;
802 pBuf->data.frame_control = TYPE_CTL_CTS;
803 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100804 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100805 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100806 /* Get SignalField,ServiceField,Length */
807 BBvCalculateParameter(pDevice, uCTSFrameLen,
808 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100809 /* Get CTSDuration_ba */
810 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
811 CTSDUR_BA, cbFrameLength, byPktType,
812 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100813 /*Get CTS Frame body*/
814 pBuf->data.duration = pBuf->wDuration_ba;
815 pBuf->data.frame_control = TYPE_CTL_CTS;
816 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400817 }
Forest Bond92b96792009-06-13 07:38:31 -0400818}
819
Forest Bond92b96792009-06-13 07:38:31 -0400820/*+
821 *
822 * Description:
823 * Generate FIFO control for MAC & Baseband controller
824 *
825 * Parameters:
826 * In:
827 * pDevice - Pointer to adpater
828 * pTxDataHead - Transmit Data Buffer
829 * pTxBufHead - pTxBufHead
830 * pvRrvTime - pvRrvTime
831 * pvRTS - RTS Buffer
832 * pCTS - CTS Buffer
833 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
834 * bNeedACK - If need ACK
835 * uDMAIdx - DMA Index
836 * Out:
837 * none
838 *
839 * Return Value: none
840 *
841-*/
Andres Morecc856e62010-05-17 21:34:01 -0300842
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000843static void s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100844 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100845 struct vnt_mic_hdr **mic_hdr, u32 need_mic,
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100846 void *rts_cts, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
847 struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400848{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100849 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100850 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000851 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
852 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000853 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400854
855 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
Forest Bond92b96792009-06-13 07:38:31 -0400856 pFifoHead->wReserved = wCurrentRate;
857 wFifoCtl = pFifoHead->wFIFOCtl;
858
Forest Bond92b96792009-06-13 07:38:31 -0400859 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
860 byFBOption = AUTO_FB_0;
861 }
862 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
863 byFBOption = AUTO_FB_1;
864 }
865
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100866 if (!pFifoHead)
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100867 return;
868
Forest Bond92b96792009-06-13 07:38:31 -0400869 if (pDevice->bLongHeader)
870 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
871
872 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100873 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400874 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100875 struct vnt_rrv_time_rts *pBuf = &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100876
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100877 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
878 byPktType, cbFrameSize, wCurrentRate);
879 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
880 byPktType, cbFrameSize, wCurrentRate);
881 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
882 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100883 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
884 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
885 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
886 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
887 bNeedACK);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100888
889 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100890 *mic_hdr = &tx_buffer->tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100891 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
892 } else {
893 head = &tx_buffer->tx_head.tx_rts.tx.head;
894 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100895
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100896 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100897 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100898 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400899 }
900 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400901 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100902 struct vnt_rrv_time_cts *pBuf = &tx_buffer->tx_head.tx_cts.cts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100903
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100904 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
905 cbFrameSize, wCurrentRate, bNeedACK);
906 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
907 PK_TYPE_11B, cbFrameSize,
908 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100909 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
910 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100911
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100912 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100913 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100914 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
915 } else {
916 head = &tx_buffer->tx_head.tx_cts.tx.head;
917 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100918
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100919 /* Fill CTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100920 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, head,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100921 cbFrameSize, bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400922 }
923 }
924 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100925 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400926 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100927 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100928
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100929 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
930 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100931 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
932 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100933
934 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100935 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100936 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
937 } else {
938 head = &tx_buffer->tx_head.tx_ab.tx.head;
939 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100940
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100941 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100942 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100943 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100944 } else {
Forest Bond92b96792009-06-13 07:38:31 -0400945 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100946 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100947
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100948 if (need_mic)
949 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
950
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100951 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
952 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400953 }
954 }
955 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100956 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400957 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100958 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100959
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100960 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
961 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100962 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
963 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100964
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100965 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100966 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100967 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
968 } else {
969 head = &tx_buffer->tx_head.tx_ab.tx.head;
970 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100971
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100972 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100973 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100974 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400975 }
976 else { //RTS_needless, non PCF mode
977 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100978 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100979
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100980 if (need_mic)
981 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
982
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100983 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
984 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400985 }
986 }
987 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
988}
989/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500990 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500991 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300992 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400993*/
994
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000995static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100996 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100997 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
998 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
999 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -04001000{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001001 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001002 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1003 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001004 u32 cb802_1_H_len;
1005 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1006 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001007 int bNeedACK;
1008 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001009 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1010 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1011 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1012 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1013 u32 uDuration;
1014 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001015 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001016 void *rts_cts = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001017 void *pvTxDataHd;
1018 u8 byFBOption = AUTO_FB_NONE, byFragType;
1019 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +01001020 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001021 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001022 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001023
1024 pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001025
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001026 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001027 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1028 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001029 }
Forest Bond92b96792009-06-13 07:38:31 -04001030
Forest Bond92b96792009-06-13 07:38:31 -04001031 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001032 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001033 if (pDevice->dwDiagRefCount == 0) {
1034 cb802_1_H_len = 8;
1035 } else {
1036 cb802_1_H_len = 2;
1037 }
1038 } else {
1039 cb802_1_H_len = 0;
1040 }
1041
Charles Clément21ec51f2010-05-18 10:08:14 -07001042 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001043
1044 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001045 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001046
1047 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001048 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001049 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1050 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001051 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1052 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001053 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001054 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001055 pTxBufHead->wFIFOCtl =
1056 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1057 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001058 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001059 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1060 }
Forest Bond92b96792009-06-13 07:38:31 -04001061 }
1062 else {
1063 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001064 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001065 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1066 }
1067 } //if (pDevice->dwDiagRefCount != 0) {
1068
1069 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1070
1071 //Set FIFOCTL_LHEAD
1072 if (pDevice->bLongHeader)
1073 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1074
Forest Bond92b96792009-06-13 07:38:31 -04001075 //Set FRAGCTL_MACHDCNT
1076 if (pDevice->bLongHeader) {
1077 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1078 } else {
1079 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1080 }
Andres More3eaca0d2013-02-25 20:32:52 -05001081 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001082
1083 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001084 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001085 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1086 }
1087
1088 //Set Auto Fallback Ctl
1089 if (wCurrentRate >= RATE_18M) {
1090 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1091 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1092 byFBOption = AUTO_FB_0;
1093 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1094 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1095 byFBOption = AUTO_FB_1;
1096 }
1097 }
1098
Andres More4e9b5e22013-02-12 20:36:30 -05001099 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001100 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1101 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1102 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1103 }
1104 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1105 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1106 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1107 }
1108 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1109 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1110 }
1111 }
1112 }
1113
Forest Bond92b96792009-06-13 07:38:31 -04001114 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1115 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1116 cbIVlen = 4;
1117 cbICVlen = 4;
1118 }
1119 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1120 cbIVlen = 8;//IV+ExtIV
1121 cbMIClen = 8;
1122 cbICVlen = 4;
1123 }
1124 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1125 cbIVlen = 8;//RSN Header
1126 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001127 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001128 }
Andres Moree269fc22013-02-12 20:36:29 -05001129 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001130 //MAC Header should be padding 0 to DW alignment.
1131 uPadding = 4 - (cbMACHdLen%4);
1132 uPadding %= 4;
1133 }
1134 }
1135
1136 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1137
Andres Moree269fc22013-02-12 20:36:29 -05001138 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1139 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001140 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001141 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001142 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1143 }
1144
Andres Moreb902fbf2013-02-25 20:32:51 -05001145 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001146 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1147
Forest Bond92b96792009-06-13 07:38:31 -04001148 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1149 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001150 if (bRTS == true) {//RTS_need
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001151 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1152 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1153 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001154 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001155 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001156 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001157 }
1158 else { //RTS_needless
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001159 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1160 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1161 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001162 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1163 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001164 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001165 }
1166 } else {
1167 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001168 if (bRTS == true) {//RTS_need
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001169 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1170 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1171 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001172 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1173 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001174 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001175 }
Andres Moree269fc22013-02-12 20:36:29 -05001176 else if (bRTS == false) { //RTS_needless
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001177 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001178 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1179 cbMICHDR + sizeof(struct vnt_cts_fb));
1180 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001181 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001182 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001183 }
1184 } // Auto Fall Back
1185 }
1186 else {//802.11a/b packet
1187 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001188 if (bRTS == true) {//RTS_need
Malcolm Priestley558becf2013-08-16 23:50:32 +01001189 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1190 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001191 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001192 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1193 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001194 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001195 }
Andres Moree269fc22013-02-12 20:36:29 -05001196 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley558becf2013-08-16 23:50:32 +01001197 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1198 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001199 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001200 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001201 }
1202 } else {
1203 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001204 if (bRTS == true) {//RTS_need
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001205 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1206 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001207 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001208 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1209 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001210 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001211 }
Andres Moree269fc22013-02-12 20:36:29 -05001212 else if (bRTS == false) { //RTS_needless
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001213 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1214 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001215 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001216 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001217 }
1218 } // Auto Fall Back
1219 }
1220
Andres Moreb902fbf2013-02-25 20:32:51 -05001221 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1222 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1223 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001224
Forest Bond92b96792009-06-13 07:38:31 -04001225 //=========================
1226 // No Fragmentation
1227 //=========================
1228 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1229 byFragType = FRAGCTL_NONFRAG;
1230 //uDMAIdx = TYPE_AC0DMA;
1231 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1232
Forest Bond92b96792009-06-13 07:38:31 -04001233 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001234 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001235 tx_buffer, &pMICHDR, cbMICHDR, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001236 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Forest Bond92b96792009-06-13 07:38:31 -04001237 //Fill DataHead
1238 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001239 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001240 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001241 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001242 byFragType, uDMAIdx, 0);
1243
Andres More4e9b5e22013-02-12 20:36:30 -05001244 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001245 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001246 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001247 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001248
1249 if (pDevice->bEnableHostWEP) {
1250 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1251 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1252 }
1253 }
1254
1255 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001256 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001257 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001258 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1259 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001260 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001261 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001262 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001263 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001264 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001265 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001266 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001267 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001268 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001269
1270 }
1271
1272 }
1273
Forest Bond92b96792009-06-13 07:38:31 -04001274 if (pPacket != NULL) {
1275 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001276 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001277 (pPacket + ETH_HLEN),
1278 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001279 );
1280
1281 } else {
1282 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001283 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001284 }
1285
Andres More4e9b5e22013-02-12 20:36:30 -05001286 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001287
1288 ///////////////////////////////////////////////////////////////////
1289
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001290 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1291 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1292 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1293 }
Forest Bond92b96792009-06-13 07:38:31 -04001294 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001295 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1296 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001297 }
1298 else {
Andres More52a7e642013-02-25 20:32:53 -05001299 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1300 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001301 }
1302 // DO Software Michael
1303 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001304 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001305 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001306 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001307 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1308 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001309
1310 ///////////////////////////////////////////////////////////////////
1311
1312 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1313 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001314 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001315 //}
1316 //DBG_PRN_GRP12(("\n\n\n"));
1317
1318 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1319
Andres More52a7e642013-02-25 20:32:53 -05001320 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1321 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001322
1323 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1324 MIC_vUnInit();
1325
Andres More4e9b5e22013-02-12 20:36:30 -05001326 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001327 *pdwMIC_L = 0;
1328 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001329 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001330 }
1331 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1332 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1333 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1334 }
1335
Andres More4e9b5e22013-02-12 20:36:30 -05001336 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001337
Andres More3eaca0d2013-02-25 20:32:52 -05001338 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001339
Andres More4e9b5e22013-02-12 20:36:30 -05001340 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1341 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1342 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001343 cbFrameSize -= cbICVlen;
1344 }
1345
Forest Bond92b96792009-06-13 07:38:31 -04001346 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001347
1348 *pcbHeaderLen = cbHeaderLength;
1349 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1350
Forest Bond92b96792009-06-13 07:38:31 -04001351 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001352 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001353
Andres More4e9b5e22013-02-12 20:36:30 -05001354 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001355
1356}
1357
Forest Bond92b96792009-06-13 07:38:31 -04001358/*+
1359 *
1360 * Description:
1361 * Translate 802.3 to 802.11 header
1362 *
1363 * Parameters:
1364 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001365 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001366 * dwTxBufferAddr - Transmit Buffer
1367 * pPacket - Packet from upper layer
1368 * cbPacketSize - Transmit Data Length
1369 * Out:
1370 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1371 * pcbAppendPayload - size of append payload for 802.1H translation
1372 *
1373 * Return Value: none
1374 *
1375-*/
1376
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001377static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001378 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001379 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001380{
Andres More1cac4a42013-03-18 20:33:50 -05001381 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001382
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001383 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001384
1385 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001386 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001387 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001388 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001389 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1390 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001391 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001392 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001393 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001394 } else {
1395 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001396 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001397 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001398 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001399 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001400 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001401 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001402 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001403 &(pDevice->abyBSSID[0]),
1404 ETH_ALEN);
1405 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001406 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001407 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001408 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001409 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001410 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001411 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001412 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001413 &(pDevice->abyBSSID[0]),
1414 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001415 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001416 }
1417 }
1418
1419 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001420 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001421
Andres More1cac4a42013-03-18 20:33:50 -05001422 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001423
1424 if (pDevice->bLongHeader) {
1425 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001426 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001427 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001428 }
Andres More1cac4a42013-03-18 20:33:50 -05001429 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001430
1431 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001432 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001433
1434 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1435 pDevice->wSeqCounter++;
1436 if (pDevice->wSeqCounter > 0x0fff)
1437 pDevice->wSeqCounter = 0;
1438 }
1439
1440 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001441 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001442 }
1443}
1444
Forest Bond92b96792009-06-13 07:38:31 -04001445/*+
1446 *
1447 * Description:
1448 * Request instructs a MAC to transmit a 802.11 management packet through
1449 * the adapter onto the medium.
1450 *
1451 * Parameters:
1452 * In:
1453 * hDeviceContext - Pointer to the adapter
1454 * pPacket - A pointer to a descriptor for the packet to transmit
1455 * Out:
1456 * none
1457 *
Andres Moree269fc22013-02-12 20:36:29 -05001458 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001459 *
1460-*/
1461
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001462CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1463 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001464{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001465 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001466 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001467 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001468 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001469 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001470 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001471 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001472 void *rts_cts = NULL;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001473 void *pvTxDataHd;
1474 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001475 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001476 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001477 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1478 u32 uPadding = 0;
1479 u16 wTxBufSize;
1480 u32 cbMacHdLen;
1481 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001482
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001483 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001484
1485 if (NULL == pContext) {
1486 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1487 return CMD_STATUS_RESOURCES;
1488 }
1489
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001490 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001491 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001492 pTxBufHead = &pTX_Buffer->fifo_head;
1493 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1494 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001495
1496 if (pDevice->byBBType == BB_TYPE_11A) {
1497 wCurrentRate = RATE_6M;
1498 byPktType = PK_TYPE_11A;
1499 } else {
1500 wCurrentRate = RATE_1M;
1501 byPktType = PK_TYPE_11B;
1502 }
1503
1504 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1505 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1506 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1507 // to set power here.
1508 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1509 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1510 } else {
1511 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1512 }
1513 pDevice->wCurrentRate = wCurrentRate;
1514
Forest Bond92b96792009-06-13 07:38:31 -04001515 //Set packet type
1516 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1517 pTxBufHead->wFIFOCtl = 0;
1518 }
1519 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1520 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1521 }
1522 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1523 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1524 }
1525 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1526 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1527 }
1528
1529 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1530 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1531
Andres More22040bb2010-08-02 20:21:44 -03001532 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001533 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001534 }
1535 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001536 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001537 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1538 };
1539
1540 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1541 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1542
1543 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1544 //Set Preamble type always long
1545 //pDevice->byPreambleType = PREAMBLE_LONG;
1546 // probe-response don't retry
1547 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001548 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001549 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1550 //}
1551 }
1552
1553 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1554
1555 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001556 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001557 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1558 } else {
1559 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1560 }
1561
1562 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001563 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001564
1565 // Notes:
1566 // Although spec says MMPDU can be fragmented; In most case,
1567 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001568 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001569
1570 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1571 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1572 cbIVlen = 4;
1573 cbICVlen = 4;
1574 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1575 }
1576 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1577 cbIVlen = 8;//IV+ExtIV
1578 cbMIClen = 8;
1579 cbICVlen = 4;
1580 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1581 //We need to get seed here for filling TxKey entry.
1582 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1583 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1584 }
1585 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1586 cbIVlen = 8;//RSN Header
1587 cbICVlen = 8;//MIC
1588 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001589 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001590 }
1591 //MAC Header should be padding 0 to DW alignment.
1592 uPadding = 4 - (cbMacHdLen%4);
1593 uPadding %= 4;
1594 }
1595
1596 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1597
1598 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001599 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001600 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1601 }
1602 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1603
1604 //Set RrvTime/RTS/CTS Buffer
1605 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001606 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001607 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1608 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001609 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001610 }
1611 else { // 802.11a/b packet
Malcolm Priestley558becf2013-08-16 23:50:32 +01001612 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1613 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001614 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001615 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001616 }
1617
Andres Moreceb8c5d2013-03-18 20:33:49 -05001618 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001619 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1620 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001621 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001622 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1623 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001624 //=========================
1625 // No Fragmentation
1626 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001627 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001628
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001629 /* Fill FIFO,RrvTime,RTS,and CTS */
1630 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001631 pTX_Buffer, &pMICHDR, 0, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001632 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001633
1634 //Fill DataHead
1635 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001636 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001637
Andres More1cac4a42013-03-18 20:33:50 -05001638 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001639
1640 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1641
1642 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001643 u8 * pbyIVHead;
1644 u8 * pbyPayloadHead;
1645 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001646 PSKeyItem pTransmitKey = NULL;
1647
Andres Moreb902fbf2013-02-25 20:32:51 -05001648 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1649 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001650 do {
1651 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001652 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001653 pbyBSSID = pDevice->abyBSSID;
1654 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001655 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001656 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001657 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001658 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1659 break;
1660 }
1661 } else {
1662 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1663 break;
1664 }
1665 }
1666 // get group key
1667 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001668 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001669 pTransmitKey = NULL;
1670 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1671 } else {
1672 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1673 }
Andres Moree269fc22013-02-12 20:36:29 -05001674 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001675 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001676 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001677 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001678
Jim Lieb3e362592009-08-12 14:54:11 -07001679 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001680 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001681 cbFrameBodySize);
1682 }
1683 else {
1684 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001685 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001686 }
1687
Andres More1cac4a42013-03-18 20:33:50 -05001688 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001689 pDevice->wSeqCounter++ ;
1690 if (pDevice->wSeqCounter > 0x0fff)
1691 pDevice->wSeqCounter = 0;
1692
1693 if (bIsPSPOLL) {
1694 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001695 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001696 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1697 // in the same place of other packet's Duration-field).
1698 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001699 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1700 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1701 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1702 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1703 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1704 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001705 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1706 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1707 }
Forest Bond92b96792009-06-13 07:38:31 -04001708 }
1709
Andres More3eaca0d2013-02-25 20:32:52 -05001710 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001711 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001712 pTX_Buffer->byType = 0x00;
1713
1714 pContext->pPacket = NULL;
1715 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001716 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001717
Andres More1cac4a42013-03-18 20:33:50 -05001718 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001719 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1720 &pMACHeader->addr1[0], (u16)cbFrameSize,
1721 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001722 }
1723 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001724 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1725 &pMACHeader->addr3[0], (u16)cbFrameSize,
1726 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001727 }
1728
1729 PIPEnsSendBulkOut(pDevice,pContext);
1730 return CMD_STATUS_PENDING;
1731}
1732
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001733CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1734 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001735{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001736 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001737 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1738 u32 cbHeaderSize = 0;
1739 u16 wTxBufSize = sizeof(STxShortBufHead);
1740 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001741 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001742 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001743 u16 wCurrentRate;
1744 u32 cbFrameBodySize;
1745 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001746 u8 *pbyTxBufferAddr;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001747 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001748 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001749
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001750 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001751 if (NULL == pContext) {
1752 status = CMD_STATUS_RESOURCES;
1753 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1754 return status ;
1755 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001756
1757 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001758 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001759
1760 cbFrameBodySize = pPacket->cbPayloadLen;
1761
1762 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1763 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001764
1765 if (pDevice->byBBType == BB_TYPE_11A) {
1766 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001767 pTxDataHead = (struct vnt_tx_datahead_ab *)
1768 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001769 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001770 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1771 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001772 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001773 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001774 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001775 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001776 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001777 } else {
1778 wCurrentRate = RATE_1M;
1779 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001780 pTxDataHead = (struct vnt_tx_datahead_ab *)
1781 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001782 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001783 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1784 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001785 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001786 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001787 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001788 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001789 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001790 }
1791
1792 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001793 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001794 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001795
Andres More1cac4a42013-03-18 20:33:50 -05001796 pMACHeader->duration_id = 0;
1797 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001798 pDevice->wSeqCounter++ ;
1799 if (pDevice->wSeqCounter > 0x0fff)
1800 pDevice->wSeqCounter = 0;
1801
1802 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1803
Andres More3eaca0d2013-02-25 20:32:52 -05001804 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001805 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001806 pTX_Buffer->byType = 0x01;
1807
1808 pContext->pPacket = NULL;
1809 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001810 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001811
1812 PIPEnsSendBulkOut(pDevice,pContext);
1813 return CMD_STATUS_PENDING;
1814
1815}
1816
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001817void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1818{
1819 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001820 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001821 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001822 u8 byPktType;
1823 u8 *pbyTxBufferAddr;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001824 void *rts_cts = NULL;
1825 void *pvTxDataHd;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001826 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001827 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001828 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001829 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001830 u32 cbFrameSize;
1831 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1832 u32 uPadding = 0;
1833 u32 cbMICHDR = 0, uLength = 0;
1834 u32 dwMICKey0, dwMICKey1;
1835 u32 dwMIC_Priority;
1836 u32 *pdwMIC_L, *pdwMIC_R;
1837 u16 wTxBufSize;
1838 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001839 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001840 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001841 u32 wCurrentRate = RATE_1M;
1842 PUWLAN_80211HDR p80211Header;
1843 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001844 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001845 SKeyItem STempKey;
1846 PSKeyItem pTransmitKey = NULL;
1847 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1848 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001849 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001850
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001851 pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001852
1853 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1854 cbFrameBodySize = 0;
1855 }
1856 else {
1857 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1858 }
1859 p80211Header = (PUWLAN_80211HDR)skb->data;
1860
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001861 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001862
1863 if (NULL == pContext) {
1864 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1865 dev_kfree_skb_irq(skb);
1866 return ;
1867 }
1868
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001869 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001870 pTxBufHead = &pTX_Buffer->fifo_head;
1871 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1872 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001873
1874 if (pDevice->byBBType == BB_TYPE_11A) {
1875 wCurrentRate = RATE_6M;
1876 byPktType = PK_TYPE_11A;
1877 } else {
1878 wCurrentRate = RATE_1M;
1879 byPktType = PK_TYPE_11B;
1880 }
1881
1882 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1883 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1884 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1885 // to set power here.
1886 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1887 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1888 } else {
1889 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1890 }
1891
1892 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1893
1894 //Set packet type
1895 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1896 pTxBufHead->wFIFOCtl = 0;
1897 }
1898 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1899 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1900 }
1901 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1902 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1903 }
1904 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1905 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1906 }
1907
1908 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1909 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1910
Andres More22040bb2010-08-02 20:21:44 -03001911 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001912 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001913 if (pDevice->bEnableHostWEP) {
1914 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001915 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001916 }
Forest Bond92b96792009-06-13 07:38:31 -04001917 }
1918 else {
1919 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001920 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001921 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001922 }
Andres More4e9b5e22013-02-12 20:36:30 -05001923 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001924 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1925 };
1926
1927 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1928 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1929
1930 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1931 //Set Preamble type always long
1932 //pDevice->byPreambleType = PREAMBLE_LONG;
1933
1934 // probe-response don't retry
1935 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001936 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001937 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1938 //}
1939 }
1940
1941 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1942
1943 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001944 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001945 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1946 } else {
1947 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1948 }
1949
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001950 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001951 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1952
1953 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1954 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1955 }
1956
1957 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1958 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1959 }
1960
1961 if (cbExtSuppRate >0) {
1962 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1963 }
1964 }
1965
Forest Bond92b96792009-06-13 07:38:31 -04001966 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001967 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001968
1969 // Notes:
1970 // Although spec says MMPDU can be fragmented; In most case,
1971 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001972 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001973
Forest Bond92b96792009-06-13 07:38:31 -04001974 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1975 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1976 cbIVlen = 4;
1977 cbICVlen = 4;
1978 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1979 }
1980 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1981 cbIVlen = 8;//IV+ExtIV
1982 cbMIClen = 8;
1983 cbICVlen = 4;
1984 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1985 //We need to get seed here for filling TxKey entry.
1986 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1987 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1988 }
1989 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1990 cbIVlen = 8;//RSN Header
1991 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001992 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001993 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001994 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001995 }
1996 //MAC Header should be padding 0 to DW alignment.
1997 uPadding = 4 - (cbMacHdLen%4);
1998 uPadding %= 4;
1999 }
2000
2001 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2002
2003 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002004 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002005 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2006 }
2007 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2008
Forest Bond92b96792009-06-13 07:38:31 -04002009 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002010 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2011 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002012 sizeof(struct vnt_cts));
2013 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002014 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002015
2016 }
2017 else {//802.11a/b packet
Malcolm Priestley558becf2013-08-16 23:50:32 +01002018 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2019 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002020 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002021 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002022 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002023 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002024 &(p80211Header->sA3.abyAddr1[0]),
2025 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002026 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002027 &(p80211Header->sA3.abyAddr2[0]),
2028 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002029 //=========================
2030 // No Fragmentation
2031 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002032 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002033
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01002034 /* Fill FIFO,RrvTime,RTS,and CTS */
2035 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01002036 pTX_Buffer, &pMICHDR, cbMICHDR, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01002037 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04002038
2039 //Fill DataHead
2040 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002041 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002042
Andres More1cac4a42013-03-18 20:33:50 -05002043 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002044
2045 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2046
Andres Moreb902fbf2013-02-25 20:32:51 -05002047 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2048 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2049 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002050
2051 // Copy the Packet into a tx Buffer
2052 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2053
2054 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002055 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002056 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2057
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002058 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002059 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2060 if (cbExtSuppRate != 0) {
2061 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2062 memcpy((pbyPayloadHead + cbFrameBodySize),
2063 pMgmt->abyCurrSuppRates,
2064 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2065 );
2066 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2067 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2068 pMgmt->abyCurrExtSuppRates,
2069 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2070 );
2071 }
2072 }
2073
2074 // Set wep
2075 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2076
2077 if (pDevice->bEnableHostWEP) {
2078 pTransmitKey = &STempKey;
2079 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2080 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2081 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2082 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2083 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2084 memcpy(pTransmitKey->abyKey,
2085 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2086 pTransmitKey->uKeyLength
2087 );
2088 }
2089
2090 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2091
Andres More52a7e642013-02-25 20:32:53 -05002092 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2093 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002094
2095 // DO Software Michael
2096 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002097 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002098 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002099 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002100 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2101 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002102
2103 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2104
2105 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2106
Andres More52a7e642013-02-25 20:32:53 -05002107 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2108 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002109
2110 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2111 MIC_vUnInit();
2112
Andres More4e9b5e22013-02-12 20:36:30 -05002113 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002114 *pdwMIC_L = 0;
2115 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002116 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002117 }
2118
2119 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2120 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002121 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2122 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002123
2124 }
2125
Andres Moreb902fbf2013-02-25 20:32:51 -05002126 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002127 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002128
2129 if (pDevice->bEnableHostWEP) {
2130 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2131 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2132 }
2133
2134 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002135 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002136 }
2137 }
2138
Andres More1cac4a42013-03-18 20:33:50 -05002139 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002140 pDevice->wSeqCounter++ ;
2141 if (pDevice->wSeqCounter > 0x0fff)
2142 pDevice->wSeqCounter = 0;
2143
Forest Bond92b96792009-06-13 07:38:31 -04002144 if (bIsPSPOLL) {
2145 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2146 // of FIFO control header.
2147 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2148 // in the same place of other packet's Duration-field).
2149 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002150 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2151 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2152 cpu_to_le16(p80211Header->sA2.wDurationID);
2153 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2154 cpu_to_le16(p80211Header->sA2.wDurationID);
2155 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002156 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2157 cpu_to_le16(p80211Header->sA2.wDurationID);
2158 }
Forest Bond92b96792009-06-13 07:38:31 -04002159 }
2160
Andres More3eaca0d2013-02-25 20:32:52 -05002161 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002162 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002163 pTX_Buffer->byType = 0x00;
2164
2165 pContext->pPacket = skb;
2166 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002167 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002168
Andres More1cac4a42013-03-18 20:33:50 -05002169 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002170 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2171 &pMACHeader->addr1[0], (u16)cbFrameSize,
2172 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002173 }
2174 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002175 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2176 &pMACHeader->addr3[0], (u16)cbFrameSize,
2177 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002178 }
2179 PIPEnsSendBulkOut(pDevice,pContext);
2180 return ;
2181
2182}
2183
Forest Bond92b96792009-06-13 07:38:31 -04002184//TYPE_AC0DMA data tx
2185/*
2186 * Description:
2187 * Tx packet via AC0DMA(DMA1)
2188 *
2189 * Parameters:
2190 * In:
2191 * pDevice - Pointer to the adapter
2192 * skb - Pointer to tx skb packet
2193 * Out:
2194 * void
2195 *
2196 * Return Value: NULL
2197 */
2198
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002199int nsDMA_tx_packet(struct vnt_private *pDevice,
2200 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002201{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002202 struct net_device_stats *pStats = &pDevice->stats;
2203 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002204 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002205 u32 BytesToWrite = 0, uHeaderLen = 0;
2206 u32 uNodeIndex = 0;
2207 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2208 u16 wAID;
2209 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002210 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002211 PSKeyItem pTransmitKey = NULL;
2212 SKeyItem STempKey;
2213 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002214 int bTKIP_UseGTK = false;
2215 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002216 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002217 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002218 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002219 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002220 u32 status;
2221 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002222 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002223
Forest Bond92b96792009-06-13 07:38:31 -04002224 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2225
2226 if (pDevice->uAssocCount == 0) {
2227 dev_kfree_skb_irq(skb);
2228 return 0;
2229 }
2230
Andres Moreb902fbf2013-02-25 20:32:51 -05002231 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002232 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002233 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002234 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2235
2236 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2237 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2238 // set tx map
2239 pMgmt->abyPSTxMap[0] |= byMask[0];
2240 return 0;
2241 }
Masanari Iida93184692012-08-13 21:21:50 +09002242 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002243
2244 if (pDevice->byBBType != BB_TYPE_11A)
2245 pDevice->wCurrentRate = RATE_2M;
2246 else
2247 pDevice->wCurrentRate = RATE_24M;
2248 // long preamble type
2249 pDevice->byPreambleType = PREAMBLE_SHORT;
2250
2251 }else {
2252
Andres Moreb902fbf2013-02-25 20:32:51 -05002253 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002254
2255 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2256
2257 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2258
2259 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2260 // set tx map
2261 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2262 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2263 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2264 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2265
2266 return 0;
2267 }
2268 // AP rate decided from node
2269 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2270 // tx preamble decided from node
2271
2272 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2273 pDevice->byPreambleType = pDevice->byShortPreamble;
2274
2275 }else {
2276 pDevice->byPreambleType = PREAMBLE_LONG;
2277 }
Andres More4e9b5e22013-02-12 20:36:30 -05002278 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002279 }
2280 }
2281
Andres Moree269fc22013-02-12 20:36:29 -05002282 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002283 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2284 dev_kfree_skb_irq(skb);
2285 return 0;
2286 }
2287 }
2288
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002289 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002290
2291 if (pContext == NULL) {
2292 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2293 dev_kfree_skb_irq(skb);
2294 return STATUS_RESOURCES;
2295 }
2296
Andres Moreceb8c5d2013-03-18 20:33:49 -05002297 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002298
2299//mike add:station mode check eapol-key challenge--->
2300{
Andres Moreb902fbf2013-02-25 20:32:51 -05002301 u8 Protocol_Version; //802.1x Authentication
2302 u8 Packet_Type; //802.1x Authentication
2303 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002304 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002305
Charles Clément21ec51f2010-05-18 10:08:14 -07002306 Protocol_Version = skb->data[ETH_HLEN];
2307 Packet_Type = skb->data[ETH_HLEN+1];
2308 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2309 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 -05002310 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002311 /* 802.1x OR eapol-key challenge frame transfer */
2312 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2313 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002314 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002315 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2316 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2317 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002318 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002319 PRINT_K("WPA ");
2320 }
2321 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002322 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002323 PRINT_K("WPA2(re-keying) ");
2324 }
2325 PRINT_K("Authentication completed!!\n");
2326 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002327 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002328 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002329 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002330 PRINT_K("WPA2 Authentication completed!!\n");
2331 }
2332 }
2333 }
2334}
2335//mike add:station mode check eapol-key challenge<---
2336
Andres More4e9b5e22013-02-12 20:36:30 -05002337 if (pDevice->bEncryptionEnable == true) {
2338 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002339 // get Transmit key
2340 do {
2341 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2342 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2343 pbyBSSID = pDevice->abyBSSID;
2344 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002345 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002346 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002347 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2348 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002349 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2350 break;
2351 }
2352 } else {
2353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2354 break;
2355 }
2356 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002357 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2358 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002359 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2360 for (ii = 0; ii< 6; ii++)
2361 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2362 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2363
2364 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002365 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002366 break;
2367 }
2368 // get group key
2369 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002370 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002371 pTransmitKey = NULL;
2372 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2374 }
2375 else
2376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2377 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002378 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2380 }
Andres Moree269fc22013-02-12 20:36:29 -05002381 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002382 }
2383
2384 if (pDevice->bEnableHostWEP) {
2385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002386 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002387 pTransmitKey = &STempKey;
2388 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2389 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2390 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2391 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2392 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2393 memcpy(pTransmitKey->abyKey,
2394 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2395 pTransmitKey->uKeyLength
2396 );
2397 }
2398 }
2399
Andres Moreb902fbf2013-02-25 20:32:51 -05002400 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002401
2402 if (pDevice->bFixRate) {
2403 if (pDevice->byBBType == BB_TYPE_11B) {
2404 if (pDevice->uConnectionRate >= RATE_11M) {
2405 pDevice->wCurrentRate = RATE_11M;
2406 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002407 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002408 }
2409 } else {
2410 if ((pDevice->byBBType == BB_TYPE_11A) &&
2411 (pDevice->uConnectionRate <= RATE_6M)) {
2412 pDevice->wCurrentRate = RATE_6M;
2413 } else {
2414 if (pDevice->uConnectionRate >= RATE_54M)
2415 pDevice->wCurrentRate = RATE_54M;
2416 else
Andres More3eaca0d2013-02-25 20:32:52 -05002417 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002418 }
2419 }
2420 }
2421 else {
2422 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2423 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002424 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002425 // Multicast use highest data rate
2426 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2427 // preamble type
2428 pDevice->byPreambleType = pDevice->byShortPreamble;
2429 }
2430 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002431 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002432 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2433 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2434 pDevice->byPreambleType = pDevice->byShortPreamble;
2435
2436 }
2437 else {
2438 pDevice->byPreambleType = PREAMBLE_LONG;
2439 }
2440 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2441 }
2442 else {
2443 if (pDevice->byBBType != BB_TYPE_11A)
2444 pDevice->wCurrentRate = RATE_2M;
2445 else
2446 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2447 // abyCurrExtSuppRates[]
2448 pDevice->byPreambleType = PREAMBLE_SHORT;
2449 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2450 }
2451 }
2452 }
2453 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2454 // Infra STA rate decided from AP Node, index = 0
2455 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2456 }
2457 }
2458
Andres Moreceb8c5d2013-03-18 20:33:49 -05002459 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002460 if (pDevice->byBBType != BB_TYPE_11A) {
2461 pDevice->wCurrentRate = RATE_1M;
2462 pDevice->byACKRate = RATE_1M;
2463 pDevice->byTopCCKBasicRate = RATE_1M;
2464 pDevice->byTopOFDMBasicRate = RATE_6M;
2465 } else {
2466 pDevice->wCurrentRate = RATE_6M;
2467 pDevice->byACKRate = RATE_6M;
2468 pDevice->byTopCCKBasicRate = RATE_1M;
2469 pDevice->byTopOFDMBasicRate = RATE_6M;
2470 }
2471 }
Forest Bond92b96792009-06-13 07:38:31 -04002472
Andres More0cbd8d92010-05-06 20:34:29 -03002473 DBG_PRT(MSG_LEVEL_DEBUG,
2474 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2475 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002476
2477 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002478 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002479 }
2480
2481 if (pDevice->wCurrentRate <= RATE_11M) {
2482 byPktType = PK_TYPE_11B;
2483 }
2484
Andres More4e9b5e22013-02-12 20:36:30 -05002485 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002486 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2487 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002488 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002489 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002490 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2491 if (pTransmitKey == NULL) {
2492 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2493 }
2494 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002495 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002496 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2497 }
2498 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002499 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2500 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002501 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002502 }
2503 }
2504 }
2505
Forest Bond92b96792009-06-13 07:38:31 -04002506 if (pDevice->bEnableHostWEP) {
2507 if ((uNodeIndex != 0) &&
2508 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002509 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2510 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002511 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002512 }
2513 }
2514 }
2515 else {
2516
Forest Bond92b96792009-06-13 07:38:31 -04002517 if (pTransmitKey == NULL) {
2518 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002519 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002520 dev_kfree_skb_irq(skb);
2521 pStats->tx_dropped++;
2522 return STATUS_FAILURE;
2523 }
Forest Bond92b96792009-06-13 07:38:31 -04002524 }
2525 }
2526
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002527 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2528
Forest Bond92b96792009-06-13 07:38:31 -04002529 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002530 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002531 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002532 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002533 pDevice->wCurrentRate,
2534 &uHeaderLen, &BytesToWrite
2535 );
2536
Andres Moree269fc22013-02-12 20:36:29 -05002537 if (fConvertedPacket == false) {
2538 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002539 dev_kfree_skb_irq(skb);
2540 return STATUS_FAILURE;
2541 }
2542
Andres More4e9b5e22013-02-12 20:36:30 -05002543 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002544 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002545 bScheduleCommand((void *) pDevice,
2546 WLAN_CMD_MAC_DISPOWERSAVING,
2547 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002548 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002549 }
2550 }
2551
Andres Moreb902fbf2013-02-25 20:32:51 -05002552 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002553 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002554
2555 pContext->pPacket = skb;
2556 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002557 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002558
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002559 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2560 &pContext->sEthHeader.h_dest[0],
2561 (u16)(BytesToWrite-uHeaderLen),
2562 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002563
2564 status = PIPEnsSendBulkOut(pDevice,pContext);
2565
Andres More4e9b5e22013-02-12 20:36:30 -05002566 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002567 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002568
Andres Moreb902fbf2013-02-25 20:32:51 -05002569 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002570 }
2571
2572 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002573 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002574 dev_kfree_skb_irq(skb);
2575 return STATUS_FAILURE;
2576 }
2577 else
2578 return 0;
2579
2580}
2581
Forest Bond92b96792009-06-13 07:38:31 -04002582/*
2583 * Description:
2584 * Relay packet send (AC1DMA) from rx dpc.
2585 *
2586 * Parameters:
2587 * In:
2588 * pDevice - Pointer to the adapter
2589 * pPacket - Pointer to rx packet
2590 * cbPacketSize - rx ethernet frame size
2591 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002592 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002593 *
Andres More4e9b5e22013-02-12 20:36:30 -05002594 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002595 */
2596
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002597int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2598 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002599{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002600 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002601 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002602 u32 BytesToWrite = 0, uHeaderLen = 0;
2603 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002604 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002605 SKeyItem STempKey;
2606 PSKeyItem pTransmitKey = NULL;
2607 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002608 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002609 u8 byPktTyp;
2610 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002611 u32 status;
2612 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002613
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002614 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002615
2616 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002617 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002618 }
2619
Andres Moreceb8c5d2013-03-18 20:33:49 -05002620 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002621
Andres More4e9b5e22013-02-12 20:36:30 -05002622 if (pDevice->bEncryptionEnable == true) {
2623 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002624 // get group key
2625 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002626 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002627 pTransmitKey = NULL;
2628 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2629 } else {
2630 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2631 }
2632 }
2633
2634 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002635 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002636 pTransmitKey = &STempKey;
2637 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2638 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2639 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2640 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2641 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2642 memcpy(pTransmitKey->abyKey,
2643 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2644 pTransmitKey->uKeyLength
2645 );
2646 }
2647 }
2648
2649 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002650 pContext->bBoolInUse = false;
2651 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002652 }
2653
Andres Moreb902fbf2013-02-25 20:32:51 -05002654 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002655
2656 if (pDevice->bFixRate) {
2657 if (pDevice->byBBType == BB_TYPE_11B) {
2658 if (pDevice->uConnectionRate >= RATE_11M) {
2659 pDevice->wCurrentRate = RATE_11M;
2660 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002661 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002662 }
2663 } else {
2664 if ((pDevice->byBBType == BB_TYPE_11A) &&
2665 (pDevice->uConnectionRate <= RATE_6M)) {
2666 pDevice->wCurrentRate = RATE_6M;
2667 } else {
2668 if (pDevice->uConnectionRate >= RATE_54M)
2669 pDevice->wCurrentRate = RATE_54M;
2670 else
Andres More3eaca0d2013-02-25 20:32:52 -05002671 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002672 }
2673 }
2674 }
2675 else {
2676 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2677 }
2678
Forest Bond92b96792009-06-13 07:38:31 -04002679 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002680 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002681 }
2682
2683 if (pDevice->wCurrentRate <= RATE_11M)
2684 byPktType = PK_TYPE_11B;
2685
Andres Moreabad19d2010-07-12 16:28:32 -03002686 BytesToWrite = uDataLen + ETH_FCS_LEN;
2687
Forest Bond92b96792009-06-13 07:38:31 -04002688 // Convert the packet to an usb frame and copy into our buffer
2689 // and send the irp.
2690
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002691 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2692
Forest Bond92b96792009-06-13 07:38:31 -04002693 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002694 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002695 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2696 pbySkbData, pTransmitKey, uNodeIndex,
2697 pDevice->wCurrentRate,
2698 &uHeaderLen, &BytesToWrite
2699 );
2700
Andres Moree269fc22013-02-12 20:36:29 -05002701 if (fConvertedPacket == false) {
2702 pContext->bBoolInUse = false;
2703 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002704 }
2705
Andres Moreb902fbf2013-02-25 20:32:51 -05002706 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002707 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002708
2709 pContext->pPacket = NULL;
2710 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002711 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002712
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002713 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2714 &pContext->sEthHeader.h_dest[0],
2715 (u16)(BytesToWrite - uHeaderLen),
2716 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002717
2718 status = PIPEnsSendBulkOut(pDevice,pContext);
2719
Andres More4e9b5e22013-02-12 20:36:30 -05002720 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002721}
2722