blob: 0e4b6fb2ec96e566bbd521e3337801c66b943732 [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;
144 struct vnt_usb_send_context *pReturnContext = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000145 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400146
147 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
148
149 for (ii = 0; ii < pDevice->cbTD; ii++) {
Malcolm Priestley18e35e082013-09-22 20:15:58 +0100150 if (!pDevice->apTD[ii])
151 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400152 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500153 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500154 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100155 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400156 pReturnContext = pContext;
157 break;
158 }
159 }
160 if ( ii == pDevice->cbTD ) {
161 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
162 }
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000163
164 return pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400165}
166
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000167static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
168 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400169{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000170 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400171
Andres More4b50fb42010-06-22 21:57:42 -0300172 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300174 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
176 else
177 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
178
179 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
180 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300181 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
182 pbyDestAddr,
183 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400184}
185
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100186static void s_vFillTxKey(struct vnt_private *pDevice,
187 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
188 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
189 struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400190{
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100191 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000192 u32 *pdwIV = (u32 *)pbyIVHead;
193 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500194 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000195 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400196
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100197 /* Fill TXKEY */
198 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100199 return;
Forest Bond92b96792009-06-13 07:38:31 -0400200
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100201 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
202 *pdwIV = pDevice->dwIVCounter;
203 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400204
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100205 switch (pTransmitKey->byCipherSuite) {
206 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100207 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
208 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
209 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
210 pTransmitKey->uKeyLength);
211 } else {
212 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
213 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
214 pTransmitKey->uKeyLength);
215 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
216 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
217 memcpy(pbyBuf+11, pTransmitKey->abyKey,
218 pTransmitKey->uKeyLength);
219 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100220
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100221 memcpy(pDevice->abyPRNG, pbyBuf, 16);
222 }
223 /* Append IV after Mac Header */
224 *pdwIV &= WEP_IV_MASK;
225 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
226 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100227
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100228 pDevice->dwIVCounter++;
229 if (pDevice->dwIVCounter > WEP_IV_MASK)
230 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100231
232 break;
233 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100234 pTransmitKey->wTSC15_0++;
235 if (pTransmitKey->wTSC15_0 == 0)
236 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100237
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100238 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
239 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
240 pDevice->abyPRNG);
241 memcpy(pbyBuf, pDevice->abyPRNG, 16);
242
243 /* Make IV */
244 memcpy(pdwIV, pDevice->abyPRNG, 3);
245
246 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
247 0xc0) | 0x20);
248 /* Append IV&ExtIV after Mac Header */
249 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
250
251 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
252 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
253
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100254 break;
255 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100256 pTransmitKey->wTSC15_0++;
257 if (pTransmitKey->wTSC15_0 == 0)
258 pTransmitKey->dwTSC47_16++;
259
260 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
261
262 /* Make IV */
263 *pdwIV = 0;
264 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
265 0xc0) | 0x20);
266
267 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
268
269 /* Append IV&ExtIV after Mac Header */
270 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
271
272 if (!mic_hdr)
273 return;
274
275 /* MICHDR0 */
276 mic_hdr->id = 0x59;
277 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
278 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
279
280 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
281 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
282
283 /* MICHDR1 */
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000284 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100285 mic_hdr->hlen = cpu_to_be16(28);
286 else
287 mic_hdr->hlen = cpu_to_be16(22);
288
289 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
290 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
291
292 /* MICHDR2 */
293 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
294 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100295 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100296 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100297
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000298 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100299 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
300 }
Forest Bond92b96792009-06-13 07:38:31 -0400301}
302
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000303static void s_vSWencryption(struct vnt_private *pDevice,
304 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400305{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000306 u32 cbICVlen = 4;
307 u32 dwICV = 0xffffffff;
308 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400309
310 if (pTransmitKey == NULL)
311 return;
312
313 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
314 //=======================================================================
315 // Append ICV after payload
316 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500317 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400318 // finally, we must invert dwCRC to get the correct answer
319 *pdwICV = cpu_to_le32(~dwICV);
320 // RC4 encryption
321 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
322 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
323 //=======================================================================
324 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
325 //=======================================================================
326 //Append ICV after payload
327 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500328 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400329 // finally, we must invert dwCRC to get the correct answer
330 *pdwICV = cpu_to_le32(~dwICV);
331 // RC4 encryption
332 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
333 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
334 //=======================================================================
335 }
336}
337
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100338static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
339{
340 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
341 [rate % MAX_RATE]);
342}
343
Forest Bond92b96792009-06-13 07:38:31 -0400344/*byPktType : PK_TYPE_11A 0
345 PK_TYPE_11B 1
346 PK_TYPE_11GB 2
347 PK_TYPE_11GA 3
348*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000349static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
350 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400351{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000352 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400353
354 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
355 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500356 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400357 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500358 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400359 }
360
361 if (bNeedAck) {
362 return (uDataTime + pDevice->uSIFS + uAckTime);
363 }
364 else {
365 return uDataTime;
366 }
367}
368
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100369static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
370 u32 frame_length, u16 rate, int need_ack)
371{
372 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
373 frame_length, rate, need_ack));
374}
375
Forest Bond92b96792009-06-13 07:38:31 -0400376//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100377static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000378 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400379{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000380 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400381
382 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
383
Forest Bond92b96792009-06-13 07:38:31 -0400384 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
385 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
386 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
387 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
388 }
389 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
390 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
391 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
392 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
393 }
394 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
395 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
396 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
397 }
398 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
399 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
400 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
401 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
402 return uRrvTime;
403 }
404
405 //RTSRrvTime
406 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100407 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400408}
409
410//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100411static u16 s_uGetDataDuration(struct vnt_private *pDevice,
412 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400413{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100414 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400415
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100416 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100417 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100418 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
419 byPktType, 14, pDevice->byTopCCKBasicRate);
420 else
421 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
422 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100423 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100424 }
Forest Bond92b96792009-06-13 07:38:31 -0400425
Forest Bond92b96792009-06-13 07:38:31 -0400426 return 0;
427}
428
Forest Bond92b96792009-06-13 07:38:31 -0400429//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100430static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000431 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
432 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400433{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000434 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400435
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100436 switch (byDurType) {
437 case RTSDUR_BB:
438 case RTSDUR_BA:
439 case RTSDUR_BA_F0:
440 case RTSDUR_BA_F1:
441 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
442 14, pDevice->byTopCCKBasicRate);
443 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
444 s_uGetTxRsvTime(pDevice, byPktType,
445 cbFrameLength, wRate, bNeedAck);
446 break;
Forest Bond92b96792009-06-13 07:38:31 -0400447
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100448 case RTSDUR_AA:
449 case RTSDUR_AA_F0:
450 case RTSDUR_AA_F1:
451 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
452 14, pDevice->byTopOFDMBasicRate);
453 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
454 s_uGetTxRsvTime(pDevice, byPktType,
455 cbFrameLength, wRate, bNeedAck);
456 break;
Forest Bond92b96792009-06-13 07:38:31 -0400457
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100458 case CTSDUR_BA:
459 case CTSDUR_BA_F0:
460 case CTSDUR_BA_F1:
461 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100462 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100463 break;
Forest Bond92b96792009-06-13 07:38:31 -0400464
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100465 default:
466 break;
467 }
Forest Bond92b96792009-06-13 07:38:31 -0400468
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100469 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400470}
471
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100472static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
473 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
474{
475 /* Get SignalField,ServiceField,Length */
476 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
477 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
478 PK_TYPE_11B, &buf->b);
479
480 /* Get Duration and TimeStamp */
481 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
482 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
483
484 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
485 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
486 priv->byTopCCKBasicRate);
487
488 return buf->wDuration_a;
489}
490
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100491static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
492 u16 rate, struct vnt_tx_datahead_g_fb *buf,
493 u32 frame_len, int need_ack)
494{
495 /* Get SignalField,ServiceField,Length */
496 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
497
498 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
499 PK_TYPE_11B, &buf->b);
500
501 /* Get Duration and TimeStamp */
502 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
503 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
504
505 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
506 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
507
508 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
509 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
510 priv->byTopCCKBasicRate);
511
512 return buf->wDuration_a;
513}
514
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100515static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
516 u16 rate, struct vnt_tx_datahead_a_fb *buf,
517 u32 frame_len, int need_ack)
518{
519 /* Get SignalField,ServiceField,Length */
520 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
521 /* Get Duration and TimeStampOff */
522 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
523
524 buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
525 buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
526
527 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
528
529 return buf->wDuration;
530}
531
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100532static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
533 u16 rate, struct vnt_tx_datahead_ab *buf,
534 u32 frame_len, int need_ack)
535{
536 /* Get SignalField,ServiceField,Length */
537 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
538 /* Get Duration and TimeStampOff */
539 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
540
541 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
542
543 return buf->wDuration;
544}
545
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100546static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
547 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
548 u16 duration)
549{
550 rts->duration = duration;
551 rts->frame_control = TYPE_CTL_RTS;
552
553 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
554 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
555 else
556 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
557
558 if (priv->eOPMode == OP_MODE_AP)
559 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
560 else
561 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
562
563 return 0;
564}
565
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100566static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100567 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
568 u8 pkt_type, u32 frame_len, int need_ack,
569 u16 current_rate, u8 fb_option)
570{
571 u16 rts_frame_len = 20;
572
573 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
574 PK_TYPE_11B, &buf->b);
575 BBvCalculateParameter(priv, rts_frame_len,
576 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
577
578 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
579 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
580 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
581 pkt_type, current_rate, need_ack, fb_option);
582 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
583 pkt_type, current_rate, need_ack, fb_option);
584
585 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
586
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100587 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
588 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100589}
590
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100591static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100592 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
593 u8 pkt_type, u32 frame_len, int need_ack,
594 u16 current_rate, u8 fb_option)
595{
596 u16 rts_frame_len = 20;
597
598 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
599 PK_TYPE_11B, &buf->b);
600 BBvCalculateParameter(priv, rts_frame_len,
601 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
602
603
604 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
605 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
606 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
607 pkt_type, current_rate, need_ack, fb_option);
608 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
609 pkt_type, current_rate, need_ack, fb_option);
610
611
612 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_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_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100615 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100616 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_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 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100619 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100620
621 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
622
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100623 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
624 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100625}
626
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100627static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100628 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
629 u8 pkt_type, u32 frame_len, int need_ack,
630 u16 current_rate, u8 fb_option)
631{
632 u16 rts_frame_len = 20;
633
634 BBvCalculateParameter(priv, rts_frame_len,
635 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
636
637 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
638 pkt_type, current_rate, need_ack, fb_option);
639
640 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
641
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100642 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
643 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100644}
645
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100646static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100647 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
648 u8 pkt_type, u32 frame_len, int need_ack,
649 u16 current_rate, u8 fb_option)
650{
651 u16 rts_frame_len = 20;
652
653 BBvCalculateParameter(priv, rts_frame_len,
654 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
655
656 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
657 pkt_type, current_rate, need_ack, fb_option);
658
659 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100660 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100661
662 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100663 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100664
665 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
666
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100667 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
668 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100669}
670
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100671static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100672 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500673 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400674{
Forest Bond92b96792009-06-13 07:38:31 -0400675
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100676 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100677 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400678
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100679 /* Note: So far RTSHead doesn't appear in ATIM
680 * & Beacom DMA, so we don't need to take them
681 * into account.
682 * Otherwise, we need to modified codes for them.
683 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100684 switch (byPktType) {
685 case PK_TYPE_11GB:
686 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100687 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100688 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100689 psEthHeader, byPktType, cbFrameLength,
690 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100691 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100692 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100693 psEthHeader, byPktType, cbFrameLength,
694 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100695 break;
696 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100697 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100698 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100699 psEthHeader, byPktType, cbFrameLength,
700 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100701 break;
702 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100703 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100704 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100705 psEthHeader, byPktType, cbFrameLength,
706 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100707 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100708
709 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400710}
711
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100712static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100713 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
714 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400715{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000716 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400717
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100718 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100719 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400720
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100721 if (byFBOption != AUTO_FB_NONE) {
722 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100723 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100724 /* Get SignalField,ServiceField,Length */
725 BBvCalculateParameter(pDevice, uCTSFrameLen,
726 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100727 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
728 cbFrameLength, byPktType,
729 wCurrentRate, bNeedAck, byFBOption);
730 /* Get CTSDuration_ba_f0 */
731 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100732 CTSDUR_BA_F0, cbFrameLength, byPktType,
733 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100734 /* Get CTSDuration_ba_f1 */
735 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100736 CTSDUR_BA_F1, cbFrameLength, byPktType,
737 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100738 /* Get CTS Frame body */
739 pBuf->data.duration = pBuf->wDuration_ba;
740 pBuf->data.frame_control = TYPE_CTL_CTS;
741 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100742
743 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
744 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100745 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100746 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100747 /* Get SignalField,ServiceField,Length */
748 BBvCalculateParameter(pDevice, uCTSFrameLen,
749 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100750 /* Get CTSDuration_ba */
751 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
752 CTSDUR_BA, cbFrameLength, byPktType,
753 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100754 /*Get CTS Frame body*/
755 pBuf->data.duration = pBuf->wDuration_ba;
756 pBuf->data.frame_control = TYPE_CTL_CTS;
757 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100758
759 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
760 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400761 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100762
763 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400764}
765
Forest Bond92b96792009-06-13 07:38:31 -0400766/*+
767 *
768 * Description:
769 * Generate FIFO control for MAC & Baseband controller
770 *
771 * Parameters:
772 * In:
773 * pDevice - Pointer to adpater
774 * pTxDataHead - Transmit Data Buffer
775 * pTxBufHead - pTxBufHead
776 * pvRrvTime - pvRrvTime
777 * pvRTS - RTS Buffer
778 * pCTS - CTS Buffer
779 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
780 * bNeedACK - If need ACK
781 * uDMAIdx - DMA Index
782 * Out:
783 * none
784 *
785 * Return Value: none
786 *
787-*/
Andres Morecc856e62010-05-17 21:34:01 -0300788
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100789static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100790 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100791 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
792 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400793{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100794 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100795 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000796 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000797 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400798
Malcolm Priestley92928f12013-10-07 20:14:01 +0100799 pFifoHead->wReserved = wCurrentRate;
800 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400801
Malcolm Priestley92928f12013-10-07 20:14:01 +0100802 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
803 byFBOption = AUTO_FB_0;
804 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
805 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400806
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100807 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100808 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100809
Malcolm Priestley92928f12013-10-07 20:14:01 +0100810 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
811 if (need_rts) {
812 struct vnt_rrv_time_rts *pBuf =
813 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100814
Malcolm Priestley92928f12013-10-07 20:14:01 +0100815 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
816 byPktType, cbFrameSize, wCurrentRate);
817 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
818 byPktType, cbFrameSize, wCurrentRate);
819 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100820 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100821
Malcolm Priestley92928f12013-10-07 20:14:01 +0100822 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
823 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
824 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
825 PK_TYPE_11B, cbFrameSize,
826 pDevice->byTopCCKBasicRate, bNeedACK);
827
828 if (need_mic) {
829 *mic_hdr = &tx_buffer->
830 tx_head.tx_rts.tx.mic.hdr;
831 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
832 } else {
833 head = &tx_buffer->tx_head.tx_rts.tx.head;
834 }
835
836 /* Fill RTS */
837 return s_vFillRTSHead(pDevice, byPktType, head,
838 cbFrameSize, bNeedACK, psEthHeader,
839 wCurrentRate, byFBOption);
840
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100841 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100842 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
843 tx_head.tx_cts.cts;
844
845 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
846 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
847 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
848 PK_TYPE_11B, cbFrameSize,
849 pDevice->byTopCCKBasicRate, bNeedACK);
850
851 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
852 byPktType, cbFrameSize, wCurrentRate);
853
854 if (need_mic) {
855 *mic_hdr = &tx_buffer->
856 tx_head.tx_cts.tx.mic.hdr;
857 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
858 } else {
859 head = &tx_buffer->tx_head.tx_cts.tx.head;
860 }
861
862 /* Fill CTS */
863 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
864 head, cbFrameSize, bNeedACK, wCurrentRate,
865 byFBOption);
866 }
867 } else if (byPktType == PK_TYPE_11A) {
868 if (need_mic) {
869 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
870 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
871 } else {
872 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100873 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100874
Malcolm Priestley92928f12013-10-07 20:14:01 +0100875 if (need_rts) {
876 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
877 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100878
Malcolm Priestley92928f12013-10-07 20:14:01 +0100879 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100880 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100881
Malcolm Priestley92928f12013-10-07 20:14:01 +0100882 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
883 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
884
885 /* Fill RTS */
886 return s_vFillRTSHead(pDevice, byPktType, head,
887 cbFrameSize, bNeedACK, psEthHeader,
888 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100889 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100890 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
891 tx_head.tx_ab.ab;
892
893 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
894 PK_TYPE_11A, cbFrameSize,
895 wCurrentRate, bNeedACK);
896
897 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
898 wCurrentRate, &head->data_head_a_fb,
899 cbFrameSize, bNeedACK);
900 }
901 } else if (byPktType == PK_TYPE_11B) {
902 if (need_mic) {
903 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
904 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
905 } else {
906 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100907 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100908
Malcolm Priestley92928f12013-10-07 20:14:01 +0100909 if (need_rts) {
910 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
911 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100912
Malcolm Priestley92928f12013-10-07 20:14:01 +0100913 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100914 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100915
Malcolm Priestley92928f12013-10-07 20:14:01 +0100916 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
917 PK_TYPE_11B, cbFrameSize, wCurrentRate,
918 bNeedACK);
919
920 /* Fill RTS */
921 return s_vFillRTSHead(pDevice, byPktType, head,
922 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100923 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100924 } else {
925 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
926 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100927
Malcolm Priestley92928f12013-10-07 20:14:01 +0100928 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
929 PK_TYPE_11B, cbFrameSize,
930 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100931
Malcolm Priestley92928f12013-10-07 20:14:01 +0100932 return vnt_rxtx_datahead_ab(pDevice, byPktType,
933 wCurrentRate, &head->data_head_ab,
934 cbFrameSize, bNeedACK);
935 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100936 }
937
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100938 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400939}
940/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500941 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500942 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300943 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400944*/
945
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000946static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100947 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100948 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
949 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
950 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400951{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100952 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000953 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
954 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000955 u32 cb802_1_H_len;
956 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
957 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100958 int bNeedACK;
959 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000960 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
961 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
962 u8 abySNAP_Bridgetunnel[ETH_ALEN]
963 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
964 u32 uDuration;
965 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100966 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000967 u8 byFBOption = AUTO_FB_NONE, byFragType;
968 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100969 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000970 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500971 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100972
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100973 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400974
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000975 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500976 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
977 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000978 }
Forest Bond92b96792009-06-13 07:38:31 -0400979
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000980 /* Get pkt type */
981 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
982 cb802_1_H_len = 8;
983 else
984 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400985
Charles Clément21ec51f2010-05-18 10:08:14 -0700986 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400987
988 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500989 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400990
Andres More22040bb2010-08-02 20:21:44 -0300991 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000992 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500993 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500994 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -0300995 pTxBufHead->wFIFOCtl =
996 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
997 } else {
Andres More4e9b5e22013-02-12 20:36:30 -0500998 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -0300999 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1000 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001001 } else {
1002 /* MSDUs in Infra mode always need ACK */
1003 bNeedACK = true;
1004 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1005 }
Forest Bond92b96792009-06-13 07:38:31 -04001006
1007 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1008
Forest Bond92b96792009-06-13 07:38:31 -04001009 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001010 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1011
Andres More3eaca0d2013-02-25 20:32:52 -05001012 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001013
1014 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001015 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001016 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1017 }
1018
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001019 /* Set Auto Fallback Ctl */
1020 if (wCurrentRate >= RATE_18M) {
1021 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1022 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1023
1024 pDevice->tx_rate_fb0 =
1025 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1026 pDevice->tx_rate_fb1 =
1027 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1028
1029 byFBOption = AUTO_FB_0;
1030 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1031 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1032 pDevice->tx_rate_fb0 =
1033 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1034 pDevice->tx_rate_fb1 =
1035 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1036
1037 byFBOption = AUTO_FB_1;
1038 }
1039 }
Forest Bond92b96792009-06-13 07:38:31 -04001040
Andres More4e9b5e22013-02-12 20:36:30 -05001041 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001042 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1043 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1044 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1045 }
1046 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1047 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1048 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1049 }
1050 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1051 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1052 }
1053 }
1054 }
1055
Forest Bond92b96792009-06-13 07:38:31 -04001056 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1057 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1058 cbIVlen = 4;
1059 cbICVlen = 4;
1060 }
1061 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1062 cbIVlen = 8;//IV+ExtIV
1063 cbMIClen = 8;
1064 cbICVlen = 4;
1065 }
1066 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1067 cbIVlen = 8;//RSN Header
1068 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001069 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001070 }
Andres Moree269fc22013-02-12 20:36:29 -05001071 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001072 //MAC Header should be padding 0 to DW alignment.
1073 uPadding = 4 - (cbMACHdLen%4);
1074 uPadding %= 4;
1075 }
1076 }
1077
1078 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1079
Andres Moree269fc22013-02-12 20:36:29 -05001080 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1081 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001082 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001083 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001084 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1085 }
1086
Andres Moreb902fbf2013-02-25 20:32:51 -05001087 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001088 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1089
Forest Bond92b96792009-06-13 07:38:31 -04001090 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1091 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001092 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001093 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001094 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001095 }
1096 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001097 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001098 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001099 }
1100 } else {
1101 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001102 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001103 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001104 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001105 }
Andres Moree269fc22013-02-12 20:36:29 -05001106 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001107 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001108 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001109 }
1110 } // Auto Fall Back
1111 }
1112 else {//802.11a/b packet
1113 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001114 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001115 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001116 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001117 }
Andres Moree269fc22013-02-12 20:36:29 -05001118 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001119 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001120 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001121 }
1122 } else {
1123 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001124 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001125 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001126 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001127 }
Andres Moree269fc22013-02-12 20:36:29 -05001128 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001129 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001130 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001131 }
1132 } // Auto Fall Back
1133 }
1134
Andres Moreb902fbf2013-02-25 20:32:51 -05001135 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1136 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1137 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001138
Forest Bond92b96792009-06-13 07:38:31 -04001139 //=========================
1140 // No Fragmentation
1141 //=========================
1142 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1143 byFragType = FRAGCTL_NONFRAG;
1144 //uDMAIdx = TYPE_AC0DMA;
1145 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1146
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001147 /* Fill FIFO, RrvTime, RTS and CTS */
1148 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1149 tx_buffer, &pMICHDR, cbMICHDR,
1150 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001151
Forest Bond92b96792009-06-13 07:38:31 -04001152 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001153 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001154 byFragType, uDMAIdx, 0);
1155
Andres More4e9b5e22013-02-12 20:36:30 -05001156 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001157 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001158 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001159 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001160
1161 if (pDevice->bEnableHostWEP) {
1162 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1163 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1164 }
1165 }
1166
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001167 /* 802.1H */
1168 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001169 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001170 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001171 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001172 abySNAP_Bridgetunnel, 6);
1173 else
1174 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001175
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001176 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001177
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001178 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1179 }
Forest Bond92b96792009-06-13 07:38:31 -04001180
Forest Bond92b96792009-06-13 07:38:31 -04001181 if (pPacket != NULL) {
1182 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001183 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001184 (pPacket + ETH_HLEN),
1185 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001186 );
1187
1188 } else {
1189 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001190 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001191 }
1192
Andres More4e9b5e22013-02-12 20:36:30 -05001193 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001194
1195 ///////////////////////////////////////////////////////////////////
1196
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001197 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1198 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1199 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1200 }
Forest Bond92b96792009-06-13 07:38:31 -04001201 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001202 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1203 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001204 }
1205 else {
Andres More52a7e642013-02-25 20:32:53 -05001206 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1207 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001208 }
1209 // DO Software Michael
1210 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001211 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001212 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001213 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1215 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001216
1217 ///////////////////////////////////////////////////////////////////
1218
1219 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1220 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001221 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001222 //}
1223 //DBG_PRN_GRP12(("\n\n\n"));
1224
1225 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1226
Andres More52a7e642013-02-25 20:32:53 -05001227 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1228 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001229
1230 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1231 MIC_vUnInit();
1232
Andres More4e9b5e22013-02-12 20:36:30 -05001233 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001234 *pdwMIC_L = 0;
1235 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001236 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001237 }
1238 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1239 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1240 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1241 }
1242
Andres More4e9b5e22013-02-12 20:36:30 -05001243 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001244
Andres More3eaca0d2013-02-25 20:32:52 -05001245 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001246
Andres More4e9b5e22013-02-12 20:36:30 -05001247 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1248 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1249 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001250 cbFrameSize -= cbICVlen;
1251 }
1252
Forest Bond92b96792009-06-13 07:38:31 -04001253 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001254
1255 *pcbHeaderLen = cbHeaderLength;
1256 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1257
Forest Bond92b96792009-06-13 07:38:31 -04001258 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001259 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001260
Andres More4e9b5e22013-02-12 20:36:30 -05001261 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001262
1263}
1264
Forest Bond92b96792009-06-13 07:38:31 -04001265/*+
1266 *
1267 * Description:
1268 * Translate 802.3 to 802.11 header
1269 *
1270 * Parameters:
1271 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001272 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001273 * dwTxBufferAddr - Transmit Buffer
1274 * pPacket - Packet from upper layer
1275 * cbPacketSize - Transmit Data Length
1276 * Out:
1277 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1278 * pcbAppendPayload - size of append payload for 802.1H translation
1279 *
1280 * Return Value: none
1281 *
1282-*/
1283
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001284static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001285 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001286 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001287{
Andres More1cac4a42013-03-18 20:33:50 -05001288 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001289
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001290 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001291
1292 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001293 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001294 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001295 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001296 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1297 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001298 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001299 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001300 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001301 } else {
1302 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001303 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001304 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001305 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001306 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001307 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001308 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001309 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001310 &(pDevice->abyBSSID[0]),
1311 ETH_ALEN);
1312 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001313 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001314 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001315 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001316 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001317 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001318 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001319 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001320 &(pDevice->abyBSSID[0]),
1321 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001322 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001323 }
1324 }
1325
1326 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001327 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001328
Andres More1cac4a42013-03-18 20:33:50 -05001329 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001330
Andres More1cac4a42013-03-18 20:33:50 -05001331 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001332
1333 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001334 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001335
1336 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1337 pDevice->wSeqCounter++;
1338 if (pDevice->wSeqCounter > 0x0fff)
1339 pDevice->wSeqCounter = 0;
1340 }
1341
1342 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001343 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001344 }
1345}
1346
Forest Bond92b96792009-06-13 07:38:31 -04001347/*+
1348 *
1349 * Description:
1350 * Request instructs a MAC to transmit a 802.11 management packet through
1351 * the adapter onto the medium.
1352 *
1353 * Parameters:
1354 * In:
1355 * hDeviceContext - Pointer to the adapter
1356 * pPacket - A pointer to a descriptor for the packet to transmit
1357 * Out:
1358 * none
1359 *
Andres Moree269fc22013-02-12 20:36:29 -05001360 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001361 *
1362-*/
1363
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001364CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1365 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001366{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001367 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001368 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001369 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001370 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001371 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001372 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001373 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001374 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001375 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001376 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001377 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1378 u32 uPadding = 0;
1379 u16 wTxBufSize;
1380 u32 cbMacHdLen;
1381 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001382
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001383 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001384
1385 if (NULL == pContext) {
1386 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1387 return CMD_STATUS_RESOURCES;
1388 }
1389
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001390 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001391 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001392 pTxBufHead = &pTX_Buffer->fifo_head;
1393 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1394 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001395
1396 if (pDevice->byBBType == BB_TYPE_11A) {
1397 wCurrentRate = RATE_6M;
1398 byPktType = PK_TYPE_11A;
1399 } else {
1400 wCurrentRate = RATE_1M;
1401 byPktType = PK_TYPE_11B;
1402 }
1403
1404 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1405 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1406 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1407 // to set power here.
1408 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1409 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1410 } else {
1411 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1412 }
1413 pDevice->wCurrentRate = wCurrentRate;
1414
Forest Bond92b96792009-06-13 07:38:31 -04001415 //Set packet type
1416 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1417 pTxBufHead->wFIFOCtl = 0;
1418 }
1419 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1420 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1421 }
1422 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1423 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1424 }
1425 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1426 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1427 }
1428
1429 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1430 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1431
Andres More22040bb2010-08-02 20:21:44 -03001432 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001433 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001434 }
1435 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001436 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001437 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1438 };
1439
1440 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1441 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1442
1443 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1444 //Set Preamble type always long
1445 //pDevice->byPreambleType = PREAMBLE_LONG;
1446 // probe-response don't retry
1447 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001448 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001449 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1450 //}
1451 }
1452
1453 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1454
1455 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001456 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001457 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1458 } else {
1459 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1460 }
1461
1462 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001463 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001464
1465 // Notes:
1466 // Although spec says MMPDU can be fragmented; In most case,
1467 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001468
1469 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1470 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1471 cbIVlen = 4;
1472 cbICVlen = 4;
1473 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1474 }
1475 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1476 cbIVlen = 8;//IV+ExtIV
1477 cbMIClen = 8;
1478 cbICVlen = 4;
1479 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1480 //We need to get seed here for filling TxKey entry.
1481 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1482 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1483 }
1484 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1485 cbIVlen = 8;//RSN Header
1486 cbICVlen = 8;//MIC
1487 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001488 }
1489 //MAC Header should be padding 0 to DW alignment.
1490 uPadding = 4 - (cbMacHdLen%4);
1491 uPadding %= 4;
1492 }
1493
1494 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1495
1496 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001497 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001498 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1499 }
1500 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1501
1502 //Set RrvTime/RTS/CTS Buffer
1503 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001504 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001505 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001506 }
1507 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001508 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001509 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001510 }
1511
Andres Moreceb8c5d2013-03-18 20:33:49 -05001512 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001513 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1514 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001515 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001516 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1517 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001518 //=========================
1519 // No Fragmentation
1520 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001521 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001522
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001523 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001524 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001525 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001526 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001527
Andres More1cac4a42013-03-18 20:33:50 -05001528 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001529
1530 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1531
1532 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001533 u8 * pbyIVHead;
1534 u8 * pbyPayloadHead;
1535 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001536 PSKeyItem pTransmitKey = NULL;
1537
Andres Moreb902fbf2013-02-25 20:32:51 -05001538 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1539 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001540 do {
1541 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001542 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001543 pbyBSSID = pDevice->abyBSSID;
1544 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001545 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001546 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001547 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001548 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1549 break;
1550 }
1551 } else {
1552 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1553 break;
1554 }
1555 }
1556 // get group key
1557 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001558 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001559 pTransmitKey = NULL;
1560 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1561 } else {
1562 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1563 }
Andres Moree269fc22013-02-12 20:36:29 -05001564 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001565 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001566 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001567 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001568
Jim Lieb3e362592009-08-12 14:54:11 -07001569 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001570 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001571 cbFrameBodySize);
1572 }
1573 else {
1574 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001575 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001576 }
1577
Andres More1cac4a42013-03-18 20:33:50 -05001578 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001579 pDevice->wSeqCounter++ ;
1580 if (pDevice->wSeqCounter > 0x0fff)
1581 pDevice->wSeqCounter = 0;
1582
1583 if (bIsPSPOLL) {
1584 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001585 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001586 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1587 // in the same place of other packet's Duration-field).
1588 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001589 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001590 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1591 tx_cts.tx.head.cts_g.data_head;
1592 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001593 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001594 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001595 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1596 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001597 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1598 tx_ab.tx.head.data_head_ab;
1599 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001600 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1601 }
Forest Bond92b96792009-06-13 07:38:31 -04001602 }
1603
Andres More3eaca0d2013-02-25 20:32:52 -05001604 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001605 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001606 pTX_Buffer->byType = 0x00;
1607
1608 pContext->pPacket = NULL;
1609 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001610 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001611
Andres More1cac4a42013-03-18 20:33:50 -05001612 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001613 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1614 &pMACHeader->addr1[0], (u16)cbFrameSize,
1615 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001616 }
1617 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001618 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1619 &pMACHeader->addr3[0], (u16)cbFrameSize,
1620 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001621 }
1622
1623 PIPEnsSendBulkOut(pDevice,pContext);
1624 return CMD_STATUS_PENDING;
1625}
1626
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001627CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1628 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001629{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001630 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001631 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001632 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1633 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001634 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001635 u16 wCurrentRate;
1636 u32 cbFrameBodySize;
1637 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001638 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001639 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001640
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001641 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001642 if (NULL == pContext) {
1643 status = CMD_STATUS_RESOURCES;
1644 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1645 return status ;
1646 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001647
1648 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001649 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001650
1651 cbFrameBodySize = pPacket->cbPayloadLen;
1652
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001653 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001654
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001655 if (pDevice->byBBType == BB_TYPE_11A) {
1656 wCurrentRate = RATE_6M;
1657
1658 /* Get SignalField,ServiceField,Length */
1659 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1660 PK_TYPE_11A, &short_head->ab);
1661
1662 /* Get Duration and TimeStampOff */
1663 short_head->duration = s_uGetDataDuration(pDevice,
1664 PK_TYPE_11A, false);
1665 short_head->time_stamp_off =
1666 vnt_time_stamp_off(pDevice, wCurrentRate);
1667 } else {
1668 wCurrentRate = RATE_1M;
1669 short_head->fifo_ctl |= FIFOCTL_11B;
1670
1671 /* Get SignalField,ServiceField,Length */
1672 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1673 PK_TYPE_11B, &short_head->ab);
1674
1675 /* Get Duration and TimeStampOff */
1676 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001677 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001678 short_head->time_stamp_off =
1679 vnt_time_stamp_off(pDevice, wCurrentRate);
1680 }
1681
Forest Bond92b96792009-06-13 07:38:31 -04001682
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001683 /* Generate Beacon Header */
1684 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001685
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001686 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1687
1688 pMACHeader->duration_id = 0;
1689 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1690 pDevice->wSeqCounter++;
1691 if (pDevice->wSeqCounter > 0x0fff)
1692 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001693
1694 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1695
Andres More3eaca0d2013-02-25 20:32:52 -05001696 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001697 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001698 pTX_Buffer->byType = 0x01;
1699
1700 pContext->pPacket = NULL;
1701 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001702 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001703
1704 PIPEnsSendBulkOut(pDevice,pContext);
1705 return CMD_STATUS_PENDING;
1706
1707}
1708
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001709void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1710{
1711 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001712 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001713 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001714 u8 byPktType;
1715 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001716 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001717 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001718 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001719 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001720 u32 cbFrameSize;
1721 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1722 u32 uPadding = 0;
1723 u32 cbMICHDR = 0, uLength = 0;
1724 u32 dwMICKey0, dwMICKey1;
1725 u32 dwMIC_Priority;
1726 u32 *pdwMIC_L, *pdwMIC_R;
1727 u16 wTxBufSize;
1728 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001729 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001730 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001731 u32 wCurrentRate = RATE_1M;
1732 PUWLAN_80211HDR p80211Header;
1733 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001734 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001735 SKeyItem STempKey;
1736 PSKeyItem pTransmitKey = NULL;
1737 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1738 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001739 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001740
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001741 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001742
1743 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1744 cbFrameBodySize = 0;
1745 }
1746 else {
1747 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1748 }
1749 p80211Header = (PUWLAN_80211HDR)skb->data;
1750
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001751 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001752
1753 if (NULL == pContext) {
1754 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1755 dev_kfree_skb_irq(skb);
1756 return ;
1757 }
1758
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001759 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001760 pTxBufHead = &pTX_Buffer->fifo_head;
1761 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1762 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001763
1764 if (pDevice->byBBType == BB_TYPE_11A) {
1765 wCurrentRate = RATE_6M;
1766 byPktType = PK_TYPE_11A;
1767 } else {
1768 wCurrentRate = RATE_1M;
1769 byPktType = PK_TYPE_11B;
1770 }
1771
1772 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1773 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1774 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1775 // to set power here.
1776 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1777 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1778 } else {
1779 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1780 }
1781
1782 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1783
1784 //Set packet type
1785 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1786 pTxBufHead->wFIFOCtl = 0;
1787 }
1788 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1789 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1790 }
1791 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1792 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1793 }
1794 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1795 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1796 }
1797
1798 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1799 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1800
Andres More22040bb2010-08-02 20:21:44 -03001801 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001802 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001803 if (pDevice->bEnableHostWEP) {
1804 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001805 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001806 }
Forest Bond92b96792009-06-13 07:38:31 -04001807 }
1808 else {
1809 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001810 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001811 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001812 }
Andres More4e9b5e22013-02-12 20:36:30 -05001813 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001814 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1815 };
1816
1817 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1818 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1819
1820 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1821 //Set Preamble type always long
1822 //pDevice->byPreambleType = PREAMBLE_LONG;
1823
1824 // probe-response don't retry
1825 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001826 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001827 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1828 //}
1829 }
1830
1831 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1832
1833 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001834 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001835 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1836 } else {
1837 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1838 }
1839
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001840 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001841 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1842
1843 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1844 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1845 }
1846
1847 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1848 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1849 }
1850
1851 if (cbExtSuppRate >0) {
1852 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1853 }
1854 }
1855
Forest Bond92b96792009-06-13 07:38:31 -04001856 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001857 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001858
1859 // Notes:
1860 // Although spec says MMPDU can be fragmented; In most case,
1861 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001862
Forest Bond92b96792009-06-13 07:38:31 -04001863 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1864 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1865 cbIVlen = 4;
1866 cbICVlen = 4;
1867 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1868 }
1869 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1870 cbIVlen = 8;//IV+ExtIV
1871 cbMIClen = 8;
1872 cbICVlen = 4;
1873 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1874 //We need to get seed here for filling TxKey entry.
1875 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1876 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1877 }
1878 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1879 cbIVlen = 8;//RSN Header
1880 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001881 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001882 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001883 }
1884 //MAC Header should be padding 0 to DW alignment.
1885 uPadding = 4 - (cbMacHdLen%4);
1886 uPadding %= 4;
1887 }
1888
1889 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1890
1891 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001892 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001893 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1894 }
1895 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1896
Forest Bond92b96792009-06-13 07:38:31 -04001897 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001898 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001899 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001900
1901 }
1902 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001903 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001904 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001905 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001906 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001907 &(p80211Header->sA3.abyAddr1[0]),
1908 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001909 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001910 &(p80211Header->sA3.abyAddr2[0]),
1911 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001912 //=========================
1913 // No Fragmentation
1914 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001915 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001916
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001917 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001918 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001919 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001920 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001921
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001922 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001923
1924 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1925
Andres Moreb902fbf2013-02-25 20:32:51 -05001926 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1927 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1928 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001929
1930 // Copy the Packet into a tx Buffer
1931 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1932
1933 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001934 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001935 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1936
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001937 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001938 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1939 if (cbExtSuppRate != 0) {
1940 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1941 memcpy((pbyPayloadHead + cbFrameBodySize),
1942 pMgmt->abyCurrSuppRates,
1943 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1944 );
1945 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1946 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1947 pMgmt->abyCurrExtSuppRates,
1948 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1949 );
1950 }
1951 }
1952
1953 // Set wep
1954 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1955
1956 if (pDevice->bEnableHostWEP) {
1957 pTransmitKey = &STempKey;
1958 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1959 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1960 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1961 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1962 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1963 memcpy(pTransmitKey->abyKey,
1964 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1965 pTransmitKey->uKeyLength
1966 );
1967 }
1968
1969 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1970
Andres More52a7e642013-02-25 20:32:53 -05001971 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1972 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001973
1974 // DO Software Michael
1975 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001976 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001977 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001978 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001979 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1980 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001981
1982 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1983
1984 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1985
Andres More52a7e642013-02-25 20:32:53 -05001986 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1987 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001988
1989 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1990 MIC_vUnInit();
1991
Andres More4e9b5e22013-02-12 20:36:30 -05001992 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001993 *pdwMIC_L = 0;
1994 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001995 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001996 }
1997
1998 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1999 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002000 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2001 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002002
2003 }
2004
Malcolm Priestley3ba09382013-10-15 21:41:38 +01002005 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002006 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002007
2008 if (pDevice->bEnableHostWEP) {
2009 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2010 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2011 }
2012
2013 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002014 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002015 }
2016 }
2017
Andres More1cac4a42013-03-18 20:33:50 -05002018 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002019 pDevice->wSeqCounter++ ;
2020 if (pDevice->wSeqCounter > 0x0fff)
2021 pDevice->wSeqCounter = 0;
2022
Forest Bond92b96792009-06-13 07:38:31 -04002023 if (bIsPSPOLL) {
2024 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2025 // of FIFO control header.
2026 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2027 // in the same place of other packet's Duration-field).
2028 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002029 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002030 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2031 tx_cts.tx.head.cts_g.data_head;
2032 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002033 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002034 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002035 cpu_to_le16(p80211Header->sA2.wDurationID);
2036 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002037 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2038 tx_ab.tx.head.data_head_ab;
2039 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002040 cpu_to_le16(p80211Header->sA2.wDurationID);
2041 }
Forest Bond92b96792009-06-13 07:38:31 -04002042 }
2043
Andres More3eaca0d2013-02-25 20:32:52 -05002044 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002045 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002046 pTX_Buffer->byType = 0x00;
2047
2048 pContext->pPacket = skb;
2049 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002050 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002051
Andres More1cac4a42013-03-18 20:33:50 -05002052 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002053 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2054 &pMACHeader->addr1[0], (u16)cbFrameSize,
2055 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002056 }
2057 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002058 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2059 &pMACHeader->addr3[0], (u16)cbFrameSize,
2060 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002061 }
2062 PIPEnsSendBulkOut(pDevice,pContext);
2063 return ;
2064
2065}
2066
Forest Bond92b96792009-06-13 07:38:31 -04002067//TYPE_AC0DMA data tx
2068/*
2069 * Description:
2070 * Tx packet via AC0DMA(DMA1)
2071 *
2072 * Parameters:
2073 * In:
2074 * pDevice - Pointer to the adapter
2075 * skb - Pointer to tx skb packet
2076 * Out:
2077 * void
2078 *
2079 * Return Value: NULL
2080 */
2081
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002082int nsDMA_tx_packet(struct vnt_private *pDevice,
2083 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002084{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002085 struct net_device_stats *pStats = &pDevice->stats;
2086 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002087 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002088 u32 BytesToWrite = 0, uHeaderLen = 0;
2089 u32 uNodeIndex = 0;
2090 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2091 u16 wAID;
2092 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002093 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002094 PSKeyItem pTransmitKey = NULL;
2095 SKeyItem STempKey;
2096 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002097 int bTKIP_UseGTK = false;
2098 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002099 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002100 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002101 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002102 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002103 u32 status;
2104 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002105 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002106
Forest Bond92b96792009-06-13 07:38:31 -04002107 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2108
2109 if (pDevice->uAssocCount == 0) {
2110 dev_kfree_skb_irq(skb);
2111 return 0;
2112 }
2113
Andres Moreb902fbf2013-02-25 20:32:51 -05002114 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002115 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002116 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002117 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2118
2119 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2120 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2121 // set tx map
2122 pMgmt->abyPSTxMap[0] |= byMask[0];
2123 return 0;
2124 }
Masanari Iida93184692012-08-13 21:21:50 +09002125 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002126
2127 if (pDevice->byBBType != BB_TYPE_11A)
2128 pDevice->wCurrentRate = RATE_2M;
2129 else
2130 pDevice->wCurrentRate = RATE_24M;
2131 // long preamble type
2132 pDevice->byPreambleType = PREAMBLE_SHORT;
2133
2134 }else {
2135
Andres Moreb902fbf2013-02-25 20:32:51 -05002136 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002137
2138 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2139
2140 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2141
2142 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2143 // set tx map
2144 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2145 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2146 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2147 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2148
2149 return 0;
2150 }
2151 // AP rate decided from node
2152 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2153 // tx preamble decided from node
2154
2155 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2156 pDevice->byPreambleType = pDevice->byShortPreamble;
2157
2158 }else {
2159 pDevice->byPreambleType = PREAMBLE_LONG;
2160 }
Andres More4e9b5e22013-02-12 20:36:30 -05002161 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002162 }
2163 }
2164
Andres Moree269fc22013-02-12 20:36:29 -05002165 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002166 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2167 dev_kfree_skb_irq(skb);
2168 return 0;
2169 }
2170 }
2171
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002172 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002173
2174 if (pContext == NULL) {
2175 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2176 dev_kfree_skb_irq(skb);
2177 return STATUS_RESOURCES;
2178 }
2179
Andres Moreceb8c5d2013-03-18 20:33:49 -05002180 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002181
2182//mike add:station mode check eapol-key challenge--->
2183{
Andres Moreb902fbf2013-02-25 20:32:51 -05002184 u8 Protocol_Version; //802.1x Authentication
2185 u8 Packet_Type; //802.1x Authentication
2186 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002187 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002188
Charles Clément21ec51f2010-05-18 10:08:14 -07002189 Protocol_Version = skb->data[ETH_HLEN];
2190 Packet_Type = skb->data[ETH_HLEN+1];
2191 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2192 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 -05002193 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002194 /* 802.1x OR eapol-key challenge frame transfer */
2195 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2196 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002197 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002198 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2199 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2200 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002201 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002202 PRINT_K("WPA ");
2203 }
2204 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002205 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002206 PRINT_K("WPA2(re-keying) ");
2207 }
2208 PRINT_K("Authentication completed!!\n");
2209 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002210 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002211 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002212 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002213 PRINT_K("WPA2 Authentication completed!!\n");
2214 }
2215 }
2216 }
2217}
2218//mike add:station mode check eapol-key challenge<---
2219
Andres More4e9b5e22013-02-12 20:36:30 -05002220 if (pDevice->bEncryptionEnable == true) {
2221 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002222 // get Transmit key
2223 do {
2224 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2225 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2226 pbyBSSID = pDevice->abyBSSID;
2227 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002228 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002229 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002230 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2231 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002232 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2233 break;
2234 }
2235 } else {
2236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2237 break;
2238 }
2239 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002240 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2241 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002242 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2243 for (ii = 0; ii< 6; ii++)
2244 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2245 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2246
2247 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002248 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002249 break;
2250 }
2251 // get group key
2252 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002253 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002254 pTransmitKey = NULL;
2255 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2256 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2257 }
2258 else
2259 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2260 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002261 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2263 }
Andres Moree269fc22013-02-12 20:36:29 -05002264 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002265 }
2266
2267 if (pDevice->bEnableHostWEP) {
2268 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002269 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002270 pTransmitKey = &STempKey;
2271 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2272 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2273 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2274 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2275 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2276 memcpy(pTransmitKey->abyKey,
2277 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2278 pTransmitKey->uKeyLength
2279 );
2280 }
2281 }
2282
Andres Moreb902fbf2013-02-25 20:32:51 -05002283 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002284
2285 if (pDevice->bFixRate) {
2286 if (pDevice->byBBType == BB_TYPE_11B) {
2287 if (pDevice->uConnectionRate >= RATE_11M) {
2288 pDevice->wCurrentRate = RATE_11M;
2289 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002290 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002291 }
2292 } else {
2293 if ((pDevice->byBBType == BB_TYPE_11A) &&
2294 (pDevice->uConnectionRate <= RATE_6M)) {
2295 pDevice->wCurrentRate = RATE_6M;
2296 } else {
2297 if (pDevice->uConnectionRate >= RATE_54M)
2298 pDevice->wCurrentRate = RATE_54M;
2299 else
Andres More3eaca0d2013-02-25 20:32:52 -05002300 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002301 }
2302 }
2303 }
2304 else {
2305 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2306 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002307 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002308 // Multicast use highest data rate
2309 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2310 // preamble type
2311 pDevice->byPreambleType = pDevice->byShortPreamble;
2312 }
2313 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002314 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002315 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2316 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2317 pDevice->byPreambleType = pDevice->byShortPreamble;
2318
2319 }
2320 else {
2321 pDevice->byPreambleType = PREAMBLE_LONG;
2322 }
2323 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2324 }
2325 else {
2326 if (pDevice->byBBType != BB_TYPE_11A)
2327 pDevice->wCurrentRate = RATE_2M;
2328 else
2329 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2330 // abyCurrExtSuppRates[]
2331 pDevice->byPreambleType = PREAMBLE_SHORT;
2332 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2333 }
2334 }
2335 }
2336 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2337 // Infra STA rate decided from AP Node, index = 0
2338 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2339 }
2340 }
2341
Andres Moreceb8c5d2013-03-18 20:33:49 -05002342 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002343 if (pDevice->byBBType != BB_TYPE_11A) {
2344 pDevice->wCurrentRate = RATE_1M;
2345 pDevice->byACKRate = RATE_1M;
2346 pDevice->byTopCCKBasicRate = RATE_1M;
2347 pDevice->byTopOFDMBasicRate = RATE_6M;
2348 } else {
2349 pDevice->wCurrentRate = RATE_6M;
2350 pDevice->byACKRate = RATE_6M;
2351 pDevice->byTopCCKBasicRate = RATE_1M;
2352 pDevice->byTopOFDMBasicRate = RATE_6M;
2353 }
2354 }
Forest Bond92b96792009-06-13 07:38:31 -04002355
Andres More0cbd8d92010-05-06 20:34:29 -03002356 DBG_PRT(MSG_LEVEL_DEBUG,
2357 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2358 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002359
2360 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002361 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002362 }
2363
2364 if (pDevice->wCurrentRate <= RATE_11M) {
2365 byPktType = PK_TYPE_11B;
2366 }
2367
Andres More4e9b5e22013-02-12 20:36:30 -05002368 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002369 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2370 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002371 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002373 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2374 if (pTransmitKey == NULL) {
2375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2376 }
2377 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002378 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2380 }
2381 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002382 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2383 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002384 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002385 }
2386 }
2387 }
2388
Forest Bond92b96792009-06-13 07:38:31 -04002389 if (pDevice->bEnableHostWEP) {
2390 if ((uNodeIndex != 0) &&
2391 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002392 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2393 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002394 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002395 }
2396 }
2397 }
2398 else {
2399
Forest Bond92b96792009-06-13 07:38:31 -04002400 if (pTransmitKey == NULL) {
2401 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002402 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002403 dev_kfree_skb_irq(skb);
2404 pStats->tx_dropped++;
2405 return STATUS_FAILURE;
2406 }
Forest Bond92b96792009-06-13 07:38:31 -04002407 }
2408 }
2409
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002410 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2411
Forest Bond92b96792009-06-13 07:38:31 -04002412 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002413 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002414 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002415 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002416 pDevice->wCurrentRate,
2417 &uHeaderLen, &BytesToWrite
2418 );
2419
Andres Moree269fc22013-02-12 20:36:29 -05002420 if (fConvertedPacket == false) {
2421 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002422 dev_kfree_skb_irq(skb);
2423 return STATUS_FAILURE;
2424 }
2425
Andres More4e9b5e22013-02-12 20:36:30 -05002426 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002427 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002428 bScheduleCommand((void *) pDevice,
2429 WLAN_CMD_MAC_DISPOWERSAVING,
2430 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002431 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002432 }
2433 }
2434
Andres Moreb902fbf2013-02-25 20:32:51 -05002435 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002436 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002437
2438 pContext->pPacket = skb;
2439 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002440 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002441
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002442 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2443 &pContext->sEthHeader.h_dest[0],
2444 (u16)(BytesToWrite-uHeaderLen),
2445 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002446
2447 status = PIPEnsSendBulkOut(pDevice,pContext);
2448
Andres More4e9b5e22013-02-12 20:36:30 -05002449 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002450 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002451
Andres Moreb902fbf2013-02-25 20:32:51 -05002452 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002453 }
2454
2455 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002456 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002457 dev_kfree_skb_irq(skb);
2458 return STATUS_FAILURE;
2459 }
2460 else
2461 return 0;
2462
2463}
2464
Forest Bond92b96792009-06-13 07:38:31 -04002465/*
2466 * Description:
2467 * Relay packet send (AC1DMA) from rx dpc.
2468 *
2469 * Parameters:
2470 * In:
2471 * pDevice - Pointer to the adapter
2472 * pPacket - Pointer to rx packet
2473 * cbPacketSize - rx ethernet frame size
2474 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002475 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002476 *
Andres More4e9b5e22013-02-12 20:36:30 -05002477 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002478 */
2479
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002480int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2481 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002482{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002483 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002484 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002485 u32 BytesToWrite = 0, uHeaderLen = 0;
2486 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002487 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002488 SKeyItem STempKey;
2489 PSKeyItem pTransmitKey = NULL;
2490 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002491 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002492 u8 byPktTyp;
2493 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002494 u32 status;
2495 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002496
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002497 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002498
2499 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002500 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002501 }
2502
Andres Moreceb8c5d2013-03-18 20:33:49 -05002503 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002504
Andres More4e9b5e22013-02-12 20:36:30 -05002505 if (pDevice->bEncryptionEnable == true) {
2506 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002507 // get group key
2508 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002509 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002510 pTransmitKey = NULL;
2511 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2512 } else {
2513 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2514 }
2515 }
2516
2517 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002518 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002519 pTransmitKey = &STempKey;
2520 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2521 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2522 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2523 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2524 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2525 memcpy(pTransmitKey->abyKey,
2526 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2527 pTransmitKey->uKeyLength
2528 );
2529 }
2530 }
2531
2532 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002533 pContext->bBoolInUse = false;
2534 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002535 }
2536
Andres Moreb902fbf2013-02-25 20:32:51 -05002537 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002538
2539 if (pDevice->bFixRate) {
2540 if (pDevice->byBBType == BB_TYPE_11B) {
2541 if (pDevice->uConnectionRate >= RATE_11M) {
2542 pDevice->wCurrentRate = RATE_11M;
2543 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002544 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002545 }
2546 } else {
2547 if ((pDevice->byBBType == BB_TYPE_11A) &&
2548 (pDevice->uConnectionRate <= RATE_6M)) {
2549 pDevice->wCurrentRate = RATE_6M;
2550 } else {
2551 if (pDevice->uConnectionRate >= RATE_54M)
2552 pDevice->wCurrentRate = RATE_54M;
2553 else
Andres More3eaca0d2013-02-25 20:32:52 -05002554 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002555 }
2556 }
2557 }
2558 else {
2559 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2560 }
2561
Forest Bond92b96792009-06-13 07:38:31 -04002562 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002563 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002564 }
2565
2566 if (pDevice->wCurrentRate <= RATE_11M)
2567 byPktType = PK_TYPE_11B;
2568
Andres Moreabad19d2010-07-12 16:28:32 -03002569 BytesToWrite = uDataLen + ETH_FCS_LEN;
2570
Forest Bond92b96792009-06-13 07:38:31 -04002571 // Convert the packet to an usb frame and copy into our buffer
2572 // and send the irp.
2573
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002574 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2575
Forest Bond92b96792009-06-13 07:38:31 -04002576 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002577 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002578 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2579 pbySkbData, pTransmitKey, uNodeIndex,
2580 pDevice->wCurrentRate,
2581 &uHeaderLen, &BytesToWrite
2582 );
2583
Andres Moree269fc22013-02-12 20:36:29 -05002584 if (fConvertedPacket == false) {
2585 pContext->bBoolInUse = false;
2586 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002587 }
2588
Andres Moreb902fbf2013-02-25 20:32:51 -05002589 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002590 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002591
2592 pContext->pPacket = NULL;
2593 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002594 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002595
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002596 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2597 &pContext->sEthHeader.h_dest[0],
2598 (u16)(BytesToWrite - uHeaderLen),
2599 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002600
2601 status = PIPEnsSendBulkOut(pDevice,pContext);
2602
Andres More4e9b5e22013-02-12 20:36:30 -05002603 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002604}
2605