blob: a4d372886b934120634c42fdf75a5c18b0181d8e [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 "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040064#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070065
Mariano Reingart4a499de2010-10-29 19:15:26 -030066static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040067
Andres More3eaca0d2013-02-25 20:32:52 -050068const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040069 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
70 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
71 };
72
Andres More3eaca0d2013-02-25 20:32:52 -050073const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040074 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
75 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
76 };
Andres More3eaca0d2013-02-25 20:32:52 -050077const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040078 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
79 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
80 };
81
Forest Bond92b96792009-06-13 07:38:31 -040082#define RTSDUR_BB 0
83#define RTSDUR_BA 1
84#define RTSDUR_AA 2
85#define CTSDUR_BA 3
86#define RTSDUR_BA_F0 4
87#define RTSDUR_AA_F0 5
88#define RTSDUR_BA_F1 6
89#define RTSDUR_AA_F1 7
90#define CTSDUR_BA_F0 8
91#define CTSDUR_BA_F1 9
92#define DATADUR_B 10
93#define DATADUR_A 11
94#define DATADUR_A_F0 12
95#define DATADUR_A_F1 13
96
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000097static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
98 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040099
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000100static void *s_vGetFreeContext(struct vnt_private *pDevice);
101
102static void s_vGenerateTxParameter(struct vnt_private *pDevice,
103 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
104 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500105 struct ethhdr *psEthHeader);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000106
107static u32 s_uFillDataHead(struct vnt_private *pDevice,
108 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100109 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400110
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000111static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500112 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000113 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400114
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000115static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
116 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
117 u8 *pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -0400118
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000119static void s_vSWencryption(struct vnt_private *pDevice,
120 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400121
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000122static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
123 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400124
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000125static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
126 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400127
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000128static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
129 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
130 int bDisCRC, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400131
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000132static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
133 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500134 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400135
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000136static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100137 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400138
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100139static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000140 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
141 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400142
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000143static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400144{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000145 PUSB_SEND_CONTEXT pContext = NULL;
146 PUSB_SEND_CONTEXT pReturnContext = NULL;
147 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400148
149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
150
151 for (ii = 0; ii < pDevice->cbTD; ii++) {
152 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500153 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500154 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100155 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400156 pReturnContext = pContext;
157 break;
158 }
159 }
160 if ( ii == pDevice->cbTD ) {
161 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
162 }
Andres More8611a292010-05-01 14:25:00 -0300163 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400164}
165
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000166static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
167 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400168{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000169 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400170
Andres More4b50fb42010-06-22 21:57:42 -0300171 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400172 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300173 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400174 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
175 else
176 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
177
178 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
179 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300180 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
181 pbyDestAddr,
182 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400183}
184
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000185static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
186 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
187 u16 wPayloadLen, u8 *pMICHDR)
Forest Bond92b96792009-06-13 07:38:31 -0400188{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000189 u32 *pdwIV = (u32 *)pbyIVHead;
190 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
191 u16 wValue;
Andres More1cac4a42013-03-18 20:33:50 -0500192 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000193 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400194
Forest Bond92b96792009-06-13 07:38:31 -0400195 //Fill TXKEY
196 if (pTransmitKey == NULL)
197 return;
198
199 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
200 *pdwIV = pDevice->dwIVCounter;
201 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
202
203 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
204 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
Andres Moreb902fbf2013-02-25 20:32:51 -0500205 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700206 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400207 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500208 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700209 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400210 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500211 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700212 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400213 }
Jim Lieb3e362592009-08-12 14:54:11 -0700214 memcpy(pDevice->abyPRNG, pbyBuf, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400215 }
216 // Append IV after Mac Header
217 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
Malcolm Priestleyd5bbef72012-11-11 15:53:14 +0000218 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
Forest Bond92b96792009-06-13 07:38:31 -0400219 *pdwIV = cpu_to_le32(*pdwIV);
220 pDevice->dwIVCounter++;
221 if (pDevice->dwIVCounter > WEP_IV_MASK) {
222 pDevice->dwIVCounter = 0;
223 }
224 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
225 pTransmitKey->wTSC15_0++;
226 if (pTransmitKey->wTSC15_0 == 0) {
227 pTransmitKey->dwTSC47_16++;
228 }
229 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
230 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
Jim Lieb3e362592009-08-12 14:54:11 -0700231 memcpy(pbyBuf, pDevice->abyPRNG, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400232 // Make IV
Jim Lieb3e362592009-08-12 14:54:11 -0700233 memcpy(pdwIV, pDevice->abyPRNG, 3);
Forest Bond92b96792009-06-13 07:38:31 -0400234
Andres Moreb902fbf2013-02-25 20:32:51 -0500235 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Forest Bond92b96792009-06-13 07:38:31 -0400236 // Append IV&ExtIV after Mac Header
237 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +0000238 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
239 *pdwExtIV);
Forest Bond92b96792009-06-13 07:38:31 -0400240
241 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
242 pTransmitKey->wTSC15_0++;
243 if (pTransmitKey->wTSC15_0 == 0) {
244 pTransmitKey->dwTSC47_16++;
245 }
Jim Lieb3e362592009-08-12 14:54:11 -0700246 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400247
248 // Make IV
249 *pdwIV = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -0500250 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Andres More3eaca0d2013-02-25 20:32:52 -0500251 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
Forest Bond92b96792009-06-13 07:38:31 -0400252 //Append IV&ExtIV after Mac Header
253 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
254
255 //Fill MICHDR0
256 *pMICHDR = 0x59;
Andres Moreb902fbf2013-02-25 20:32:51 -0500257 *((u8 *)(pMICHDR+1)) = 0; // TxPriority
Andres More1cac4a42013-03-18 20:33:50 -0500258 memcpy(pMICHDR+2, &(pMACHeader->addr2[0]), 6);
Andres Moreb902fbf2013-02-25 20:32:51 -0500259 *((u8 *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
260 *((u8 *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
261 *((u8 *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
262 *((u8 *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
263 *((u8 *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
264 *((u8 *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
265 *((u8 *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
266 *((u8 *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
Forest Bond92b96792009-06-13 07:38:31 -0400267
268 //Fill MICHDR1
Andres Moreb902fbf2013-02-25 20:32:51 -0500269 *((u8 *)(pMICHDR+16)) = 0; // HLEN[15:8]
Forest Bond92b96792009-06-13 07:38:31 -0400270 if (pDevice->bLongHeader) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500271 *((u8 *)(pMICHDR+17)) = 28; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400272 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500273 *((u8 *)(pMICHDR+17)) = 22; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400274 }
Andres More1cac4a42013-03-18 20:33:50 -0500275 wValue = cpu_to_le16(pMACHeader->frame_control & 0xC78F);
Andres Moreb902fbf2013-02-25 20:32:51 -0500276 memcpy(pMICHDR+18, (u8 *)&wValue, 2); // MSKFRACTL
Andres More1cac4a42013-03-18 20:33:50 -0500277 memcpy(pMICHDR+20, &(pMACHeader->addr1[0]), 6);
278 memcpy(pMICHDR+26, &(pMACHeader->addr2[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400279
280 //Fill MICHDR2
Andres More1cac4a42013-03-18 20:33:50 -0500281 memcpy(pMICHDR+32, &(pMACHeader->addr3[0]), 6);
282 wValue = pMACHeader->seq_ctrl;
Forest Bond92b96792009-06-13 07:38:31 -0400283 wValue &= 0x000F;
284 wValue = cpu_to_le16(wValue);
Andres Moreb902fbf2013-02-25 20:32:51 -0500285 memcpy(pMICHDR+38, (u8 *)&wValue, 2); // MSKSEQCTL
Forest Bond92b96792009-06-13 07:38:31 -0400286 if (pDevice->bLongHeader) {
Andres More1cac4a42013-03-18 20:33:50 -0500287 memcpy(pMICHDR+40, &(pMACHeader->addr4[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400288 }
289 }
290}
291
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000292static void s_vSWencryption(struct vnt_private *pDevice,
293 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400294{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000295 u32 cbICVlen = 4;
296 u32 dwICV = 0xffffffff;
297 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400298
299 if (pTransmitKey == NULL)
300 return;
301
302 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
303 //=======================================================================
304 // Append ICV after payload
305 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500306 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400307 // finally, we must invert dwCRC to get the correct answer
308 *pdwICV = cpu_to_le32(~dwICV);
309 // RC4 encryption
310 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
311 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
312 //=======================================================================
313 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
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, TKIP_KEY_LEN);
322 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
323 //=======================================================================
324 }
325}
326
Forest Bond92b96792009-06-13 07:38:31 -0400327/*byPktType : PK_TYPE_11A 0
328 PK_TYPE_11B 1
329 PK_TYPE_11GB 2
330 PK_TYPE_11GA 3
331*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000332static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
333 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400334{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000335 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400336
337 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
338 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500339 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400340 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500341 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400342 }
343
344 if (bNeedAck) {
345 return (uDataTime + pDevice->uSIFS + uAckTime);
346 }
347 else {
348 return uDataTime;
349 }
350}
351
352//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000353static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
354 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400355{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000356 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400357
358 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
359
Forest Bond92b96792009-06-13 07:38:31 -0400360 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
361 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
362 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
363 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
364 }
365 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
366 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
367 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
368 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
369 }
370 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
371 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
372 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
373 }
374 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
375 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
376 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
377 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
378 return uRrvTime;
379 }
380
381 //RTSRrvTime
382 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
383 return uRrvTime;
384}
385
386//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000387static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100388 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400389{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100390 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400391
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100392 if (bNeedAck) {
393 if (byDurType == DATADUR_B)
394 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
395 byPktType, 14, pDevice->byTopCCKBasicRate);
396 else
397 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
398 byPktType, 14, pDevice->byTopOFDMBasicRate);
399 return pDevice->uSIFS + uAckTime;
400 }
Forest Bond92b96792009-06-13 07:38:31 -0400401
Forest Bond92b96792009-06-13 07:38:31 -0400402 return 0;
403}
404
Forest Bond92b96792009-06-13 07:38:31 -0400405//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100406static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000407 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
408 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400409{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000410 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400411
Forest Bond92b96792009-06-13 07:38:31 -0400412 switch (byDurType) {
413
414 case RTSDUR_BB: //RTSDuration_bb
415 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
416 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
417 break;
418
419 case RTSDUR_BA: //RTSDuration_ba
420 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
421 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
422 break;
423
424 case RTSDUR_AA: //RTSDuration_aa
425 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
426 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
427 break;
428
429 case CTSDUR_BA: //CTSDuration_ba
430 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
431 break;
432
433 case RTSDUR_BA_F0: //RTSDuration_ba_f0
434 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
435 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
436 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
437 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
438 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
439 }
440 break;
441
442 case RTSDUR_AA_F0: //RTSDuration_aa_f0
443 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
444 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
445 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
446 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
447 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
448 }
449 break;
450
451 case RTSDUR_BA_F1: //RTSDuration_ba_f1
452 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
453 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
454 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
455 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
456 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
457 }
458 break;
459
460 case RTSDUR_AA_F1: //RTSDuration_aa_f1
461 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
462 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
463 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
464 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
465 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
466 }
467 break;
468
469 case CTSDUR_BA_F0: //CTSDuration_ba_f0
470 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
471 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
472 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
473 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
474 }
475 break;
476
477 case CTSDUR_BA_F1: //CTSDuration_ba_f1
478 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
479 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
480 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
481 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
482 }
483 break;
484
485 default:
486 break;
487 }
488
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100489 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400490}
491
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000492static u32 s_uFillDataHead(struct vnt_private *pDevice,
493 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100494 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400495{
496
497 if (pTxDataHead == NULL) {
498 return 0;
499 }
500
501 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Andres Morebd2bc4c2010-08-02 23:35:57 -0300502 if ((uDMAIdx == TYPE_ATIMDMA) || (uDMAIdx == TYPE_BEACONDMA)) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100503 struct vnt_tx_datahead_ab *pBuf =
504 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400505 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700506 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500507 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400508 );
509 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100510 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
511 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400512 if(uDMAIdx!=TYPE_ATIMDMA) {
513 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
514 }
515 return (pBuf->wDuration);
516 }
517 else { // DATA & MANAGE Frame
518 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100519 struct vnt_tx_datahead_g *pBuf =
520 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400521 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700522 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500523 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400524 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700525 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500526 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400527 );
528 //Get Duration and TimeStamp
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100529 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
530 byPktType, bNeedAck);
531 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
532 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400533
534 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
535 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
536 return (pBuf->wDuration_a);
537 } else {
538 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100539 struct vnt_tx_datahead_g_fb *pBuf =
540 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400541 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700542 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500543 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400544 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700545 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500546 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400547 );
548 //Get Duration and TimeStamp
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100549 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
550 byPktType, bNeedAck);
551 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
552 PK_TYPE_11B, bNeedAck);
553 pBuf->wDuration_a_f0 = (u16)s_uGetDataDuration(pDevice,
554 DATADUR_A_F0, byPktType, bNeedAck);
555 pBuf->wDuration_a_f1 = (u16)s_uGetDataDuration(pDevice,
556 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400557 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
558 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
559 return (pBuf->wDuration_a);
560 } //if (byFBOption == AUTO_FB_NONE)
561 }
562 }
563 else if (byPktType == PK_TYPE_11A) {
564 if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
565 // Auto Fallback
566 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
567 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700568 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500569 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400570 );
571 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100572 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
573 byPktType, bNeedAck);
574 pBuf->wDuration_f0 = (u16)s_uGetDataDuration(pDevice,
575 DATADUR_A_F0, byPktType, bNeedAck);
576 pBuf->wDuration_f1 = (u16)s_uGetDataDuration(pDevice,
577 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400578 if(uDMAIdx!=TYPE_ATIMDMA) {
579 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
580 }
581 return (pBuf->wDuration);
582 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100583 struct vnt_tx_datahead_ab *pBuf =
584 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400585 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700586 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500587 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400588 );
589 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100590 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
591 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400592
593 if(uDMAIdx!=TYPE_ATIMDMA) {
594 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
595 }
596 return (pBuf->wDuration);
597 }
598 }
599 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100600 struct vnt_tx_datahead_ab *pBuf =
601 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400602 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700603 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500604 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400605 );
606 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100607 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
608 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400609 if (uDMAIdx != TYPE_ATIMDMA) {
610 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
611 }
612 return (pBuf->wDuration);
613 }
614 return 0;
615}
616
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000617static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
618 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500619 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400620{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000621 u32 uRTSFrameLen = 20;
622 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400623
Forest Bond92b96792009-06-13 07:38:31 -0400624 if (pvRTS == NULL)
625 return;
626
627 if (bDisCRC) {
628 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
629 // in this case we need to decrease its length by 4.
630 uRTSFrameLen -= 4;
631 }
632
Masanari Iida93184692012-08-13 21:21:50 +0900633 // Note: So far RTSHead doesn't appear in ATIM & Beacom DMA, so we don't need to take them into account.
Forest Bond92b96792009-06-13 07:38:31 -0400634 // Otherwise, we need to modified codes for them.
635 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
636 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100637 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400638 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700639 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500640 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400641 );
642 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700643 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500644 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400645 );
646 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
647 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100648 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
649 cbFrameLength, PK_TYPE_11B,
650 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
651 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
652 cbFrameLength, byPktType,
653 wCurrentRate, bNeedAck, byFBOption);
654 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
655 cbFrameLength, byPktType,
656 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100657 pBuf->data.duration = pBuf->wDuration_aa;
658 /*Get RTS Frame body */
659 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400660
Malcolm Priestley07738932013-08-05 22:08:05 +0100661 if (pDevice->eOPMode == OP_MODE_ADHOC ||
662 pDevice->eOPMode == OP_MODE_AP)
663 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
664 else
665 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300666
Malcolm Priestley07738932013-08-05 22:08:05 +0100667 if (pDevice->eOPMode == OP_MODE_AP)
668 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
669 else
670 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400671 }
672 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100673 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400674 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700675 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500676 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400677 );
678 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700679 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500680 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400681 );
682 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
683 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100684 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
685 cbFrameLength, PK_TYPE_11B,
686 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
687 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
688 cbFrameLength, byPktType,
689 wCurrentRate, bNeedAck, byFBOption);
690 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
691 cbFrameLength, byPktType,
692 wCurrentRate, bNeedAck, byFBOption);
693 pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
694 RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
695 bNeedAck, byFBOption);
696 pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
697 RTSDUR_AA_F0, cbFrameLength, byPktType,
698 wCurrentRate, bNeedAck, byFBOption);
699 pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
700 RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
701 bNeedAck, byFBOption);
702 pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
703 RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
704 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100705 pBuf->data.duration = pBuf->wDuration_aa;
706 /*Get RTS Frame body*/
707 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400708
Malcolm Priestley07738932013-08-05 22:08:05 +0100709 if (pDevice->eOPMode == OP_MODE_ADHOC ||
710 pDevice->eOPMode == OP_MODE_AP)
711 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
712 else
713 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400714
Malcolm Priestley07738932013-08-05 22:08:05 +0100715 if (pDevice->eOPMode == OP_MODE_AP)
716 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
717 else
718 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400719 } // if (byFBOption == AUTO_FB_NONE)
720 }
721 else if (byPktType == PK_TYPE_11A) {
722 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100723 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400724 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700725 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500726 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400727 );
728 pBuf->wTransmitLength = cpu_to_le16(wLen);
729 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100730 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
731 cbFrameLength, byPktType, wCurrentRate,
732 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100733 pBuf->data.duration = pBuf->wDuration;
734 /* Get RTS Frame body */
735 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400736
Malcolm Priestley07738932013-08-05 22:08:05 +0100737 if (pDevice->eOPMode == OP_MODE_ADHOC ||
738 pDevice->eOPMode == OP_MODE_AP)
739 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
740 else
741 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400742
Malcolm Priestley07738932013-08-05 22:08:05 +0100743 if (pDevice->eOPMode == OP_MODE_AP)
744 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
745 else
746 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400747 }
748 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100749 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400750 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700751 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500752 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400753 );
754 pBuf->wTransmitLength = cpu_to_le16(wLen);
755 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100756 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
757 cbFrameLength, byPktType, wCurrentRate,
758 bNeedAck, byFBOption);
759 pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
760 RTSDUR_AA_F0, cbFrameLength, byPktType,
761 wCurrentRate, bNeedAck, byFBOption);
762 pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
763 RTSDUR_AA_F1, cbFrameLength, byPktType,
764 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100765 pBuf->data.duration = pBuf->wDuration;
766 /* Get RTS Frame body */
767 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400768
Malcolm Priestley07738932013-08-05 22:08:05 +0100769 if (pDevice->eOPMode == OP_MODE_ADHOC ||
770 pDevice->eOPMode == OP_MODE_AP)
771 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
772 else
773 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
774
775 if (pDevice->eOPMode == OP_MODE_AP)
776 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
777 else
778 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400779 }
780 }
781 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100782 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400783 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700784 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500785 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400786 );
787 pBuf->wTransmitLength = cpu_to_le16(wLen);
788 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100789 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
790 cbFrameLength, byPktType, wCurrentRate,
791 bNeedAck, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400792
Malcolm Priestley07738932013-08-05 22:08:05 +0100793 pBuf->data.duration = pBuf->wDuration;
794 /* Get RTS Frame body */
795 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400796
Malcolm Priestley07738932013-08-05 22:08:05 +0100797 if (pDevice->eOPMode == OP_MODE_ADHOC ||
798 pDevice->eOPMode == OP_MODE_AP)
799 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
800 else
801 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
802
803 if (pDevice->eOPMode == OP_MODE_AP)
804 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
805 else
806 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400807 }
808}
809
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000810static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
811 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
812 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400813{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000814 u32 uCTSFrameLen = 14;
815 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400816
817 if (pvCTS == NULL) {
818 return;
819 }
820
821 if (bDisCRC) {
822 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
823 // in this case we need to decrease its length by 4.
824 uCTSFrameLen -= 4;
825 }
826
827 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
828 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
829 // Auto Fall back
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100830 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Forest Bond92b96792009-06-13 07:38:31 -0400831 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700832 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500833 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400834 );
835 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100836 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
837 cbFrameLength, byPktType,
838 wCurrentRate, bNeedAck, byFBOption);
839 /* Get CTSDuration_ba_f0 */
840 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
841 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
842 bNeedAck, byFBOption);
843 /* Get CTSDuration_ba_f1 */
844 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
845 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
846 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100847 /* Get CTS Frame body */
848 pBuf->data.duration = pBuf->wDuration_ba;
849 pBuf->data.frame_control = TYPE_CTL_CTS;
850 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400851 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100852 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Forest Bond92b96792009-06-13 07:38:31 -0400853 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700854 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500855 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400856 );
857 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100858 /* Get CTSDuration_ba */
859 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
860 CTSDUR_BA, cbFrameLength, byPktType,
861 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100862 /*Get CTS Frame body*/
863 pBuf->data.duration = pBuf->wDuration_ba;
864 pBuf->data.frame_control = TYPE_CTL_CTS;
865 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400866 }
867 }
868}
869
Forest Bond92b96792009-06-13 07:38:31 -0400870/*+
871 *
872 * Description:
873 * Generate FIFO control for MAC & Baseband controller
874 *
875 * Parameters:
876 * In:
877 * pDevice - Pointer to adpater
878 * pTxDataHead - Transmit Data Buffer
879 * pTxBufHead - pTxBufHead
880 * pvRrvTime - pvRrvTime
881 * pvRTS - RTS Buffer
882 * pCTS - CTS Buffer
883 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
884 * bNeedACK - If need ACK
885 * uDMAIdx - DMA Index
886 * Out:
887 * none
888 *
889 * Return Value: none
890 *
891-*/
Andres Morecc856e62010-05-17 21:34:01 -0300892
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000893static void s_vGenerateTxParameter(struct vnt_private *pDevice,
894 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
895 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500896 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400897{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000898 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
899 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -0500900 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000901 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400902
903 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
904 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
905 pFifoHead->wReserved = wCurrentRate;
906 wFifoCtl = pFifoHead->wFIFOCtl;
907
908 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -0500909 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -0400910 }
911
912 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
913 byFBOption = AUTO_FB_0;
914 }
915 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
916 byFBOption = AUTO_FB_1;
917 }
918
919 if (pDevice->bLongHeader)
920 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
921
922 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
923
924 if (pvRTS != NULL) { //RTS_need
925 //Fill RsvTime
926 if (pvRrvTime) {
Malcolm Priestley6398a592013-08-16 21:26:55 +0100927 struct vnt_rrv_time_rts *pBuf =
928 (struct vnt_rrv_time_rts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500929 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
930 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
931 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
932 pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
933 pBuf->wTxRrvTime_b = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400934 }
935 //Fill RTS
936 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
937 }
938 else {//RTS_needless, PCF mode
939
940 //Fill RsvTime
941 if (pvRrvTime) {
Malcolm Priestley4f990052013-08-16 23:38:57 +0100942 struct vnt_rrv_time_cts *pBuf =
943 (struct vnt_rrv_time_cts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500944 pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
945 pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
946 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
Forest Bond92b96792009-06-13 07:38:31 -0400947 }
948 //Fill CTS
949 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
950 }
951 }
952 else if (byPktType == PK_TYPE_11A) {
953
954 if (pvRTS != NULL) {//RTS_need, non PCF mode
955 //Fill RsvTime
956 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100957 struct vnt_rrv_time_ab *pBuf =
958 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500959 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
960 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400961 }
962 //Fill RTS
963 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
964 }
965 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
966 //Fill RsvTime
967 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100968 struct vnt_rrv_time_ab *pBuf =
969 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500970 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400971 }
972 }
973 }
974 else if (byPktType == PK_TYPE_11B) {
975
976 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
977 //Fill RsvTime
978 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100979 struct vnt_rrv_time_ab *pBuf =
980 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500981 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
982 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400983 }
984 //Fill RTS
985 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
986 }
987 else { //RTS_needless, non PCF mode
988 //Fill RsvTime
989 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100990 struct vnt_rrv_time_ab *pBuf =
991 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500992 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400993 }
994 }
995 }
996 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
997}
998/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500999 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -05001000 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -03001001 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -04001002*/
1003
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001004static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01001005 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
1006 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
1007 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
1008 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -04001009{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001010 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1011 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001012 u32 cb802_1_H_len;
1013 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1014 u32 cbFCSlen = 4, cbMICHDR = 0;
1015 int bNeedACK, bRTS;
1016 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1017 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1018 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1019 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1020 u32 uDuration;
1021 u32 cbHeaderLength = 0, uPadding = 0;
1022 void *pvRrvTime;
1023 PSMICHDRHead pMICHDR;
1024 void *pvRTS;
1025 void *pvCTS;
1026 void *pvTxDataHd;
1027 u8 byFBOption = AUTO_FB_NONE, byFragType;
1028 u16 wTxBufSize;
1029 u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
1030 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001031 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -04001032
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001033 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001034
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001035 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001036 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1037 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001038 }
Forest Bond92b96792009-06-13 07:38:31 -04001039
Forest Bond92b96792009-06-13 07:38:31 -04001040 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001041 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001042 if (pDevice->dwDiagRefCount == 0) {
1043 cb802_1_H_len = 8;
1044 } else {
1045 cb802_1_H_len = 2;
1046 }
1047 } else {
1048 cb802_1_H_len = 0;
1049 }
1050
Charles Clément21ec51f2010-05-18 10:08:14 -07001051 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001052
1053 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001054 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001055
1056 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001057 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001058 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1059 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001060 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1061 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001062 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001063 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001064 pTxBufHead->wFIFOCtl =
1065 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1066 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001067 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001068 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1069 }
Forest Bond92b96792009-06-13 07:38:31 -04001070 }
1071 else {
1072 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001073 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001074 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1075 }
1076 } //if (pDevice->dwDiagRefCount != 0) {
1077
1078 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1079
1080 //Set FIFOCTL_LHEAD
1081 if (pDevice->bLongHeader)
1082 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1083
1084 if (pDevice->bSoftwareGenCrcErr) {
1085 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1086 }
1087
1088 //Set FRAGCTL_MACHDCNT
1089 if (pDevice->bLongHeader) {
1090 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1091 } else {
1092 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1093 }
Andres More3eaca0d2013-02-25 20:32:52 -05001094 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001095
1096 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001097 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001098 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1099 }
1100
1101 //Set Auto Fallback Ctl
1102 if (wCurrentRate >= RATE_18M) {
1103 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1104 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1105 byFBOption = AUTO_FB_0;
1106 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1107 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1108 byFBOption = AUTO_FB_1;
1109 }
1110 }
1111
Andres More4e9b5e22013-02-12 20:36:30 -05001112 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001113 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1114 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1115 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1116 }
1117 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1119 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1120 }
1121 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1122 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1123 }
1124 }
1125 }
1126
Forest Bond92b96792009-06-13 07:38:31 -04001127 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1128 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1129 cbIVlen = 4;
1130 cbICVlen = 4;
1131 }
1132 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1133 cbIVlen = 8;//IV+ExtIV
1134 cbMIClen = 8;
1135 cbICVlen = 4;
1136 }
1137 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1138 cbIVlen = 8;//RSN Header
1139 cbICVlen = 8;//MIC
1140 cbMICHDR = sizeof(SMICHDRHead);
1141 }
Andres Moree269fc22013-02-12 20:36:29 -05001142 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001143 //MAC Header should be padding 0 to DW alignment.
1144 uPadding = 4 - (cbMACHdLen%4);
1145 uPadding %= 4;
1146 }
1147 }
1148
1149 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1150
Andres Moree269fc22013-02-12 20:36:29 -05001151 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1152 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001153 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001154 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001155 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1156 }
1157
Andres Moreb902fbf2013-02-25 20:32:51 -05001158 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001159 wTxBufSize = sizeof(STxBufHead);
1160 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1161 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001162 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001163 pvRrvTime = (struct vnt_rrv_time_rts *)
1164 (pbyTxBufferAddr + wTxBufSize);
1165 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1166 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001167 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001168 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001169 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001170 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1171 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1172 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001173 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001174 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001175 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001176 }
1177 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001178 pvRrvTime = (struct vnt_rrv_time_cts *)
1179 (pbyTxBufferAddr + wTxBufSize);
1180 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1181 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001182 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001183 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001184 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001185 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1186 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1187 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001188 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1189 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001190 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001191 }
1192 } else {
1193 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001194 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001195 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1196 wTxBufSize);
1197 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1198 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001199 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001200 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001201 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001202 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1203 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1204 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001205 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1206 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001207 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001208 }
Andres Moree269fc22013-02-12 20:36:29 -05001209 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001210 pvRrvTime = (struct vnt_rrv_time_cts *)
1211 (pbyTxBufferAddr + wTxBufSize);
1212 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1213 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001214 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001215 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001216 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001217 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001218 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1219 cbMICHDR + sizeof(struct vnt_cts_fb));
1220 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001221 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001222 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001223 }
1224 } // Auto Fall Back
1225 }
1226 else {//802.11a/b packet
1227 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001228 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001229 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1230 wTxBufSize);
1231 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1232 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001233 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001234 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001235 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001236 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1237 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001238 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001239 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1240 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001241 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001242 }
Andres Moree269fc22013-02-12 20:36:29 -05001243 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001244 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1245 wTxBufSize);
1246 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1247 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001248 pvRTS = NULL;
1249 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001250 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1251 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001252 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001253 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001254 }
1255 } else {
1256 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001257 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001258 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1259 wTxBufSize);
1260 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1261 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001262 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001263 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001264 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001265 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001266 sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001267 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001268 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1269 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
1270 sizeof(STxDataHead_a_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001271 }
Andres Moree269fc22013-02-12 20:36:29 -05001272 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001273 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1274 wTxBufSize);
1275 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1276 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001277 pvRTS = NULL;
1278 pvCTS = NULL;
Malcolm Priestley976467d2013-08-16 23:44:04 +01001279 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize +
1280 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1281 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1282 cbMICHDR + sizeof(STxDataHead_a_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001283 }
1284 } // Auto Fall Back
1285 }
1286
Andres Moreb902fbf2013-02-25 20:32:51 -05001287 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1288 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1289 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001290
Forest Bond92b96792009-06-13 07:38:31 -04001291 //=========================
1292 // No Fragmentation
1293 //=========================
1294 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1295 byFragType = FRAGCTL_NONFRAG;
1296 //uDMAIdx = TYPE_AC0DMA;
1297 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1298
Forest Bond92b96792009-06-13 07:38:31 -04001299 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001300 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1301 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001302 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1303 //Fill DataHead
1304 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001305 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001306 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001307 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001308 byFragType, uDMAIdx, 0);
1309
Andres More4e9b5e22013-02-12 20:36:30 -05001310 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001311 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001312 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001313 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001314
1315 if (pDevice->bEnableHostWEP) {
1316 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1317 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1318 }
1319 }
1320
1321 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001322 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001323 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001324 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1325 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001326 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001327 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001328 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001329 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001330 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001331 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001332 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001333 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001334 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001335
1336 }
1337
1338 }
1339
Forest Bond92b96792009-06-13 07:38:31 -04001340 if (pPacket != NULL) {
1341 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001342 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001343 (pPacket + ETH_HLEN),
1344 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001345 );
1346
1347 } else {
1348 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001349 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001350 }
1351
Andres More4e9b5e22013-02-12 20:36:30 -05001352 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001353
1354 ///////////////////////////////////////////////////////////////////
1355
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001356 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1357 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1358 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1359 }
Forest Bond92b96792009-06-13 07:38:31 -04001360 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001361 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1362 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001363 }
1364 else {
Andres More52a7e642013-02-25 20:32:53 -05001365 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1366 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001367 }
1368 // DO Software Michael
1369 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001370 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001371 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001372 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1374 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001375
1376 ///////////////////////////////////////////////////////////////////
1377
1378 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1379 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001380 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001381 //}
1382 //DBG_PRN_GRP12(("\n\n\n"));
1383
1384 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1385
Andres More52a7e642013-02-25 20:32:53 -05001386 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1387 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001388
1389 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1390 MIC_vUnInit();
1391
Andres More4e9b5e22013-02-12 20:36:30 -05001392 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001393 *pdwMIC_L = 0;
1394 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001395 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001396 }
1397 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1398 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1399 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1400 }
1401
Andres More4e9b5e22013-02-12 20:36:30 -05001402 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001403
Andres More3eaca0d2013-02-25 20:32:52 -05001404 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001405
Andres More4e9b5e22013-02-12 20:36:30 -05001406 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1407 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1408 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001409 cbFrameSize -= cbICVlen;
1410 }
1411
Andres More4e9b5e22013-02-12 20:36:30 -05001412 if (pDevice->bSoftwareGenCrcErr == true) {
Andres Morecc856e62010-05-17 21:34:01 -03001413 unsigned int cbLen;
Andres More52a7e642013-02-25 20:32:53 -05001414 u32 * pdwCRC;
Forest Bond92b96792009-06-13 07:38:31 -04001415
1416 dwCRC = 0xFFFFFFFFL;
1417 cbLen = cbFrameSize - cbFCSlen;
1418 // calculate CRC, and wrtie CRC value to end of TD
1419 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
Andres More52a7e642013-02-25 20:32:53 -05001420 pdwCRC = (u32 *)(pbyMacHdr + cbLen);
Forest Bond92b96792009-06-13 07:38:31 -04001421 // finally, we must invert dwCRC to get the correct answer
1422 *pdwCRC = ~dwCRC;
1423 // Force Error
1424 *pdwCRC -= 1;
1425 } else {
1426 cbFrameSize -= cbFCSlen;
1427 }
1428
1429 *pcbHeaderLen = cbHeaderLength;
1430 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1431
Forest Bond92b96792009-06-13 07:38:31 -04001432 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001433 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001434
Andres More4e9b5e22013-02-12 20:36:30 -05001435 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001436
1437}
1438
Forest Bond92b96792009-06-13 07:38:31 -04001439/*+
1440 *
1441 * Description:
1442 * Translate 802.3 to 802.11 header
1443 *
1444 * Parameters:
1445 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001446 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001447 * dwTxBufferAddr - Transmit Buffer
1448 * pPacket - Packet from upper layer
1449 * cbPacketSize - Transmit Data Length
1450 * Out:
1451 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1452 * pcbAppendPayload - size of append payload for 802.1H translation
1453 *
1454 * Return Value: none
1455 *
1456-*/
1457
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001458static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001459 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001460 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001461{
Andres More1cac4a42013-03-18 20:33:50 -05001462 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001463
Forest Bond92b96792009-06-13 07:38:31 -04001464 if (uDMAIdx == TYPE_ATIMDMA) {
Andres More1cac4a42013-03-18 20:33:50 -05001465 pMACHeader->frame_control = TYPE_802_11_ATIM;
Forest Bond92b96792009-06-13 07:38:31 -04001466 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001467 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001468 }
1469
1470 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001471 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001472 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001473 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001474 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1475 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001476 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001477 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001478 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001479 } else {
1480 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001481 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001482 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001483 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001484 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001485 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001486 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001487 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001488 &(pDevice->abyBSSID[0]),
1489 ETH_ALEN);
1490 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001491 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001492 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001493 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001494 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001495 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001496 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001497 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001498 &(pDevice->abyBSSID[0]),
1499 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001500 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001501 }
1502 }
1503
1504 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001505 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001506
Andres More1cac4a42013-03-18 20:33:50 -05001507 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001508
1509 if (pDevice->bLongHeader) {
1510 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001511 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001512 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001513 }
Andres More1cac4a42013-03-18 20:33:50 -05001514 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001515
1516 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001517 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001518
1519 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1520 pDevice->wSeqCounter++;
1521 if (pDevice->wSeqCounter > 0x0fff)
1522 pDevice->wSeqCounter = 0;
1523 }
1524
1525 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001526 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001527 }
1528}
1529
Forest Bond92b96792009-06-13 07:38:31 -04001530/*+
1531 *
1532 * Description:
1533 * Request instructs a MAC to transmit a 802.11 management packet through
1534 * the adapter onto the medium.
1535 *
1536 * Parameters:
1537 * In:
1538 * hDeviceContext - Pointer to the adapter
1539 * pPacket - A pointer to a descriptor for the packet to transmit
1540 * Out:
1541 * none
1542 *
Andres Moree269fc22013-02-12 20:36:29 -05001543 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001544 *
1545-*/
1546
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001547CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1548 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001549{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001550 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001551 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001552 PSTxBufHead pTxBufHead;
1553 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001554 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001555 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001556 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001557 u8 byPktType, *pbyTxBufferAddr;
1558 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1559 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001560 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001561 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1562 u32 uPadding = 0;
1563 u16 wTxBufSize;
1564 u32 cbMacHdLen;
1565 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001566
Forest Bond92b96792009-06-13 07:38:31 -04001567 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1568
1569 if (NULL == pContext) {
1570 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1571 return CMD_STATUS_RESOURCES;
1572 }
1573
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001574 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001575 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001576 cbFrameBodySize = pPacket->cbPayloadLen;
1577 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1578 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001579
1580 if (pDevice->byBBType == BB_TYPE_11A) {
1581 wCurrentRate = RATE_6M;
1582 byPktType = PK_TYPE_11A;
1583 } else {
1584 wCurrentRate = RATE_1M;
1585 byPktType = PK_TYPE_11B;
1586 }
1587
1588 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1589 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1590 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1591 // to set power here.
1592 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1593 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1594 } else {
1595 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1596 }
1597 pDevice->wCurrentRate = wCurrentRate;
1598
Forest Bond92b96792009-06-13 07:38:31 -04001599 //Set packet type
1600 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1601 pTxBufHead->wFIFOCtl = 0;
1602 }
1603 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1604 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1605 }
1606 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1607 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1608 }
1609 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1610 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1611 }
1612
1613 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1614 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1615
Andres More22040bb2010-08-02 20:21:44 -03001616 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001617 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001618 }
1619 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001620 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001621 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1622 };
1623
1624 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1625 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1626
1627 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1628 //Set Preamble type always long
1629 //pDevice->byPreambleType = PREAMBLE_LONG;
1630 // probe-response don't retry
1631 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001632 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001633 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1634 //}
1635 }
1636
1637 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1638
1639 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001640 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001641 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1642 } else {
1643 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1644 }
1645
1646 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001647 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001648
1649 // Notes:
1650 // Although spec says MMPDU can be fragmented; In most case,
1651 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001652 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001653
1654 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1655 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1656 cbIVlen = 4;
1657 cbICVlen = 4;
1658 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1659 }
1660 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1661 cbIVlen = 8;//IV+ExtIV
1662 cbMIClen = 8;
1663 cbICVlen = 4;
1664 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1665 //We need to get seed here for filling TxKey entry.
1666 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1667 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1668 }
1669 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1670 cbIVlen = 8;//RSN Header
1671 cbICVlen = 8;//MIC
1672 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001673 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001674 }
1675 //MAC Header should be padding 0 to DW alignment.
1676 uPadding = 4 - (cbMacHdLen%4);
1677 uPadding %= 4;
1678 }
1679
1680 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1681
1682 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001683 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001684 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1685 }
1686 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1687
1688 //Set RrvTime/RTS/CTS Buffer
1689 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1690
Malcolm Priestley4f990052013-08-16 23:38:57 +01001691 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001692 pMICHDR = NULL;
1693 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001694 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001695 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001696 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001697 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1698 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001699 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001700 }
1701 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001702 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001703 pMICHDR = NULL;
1704 pvRTS = NULL;
1705 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001706 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1707 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001708 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001709 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001710 }
1711
Andres Moreceb8c5d2013-03-18 20:33:49 -05001712 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001713 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1714 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001715 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001716 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1717 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001718 //=========================
1719 // No Fragmentation
1720 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001721 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001722
Forest Bond92b96792009-06-13 07:38:31 -04001723 //Fill FIFO,RrvTime,RTS,and CTS
1724 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1725 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1726
1727 //Fill DataHead
1728 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001729 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001730
Andres More1cac4a42013-03-18 20:33:50 -05001731 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001732
1733 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1734
1735 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001736 u8 * pbyIVHead;
1737 u8 * pbyPayloadHead;
1738 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001739 PSKeyItem pTransmitKey = NULL;
1740
Andres Moreb902fbf2013-02-25 20:32:51 -05001741 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1742 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001743 do {
1744 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001745 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001746 pbyBSSID = pDevice->abyBSSID;
1747 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001748 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001749 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001750 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001751 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1752 break;
1753 }
1754 } else {
1755 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1756 break;
1757 }
1758 }
1759 // get group key
1760 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001761 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001762 pTransmitKey = NULL;
1763 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1764 } else {
1765 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1766 }
Andres Moree269fc22013-02-12 20:36:29 -05001767 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001768 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001769 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001770 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001771
Jim Lieb3e362592009-08-12 14:54:11 -07001772 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001773 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001774 cbFrameBodySize);
1775 }
1776 else {
1777 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001778 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001779 }
1780
Andres More1cac4a42013-03-18 20:33:50 -05001781 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001782 pDevice->wSeqCounter++ ;
1783 if (pDevice->wSeqCounter > 0x0fff)
1784 pDevice->wSeqCounter = 0;
1785
1786 if (bIsPSPOLL) {
1787 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001788 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001789 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1790 // in the same place of other packet's Duration-field).
1791 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001792 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1793 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1794 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1795 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1796 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1797 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001798 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1799 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1800 }
Forest Bond92b96792009-06-13 07:38:31 -04001801 }
1802
Andres More3eaca0d2013-02-25 20:32:52 -05001803 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001804 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001805 pTX_Buffer->byType = 0x00;
1806
1807 pContext->pPacket = NULL;
1808 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001809 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001810
Andres More1cac4a42013-03-18 20:33:50 -05001811 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1812 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001813 }
1814 else {
Andres More1cac4a42013-03-18 20:33:50 -05001815 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001816 }
1817
1818 PIPEnsSendBulkOut(pDevice,pContext);
1819 return CMD_STATUS_PENDING;
1820}
1821
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001822CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1823 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001824{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001825 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001826 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1827 u32 cbHeaderSize = 0;
1828 u16 wTxBufSize = sizeof(STxShortBufHead);
1829 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001830 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001831 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001832 u16 wCurrentRate;
1833 u32 cbFrameBodySize;
1834 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001835 u8 *pbyTxBufferAddr;
1836 PUSB_SEND_CONTEXT pContext;
1837 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001838
Forest Bond92b96792009-06-13 07:38:31 -04001839 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1840 if (NULL == pContext) {
1841 status = CMD_STATUS_RESOURCES;
1842 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1843 return status ;
1844 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001845
1846 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001847 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001848
1849 cbFrameBodySize = pPacket->cbPayloadLen;
1850
1851 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1852 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001853
1854 if (pDevice->byBBType == BB_TYPE_11A) {
1855 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001856 pTxDataHead = (struct vnt_tx_datahead_ab *)
1857 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001858 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001859 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
Andres More3eaca0d2013-02-25 20:32:52 -05001860 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001861 );
1862 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +01001863 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice,
1864 DATADUR_A, PK_TYPE_11A, false));
Forest Bond92b96792009-06-13 07:38:31 -04001865 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestley558becf2013-08-16 23:50:32 +01001866 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001867 } else {
1868 wCurrentRate = RATE_1M;
1869 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001870 pTxDataHead = (struct vnt_tx_datahead_ab *)
1871 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001872 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001873 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -05001874 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001875 );
1876 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +01001877 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice,
1878 DATADUR_B, PK_TYPE_11B, false));
Forest Bond92b96792009-06-13 07:38:31 -04001879 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestley558becf2013-08-16 23:50:32 +01001880 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001881 }
1882
1883 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001884 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001885 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001886
Andres More1cac4a42013-03-18 20:33:50 -05001887 pMACHeader->duration_id = 0;
1888 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001889 pDevice->wSeqCounter++ ;
1890 if (pDevice->wSeqCounter > 0x0fff)
1891 pDevice->wSeqCounter = 0;
1892
1893 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1894
Andres More3eaca0d2013-02-25 20:32:52 -05001895 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001896 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001897 pTX_Buffer->byType = 0x01;
1898
1899 pContext->pPacket = NULL;
1900 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001901 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001902
1903 PIPEnsSendBulkOut(pDevice,pContext);
1904 return CMD_STATUS_PENDING;
1905
1906}
1907
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001908void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1909{
1910 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001911 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001912 u8 byPktType;
1913 u8 *pbyTxBufferAddr;
1914 void *pvRTS, *pvCTS, *pvTxDataHd;
1915 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001916 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001917 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001918 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001919 PSTxBufHead pTxBufHead;
1920 u32 cbFrameSize;
1921 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1922 u32 uPadding = 0;
1923 u32 cbMICHDR = 0, uLength = 0;
1924 u32 dwMICKey0, dwMICKey1;
1925 u32 dwMIC_Priority;
1926 u32 *pdwMIC_L, *pdwMIC_R;
1927 u16 wTxBufSize;
1928 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001929 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001930 void *pvRrvTime, *pMICHDR;
1931 u32 wCurrentRate = RATE_1M;
1932 PUWLAN_80211HDR p80211Header;
1933 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001934 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001935 SKeyItem STempKey;
1936 PSKeyItem pTransmitKey = NULL;
1937 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1938 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001939 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001940
Forest Bond92b96792009-06-13 07:38:31 -04001941 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1942
1943 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1944 cbFrameBodySize = 0;
1945 }
1946 else {
1947 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1948 }
1949 p80211Header = (PUWLAN_80211HDR)skb->data;
1950
1951 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1952
1953 if (NULL == pContext) {
1954 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1955 dev_kfree_skb_irq(skb);
1956 return ;
1957 }
1958
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001959 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001960 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001961 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1962 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001963
1964 if (pDevice->byBBType == BB_TYPE_11A) {
1965 wCurrentRate = RATE_6M;
1966 byPktType = PK_TYPE_11A;
1967 } else {
1968 wCurrentRate = RATE_1M;
1969 byPktType = PK_TYPE_11B;
1970 }
1971
1972 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1973 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1974 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1975 // to set power here.
1976 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1977 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1978 } else {
1979 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1980 }
1981
1982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1983
1984 //Set packet type
1985 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1986 pTxBufHead->wFIFOCtl = 0;
1987 }
1988 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1989 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1990 }
1991 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1992 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1993 }
1994 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1995 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1996 }
1997
1998 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1999 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2000
Andres More22040bb2010-08-02 20:21:44 -03002001 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05002002 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04002003 if (pDevice->bEnableHostWEP) {
2004 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002005 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07002006 }
Forest Bond92b96792009-06-13 07:38:31 -04002007 }
2008 else {
2009 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05002010 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05002011 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07002012 }
Andres More4e9b5e22013-02-12 20:36:30 -05002013 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002014 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2015 };
2016
2017 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2018 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2019
2020 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2021 //Set Preamble type always long
2022 //pDevice->byPreambleType = PREAMBLE_LONG;
2023
2024 // probe-response don't retry
2025 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05002026 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04002027 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2028 //}
2029 }
2030
2031 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2032
2033 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05002034 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04002035 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2036 } else {
2037 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2038 }
2039
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002040 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04002041 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2042
2043 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2044 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2045 }
2046
2047 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2048 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2049 }
2050
2051 if (cbExtSuppRate >0) {
2052 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2053 }
2054 }
2055
Forest Bond92b96792009-06-13 07:38:31 -04002056 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002057 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002058
2059 // Notes:
2060 // Although spec says MMPDU can be fragmented; In most case,
2061 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002062 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002063
Forest Bond92b96792009-06-13 07:38:31 -04002064 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2065 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2066 cbIVlen = 4;
2067 cbICVlen = 4;
2068 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2069 }
2070 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2071 cbIVlen = 8;//IV+ExtIV
2072 cbMIClen = 8;
2073 cbICVlen = 4;
2074 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2075 //We need to get seed here for filling TxKey entry.
2076 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2077 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2078 }
2079 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2080 cbIVlen = 8;//RSN Header
2081 cbICVlen = 8;//MIC
2082 cbMICHDR = sizeof(SMICHDRHead);
2083 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002084 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002085 }
2086 //MAC Header should be padding 0 to DW alignment.
2087 uPadding = 4 - (cbMacHdLen%4);
2088 uPadding %= 4;
2089 }
2090
2091 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2092
2093 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002094 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002095 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2096 }
2097 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2098
Forest Bond92b96792009-06-13 07:38:31 -04002099 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002100 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
2101 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2102 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002103 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002104 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002105 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002106 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2107 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002108 sizeof(struct vnt_cts));
2109 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002110 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002111
2112 }
2113 else {//802.11a/b packet
2114
Malcolm Priestley976467d2013-08-16 23:44:04 +01002115 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
2116 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2117 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002118 pvRTS = NULL;
2119 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002120 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2121 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002122 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002123 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002124 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002125 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002126 &(p80211Header->sA3.abyAddr1[0]),
2127 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002128 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002129 &(p80211Header->sA3.abyAddr2[0]),
2130 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002131 //=========================
2132 // No Fragmentation
2133 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002134 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002135
Forest Bond92b96792009-06-13 07:38:31 -04002136 //Fill FIFO,RrvTime,RTS,and CTS
2137 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2138 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2139
2140 //Fill DataHead
2141 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002142 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002143
Andres More1cac4a42013-03-18 20:33:50 -05002144 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002145
2146 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2147
Andres Moreb902fbf2013-02-25 20:32:51 -05002148 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2149 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2150 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002151
2152 // Copy the Packet into a tx Buffer
2153 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2154
2155 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002156 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002157 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2158
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002159 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002160 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2161 if (cbExtSuppRate != 0) {
2162 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2163 memcpy((pbyPayloadHead + cbFrameBodySize),
2164 pMgmt->abyCurrSuppRates,
2165 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2166 );
2167 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2168 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2169 pMgmt->abyCurrExtSuppRates,
2170 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2171 );
2172 }
2173 }
2174
2175 // Set wep
2176 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2177
2178 if (pDevice->bEnableHostWEP) {
2179 pTransmitKey = &STempKey;
2180 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2181 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2182 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2183 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2184 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2185 memcpy(pTransmitKey->abyKey,
2186 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2187 pTransmitKey->uKeyLength
2188 );
2189 }
2190
2191 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2192
Andres More52a7e642013-02-25 20:32:53 -05002193 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2194 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002195
2196 // DO Software Michael
2197 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002198 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002199 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002200 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002201 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2202 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002203
2204 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2205
2206 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2207
Andres More52a7e642013-02-25 20:32:53 -05002208 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2209 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002210
2211 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2212 MIC_vUnInit();
2213
Andres More4e9b5e22013-02-12 20:36:30 -05002214 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002215 *pdwMIC_L = 0;
2216 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002217 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002218 }
2219
2220 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2221 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002222 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2223 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002224
2225 }
2226
Andres Moreb902fbf2013-02-25 20:32:51 -05002227 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05002228 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002229
2230 if (pDevice->bEnableHostWEP) {
2231 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2232 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2233 }
2234
2235 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002236 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002237 }
2238 }
2239
Andres More1cac4a42013-03-18 20:33:50 -05002240 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002241 pDevice->wSeqCounter++ ;
2242 if (pDevice->wSeqCounter > 0x0fff)
2243 pDevice->wSeqCounter = 0;
2244
Forest Bond92b96792009-06-13 07:38:31 -04002245 if (bIsPSPOLL) {
2246 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2247 // of FIFO control header.
2248 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2249 // in the same place of other packet's Duration-field).
2250 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002251 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2252 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2253 cpu_to_le16(p80211Header->sA2.wDurationID);
2254 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2255 cpu_to_le16(p80211Header->sA2.wDurationID);
2256 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002257 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2258 cpu_to_le16(p80211Header->sA2.wDurationID);
2259 }
Forest Bond92b96792009-06-13 07:38:31 -04002260 }
2261
Andres More3eaca0d2013-02-25 20:32:52 -05002262 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002263 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002264 pTX_Buffer->byType = 0x00;
2265
2266 pContext->pPacket = skb;
2267 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002268 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002269
Andres More1cac4a42013-03-18 20:33:50 -05002270 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2271 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002272 }
2273 else {
Andres More1cac4a42013-03-18 20:33:50 -05002274 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002275 }
2276 PIPEnsSendBulkOut(pDevice,pContext);
2277 return ;
2278
2279}
2280
Forest Bond92b96792009-06-13 07:38:31 -04002281//TYPE_AC0DMA data tx
2282/*
2283 * Description:
2284 * Tx packet via AC0DMA(DMA1)
2285 *
2286 * Parameters:
2287 * In:
2288 * pDevice - Pointer to the adapter
2289 * skb - Pointer to tx skb packet
2290 * Out:
2291 * void
2292 *
2293 * Return Value: NULL
2294 */
2295
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002296int nsDMA_tx_packet(struct vnt_private *pDevice,
2297 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002298{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002299 struct net_device_stats *pStats = &pDevice->stats;
2300 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002301 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002302 u32 BytesToWrite = 0, uHeaderLen = 0;
2303 u32 uNodeIndex = 0;
2304 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2305 u16 wAID;
2306 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002307 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002308 PSKeyItem pTransmitKey = NULL;
2309 SKeyItem STempKey;
2310 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002311 int bTKIP_UseGTK = false;
2312 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002313 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002314 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002315 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002316 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002317 u32 status;
2318 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002319 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002320
Forest Bond92b96792009-06-13 07:38:31 -04002321 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2322
2323 if (pDevice->uAssocCount == 0) {
2324 dev_kfree_skb_irq(skb);
2325 return 0;
2326 }
2327
Andres Moreb902fbf2013-02-25 20:32:51 -05002328 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002329 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002330 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002331 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2332
2333 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2334 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2335 // set tx map
2336 pMgmt->abyPSTxMap[0] |= byMask[0];
2337 return 0;
2338 }
Masanari Iida93184692012-08-13 21:21:50 +09002339 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002340
2341 if (pDevice->byBBType != BB_TYPE_11A)
2342 pDevice->wCurrentRate = RATE_2M;
2343 else
2344 pDevice->wCurrentRate = RATE_24M;
2345 // long preamble type
2346 pDevice->byPreambleType = PREAMBLE_SHORT;
2347
2348 }else {
2349
Andres Moreb902fbf2013-02-25 20:32:51 -05002350 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002351
2352 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2353
2354 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2355
2356 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2357 // set tx map
2358 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2359 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2360 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2361 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2362
2363 return 0;
2364 }
2365 // AP rate decided from node
2366 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2367 // tx preamble decided from node
2368
2369 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2370 pDevice->byPreambleType = pDevice->byShortPreamble;
2371
2372 }else {
2373 pDevice->byPreambleType = PREAMBLE_LONG;
2374 }
Andres More4e9b5e22013-02-12 20:36:30 -05002375 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002376 }
2377 }
2378
Andres Moree269fc22013-02-12 20:36:29 -05002379 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2381 dev_kfree_skb_irq(skb);
2382 return 0;
2383 }
2384 }
2385
2386 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2387
2388 if (pContext == NULL) {
2389 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2390 dev_kfree_skb_irq(skb);
2391 return STATUS_RESOURCES;
2392 }
2393
Andres Moreceb8c5d2013-03-18 20:33:49 -05002394 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002395
2396//mike add:station mode check eapol-key challenge--->
2397{
Andres Moreb902fbf2013-02-25 20:32:51 -05002398 u8 Protocol_Version; //802.1x Authentication
2399 u8 Packet_Type; //802.1x Authentication
2400 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002401 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002402
Charles Clément21ec51f2010-05-18 10:08:14 -07002403 Protocol_Version = skb->data[ETH_HLEN];
2404 Packet_Type = skb->data[ETH_HLEN+1];
2405 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2406 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 -05002407 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002408 /* 802.1x OR eapol-key challenge frame transfer */
2409 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2410 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002411 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002412 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2413 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2414 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002415 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002416 PRINT_K("WPA ");
2417 }
2418 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002419 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002420 PRINT_K("WPA2(re-keying) ");
2421 }
2422 PRINT_K("Authentication completed!!\n");
2423 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002424 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002425 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002426 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002427 PRINT_K("WPA2 Authentication completed!!\n");
2428 }
2429 }
2430 }
2431}
2432//mike add:station mode check eapol-key challenge<---
2433
Andres More4e9b5e22013-02-12 20:36:30 -05002434 if (pDevice->bEncryptionEnable == true) {
2435 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002436 // get Transmit key
2437 do {
2438 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2439 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2440 pbyBSSID = pDevice->abyBSSID;
2441 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002442 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002443 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002444 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2445 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002446 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2447 break;
2448 }
2449 } else {
2450 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2451 break;
2452 }
2453 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002454 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2455 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002456 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2457 for (ii = 0; ii< 6; ii++)
2458 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2459 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2460
2461 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002462 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002463 break;
2464 }
2465 // get group key
2466 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002467 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002468 pTransmitKey = NULL;
2469 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2470 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2471 }
2472 else
2473 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2474 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002475 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002476 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2477 }
Andres Moree269fc22013-02-12 20:36:29 -05002478 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002479 }
2480
2481 if (pDevice->bEnableHostWEP) {
2482 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002483 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002484 pTransmitKey = &STempKey;
2485 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2486 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2487 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2488 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2489 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2490 memcpy(pTransmitKey->abyKey,
2491 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2492 pTransmitKey->uKeyLength
2493 );
2494 }
2495 }
2496
Andres Moreb902fbf2013-02-25 20:32:51 -05002497 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002498
2499 if (pDevice->bFixRate) {
2500 if (pDevice->byBBType == BB_TYPE_11B) {
2501 if (pDevice->uConnectionRate >= RATE_11M) {
2502 pDevice->wCurrentRate = RATE_11M;
2503 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002504 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002505 }
2506 } else {
2507 if ((pDevice->byBBType == BB_TYPE_11A) &&
2508 (pDevice->uConnectionRate <= RATE_6M)) {
2509 pDevice->wCurrentRate = RATE_6M;
2510 } else {
2511 if (pDevice->uConnectionRate >= RATE_54M)
2512 pDevice->wCurrentRate = RATE_54M;
2513 else
Andres More3eaca0d2013-02-25 20:32:52 -05002514 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002515 }
2516 }
2517 }
2518 else {
2519 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2520 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002521 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002522 // Multicast use highest data rate
2523 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2524 // preamble type
2525 pDevice->byPreambleType = pDevice->byShortPreamble;
2526 }
2527 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002528 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002529 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2530 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2531 pDevice->byPreambleType = pDevice->byShortPreamble;
2532
2533 }
2534 else {
2535 pDevice->byPreambleType = PREAMBLE_LONG;
2536 }
2537 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2538 }
2539 else {
2540 if (pDevice->byBBType != BB_TYPE_11A)
2541 pDevice->wCurrentRate = RATE_2M;
2542 else
2543 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2544 // abyCurrExtSuppRates[]
2545 pDevice->byPreambleType = PREAMBLE_SHORT;
2546 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2547 }
2548 }
2549 }
2550 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2551 // Infra STA rate decided from AP Node, index = 0
2552 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2553 }
2554 }
2555
Andres Moreceb8c5d2013-03-18 20:33:49 -05002556 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002557 if (pDevice->byBBType != BB_TYPE_11A) {
2558 pDevice->wCurrentRate = RATE_1M;
2559 pDevice->byACKRate = RATE_1M;
2560 pDevice->byTopCCKBasicRate = RATE_1M;
2561 pDevice->byTopOFDMBasicRate = RATE_6M;
2562 } else {
2563 pDevice->wCurrentRate = RATE_6M;
2564 pDevice->byACKRate = RATE_6M;
2565 pDevice->byTopCCKBasicRate = RATE_1M;
2566 pDevice->byTopOFDMBasicRate = RATE_6M;
2567 }
2568 }
Forest Bond92b96792009-06-13 07:38:31 -04002569
Andres More0cbd8d92010-05-06 20:34:29 -03002570 DBG_PRT(MSG_LEVEL_DEBUG,
2571 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2572 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002573
2574 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002575 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002576 }
2577
2578 if (pDevice->wCurrentRate <= RATE_11M) {
2579 byPktType = PK_TYPE_11B;
2580 }
2581
Andres More4e9b5e22013-02-12 20:36:30 -05002582 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002583 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2584 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002585 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002586 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002587 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2588 if (pTransmitKey == NULL) {
2589 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2590 }
2591 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002592 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002593 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2594 }
2595 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002596 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2597 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002598 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002599 }
2600 }
2601 }
2602
Forest Bond92b96792009-06-13 07:38:31 -04002603 if (pDevice->bEnableHostWEP) {
2604 if ((uNodeIndex != 0) &&
2605 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002606 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2607 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002608 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002609 }
2610 }
2611 }
2612 else {
2613
Forest Bond92b96792009-06-13 07:38:31 -04002614 if (pTransmitKey == NULL) {
2615 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002616 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002617 dev_kfree_skb_irq(skb);
2618 pStats->tx_dropped++;
2619 return STATUS_FAILURE;
2620 }
Forest Bond92b96792009-06-13 07:38:31 -04002621 }
2622 }
2623
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002624 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2625
Forest Bond92b96792009-06-13 07:38:31 -04002626 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002627 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002628 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002629 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002630 pDevice->wCurrentRate,
2631 &uHeaderLen, &BytesToWrite
2632 );
2633
Andres Moree269fc22013-02-12 20:36:29 -05002634 if (fConvertedPacket == false) {
2635 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002636 dev_kfree_skb_irq(skb);
2637 return STATUS_FAILURE;
2638 }
2639
Andres More4e9b5e22013-02-12 20:36:30 -05002640 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002641 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002642 bScheduleCommand((void *) pDevice,
2643 WLAN_CMD_MAC_DISPOWERSAVING,
2644 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002645 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002646 }
2647 }
2648
Andres Moreb902fbf2013-02-25 20:32:51 -05002649 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002650 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002651
2652 pContext->pPacket = skb;
2653 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002654 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002655
Andres Moreceb8c5d2013-03-18 20:33:49 -05002656 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.h_dest[0]), (u16) (BytesToWrite-uHeaderLen), pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002657
2658 status = PIPEnsSendBulkOut(pDevice,pContext);
2659
Andres More4e9b5e22013-02-12 20:36:30 -05002660 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002661 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002662
Andres Moreb902fbf2013-02-25 20:32:51 -05002663 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002664 }
2665
2666 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002667 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002668 dev_kfree_skb_irq(skb);
2669 return STATUS_FAILURE;
2670 }
2671 else
2672 return 0;
2673
2674}
2675
Forest Bond92b96792009-06-13 07:38:31 -04002676/*
2677 * Description:
2678 * Relay packet send (AC1DMA) from rx dpc.
2679 *
2680 * Parameters:
2681 * In:
2682 * pDevice - Pointer to the adapter
2683 * pPacket - Pointer to rx packet
2684 * cbPacketSize - rx ethernet frame size
2685 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002686 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002687 *
Andres More4e9b5e22013-02-12 20:36:30 -05002688 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002689 */
2690
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002691int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2692 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002693{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002694 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002695 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002696 u32 BytesToWrite = 0, uHeaderLen = 0;
2697 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002698 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002699 SKeyItem STempKey;
2700 PSKeyItem pTransmitKey = NULL;
2701 u8 *pbyBSSID;
2702 PUSB_SEND_CONTEXT pContext;
2703 u8 byPktTyp;
2704 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002705 u32 status;
2706 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002707
Forest Bond92b96792009-06-13 07:38:31 -04002708 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2709
2710 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002711 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002712 }
2713
Andres Moreceb8c5d2013-03-18 20:33:49 -05002714 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002715
Andres More4e9b5e22013-02-12 20:36:30 -05002716 if (pDevice->bEncryptionEnable == true) {
2717 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002718 // get group key
2719 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002720 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002721 pTransmitKey = NULL;
2722 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2723 } else {
2724 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2725 }
2726 }
2727
2728 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002729 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002730 pTransmitKey = &STempKey;
2731 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2732 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2733 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2734 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2735 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2736 memcpy(pTransmitKey->abyKey,
2737 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2738 pTransmitKey->uKeyLength
2739 );
2740 }
2741 }
2742
2743 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002744 pContext->bBoolInUse = false;
2745 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002746 }
2747
Andres Moreb902fbf2013-02-25 20:32:51 -05002748 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002749
2750 if (pDevice->bFixRate) {
2751 if (pDevice->byBBType == BB_TYPE_11B) {
2752 if (pDevice->uConnectionRate >= RATE_11M) {
2753 pDevice->wCurrentRate = RATE_11M;
2754 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002755 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002756 }
2757 } else {
2758 if ((pDevice->byBBType == BB_TYPE_11A) &&
2759 (pDevice->uConnectionRate <= RATE_6M)) {
2760 pDevice->wCurrentRate = RATE_6M;
2761 } else {
2762 if (pDevice->uConnectionRate >= RATE_54M)
2763 pDevice->wCurrentRate = RATE_54M;
2764 else
Andres More3eaca0d2013-02-25 20:32:52 -05002765 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002766 }
2767 }
2768 }
2769 else {
2770 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2771 }
2772
Forest Bond92b96792009-06-13 07:38:31 -04002773 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002774 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002775 }
2776
2777 if (pDevice->wCurrentRate <= RATE_11M)
2778 byPktType = PK_TYPE_11B;
2779
Andres Moreabad19d2010-07-12 16:28:32 -03002780 BytesToWrite = uDataLen + ETH_FCS_LEN;
2781
Forest Bond92b96792009-06-13 07:38:31 -04002782 // Convert the packet to an usb frame and copy into our buffer
2783 // and send the irp.
2784
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002785 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2786
Forest Bond92b96792009-06-13 07:38:31 -04002787 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002788 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002789 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2790 pbySkbData, pTransmitKey, uNodeIndex,
2791 pDevice->wCurrentRate,
2792 &uHeaderLen, &BytesToWrite
2793 );
2794
Andres Moree269fc22013-02-12 20:36:29 -05002795 if (fConvertedPacket == false) {
2796 pContext->bBoolInUse = false;
2797 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002798 }
2799
Andres Moreb902fbf2013-02-25 20:32:51 -05002800 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002801 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002802
2803 pContext->pPacket = NULL;
2804 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002805 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002806
Andres Moreceb8c5d2013-03-18 20:33:49 -05002807 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.h_dest[0]), (u16) (BytesToWrite-uHeaderLen), pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002808
2809 status = PIPEnsSendBulkOut(pDevice,pContext);
2810
Andres More4e9b5e22013-02-12 20:36:30 -05002811 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002812}
2813