blob: 2db03d6d4c20adedf80e6628e2c875f08f4f32d2 [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Valentina Manea3b138852013-11-04 10:44:02 +020067static const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Valentina Manea3b138852013-11-04 10:44:02 +020072static const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Valentina Manea3b138852013-11-04 10:44:02 +020076static const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000099static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000100
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100101static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100102 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100103 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
104 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000106static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500107 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000108 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100110static void s_vFillTxKey(struct vnt_private *pDevice,
111 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
112 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100113 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400114
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000115static void s_vSWencryption(struct vnt_private *pDevice,
116 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
119 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100121static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000122 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100124static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100125 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
126 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400127
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100128static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100129 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500130 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400131
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100132static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100133 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100135static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000136 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
137 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400138
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000139static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000140 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400141{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000142 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000143 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400144
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400146
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000147 for (ii = 0; ii < priv->cbTD; ii++) {
148 if (!priv->apTD[ii])
149 return NULL;
150
151 context = priv->apTD[ii];
152 if (context->bBoolInUse == false) {
153 context->bBoolInUse = true;
154 memset(context->Data, 0,
155 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
156 return context;
157 }
158 }
159
160 if (ii == priv->cbTD)
161 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000162
Malcolm Priestley5c851382013-11-26 19:12:38 +0000163 return NULL;
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 Priestley3ba09382013-10-15 21:41:38 +0100185static void s_vFillTxKey(struct vnt_private *pDevice,
186 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
187 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
188 struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400189{
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100190 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000191 u32 *pdwIV = (u32 *)pbyIVHead;
192 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500193 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000194 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400195
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100196 /* Fill TXKEY */
197 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100198 return;
Forest Bond92b96792009-06-13 07:38:31 -0400199
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100200 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
201 *pdwIV = pDevice->dwIVCounter;
202 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400203
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100204 switch (pTransmitKey->byCipherSuite) {
205 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100206 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
207 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
208 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
209 pTransmitKey->uKeyLength);
210 } else {
211 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
212 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
213 pTransmitKey->uKeyLength);
214 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
215 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
216 memcpy(pbyBuf+11, pTransmitKey->abyKey,
217 pTransmitKey->uKeyLength);
218 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100219
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100220 memcpy(pDevice->abyPRNG, pbyBuf, 16);
221 }
222 /* Append IV after Mac Header */
223 *pdwIV &= WEP_IV_MASK;
224 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
225 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100226
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100227 pDevice->dwIVCounter++;
228 if (pDevice->dwIVCounter > WEP_IV_MASK)
229 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100230
231 break;
232 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100233 pTransmitKey->wTSC15_0++;
234 if (pTransmitKey->wTSC15_0 == 0)
235 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100236
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100237 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
238 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
239 pDevice->abyPRNG);
240 memcpy(pbyBuf, pDevice->abyPRNG, 16);
241
242 /* Make IV */
243 memcpy(pdwIV, pDevice->abyPRNG, 3);
244
245 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
246 0xc0) | 0x20);
247 /* Append IV&ExtIV after Mac Header */
248 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
249
250 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
251 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
252
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100253 break;
254 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100255 pTransmitKey->wTSC15_0++;
256 if (pTransmitKey->wTSC15_0 == 0)
257 pTransmitKey->dwTSC47_16++;
258
259 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
260
261 /* Make IV */
262 *pdwIV = 0;
263 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
264 0xc0) | 0x20);
265
266 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
267
268 /* Append IV&ExtIV after Mac Header */
269 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
270
271 if (!mic_hdr)
272 return;
273
274 /* MICHDR0 */
275 mic_hdr->id = 0x59;
276 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
277 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
278
279 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
280 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
281
282 /* MICHDR1 */
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000283 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100284 mic_hdr->hlen = cpu_to_be16(28);
285 else
286 mic_hdr->hlen = cpu_to_be16(22);
287
288 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
289 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
290
291 /* MICHDR2 */
292 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
293 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100294 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100295 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100296
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000297 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100298 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
299 }
Forest Bond92b96792009-06-13 07:38:31 -0400300}
301
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000302static void s_vSWencryption(struct vnt_private *pDevice,
303 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400304{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000305 u32 cbICVlen = 4;
306 u32 dwICV = 0xffffffff;
307 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400308
309 if (pTransmitKey == NULL)
310 return;
311
312 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
313 //=======================================================================
314 // Append ICV after payload
315 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500316 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400317 // finally, we must invert dwCRC to get the correct answer
318 *pdwICV = cpu_to_le32(~dwICV);
319 // RC4 encryption
320 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
321 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
322 //=======================================================================
323 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
324 //=======================================================================
325 //Append ICV after payload
326 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500327 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400328 // finally, we must invert dwCRC to get the correct answer
329 *pdwICV = cpu_to_le32(~dwICV);
330 // RC4 encryption
331 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
332 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
333 //=======================================================================
334 }
335}
336
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100337static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
338{
339 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
340 [rate % MAX_RATE]);
341}
342
Forest Bond92b96792009-06-13 07:38:31 -0400343/*byPktType : PK_TYPE_11A 0
344 PK_TYPE_11B 1
345 PK_TYPE_11GB 2
346 PK_TYPE_11GA 3
347*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000348static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
349 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400350{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000351 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400352
353 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
354 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500355 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400356 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500357 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400358 }
359
360 if (bNeedAck) {
361 return (uDataTime + pDevice->uSIFS + uAckTime);
362 }
363 else {
364 return uDataTime;
365 }
366}
367
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100368static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
369 u32 frame_length, u16 rate, int need_ack)
370{
371 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
372 frame_length, rate, need_ack));
373}
374
Forest Bond92b96792009-06-13 07:38:31 -0400375//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100376static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000377 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400378{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000379 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400380
381 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
382
Forest Bond92b96792009-06-13 07:38:31 -0400383 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
384 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
385 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
386 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
387 }
388 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
389 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
390 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
391 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
392 }
393 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
394 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
395 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
396 }
397 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
398 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
399 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
400 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
401 return uRrvTime;
402 }
403
404 //RTSRrvTime
405 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100406 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400407}
408
409//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100410static u16 s_uGetDataDuration(struct vnt_private *pDevice,
411 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400412{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100413 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400414
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100415 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100416 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100417 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
418 byPktType, 14, pDevice->byTopCCKBasicRate);
419 else
420 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
421 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100422 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100423 }
Forest Bond92b96792009-06-13 07:38:31 -0400424
Forest Bond92b96792009-06-13 07:38:31 -0400425 return 0;
426}
427
Forest Bond92b96792009-06-13 07:38:31 -0400428//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100429static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000430 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
431 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400432{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000433 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400434
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100435 switch (byDurType) {
436 case RTSDUR_BB:
437 case RTSDUR_BA:
438 case RTSDUR_BA_F0:
439 case RTSDUR_BA_F1:
440 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
441 14, pDevice->byTopCCKBasicRate);
442 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
443 s_uGetTxRsvTime(pDevice, byPktType,
444 cbFrameLength, wRate, bNeedAck);
445 break;
Forest Bond92b96792009-06-13 07:38:31 -0400446
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100447 case RTSDUR_AA:
448 case RTSDUR_AA_F0:
449 case RTSDUR_AA_F1:
450 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
451 14, pDevice->byTopOFDMBasicRate);
452 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
453 s_uGetTxRsvTime(pDevice, byPktType,
454 cbFrameLength, wRate, bNeedAck);
455 break;
Forest Bond92b96792009-06-13 07:38:31 -0400456
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100457 case CTSDUR_BA:
458 case CTSDUR_BA_F0:
459 case CTSDUR_BA_F1:
460 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100461 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100462 break;
Forest Bond92b96792009-06-13 07:38:31 -0400463
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100464 default:
465 break;
466 }
Forest Bond92b96792009-06-13 07:38:31 -0400467
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100468 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400469}
470
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100471static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
472 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
473{
474 /* Get SignalField,ServiceField,Length */
475 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
476 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
477 PK_TYPE_11B, &buf->b);
478
479 /* Get Duration and TimeStamp */
480 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
481 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
482
483 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
484 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
485 priv->byTopCCKBasicRate);
486
487 return buf->wDuration_a;
488}
489
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100490static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
491 u16 rate, struct vnt_tx_datahead_g_fb *buf,
492 u32 frame_len, int need_ack)
493{
494 /* Get SignalField,ServiceField,Length */
495 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
496
497 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
498 PK_TYPE_11B, &buf->b);
499
500 /* Get Duration and TimeStamp */
501 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
502 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
503
504 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
505 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
506
507 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
508 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
509 priv->byTopCCKBasicRate);
510
511 return buf->wDuration_a;
512}
513
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100514static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
515 u16 rate, struct vnt_tx_datahead_a_fb *buf,
516 u32 frame_len, int need_ack)
517{
518 /* Get SignalField,ServiceField,Length */
519 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
520 /* Get Duration and TimeStampOff */
521 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
522
523 buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
524 buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
525
526 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
527
528 return buf->wDuration;
529}
530
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100531static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
532 u16 rate, struct vnt_tx_datahead_ab *buf,
533 u32 frame_len, int need_ack)
534{
535 /* Get SignalField,ServiceField,Length */
536 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
537 /* Get Duration and TimeStampOff */
538 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
539
540 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
541
542 return buf->wDuration;
543}
544
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100545static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
546 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
547 u16 duration)
548{
549 rts->duration = duration;
550 rts->frame_control = TYPE_CTL_RTS;
551
552 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
553 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
554 else
555 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
556
557 if (priv->eOPMode == OP_MODE_AP)
558 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
559 else
560 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
561
562 return 0;
563}
564
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100565static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100566 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
567 u8 pkt_type, u32 frame_len, int need_ack,
568 u16 current_rate, u8 fb_option)
569{
570 u16 rts_frame_len = 20;
571
572 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
573 PK_TYPE_11B, &buf->b);
574 BBvCalculateParameter(priv, rts_frame_len,
575 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
576
577 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
578 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
579 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
580 pkt_type, current_rate, need_ack, fb_option);
581 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
582 pkt_type, current_rate, need_ack, fb_option);
583
584 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
585
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100586 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
587 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100588}
589
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100590static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100591 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
592 u8 pkt_type, u32 frame_len, int need_ack,
593 u16 current_rate, u8 fb_option)
594{
595 u16 rts_frame_len = 20;
596
597 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
598 PK_TYPE_11B, &buf->b);
599 BBvCalculateParameter(priv, rts_frame_len,
600 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
601
602
603 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
604 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
605 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
606 pkt_type, current_rate, need_ack, fb_option);
607 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
608 pkt_type, current_rate, need_ack, fb_option);
609
610
611 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100612 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100613 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100614 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100615 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100616 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100617 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100618 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100619
620 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
621
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100622 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
623 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100624}
625
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100626static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100627 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
628 u8 pkt_type, u32 frame_len, int need_ack,
629 u16 current_rate, u8 fb_option)
630{
631 u16 rts_frame_len = 20;
632
633 BBvCalculateParameter(priv, rts_frame_len,
634 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
635
636 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
637 pkt_type, current_rate, need_ack, fb_option);
638
639 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
640
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100641 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
642 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100643}
644
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100645static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100646 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
647 u8 pkt_type, u32 frame_len, int need_ack,
648 u16 current_rate, u8 fb_option)
649{
650 u16 rts_frame_len = 20;
651
652 BBvCalculateParameter(priv, rts_frame_len,
653 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
654
655 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
656 pkt_type, current_rate, need_ack, fb_option);
657
658 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100659 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100660
661 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100662 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100663
664 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
665
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100666 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
667 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100668}
669
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100670static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100671 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500672 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400673{
Forest Bond92b96792009-06-13 07:38:31 -0400674
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100675 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100676 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400677
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100678 /* Note: So far RTSHead doesn't appear in ATIM
679 * & Beacom DMA, so we don't need to take them
680 * into account.
681 * Otherwise, we need to modified codes for them.
682 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100683 switch (byPktType) {
684 case PK_TYPE_11GB:
685 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100686 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100687 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100688 psEthHeader, byPktType, cbFrameLength,
689 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100690 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100691 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100692 psEthHeader, byPktType, cbFrameLength,
693 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100694 break;
695 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100696 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100697 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100698 psEthHeader, byPktType, cbFrameLength,
699 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100700 break;
701 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100702 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100703 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100704 psEthHeader, byPktType, cbFrameLength,
705 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100706 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100707
708 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400709}
710
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100711static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100712 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
713 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400714{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000715 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400716
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100717 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100718 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400719
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100720 if (byFBOption != AUTO_FB_NONE) {
721 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100722 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100723 /* Get SignalField,ServiceField,Length */
724 BBvCalculateParameter(pDevice, uCTSFrameLen,
725 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100726 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
727 cbFrameLength, byPktType,
728 wCurrentRate, bNeedAck, byFBOption);
729 /* Get CTSDuration_ba_f0 */
730 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100731 CTSDUR_BA_F0, cbFrameLength, byPktType,
732 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100733 /* Get CTSDuration_ba_f1 */
734 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100735 CTSDUR_BA_F1, cbFrameLength, byPktType,
736 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100737 /* Get CTS Frame body */
738 pBuf->data.duration = pBuf->wDuration_ba;
739 pBuf->data.frame_control = TYPE_CTL_CTS;
740 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100741
742 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
743 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100744 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100745 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100746 /* Get SignalField,ServiceField,Length */
747 BBvCalculateParameter(pDevice, uCTSFrameLen,
748 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100749 /* Get CTSDuration_ba */
750 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
751 CTSDUR_BA, cbFrameLength, byPktType,
752 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100753 /*Get CTS Frame body*/
754 pBuf->data.duration = pBuf->wDuration_ba;
755 pBuf->data.frame_control = TYPE_CTL_CTS;
756 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100757
758 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
759 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400760 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100761
762 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400763}
764
Forest Bond92b96792009-06-13 07:38:31 -0400765/*+
766 *
767 * Description:
768 * Generate FIFO control for MAC & Baseband controller
769 *
770 * Parameters:
771 * In:
772 * pDevice - Pointer to adpater
773 * pTxDataHead - Transmit Data Buffer
774 * pTxBufHead - pTxBufHead
775 * pvRrvTime - pvRrvTime
776 * pvRTS - RTS Buffer
777 * pCTS - CTS Buffer
778 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
779 * bNeedACK - If need ACK
780 * uDMAIdx - DMA Index
781 * Out:
782 * none
783 *
784 * Return Value: none
785 *
786-*/
Andres Morecc856e62010-05-17 21:34:01 -0300787
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100788static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100789 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100790 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
791 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400792{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100793 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100794 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000795 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000796 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400797
Malcolm Priestley92928f12013-10-07 20:14:01 +0100798 pFifoHead->wReserved = wCurrentRate;
799 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400800
Malcolm Priestley92928f12013-10-07 20:14:01 +0100801 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
802 byFBOption = AUTO_FB_0;
803 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
804 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400805
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100806 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100807 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100808
Malcolm Priestley92928f12013-10-07 20:14:01 +0100809 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
810 if (need_rts) {
811 struct vnt_rrv_time_rts *pBuf =
812 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100813
Malcolm Priestley92928f12013-10-07 20:14:01 +0100814 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
815 byPktType, cbFrameSize, wCurrentRate);
816 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
817 byPktType, cbFrameSize, wCurrentRate);
818 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100819 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100820
Malcolm Priestley92928f12013-10-07 20:14:01 +0100821 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
822 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
823 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
824 PK_TYPE_11B, cbFrameSize,
825 pDevice->byTopCCKBasicRate, bNeedACK);
826
827 if (need_mic) {
828 *mic_hdr = &tx_buffer->
829 tx_head.tx_rts.tx.mic.hdr;
830 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
831 } else {
832 head = &tx_buffer->tx_head.tx_rts.tx.head;
833 }
834
835 /* Fill RTS */
836 return s_vFillRTSHead(pDevice, byPktType, head,
837 cbFrameSize, bNeedACK, psEthHeader,
838 wCurrentRate, byFBOption);
839
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100840 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100841 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
842 tx_head.tx_cts.cts;
843
844 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
845 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
846 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
847 PK_TYPE_11B, cbFrameSize,
848 pDevice->byTopCCKBasicRate, bNeedACK);
849
850 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
851 byPktType, cbFrameSize, wCurrentRate);
852
853 if (need_mic) {
854 *mic_hdr = &tx_buffer->
855 tx_head.tx_cts.tx.mic.hdr;
856 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
857 } else {
858 head = &tx_buffer->tx_head.tx_cts.tx.head;
859 }
860
861 /* Fill CTS */
862 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
863 head, cbFrameSize, bNeedACK, wCurrentRate,
864 byFBOption);
865 }
866 } else if (byPktType == PK_TYPE_11A) {
867 if (need_mic) {
868 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
869 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
870 } else {
871 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100872 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100873
Malcolm Priestley92928f12013-10-07 20:14:01 +0100874 if (need_rts) {
875 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
876 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100877
Malcolm Priestley92928f12013-10-07 20:14:01 +0100878 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100879 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100880
Malcolm Priestley92928f12013-10-07 20:14:01 +0100881 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
882 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
883
884 /* Fill RTS */
885 return s_vFillRTSHead(pDevice, byPktType, head,
886 cbFrameSize, bNeedACK, psEthHeader,
887 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100888 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100889 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
890 tx_head.tx_ab.ab;
891
892 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
893 PK_TYPE_11A, cbFrameSize,
894 wCurrentRate, bNeedACK);
895
896 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
897 wCurrentRate, &head->data_head_a_fb,
898 cbFrameSize, bNeedACK);
899 }
900 } else if (byPktType == PK_TYPE_11B) {
901 if (need_mic) {
902 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
903 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
904 } else {
905 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100906 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100907
Malcolm Priestley92928f12013-10-07 20:14:01 +0100908 if (need_rts) {
909 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
910 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100911
Malcolm Priestley92928f12013-10-07 20:14:01 +0100912 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100913 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100914
Malcolm Priestley92928f12013-10-07 20:14:01 +0100915 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
916 PK_TYPE_11B, cbFrameSize, wCurrentRate,
917 bNeedACK);
918
919 /* Fill RTS */
920 return s_vFillRTSHead(pDevice, byPktType, head,
921 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100922 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100923 } else {
924 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
925 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100926
Malcolm Priestley92928f12013-10-07 20:14:01 +0100927 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
928 PK_TYPE_11B, cbFrameSize,
929 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100930
Malcolm Priestley92928f12013-10-07 20:14:01 +0100931 return vnt_rxtx_datahead_ab(pDevice, byPktType,
932 wCurrentRate, &head->data_head_ab,
933 cbFrameSize, bNeedACK);
934 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100935 }
936
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100937 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400938}
939/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500940 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500941 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300942 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400943*/
944
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000945static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100946 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100947 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
948 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
949 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400950{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100951 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000952 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
953 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000954 u32 cb802_1_H_len;
955 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
956 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100957 int bNeedACK;
958 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000959 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
960 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
961 u8 abySNAP_Bridgetunnel[ETH_ALEN]
962 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
963 u32 uDuration;
964 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100965 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000966 u8 byFBOption = AUTO_FB_NONE, byFragType;
967 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100968 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000969 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500970 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100971
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100972 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400973
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000974 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500975 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
976 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000977 }
Forest Bond92b96792009-06-13 07:38:31 -0400978
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000979 /* Get pkt type */
980 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
981 cb802_1_H_len = 8;
982 else
983 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400984
Charles Clément21ec51f2010-05-18 10:08:14 -0700985 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400986
987 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500988 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400989
Andres More22040bb2010-08-02 20:21:44 -0300990 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000991 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500992 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500993 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -0300994 pTxBufHead->wFIFOCtl =
995 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
996 } else {
Andres More4e9b5e22013-02-12 20:36:30 -0500997 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -0300998 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
999 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001000 } else {
1001 /* MSDUs in Infra mode always need ACK */
1002 bNeedACK = true;
1003 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1004 }
Forest Bond92b96792009-06-13 07:38:31 -04001005
1006 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1007
Forest Bond92b96792009-06-13 07:38:31 -04001008 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001009 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1010
Andres More3eaca0d2013-02-25 20:32:52 -05001011 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001012
1013 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001014 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001015 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1016 }
1017
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001018 /* Set Auto Fallback Ctl */
1019 if (wCurrentRate >= RATE_18M) {
1020 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1021 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1022
1023 pDevice->tx_rate_fb0 =
1024 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1025 pDevice->tx_rate_fb1 =
1026 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1027
1028 byFBOption = AUTO_FB_0;
1029 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1030 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1031 pDevice->tx_rate_fb0 =
1032 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1033 pDevice->tx_rate_fb1 =
1034 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1035
1036 byFBOption = AUTO_FB_1;
1037 }
1038 }
Forest Bond92b96792009-06-13 07:38:31 -04001039
Andres More4e9b5e22013-02-12 20:36:30 -05001040 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001041 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1042 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1043 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1044 }
1045 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1046 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1047 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1048 }
1049 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1050 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1051 }
1052 }
1053 }
1054
Forest Bond92b96792009-06-13 07:38:31 -04001055 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1056 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1057 cbIVlen = 4;
1058 cbICVlen = 4;
1059 }
1060 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1061 cbIVlen = 8;//IV+ExtIV
1062 cbMIClen = 8;
1063 cbICVlen = 4;
1064 }
1065 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1066 cbIVlen = 8;//RSN Header
1067 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001068 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001069 }
Andres Moree269fc22013-02-12 20:36:29 -05001070 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001071 //MAC Header should be padding 0 to DW alignment.
1072 uPadding = 4 - (cbMACHdLen%4);
1073 uPadding %= 4;
1074 }
1075 }
1076
1077 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1078
Andres Moree269fc22013-02-12 20:36:29 -05001079 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1080 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001081 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001082 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001083 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1084 }
1085
Andres Moreb902fbf2013-02-25 20:32:51 -05001086 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001087 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1088
Forest Bond92b96792009-06-13 07:38:31 -04001089 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1090 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001091 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001092 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001093 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001094 }
1095 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001096 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001097 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001098 }
1099 } else {
1100 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001101 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001102 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001103 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001104 }
Andres Moree269fc22013-02-12 20:36:29 -05001105 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001106 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001107 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001108 }
1109 } // Auto Fall Back
1110 }
1111 else {//802.11a/b packet
1112 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001113 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001114 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001115 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001116 }
Andres Moree269fc22013-02-12 20:36:29 -05001117 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001118 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001119 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001120 }
1121 } else {
1122 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001123 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001124 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001125 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001126 }
Andres Moree269fc22013-02-12 20:36:29 -05001127 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001128 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001129 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001130 }
1131 } // Auto Fall Back
1132 }
1133
Andres Moreb902fbf2013-02-25 20:32:51 -05001134 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1135 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1136 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001137
Forest Bond92b96792009-06-13 07:38:31 -04001138 //=========================
1139 // No Fragmentation
1140 //=========================
1141 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1142 byFragType = FRAGCTL_NONFRAG;
1143 //uDMAIdx = TYPE_AC0DMA;
1144 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1145
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001146 /* Fill FIFO, RrvTime, RTS and CTS */
1147 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1148 tx_buffer, &pMICHDR, cbMICHDR,
1149 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001150
Forest Bond92b96792009-06-13 07:38:31 -04001151 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001152 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001153 byFragType, uDMAIdx, 0);
1154
Andres More4e9b5e22013-02-12 20:36:30 -05001155 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001156 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001157 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001158 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001159
1160 if (pDevice->bEnableHostWEP) {
1161 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1162 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1163 }
1164 }
1165
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001166 /* 802.1H */
1167 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001168 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001169 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001170 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001171 abySNAP_Bridgetunnel, 6);
1172 else
1173 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001174
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001175 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001176
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001177 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1178 }
Forest Bond92b96792009-06-13 07:38:31 -04001179
Forest Bond92b96792009-06-13 07:38:31 -04001180 if (pPacket != NULL) {
1181 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001182 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001183 (pPacket + ETH_HLEN),
1184 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001185 );
1186
1187 } else {
1188 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001189 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001190 }
1191
Andres More4e9b5e22013-02-12 20:36:30 -05001192 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001193
1194 ///////////////////////////////////////////////////////////////////
1195
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001196 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1197 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1198 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1199 }
Forest Bond92b96792009-06-13 07:38:31 -04001200 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001201 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1202 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001203 }
1204 else {
Andres More52a7e642013-02-25 20:32:53 -05001205 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1206 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001207 }
1208 // DO Software Michael
1209 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001210 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001211 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001212 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001213 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1214 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001215
1216 ///////////////////////////////////////////////////////////////////
1217
1218 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1219 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001220 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001221 //}
1222 //DBG_PRN_GRP12(("\n\n\n"));
1223
1224 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1225
Andres More52a7e642013-02-25 20:32:53 -05001226 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1227 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001228
1229 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1230 MIC_vUnInit();
1231
Andres More4e9b5e22013-02-12 20:36:30 -05001232 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001233 *pdwMIC_L = 0;
1234 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001235 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001236 }
1237 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1238 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1239 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1240 }
1241
Andres More4e9b5e22013-02-12 20:36:30 -05001242 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001243
Andres More3eaca0d2013-02-25 20:32:52 -05001244 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001245
Andres More4e9b5e22013-02-12 20:36:30 -05001246 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1247 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1248 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001249 cbFrameSize -= cbICVlen;
1250 }
1251
Forest Bond92b96792009-06-13 07:38:31 -04001252 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001253
1254 *pcbHeaderLen = cbHeaderLength;
1255 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1256
Forest Bond92b96792009-06-13 07:38:31 -04001257 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001258 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001259
Andres More4e9b5e22013-02-12 20:36:30 -05001260 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001261
1262}
1263
Forest Bond92b96792009-06-13 07:38:31 -04001264/*+
1265 *
1266 * Description:
1267 * Translate 802.3 to 802.11 header
1268 *
1269 * Parameters:
1270 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001271 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001272 * dwTxBufferAddr - Transmit Buffer
1273 * pPacket - Packet from upper layer
1274 * cbPacketSize - Transmit Data Length
1275 * Out:
1276 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1277 * pcbAppendPayload - size of append payload for 802.1H translation
1278 *
1279 * Return Value: none
1280 *
1281-*/
1282
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001283static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001284 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001285 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001286{
Andres More1cac4a42013-03-18 20:33:50 -05001287 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001288
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001289 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001290
1291 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001292 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001293 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001294 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001295 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1296 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001297 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001298 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001299 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001300 } else {
1301 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001302 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001303 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001304 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001305 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001306 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001307 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001308 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001309 &(pDevice->abyBSSID[0]),
1310 ETH_ALEN);
1311 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001312 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001313 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001314 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001315 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001316 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001317 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001318 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001319 &(pDevice->abyBSSID[0]),
1320 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001321 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001322 }
1323 }
1324
1325 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001326 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001327
Andres More1cac4a42013-03-18 20:33:50 -05001328 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001329
Andres More1cac4a42013-03-18 20:33:50 -05001330 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001331
1332 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001333 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001334
1335 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1336 pDevice->wSeqCounter++;
1337 if (pDevice->wSeqCounter > 0x0fff)
1338 pDevice->wSeqCounter = 0;
1339 }
1340
1341 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001342 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001343 }
1344}
1345
Forest Bond92b96792009-06-13 07:38:31 -04001346/*+
1347 *
1348 * Description:
1349 * Request instructs a MAC to transmit a 802.11 management packet through
1350 * the adapter onto the medium.
1351 *
1352 * Parameters:
1353 * In:
1354 * hDeviceContext - Pointer to the adapter
1355 * pPacket - A pointer to a descriptor for the packet to transmit
1356 * Out:
1357 * none
1358 *
Andres Moree269fc22013-02-12 20:36:29 -05001359 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001360 *
1361-*/
1362
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001363CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1364 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001365{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001366 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001367 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001368 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001369 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001370 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001371 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001372 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001373 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001374 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001375 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001376 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1377 u32 uPadding = 0;
1378 u16 wTxBufSize;
1379 u32 cbMacHdLen;
1380 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001381
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001382 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001383
1384 if (NULL == pContext) {
1385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1386 return CMD_STATUS_RESOURCES;
1387 }
1388
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001389 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001390 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001391 pTxBufHead = &pTX_Buffer->fifo_head;
1392 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1393 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001394
1395 if (pDevice->byBBType == BB_TYPE_11A) {
1396 wCurrentRate = RATE_6M;
1397 byPktType = PK_TYPE_11A;
1398 } else {
1399 wCurrentRate = RATE_1M;
1400 byPktType = PK_TYPE_11B;
1401 }
1402
1403 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1404 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1405 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1406 // to set power here.
1407 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1408 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1409 } else {
1410 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1411 }
1412 pDevice->wCurrentRate = wCurrentRate;
1413
Forest Bond92b96792009-06-13 07:38:31 -04001414 //Set packet type
1415 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1416 pTxBufHead->wFIFOCtl = 0;
1417 }
1418 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1419 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1420 }
1421 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1422 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1423 }
1424 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1425 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1426 }
1427
1428 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1429 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1430
Andres More22040bb2010-08-02 20:21:44 -03001431 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001432 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001433 }
1434 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001435 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001436 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1437 };
1438
1439 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1440 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1441
1442 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1443 //Set Preamble type always long
1444 //pDevice->byPreambleType = PREAMBLE_LONG;
1445 // probe-response don't retry
1446 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001447 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001448 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1449 //}
1450 }
1451
1452 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1453
1454 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001455 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001456 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1457 } else {
1458 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1459 }
1460
1461 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001462 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001463
1464 // Notes:
1465 // Although spec says MMPDU can be fragmented; In most case,
1466 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001467
1468 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1469 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1470 cbIVlen = 4;
1471 cbICVlen = 4;
1472 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1473 }
1474 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1475 cbIVlen = 8;//IV+ExtIV
1476 cbMIClen = 8;
1477 cbICVlen = 4;
1478 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1479 //We need to get seed here for filling TxKey entry.
1480 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1481 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1482 }
1483 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1484 cbIVlen = 8;//RSN Header
1485 cbICVlen = 8;//MIC
1486 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001487 }
1488 //MAC Header should be padding 0 to DW alignment.
1489 uPadding = 4 - (cbMacHdLen%4);
1490 uPadding %= 4;
1491 }
1492
1493 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1494
1495 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001496 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001497 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1498 }
1499 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1500
1501 //Set RrvTime/RTS/CTS Buffer
1502 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001503 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001504 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001505 }
1506 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001507 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001508 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001509 }
1510
Andres Moreceb8c5d2013-03-18 20:33:49 -05001511 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001512 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1513 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001514 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001515 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1516 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001517 //=========================
1518 // No Fragmentation
1519 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001520 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001521
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001522 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001523 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001524 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001525 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001526
Andres More1cac4a42013-03-18 20:33:50 -05001527 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001528
1529 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1530
1531 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001532 u8 * pbyIVHead;
1533 u8 * pbyPayloadHead;
1534 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001535 PSKeyItem pTransmitKey = NULL;
1536
Andres Moreb902fbf2013-02-25 20:32:51 -05001537 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1538 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001539 do {
1540 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001541 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001542 pbyBSSID = pDevice->abyBSSID;
1543 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001544 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001545 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001546 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001547 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1548 break;
1549 }
1550 } else {
1551 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1552 break;
1553 }
1554 }
1555 // get group key
1556 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001557 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001558 pTransmitKey = NULL;
1559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1560 } else {
1561 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1562 }
Andres Moree269fc22013-02-12 20:36:29 -05001563 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001564 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001565 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001566 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001567
Jim Lieb3e362592009-08-12 14:54:11 -07001568 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001569 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001570 cbFrameBodySize);
1571 }
1572 else {
1573 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001574 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001575 }
1576
Andres More1cac4a42013-03-18 20:33:50 -05001577 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001578 pDevice->wSeqCounter++ ;
1579 if (pDevice->wSeqCounter > 0x0fff)
1580 pDevice->wSeqCounter = 0;
1581
1582 if (bIsPSPOLL) {
1583 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001584 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001585 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1586 // in the same place of other packet's Duration-field).
1587 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001588 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001589 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1590 tx_cts.tx.head.cts_g.data_head;
1591 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001592 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001593 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001594 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1595 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001596 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1597 tx_ab.tx.head.data_head_ab;
1598 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001599 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1600 }
Forest Bond92b96792009-06-13 07:38:31 -04001601 }
1602
Andres More3eaca0d2013-02-25 20:32:52 -05001603 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001604 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001605 pTX_Buffer->byType = 0x00;
1606
1607 pContext->pPacket = NULL;
1608 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001609 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001610
Andres More1cac4a42013-03-18 20:33:50 -05001611 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001612 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1613 &pMACHeader->addr1[0], (u16)cbFrameSize,
1614 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001615 }
1616 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001617 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1618 &pMACHeader->addr3[0], (u16)cbFrameSize,
1619 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001620 }
1621
1622 PIPEnsSendBulkOut(pDevice,pContext);
1623 return CMD_STATUS_PENDING;
1624}
1625
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001626CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1627 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001628{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001629 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001630 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001631 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1632 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001633 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001634 u16 wCurrentRate;
1635 u32 cbFrameBodySize;
1636 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001637 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001638 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001639
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001640 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001641 if (NULL == pContext) {
1642 status = CMD_STATUS_RESOURCES;
1643 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1644 return status ;
1645 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001646
1647 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001648 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001649
1650 cbFrameBodySize = pPacket->cbPayloadLen;
1651
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001652 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001653
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001654 if (pDevice->byBBType == BB_TYPE_11A) {
1655 wCurrentRate = RATE_6M;
1656
1657 /* Get SignalField,ServiceField,Length */
1658 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1659 PK_TYPE_11A, &short_head->ab);
1660
1661 /* Get Duration and TimeStampOff */
1662 short_head->duration = s_uGetDataDuration(pDevice,
1663 PK_TYPE_11A, false);
1664 short_head->time_stamp_off =
1665 vnt_time_stamp_off(pDevice, wCurrentRate);
1666 } else {
1667 wCurrentRate = RATE_1M;
1668 short_head->fifo_ctl |= FIFOCTL_11B;
1669
1670 /* Get SignalField,ServiceField,Length */
1671 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1672 PK_TYPE_11B, &short_head->ab);
1673
1674 /* Get Duration and TimeStampOff */
1675 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001676 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001677 short_head->time_stamp_off =
1678 vnt_time_stamp_off(pDevice, wCurrentRate);
1679 }
1680
Forest Bond92b96792009-06-13 07:38:31 -04001681
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001682 /* Generate Beacon Header */
1683 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001684
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001685 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1686
1687 pMACHeader->duration_id = 0;
1688 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1689 pDevice->wSeqCounter++;
1690 if (pDevice->wSeqCounter > 0x0fff)
1691 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001692
1693 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1694
Andres More3eaca0d2013-02-25 20:32:52 -05001695 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001696 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001697 pTX_Buffer->byType = 0x01;
1698
1699 pContext->pPacket = NULL;
1700 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001701 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001702
1703 PIPEnsSendBulkOut(pDevice,pContext);
1704 return CMD_STATUS_PENDING;
1705
1706}
1707
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001708void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1709{
1710 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001711 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001712 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001713 u8 byPktType;
1714 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001715 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001716 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001717 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001718 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001719 u32 cbFrameSize;
1720 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1721 u32 uPadding = 0;
1722 u32 cbMICHDR = 0, uLength = 0;
1723 u32 dwMICKey0, dwMICKey1;
1724 u32 dwMIC_Priority;
1725 u32 *pdwMIC_L, *pdwMIC_R;
1726 u16 wTxBufSize;
1727 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001728 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001729 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001730 u32 wCurrentRate = RATE_1M;
1731 PUWLAN_80211HDR p80211Header;
1732 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001733 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001734 SKeyItem STempKey;
1735 PSKeyItem pTransmitKey = NULL;
1736 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1737 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001738 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001739
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001740 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001741
1742 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1743 cbFrameBodySize = 0;
1744 }
1745 else {
1746 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1747 }
1748 p80211Header = (PUWLAN_80211HDR)skb->data;
1749
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001750 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001751
1752 if (NULL == pContext) {
1753 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1754 dev_kfree_skb_irq(skb);
1755 return ;
1756 }
1757
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001758 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001759 pTxBufHead = &pTX_Buffer->fifo_head;
1760 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1761 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001762
1763 if (pDevice->byBBType == BB_TYPE_11A) {
1764 wCurrentRate = RATE_6M;
1765 byPktType = PK_TYPE_11A;
1766 } else {
1767 wCurrentRate = RATE_1M;
1768 byPktType = PK_TYPE_11B;
1769 }
1770
1771 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1772 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1773 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1774 // to set power here.
1775 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1776 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1777 } else {
1778 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1779 }
1780
1781 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1782
1783 //Set packet type
1784 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1785 pTxBufHead->wFIFOCtl = 0;
1786 }
1787 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1788 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1789 }
1790 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1791 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1792 }
1793 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1794 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1795 }
1796
1797 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1798 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1799
Andres More22040bb2010-08-02 20:21:44 -03001800 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001801 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001802 if (pDevice->bEnableHostWEP) {
1803 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001804 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001805 }
Forest Bond92b96792009-06-13 07:38:31 -04001806 }
1807 else {
1808 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001809 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001810 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001811 }
Andres More4e9b5e22013-02-12 20:36:30 -05001812 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001813 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1814 };
1815
1816 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1817 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1818
1819 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1820 //Set Preamble type always long
1821 //pDevice->byPreambleType = PREAMBLE_LONG;
1822
1823 // probe-response don't retry
1824 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001825 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001826 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1827 //}
1828 }
1829
1830 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1831
1832 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001833 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001834 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1835 } else {
1836 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1837 }
1838
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001839 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001840 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1841
1842 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1843 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1844 }
1845
1846 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1847 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1848 }
1849
1850 if (cbExtSuppRate >0) {
1851 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1852 }
1853 }
1854
Forest Bond92b96792009-06-13 07:38:31 -04001855 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001856 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001857
1858 // Notes:
1859 // Although spec says MMPDU can be fragmented; In most case,
1860 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001861
Forest Bond92b96792009-06-13 07:38:31 -04001862 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1863 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1864 cbIVlen = 4;
1865 cbICVlen = 4;
1866 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1867 }
1868 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1869 cbIVlen = 8;//IV+ExtIV
1870 cbMIClen = 8;
1871 cbICVlen = 4;
1872 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1873 //We need to get seed here for filling TxKey entry.
1874 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1875 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1876 }
1877 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1878 cbIVlen = 8;//RSN Header
1879 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001880 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001881 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001882 }
1883 //MAC Header should be padding 0 to DW alignment.
1884 uPadding = 4 - (cbMacHdLen%4);
1885 uPadding %= 4;
1886 }
1887
1888 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1889
1890 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001891 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001892 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1893 }
1894 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1895
Forest Bond92b96792009-06-13 07:38:31 -04001896 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001897 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001898 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001899
1900 }
1901 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001902 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001903 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001904 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001905 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001906 &(p80211Header->sA3.abyAddr1[0]),
1907 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001908 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001909 &(p80211Header->sA3.abyAddr2[0]),
1910 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001911 //=========================
1912 // No Fragmentation
1913 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001914 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001915
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001916 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001917 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001918 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001919 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001920
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001921 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001922
1923 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1924
Andres Moreb902fbf2013-02-25 20:32:51 -05001925 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1926 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1927 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001928
1929 // Copy the Packet into a tx Buffer
1930 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1931
1932 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001933 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001934 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1935
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001936 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001937 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1938 if (cbExtSuppRate != 0) {
1939 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1940 memcpy((pbyPayloadHead + cbFrameBodySize),
1941 pMgmt->abyCurrSuppRates,
1942 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1943 );
1944 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1945 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1946 pMgmt->abyCurrExtSuppRates,
1947 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1948 );
1949 }
1950 }
1951
1952 // Set wep
1953 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1954
1955 if (pDevice->bEnableHostWEP) {
1956 pTransmitKey = &STempKey;
1957 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1958 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1959 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1960 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1961 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1962 memcpy(pTransmitKey->abyKey,
1963 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1964 pTransmitKey->uKeyLength
1965 );
1966 }
1967
1968 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1969
Andres More52a7e642013-02-25 20:32:53 -05001970 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1971 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001972
1973 // DO Software Michael
1974 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001975 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001976 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001977 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001978 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1979 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001980
1981 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1982
1983 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1984
Andres More52a7e642013-02-25 20:32:53 -05001985 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1986 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001987
1988 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1989 MIC_vUnInit();
1990
Andres More4e9b5e22013-02-12 20:36:30 -05001991 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001992 *pdwMIC_L = 0;
1993 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001994 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001995 }
1996
1997 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1998 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001999 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2000 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002001
2002 }
2003
Malcolm Priestley3ba09382013-10-15 21:41:38 +01002004 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002005 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002006
2007 if (pDevice->bEnableHostWEP) {
2008 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2009 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2010 }
2011
2012 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002013 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002014 }
2015 }
2016
Andres More1cac4a42013-03-18 20:33:50 -05002017 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002018 pDevice->wSeqCounter++ ;
2019 if (pDevice->wSeqCounter > 0x0fff)
2020 pDevice->wSeqCounter = 0;
2021
Forest Bond92b96792009-06-13 07:38:31 -04002022 if (bIsPSPOLL) {
2023 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2024 // of FIFO control header.
2025 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2026 // in the same place of other packet's Duration-field).
2027 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002028 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002029 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2030 tx_cts.tx.head.cts_g.data_head;
2031 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002032 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002033 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002034 cpu_to_le16(p80211Header->sA2.wDurationID);
2035 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002036 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2037 tx_ab.tx.head.data_head_ab;
2038 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002039 cpu_to_le16(p80211Header->sA2.wDurationID);
2040 }
Forest Bond92b96792009-06-13 07:38:31 -04002041 }
2042
Andres More3eaca0d2013-02-25 20:32:52 -05002043 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002044 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002045 pTX_Buffer->byType = 0x00;
2046
2047 pContext->pPacket = skb;
2048 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002049 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002050
Andres More1cac4a42013-03-18 20:33:50 -05002051 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002052 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2053 &pMACHeader->addr1[0], (u16)cbFrameSize,
2054 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002055 }
2056 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002057 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2058 &pMACHeader->addr3[0], (u16)cbFrameSize,
2059 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002060 }
2061 PIPEnsSendBulkOut(pDevice,pContext);
2062 return ;
2063
2064}
2065
Forest Bond92b96792009-06-13 07:38:31 -04002066//TYPE_AC0DMA data tx
2067/*
2068 * Description:
2069 * Tx packet via AC0DMA(DMA1)
2070 *
2071 * Parameters:
2072 * In:
2073 * pDevice - Pointer to the adapter
2074 * skb - Pointer to tx skb packet
2075 * Out:
2076 * void
2077 *
2078 * Return Value: NULL
2079 */
2080
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002081int nsDMA_tx_packet(struct vnt_private *pDevice,
2082 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002083{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002084 struct net_device_stats *pStats = &pDevice->stats;
2085 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002086 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002087 u32 BytesToWrite = 0, uHeaderLen = 0;
2088 u32 uNodeIndex = 0;
2089 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2090 u16 wAID;
2091 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002092 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002093 PSKeyItem pTransmitKey = NULL;
2094 SKeyItem STempKey;
2095 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002096 int bTKIP_UseGTK = false;
2097 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002098 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002099 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002100 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002101 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002102 u32 status;
2103 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002104 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002105
Forest Bond92b96792009-06-13 07:38:31 -04002106 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2107
2108 if (pDevice->uAssocCount == 0) {
2109 dev_kfree_skb_irq(skb);
2110 return 0;
2111 }
2112
Andres Moreb902fbf2013-02-25 20:32:51 -05002113 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002114 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002115 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002116 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2117
2118 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2119 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2120 // set tx map
2121 pMgmt->abyPSTxMap[0] |= byMask[0];
2122 return 0;
2123 }
Masanari Iida93184692012-08-13 21:21:50 +09002124 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002125
2126 if (pDevice->byBBType != BB_TYPE_11A)
2127 pDevice->wCurrentRate = RATE_2M;
2128 else
2129 pDevice->wCurrentRate = RATE_24M;
2130 // long preamble type
2131 pDevice->byPreambleType = PREAMBLE_SHORT;
2132
2133 }else {
2134
Andres Moreb902fbf2013-02-25 20:32:51 -05002135 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002136
2137 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2138
2139 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2140
2141 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2142 // set tx map
2143 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2144 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2146 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2147
2148 return 0;
2149 }
2150 // AP rate decided from node
2151 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2152 // tx preamble decided from node
2153
2154 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2155 pDevice->byPreambleType = pDevice->byShortPreamble;
2156
2157 }else {
2158 pDevice->byPreambleType = PREAMBLE_LONG;
2159 }
Andres More4e9b5e22013-02-12 20:36:30 -05002160 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002161 }
2162 }
2163
Andres Moree269fc22013-02-12 20:36:29 -05002164 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002165 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2166 dev_kfree_skb_irq(skb);
2167 return 0;
2168 }
2169 }
2170
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002171 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002172
2173 if (pContext == NULL) {
2174 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2175 dev_kfree_skb_irq(skb);
2176 return STATUS_RESOURCES;
2177 }
2178
Andres Moreceb8c5d2013-03-18 20:33:49 -05002179 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002180
2181//mike add:station mode check eapol-key challenge--->
2182{
Andres Moreb902fbf2013-02-25 20:32:51 -05002183 u8 Protocol_Version; //802.1x Authentication
2184 u8 Packet_Type; //802.1x Authentication
2185 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002186 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002187
Charles Clément21ec51f2010-05-18 10:08:14 -07002188 Protocol_Version = skb->data[ETH_HLEN];
2189 Packet_Type = skb->data[ETH_HLEN+1];
2190 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2191 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 -05002192 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002193 /* 802.1x OR eapol-key challenge frame transfer */
2194 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2195 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002196 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002197 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2198 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2199 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002200 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002201 PRINT_K("WPA ");
2202 }
2203 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002204 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002205 PRINT_K("WPA2(re-keying) ");
2206 }
2207 PRINT_K("Authentication completed!!\n");
2208 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002209 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002210 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002211 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002212 PRINT_K("WPA2 Authentication completed!!\n");
2213 }
2214 }
2215 }
2216}
2217//mike add:station mode check eapol-key challenge<---
2218
Andres More4e9b5e22013-02-12 20:36:30 -05002219 if (pDevice->bEncryptionEnable == true) {
2220 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002221 // get Transmit key
2222 do {
2223 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2224 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2225 pbyBSSID = pDevice->abyBSSID;
2226 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002227 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002228 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002229 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2230 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002231 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2232 break;
2233 }
2234 } else {
2235 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2236 break;
2237 }
2238 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002239 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2240 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002241 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2242 for (ii = 0; ii< 6; ii++)
2243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2244 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2245
2246 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002247 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002248 break;
2249 }
2250 // get group key
2251 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002252 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002253 pTransmitKey = NULL;
2254 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2255 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2256 }
2257 else
2258 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2259 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002260 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2262 }
Andres Moree269fc22013-02-12 20:36:29 -05002263 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002264 }
2265
2266 if (pDevice->bEnableHostWEP) {
2267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002268 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002269 pTransmitKey = &STempKey;
2270 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2271 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2272 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2273 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2274 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2275 memcpy(pTransmitKey->abyKey,
2276 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2277 pTransmitKey->uKeyLength
2278 );
2279 }
2280 }
2281
Andres Moreb902fbf2013-02-25 20:32:51 -05002282 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002283
2284 if (pDevice->bFixRate) {
2285 if (pDevice->byBBType == BB_TYPE_11B) {
2286 if (pDevice->uConnectionRate >= RATE_11M) {
2287 pDevice->wCurrentRate = RATE_11M;
2288 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002289 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002290 }
2291 } else {
2292 if ((pDevice->byBBType == BB_TYPE_11A) &&
2293 (pDevice->uConnectionRate <= RATE_6M)) {
2294 pDevice->wCurrentRate = RATE_6M;
2295 } else {
2296 if (pDevice->uConnectionRate >= RATE_54M)
2297 pDevice->wCurrentRate = RATE_54M;
2298 else
Andres More3eaca0d2013-02-25 20:32:52 -05002299 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002300 }
2301 }
2302 }
2303 else {
2304 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2305 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002306 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002307 // Multicast use highest data rate
2308 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2309 // preamble type
2310 pDevice->byPreambleType = pDevice->byShortPreamble;
2311 }
2312 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002313 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002314 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2315 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2316 pDevice->byPreambleType = pDevice->byShortPreamble;
2317
2318 }
2319 else {
2320 pDevice->byPreambleType = PREAMBLE_LONG;
2321 }
2322 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2323 }
2324 else {
2325 if (pDevice->byBBType != BB_TYPE_11A)
2326 pDevice->wCurrentRate = RATE_2M;
2327 else
2328 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2329 // abyCurrExtSuppRates[]
2330 pDevice->byPreambleType = PREAMBLE_SHORT;
2331 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2332 }
2333 }
2334 }
2335 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2336 // Infra STA rate decided from AP Node, index = 0
2337 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2338 }
2339 }
2340
Andres Moreceb8c5d2013-03-18 20:33:49 -05002341 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002342 if (pDevice->byBBType != BB_TYPE_11A) {
2343 pDevice->wCurrentRate = RATE_1M;
2344 pDevice->byACKRate = RATE_1M;
2345 pDevice->byTopCCKBasicRate = RATE_1M;
2346 pDevice->byTopOFDMBasicRate = RATE_6M;
2347 } else {
2348 pDevice->wCurrentRate = RATE_6M;
2349 pDevice->byACKRate = RATE_6M;
2350 pDevice->byTopCCKBasicRate = RATE_1M;
2351 pDevice->byTopOFDMBasicRate = RATE_6M;
2352 }
2353 }
Forest Bond92b96792009-06-13 07:38:31 -04002354
Andres More0cbd8d92010-05-06 20:34:29 -03002355 DBG_PRT(MSG_LEVEL_DEBUG,
2356 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2357 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002358
2359 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002360 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002361 }
2362
2363 if (pDevice->wCurrentRate <= RATE_11M) {
2364 byPktType = PK_TYPE_11B;
2365 }
2366
Andres More4e9b5e22013-02-12 20:36:30 -05002367 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2369 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002370 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002372 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2373 if (pTransmitKey == NULL) {
2374 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2375 }
2376 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002377 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2379 }
2380 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2382 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002383 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002384 }
2385 }
2386 }
2387
Forest Bond92b96792009-06-13 07:38:31 -04002388 if (pDevice->bEnableHostWEP) {
2389 if ((uNodeIndex != 0) &&
2390 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2392 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002393 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002394 }
2395 }
2396 }
2397 else {
2398
Forest Bond92b96792009-06-13 07:38:31 -04002399 if (pTransmitKey == NULL) {
2400 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002401 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002402 dev_kfree_skb_irq(skb);
2403 pStats->tx_dropped++;
2404 return STATUS_FAILURE;
2405 }
Forest Bond92b96792009-06-13 07:38:31 -04002406 }
2407 }
2408
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002409 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2410
Forest Bond92b96792009-06-13 07:38:31 -04002411 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002412 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002413 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002414 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002415 pDevice->wCurrentRate,
2416 &uHeaderLen, &BytesToWrite
2417 );
2418
Andres Moree269fc22013-02-12 20:36:29 -05002419 if (fConvertedPacket == false) {
2420 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002421 dev_kfree_skb_irq(skb);
2422 return STATUS_FAILURE;
2423 }
2424
Andres More4e9b5e22013-02-12 20:36:30 -05002425 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002426 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002427 bScheduleCommand((void *) pDevice,
2428 WLAN_CMD_MAC_DISPOWERSAVING,
2429 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002430 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002431 }
2432 }
2433
Andres Moreb902fbf2013-02-25 20:32:51 -05002434 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002435 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002436
2437 pContext->pPacket = skb;
2438 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002439 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002440
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002441 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2442 &pContext->sEthHeader.h_dest[0],
2443 (u16)(BytesToWrite-uHeaderLen),
2444 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002445
2446 status = PIPEnsSendBulkOut(pDevice,pContext);
2447
Andres More4e9b5e22013-02-12 20:36:30 -05002448 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002449 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002450
Andres Moreb902fbf2013-02-25 20:32:51 -05002451 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002452 }
2453
2454 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002455 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002456 dev_kfree_skb_irq(skb);
2457 return STATUS_FAILURE;
2458 }
2459 else
2460 return 0;
2461
2462}
2463
Forest Bond92b96792009-06-13 07:38:31 -04002464/*
2465 * Description:
2466 * Relay packet send (AC1DMA) from rx dpc.
2467 *
2468 * Parameters:
2469 * In:
2470 * pDevice - Pointer to the adapter
2471 * pPacket - Pointer to rx packet
2472 * cbPacketSize - rx ethernet frame size
2473 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002474 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002475 *
Andres More4e9b5e22013-02-12 20:36:30 -05002476 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002477 */
2478
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002479int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2480 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002481{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002482 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002483 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002484 u32 BytesToWrite = 0, uHeaderLen = 0;
2485 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002486 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002487 SKeyItem STempKey;
2488 PSKeyItem pTransmitKey = NULL;
2489 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002490 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002491 u8 byPktTyp;
2492 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002493 u32 status;
2494 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002495
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002496 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002497
2498 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002499 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002500 }
2501
Andres Moreceb8c5d2013-03-18 20:33:49 -05002502 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002503
Andres More4e9b5e22013-02-12 20:36:30 -05002504 if (pDevice->bEncryptionEnable == true) {
2505 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002506 // get group key
2507 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002508 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002509 pTransmitKey = NULL;
2510 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2511 } else {
2512 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2513 }
2514 }
2515
2516 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002517 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002518 pTransmitKey = &STempKey;
2519 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2520 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2521 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2522 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2523 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2524 memcpy(pTransmitKey->abyKey,
2525 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2526 pTransmitKey->uKeyLength
2527 );
2528 }
2529 }
2530
2531 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002532 pContext->bBoolInUse = false;
2533 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002534 }
2535
Andres Moreb902fbf2013-02-25 20:32:51 -05002536 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002537
2538 if (pDevice->bFixRate) {
2539 if (pDevice->byBBType == BB_TYPE_11B) {
2540 if (pDevice->uConnectionRate >= RATE_11M) {
2541 pDevice->wCurrentRate = RATE_11M;
2542 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002543 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002544 }
2545 } else {
2546 if ((pDevice->byBBType == BB_TYPE_11A) &&
2547 (pDevice->uConnectionRate <= RATE_6M)) {
2548 pDevice->wCurrentRate = RATE_6M;
2549 } else {
2550 if (pDevice->uConnectionRate >= RATE_54M)
2551 pDevice->wCurrentRate = RATE_54M;
2552 else
Andres More3eaca0d2013-02-25 20:32:52 -05002553 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002554 }
2555 }
2556 }
2557 else {
2558 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2559 }
2560
Forest Bond92b96792009-06-13 07:38:31 -04002561 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002562 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002563 }
2564
2565 if (pDevice->wCurrentRate <= RATE_11M)
2566 byPktType = PK_TYPE_11B;
2567
Andres Moreabad19d2010-07-12 16:28:32 -03002568 BytesToWrite = uDataLen + ETH_FCS_LEN;
2569
Forest Bond92b96792009-06-13 07:38:31 -04002570 // Convert the packet to an usb frame and copy into our buffer
2571 // and send the irp.
2572
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002573 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2574
Forest Bond92b96792009-06-13 07:38:31 -04002575 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002576 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002577 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2578 pbySkbData, pTransmitKey, uNodeIndex,
2579 pDevice->wCurrentRate,
2580 &uHeaderLen, &BytesToWrite
2581 );
2582
Andres Moree269fc22013-02-12 20:36:29 -05002583 if (fConvertedPacket == false) {
2584 pContext->bBoolInUse = false;
2585 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002586 }
2587
Andres Moreb902fbf2013-02-25 20:32:51 -05002588 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002589 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002590
2591 pContext->pPacket = NULL;
2592 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002593 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002594
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002595 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2596 &pContext->sEthHeader.h_dest[0],
2597 (u16)(BytesToWrite - uHeaderLen),
2598 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002599
2600 status = PIPEnsSendBulkOut(pDevice,pContext);
2601
Andres More4e9b5e22013-02-12 20:36:30 -05002602 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002603}
2604