blob: 791144a50b17897739a40826310e84b68927cd0b [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 Priestleyfa575602013-09-26 19:00:41 +0100103 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
104 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
106static u32 s_uFillDataHead(struct vnt_private *pDevice,
107 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100108 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000110static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500111 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000112 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
115 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100116 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static void s_vSWencryption(struct vnt_private *pDevice,
119 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000121static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
122 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100124static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000125 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000127static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100128 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
129 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400130
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000131static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100132 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500133 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100135static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100136 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400137
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100138static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000139 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
140 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400141
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000142static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400143{
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +0100144 struct vnt_usb_send_context *pContext = NULL;
145 struct vnt_usb_send_context *pReturnContext = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000146 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400147
148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
149
150 for (ii = 0; ii < pDevice->cbTD; ii++) {
151 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500152 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500153 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100154 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400155 pReturnContext = pContext;
156 break;
157 }
158 }
159 if ( ii == pDevice->cbTD ) {
160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
161 }
Andres More8611a292010-05-01 14:25:00 -0300162 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400163}
164
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000165static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
166 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400167{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000168 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400169
Andres More4b50fb42010-06-22 21:57:42 -0300170 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400171 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300172 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
174 else
175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
176
177 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
178 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300179 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
180 pbyDestAddr,
181 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400182}
183
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000184static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
185 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100186 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400187{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000188 u32 *pdwIV = (u32 *)pbyIVHead;
189 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500190 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000191 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400192
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100193 /* Fill TXKEY */
194 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100195 return;
Forest Bond92b96792009-06-13 07:38:31 -0400196
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100197 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
198 *pdwIV = pDevice->dwIVCounter;
199 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400200
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100201 switch (pTransmitKey->byCipherSuite) {
202 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100203 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
204 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
205 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
206 pTransmitKey->uKeyLength);
207 } else {
208 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
209 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
210 pTransmitKey->uKeyLength);
211 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
212 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
213 memcpy(pbyBuf+11, pTransmitKey->abyKey,
214 pTransmitKey->uKeyLength);
215 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100216
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100217 memcpy(pDevice->abyPRNG, pbyBuf, 16);
218 }
219 /* Append IV after Mac Header */
220 *pdwIV &= WEP_IV_MASK;
221 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
222 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100223
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100224 pDevice->dwIVCounter++;
225 if (pDevice->dwIVCounter > WEP_IV_MASK)
226 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100227
228 break;
229 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100230 pTransmitKey->wTSC15_0++;
231 if (pTransmitKey->wTSC15_0 == 0)
232 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100233
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100234 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
235 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
236 pDevice->abyPRNG);
237 memcpy(pbyBuf, pDevice->abyPRNG, 16);
238
239 /* Make IV */
240 memcpy(pdwIV, pDevice->abyPRNG, 3);
241
242 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
243 0xc0) | 0x20);
244 /* Append IV&ExtIV after Mac Header */
245 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
246
247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
248 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
249
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100250 break;
251 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100252 pTransmitKey->wTSC15_0++;
253 if (pTransmitKey->wTSC15_0 == 0)
254 pTransmitKey->dwTSC47_16++;
255
256 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
257
258 /* Make IV */
259 *pdwIV = 0;
260 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
261 0xc0) | 0x20);
262
263 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
264
265 /* Append IV&ExtIV after Mac Header */
266 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
267
268 if (!mic_hdr)
269 return;
270
271 /* MICHDR0 */
272 mic_hdr->id = 0x59;
273 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
274 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
275
276 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
277 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
278
279 /* MICHDR1 */
280 if (pDevice->bLongHeader)
281 mic_hdr->hlen = cpu_to_be16(28);
282 else
283 mic_hdr->hlen = cpu_to_be16(22);
284
285 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
286 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
287
288 /* MICHDR2 */
289 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
290 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100291 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100292 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100293
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100294 if (pDevice->bLongHeader)
295 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
296 }
Forest Bond92b96792009-06-13 07:38:31 -0400297}
298
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000299static void s_vSWencryption(struct vnt_private *pDevice,
300 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400301{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000302 u32 cbICVlen = 4;
303 u32 dwICV = 0xffffffff;
304 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400305
306 if (pTransmitKey == NULL)
307 return;
308
309 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
310 //=======================================================================
311 // Append ICV after payload
312 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500313 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400314 // finally, we must invert dwCRC to get the correct answer
315 *pdwICV = cpu_to_le32(~dwICV);
316 // RC4 encryption
317 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
318 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
319 //=======================================================================
320 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
321 //=======================================================================
322 //Append ICV after payload
323 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500324 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400325 // finally, we must invert dwCRC to get the correct answer
326 *pdwICV = cpu_to_le32(~dwICV);
327 // RC4 encryption
328 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
329 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
330 //=======================================================================
331 }
332}
333
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100334static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
335{
336 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
337 [rate % MAX_RATE]);
338}
339
Forest Bond92b96792009-06-13 07:38:31 -0400340/*byPktType : PK_TYPE_11A 0
341 PK_TYPE_11B 1
342 PK_TYPE_11GB 2
343 PK_TYPE_11GA 3
344*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000345static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
346 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400347{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000348 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400349
350 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
351 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500352 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400353 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500354 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400355 }
356
357 if (bNeedAck) {
358 return (uDataTime + pDevice->uSIFS + uAckTime);
359 }
360 else {
361 return uDataTime;
362 }
363}
364
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100365static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
366 u32 frame_length, u16 rate, int need_ack)
367{
368 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
369 frame_length, rate, need_ack));
370}
371
Forest Bond92b96792009-06-13 07:38:31 -0400372//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100373static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000374 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400375{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000376 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400377
378 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
379
Forest Bond92b96792009-06-13 07:38:31 -0400380 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
381 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
382 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
383 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
384 }
385 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
386 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
387 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
388 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
389 }
390 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
391 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
392 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
393 }
394 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
395 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
396 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
397 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
398 return uRrvTime;
399 }
400
401 //RTSRrvTime
402 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100403 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400404}
405
406//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100407static u16 s_uGetDataDuration(struct vnt_private *pDevice,
408 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400409{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100410 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400411
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100412 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100413 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100414 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
415 byPktType, 14, pDevice->byTopCCKBasicRate);
416 else
417 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
418 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100419 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100420 }
Forest Bond92b96792009-06-13 07:38:31 -0400421
Forest Bond92b96792009-06-13 07:38:31 -0400422 return 0;
423}
424
Forest Bond92b96792009-06-13 07:38:31 -0400425//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100426static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000427 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
428 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400429{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000430 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400431
Forest Bond92b96792009-06-13 07:38:31 -0400432 switch (byDurType) {
433
434 case RTSDUR_BB: //RTSDuration_bb
435 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
436 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
437 break;
438
439 case RTSDUR_BA: //RTSDuration_ba
440 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
441 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
442 break;
443
444 case RTSDUR_AA: //RTSDuration_aa
445 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
446 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
447 break;
448
449 case CTSDUR_BA: //CTSDuration_ba
450 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
451 break;
452
453 case RTSDUR_BA_F0: //RTSDuration_ba_f0
454 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
455 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
456 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
457 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
458 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
459 }
460 break;
461
462 case RTSDUR_AA_F0: //RTSDuration_aa_f0
463 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
464 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
465 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
466 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
467 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
468 }
469 break;
470
471 case RTSDUR_BA_F1: //RTSDuration_ba_f1
472 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
473 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
474 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
475 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
476 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
477 }
478 break;
479
480 case RTSDUR_AA_F1: //RTSDuration_aa_f1
481 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
482 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
483 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
484 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
485 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
486 }
487 break;
488
489 case CTSDUR_BA_F0: //CTSDuration_ba_f0
490 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
491 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
492 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
493 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
494 }
495 break;
496
497 case CTSDUR_BA_F1: //CTSDuration_ba_f1
498 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
499 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
500 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
501 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
502 }
503 break;
504
505 default:
506 break;
507 }
508
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100509 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400510}
511
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000512static u32 s_uFillDataHead(struct vnt_private *pDevice,
513 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100514 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400515{
516
517 if (pTxDataHead == NULL) {
518 return 0;
519 }
520
521 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Forest Bond92b96792009-06-13 07:38:31 -0400522 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100523 struct vnt_tx_datahead_g *pBuf =
524 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400525 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100526 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
527 byPktType, &pBuf->a);
528 BBvCalculateParameter(pDevice, cbFrameLength,
529 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400530 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100531 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100532 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100533 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100534 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400535
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100536 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
537 wCurrentRate);
538 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
539 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400540 return (pBuf->wDuration_a);
541 } else {
542 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100543 struct vnt_tx_datahead_g_fb *pBuf =
544 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400545 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100546 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
547 byPktType, &pBuf->a);
548 BBvCalculateParameter(pDevice, cbFrameLength,
549 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400550 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100551 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100552 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100553 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100554 PK_TYPE_11B, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100555 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100556 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100557 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100558 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100559 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
560 wCurrentRate);
561 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
562 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400563 return (pBuf->wDuration_a);
564 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400565 }
566 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100567 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100568 struct vnt_tx_datahead_a_fb *pBuf =
569 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400570 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100571 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
572 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400573 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100574 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100575 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100576 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100577 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100578 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100579 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100580 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
581 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400582 return (pBuf->wDuration);
583 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100584 struct vnt_tx_datahead_ab *pBuf =
585 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400586 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100587 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
588 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400589 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100590 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100591 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100592 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
593 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400594 return (pBuf->wDuration);
595 }
596 }
597 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100598 struct vnt_tx_datahead_ab *pBuf =
599 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400600 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100601 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
602 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400603 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100604 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100605 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100606 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
607 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400608 return (pBuf->wDuration);
609 }
610 return 0;
611}
612
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100613static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
614 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
615 u16 duration)
616{
617 rts->duration = duration;
618 rts->frame_control = TYPE_CTL_RTS;
619
620 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
621 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
622 else
623 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
624
625 if (priv->eOPMode == OP_MODE_AP)
626 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
627 else
628 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
629
630 return 0;
631}
632
633static int vnt_rxtx_rts_g_head(struct vnt_private *priv,
634 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
635 u8 pkt_type, u32 frame_len, int need_ack,
636 u16 current_rate, u8 fb_option)
637{
638 u16 rts_frame_len = 20;
639
640 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
641 PK_TYPE_11B, &buf->b);
642 BBvCalculateParameter(priv, rts_frame_len,
643 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
644
645 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
646 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
647 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
648 pkt_type, current_rate, need_ack, fb_option);
649 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
650 pkt_type, current_rate, need_ack, fb_option);
651
652 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
653
654 return 0;
655}
656
Malcolm Priestleyec917132013-08-26 11:07:46 +0100657static int vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
658 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
659 u8 pkt_type, u32 frame_len, int need_ack,
660 u16 current_rate, u8 fb_option)
661{
662 u16 rts_frame_len = 20;
663
664 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
665 PK_TYPE_11B, &buf->b);
666 BBvCalculateParameter(priv, rts_frame_len,
667 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
668
669
670 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
671 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
672 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
673 pkt_type, current_rate, need_ack, fb_option);
674 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
675 pkt_type, current_rate, need_ack, fb_option);
676
677
678 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
679 frame_len, pkt_type, current_rate, need_ack, fb_option);
680 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
681 frame_len, pkt_type, current_rate, need_ack, fb_option);
682 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
683 frame_len, pkt_type, current_rate, need_ack, fb_option);
684 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
685 frame_len, pkt_type, current_rate, need_ack, fb_option);
686
687 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
688
689 return 0;
690}
691
Malcolm Priestley17126332013-08-26 11:09:38 +0100692static int vnt_rxtx_rts_ab_head(struct vnt_private *priv,
693 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
694 u8 pkt_type, u32 frame_len, int need_ack,
695 u16 current_rate, u8 fb_option)
696{
697 u16 rts_frame_len = 20;
698
699 BBvCalculateParameter(priv, rts_frame_len,
700 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
701
702 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
703 pkt_type, current_rate, need_ack, fb_option);
704
705 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
706
707 return 0;
708}
709
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100710static int vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
711 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
712 u8 pkt_type, u32 frame_len, int need_ack,
713 u16 current_rate, u8 fb_option)
714{
715 u16 rts_frame_len = 20;
716
717 BBvCalculateParameter(priv, rts_frame_len,
718 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
719
720 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
721 pkt_type, current_rate, need_ack, fb_option);
722
723 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
724 frame_len, pkt_type, current_rate, need_ack, fb_option);
725
726 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
727 frame_len, pkt_type, current_rate, need_ack, fb_option);
728
729 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
730
731 return 0;
732}
733
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000734static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100735 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500736 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400737{
Forest Bond92b96792009-06-13 07:38:31 -0400738
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100739 if (!head)
740 return;
Forest Bond92b96792009-06-13 07:38:31 -0400741
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100742 /* Note: So far RTSHead doesn't appear in ATIM
743 * & Beacom DMA, so we don't need to take them
744 * into account.
745 * Otherwise, we need to modified codes for them.
746 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100747 switch (byPktType) {
748 case PK_TYPE_11GB:
749 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100750 if (byFBOption == AUTO_FB_NONE)
751 vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100752 psEthHeader, byPktType, cbFrameLength,
753 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100754 else
755 vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100756 psEthHeader, byPktType, cbFrameLength,
757 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100758 break;
759 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100760 if (byFBOption) {
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100761 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
762 psEthHeader, byPktType, cbFrameLength,
763 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100764 break;
765 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100766 case PK_TYPE_11B:
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100767 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100768 psEthHeader, byPktType, cbFrameLength,
769 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100770 }
Forest Bond92b96792009-06-13 07:38:31 -0400771}
772
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000773static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100774 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
775 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400776{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000777 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400778
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100779 if (!head)
780 return;
Forest Bond92b96792009-06-13 07:38:31 -0400781
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100782 if (byFBOption != AUTO_FB_NONE) {
783 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100784 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100785 /* Get SignalField,ServiceField,Length */
786 BBvCalculateParameter(pDevice, uCTSFrameLen,
787 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100788 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
789 cbFrameLength, byPktType,
790 wCurrentRate, bNeedAck, byFBOption);
791 /* Get CTSDuration_ba_f0 */
792 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
793 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
794 bNeedAck, byFBOption);
795 /* Get CTSDuration_ba_f1 */
796 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
797 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
798 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100799 /* Get CTS Frame body */
800 pBuf->data.duration = pBuf->wDuration_ba;
801 pBuf->data.frame_control = TYPE_CTL_CTS;
802 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100803 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100804 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100805 /* Get SignalField,ServiceField,Length */
806 BBvCalculateParameter(pDevice, uCTSFrameLen,
807 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100808 /* Get CTSDuration_ba */
809 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
810 CTSDUR_BA, cbFrameLength, byPktType,
811 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100812 /*Get CTS Frame body*/
813 pBuf->data.duration = pBuf->wDuration_ba;
814 pBuf->data.frame_control = TYPE_CTL_CTS;
815 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400816 }
Forest Bond92b96792009-06-13 07:38:31 -0400817}
818
Forest Bond92b96792009-06-13 07:38:31 -0400819/*+
820 *
821 * Description:
822 * Generate FIFO control for MAC & Baseband controller
823 *
824 * Parameters:
825 * In:
826 * pDevice - Pointer to adpater
827 * pTxDataHead - Transmit Data Buffer
828 * pTxBufHead - pTxBufHead
829 * pvRrvTime - pvRrvTime
830 * pvRTS - RTS Buffer
831 * pCTS - CTS Buffer
832 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
833 * bNeedACK - If need ACK
834 * uDMAIdx - DMA Index
835 * Out:
836 * none
837 *
838 * Return Value: none
839 *
840-*/
Andres Morecc856e62010-05-17 21:34:01 -0300841
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000842static void s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100843 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100844 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
845 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400846{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100847 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100848 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000849 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
850 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000851 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400852
853 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
Forest Bond92b96792009-06-13 07:38:31 -0400854 pFifoHead->wReserved = wCurrentRate;
855 wFifoCtl = pFifoHead->wFIFOCtl;
856
Forest Bond92b96792009-06-13 07:38:31 -0400857 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
858 byFBOption = AUTO_FB_0;
859 }
860 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
861 byFBOption = AUTO_FB_1;
862 }
863
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100864 if (!pFifoHead)
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100865 return;
866
Forest Bond92b96792009-06-13 07:38:31 -0400867 if (pDevice->bLongHeader)
868 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
869
870 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100871 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400872 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100873 struct vnt_rrv_time_rts *pBuf = &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100874
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100875 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
876 byPktType, cbFrameSize, wCurrentRate);
877 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
878 byPktType, cbFrameSize, wCurrentRate);
879 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
880 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100881 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
882 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
883 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
884 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
885 bNeedACK);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100886
887 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100888 *mic_hdr = &tx_buffer->tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100889 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
890 } else {
891 head = &tx_buffer->tx_head.tx_rts.tx.head;
892 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100893
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100894 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100895 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100896 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400897 }
898 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400899 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100900 struct vnt_rrv_time_cts *pBuf = &tx_buffer->tx_head.tx_cts.cts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100901
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100902 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
903 cbFrameSize, wCurrentRate, bNeedACK);
904 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
905 PK_TYPE_11B, cbFrameSize,
906 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100907 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
908 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100909
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100910 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100911 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100912 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
913 } else {
914 head = &tx_buffer->tx_head.tx_cts.tx.head;
915 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100916
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100917 /* Fill CTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100918 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, head,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100919 cbFrameSize, bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400920 }
921 }
922 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100923 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400924 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100925 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100926
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100927 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
928 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100929 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
930 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100931
932 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100933 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100934 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
935 } else {
936 head = &tx_buffer->tx_head.tx_ab.tx.head;
937 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100938
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100939 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100940 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100941 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100942 } else {
Forest Bond92b96792009-06-13 07:38:31 -0400943 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100944 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100945
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100946 if (need_mic)
947 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
948
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100949 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
950 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400951 }
952 }
953 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100954 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400955 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100956 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100957
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100958 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
959 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100960 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
961 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100962
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100963 if (need_mic) {
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100964 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100965 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
966 } else {
967 head = &tx_buffer->tx_head.tx_ab.tx.head;
968 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100969
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100970 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100971 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100972 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400973 }
974 else { //RTS_needless, non PCF mode
975 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100976 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100977
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100978 if (need_mic)
979 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
980
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100981 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
982 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400983 }
984 }
985 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
986}
987/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500988 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500989 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300990 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400991*/
992
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000993static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100994 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100995 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
996 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
997 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400998{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100999 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001000 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1001 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001002 u32 cb802_1_H_len;
1003 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1004 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001005 int bNeedACK;
1006 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001007 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1008 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1009 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1010 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1011 u32 uDuration;
1012 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001013 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001014 void *pvTxDataHd;
1015 u8 byFBOption = AUTO_FB_NONE, byFragType;
1016 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +01001017 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001018 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001019 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001020
1021 pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001022
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001023 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001024 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1025 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001026 }
Forest Bond92b96792009-06-13 07:38:31 -04001027
Forest Bond92b96792009-06-13 07:38:31 -04001028 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001029 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001030 if (pDevice->dwDiagRefCount == 0) {
1031 cb802_1_H_len = 8;
1032 } else {
1033 cb802_1_H_len = 2;
1034 }
1035 } else {
1036 cb802_1_H_len = 0;
1037 }
1038
Charles Clément21ec51f2010-05-18 10:08:14 -07001039 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001040
1041 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001042 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001043
1044 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001045 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001046 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1047 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001048 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1049 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001050 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001051 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001052 pTxBufHead->wFIFOCtl =
1053 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1054 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001055 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001056 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1057 }
Forest Bond92b96792009-06-13 07:38:31 -04001058 }
1059 else {
1060 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001061 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001062 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1063 }
1064 } //if (pDevice->dwDiagRefCount != 0) {
1065
1066 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1067
1068 //Set FIFOCTL_LHEAD
1069 if (pDevice->bLongHeader)
1070 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1071
Forest Bond92b96792009-06-13 07:38:31 -04001072 //Set FRAGCTL_MACHDCNT
1073 if (pDevice->bLongHeader) {
1074 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1075 } else {
1076 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1077 }
Andres More3eaca0d2013-02-25 20:32:52 -05001078 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001079
1080 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001081 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001082 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1083 }
1084
1085 //Set Auto Fallback Ctl
1086 if (wCurrentRate >= RATE_18M) {
1087 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1088 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1089 byFBOption = AUTO_FB_0;
1090 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1091 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1092 byFBOption = AUTO_FB_1;
1093 }
1094 }
1095
Andres More4e9b5e22013-02-12 20:36:30 -05001096 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001097 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1098 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1099 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1100 }
1101 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1102 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1103 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1104 }
1105 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1106 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1107 }
1108 }
1109 }
1110
Forest Bond92b96792009-06-13 07:38:31 -04001111 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1112 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1113 cbIVlen = 4;
1114 cbICVlen = 4;
1115 }
1116 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1117 cbIVlen = 8;//IV+ExtIV
1118 cbMIClen = 8;
1119 cbICVlen = 4;
1120 }
1121 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1122 cbIVlen = 8;//RSN Header
1123 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001124 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001125 }
Andres Moree269fc22013-02-12 20:36:29 -05001126 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001127 //MAC Header should be padding 0 to DW alignment.
1128 uPadding = 4 - (cbMACHdLen%4);
1129 uPadding %= 4;
1130 }
1131 }
1132
1133 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1134
Andres Moree269fc22013-02-12 20:36:29 -05001135 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1136 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001137 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001138 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001139 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1140 }
1141
Andres Moreb902fbf2013-02-25 20:32:51 -05001142 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001143 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1144
Forest Bond92b96792009-06-13 07:38:31 -04001145 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1146 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001147 if (bRTS == true) {//RTS_need
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001148 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1149 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1150 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001151 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001152 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001153 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001154 }
1155 else { //RTS_needless
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001156 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1157 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1158 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001159 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1160 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001161 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001162 }
1163 } else {
1164 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001165 if (bRTS == true) {//RTS_need
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001166 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1167 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1168 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001169 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1170 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001171 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001172 }
Andres Moree269fc22013-02-12 20:36:29 -05001173 else if (bRTS == false) { //RTS_needless
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001174 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001175 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1176 cbMICHDR + sizeof(struct vnt_cts_fb));
1177 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001178 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001179 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001180 }
1181 } // Auto Fall Back
1182 }
1183 else {//802.11a/b packet
1184 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001185 if (bRTS == true) {//RTS_need
Malcolm Priestley558becf2013-08-16 23:50:32 +01001186 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1187 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001188 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001189 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1190 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001191 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001192 }
Andres Moree269fc22013-02-12 20:36:29 -05001193 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley558becf2013-08-16 23:50:32 +01001194 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1195 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001196 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001197 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001198 }
1199 } else {
1200 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001201 if (bRTS == true) {//RTS_need
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001202 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1203 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001204 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001205 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1206 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001207 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001208 }
Andres Moree269fc22013-02-12 20:36:29 -05001209 else if (bRTS == false) { //RTS_needless
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001210 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1211 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001212 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001213 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001214 }
1215 } // Auto Fall Back
1216 }
1217
Andres Moreb902fbf2013-02-25 20:32:51 -05001218 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1219 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1220 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001221
Forest Bond92b96792009-06-13 07:38:31 -04001222 //=========================
1223 // No Fragmentation
1224 //=========================
1225 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1226 byFragType = FRAGCTL_NONFRAG;
1227 //uDMAIdx = TYPE_AC0DMA;
1228 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1229
Forest Bond92b96792009-06-13 07:38:31 -04001230 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001231 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001232 tx_buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001233 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Forest Bond92b96792009-06-13 07:38:31 -04001234 //Fill DataHead
1235 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001236 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001237 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001238 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001239 byFragType, uDMAIdx, 0);
1240
Andres More4e9b5e22013-02-12 20:36:30 -05001241 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001242 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001243 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001244 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001245
1246 if (pDevice->bEnableHostWEP) {
1247 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1248 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1249 }
1250 }
1251
1252 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001253 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001254 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001255 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1256 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001257 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001258 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001259 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001260 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001261 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001262 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001263 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001264 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001265 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001266
1267 }
1268
1269 }
1270
Forest Bond92b96792009-06-13 07:38:31 -04001271 if (pPacket != NULL) {
1272 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001273 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001274 (pPacket + ETH_HLEN),
1275 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001276 );
1277
1278 } else {
1279 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001280 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001281 }
1282
Andres More4e9b5e22013-02-12 20:36:30 -05001283 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001284
1285 ///////////////////////////////////////////////////////////////////
1286
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001287 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1288 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1289 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1290 }
Forest Bond92b96792009-06-13 07:38:31 -04001291 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001292 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1293 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001294 }
1295 else {
Andres More52a7e642013-02-25 20:32:53 -05001296 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1297 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001298 }
1299 // DO Software Michael
1300 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001301 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001302 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001303 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1305 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001306
1307 ///////////////////////////////////////////////////////////////////
1308
1309 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1310 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001311 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001312 //}
1313 //DBG_PRN_GRP12(("\n\n\n"));
1314
1315 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1316
Andres More52a7e642013-02-25 20:32:53 -05001317 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1318 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001319
1320 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1321 MIC_vUnInit();
1322
Andres More4e9b5e22013-02-12 20:36:30 -05001323 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001324 *pdwMIC_L = 0;
1325 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001326 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001327 }
1328 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1329 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1330 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1331 }
1332
Andres More4e9b5e22013-02-12 20:36:30 -05001333 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001334
Andres More3eaca0d2013-02-25 20:32:52 -05001335 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001336
Andres More4e9b5e22013-02-12 20:36:30 -05001337 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1338 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1339 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001340 cbFrameSize -= cbICVlen;
1341 }
1342
Forest Bond92b96792009-06-13 07:38:31 -04001343 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001344
1345 *pcbHeaderLen = cbHeaderLength;
1346 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1347
Forest Bond92b96792009-06-13 07:38:31 -04001348 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001349 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001350
Andres More4e9b5e22013-02-12 20:36:30 -05001351 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001352
1353}
1354
Forest Bond92b96792009-06-13 07:38:31 -04001355/*+
1356 *
1357 * Description:
1358 * Translate 802.3 to 802.11 header
1359 *
1360 * Parameters:
1361 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001362 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001363 * dwTxBufferAddr - Transmit Buffer
1364 * pPacket - Packet from upper layer
1365 * cbPacketSize - Transmit Data Length
1366 * Out:
1367 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1368 * pcbAppendPayload - size of append payload for 802.1H translation
1369 *
1370 * Return Value: none
1371 *
1372-*/
1373
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001374static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001375 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001376 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001377{
Andres More1cac4a42013-03-18 20:33:50 -05001378 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001379
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001380 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001381
1382 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001383 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001384 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001385 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001386 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1387 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001388 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001389 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001390 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001391 } else {
1392 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001393 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001394 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001395 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001396 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001397 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001398 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001399 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001400 &(pDevice->abyBSSID[0]),
1401 ETH_ALEN);
1402 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001403 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001404 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001405 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001406 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001407 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001408 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001409 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001410 &(pDevice->abyBSSID[0]),
1411 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001412 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001413 }
1414 }
1415
1416 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001417 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001418
Andres More1cac4a42013-03-18 20:33:50 -05001419 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001420
1421 if (pDevice->bLongHeader) {
1422 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001423 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001424 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001425 }
Andres More1cac4a42013-03-18 20:33:50 -05001426 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001427
1428 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001429 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001430
1431 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1432 pDevice->wSeqCounter++;
1433 if (pDevice->wSeqCounter > 0x0fff)
1434 pDevice->wSeqCounter = 0;
1435 }
1436
1437 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001438 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001439 }
1440}
1441
Forest Bond92b96792009-06-13 07:38:31 -04001442/*+
1443 *
1444 * Description:
1445 * Request instructs a MAC to transmit a 802.11 management packet through
1446 * the adapter onto the medium.
1447 *
1448 * Parameters:
1449 * In:
1450 * hDeviceContext - Pointer to the adapter
1451 * pPacket - A pointer to a descriptor for the packet to transmit
1452 * Out:
1453 * none
1454 *
Andres Moree269fc22013-02-12 20:36:29 -05001455 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001456 *
1457-*/
1458
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001459CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1460 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001461{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001462 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001463 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001464 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001465 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001466 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001467 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001468 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001469 void *pvTxDataHd;
1470 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001471 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001472 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001473 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1474 u32 uPadding = 0;
1475 u16 wTxBufSize;
1476 u32 cbMacHdLen;
1477 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001478
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001479 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001480
1481 if (NULL == pContext) {
1482 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1483 return CMD_STATUS_RESOURCES;
1484 }
1485
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001486 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001487 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001488 pTxBufHead = &pTX_Buffer->fifo_head;
1489 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1490 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001491
1492 if (pDevice->byBBType == BB_TYPE_11A) {
1493 wCurrentRate = RATE_6M;
1494 byPktType = PK_TYPE_11A;
1495 } else {
1496 wCurrentRate = RATE_1M;
1497 byPktType = PK_TYPE_11B;
1498 }
1499
1500 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1501 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1502 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1503 // to set power here.
1504 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1505 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1506 } else {
1507 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1508 }
1509 pDevice->wCurrentRate = wCurrentRate;
1510
Forest Bond92b96792009-06-13 07:38:31 -04001511 //Set packet type
1512 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1513 pTxBufHead->wFIFOCtl = 0;
1514 }
1515 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1516 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1517 }
1518 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1519 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1520 }
1521 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1522 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1523 }
1524
1525 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1526 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1527
Andres More22040bb2010-08-02 20:21:44 -03001528 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001529 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001530 }
1531 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001532 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001533 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1534 };
1535
1536 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1537 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1538
1539 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1540 //Set Preamble type always long
1541 //pDevice->byPreambleType = PREAMBLE_LONG;
1542 // probe-response don't retry
1543 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001544 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001545 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1546 //}
1547 }
1548
1549 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1550
1551 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001552 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001553 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1554 } else {
1555 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1556 }
1557
1558 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001559 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001560
1561 // Notes:
1562 // Although spec says MMPDU can be fragmented; In most case,
1563 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001564 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001565
1566 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1567 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1568 cbIVlen = 4;
1569 cbICVlen = 4;
1570 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1571 }
1572 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1573 cbIVlen = 8;//IV+ExtIV
1574 cbMIClen = 8;
1575 cbICVlen = 4;
1576 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1577 //We need to get seed here for filling TxKey entry.
1578 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1579 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1580 }
1581 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1582 cbIVlen = 8;//RSN Header
1583 cbICVlen = 8;//MIC
1584 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001585 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001586 }
1587 //MAC Header should be padding 0 to DW alignment.
1588 uPadding = 4 - (cbMacHdLen%4);
1589 uPadding %= 4;
1590 }
1591
1592 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1593
1594 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001595 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001596 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1597 }
1598 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1599
1600 //Set RrvTime/RTS/CTS Buffer
1601 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001602 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001603 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1604 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001605 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001606 }
1607 else { // 802.11a/b packet
Malcolm Priestley558becf2013-08-16 23:50:32 +01001608 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1609 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001610 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001611 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001612 }
1613
Andres Moreceb8c5d2013-03-18 20:33:49 -05001614 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001615 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1616 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001617 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001618 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1619 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001620 //=========================
1621 // No Fragmentation
1622 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001623 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001624
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001625 /* Fill FIFO,RrvTime,RTS,and CTS */
1626 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001627 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001628 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001629
1630 //Fill DataHead
1631 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001632 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001633
Andres More1cac4a42013-03-18 20:33:50 -05001634 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001635
1636 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1637
1638 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001639 u8 * pbyIVHead;
1640 u8 * pbyPayloadHead;
1641 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001642 PSKeyItem pTransmitKey = NULL;
1643
Andres Moreb902fbf2013-02-25 20:32:51 -05001644 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1645 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001646 do {
1647 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001648 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001649 pbyBSSID = pDevice->abyBSSID;
1650 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001651 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001652 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001653 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001654 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1655 break;
1656 }
1657 } else {
1658 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1659 break;
1660 }
1661 }
1662 // get group key
1663 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001664 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001665 pTransmitKey = NULL;
1666 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1667 } else {
1668 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1669 }
Andres Moree269fc22013-02-12 20:36:29 -05001670 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001671 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001672 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001673 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001674
Jim Lieb3e362592009-08-12 14:54:11 -07001675 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001676 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001677 cbFrameBodySize);
1678 }
1679 else {
1680 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001681 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001682 }
1683
Andres More1cac4a42013-03-18 20:33:50 -05001684 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001685 pDevice->wSeqCounter++ ;
1686 if (pDevice->wSeqCounter > 0x0fff)
1687 pDevice->wSeqCounter = 0;
1688
1689 if (bIsPSPOLL) {
1690 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001691 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001692 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1693 // in the same place of other packet's Duration-field).
1694 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001695 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1696 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1697 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1698 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1699 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1700 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001701 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1702 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1703 }
Forest Bond92b96792009-06-13 07:38:31 -04001704 }
1705
Andres More3eaca0d2013-02-25 20:32:52 -05001706 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001707 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001708 pTX_Buffer->byType = 0x00;
1709
1710 pContext->pPacket = NULL;
1711 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001712 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001713
Andres More1cac4a42013-03-18 20:33:50 -05001714 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001715 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1716 &pMACHeader->addr1[0], (u16)cbFrameSize,
1717 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001718 }
1719 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001720 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1721 &pMACHeader->addr3[0], (u16)cbFrameSize,
1722 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001723 }
1724
1725 PIPEnsSendBulkOut(pDevice,pContext);
1726 return CMD_STATUS_PENDING;
1727}
1728
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001729CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1730 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001731{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001732 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001733 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1734 u32 cbHeaderSize = 0;
1735 u16 wTxBufSize = sizeof(STxShortBufHead);
1736 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001737 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001738 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001739 u16 wCurrentRate;
1740 u32 cbFrameBodySize;
1741 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001742 u8 *pbyTxBufferAddr;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001743 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001744 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001745
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001746 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001747 if (NULL == pContext) {
1748 status = CMD_STATUS_RESOURCES;
1749 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1750 return status ;
1751 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001752
1753 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001754 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001755
1756 cbFrameBodySize = pPacket->cbPayloadLen;
1757
1758 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1759 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001760
1761 if (pDevice->byBBType == BB_TYPE_11A) {
1762 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001763 pTxDataHead = (struct vnt_tx_datahead_ab *)
1764 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001765 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001766 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1767 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001768 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001769 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001770 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001771 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001772 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001773 } else {
1774 wCurrentRate = RATE_1M;
1775 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001776 pTxDataHead = (struct vnt_tx_datahead_ab *)
1777 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001778 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001779 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1780 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001781 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001782 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001783 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001784 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001785 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001786 }
1787
1788 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001789 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001790 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001791
Andres More1cac4a42013-03-18 20:33:50 -05001792 pMACHeader->duration_id = 0;
1793 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001794 pDevice->wSeqCounter++ ;
1795 if (pDevice->wSeqCounter > 0x0fff)
1796 pDevice->wSeqCounter = 0;
1797
1798 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1799
Andres More3eaca0d2013-02-25 20:32:52 -05001800 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001801 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001802 pTX_Buffer->byType = 0x01;
1803
1804 pContext->pPacket = NULL;
1805 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001806 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001807
1808 PIPEnsSendBulkOut(pDevice,pContext);
1809 return CMD_STATUS_PENDING;
1810
1811}
1812
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001813void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1814{
1815 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001816 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001817 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001818 u8 byPktType;
1819 u8 *pbyTxBufferAddr;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001820 void *pvTxDataHd;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001821 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001822 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001823 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001824 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001825 u32 cbFrameSize;
1826 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1827 u32 uPadding = 0;
1828 u32 cbMICHDR = 0, uLength = 0;
1829 u32 dwMICKey0, dwMICKey1;
1830 u32 dwMIC_Priority;
1831 u32 *pdwMIC_L, *pdwMIC_R;
1832 u16 wTxBufSize;
1833 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001834 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001835 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001836 u32 wCurrentRate = RATE_1M;
1837 PUWLAN_80211HDR p80211Header;
1838 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001839 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001840 SKeyItem STempKey;
1841 PSKeyItem pTransmitKey = NULL;
1842 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1843 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001844 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001845
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001846 pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001847
1848 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1849 cbFrameBodySize = 0;
1850 }
1851 else {
1852 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1853 }
1854 p80211Header = (PUWLAN_80211HDR)skb->data;
1855
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001856 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001857
1858 if (NULL == pContext) {
1859 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1860 dev_kfree_skb_irq(skb);
1861 return ;
1862 }
1863
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001864 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001865 pTxBufHead = &pTX_Buffer->fifo_head;
1866 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1867 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001868
1869 if (pDevice->byBBType == BB_TYPE_11A) {
1870 wCurrentRate = RATE_6M;
1871 byPktType = PK_TYPE_11A;
1872 } else {
1873 wCurrentRate = RATE_1M;
1874 byPktType = PK_TYPE_11B;
1875 }
1876
1877 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1878 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1879 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1880 // to set power here.
1881 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1882 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1883 } else {
1884 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1885 }
1886
1887 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1888
1889 //Set packet type
1890 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1891 pTxBufHead->wFIFOCtl = 0;
1892 }
1893 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1894 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1895 }
1896 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1897 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1898 }
1899 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1900 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1901 }
1902
1903 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1904 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1905
Andres More22040bb2010-08-02 20:21:44 -03001906 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001907 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001908 if (pDevice->bEnableHostWEP) {
1909 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001910 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001911 }
Forest Bond92b96792009-06-13 07:38:31 -04001912 }
1913 else {
1914 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001915 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001916 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001917 }
Andres More4e9b5e22013-02-12 20:36:30 -05001918 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001919 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1920 };
1921
1922 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1923 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1924
1925 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1926 //Set Preamble type always long
1927 //pDevice->byPreambleType = PREAMBLE_LONG;
1928
1929 // probe-response don't retry
1930 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001931 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001932 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1933 //}
1934 }
1935
1936 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1937
1938 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001939 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001940 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1941 } else {
1942 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1943 }
1944
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001945 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001946 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1947
1948 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1949 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1950 }
1951
1952 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1953 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1954 }
1955
1956 if (cbExtSuppRate >0) {
1957 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1958 }
1959 }
1960
Forest Bond92b96792009-06-13 07:38:31 -04001961 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001962 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001963
1964 // Notes:
1965 // Although spec says MMPDU can be fragmented; In most case,
1966 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001967 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001968
Forest Bond92b96792009-06-13 07:38:31 -04001969 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1970 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1971 cbIVlen = 4;
1972 cbICVlen = 4;
1973 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1974 }
1975 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1976 cbIVlen = 8;//IV+ExtIV
1977 cbMIClen = 8;
1978 cbICVlen = 4;
1979 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1980 //We need to get seed here for filling TxKey entry.
1981 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1982 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1983 }
1984 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1985 cbIVlen = 8;//RSN Header
1986 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001987 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001988 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001989 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001990 }
1991 //MAC Header should be padding 0 to DW alignment.
1992 uPadding = 4 - (cbMacHdLen%4);
1993 uPadding %= 4;
1994 }
1995
1996 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1997
1998 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001999 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002000 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2001 }
2002 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2003
Forest Bond92b96792009-06-13 07:38:31 -04002004 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002005 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2006 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002007 sizeof(struct vnt_cts));
2008 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002009 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002010
2011 }
2012 else {//802.11a/b packet
Malcolm Priestley558becf2013-08-16 23:50:32 +01002013 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2014 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002015 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002016 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002017 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002018 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002019 &(p80211Header->sA3.abyAddr1[0]),
2020 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002021 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002022 &(p80211Header->sA3.abyAddr2[0]),
2023 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002024 //=========================
2025 // No Fragmentation
2026 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002027 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002028
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01002029 /* Fill FIFO,RrvTime,RTS,and CTS */
2030 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01002031 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01002032 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04002033
2034 //Fill DataHead
2035 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002036 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002037
Andres More1cac4a42013-03-18 20:33:50 -05002038 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002039
2040 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2041
Andres Moreb902fbf2013-02-25 20:32:51 -05002042 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2043 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2044 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002045
2046 // Copy the Packet into a tx Buffer
2047 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2048
2049 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002050 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002051 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2052
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002053 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002054 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2055 if (cbExtSuppRate != 0) {
2056 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2057 memcpy((pbyPayloadHead + cbFrameBodySize),
2058 pMgmt->abyCurrSuppRates,
2059 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2060 );
2061 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2062 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2063 pMgmt->abyCurrExtSuppRates,
2064 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2065 );
2066 }
2067 }
2068
2069 // Set wep
2070 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2071
2072 if (pDevice->bEnableHostWEP) {
2073 pTransmitKey = &STempKey;
2074 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2075 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2076 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2077 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2078 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2079 memcpy(pTransmitKey->abyKey,
2080 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2081 pTransmitKey->uKeyLength
2082 );
2083 }
2084
2085 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2086
Andres More52a7e642013-02-25 20:32:53 -05002087 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2088 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002089
2090 // DO Software Michael
2091 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002092 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002093 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002094 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002095 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2096 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002097
2098 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2099
2100 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2101
Andres More52a7e642013-02-25 20:32:53 -05002102 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2103 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002104
2105 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2106 MIC_vUnInit();
2107
Andres More4e9b5e22013-02-12 20:36:30 -05002108 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002109 *pdwMIC_L = 0;
2110 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002111 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002112 }
2113
2114 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2115 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002116 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2117 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002118
2119 }
2120
Andres Moreb902fbf2013-02-25 20:32:51 -05002121 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002122 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002123
2124 if (pDevice->bEnableHostWEP) {
2125 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2126 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2127 }
2128
2129 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002130 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002131 }
2132 }
2133
Andres More1cac4a42013-03-18 20:33:50 -05002134 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002135 pDevice->wSeqCounter++ ;
2136 if (pDevice->wSeqCounter > 0x0fff)
2137 pDevice->wSeqCounter = 0;
2138
Forest Bond92b96792009-06-13 07:38:31 -04002139 if (bIsPSPOLL) {
2140 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2141 // of FIFO control header.
2142 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2143 // in the same place of other packet's Duration-field).
2144 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002145 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2146 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2147 cpu_to_le16(p80211Header->sA2.wDurationID);
2148 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2149 cpu_to_le16(p80211Header->sA2.wDurationID);
2150 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002151 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2152 cpu_to_le16(p80211Header->sA2.wDurationID);
2153 }
Forest Bond92b96792009-06-13 07:38:31 -04002154 }
2155
Andres More3eaca0d2013-02-25 20:32:52 -05002156 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002157 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002158 pTX_Buffer->byType = 0x00;
2159
2160 pContext->pPacket = skb;
2161 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002162 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002163
Andres More1cac4a42013-03-18 20:33:50 -05002164 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002165 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2166 &pMACHeader->addr1[0], (u16)cbFrameSize,
2167 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002168 }
2169 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002170 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2171 &pMACHeader->addr3[0], (u16)cbFrameSize,
2172 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002173 }
2174 PIPEnsSendBulkOut(pDevice,pContext);
2175 return ;
2176
2177}
2178
Forest Bond92b96792009-06-13 07:38:31 -04002179//TYPE_AC0DMA data tx
2180/*
2181 * Description:
2182 * Tx packet via AC0DMA(DMA1)
2183 *
2184 * Parameters:
2185 * In:
2186 * pDevice - Pointer to the adapter
2187 * skb - Pointer to tx skb packet
2188 * Out:
2189 * void
2190 *
2191 * Return Value: NULL
2192 */
2193
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002194int nsDMA_tx_packet(struct vnt_private *pDevice,
2195 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002196{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002197 struct net_device_stats *pStats = &pDevice->stats;
2198 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002199 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002200 u32 BytesToWrite = 0, uHeaderLen = 0;
2201 u32 uNodeIndex = 0;
2202 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2203 u16 wAID;
2204 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002205 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002206 PSKeyItem pTransmitKey = NULL;
2207 SKeyItem STempKey;
2208 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002209 int bTKIP_UseGTK = false;
2210 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002211 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002212 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002213 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002214 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002215 u32 status;
2216 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002217 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002218
Forest Bond92b96792009-06-13 07:38:31 -04002219 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2220
2221 if (pDevice->uAssocCount == 0) {
2222 dev_kfree_skb_irq(skb);
2223 return 0;
2224 }
2225
Andres Moreb902fbf2013-02-25 20:32:51 -05002226 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002227 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002228 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002229 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2230
2231 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2232 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2233 // set tx map
2234 pMgmt->abyPSTxMap[0] |= byMask[0];
2235 return 0;
2236 }
Masanari Iida93184692012-08-13 21:21:50 +09002237 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002238
2239 if (pDevice->byBBType != BB_TYPE_11A)
2240 pDevice->wCurrentRate = RATE_2M;
2241 else
2242 pDevice->wCurrentRate = RATE_24M;
2243 // long preamble type
2244 pDevice->byPreambleType = PREAMBLE_SHORT;
2245
2246 }else {
2247
Andres Moreb902fbf2013-02-25 20:32:51 -05002248 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002249
2250 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2251
2252 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2253
2254 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2255 // set tx map
2256 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2257 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2258 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2259 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2260
2261 return 0;
2262 }
2263 // AP rate decided from node
2264 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2265 // tx preamble decided from node
2266
2267 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2268 pDevice->byPreambleType = pDevice->byShortPreamble;
2269
2270 }else {
2271 pDevice->byPreambleType = PREAMBLE_LONG;
2272 }
Andres More4e9b5e22013-02-12 20:36:30 -05002273 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002274 }
2275 }
2276
Andres Moree269fc22013-02-12 20:36:29 -05002277 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2279 dev_kfree_skb_irq(skb);
2280 return 0;
2281 }
2282 }
2283
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002284 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002285
2286 if (pContext == NULL) {
2287 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2288 dev_kfree_skb_irq(skb);
2289 return STATUS_RESOURCES;
2290 }
2291
Andres Moreceb8c5d2013-03-18 20:33:49 -05002292 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002293
2294//mike add:station mode check eapol-key challenge--->
2295{
Andres Moreb902fbf2013-02-25 20:32:51 -05002296 u8 Protocol_Version; //802.1x Authentication
2297 u8 Packet_Type; //802.1x Authentication
2298 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002299 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002300
Charles Clément21ec51f2010-05-18 10:08:14 -07002301 Protocol_Version = skb->data[ETH_HLEN];
2302 Packet_Type = skb->data[ETH_HLEN+1];
2303 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2304 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 -05002305 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002306 /* 802.1x OR eapol-key challenge frame transfer */
2307 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2308 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002309 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002310 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2311 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2312 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002313 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002314 PRINT_K("WPA ");
2315 }
2316 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002317 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002318 PRINT_K("WPA2(re-keying) ");
2319 }
2320 PRINT_K("Authentication completed!!\n");
2321 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002322 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002323 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002324 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002325 PRINT_K("WPA2 Authentication completed!!\n");
2326 }
2327 }
2328 }
2329}
2330//mike add:station mode check eapol-key challenge<---
2331
Andres More4e9b5e22013-02-12 20:36:30 -05002332 if (pDevice->bEncryptionEnable == true) {
2333 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002334 // get Transmit key
2335 do {
2336 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2337 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2338 pbyBSSID = pDevice->abyBSSID;
2339 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002340 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002341 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002342 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2343 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002344 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2345 break;
2346 }
2347 } else {
2348 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2349 break;
2350 }
2351 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002352 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2353 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2355 for (ii = 0; ii< 6; ii++)
2356 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2357 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2358
2359 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002360 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002361 break;
2362 }
2363 // get group key
2364 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002365 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002366 pTransmitKey = NULL;
2367 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2369 }
2370 else
2371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2372 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002373 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002374 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2375 }
Andres Moree269fc22013-02-12 20:36:29 -05002376 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002377 }
2378
2379 if (pDevice->bEnableHostWEP) {
2380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002381 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002382 pTransmitKey = &STempKey;
2383 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2384 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2385 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2386 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2387 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2388 memcpy(pTransmitKey->abyKey,
2389 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2390 pTransmitKey->uKeyLength
2391 );
2392 }
2393 }
2394
Andres Moreb902fbf2013-02-25 20:32:51 -05002395 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002396
2397 if (pDevice->bFixRate) {
2398 if (pDevice->byBBType == BB_TYPE_11B) {
2399 if (pDevice->uConnectionRate >= RATE_11M) {
2400 pDevice->wCurrentRate = RATE_11M;
2401 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002402 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002403 }
2404 } else {
2405 if ((pDevice->byBBType == BB_TYPE_11A) &&
2406 (pDevice->uConnectionRate <= RATE_6M)) {
2407 pDevice->wCurrentRate = RATE_6M;
2408 } else {
2409 if (pDevice->uConnectionRate >= RATE_54M)
2410 pDevice->wCurrentRate = RATE_54M;
2411 else
Andres More3eaca0d2013-02-25 20:32:52 -05002412 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002413 }
2414 }
2415 }
2416 else {
2417 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2418 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002419 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002420 // Multicast use highest data rate
2421 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2422 // preamble type
2423 pDevice->byPreambleType = pDevice->byShortPreamble;
2424 }
2425 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002426 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002427 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2428 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2429 pDevice->byPreambleType = pDevice->byShortPreamble;
2430
2431 }
2432 else {
2433 pDevice->byPreambleType = PREAMBLE_LONG;
2434 }
2435 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2436 }
2437 else {
2438 if (pDevice->byBBType != BB_TYPE_11A)
2439 pDevice->wCurrentRate = RATE_2M;
2440 else
2441 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2442 // abyCurrExtSuppRates[]
2443 pDevice->byPreambleType = PREAMBLE_SHORT;
2444 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2445 }
2446 }
2447 }
2448 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2449 // Infra STA rate decided from AP Node, index = 0
2450 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2451 }
2452 }
2453
Andres Moreceb8c5d2013-03-18 20:33:49 -05002454 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002455 if (pDevice->byBBType != BB_TYPE_11A) {
2456 pDevice->wCurrentRate = RATE_1M;
2457 pDevice->byACKRate = RATE_1M;
2458 pDevice->byTopCCKBasicRate = RATE_1M;
2459 pDevice->byTopOFDMBasicRate = RATE_6M;
2460 } else {
2461 pDevice->wCurrentRate = RATE_6M;
2462 pDevice->byACKRate = RATE_6M;
2463 pDevice->byTopCCKBasicRate = RATE_1M;
2464 pDevice->byTopOFDMBasicRate = RATE_6M;
2465 }
2466 }
Forest Bond92b96792009-06-13 07:38:31 -04002467
Andres More0cbd8d92010-05-06 20:34:29 -03002468 DBG_PRT(MSG_LEVEL_DEBUG,
2469 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2470 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002471
2472 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002473 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002474 }
2475
2476 if (pDevice->wCurrentRate <= RATE_11M) {
2477 byPktType = PK_TYPE_11B;
2478 }
2479
Andres More4e9b5e22013-02-12 20:36:30 -05002480 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002481 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2482 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002483 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002484 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002485 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2486 if (pTransmitKey == NULL) {
2487 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2488 }
2489 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002490 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002491 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2492 }
2493 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002494 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2495 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002496 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002497 }
2498 }
2499 }
2500
Forest Bond92b96792009-06-13 07:38:31 -04002501 if (pDevice->bEnableHostWEP) {
2502 if ((uNodeIndex != 0) &&
2503 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002504 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2505 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002506 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002507 }
2508 }
2509 }
2510 else {
2511
Forest Bond92b96792009-06-13 07:38:31 -04002512 if (pTransmitKey == NULL) {
2513 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002514 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002515 dev_kfree_skb_irq(skb);
2516 pStats->tx_dropped++;
2517 return STATUS_FAILURE;
2518 }
Forest Bond92b96792009-06-13 07:38:31 -04002519 }
2520 }
2521
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002522 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2523
Forest Bond92b96792009-06-13 07:38:31 -04002524 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002525 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002526 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002527 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002528 pDevice->wCurrentRate,
2529 &uHeaderLen, &BytesToWrite
2530 );
2531
Andres Moree269fc22013-02-12 20:36:29 -05002532 if (fConvertedPacket == false) {
2533 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002534 dev_kfree_skb_irq(skb);
2535 return STATUS_FAILURE;
2536 }
2537
Andres More4e9b5e22013-02-12 20:36:30 -05002538 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002539 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002540 bScheduleCommand((void *) pDevice,
2541 WLAN_CMD_MAC_DISPOWERSAVING,
2542 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002543 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002544 }
2545 }
2546
Andres Moreb902fbf2013-02-25 20:32:51 -05002547 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002548 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002549
2550 pContext->pPacket = skb;
2551 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002552 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002553
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002554 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2555 &pContext->sEthHeader.h_dest[0],
2556 (u16)(BytesToWrite-uHeaderLen),
2557 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002558
2559 status = PIPEnsSendBulkOut(pDevice,pContext);
2560
Andres More4e9b5e22013-02-12 20:36:30 -05002561 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002562 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002563
Andres Moreb902fbf2013-02-25 20:32:51 -05002564 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002565 }
2566
2567 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002568 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002569 dev_kfree_skb_irq(skb);
2570 return STATUS_FAILURE;
2571 }
2572 else
2573 return 0;
2574
2575}
2576
Forest Bond92b96792009-06-13 07:38:31 -04002577/*
2578 * Description:
2579 * Relay packet send (AC1DMA) from rx dpc.
2580 *
2581 * Parameters:
2582 * In:
2583 * pDevice - Pointer to the adapter
2584 * pPacket - Pointer to rx packet
2585 * cbPacketSize - rx ethernet frame size
2586 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002587 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002588 *
Andres More4e9b5e22013-02-12 20:36:30 -05002589 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002590 */
2591
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002592int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2593 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002594{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002595 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002596 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002597 u32 BytesToWrite = 0, uHeaderLen = 0;
2598 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002599 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002600 SKeyItem STempKey;
2601 PSKeyItem pTransmitKey = NULL;
2602 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002603 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002604 u8 byPktTyp;
2605 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002606 u32 status;
2607 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002608
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002609 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002610
2611 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002612 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002613 }
2614
Andres Moreceb8c5d2013-03-18 20:33:49 -05002615 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002616
Andres More4e9b5e22013-02-12 20:36:30 -05002617 if (pDevice->bEncryptionEnable == true) {
2618 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002619 // get group key
2620 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002621 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002622 pTransmitKey = NULL;
2623 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2624 } else {
2625 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2626 }
2627 }
2628
2629 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002630 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002631 pTransmitKey = &STempKey;
2632 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2633 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2634 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2635 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2636 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2637 memcpy(pTransmitKey->abyKey,
2638 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2639 pTransmitKey->uKeyLength
2640 );
2641 }
2642 }
2643
2644 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002645 pContext->bBoolInUse = false;
2646 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002647 }
2648
Andres Moreb902fbf2013-02-25 20:32:51 -05002649 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002650
2651 if (pDevice->bFixRate) {
2652 if (pDevice->byBBType == BB_TYPE_11B) {
2653 if (pDevice->uConnectionRate >= RATE_11M) {
2654 pDevice->wCurrentRate = RATE_11M;
2655 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002656 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002657 }
2658 } else {
2659 if ((pDevice->byBBType == BB_TYPE_11A) &&
2660 (pDevice->uConnectionRate <= RATE_6M)) {
2661 pDevice->wCurrentRate = RATE_6M;
2662 } else {
2663 if (pDevice->uConnectionRate >= RATE_54M)
2664 pDevice->wCurrentRate = RATE_54M;
2665 else
Andres More3eaca0d2013-02-25 20:32:52 -05002666 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002667 }
2668 }
2669 }
2670 else {
2671 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2672 }
2673
Forest Bond92b96792009-06-13 07:38:31 -04002674 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002675 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002676 }
2677
2678 if (pDevice->wCurrentRate <= RATE_11M)
2679 byPktType = PK_TYPE_11B;
2680
Andres Moreabad19d2010-07-12 16:28:32 -03002681 BytesToWrite = uDataLen + ETH_FCS_LEN;
2682
Forest Bond92b96792009-06-13 07:38:31 -04002683 // Convert the packet to an usb frame and copy into our buffer
2684 // and send the irp.
2685
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002686 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2687
Forest Bond92b96792009-06-13 07:38:31 -04002688 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002689 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002690 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2691 pbySkbData, pTransmitKey, uNodeIndex,
2692 pDevice->wCurrentRate,
2693 &uHeaderLen, &BytesToWrite
2694 );
2695
Andres Moree269fc22013-02-12 20:36:29 -05002696 if (fConvertedPacket == false) {
2697 pContext->bBoolInUse = false;
2698 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002699 }
2700
Andres Moreb902fbf2013-02-25 20:32:51 -05002701 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002702 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002703
2704 pContext->pPacket = NULL;
2705 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002706 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002707
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002708 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2709 &pContext->sEthHeader.h_dest[0],
2710 (u16)(BytesToWrite - uHeaderLen),
2711 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002712
2713 status = PIPEnsSendBulkOut(pDevice,pContext);
2714
Andres More4e9b5e22013-02-12 20:36:30 -05002715 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002716}
2717