blob: c80a809d4a41099bfd2447cf9ceabf758e21257d [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 Priestley9e38a5c2013-09-26 18:47:25 +0100103 void *rts_cts, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
104 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 Priestley9e38a5c2013-09-26 18:47:25 +0100844 void *rts_cts, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
845 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 Priestley5fb8e412013-08-27 12:07:58 +0100848 union vnt_tx_data_head *head = rts_cts;
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 Priestley351c7dc2013-08-27 12:02:54 +0100886 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100887 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100888 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400889 }
890 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400891 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100892 struct vnt_rrv_time_cts *pBuf = &tx_buffer->tx_head.tx_cts.cts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100893
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100894 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
895 cbFrameSize, wCurrentRate, bNeedACK);
896 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
897 PK_TYPE_11B, cbFrameSize,
898 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100899 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
900 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100901 /* Fill CTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100902 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, head,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100903 cbFrameSize, bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400904 }
905 }
906 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100907 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400908 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100909 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100910
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100911 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
912 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100913 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
914 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100915 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100916 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100917 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100918 } else {
Forest Bond92b96792009-06-13 07:38:31 -0400919 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100920 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100921
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100922 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
923 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400924 }
925 }
926 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100927 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400928 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100929 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100930
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100931 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
932 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100933 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
934 cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100935 /* Fill RTS */
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100936 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100937 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400938 }
939 else { //RTS_needless, non PCF mode
940 //Fill RsvTime
Malcolm Priestley56c60e42013-09-26 18:49:44 +0100941 struct vnt_rrv_time_ab *pBuf = &tx_buffer->tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100942
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100943 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
944 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400945 }
946 }
947 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
948}
949/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500950 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500951 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300952 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400953*/
954
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000955static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100956 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100957 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
958 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
959 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400960{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100961 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000962 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
963 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000964 u32 cb802_1_H_len;
965 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
966 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100967 int bNeedACK;
968 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000969 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
970 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
971 u8 abySNAP_Bridgetunnel[ETH_ALEN]
972 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
973 u32 uDuration;
974 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100975 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100976 void *rts_cts = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000977 void *pvTxDataHd;
978 u8 byFBOption = AUTO_FB_NONE, byFragType;
979 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100980 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000981 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500982 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100983
984 pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400985
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000986 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500987 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
988 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000989 }
Forest Bond92b96792009-06-13 07:38:31 -0400990
Forest Bond92b96792009-06-13 07:38:31 -0400991 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -0500992 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -0400993 if (pDevice->dwDiagRefCount == 0) {
994 cb802_1_H_len = 8;
995 } else {
996 cb802_1_H_len = 2;
997 }
998 } else {
999 cb802_1_H_len = 0;
1000 }
1001
Charles Clément21ec51f2010-05-18 10:08:14 -07001002 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001003
1004 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001005 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001006
1007 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001008 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001009 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1010 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001011 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1012 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001013 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001014 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001015 pTxBufHead->wFIFOCtl =
1016 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1017 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001018 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001019 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1020 }
Forest Bond92b96792009-06-13 07:38:31 -04001021 }
1022 else {
1023 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001024 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001025 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1026 }
1027 } //if (pDevice->dwDiagRefCount != 0) {
1028
1029 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1030
1031 //Set FIFOCTL_LHEAD
1032 if (pDevice->bLongHeader)
1033 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1034
Forest Bond92b96792009-06-13 07:38:31 -04001035 //Set FRAGCTL_MACHDCNT
1036 if (pDevice->bLongHeader) {
1037 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1038 } else {
1039 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1040 }
Andres More3eaca0d2013-02-25 20:32:52 -05001041 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001042
1043 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001044 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001045 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1046 }
1047
1048 //Set Auto Fallback Ctl
1049 if (wCurrentRate >= RATE_18M) {
1050 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1051 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1052 byFBOption = AUTO_FB_0;
1053 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1054 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1055 byFBOption = AUTO_FB_1;
1056 }
1057 }
1058
Andres More4e9b5e22013-02-12 20:36:30 -05001059 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001060 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1061 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1062 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1063 }
1064 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1065 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1066 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1067 }
1068 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1069 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1070 }
1071 }
1072 }
1073
Forest Bond92b96792009-06-13 07:38:31 -04001074 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1075 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1076 cbIVlen = 4;
1077 cbICVlen = 4;
1078 }
1079 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1080 cbIVlen = 8;//IV+ExtIV
1081 cbMIClen = 8;
1082 cbICVlen = 4;
1083 }
1084 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1085 cbIVlen = 8;//RSN Header
1086 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001087 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001088 }
Andres Moree269fc22013-02-12 20:36:29 -05001089 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001090 //MAC Header should be padding 0 to DW alignment.
1091 uPadding = 4 - (cbMACHdLen%4);
1092 uPadding %= 4;
1093 }
1094 }
1095
1096 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1097
Andres Moree269fc22013-02-12 20:36:29 -05001098 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1099 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001100 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001101 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001102 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1103 }
1104
Andres Moreb902fbf2013-02-25 20:32:51 -05001105 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001106 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1107
Forest Bond92b96792009-06-13 07:38:31 -04001108 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1109 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001110 if (bRTS == true) {//RTS_need
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001111 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001112 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001113 rts_cts = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001114 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001115 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1116 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1117 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001118 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001119 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001120 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001121 }
1122 else { //RTS_needless
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001123 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001124 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001125 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001126 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001127 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1128 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1129 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001130 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1131 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001132 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001133 }
1134 } else {
1135 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001136 if (bRTS == true) {//RTS_need
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001137 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001138 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001139 rts_cts = (struct vnt_rts_g_fb *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001140 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001141 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1142 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1143 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001144 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1145 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001146 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001147 }
Andres Moree269fc22013-02-12 20:36:29 -05001148 else if (bRTS == false) { //RTS_needless
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001149 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001150 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001151 rts_cts = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001152 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001153 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001154 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1155 cbMICHDR + sizeof(struct vnt_cts_fb));
1156 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001157 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001158 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001159 }
1160 } // Auto Fall Back
1161 }
1162 else {//802.11a/b packet
1163 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001164 if (bRTS == true) {//RTS_need
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001165 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001166 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001167 rts_cts = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001168 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001169 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1170 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001171 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001172 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1173 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001174 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001175 }
Andres Moree269fc22013-02-12 20:36:29 -05001176 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001177 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001178 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley558becf2013-08-16 23:50:32 +01001179 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1180 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001181 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001182 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001183 }
1184 } else {
1185 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001186 if (bRTS == true) {//RTS_need
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001187 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001188 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001189 rts_cts = (struct vnt_rts_a_fb *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001190 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001191 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1192 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001193 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001194 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1195 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001196 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001197 }
Andres Moree269fc22013-02-12 20:36:29 -05001198 else if (bRTS == false) { //RTS_needless
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001199 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001200 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001201 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1202 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001203 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001204 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001205 }
1206 } // Auto Fall Back
1207 }
1208
Andres Moreb902fbf2013-02-25 20:32:51 -05001209 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1210 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1211 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001212
Forest Bond92b96792009-06-13 07:38:31 -04001213 //=========================
1214 // No Fragmentation
1215 //=========================
1216 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1217 byFragType = FRAGCTL_NONFRAG;
1218 //uDMAIdx = TYPE_AC0DMA;
1219 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1220
Forest Bond92b96792009-06-13 07:38:31 -04001221 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001222 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001223 tx_buffer, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001224 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Forest Bond92b96792009-06-13 07:38:31 -04001225 //Fill DataHead
1226 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001227 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001228 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001229 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001230 byFragType, uDMAIdx, 0);
1231
Andres More4e9b5e22013-02-12 20:36:30 -05001232 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001233 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001234 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001235 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001236
1237 if (pDevice->bEnableHostWEP) {
1238 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1239 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1240 }
1241 }
1242
1243 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001244 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001245 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001246 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1247 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001248 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001249 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001250 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001251 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001252 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001253 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001254 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001255 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001256 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001257
1258 }
1259
1260 }
1261
Forest Bond92b96792009-06-13 07:38:31 -04001262 if (pPacket != NULL) {
1263 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001264 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001265 (pPacket + ETH_HLEN),
1266 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001267 );
1268
1269 } else {
1270 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001271 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001272 }
1273
Andres More4e9b5e22013-02-12 20:36:30 -05001274 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001275
1276 ///////////////////////////////////////////////////////////////////
1277
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001278 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1279 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1280 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1281 }
Forest Bond92b96792009-06-13 07:38:31 -04001282 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001283 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1284 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001285 }
1286 else {
Andres More52a7e642013-02-25 20:32:53 -05001287 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1288 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001289 }
1290 // DO Software Michael
1291 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001292 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001293 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001294 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001295 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1296 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001297
1298 ///////////////////////////////////////////////////////////////////
1299
1300 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1301 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001302 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001303 //}
1304 //DBG_PRN_GRP12(("\n\n\n"));
1305
1306 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1307
Andres More52a7e642013-02-25 20:32:53 -05001308 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1309 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001310
1311 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1312 MIC_vUnInit();
1313
Andres More4e9b5e22013-02-12 20:36:30 -05001314 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001315 *pdwMIC_L = 0;
1316 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001317 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001318 }
1319 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1320 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1321 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1322 }
1323
Andres More4e9b5e22013-02-12 20:36:30 -05001324 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001325
Andres More3eaca0d2013-02-25 20:32:52 -05001326 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001327
Andres More4e9b5e22013-02-12 20:36:30 -05001328 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1329 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1330 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001331 cbFrameSize -= cbICVlen;
1332 }
1333
Forest Bond92b96792009-06-13 07:38:31 -04001334 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001335
1336 *pcbHeaderLen = cbHeaderLength;
1337 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1338
Forest Bond92b96792009-06-13 07:38:31 -04001339 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001340 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001341
Andres More4e9b5e22013-02-12 20:36:30 -05001342 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001343
1344}
1345
Forest Bond92b96792009-06-13 07:38:31 -04001346/*+
1347 *
1348 * Description:
1349 * Translate 802.3 to 802.11 header
1350 *
1351 * Parameters:
1352 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001353 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001354 * dwTxBufferAddr - Transmit Buffer
1355 * pPacket - Packet from upper layer
1356 * cbPacketSize - Transmit Data Length
1357 * Out:
1358 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1359 * pcbAppendPayload - size of append payload for 802.1H translation
1360 *
1361 * Return Value: none
1362 *
1363-*/
1364
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001365static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001366 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001367 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001368{
Andres More1cac4a42013-03-18 20:33:50 -05001369 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001370
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001371 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001372
1373 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001374 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001375 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001376 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001377 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1378 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001379 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001380 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001381 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001382 } else {
1383 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001384 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001385 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001386 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001387 memcpy(&(pMACHeader->addr2[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 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001391 &(pDevice->abyBSSID[0]),
1392 ETH_ALEN);
1393 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001394 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001395 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001396 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001397 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001398 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001399 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001400 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001401 &(pDevice->abyBSSID[0]),
1402 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001403 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001404 }
1405 }
1406
1407 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001408 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001409
Andres More1cac4a42013-03-18 20:33:50 -05001410 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001411
1412 if (pDevice->bLongHeader) {
1413 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001414 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001415 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001416 }
Andres More1cac4a42013-03-18 20:33:50 -05001417 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001418
1419 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001420 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001421
1422 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1423 pDevice->wSeqCounter++;
1424 if (pDevice->wSeqCounter > 0x0fff)
1425 pDevice->wSeqCounter = 0;
1426 }
1427
1428 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001429 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001430 }
1431}
1432
Forest Bond92b96792009-06-13 07:38:31 -04001433/*+
1434 *
1435 * Description:
1436 * Request instructs a MAC to transmit a 802.11 management packet through
1437 * the adapter onto the medium.
1438 *
1439 * Parameters:
1440 * In:
1441 * hDeviceContext - Pointer to the adapter
1442 * pPacket - A pointer to a descriptor for the packet to transmit
1443 * Out:
1444 * none
1445 *
Andres Moree269fc22013-02-12 20:36:29 -05001446 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001447 *
1448-*/
1449
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001450CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1451 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001452{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001453 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001454 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001455 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001456 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001457 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001458 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001459 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001460 void *rts_cts = NULL;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001461 void *pvTxDataHd, *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001462 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001463 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001464 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1465 u32 uPadding = 0;
1466 u16 wTxBufSize;
1467 u32 cbMacHdLen;
1468 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001469
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001470 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001471
1472 if (NULL == pContext) {
1473 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1474 return CMD_STATUS_RESOURCES;
1475 }
1476
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001477 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001478 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001479 pTxBufHead = &pTX_Buffer->fifo_head;
1480 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1481 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001482
1483 if (pDevice->byBBType == BB_TYPE_11A) {
1484 wCurrentRate = RATE_6M;
1485 byPktType = PK_TYPE_11A;
1486 } else {
1487 wCurrentRate = RATE_1M;
1488 byPktType = PK_TYPE_11B;
1489 }
1490
1491 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1492 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1493 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1494 // to set power here.
1495 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1496 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1497 } else {
1498 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1499 }
1500 pDevice->wCurrentRate = wCurrentRate;
1501
Forest Bond92b96792009-06-13 07:38:31 -04001502 //Set packet type
1503 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1504 pTxBufHead->wFIFOCtl = 0;
1505 }
1506 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1507 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1508 }
1509 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1510 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1511 }
1512 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1513 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1514 }
1515
1516 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1517 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1518
Andres More22040bb2010-08-02 20:21:44 -03001519 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001520 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001521 }
1522 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001523 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001524 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1525 };
1526
1527 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1528 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1529
1530 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1531 //Set Preamble type always long
1532 //pDevice->byPreambleType = PREAMBLE_LONG;
1533 // probe-response don't retry
1534 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001535 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001536 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1537 //}
1538 }
1539
1540 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1541
1542 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001543 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001544 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1545 } else {
1546 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1547 }
1548
1549 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001550 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001551
1552 // Notes:
1553 // Although spec says MMPDU can be fragmented; In most case,
1554 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001555 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001556
1557 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1558 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1559 cbIVlen = 4;
1560 cbICVlen = 4;
1561 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1562 }
1563 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1564 cbIVlen = 8;//IV+ExtIV
1565 cbMIClen = 8;
1566 cbICVlen = 4;
1567 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1568 //We need to get seed here for filling TxKey entry.
1569 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1570 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1571 }
1572 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1573 cbIVlen = 8;//RSN Header
1574 cbICVlen = 8;//MIC
1575 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001576 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001577 }
1578 //MAC Header should be padding 0 to DW alignment.
1579 uPadding = 4 - (cbMacHdLen%4);
1580 uPadding %= 4;
1581 }
1582
1583 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1584
1585 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001586 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001587 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1588 }
1589 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1590
1591 //Set RrvTime/RTS/CTS Buffer
1592 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Forest Bond92b96792009-06-13 07:38:31 -04001593 pMICHDR = NULL;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001594 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001595 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001596 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001597 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1598 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001599 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001600 }
1601 else { // 802.11a/b packet
Forest Bond92b96792009-06-13 07:38:31 -04001602 pMICHDR = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001603 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1604 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001605 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001606 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001607 }
1608
Andres Moreceb8c5d2013-03-18 20:33:49 -05001609 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001610 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1611 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001612 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001613 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1614 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001615 //=========================
1616 // No Fragmentation
1617 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001618 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001619
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001620 /* Fill FIFO,RrvTime,RTS,and CTS */
1621 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001622 pTX_Buffer, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001623 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001624
1625 //Fill DataHead
1626 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001627 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001628
Andres More1cac4a42013-03-18 20:33:50 -05001629 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001630
1631 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1632
1633 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001634 u8 * pbyIVHead;
1635 u8 * pbyPayloadHead;
1636 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001637 PSKeyItem pTransmitKey = NULL;
1638
Andres Moreb902fbf2013-02-25 20:32:51 -05001639 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1640 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001641 do {
1642 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001643 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001644 pbyBSSID = pDevice->abyBSSID;
1645 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001646 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001647 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001648 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001649 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1650 break;
1651 }
1652 } else {
1653 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1654 break;
1655 }
1656 }
1657 // get group key
1658 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001659 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001660 pTransmitKey = NULL;
1661 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1662 } else {
1663 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1664 }
Andres Moree269fc22013-02-12 20:36:29 -05001665 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001666 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001667 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001668 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001669
Jim Lieb3e362592009-08-12 14:54:11 -07001670 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001671 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001672 cbFrameBodySize);
1673 }
1674 else {
1675 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001676 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001677 }
1678
Andres More1cac4a42013-03-18 20:33:50 -05001679 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001680 pDevice->wSeqCounter++ ;
1681 if (pDevice->wSeqCounter > 0x0fff)
1682 pDevice->wSeqCounter = 0;
1683
1684 if (bIsPSPOLL) {
1685 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001686 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001687 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1688 // in the same place of other packet's Duration-field).
1689 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001690 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1691 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1692 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1693 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1694 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1695 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001696 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1697 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1698 }
Forest Bond92b96792009-06-13 07:38:31 -04001699 }
1700
Andres More3eaca0d2013-02-25 20:32:52 -05001701 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001702 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001703 pTX_Buffer->byType = 0x00;
1704
1705 pContext->pPacket = NULL;
1706 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001707 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001708
Andres More1cac4a42013-03-18 20:33:50 -05001709 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001710 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1711 &pMACHeader->addr1[0], (u16)cbFrameSize,
1712 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001713 }
1714 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001715 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1716 &pMACHeader->addr3[0], (u16)cbFrameSize,
1717 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001718 }
1719
1720 PIPEnsSendBulkOut(pDevice,pContext);
1721 return CMD_STATUS_PENDING;
1722}
1723
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001724CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1725 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001726{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001727 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001728 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1729 u32 cbHeaderSize = 0;
1730 u16 wTxBufSize = sizeof(STxShortBufHead);
1731 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001732 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001733 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001734 u16 wCurrentRate;
1735 u32 cbFrameBodySize;
1736 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001737 u8 *pbyTxBufferAddr;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001738 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001739 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001740
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001741 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001742 if (NULL == pContext) {
1743 status = CMD_STATUS_RESOURCES;
1744 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1745 return status ;
1746 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001747
1748 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001749 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001750
1751 cbFrameBodySize = pPacket->cbPayloadLen;
1752
1753 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1754 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001755
1756 if (pDevice->byBBType == BB_TYPE_11A) {
1757 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001758 pTxDataHead = (struct vnt_tx_datahead_ab *)
1759 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001760 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001761 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1762 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001763 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001764 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001765 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001766 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001767 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001768 } else {
1769 wCurrentRate = RATE_1M;
1770 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001771 pTxDataHead = (struct vnt_tx_datahead_ab *)
1772 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001773 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001774 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1775 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001776 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001777 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001778 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001779 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001780 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001781 }
1782
1783 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001784 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001785 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001786
Andres More1cac4a42013-03-18 20:33:50 -05001787 pMACHeader->duration_id = 0;
1788 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001789 pDevice->wSeqCounter++ ;
1790 if (pDevice->wSeqCounter > 0x0fff)
1791 pDevice->wSeqCounter = 0;
1792
1793 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1794
Andres More3eaca0d2013-02-25 20:32:52 -05001795 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001796 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001797 pTX_Buffer->byType = 0x01;
1798
1799 pContext->pPacket = NULL;
1800 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001801 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001802
1803 PIPEnsSendBulkOut(pDevice,pContext);
1804 return CMD_STATUS_PENDING;
1805
1806}
1807
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001808void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1809{
1810 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001811 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001812 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001813 u8 byPktType;
1814 u8 *pbyTxBufferAddr;
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001815 void *rts_cts = NULL;
1816 void *pvTxDataHd;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001817 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001818 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001819 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001820 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001821 u32 cbFrameSize;
1822 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1823 u32 uPadding = 0;
1824 u32 cbMICHDR = 0, uLength = 0;
1825 u32 dwMICKey0, dwMICKey1;
1826 u32 dwMIC_Priority;
1827 u32 *pdwMIC_L, *pdwMIC_R;
1828 u16 wTxBufSize;
1829 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001830 struct ethhdr sEthHeader;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001831 void *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001832 u32 wCurrentRate = RATE_1M;
1833 PUWLAN_80211HDR p80211Header;
1834 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001835 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001836 SKeyItem STempKey;
1837 PSKeyItem pTransmitKey = NULL;
1838 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1839 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001840 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001841
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001842 pMICHDR = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001843
1844 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1845 cbFrameBodySize = 0;
1846 }
1847 else {
1848 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1849 }
1850 p80211Header = (PUWLAN_80211HDR)skb->data;
1851
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001852 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001853
1854 if (NULL == pContext) {
1855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1856 dev_kfree_skb_irq(skb);
1857 return ;
1858 }
1859
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001860 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001861 pTxBufHead = &pTX_Buffer->fifo_head;
1862 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1863 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001864
1865 if (pDevice->byBBType == BB_TYPE_11A) {
1866 wCurrentRate = RATE_6M;
1867 byPktType = PK_TYPE_11A;
1868 } else {
1869 wCurrentRate = RATE_1M;
1870 byPktType = PK_TYPE_11B;
1871 }
1872
1873 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1874 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1875 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1876 // to set power here.
1877 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1878 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1879 } else {
1880 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1881 }
1882
1883 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1884
1885 //Set packet type
1886 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1887 pTxBufHead->wFIFOCtl = 0;
1888 }
1889 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1890 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1891 }
1892 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1893 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1894 }
1895 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1896 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1897 }
1898
1899 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1900 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1901
Andres More22040bb2010-08-02 20:21:44 -03001902 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001903 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001904 if (pDevice->bEnableHostWEP) {
1905 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001906 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001907 }
Forest Bond92b96792009-06-13 07:38:31 -04001908 }
1909 else {
1910 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001911 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001912 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001913 }
Andres More4e9b5e22013-02-12 20:36:30 -05001914 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001915 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1916 };
1917
1918 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1919 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1920
1921 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1922 //Set Preamble type always long
1923 //pDevice->byPreambleType = PREAMBLE_LONG;
1924
1925 // probe-response don't retry
1926 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001927 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001928 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1929 //}
1930 }
1931
1932 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1933
1934 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001935 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001936 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1937 } else {
1938 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1939 }
1940
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001941 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001942 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1943
1944 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1945 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1946 }
1947
1948 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1949 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1950 }
1951
1952 if (cbExtSuppRate >0) {
1953 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1954 }
1955 }
1956
Forest Bond92b96792009-06-13 07:38:31 -04001957 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001958 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001959
1960 // Notes:
1961 // Although spec says MMPDU can be fragmented; In most case,
1962 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001963 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001964
Forest Bond92b96792009-06-13 07:38:31 -04001965 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1966 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1967 cbIVlen = 4;
1968 cbICVlen = 4;
1969 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1970 }
1971 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1972 cbIVlen = 8;//IV+ExtIV
1973 cbMIClen = 8;
1974 cbICVlen = 4;
1975 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1976 //We need to get seed here for filling TxKey entry.
1977 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1978 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1979 }
1980 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1981 cbIVlen = 8;//RSN Header
1982 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001983 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001984 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001985 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001986 }
1987 //MAC Header should be padding 0 to DW alignment.
1988 uPadding = 4 - (cbMacHdLen%4);
1989 uPadding %= 4;
1990 }
1991
1992 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1993
1994 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001995 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001996 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1997 }
1998 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1999
Forest Bond92b96792009-06-13 07:38:31 -04002000 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002001 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002002 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01002003 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002004 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
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 Priestley5a5d6a82013-08-23 14:33:55 +01002013 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002014 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley558becf2013-08-16 23:50:32 +01002015 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2016 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002017 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002018 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002019 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002020 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002021 &(p80211Header->sA3.abyAddr1[0]),
2022 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002023 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002024 &(p80211Header->sA3.abyAddr2[0]),
2025 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002026 //=========================
2027 // No Fragmentation
2028 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002029 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002030
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01002031 /* Fill FIFO,RrvTime,RTS,and CTS */
2032 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01002033 pTX_Buffer, rts_cts,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01002034 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04002035
2036 //Fill DataHead
2037 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002038 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002039
Andres More1cac4a42013-03-18 20:33:50 -05002040 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002041
2042 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2043
Andres Moreb902fbf2013-02-25 20:32:51 -05002044 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2045 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2046 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002047
2048 // Copy the Packet into a tx Buffer
2049 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2050
2051 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002052 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002053 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2054
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002055 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002056 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2057 if (cbExtSuppRate != 0) {
2058 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2059 memcpy((pbyPayloadHead + cbFrameBodySize),
2060 pMgmt->abyCurrSuppRates,
2061 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2062 );
2063 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2064 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2065 pMgmt->abyCurrExtSuppRates,
2066 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2067 );
2068 }
2069 }
2070
2071 // Set wep
2072 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2073
2074 if (pDevice->bEnableHostWEP) {
2075 pTransmitKey = &STempKey;
2076 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2077 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2078 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2079 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2080 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2081 memcpy(pTransmitKey->abyKey,
2082 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2083 pTransmitKey->uKeyLength
2084 );
2085 }
2086
2087 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2088
Andres More52a7e642013-02-25 20:32:53 -05002089 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2090 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002091
2092 // DO Software Michael
2093 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002094 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002095 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002096 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002097 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2098 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002099
2100 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2101
2102 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2103
Andres More52a7e642013-02-25 20:32:53 -05002104 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2105 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002106
2107 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2108 MIC_vUnInit();
2109
Andres More4e9b5e22013-02-12 20:36:30 -05002110 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002111 *pdwMIC_L = 0;
2112 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002113 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002114 }
2115
2116 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2117 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2119 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002120
2121 }
2122
Andres Moreb902fbf2013-02-25 20:32:51 -05002123 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002124 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002125
2126 if (pDevice->bEnableHostWEP) {
2127 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2128 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2129 }
2130
2131 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002132 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002133 }
2134 }
2135
Andres More1cac4a42013-03-18 20:33:50 -05002136 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002137 pDevice->wSeqCounter++ ;
2138 if (pDevice->wSeqCounter > 0x0fff)
2139 pDevice->wSeqCounter = 0;
2140
Forest Bond92b96792009-06-13 07:38:31 -04002141 if (bIsPSPOLL) {
2142 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2143 // of FIFO control header.
2144 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2145 // in the same place of other packet's Duration-field).
2146 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002147 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2148 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2149 cpu_to_le16(p80211Header->sA2.wDurationID);
2150 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2151 cpu_to_le16(p80211Header->sA2.wDurationID);
2152 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002153 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2154 cpu_to_le16(p80211Header->sA2.wDurationID);
2155 }
Forest Bond92b96792009-06-13 07:38:31 -04002156 }
2157
Andres More3eaca0d2013-02-25 20:32:52 -05002158 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002159 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002160 pTX_Buffer->byType = 0x00;
2161
2162 pContext->pPacket = skb;
2163 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002164 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002165
Andres More1cac4a42013-03-18 20:33:50 -05002166 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002167 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2168 &pMACHeader->addr1[0], (u16)cbFrameSize,
2169 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002170 }
2171 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002172 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2173 &pMACHeader->addr3[0], (u16)cbFrameSize,
2174 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002175 }
2176 PIPEnsSendBulkOut(pDevice,pContext);
2177 return ;
2178
2179}
2180
Forest Bond92b96792009-06-13 07:38:31 -04002181//TYPE_AC0DMA data tx
2182/*
2183 * Description:
2184 * Tx packet via AC0DMA(DMA1)
2185 *
2186 * Parameters:
2187 * In:
2188 * pDevice - Pointer to the adapter
2189 * skb - Pointer to tx skb packet
2190 * Out:
2191 * void
2192 *
2193 * Return Value: NULL
2194 */
2195
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002196int nsDMA_tx_packet(struct vnt_private *pDevice,
2197 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002198{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002199 struct net_device_stats *pStats = &pDevice->stats;
2200 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002201 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002202 u32 BytesToWrite = 0, uHeaderLen = 0;
2203 u32 uNodeIndex = 0;
2204 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2205 u16 wAID;
2206 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002207 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002208 PSKeyItem pTransmitKey = NULL;
2209 SKeyItem STempKey;
2210 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002211 int bTKIP_UseGTK = false;
2212 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002213 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002214 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002215 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002216 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002217 u32 status;
2218 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002219 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002220
Forest Bond92b96792009-06-13 07:38:31 -04002221 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2222
2223 if (pDevice->uAssocCount == 0) {
2224 dev_kfree_skb_irq(skb);
2225 return 0;
2226 }
2227
Andres Moreb902fbf2013-02-25 20:32:51 -05002228 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002229 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002230 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002231 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2232
2233 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2234 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2235 // set tx map
2236 pMgmt->abyPSTxMap[0] |= byMask[0];
2237 return 0;
2238 }
Masanari Iida93184692012-08-13 21:21:50 +09002239 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002240
2241 if (pDevice->byBBType != BB_TYPE_11A)
2242 pDevice->wCurrentRate = RATE_2M;
2243 else
2244 pDevice->wCurrentRate = RATE_24M;
2245 // long preamble type
2246 pDevice->byPreambleType = PREAMBLE_SHORT;
2247
2248 }else {
2249
Andres Moreb902fbf2013-02-25 20:32:51 -05002250 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002251
2252 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2253
2254 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2255
2256 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2257 // set tx map
2258 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2259 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2260 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2261 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2262
2263 return 0;
2264 }
2265 // AP rate decided from node
2266 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2267 // tx preamble decided from node
2268
2269 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2270 pDevice->byPreambleType = pDevice->byShortPreamble;
2271
2272 }else {
2273 pDevice->byPreambleType = PREAMBLE_LONG;
2274 }
Andres More4e9b5e22013-02-12 20:36:30 -05002275 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002276 }
2277 }
2278
Andres Moree269fc22013-02-12 20:36:29 -05002279 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002280 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2281 dev_kfree_skb_irq(skb);
2282 return 0;
2283 }
2284 }
2285
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002286 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002287
2288 if (pContext == NULL) {
2289 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2290 dev_kfree_skb_irq(skb);
2291 return STATUS_RESOURCES;
2292 }
2293
Andres Moreceb8c5d2013-03-18 20:33:49 -05002294 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002295
2296//mike add:station mode check eapol-key challenge--->
2297{
Andres Moreb902fbf2013-02-25 20:32:51 -05002298 u8 Protocol_Version; //802.1x Authentication
2299 u8 Packet_Type; //802.1x Authentication
2300 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002301 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002302
Charles Clément21ec51f2010-05-18 10:08:14 -07002303 Protocol_Version = skb->data[ETH_HLEN];
2304 Packet_Type = skb->data[ETH_HLEN+1];
2305 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2306 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 -05002307 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002308 /* 802.1x OR eapol-key challenge frame transfer */
2309 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2310 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002311 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002312 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2313 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2314 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002315 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002316 PRINT_K("WPA ");
2317 }
2318 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002319 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002320 PRINT_K("WPA2(re-keying) ");
2321 }
2322 PRINT_K("Authentication completed!!\n");
2323 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002324 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002325 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002326 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002327 PRINT_K("WPA2 Authentication completed!!\n");
2328 }
2329 }
2330 }
2331}
2332//mike add:station mode check eapol-key challenge<---
2333
Andres More4e9b5e22013-02-12 20:36:30 -05002334 if (pDevice->bEncryptionEnable == true) {
2335 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002336 // get Transmit key
2337 do {
2338 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2339 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2340 pbyBSSID = pDevice->abyBSSID;
2341 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002342 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002343 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002344 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2345 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002346 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2347 break;
2348 }
2349 } else {
2350 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2351 break;
2352 }
2353 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002354 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2355 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002356 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2357 for (ii = 0; ii< 6; ii++)
2358 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2359 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2360
2361 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002362 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002363 break;
2364 }
2365 // get group key
2366 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002367 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002368 pTransmitKey = NULL;
2369 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2371 }
2372 else
2373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2374 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002375 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2377 }
Andres Moree269fc22013-02-12 20:36:29 -05002378 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002379 }
2380
2381 if (pDevice->bEnableHostWEP) {
2382 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002383 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002384 pTransmitKey = &STempKey;
2385 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2386 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2387 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2388 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2389 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2390 memcpy(pTransmitKey->abyKey,
2391 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2392 pTransmitKey->uKeyLength
2393 );
2394 }
2395 }
2396
Andres Moreb902fbf2013-02-25 20:32:51 -05002397 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002398
2399 if (pDevice->bFixRate) {
2400 if (pDevice->byBBType == BB_TYPE_11B) {
2401 if (pDevice->uConnectionRate >= RATE_11M) {
2402 pDevice->wCurrentRate = RATE_11M;
2403 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002404 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002405 }
2406 } else {
2407 if ((pDevice->byBBType == BB_TYPE_11A) &&
2408 (pDevice->uConnectionRate <= RATE_6M)) {
2409 pDevice->wCurrentRate = RATE_6M;
2410 } else {
2411 if (pDevice->uConnectionRate >= RATE_54M)
2412 pDevice->wCurrentRate = RATE_54M;
2413 else
Andres More3eaca0d2013-02-25 20:32:52 -05002414 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002415 }
2416 }
2417 }
2418 else {
2419 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2420 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002421 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002422 // Multicast use highest data rate
2423 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2424 // preamble type
2425 pDevice->byPreambleType = pDevice->byShortPreamble;
2426 }
2427 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002428 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002429 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2430 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2431 pDevice->byPreambleType = pDevice->byShortPreamble;
2432
2433 }
2434 else {
2435 pDevice->byPreambleType = PREAMBLE_LONG;
2436 }
2437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2438 }
2439 else {
2440 if (pDevice->byBBType != BB_TYPE_11A)
2441 pDevice->wCurrentRate = RATE_2M;
2442 else
2443 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2444 // abyCurrExtSuppRates[]
2445 pDevice->byPreambleType = PREAMBLE_SHORT;
2446 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2447 }
2448 }
2449 }
2450 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2451 // Infra STA rate decided from AP Node, index = 0
2452 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2453 }
2454 }
2455
Andres Moreceb8c5d2013-03-18 20:33:49 -05002456 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002457 if (pDevice->byBBType != BB_TYPE_11A) {
2458 pDevice->wCurrentRate = RATE_1M;
2459 pDevice->byACKRate = RATE_1M;
2460 pDevice->byTopCCKBasicRate = RATE_1M;
2461 pDevice->byTopOFDMBasicRate = RATE_6M;
2462 } else {
2463 pDevice->wCurrentRate = RATE_6M;
2464 pDevice->byACKRate = RATE_6M;
2465 pDevice->byTopCCKBasicRate = RATE_1M;
2466 pDevice->byTopOFDMBasicRate = RATE_6M;
2467 }
2468 }
Forest Bond92b96792009-06-13 07:38:31 -04002469
Andres More0cbd8d92010-05-06 20:34:29 -03002470 DBG_PRT(MSG_LEVEL_DEBUG,
2471 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2472 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002473
2474 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002475 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002476 }
2477
2478 if (pDevice->wCurrentRate <= RATE_11M) {
2479 byPktType = PK_TYPE_11B;
2480 }
2481
Andres More4e9b5e22013-02-12 20:36:30 -05002482 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002483 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2484 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002485 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002486 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002487 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2488 if (pTransmitKey == NULL) {
2489 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2490 }
2491 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002492 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002493 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2494 }
2495 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002496 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2497 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002498 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002499 }
2500 }
2501 }
2502
Forest Bond92b96792009-06-13 07:38:31 -04002503 if (pDevice->bEnableHostWEP) {
2504 if ((uNodeIndex != 0) &&
2505 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002506 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2507 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002508 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002509 }
2510 }
2511 }
2512 else {
2513
Forest Bond92b96792009-06-13 07:38:31 -04002514 if (pTransmitKey == NULL) {
2515 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002516 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002517 dev_kfree_skb_irq(skb);
2518 pStats->tx_dropped++;
2519 return STATUS_FAILURE;
2520 }
Forest Bond92b96792009-06-13 07:38:31 -04002521 }
2522 }
2523
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002524 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2525
Forest Bond92b96792009-06-13 07:38:31 -04002526 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002527 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002528 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002529 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002530 pDevice->wCurrentRate,
2531 &uHeaderLen, &BytesToWrite
2532 );
2533
Andres Moree269fc22013-02-12 20:36:29 -05002534 if (fConvertedPacket == false) {
2535 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002536 dev_kfree_skb_irq(skb);
2537 return STATUS_FAILURE;
2538 }
2539
Andres More4e9b5e22013-02-12 20:36:30 -05002540 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002541 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002542 bScheduleCommand((void *) pDevice,
2543 WLAN_CMD_MAC_DISPOWERSAVING,
2544 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002545 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002546 }
2547 }
2548
Andres Moreb902fbf2013-02-25 20:32:51 -05002549 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002550 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002551
2552 pContext->pPacket = skb;
2553 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002554 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002555
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002556 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2557 &pContext->sEthHeader.h_dest[0],
2558 (u16)(BytesToWrite-uHeaderLen),
2559 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002560
2561 status = PIPEnsSendBulkOut(pDevice,pContext);
2562
Andres More4e9b5e22013-02-12 20:36:30 -05002563 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002564 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002565
Andres Moreb902fbf2013-02-25 20:32:51 -05002566 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002567 }
2568
2569 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002570 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002571 dev_kfree_skb_irq(skb);
2572 return STATUS_FAILURE;
2573 }
2574 else
2575 return 0;
2576
2577}
2578
Forest Bond92b96792009-06-13 07:38:31 -04002579/*
2580 * Description:
2581 * Relay packet send (AC1DMA) from rx dpc.
2582 *
2583 * Parameters:
2584 * In:
2585 * pDevice - Pointer to the adapter
2586 * pPacket - Pointer to rx packet
2587 * cbPacketSize - rx ethernet frame size
2588 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002589 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002590 *
Andres More4e9b5e22013-02-12 20:36:30 -05002591 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002592 */
2593
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002594int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2595 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002596{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002597 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002598 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002599 u32 BytesToWrite = 0, uHeaderLen = 0;
2600 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002601 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002602 SKeyItem STempKey;
2603 PSKeyItem pTransmitKey = NULL;
2604 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002605 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002606 u8 byPktTyp;
2607 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002608 u32 status;
2609 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002610
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002611 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002612
2613 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002614 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002615 }
2616
Andres Moreceb8c5d2013-03-18 20:33:49 -05002617 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002618
Andres More4e9b5e22013-02-12 20:36:30 -05002619 if (pDevice->bEncryptionEnable == true) {
2620 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002621 // get group key
2622 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002623 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002624 pTransmitKey = NULL;
2625 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2626 } else {
2627 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2628 }
2629 }
2630
2631 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002632 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002633 pTransmitKey = &STempKey;
2634 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2635 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2636 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2637 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2638 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2639 memcpy(pTransmitKey->abyKey,
2640 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2641 pTransmitKey->uKeyLength
2642 );
2643 }
2644 }
2645
2646 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002647 pContext->bBoolInUse = false;
2648 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002649 }
2650
Andres Moreb902fbf2013-02-25 20:32:51 -05002651 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002652
2653 if (pDevice->bFixRate) {
2654 if (pDevice->byBBType == BB_TYPE_11B) {
2655 if (pDevice->uConnectionRate >= RATE_11M) {
2656 pDevice->wCurrentRate = RATE_11M;
2657 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002658 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002659 }
2660 } else {
2661 if ((pDevice->byBBType == BB_TYPE_11A) &&
2662 (pDevice->uConnectionRate <= RATE_6M)) {
2663 pDevice->wCurrentRate = RATE_6M;
2664 } else {
2665 if (pDevice->uConnectionRate >= RATE_54M)
2666 pDevice->wCurrentRate = RATE_54M;
2667 else
Andres More3eaca0d2013-02-25 20:32:52 -05002668 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002669 }
2670 }
2671 }
2672 else {
2673 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2674 }
2675
Forest Bond92b96792009-06-13 07:38:31 -04002676 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002677 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002678 }
2679
2680 if (pDevice->wCurrentRate <= RATE_11M)
2681 byPktType = PK_TYPE_11B;
2682
Andres Moreabad19d2010-07-12 16:28:32 -03002683 BytesToWrite = uDataLen + ETH_FCS_LEN;
2684
Forest Bond92b96792009-06-13 07:38:31 -04002685 // Convert the packet to an usb frame and copy into our buffer
2686 // and send the irp.
2687
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002688 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2689
Forest Bond92b96792009-06-13 07:38:31 -04002690 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002691 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002692 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2693 pbySkbData, pTransmitKey, uNodeIndex,
2694 pDevice->wCurrentRate,
2695 &uHeaderLen, &BytesToWrite
2696 );
2697
Andres Moree269fc22013-02-12 20:36:29 -05002698 if (fConvertedPacket == false) {
2699 pContext->bBoolInUse = false;
2700 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002701 }
2702
Andres Moreb902fbf2013-02-25 20:32:51 -05002703 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002704 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002705
2706 pContext->pPacket = NULL;
2707 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002708 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002709
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002710 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2711 &pContext->sEthHeader.h_dest[0],
2712 (u16)(BytesToWrite - uHeaderLen),
2713 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002714
2715 status = PIPEnsSendBulkOut(pDevice,pContext);
2716
Andres More4e9b5e22013-02-12 20:36:30 -05002717 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002718}
2719