blob: 6534f753296aada14a3450739a49c6132d8eee1d [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Valentina Manea3b138852013-11-04 10:44:02 +020067static const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Valentina Manea3b138852013-11-04 10:44:02 +020072static const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Valentina Manea3b138852013-11-04 10:44:02 +020076static const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyaceaf012013-11-26 19:06:35 +000099static struct vnt_usb_send_context
100 *s_vGetFreeContext(struct vnt_private *pDevice);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000101
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100102static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100103 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100104 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
105 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000106
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000107static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500108 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000109 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400110
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100111static void s_vFillTxKey(struct vnt_private *pDevice,
112 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
113 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100114 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400115
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000116static void s_vSWencryption(struct vnt_private *pDevice,
117 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400118
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000119static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
120 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400121
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100122static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000123 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400124
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100125static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100126 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
127 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400128
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100129static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100130 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500131 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400132
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100133static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100134 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400135
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100136static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000137 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
138 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400139
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000140static struct vnt_usb_send_context
141 *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400142{
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +0100143 struct vnt_usb_send_context *pContext = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000144 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400145
146 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
147
148 for (ii = 0; ii < pDevice->cbTD; ii++) {
Malcolm Priestley18e35e082013-09-22 20:15:58 +0100149 if (!pDevice->apTD[ii])
150 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400151 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);
Malcolm Priestley5c851382013-11-26 19:12:38 +0000155 return pContext;
Forest Bond92b96792009-06-13 07:38:31 -0400156 }
157 }
158 if ( ii == pDevice->cbTD ) {
159 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
160 }
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000161
Malcolm Priestley5c851382013-11-26 19:12:38 +0000162 return NULL;
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 Priestley3ba09382013-10-15 21:41:38 +0100184static void s_vFillTxKey(struct vnt_private *pDevice,
185 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
186 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
187 struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400188{
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100189 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000190 u32 *pdwIV = (u32 *)pbyIVHead;
191 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500192 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000193 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400194
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100195 /* Fill TXKEY */
196 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100197 return;
Forest Bond92b96792009-06-13 07:38:31 -0400198
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100199 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
200 *pdwIV = pDevice->dwIVCounter;
201 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400202
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100203 switch (pTransmitKey->byCipherSuite) {
204 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100205 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
206 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
207 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
208 pTransmitKey->uKeyLength);
209 } else {
210 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
211 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
212 pTransmitKey->uKeyLength);
213 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
214 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
215 memcpy(pbyBuf+11, pTransmitKey->abyKey,
216 pTransmitKey->uKeyLength);
217 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100218
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100219 memcpy(pDevice->abyPRNG, pbyBuf, 16);
220 }
221 /* Append IV after Mac Header */
222 *pdwIV &= WEP_IV_MASK;
223 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
224 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100225
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100226 pDevice->dwIVCounter++;
227 if (pDevice->dwIVCounter > WEP_IV_MASK)
228 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100229
230 break;
231 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100232 pTransmitKey->wTSC15_0++;
233 if (pTransmitKey->wTSC15_0 == 0)
234 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100235
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100236 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
237 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
238 pDevice->abyPRNG);
239 memcpy(pbyBuf, pDevice->abyPRNG, 16);
240
241 /* Make IV */
242 memcpy(pdwIV, pDevice->abyPRNG, 3);
243
244 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
245 0xc0) | 0x20);
246 /* Append IV&ExtIV after Mac Header */
247 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
248
249 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
250 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
251
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100252 break;
253 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100254 pTransmitKey->wTSC15_0++;
255 if (pTransmitKey->wTSC15_0 == 0)
256 pTransmitKey->dwTSC47_16++;
257
258 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
259
260 /* Make IV */
261 *pdwIV = 0;
262 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
263 0xc0) | 0x20);
264
265 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
266
267 /* Append IV&ExtIV after Mac Header */
268 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
269
270 if (!mic_hdr)
271 return;
272
273 /* MICHDR0 */
274 mic_hdr->id = 0x59;
275 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
276 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
277
278 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
279 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
280
281 /* MICHDR1 */
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000282 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100283 mic_hdr->hlen = cpu_to_be16(28);
284 else
285 mic_hdr->hlen = cpu_to_be16(22);
286
287 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
288 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
289
290 /* MICHDR2 */
291 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
292 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100293 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100294 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100295
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000296 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100297 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
298 }
Forest Bond92b96792009-06-13 07:38:31 -0400299}
300
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000301static void s_vSWencryption(struct vnt_private *pDevice,
302 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400303{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000304 u32 cbICVlen = 4;
305 u32 dwICV = 0xffffffff;
306 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400307
308 if (pTransmitKey == NULL)
309 return;
310
311 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
312 //=======================================================================
313 // Append ICV after payload
314 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500315 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400316 // finally, we must invert dwCRC to get the correct answer
317 *pdwICV = cpu_to_le32(~dwICV);
318 // RC4 encryption
319 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
320 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
321 //=======================================================================
322 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
323 //=======================================================================
324 //Append ICV after payload
325 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500326 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400327 // finally, we must invert dwCRC to get the correct answer
328 *pdwICV = cpu_to_le32(~dwICV);
329 // RC4 encryption
330 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
331 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
332 //=======================================================================
333 }
334}
335
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100336static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
337{
338 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
339 [rate % MAX_RATE]);
340}
341
Forest Bond92b96792009-06-13 07:38:31 -0400342/*byPktType : PK_TYPE_11A 0
343 PK_TYPE_11B 1
344 PK_TYPE_11GB 2
345 PK_TYPE_11GA 3
346*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000347static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
348 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400349{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000350 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400351
352 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
353 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500354 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400355 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500356 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400357 }
358
359 if (bNeedAck) {
360 return (uDataTime + pDevice->uSIFS + uAckTime);
361 }
362 else {
363 return uDataTime;
364 }
365}
366
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100367static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
368 u32 frame_length, u16 rate, int need_ack)
369{
370 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
371 frame_length, rate, need_ack));
372}
373
Forest Bond92b96792009-06-13 07:38:31 -0400374//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100375static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000376 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400377{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000378 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400379
380 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
381
Forest Bond92b96792009-06-13 07:38:31 -0400382 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
383 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
384 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
385 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
386 }
387 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
388 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
389 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
390 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
391 }
392 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
393 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
394 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
395 }
396 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
397 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
398 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
399 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
400 return uRrvTime;
401 }
402
403 //RTSRrvTime
404 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100405 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400406}
407
408//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100409static u16 s_uGetDataDuration(struct vnt_private *pDevice,
410 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400411{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100412 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400413
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100414 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100415 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100416 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
417 byPktType, 14, pDevice->byTopCCKBasicRate);
418 else
419 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
420 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100421 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100422 }
Forest Bond92b96792009-06-13 07:38:31 -0400423
Forest Bond92b96792009-06-13 07:38:31 -0400424 return 0;
425}
426
Forest Bond92b96792009-06-13 07:38:31 -0400427//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100428static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000429 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
430 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400431{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000432 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400433
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100434 switch (byDurType) {
435 case RTSDUR_BB:
436 case RTSDUR_BA:
437 case RTSDUR_BA_F0:
438 case RTSDUR_BA_F1:
439 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
440 14, pDevice->byTopCCKBasicRate);
441 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
442 s_uGetTxRsvTime(pDevice, byPktType,
443 cbFrameLength, wRate, bNeedAck);
444 break;
Forest Bond92b96792009-06-13 07:38:31 -0400445
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100446 case RTSDUR_AA:
447 case RTSDUR_AA_F0:
448 case RTSDUR_AA_F1:
449 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
450 14, pDevice->byTopOFDMBasicRate);
451 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
452 s_uGetTxRsvTime(pDevice, byPktType,
453 cbFrameLength, wRate, bNeedAck);
454 break;
Forest Bond92b96792009-06-13 07:38:31 -0400455
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100456 case CTSDUR_BA:
457 case CTSDUR_BA_F0:
458 case CTSDUR_BA_F1:
459 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100460 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100461 break;
Forest Bond92b96792009-06-13 07:38:31 -0400462
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100463 default:
464 break;
465 }
Forest Bond92b96792009-06-13 07:38:31 -0400466
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100467 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400468}
469
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100470static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
471 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
472{
473 /* Get SignalField,ServiceField,Length */
474 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
475 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
476 PK_TYPE_11B, &buf->b);
477
478 /* Get Duration and TimeStamp */
479 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
480 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
481
482 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
483 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
484 priv->byTopCCKBasicRate);
485
486 return buf->wDuration_a;
487}
488
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100489static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
490 u16 rate, struct vnt_tx_datahead_g_fb *buf,
491 u32 frame_len, int need_ack)
492{
493 /* Get SignalField,ServiceField,Length */
494 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
495
496 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
497 PK_TYPE_11B, &buf->b);
498
499 /* Get Duration and TimeStamp */
500 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
501 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
502
503 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
504 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
505
506 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
507 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
508 priv->byTopCCKBasicRate);
509
510 return buf->wDuration_a;
511}
512
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100513static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
514 u16 rate, struct vnt_tx_datahead_a_fb *buf,
515 u32 frame_len, int need_ack)
516{
517 /* Get SignalField,ServiceField,Length */
518 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
519 /* Get Duration and TimeStampOff */
520 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
521
522 buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
523 buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
524
525 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
526
527 return buf->wDuration;
528}
529
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100530static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
531 u16 rate, struct vnt_tx_datahead_ab *buf,
532 u32 frame_len, int need_ack)
533{
534 /* Get SignalField,ServiceField,Length */
535 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
536 /* Get Duration and TimeStampOff */
537 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
538
539 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
540
541 return buf->wDuration;
542}
543
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100544static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
545 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
546 u16 duration)
547{
548 rts->duration = duration;
549 rts->frame_control = TYPE_CTL_RTS;
550
551 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
552 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
553 else
554 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
555
556 if (priv->eOPMode == OP_MODE_AP)
557 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
558 else
559 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
560
561 return 0;
562}
563
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100564static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100565 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
566 u8 pkt_type, u32 frame_len, int need_ack,
567 u16 current_rate, u8 fb_option)
568{
569 u16 rts_frame_len = 20;
570
571 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
572 PK_TYPE_11B, &buf->b);
573 BBvCalculateParameter(priv, rts_frame_len,
574 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
575
576 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
577 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
578 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
579 pkt_type, current_rate, need_ack, fb_option);
580 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
581 pkt_type, current_rate, need_ack, fb_option);
582
583 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
584
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100585 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
586 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100587}
588
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100589static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100590 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
591 u8 pkt_type, u32 frame_len, int need_ack,
592 u16 current_rate, u8 fb_option)
593{
594 u16 rts_frame_len = 20;
595
596 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
597 PK_TYPE_11B, &buf->b);
598 BBvCalculateParameter(priv, rts_frame_len,
599 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
600
601
602 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
603 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
604 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
605 pkt_type, current_rate, need_ack, fb_option);
606 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
607 pkt_type, current_rate, need_ack, fb_option);
608
609
610 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100611 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100612 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100613 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100614 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100615 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100616 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100617 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100618
619 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
620
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100621 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
622 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100623}
624
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100625static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100626 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
627 u8 pkt_type, u32 frame_len, int need_ack,
628 u16 current_rate, u8 fb_option)
629{
630 u16 rts_frame_len = 20;
631
632 BBvCalculateParameter(priv, rts_frame_len,
633 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
634
635 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
636 pkt_type, current_rate, need_ack, fb_option);
637
638 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
639
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100640 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
641 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100642}
643
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100644static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100645 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
646 u8 pkt_type, u32 frame_len, int need_ack,
647 u16 current_rate, u8 fb_option)
648{
649 u16 rts_frame_len = 20;
650
651 BBvCalculateParameter(priv, rts_frame_len,
652 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
653
654 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
655 pkt_type, current_rate, need_ack, fb_option);
656
657 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100658 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100659
660 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100661 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100662
663 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
664
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100665 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
666 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100667}
668
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100669static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100670 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500671 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400672{
Forest Bond92b96792009-06-13 07:38:31 -0400673
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100674 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100675 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400676
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100677 /* Note: So far RTSHead doesn't appear in ATIM
678 * & Beacom DMA, so we don't need to take them
679 * into account.
680 * Otherwise, we need to modified codes for them.
681 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100682 switch (byPktType) {
683 case PK_TYPE_11GB:
684 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100685 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100686 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100687 psEthHeader, byPktType, cbFrameLength,
688 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100689 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100690 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100691 psEthHeader, byPktType, cbFrameLength,
692 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100693 break;
694 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100695 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100696 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100697 psEthHeader, byPktType, cbFrameLength,
698 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100699 break;
700 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100701 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100702 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100703 psEthHeader, byPktType, cbFrameLength,
704 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100705 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100706
707 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400708}
709
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100710static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100711 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
712 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400713{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000714 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400715
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100716 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100717 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400718
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100719 if (byFBOption != AUTO_FB_NONE) {
720 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100721 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100722 /* Get SignalField,ServiceField,Length */
723 BBvCalculateParameter(pDevice, uCTSFrameLen,
724 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100725 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
726 cbFrameLength, byPktType,
727 wCurrentRate, bNeedAck, byFBOption);
728 /* Get CTSDuration_ba_f0 */
729 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100730 CTSDUR_BA_F0, cbFrameLength, byPktType,
731 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100732 /* Get CTSDuration_ba_f1 */
733 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100734 CTSDUR_BA_F1, cbFrameLength, byPktType,
735 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100736 /* Get CTS Frame body */
737 pBuf->data.duration = pBuf->wDuration_ba;
738 pBuf->data.frame_control = TYPE_CTL_CTS;
739 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100740
741 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
742 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100743 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100744 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100745 /* Get SignalField,ServiceField,Length */
746 BBvCalculateParameter(pDevice, uCTSFrameLen,
747 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100748 /* Get CTSDuration_ba */
749 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
750 CTSDUR_BA, cbFrameLength, byPktType,
751 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100752 /*Get CTS Frame body*/
753 pBuf->data.duration = pBuf->wDuration_ba;
754 pBuf->data.frame_control = TYPE_CTL_CTS;
755 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100756
757 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
758 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400759 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100760
761 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400762}
763
Forest Bond92b96792009-06-13 07:38:31 -0400764/*+
765 *
766 * Description:
767 * Generate FIFO control for MAC & Baseband controller
768 *
769 * Parameters:
770 * In:
771 * pDevice - Pointer to adpater
772 * pTxDataHead - Transmit Data Buffer
773 * pTxBufHead - pTxBufHead
774 * pvRrvTime - pvRrvTime
775 * pvRTS - RTS Buffer
776 * pCTS - CTS Buffer
777 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
778 * bNeedACK - If need ACK
779 * uDMAIdx - DMA Index
780 * Out:
781 * none
782 *
783 * Return Value: none
784 *
785-*/
Andres Morecc856e62010-05-17 21:34:01 -0300786
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100787static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100788 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100789 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
790 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400791{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100792 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100793 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000794 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000795 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400796
Malcolm Priestley92928f12013-10-07 20:14:01 +0100797 pFifoHead->wReserved = wCurrentRate;
798 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400799
Malcolm Priestley92928f12013-10-07 20:14:01 +0100800 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
801 byFBOption = AUTO_FB_0;
802 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
803 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400804
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100805 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100806 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100807
Malcolm Priestley92928f12013-10-07 20:14:01 +0100808 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
809 if (need_rts) {
810 struct vnt_rrv_time_rts *pBuf =
811 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100812
Malcolm Priestley92928f12013-10-07 20:14:01 +0100813 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
814 byPktType, cbFrameSize, wCurrentRate);
815 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
816 byPktType, cbFrameSize, wCurrentRate);
817 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100818 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100819
Malcolm Priestley92928f12013-10-07 20:14:01 +0100820 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
821 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
822 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
823 PK_TYPE_11B, cbFrameSize,
824 pDevice->byTopCCKBasicRate, bNeedACK);
825
826 if (need_mic) {
827 *mic_hdr = &tx_buffer->
828 tx_head.tx_rts.tx.mic.hdr;
829 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
830 } else {
831 head = &tx_buffer->tx_head.tx_rts.tx.head;
832 }
833
834 /* Fill RTS */
835 return s_vFillRTSHead(pDevice, byPktType, head,
836 cbFrameSize, bNeedACK, psEthHeader,
837 wCurrentRate, byFBOption);
838
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100839 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100840 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
841 tx_head.tx_cts.cts;
842
843 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
844 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
845 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
846 PK_TYPE_11B, cbFrameSize,
847 pDevice->byTopCCKBasicRate, bNeedACK);
848
849 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
850 byPktType, cbFrameSize, wCurrentRate);
851
852 if (need_mic) {
853 *mic_hdr = &tx_buffer->
854 tx_head.tx_cts.tx.mic.hdr;
855 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
856 } else {
857 head = &tx_buffer->tx_head.tx_cts.tx.head;
858 }
859
860 /* Fill CTS */
861 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
862 head, cbFrameSize, bNeedACK, wCurrentRate,
863 byFBOption);
864 }
865 } else if (byPktType == PK_TYPE_11A) {
866 if (need_mic) {
867 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
868 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
869 } else {
870 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100871 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100872
Malcolm Priestley92928f12013-10-07 20:14:01 +0100873 if (need_rts) {
874 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
875 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100876
Malcolm Priestley92928f12013-10-07 20:14:01 +0100877 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100878 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100879
Malcolm Priestley92928f12013-10-07 20:14:01 +0100880 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
881 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
882
883 /* Fill RTS */
884 return s_vFillRTSHead(pDevice, byPktType, head,
885 cbFrameSize, bNeedACK, psEthHeader,
886 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100887 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100888 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
889 tx_head.tx_ab.ab;
890
891 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
892 PK_TYPE_11A, cbFrameSize,
893 wCurrentRate, bNeedACK);
894
895 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
896 wCurrentRate, &head->data_head_a_fb,
897 cbFrameSize, bNeedACK);
898 }
899 } else if (byPktType == PK_TYPE_11B) {
900 if (need_mic) {
901 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
902 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
903 } else {
904 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100905 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100906
Malcolm Priestley92928f12013-10-07 20:14:01 +0100907 if (need_rts) {
908 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
909 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100910
Malcolm Priestley92928f12013-10-07 20:14:01 +0100911 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100912 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100913
Malcolm Priestley92928f12013-10-07 20:14:01 +0100914 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
915 PK_TYPE_11B, cbFrameSize, wCurrentRate,
916 bNeedACK);
917
918 /* Fill RTS */
919 return s_vFillRTSHead(pDevice, byPktType, head,
920 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100921 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100922 } else {
923 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
924 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100925
Malcolm Priestley92928f12013-10-07 20:14:01 +0100926 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
927 PK_TYPE_11B, cbFrameSize,
928 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100929
Malcolm Priestley92928f12013-10-07 20:14:01 +0100930 return vnt_rxtx_datahead_ab(pDevice, byPktType,
931 wCurrentRate, &head->data_head_ab,
932 cbFrameSize, bNeedACK);
933 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100934 }
935
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100936 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400937}
938/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500939 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500940 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300941 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400942*/
943
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000944static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100945 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100946 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
947 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
948 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400949{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100950 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000951 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
952 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000953 u32 cb802_1_H_len;
954 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
955 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100956 int bNeedACK;
957 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000958 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
959 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
960 u8 abySNAP_Bridgetunnel[ETH_ALEN]
961 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
962 u32 uDuration;
963 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100964 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000965 u8 byFBOption = AUTO_FB_NONE, byFragType;
966 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100967 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000968 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500969 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100970
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100971 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400972
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000973 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500974 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
975 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000976 }
Forest Bond92b96792009-06-13 07:38:31 -0400977
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000978 /* Get pkt type */
979 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
980 cb802_1_H_len = 8;
981 else
982 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400983
Charles Clément21ec51f2010-05-18 10:08:14 -0700984 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400985
986 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500987 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400988
Andres More22040bb2010-08-02 20:21:44 -0300989 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000990 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500991 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500992 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -0300993 pTxBufHead->wFIFOCtl =
994 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
995 } else {
Andres More4e9b5e22013-02-12 20:36:30 -0500996 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -0300997 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
998 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000999 } else {
1000 /* MSDUs in Infra mode always need ACK */
1001 bNeedACK = true;
1002 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1003 }
Forest Bond92b96792009-06-13 07:38:31 -04001004
1005 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1006
Forest Bond92b96792009-06-13 07:38:31 -04001007 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001008 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1009
Andres More3eaca0d2013-02-25 20:32:52 -05001010 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001011
1012 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001013 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001014 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1015 }
1016
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001017 /* Set Auto Fallback Ctl */
1018 if (wCurrentRate >= RATE_18M) {
1019 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1020 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1021
1022 pDevice->tx_rate_fb0 =
1023 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1024 pDevice->tx_rate_fb1 =
1025 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1026
1027 byFBOption = AUTO_FB_0;
1028 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1029 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1030 pDevice->tx_rate_fb0 =
1031 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1032 pDevice->tx_rate_fb1 =
1033 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1034
1035 byFBOption = AUTO_FB_1;
1036 }
1037 }
Forest Bond92b96792009-06-13 07:38:31 -04001038
Andres More4e9b5e22013-02-12 20:36:30 -05001039 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001040 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1041 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1042 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1043 }
1044 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1045 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1046 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1047 }
1048 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1049 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1050 }
1051 }
1052 }
1053
Forest Bond92b96792009-06-13 07:38:31 -04001054 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1055 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1056 cbIVlen = 4;
1057 cbICVlen = 4;
1058 }
1059 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1060 cbIVlen = 8;//IV+ExtIV
1061 cbMIClen = 8;
1062 cbICVlen = 4;
1063 }
1064 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1065 cbIVlen = 8;//RSN Header
1066 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001067 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001068 }
Andres Moree269fc22013-02-12 20:36:29 -05001069 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001070 //MAC Header should be padding 0 to DW alignment.
1071 uPadding = 4 - (cbMACHdLen%4);
1072 uPadding %= 4;
1073 }
1074 }
1075
1076 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1077
Andres Moree269fc22013-02-12 20:36:29 -05001078 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1079 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001080 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001081 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001082 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1083 }
1084
Andres Moreb902fbf2013-02-25 20:32:51 -05001085 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001086 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1087
Forest Bond92b96792009-06-13 07:38:31 -04001088 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1089 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001090 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001091 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001092 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001093 }
1094 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001095 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001096 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001097 }
1098 } else {
1099 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001100 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001101 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001102 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001103 }
Andres Moree269fc22013-02-12 20:36:29 -05001104 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001105 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001106 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001107 }
1108 } // Auto Fall Back
1109 }
1110 else {//802.11a/b packet
1111 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001112 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001113 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001114 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001115 }
Andres Moree269fc22013-02-12 20:36:29 -05001116 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001117 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001118 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001119 }
1120 } else {
1121 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001122 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001123 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001124 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001125 }
Andres Moree269fc22013-02-12 20:36:29 -05001126 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001127 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001128 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001129 }
1130 } // Auto Fall Back
1131 }
1132
Andres Moreb902fbf2013-02-25 20:32:51 -05001133 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1134 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1135 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001136
Forest Bond92b96792009-06-13 07:38:31 -04001137 //=========================
1138 // No Fragmentation
1139 //=========================
1140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1141 byFragType = FRAGCTL_NONFRAG;
1142 //uDMAIdx = TYPE_AC0DMA;
1143 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1144
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001145 /* Fill FIFO, RrvTime, RTS and CTS */
1146 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1147 tx_buffer, &pMICHDR, cbMICHDR,
1148 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001149
Forest Bond92b96792009-06-13 07:38:31 -04001150 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001151 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001152 byFragType, uDMAIdx, 0);
1153
Andres More4e9b5e22013-02-12 20:36:30 -05001154 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001155 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001156 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001157 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001158
1159 if (pDevice->bEnableHostWEP) {
1160 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1161 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1162 }
1163 }
1164
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001165 /* 802.1H */
1166 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001167 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001168 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001169 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001170 abySNAP_Bridgetunnel, 6);
1171 else
1172 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001173
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001174 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001175
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001176 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1177 }
Forest Bond92b96792009-06-13 07:38:31 -04001178
Forest Bond92b96792009-06-13 07:38:31 -04001179 if (pPacket != NULL) {
1180 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001181 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001182 (pPacket + ETH_HLEN),
1183 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001184 );
1185
1186 } else {
1187 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001188 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001189 }
1190
Andres More4e9b5e22013-02-12 20:36:30 -05001191 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001192
1193 ///////////////////////////////////////////////////////////////////
1194
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001195 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1196 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1197 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1198 }
Forest Bond92b96792009-06-13 07:38:31 -04001199 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001200 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1201 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001202 }
1203 else {
Andres More52a7e642013-02-25 20:32:53 -05001204 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1205 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001206 }
1207 // DO Software Michael
1208 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001209 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001210 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001211 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001212 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1213 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001214
1215 ///////////////////////////////////////////////////////////////////
1216
1217 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1218 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001219 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001220 //}
1221 //DBG_PRN_GRP12(("\n\n\n"));
1222
1223 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1224
Andres More52a7e642013-02-25 20:32:53 -05001225 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1226 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001227
1228 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1229 MIC_vUnInit();
1230
Andres More4e9b5e22013-02-12 20:36:30 -05001231 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001232 *pdwMIC_L = 0;
1233 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001234 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001235 }
1236 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1237 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1238 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1239 }
1240
Andres More4e9b5e22013-02-12 20:36:30 -05001241 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001242
Andres More3eaca0d2013-02-25 20:32:52 -05001243 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001244
Andres More4e9b5e22013-02-12 20:36:30 -05001245 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1246 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1247 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001248 cbFrameSize -= cbICVlen;
1249 }
1250
Forest Bond92b96792009-06-13 07:38:31 -04001251 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001252
1253 *pcbHeaderLen = cbHeaderLength;
1254 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1255
Forest Bond92b96792009-06-13 07:38:31 -04001256 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001257 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001258
Andres More4e9b5e22013-02-12 20:36:30 -05001259 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001260
1261}
1262
Forest Bond92b96792009-06-13 07:38:31 -04001263/*+
1264 *
1265 * Description:
1266 * Translate 802.3 to 802.11 header
1267 *
1268 * Parameters:
1269 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001270 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001271 * dwTxBufferAddr - Transmit Buffer
1272 * pPacket - Packet from upper layer
1273 * cbPacketSize - Transmit Data Length
1274 * Out:
1275 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1276 * pcbAppendPayload - size of append payload for 802.1H translation
1277 *
1278 * Return Value: none
1279 *
1280-*/
1281
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001282static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001283 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001284 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001285{
Andres More1cac4a42013-03-18 20:33:50 -05001286 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001287
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001288 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001289
1290 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001291 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001292 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001293 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001294 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1295 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001296 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001297 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001298 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001299 } else {
1300 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001301 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001302 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001303 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001304 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001305 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001306 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001307 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001308 &(pDevice->abyBSSID[0]),
1309 ETH_ALEN);
1310 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001311 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001312 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001313 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001314 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001315 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001316 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001317 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001318 &(pDevice->abyBSSID[0]),
1319 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001320 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001321 }
1322 }
1323
1324 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001325 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001326
Andres More1cac4a42013-03-18 20:33:50 -05001327 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001328
Andres More1cac4a42013-03-18 20:33:50 -05001329 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001330
1331 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001332 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001333
1334 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1335 pDevice->wSeqCounter++;
1336 if (pDevice->wSeqCounter > 0x0fff)
1337 pDevice->wSeqCounter = 0;
1338 }
1339
1340 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001341 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001342 }
1343}
1344
Forest Bond92b96792009-06-13 07:38:31 -04001345/*+
1346 *
1347 * Description:
1348 * Request instructs a MAC to transmit a 802.11 management packet through
1349 * the adapter onto the medium.
1350 *
1351 * Parameters:
1352 * In:
1353 * hDeviceContext - Pointer to the adapter
1354 * pPacket - A pointer to a descriptor for the packet to transmit
1355 * Out:
1356 * none
1357 *
Andres Moree269fc22013-02-12 20:36:29 -05001358 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001359 *
1360-*/
1361
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001362CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1363 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001364{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001365 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001366 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001367 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001368 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001369 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001370 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001371 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001372 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001373 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001374 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001375 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1376 u32 uPadding = 0;
1377 u16 wTxBufSize;
1378 u32 cbMacHdLen;
1379 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001380
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001381 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001382
1383 if (NULL == pContext) {
1384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1385 return CMD_STATUS_RESOURCES;
1386 }
1387
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001388 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001389 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001390 pTxBufHead = &pTX_Buffer->fifo_head;
1391 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1392 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001393
1394 if (pDevice->byBBType == BB_TYPE_11A) {
1395 wCurrentRate = RATE_6M;
1396 byPktType = PK_TYPE_11A;
1397 } else {
1398 wCurrentRate = RATE_1M;
1399 byPktType = PK_TYPE_11B;
1400 }
1401
1402 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1403 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1404 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1405 // to set power here.
1406 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1407 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1408 } else {
1409 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1410 }
1411 pDevice->wCurrentRate = wCurrentRate;
1412
Forest Bond92b96792009-06-13 07:38:31 -04001413 //Set packet type
1414 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1415 pTxBufHead->wFIFOCtl = 0;
1416 }
1417 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1418 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1419 }
1420 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1421 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1422 }
1423 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1424 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1425 }
1426
1427 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1428 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1429
Andres More22040bb2010-08-02 20:21:44 -03001430 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001431 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001432 }
1433 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001434 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001435 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1436 };
1437
1438 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1439 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1440
1441 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1442 //Set Preamble type always long
1443 //pDevice->byPreambleType = PREAMBLE_LONG;
1444 // probe-response don't retry
1445 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001446 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001447 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1448 //}
1449 }
1450
1451 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1452
1453 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001454 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001455 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1456 } else {
1457 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1458 }
1459
1460 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001461 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001462
1463 // Notes:
1464 // Although spec says MMPDU can be fragmented; In most case,
1465 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001466
1467 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1468 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1469 cbIVlen = 4;
1470 cbICVlen = 4;
1471 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1472 }
1473 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1474 cbIVlen = 8;//IV+ExtIV
1475 cbMIClen = 8;
1476 cbICVlen = 4;
1477 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1478 //We need to get seed here for filling TxKey entry.
1479 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1480 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1481 }
1482 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1483 cbIVlen = 8;//RSN Header
1484 cbICVlen = 8;//MIC
1485 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001486 }
1487 //MAC Header should be padding 0 to DW alignment.
1488 uPadding = 4 - (cbMacHdLen%4);
1489 uPadding %= 4;
1490 }
1491
1492 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1493
1494 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001495 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001496 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1497 }
1498 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1499
1500 //Set RrvTime/RTS/CTS Buffer
1501 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001502 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001503 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001504 }
1505 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001506 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001507 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001508 }
1509
Andres Moreceb8c5d2013-03-18 20:33:49 -05001510 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001511 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1512 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001513 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001514 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1515 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001516 //=========================
1517 // No Fragmentation
1518 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001519 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001520
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001521 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001522 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001523 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001524 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001525
Andres More1cac4a42013-03-18 20:33:50 -05001526 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001527
1528 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1529
1530 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001531 u8 * pbyIVHead;
1532 u8 * pbyPayloadHead;
1533 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001534 PSKeyItem pTransmitKey = NULL;
1535
Andres Moreb902fbf2013-02-25 20:32:51 -05001536 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1537 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001538 do {
1539 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001540 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001541 pbyBSSID = pDevice->abyBSSID;
1542 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001543 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001544 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001545 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001546 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1547 break;
1548 }
1549 } else {
1550 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1551 break;
1552 }
1553 }
1554 // get group key
1555 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001556 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001557 pTransmitKey = NULL;
1558 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1559 } else {
1560 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1561 }
Andres Moree269fc22013-02-12 20:36:29 -05001562 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001563 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001564 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001565 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001566
Jim Lieb3e362592009-08-12 14:54:11 -07001567 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001568 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001569 cbFrameBodySize);
1570 }
1571 else {
1572 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001573 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001574 }
1575
Andres More1cac4a42013-03-18 20:33:50 -05001576 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001577 pDevice->wSeqCounter++ ;
1578 if (pDevice->wSeqCounter > 0x0fff)
1579 pDevice->wSeqCounter = 0;
1580
1581 if (bIsPSPOLL) {
1582 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001583 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001584 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1585 // in the same place of other packet's Duration-field).
1586 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001587 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001588 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1589 tx_cts.tx.head.cts_g.data_head;
1590 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001591 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001592 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001593 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1594 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001595 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1596 tx_ab.tx.head.data_head_ab;
1597 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001598 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1599 }
Forest Bond92b96792009-06-13 07:38:31 -04001600 }
1601
Andres More3eaca0d2013-02-25 20:32:52 -05001602 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001603 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001604 pTX_Buffer->byType = 0x00;
1605
1606 pContext->pPacket = NULL;
1607 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001608 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001609
Andres More1cac4a42013-03-18 20:33:50 -05001610 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001611 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1612 &pMACHeader->addr1[0], (u16)cbFrameSize,
1613 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001614 }
1615 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001616 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1617 &pMACHeader->addr3[0], (u16)cbFrameSize,
1618 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001619 }
1620
1621 PIPEnsSendBulkOut(pDevice,pContext);
1622 return CMD_STATUS_PENDING;
1623}
1624
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001625CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1626 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001627{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001628 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001629 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001630 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1631 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001632 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001633 u16 wCurrentRate;
1634 u32 cbFrameBodySize;
1635 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001636 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001637 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001638
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001639 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001640 if (NULL == pContext) {
1641 status = CMD_STATUS_RESOURCES;
1642 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1643 return status ;
1644 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001645
1646 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001647 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001648
1649 cbFrameBodySize = pPacket->cbPayloadLen;
1650
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001651 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001652
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001653 if (pDevice->byBBType == BB_TYPE_11A) {
1654 wCurrentRate = RATE_6M;
1655
1656 /* Get SignalField,ServiceField,Length */
1657 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1658 PK_TYPE_11A, &short_head->ab);
1659
1660 /* Get Duration and TimeStampOff */
1661 short_head->duration = s_uGetDataDuration(pDevice,
1662 PK_TYPE_11A, false);
1663 short_head->time_stamp_off =
1664 vnt_time_stamp_off(pDevice, wCurrentRate);
1665 } else {
1666 wCurrentRate = RATE_1M;
1667 short_head->fifo_ctl |= FIFOCTL_11B;
1668
1669 /* Get SignalField,ServiceField,Length */
1670 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1671 PK_TYPE_11B, &short_head->ab);
1672
1673 /* Get Duration and TimeStampOff */
1674 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001675 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001676 short_head->time_stamp_off =
1677 vnt_time_stamp_off(pDevice, wCurrentRate);
1678 }
1679
Forest Bond92b96792009-06-13 07:38:31 -04001680
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001681 /* Generate Beacon Header */
1682 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001683
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001684 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1685
1686 pMACHeader->duration_id = 0;
1687 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1688 pDevice->wSeqCounter++;
1689 if (pDevice->wSeqCounter > 0x0fff)
1690 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001691
1692 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1693
Andres More3eaca0d2013-02-25 20:32:52 -05001694 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001695 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001696 pTX_Buffer->byType = 0x01;
1697
1698 pContext->pPacket = NULL;
1699 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001700 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001701
1702 PIPEnsSendBulkOut(pDevice,pContext);
1703 return CMD_STATUS_PENDING;
1704
1705}
1706
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001707void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1708{
1709 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001710 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001711 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001712 u8 byPktType;
1713 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001714 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001715 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001716 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001717 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001718 u32 cbFrameSize;
1719 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1720 u32 uPadding = 0;
1721 u32 cbMICHDR = 0, uLength = 0;
1722 u32 dwMICKey0, dwMICKey1;
1723 u32 dwMIC_Priority;
1724 u32 *pdwMIC_L, *pdwMIC_R;
1725 u16 wTxBufSize;
1726 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001727 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001728 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001729 u32 wCurrentRate = RATE_1M;
1730 PUWLAN_80211HDR p80211Header;
1731 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001732 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001733 SKeyItem STempKey;
1734 PSKeyItem pTransmitKey = NULL;
1735 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1736 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001737 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001738
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001739 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001740
1741 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1742 cbFrameBodySize = 0;
1743 }
1744 else {
1745 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1746 }
1747 p80211Header = (PUWLAN_80211HDR)skb->data;
1748
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001749 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001750
1751 if (NULL == pContext) {
1752 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1753 dev_kfree_skb_irq(skb);
1754 return ;
1755 }
1756
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001757 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001758 pTxBufHead = &pTX_Buffer->fifo_head;
1759 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1760 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001761
1762 if (pDevice->byBBType == BB_TYPE_11A) {
1763 wCurrentRate = RATE_6M;
1764 byPktType = PK_TYPE_11A;
1765 } else {
1766 wCurrentRate = RATE_1M;
1767 byPktType = PK_TYPE_11B;
1768 }
1769
1770 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1771 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1772 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1773 // to set power here.
1774 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1775 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1776 } else {
1777 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1778 }
1779
1780 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1781
1782 //Set packet type
1783 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1784 pTxBufHead->wFIFOCtl = 0;
1785 }
1786 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1787 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1788 }
1789 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1790 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1791 }
1792 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1793 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1794 }
1795
1796 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1797 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1798
Andres More22040bb2010-08-02 20:21:44 -03001799 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001800 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001801 if (pDevice->bEnableHostWEP) {
1802 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001803 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001804 }
Forest Bond92b96792009-06-13 07:38:31 -04001805 }
1806 else {
1807 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001808 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001809 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001810 }
Andres More4e9b5e22013-02-12 20:36:30 -05001811 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001812 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1813 };
1814
1815 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1816 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1817
1818 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1819 //Set Preamble type always long
1820 //pDevice->byPreambleType = PREAMBLE_LONG;
1821
1822 // probe-response don't retry
1823 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001824 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001825 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1826 //}
1827 }
1828
1829 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1830
1831 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001832 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001833 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1834 } else {
1835 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1836 }
1837
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001838 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001839 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1840
1841 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1842 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1843 }
1844
1845 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1846 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1847 }
1848
1849 if (cbExtSuppRate >0) {
1850 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1851 }
1852 }
1853
Forest Bond92b96792009-06-13 07:38:31 -04001854 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001855 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001856
1857 // Notes:
1858 // Although spec says MMPDU can be fragmented; In most case,
1859 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001860
Forest Bond92b96792009-06-13 07:38:31 -04001861 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1862 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1863 cbIVlen = 4;
1864 cbICVlen = 4;
1865 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1866 }
1867 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1868 cbIVlen = 8;//IV+ExtIV
1869 cbMIClen = 8;
1870 cbICVlen = 4;
1871 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1872 //We need to get seed here for filling TxKey entry.
1873 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1874 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1875 }
1876 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1877 cbIVlen = 8;//RSN Header
1878 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001879 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001880 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001881 }
1882 //MAC Header should be padding 0 to DW alignment.
1883 uPadding = 4 - (cbMacHdLen%4);
1884 uPadding %= 4;
1885 }
1886
1887 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1888
1889 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001890 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001891 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1892 }
1893 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1894
Forest Bond92b96792009-06-13 07:38:31 -04001895 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001896 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001897 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001898
1899 }
1900 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001901 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001902 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001903 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001904 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001905 &(p80211Header->sA3.abyAddr1[0]),
1906 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001907 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001908 &(p80211Header->sA3.abyAddr2[0]),
1909 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001910 //=========================
1911 // No Fragmentation
1912 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001913 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001914
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001915 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001916 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001917 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001918 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001919
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001920 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001921
1922 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1923
Andres Moreb902fbf2013-02-25 20:32:51 -05001924 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1925 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1926 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001927
1928 // Copy the Packet into a tx Buffer
1929 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1930
1931 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001932 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001933 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1934
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001935 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001936 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1937 if (cbExtSuppRate != 0) {
1938 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1939 memcpy((pbyPayloadHead + cbFrameBodySize),
1940 pMgmt->abyCurrSuppRates,
1941 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1942 );
1943 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1944 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1945 pMgmt->abyCurrExtSuppRates,
1946 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1947 );
1948 }
1949 }
1950
1951 // Set wep
1952 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1953
1954 if (pDevice->bEnableHostWEP) {
1955 pTransmitKey = &STempKey;
1956 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1957 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1958 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1959 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1960 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1961 memcpy(pTransmitKey->abyKey,
1962 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1963 pTransmitKey->uKeyLength
1964 );
1965 }
1966
1967 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1968
Andres More52a7e642013-02-25 20:32:53 -05001969 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1970 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001971
1972 // DO Software Michael
1973 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001974 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001975 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001976 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001977 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1978 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001979
1980 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1981
1982 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1983
Andres More52a7e642013-02-25 20:32:53 -05001984 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1985 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001986
1987 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1988 MIC_vUnInit();
1989
Andres More4e9b5e22013-02-12 20:36:30 -05001990 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001991 *pdwMIC_L = 0;
1992 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001993 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001994 }
1995
1996 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1997 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001998 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
1999 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002000
2001 }
2002
Malcolm Priestley3ba09382013-10-15 21:41:38 +01002003 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002004 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002005
2006 if (pDevice->bEnableHostWEP) {
2007 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2008 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2009 }
2010
2011 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002012 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002013 }
2014 }
2015
Andres More1cac4a42013-03-18 20:33:50 -05002016 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002017 pDevice->wSeqCounter++ ;
2018 if (pDevice->wSeqCounter > 0x0fff)
2019 pDevice->wSeqCounter = 0;
2020
Forest Bond92b96792009-06-13 07:38:31 -04002021 if (bIsPSPOLL) {
2022 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2023 // of FIFO control header.
2024 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2025 // in the same place of other packet's Duration-field).
2026 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002027 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002028 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2029 tx_cts.tx.head.cts_g.data_head;
2030 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002031 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002032 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002033 cpu_to_le16(p80211Header->sA2.wDurationID);
2034 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002035 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2036 tx_ab.tx.head.data_head_ab;
2037 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002038 cpu_to_le16(p80211Header->sA2.wDurationID);
2039 }
Forest Bond92b96792009-06-13 07:38:31 -04002040 }
2041
Andres More3eaca0d2013-02-25 20:32:52 -05002042 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002043 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002044 pTX_Buffer->byType = 0x00;
2045
2046 pContext->pPacket = skb;
2047 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002048 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002049
Andres More1cac4a42013-03-18 20:33:50 -05002050 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002051 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2052 &pMACHeader->addr1[0], (u16)cbFrameSize,
2053 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002054 }
2055 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002056 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2057 &pMACHeader->addr3[0], (u16)cbFrameSize,
2058 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002059 }
2060 PIPEnsSendBulkOut(pDevice,pContext);
2061 return ;
2062
2063}
2064
Forest Bond92b96792009-06-13 07:38:31 -04002065//TYPE_AC0DMA data tx
2066/*
2067 * Description:
2068 * Tx packet via AC0DMA(DMA1)
2069 *
2070 * Parameters:
2071 * In:
2072 * pDevice - Pointer to the adapter
2073 * skb - Pointer to tx skb packet
2074 * Out:
2075 * void
2076 *
2077 * Return Value: NULL
2078 */
2079
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002080int nsDMA_tx_packet(struct vnt_private *pDevice,
2081 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002082{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002083 struct net_device_stats *pStats = &pDevice->stats;
2084 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002085 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002086 u32 BytesToWrite = 0, uHeaderLen = 0;
2087 u32 uNodeIndex = 0;
2088 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2089 u16 wAID;
2090 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002091 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002092 PSKeyItem pTransmitKey = NULL;
2093 SKeyItem STempKey;
2094 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002095 int bTKIP_UseGTK = false;
2096 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002097 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002098 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002099 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002100 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002101 u32 status;
2102 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002103 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002104
Forest Bond92b96792009-06-13 07:38:31 -04002105 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2106
2107 if (pDevice->uAssocCount == 0) {
2108 dev_kfree_skb_irq(skb);
2109 return 0;
2110 }
2111
Andres Moreb902fbf2013-02-25 20:32:51 -05002112 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002113 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002114 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002115 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2116
2117 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2118 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2119 // set tx map
2120 pMgmt->abyPSTxMap[0] |= byMask[0];
2121 return 0;
2122 }
Masanari Iida93184692012-08-13 21:21:50 +09002123 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002124
2125 if (pDevice->byBBType != BB_TYPE_11A)
2126 pDevice->wCurrentRate = RATE_2M;
2127 else
2128 pDevice->wCurrentRate = RATE_24M;
2129 // long preamble type
2130 pDevice->byPreambleType = PREAMBLE_SHORT;
2131
2132 }else {
2133
Andres Moreb902fbf2013-02-25 20:32:51 -05002134 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002135
2136 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2137
2138 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2139
2140 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2141 // set tx map
2142 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2143 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2144 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2145 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2146
2147 return 0;
2148 }
2149 // AP rate decided from node
2150 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2151 // tx preamble decided from node
2152
2153 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2154 pDevice->byPreambleType = pDevice->byShortPreamble;
2155
2156 }else {
2157 pDevice->byPreambleType = PREAMBLE_LONG;
2158 }
Andres More4e9b5e22013-02-12 20:36:30 -05002159 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002160 }
2161 }
2162
Andres Moree269fc22013-02-12 20:36:29 -05002163 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002164 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2165 dev_kfree_skb_irq(skb);
2166 return 0;
2167 }
2168 }
2169
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002170 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002171
2172 if (pContext == NULL) {
2173 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2174 dev_kfree_skb_irq(skb);
2175 return STATUS_RESOURCES;
2176 }
2177
Andres Moreceb8c5d2013-03-18 20:33:49 -05002178 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002179
2180//mike add:station mode check eapol-key challenge--->
2181{
Andres Moreb902fbf2013-02-25 20:32:51 -05002182 u8 Protocol_Version; //802.1x Authentication
2183 u8 Packet_Type; //802.1x Authentication
2184 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002185 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002186
Charles Clément21ec51f2010-05-18 10:08:14 -07002187 Protocol_Version = skb->data[ETH_HLEN];
2188 Packet_Type = skb->data[ETH_HLEN+1];
2189 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2190 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 -05002191 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002192 /* 802.1x OR eapol-key challenge frame transfer */
2193 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2194 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002195 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002196 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2197 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2198 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002199 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002200 PRINT_K("WPA ");
2201 }
2202 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002203 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002204 PRINT_K("WPA2(re-keying) ");
2205 }
2206 PRINT_K("Authentication completed!!\n");
2207 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002208 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002209 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002210 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002211 PRINT_K("WPA2 Authentication completed!!\n");
2212 }
2213 }
2214 }
2215}
2216//mike add:station mode check eapol-key challenge<---
2217
Andres More4e9b5e22013-02-12 20:36:30 -05002218 if (pDevice->bEncryptionEnable == true) {
2219 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002220 // get Transmit key
2221 do {
2222 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2223 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2224 pbyBSSID = pDevice->abyBSSID;
2225 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002226 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002227 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002228 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2229 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002230 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2231 break;
2232 }
2233 } else {
2234 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2235 break;
2236 }
2237 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002238 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2239 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2241 for (ii = 0; ii< 6; ii++)
2242 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2244
2245 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002246 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002247 break;
2248 }
2249 // get group key
2250 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002251 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002252 pTransmitKey = NULL;
2253 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2254 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2255 }
2256 else
2257 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2258 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002259 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002260 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2261 }
Andres Moree269fc22013-02-12 20:36:29 -05002262 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002263 }
2264
2265 if (pDevice->bEnableHostWEP) {
2266 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002267 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002268 pTransmitKey = &STempKey;
2269 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2270 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2271 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2272 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2273 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2274 memcpy(pTransmitKey->abyKey,
2275 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2276 pTransmitKey->uKeyLength
2277 );
2278 }
2279 }
2280
Andres Moreb902fbf2013-02-25 20:32:51 -05002281 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002282
2283 if (pDevice->bFixRate) {
2284 if (pDevice->byBBType == BB_TYPE_11B) {
2285 if (pDevice->uConnectionRate >= RATE_11M) {
2286 pDevice->wCurrentRate = RATE_11M;
2287 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002288 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002289 }
2290 } else {
2291 if ((pDevice->byBBType == BB_TYPE_11A) &&
2292 (pDevice->uConnectionRate <= RATE_6M)) {
2293 pDevice->wCurrentRate = RATE_6M;
2294 } else {
2295 if (pDevice->uConnectionRate >= RATE_54M)
2296 pDevice->wCurrentRate = RATE_54M;
2297 else
Andres More3eaca0d2013-02-25 20:32:52 -05002298 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002299 }
2300 }
2301 }
2302 else {
2303 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2304 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002305 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002306 // Multicast use highest data rate
2307 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2308 // preamble type
2309 pDevice->byPreambleType = pDevice->byShortPreamble;
2310 }
2311 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002312 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002313 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2314 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2315 pDevice->byPreambleType = pDevice->byShortPreamble;
2316
2317 }
2318 else {
2319 pDevice->byPreambleType = PREAMBLE_LONG;
2320 }
2321 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2322 }
2323 else {
2324 if (pDevice->byBBType != BB_TYPE_11A)
2325 pDevice->wCurrentRate = RATE_2M;
2326 else
2327 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2328 // abyCurrExtSuppRates[]
2329 pDevice->byPreambleType = PREAMBLE_SHORT;
2330 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2331 }
2332 }
2333 }
2334 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2335 // Infra STA rate decided from AP Node, index = 0
2336 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2337 }
2338 }
2339
Andres Moreceb8c5d2013-03-18 20:33:49 -05002340 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002341 if (pDevice->byBBType != BB_TYPE_11A) {
2342 pDevice->wCurrentRate = RATE_1M;
2343 pDevice->byACKRate = RATE_1M;
2344 pDevice->byTopCCKBasicRate = RATE_1M;
2345 pDevice->byTopOFDMBasicRate = RATE_6M;
2346 } else {
2347 pDevice->wCurrentRate = RATE_6M;
2348 pDevice->byACKRate = RATE_6M;
2349 pDevice->byTopCCKBasicRate = RATE_1M;
2350 pDevice->byTopOFDMBasicRate = RATE_6M;
2351 }
2352 }
Forest Bond92b96792009-06-13 07:38:31 -04002353
Andres More0cbd8d92010-05-06 20:34:29 -03002354 DBG_PRT(MSG_LEVEL_DEBUG,
2355 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2356 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002357
2358 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002359 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002360 }
2361
2362 if (pDevice->wCurrentRate <= RATE_11M) {
2363 byPktType = PK_TYPE_11B;
2364 }
2365
Andres More4e9b5e22013-02-12 20:36:30 -05002366 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002367 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2368 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002369 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002371 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2372 if (pTransmitKey == NULL) {
2373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2374 }
2375 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002376 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002377 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2378 }
2379 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2381 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002382 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002383 }
2384 }
2385 }
2386
Forest Bond92b96792009-06-13 07:38:31 -04002387 if (pDevice->bEnableHostWEP) {
2388 if ((uNodeIndex != 0) &&
2389 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2391 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002392 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002393 }
2394 }
2395 }
2396 else {
2397
Forest Bond92b96792009-06-13 07:38:31 -04002398 if (pTransmitKey == NULL) {
2399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002400 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002401 dev_kfree_skb_irq(skb);
2402 pStats->tx_dropped++;
2403 return STATUS_FAILURE;
2404 }
Forest Bond92b96792009-06-13 07:38:31 -04002405 }
2406 }
2407
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002408 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2409
Forest Bond92b96792009-06-13 07:38:31 -04002410 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002411 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002412 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002413 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002414 pDevice->wCurrentRate,
2415 &uHeaderLen, &BytesToWrite
2416 );
2417
Andres Moree269fc22013-02-12 20:36:29 -05002418 if (fConvertedPacket == false) {
2419 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002420 dev_kfree_skb_irq(skb);
2421 return STATUS_FAILURE;
2422 }
2423
Andres More4e9b5e22013-02-12 20:36:30 -05002424 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002425 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002426 bScheduleCommand((void *) pDevice,
2427 WLAN_CMD_MAC_DISPOWERSAVING,
2428 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002429 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002430 }
2431 }
2432
Andres Moreb902fbf2013-02-25 20:32:51 -05002433 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002434 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002435
2436 pContext->pPacket = skb;
2437 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002438 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002439
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002440 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2441 &pContext->sEthHeader.h_dest[0],
2442 (u16)(BytesToWrite-uHeaderLen),
2443 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002444
2445 status = PIPEnsSendBulkOut(pDevice,pContext);
2446
Andres More4e9b5e22013-02-12 20:36:30 -05002447 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002448 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002449
Andres Moreb902fbf2013-02-25 20:32:51 -05002450 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002451 }
2452
2453 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002454 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002455 dev_kfree_skb_irq(skb);
2456 return STATUS_FAILURE;
2457 }
2458 else
2459 return 0;
2460
2461}
2462
Forest Bond92b96792009-06-13 07:38:31 -04002463/*
2464 * Description:
2465 * Relay packet send (AC1DMA) from rx dpc.
2466 *
2467 * Parameters:
2468 * In:
2469 * pDevice - Pointer to the adapter
2470 * pPacket - Pointer to rx packet
2471 * cbPacketSize - rx ethernet frame size
2472 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002473 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002474 *
Andres More4e9b5e22013-02-12 20:36:30 -05002475 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002476 */
2477
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002478int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2479 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002480{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002481 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002482 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002483 u32 BytesToWrite = 0, uHeaderLen = 0;
2484 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002485 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002486 SKeyItem STempKey;
2487 PSKeyItem pTransmitKey = NULL;
2488 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002489 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002490 u8 byPktTyp;
2491 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002492 u32 status;
2493 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002494
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002495 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002496
2497 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002498 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002499 }
2500
Andres Moreceb8c5d2013-03-18 20:33:49 -05002501 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002502
Andres More4e9b5e22013-02-12 20:36:30 -05002503 if (pDevice->bEncryptionEnable == true) {
2504 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002505 // get group key
2506 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002507 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002508 pTransmitKey = NULL;
2509 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2510 } else {
2511 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2512 }
2513 }
2514
2515 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002516 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002517 pTransmitKey = &STempKey;
2518 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2519 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2520 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2521 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2522 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2523 memcpy(pTransmitKey->abyKey,
2524 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2525 pTransmitKey->uKeyLength
2526 );
2527 }
2528 }
2529
2530 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002531 pContext->bBoolInUse = false;
2532 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002533 }
2534
Andres Moreb902fbf2013-02-25 20:32:51 -05002535 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002536
2537 if (pDevice->bFixRate) {
2538 if (pDevice->byBBType == BB_TYPE_11B) {
2539 if (pDevice->uConnectionRate >= RATE_11M) {
2540 pDevice->wCurrentRate = RATE_11M;
2541 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002542 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002543 }
2544 } else {
2545 if ((pDevice->byBBType == BB_TYPE_11A) &&
2546 (pDevice->uConnectionRate <= RATE_6M)) {
2547 pDevice->wCurrentRate = RATE_6M;
2548 } else {
2549 if (pDevice->uConnectionRate >= RATE_54M)
2550 pDevice->wCurrentRate = RATE_54M;
2551 else
Andres More3eaca0d2013-02-25 20:32:52 -05002552 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002553 }
2554 }
2555 }
2556 else {
2557 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2558 }
2559
Forest Bond92b96792009-06-13 07:38:31 -04002560 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002561 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002562 }
2563
2564 if (pDevice->wCurrentRate <= RATE_11M)
2565 byPktType = PK_TYPE_11B;
2566
Andres Moreabad19d2010-07-12 16:28:32 -03002567 BytesToWrite = uDataLen + ETH_FCS_LEN;
2568
Forest Bond92b96792009-06-13 07:38:31 -04002569 // Convert the packet to an usb frame and copy into our buffer
2570 // and send the irp.
2571
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002572 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2573
Forest Bond92b96792009-06-13 07:38:31 -04002574 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002575 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002576 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2577 pbySkbData, pTransmitKey, uNodeIndex,
2578 pDevice->wCurrentRate,
2579 &uHeaderLen, &BytesToWrite
2580 );
2581
Andres Moree269fc22013-02-12 20:36:29 -05002582 if (fConvertedPacket == false) {
2583 pContext->bBoolInUse = false;
2584 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002585 }
2586
Andres Moreb902fbf2013-02-25 20:32:51 -05002587 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002588 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002589
2590 pContext->pPacket = NULL;
2591 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002592 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002593
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002594 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2595 &pContext->sEthHeader.h_dest[0],
2596 (u16)(BytesToWrite - uHeaderLen),
2597 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002598
2599 status = PIPEnsSendBulkOut(pDevice,pContext);
2600
Andres More4e9b5e22013-02-12 20:36:30 -05002601 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002602}
2603