blob: ac60999bc06764a5747e64137e9da695b1550bd7 [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 Priestley20338012014-03-18 19:25:08 +0000121static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000122 u8 rsv_type, u8 pkt_type, u32 frame_lenght, u16 current_rate);
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 Priestley5abe3d62014-03-18 19:25:06 +0000132static __le16 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 Priestley7f591a12014-03-18 19:25:05 +0000135static __le16 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 Priestleyae27b142013-12-09 22:23:19 +0000169 struct net_device_stats *stats = &pDevice->stats;
Malcolm Priestley51934e72013-12-09 22:30:14 +0000170 struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info;
Forest Bond92b96792009-06-13 07:38:31 -0400171
Malcolm Priestley51934e72013-12-09 22:30:14 +0000172 pkt_info[byPktNum].fifo_ctl = wFIFOCtl;
173 memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN);
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000174
175 stats->tx_bytes += wPktLength;
Forest Bond92b96792009-06-13 07:38:31 -0400176}
177
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100178static void s_vFillTxKey(struct vnt_private *pDevice,
179 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
180 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
181 struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400182{
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100183 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000184 __le32 *pdwIV = (__le32 *)pbyIVHead;
Malcolm Priestley2fbb2302014-03-22 09:01:25 +0000185 __le32 *pdwExtIV = (__le32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500186 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000187 __le32 rev_iv_counter;
Forest Bond92b96792009-06-13 07:38:31 -0400188
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100189 /* Fill TXKEY */
190 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100191 return;
Forest Bond92b96792009-06-13 07:38:31 -0400192
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000193 rev_iv_counter = cpu_to_le32(pDevice->dwIVCounter);
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000194 *pdwIV = cpu_to_le32(pDevice->dwIVCounter);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100195 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400196
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100197 switch (pTransmitKey->byCipherSuite) {
198 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100199 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000200 memcpy(pDevice->abyPRNG, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100201 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
202 pTransmitKey->uKeyLength);
203 } else {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000204 memcpy(pbyBuf, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100205 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
206 pTransmitKey->uKeyLength);
207 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000208 memcpy(pbyBuf+8, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100209 memcpy(pbyBuf+11, pTransmitKey->abyKey,
210 pTransmitKey->uKeyLength);
211 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100212
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100213 memcpy(pDevice->abyPRNG, pbyBuf, 16);
214 }
215 /* Append IV after Mac Header */
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000216 *pdwIV &= cpu_to_le32(WEP_IV_MASK);
217 *pdwIV |= cpu_to_le32((u32)pDevice->byKeyIndex << 30);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100218
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100219 pDevice->dwIVCounter++;
220 if (pDevice->dwIVCounter > WEP_IV_MASK)
221 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100222
223 break;
224 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100225 pTransmitKey->wTSC15_0++;
226 if (pTransmitKey->wTSC15_0 == 0)
227 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100228
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100229 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
230 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
231 pDevice->abyPRNG);
232 memcpy(pbyBuf, pDevice->abyPRNG, 16);
233
234 /* Make IV */
235 memcpy(pdwIV, pDevice->abyPRNG, 3);
236
237 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
238 0xc0) | 0x20);
239 /* Append IV&ExtIV after Mac Header */
240 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
241
242 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
243 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
244
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100245 break;
246 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100247 pTransmitKey->wTSC15_0++;
248 if (pTransmitKey->wTSC15_0 == 0)
249 pTransmitKey->dwTSC47_16++;
250
251 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
252
253 /* Make IV */
254 *pdwIV = 0;
255 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
256 0xc0) | 0x20);
257
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000258 *pdwIV |= cpu_to_le32((u32)(pTransmitKey->wTSC15_0));
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100259
260 /* Append IV&ExtIV after Mac Header */
261 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
262
263 if (!mic_hdr)
264 return;
265
266 /* MICHDR0 */
267 mic_hdr->id = 0x59;
268 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
269 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
270
271 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
272 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
273
274 /* MICHDR1 */
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000275 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100276 mic_hdr->hlen = cpu_to_be16(28);
277 else
278 mic_hdr->hlen = cpu_to_be16(22);
279
280 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
281 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
282
283 /* MICHDR2 */
284 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
Malcolm Priestley5d4fe752014-03-22 09:01:26 +0000285 mic_hdr->frame_control = cpu_to_le16(
286 le16_to_cpu(pMACHeader->frame_control) & 0xc78f);
287 mic_hdr->seq_ctrl = cpu_to_le16(
288 le16_to_cpu(pMACHeader->seq_ctrl) & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100289
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000290 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100291 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
292 }
Forest Bond92b96792009-06-13 07:38:31 -0400293}
294
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000295static void s_vSWencryption(struct vnt_private *pDevice,
296 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400297{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000298 u32 cbICVlen = 4;
299 u32 dwICV = 0xffffffff;
300 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400301
302 if (pTransmitKey == NULL)
303 return;
304
305 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
306 //=======================================================================
307 // Append ICV after payload
308 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500309 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400310 // finally, we must invert dwCRC to get the correct answer
311 *pdwICV = cpu_to_le32(~dwICV);
312 // RC4 encryption
313 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
317 //=======================================================================
318 //Append ICV after payload
319 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500320 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400321 // finally, we must invert dwCRC to get the correct answer
322 *pdwICV = cpu_to_le32(~dwICV);
323 // RC4 encryption
324 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
325 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
326 //=======================================================================
327 }
328}
329
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000330static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100331{
332 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
333 [rate % MAX_RATE]);
334}
335
Forest Bond92b96792009-06-13 07:38:31 -0400336/*byPktType : PK_TYPE_11A 0
337 PK_TYPE_11B 1
338 PK_TYPE_11GB 2
339 PK_TYPE_11GA 3
340*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000341static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
342 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400343{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000344 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400345
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000346 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
347 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400348
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000349 if (pkt_type == PK_TYPE_11B)
350 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
351 (u16)priv->byTopCCKBasicRate);
352 else
353 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
354 (u16)priv->byTopOFDMBasicRate);
355
356 if (need_ack)
357 return data_time + priv->uSIFS + ack_time;
358
359 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400360}
361
Malcolm Priestley2075f652014-03-18 19:25:07 +0000362static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100363 u32 frame_length, u16 rate, int need_ack)
364{
365 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
366 frame_length, rate, need_ack));
367}
368
Forest Bond92b96792009-06-13 07:38:31 -0400369//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000370static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000371 u8 rsv_type, u8 pkt_type, u32 frame_lenght, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400372{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000373 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400374
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000375 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400376
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000377 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
378 frame_lenght, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400379
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000380 if (rsv_type == 0) {
381 rts_time = BBuGetFrameTime(priv->byPreambleType,
382 pkt_type, 20, priv->byTopCCKBasicRate);
383 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
384 pkt_type, 14, priv->byTopCCKBasicRate);
385 } else if (rsv_type == 1) {
386 rts_time = BBuGetFrameTime(priv->byPreambleType,
387 pkt_type, 20, priv->byTopCCKBasicRate);
388 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
389 14, priv->byTopCCKBasicRate);
390 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
391 14, priv->byTopOFDMBasicRate);
392 } else if (rsv_type == 2) {
393 rts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
394 20, priv->byTopOFDMBasicRate);
395 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
396 pkt_type, 14, priv->byTopOFDMBasicRate);
397 } else if (rsv_type == 3) {
398 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
399 14, priv->byTopCCKBasicRate);
400 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
401 14, priv->byTopOFDMBasicRate);
402
403 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
404
Malcolm Priestley20338012014-03-18 19:25:08 +0000405 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000406 }
407
408 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
409
410 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400411}
412
413//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000414static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100415 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400416{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100417 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400418
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100419 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100420 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100421 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
422 byPktType, 14, pDevice->byTopCCKBasicRate);
423 else
424 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
425 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100426 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100427 }
Forest Bond92b96792009-06-13 07:38:31 -0400428
Forest Bond92b96792009-06-13 07:38:31 -0400429 return 0;
430}
431
Forest Bond92b96792009-06-13 07:38:31 -0400432//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000433static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000434 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
435 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400436{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000437 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400438
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100439 switch (byDurType) {
440 case RTSDUR_BB:
441 case RTSDUR_BA:
442 case RTSDUR_BA_F0:
443 case RTSDUR_BA_F1:
444 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
445 14, pDevice->byTopCCKBasicRate);
446 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
447 s_uGetTxRsvTime(pDevice, byPktType,
448 cbFrameLength, wRate, bNeedAck);
449 break;
Forest Bond92b96792009-06-13 07:38:31 -0400450
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100451 case RTSDUR_AA:
452 case RTSDUR_AA_F0:
453 case RTSDUR_AA_F1:
454 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
455 14, pDevice->byTopOFDMBasicRate);
456 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
457 s_uGetTxRsvTime(pDevice, byPktType,
458 cbFrameLength, wRate, bNeedAck);
459 break;
Forest Bond92b96792009-06-13 07:38:31 -0400460
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100461 case CTSDUR_BA:
462 case CTSDUR_BA_F0:
463 case CTSDUR_BA_F1:
464 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100465 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100466 break;
Forest Bond92b96792009-06-13 07:38:31 -0400467
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100468 default:
469 break;
470 }
Forest Bond92b96792009-06-13 07:38:31 -0400471
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100472 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400473}
474
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100475static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
476 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
477{
478 /* Get SignalField,ServiceField,Length */
479 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
480 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
481 PK_TYPE_11B, &buf->b);
482
483 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000484 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
485 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100486
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000487 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
488 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100489 priv->byTopCCKBasicRate);
490
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000491 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100492}
493
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100494static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
495 u16 rate, struct vnt_tx_datahead_g_fb *buf,
496 u32 frame_len, int need_ack)
497{
498 /* Get SignalField,ServiceField,Length */
499 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
500
501 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
502 PK_TYPE_11B, &buf->b);
503
504 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000505 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
506 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100507
Malcolm Priestley4e011172014-03-18 19:24:55 +0000508 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
509 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100510
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000511 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
512 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100513 priv->byTopCCKBasicRate);
514
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000515 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100516}
517
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100518static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
519 u16 rate, struct vnt_tx_datahead_a_fb *buf,
520 u32 frame_len, int need_ack)
521{
522 /* Get SignalField,ServiceField,Length */
523 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
524 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000525 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100526
Malcolm Priestley4e011172014-03-18 19:24:55 +0000527 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
528 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100529
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000530 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100531
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000532 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100533}
534
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100535static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
536 u16 rate, struct vnt_tx_datahead_ab *buf,
537 u32 frame_len, int need_ack)
538{
539 /* Get SignalField,ServiceField,Length */
540 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
541 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000542 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100543
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000544 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100545
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000546 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100547}
548
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100549static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
550 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000551 __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100552{
553 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000554 rts->frame_control =
555 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100556
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000557 if (priv->op_mode == NL80211_IFTYPE_ADHOC ||
558 priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100559 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
560 else
561 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
562
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000563 if (priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100564 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
565 else
566 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
567
568 return 0;
569}
570
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100571static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100572 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
573 u8 pkt_type, u32 frame_len, int need_ack,
574 u16 current_rate, u8 fb_option)
575{
576 u16 rts_frame_len = 20;
577
578 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
579 PK_TYPE_11B, &buf->b);
580 BBvCalculateParameter(priv, rts_frame_len,
581 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
582
Malcolm Priestley4e011172014-03-18 19:24:55 +0000583 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100584 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000585 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100586 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000587 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100588 pkt_type, current_rate, need_ack, fb_option);
589
Malcolm Priestley4e011172014-03-18 19:24:55 +0000590 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100591
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100592 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
593 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100594}
595
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100596static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100597 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
598 u8 pkt_type, u32 frame_len, int need_ack,
599 u16 current_rate, u8 fb_option)
600{
601 u16 rts_frame_len = 20;
602
603 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
604 PK_TYPE_11B, &buf->b);
605 BBvCalculateParameter(priv, rts_frame_len,
606 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
607
608
Malcolm Priestley4e011172014-03-18 19:24:55 +0000609 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100610 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000611 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100612 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000613 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100614 pkt_type, current_rate, need_ack, fb_option);
615
616
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000617 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100618 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000619 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100620 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000621 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100622 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000623 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100624 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100625
Malcolm Priestley4e011172014-03-18 19:24:55 +0000626 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100627
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100628 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
629 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100630}
631
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100632static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100633 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
634 u8 pkt_type, u32 frame_len, int need_ack,
635 u16 current_rate, u8 fb_option)
636{
637 u16 rts_frame_len = 20;
638
639 BBvCalculateParameter(priv, rts_frame_len,
640 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
641
Malcolm Priestley4e011172014-03-18 19:24:55 +0000642 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100643 pkt_type, current_rate, need_ack, fb_option);
644
Malcolm Priestley4e011172014-03-18 19:24:55 +0000645 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100646
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100647 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
648 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100649}
650
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100651static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100652 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
653 u8 pkt_type, u32 frame_len, int need_ack,
654 u16 current_rate, u8 fb_option)
655{
656 u16 rts_frame_len = 20;
657
658 BBvCalculateParameter(priv, rts_frame_len,
659 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
660
Malcolm Priestley4e011172014-03-18 19:24:55 +0000661 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100662 pkt_type, current_rate, need_ack, fb_option);
663
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000664 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100665 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100666
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000667 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100668 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100669
Malcolm Priestley4e011172014-03-18 19:24:55 +0000670 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100671
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100672 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
673 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100674}
675
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100676static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100677 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500678 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400679{
Forest Bond92b96792009-06-13 07:38:31 -0400680
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100681 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100682 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400683
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100684 /* Note: So far RTSHead doesn't appear in ATIM
685 * & Beacom DMA, so we don't need to take them
686 * into account.
687 * Otherwise, we need to modified codes for them.
688 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100689 switch (byPktType) {
690 case PK_TYPE_11GB:
691 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100692 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100693 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100694 psEthHeader, byPktType, cbFrameLength,
695 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100696 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100697 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100698 psEthHeader, byPktType, cbFrameLength,
699 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100700 break;
701 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100702 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100703 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100704 psEthHeader, byPktType, cbFrameLength,
705 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100706 break;
707 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100708 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100709 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100710 psEthHeader, byPktType, cbFrameLength,
711 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100712 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100713
714 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400715}
716
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100717static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100718 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
719 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400720{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000721 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400722
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100723 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100724 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400725
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100726 if (byFBOption != AUTO_FB_NONE) {
727 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100728 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100729 /* Get SignalField,ServiceField,Length */
730 BBvCalculateParameter(pDevice, uCTSFrameLen,
731 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000732 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100733 cbFrameLength, byPktType,
734 wCurrentRate, bNeedAck, byFBOption);
735 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000736 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100737 CTSDUR_BA_F0, cbFrameLength, byPktType,
738 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100739 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000740 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100741 CTSDUR_BA_F1, cbFrameLength, byPktType,
742 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100743 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000744 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100745 pBuf->data.frame_control = TYPE_CTL_CTS;
746 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100747
748 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
749 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100750 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100751 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100752 /* Get SignalField,ServiceField,Length */
753 BBvCalculateParameter(pDevice, uCTSFrameLen,
754 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100755 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000756 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100757 CTSDUR_BA, cbFrameLength, byPktType,
758 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100759 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000760 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100761 pBuf->data.frame_control = TYPE_CTL_CTS;
762 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100763
764 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
765 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400766 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100767
768 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400769}
770
Forest Bond92b96792009-06-13 07:38:31 -0400771/*+
772 *
773 * Description:
774 * Generate FIFO control for MAC & Baseband controller
775 *
776 * Parameters:
777 * In:
778 * pDevice - Pointer to adpater
779 * pTxDataHead - Transmit Data Buffer
780 * pTxBufHead - pTxBufHead
781 * pvRrvTime - pvRrvTime
782 * pvRTS - RTS Buffer
783 * pCTS - CTS Buffer
784 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
785 * bNeedACK - If need ACK
786 * uDMAIdx - DMA Index
787 * Out:
788 * none
789 *
790 * Return Value: none
791 *
792-*/
Andres Morecc856e62010-05-17 21:34:01 -0300793
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100794static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100795 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100796 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
797 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400798{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100799 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100800 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000801 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000802 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400803
Malcolm Priestley03a9cf32014-03-22 09:01:30 +0000804 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100805 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400806
Malcolm Priestley92928f12013-10-07 20:14:01 +0100807 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
808 byFBOption = AUTO_FB_0;
809 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
810 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400811
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100812 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100813 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100814
Malcolm Priestley92928f12013-10-07 20:14:01 +0100815 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
816 if (need_rts) {
817 struct vnt_rrv_time_rts *pBuf =
818 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100819
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000820 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100821 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000822 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100823 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000824 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100825 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100826
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000827 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100828 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000829 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100830 PK_TYPE_11B, cbFrameSize,
831 pDevice->byTopCCKBasicRate, bNeedACK);
832
833 if (need_mic) {
834 *mic_hdr = &tx_buffer->
835 tx_head.tx_rts.tx.mic.hdr;
836 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
837 } else {
838 head = &tx_buffer->tx_head.tx_rts.tx.head;
839 }
840
841 /* Fill RTS */
842 return s_vFillRTSHead(pDevice, byPktType, head,
843 cbFrameSize, bNeedACK, psEthHeader,
844 wCurrentRate, byFBOption);
845
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100846 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100847 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
848 tx_head.tx_cts.cts;
849
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000850 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100851 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000852 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100853 PK_TYPE_11B, cbFrameSize,
854 pDevice->byTopCCKBasicRate, bNeedACK);
855
Malcolm Priestley372108e2014-03-18 19:25:00 +0000856 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100857 byPktType, cbFrameSize, wCurrentRate);
858
859 if (need_mic) {
860 *mic_hdr = &tx_buffer->
861 tx_head.tx_cts.tx.mic.hdr;
862 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
863 } else {
864 head = &tx_buffer->tx_head.tx_cts.tx.head;
865 }
866
867 /* Fill CTS */
868 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
869 head, cbFrameSize, bNeedACK, wCurrentRate,
870 byFBOption);
871 }
872 } else if (byPktType == PK_TYPE_11A) {
873 if (need_mic) {
874 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
875 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
876 } else {
877 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100878 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100879
Malcolm Priestley92928f12013-10-07 20:14:01 +0100880 if (need_rts) {
881 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
882 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100883
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000884 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100885 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100886
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000887 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100888 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
889
890 /* Fill RTS */
891 return s_vFillRTSHead(pDevice, byPktType, head,
892 cbFrameSize, bNeedACK, psEthHeader,
893 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100894 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100895 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
896 tx_head.tx_ab.ab;
897
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000898 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100899 PK_TYPE_11A, cbFrameSize,
900 wCurrentRate, bNeedACK);
901
902 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
903 wCurrentRate, &head->data_head_a_fb,
904 cbFrameSize, bNeedACK);
905 }
906 } else if (byPktType == PK_TYPE_11B) {
907 if (need_mic) {
908 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
909 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
910 } else {
911 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100912 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100913
Malcolm Priestley92928f12013-10-07 20:14:01 +0100914 if (need_rts) {
915 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
916 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100917
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000918 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100919 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100920
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000921 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100922 PK_TYPE_11B, cbFrameSize, wCurrentRate,
923 bNeedACK);
924
925 /* Fill RTS */
926 return s_vFillRTSHead(pDevice, byPktType, head,
927 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100928 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100929 } else {
930 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
931 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100932
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000933 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100934 PK_TYPE_11B, cbFrameSize,
935 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100936
Malcolm Priestley92928f12013-10-07 20:14:01 +0100937 return vnt_rxtx_datahead_ab(pDevice, byPktType,
938 wCurrentRate, &head->data_head_ab,
939 cbFrameSize, bNeedACK);
940 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100941 }
942
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100943 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400944}
945/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500946 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500947 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300948 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400949*/
950
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000951static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100952 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100953 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
954 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
955 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400956{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100957 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000958 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
959 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000960 u32 cb802_1_H_len;
961 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
962 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100963 int bNeedACK;
964 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000965 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
966 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
967 u8 abySNAP_Bridgetunnel[ETH_ALEN]
968 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
969 u32 uDuration;
970 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100971 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000972 u8 byFBOption = AUTO_FB_NONE, byFragType;
973 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100974 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000975 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500976 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100977
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100978 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400979
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000980 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500981 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
982 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000983 }
Forest Bond92b96792009-06-13 07:38:31 -0400984
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000985 /* Get pkt type */
986 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
987 cb802_1_H_len = 8;
988 else
989 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400990
Charles Clément21ec51f2010-05-18 10:08:14 -0700991 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400992
993 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500994 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400995
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000996 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC ||
997 pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500998 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500999 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001000 pTxBufHead->wFIFOCtl =
1001 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1002 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001003 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001004 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1005 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001006 } else {
1007 /* MSDUs in Infra mode always need ACK */
1008 bNeedACK = true;
1009 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1010 }
Forest Bond92b96792009-06-13 07:38:31 -04001011
Malcolm Priestley58462512014-03-22 09:01:27 +00001012 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001013
Forest Bond92b96792009-06-13 07:38:31 -04001014 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001015 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1016
Andres More3eaca0d2013-02-25 20:32:52 -05001017 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001018
1019 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001020 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001021 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1022 }
1023
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001024 /* Set Auto Fallback Ctl */
1025 if (wCurrentRate >= RATE_18M) {
1026 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1027 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1028
1029 pDevice->tx_rate_fb0 =
1030 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1031 pDevice->tx_rate_fb1 =
1032 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1033
1034 byFBOption = AUTO_FB_0;
1035 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1036 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1037 pDevice->tx_rate_fb0 =
1038 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1039 pDevice->tx_rate_fb1 =
1040 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1041
1042 byFBOption = AUTO_FB_1;
1043 }
1044 }
Forest Bond92b96792009-06-13 07:38:31 -04001045
Andres More4e9b5e22013-02-12 20:36:30 -05001046 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001047 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1048 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1049 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1050 }
1051 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1052 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1053 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1054 }
1055 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1056 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1057 }
1058 }
1059 }
1060
Forest Bond92b96792009-06-13 07:38:31 -04001061 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1062 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1063 cbIVlen = 4;
1064 cbICVlen = 4;
1065 }
1066 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1067 cbIVlen = 8;//IV+ExtIV
1068 cbMIClen = 8;
1069 cbICVlen = 4;
1070 }
1071 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1072 cbIVlen = 8;//RSN Header
1073 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001074 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001075 }
Andres Moree269fc22013-02-12 20:36:29 -05001076 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001077 //MAC Header should be padding 0 to DW alignment.
1078 uPadding = 4 - (cbMACHdLen%4);
1079 uPadding %= 4;
1080 }
1081 }
1082
1083 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1084
Andres Moree269fc22013-02-12 20:36:29 -05001085 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1086 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001087 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001088 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001089 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1090 }
1091
Andres Moreb902fbf2013-02-25 20:32:51 -05001092 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001093 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1094
Forest Bond92b96792009-06-13 07:38:31 -04001095 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1096 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001097 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001098 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001099 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001100 }
1101 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001102 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001103 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001104 }
1105 } else {
1106 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001107 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001108 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001109 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001110 }
Andres Moree269fc22013-02-12 20:36:29 -05001111 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001112 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001113 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001114 }
1115 } // Auto Fall Back
1116 }
1117 else {//802.11a/b packet
1118 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001119 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001120 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001121 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001122 }
Andres Moree269fc22013-02-12 20:36:29 -05001123 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001124 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001125 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001126 }
1127 } else {
1128 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001129 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001130 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001131 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001132 }
Andres Moree269fc22013-02-12 20:36:29 -05001133 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001134 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001135 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001136 }
1137 } // Auto Fall Back
1138 }
1139
Andres Moreb902fbf2013-02-25 20:32:51 -05001140 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1141 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1142 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001143
Forest Bond92b96792009-06-13 07:38:31 -04001144 //=========================
1145 // No Fragmentation
1146 //=========================
1147 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1148 byFragType = FRAGCTL_NONFRAG;
1149 //uDMAIdx = TYPE_AC0DMA;
1150 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1151
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001152 /* Fill FIFO, RrvTime, RTS and CTS */
1153 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1154 tx_buffer, &pMICHDR, cbMICHDR,
1155 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001156
Forest Bond92b96792009-06-13 07:38:31 -04001157 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001158 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001159 byFragType, uDMAIdx, 0);
1160
Andres More4e9b5e22013-02-12 20:36:30 -05001161 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001162 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001163 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001164 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001165
1166 if (pDevice->bEnableHostWEP) {
1167 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1168 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1169 }
1170 }
1171
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001172 /* 802.1H */
1173 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001174 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001175 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001176 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001177 abySNAP_Bridgetunnel, 6);
1178 else
1179 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001180
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001181 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001182
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001183 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1184 }
Forest Bond92b96792009-06-13 07:38:31 -04001185
Forest Bond92b96792009-06-13 07:38:31 -04001186 if (pPacket != NULL) {
1187 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001188 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001189 (pPacket + ETH_HLEN),
1190 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001191 );
1192
1193 } else {
1194 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001195 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001196 }
1197
Andres More4e9b5e22013-02-12 20:36:30 -05001198 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001199
1200 ///////////////////////////////////////////////////////////////////
1201
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001202 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1203 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1204 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1205 }
Forest Bond92b96792009-06-13 07:38:31 -04001206 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001207 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1208 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001209 }
1210 else {
Andres More52a7e642013-02-25 20:32:53 -05001211 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1212 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001213 }
1214 // DO Software Michael
1215 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001216 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001217 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001218 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001219 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1220 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001221
1222 ///////////////////////////////////////////////////////////////////
1223
1224 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1225 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001226 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001227 //}
1228 //DBG_PRN_GRP12(("\n\n\n"));
1229
1230 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1231
Andres More52a7e642013-02-25 20:32:53 -05001232 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1233 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001234
1235 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1236 MIC_vUnInit();
1237
Andres More4e9b5e22013-02-12 20:36:30 -05001238 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001239 *pdwMIC_L = 0;
1240 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001241 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001242 }
1243 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1244 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1245 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1246 }
1247
Andres More4e9b5e22013-02-12 20:36:30 -05001248 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001249
Andres More3eaca0d2013-02-25 20:32:52 -05001250 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001251
Andres More4e9b5e22013-02-12 20:36:30 -05001252 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1253 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1254 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001255 cbFrameSize -= cbICVlen;
1256 }
1257
Forest Bond92b96792009-06-13 07:38:31 -04001258 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001259
1260 *pcbHeaderLen = cbHeaderLength;
1261 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1262
Forest Bond92b96792009-06-13 07:38:31 -04001263 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001264 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001265
Andres More4e9b5e22013-02-12 20:36:30 -05001266 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001267
1268}
1269
Forest Bond92b96792009-06-13 07:38:31 -04001270/*+
1271 *
1272 * Description:
1273 * Translate 802.3 to 802.11 header
1274 *
1275 * Parameters:
1276 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001277 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001278 * dwTxBufferAddr - Transmit Buffer
1279 * pPacket - Packet from upper layer
1280 * cbPacketSize - Transmit Data Length
1281 * Out:
1282 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1283 * pcbAppendPayload - size of append payload for 802.1H translation
1284 *
1285 * Return Value: none
1286 *
1287-*/
1288
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001289static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001290 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001291 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001292{
Andres More1cac4a42013-03-18 20:33:50 -05001293 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001294
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001295 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001296
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001297 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001298 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001299 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001300 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001301 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1302 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001303 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001304 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001305 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001306 } else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001307 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001308 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001309 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001310 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001311 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001312 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001313 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001314 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001315 &(pDevice->abyBSSID[0]),
1316 ETH_ALEN);
1317 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001318 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001319 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001320 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001321 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001322 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001323 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001324 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001325 &(pDevice->abyBSSID[0]),
1326 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001327 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001328 }
1329 }
1330
1331 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001332 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001333
Andres More1cac4a42013-03-18 20:33:50 -05001334 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001335
Andres More1cac4a42013-03-18 20:33:50 -05001336 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001337
1338 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001339 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001340
1341 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1342 pDevice->wSeqCounter++;
1343 if (pDevice->wSeqCounter > 0x0fff)
1344 pDevice->wSeqCounter = 0;
1345 }
1346
1347 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001348 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001349 }
1350}
1351
Forest Bond92b96792009-06-13 07:38:31 -04001352/*+
1353 *
1354 * Description:
1355 * Request instructs a MAC to transmit a 802.11 management packet through
1356 * the adapter onto the medium.
1357 *
1358 * Parameters:
1359 * In:
1360 * hDeviceContext - Pointer to the adapter
1361 * pPacket - A pointer to a descriptor for the packet to transmit
1362 * Out:
1363 * none
1364 *
Andres Moree269fc22013-02-12 20:36:29 -05001365 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001366 *
1367-*/
1368
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001369CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1370 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001371{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001372 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001373 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001374 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001375 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001376 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001377 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001378 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001379 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001380 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001381 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001382 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1383 u32 uPadding = 0;
1384 u16 wTxBufSize;
1385 u32 cbMacHdLen;
1386 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001387
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001388 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001389
1390 if (NULL == pContext) {
1391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1392 return CMD_STATUS_RESOURCES;
1393 }
1394
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001395 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001396 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001397 pTxBufHead = &pTX_Buffer->fifo_head;
1398 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1399 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001400
1401 if (pDevice->byBBType == BB_TYPE_11A) {
1402 wCurrentRate = RATE_6M;
1403 byPktType = PK_TYPE_11A;
1404 } else {
1405 wCurrentRate = RATE_1M;
1406 byPktType = PK_TYPE_11B;
1407 }
1408
1409 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1410 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1411 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1412 // to set power here.
1413 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1414 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1415 } else {
1416 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1417 }
1418 pDevice->wCurrentRate = wCurrentRate;
1419
Forest Bond92b96792009-06-13 07:38:31 -04001420 //Set packet type
1421 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1422 pTxBufHead->wFIFOCtl = 0;
1423 }
1424 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1425 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1426 }
1427 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1428 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1429 }
1430 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1431 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1432 }
1433
1434 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
Malcolm Priestley58462512014-03-22 09:01:27 +00001435 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001436
Andres More22040bb2010-08-02 20:21:44 -03001437 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001438 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001439 }
1440 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001441 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001442 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1443 };
1444
1445 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1446 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1447
1448 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1449 //Set Preamble type always long
1450 //pDevice->byPreambleType = PREAMBLE_LONG;
1451 // probe-response don't retry
1452 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001453 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001454 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1455 //}
1456 }
1457
1458 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1459
1460 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001461 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001462 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1463 } else {
1464 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1465 }
1466
1467 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001468 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001469
1470 // Notes:
1471 // Although spec says MMPDU can be fragmented; In most case,
1472 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001473
1474 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1475 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1476 cbIVlen = 4;
1477 cbICVlen = 4;
1478 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1479 }
1480 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1481 cbIVlen = 8;//IV+ExtIV
1482 cbMIClen = 8;
1483 cbICVlen = 4;
1484 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1485 //We need to get seed here for filling TxKey entry.
1486 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1487 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1488 }
1489 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1490 cbIVlen = 8;//RSN Header
1491 cbICVlen = 8;//MIC
1492 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001493 }
1494 //MAC Header should be padding 0 to DW alignment.
1495 uPadding = 4 - (cbMacHdLen%4);
1496 uPadding %= 4;
1497 }
1498
1499 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1500
1501 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001502 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001503 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1504 }
1505 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1506
1507 //Set RrvTime/RTS/CTS Buffer
1508 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001509 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001510 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001511 }
1512 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001513 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001514 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001515 }
1516
Andres Moreceb8c5d2013-03-18 20:33:49 -05001517 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001518 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1519 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001520 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001521 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1522 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001523 //=========================
1524 // No Fragmentation
1525 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001526 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001527
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001528 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001529 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001530 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001531 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001532
Andres More1cac4a42013-03-18 20:33:50 -05001533 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001534
1535 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1536
1537 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001538 u8 * pbyIVHead;
1539 u8 * pbyPayloadHead;
1540 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001541 PSKeyItem pTransmitKey = NULL;
1542
Andres Moreb902fbf2013-02-25 20:32:51 -05001543 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1544 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001545 do {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001546 if (pDevice->op_mode == NL80211_IFTYPE_STATION &&
1547 pDevice->bLinkPass == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001548 pbyBSSID = pDevice->abyBSSID;
1549 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001550 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001551 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001552 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1554 break;
1555 }
1556 } else {
1557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1558 break;
1559 }
1560 }
1561 // get group key
1562 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001563 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001564 pTransmitKey = NULL;
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001565 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode);
Forest Bond92b96792009-06-13 07:38:31 -04001566 } else {
1567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1568 }
Andres Moree269fc22013-02-12 20:36:29 -05001569 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001570 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001571 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001572 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001573
Jim Lieb3e362592009-08-12 14:54:11 -07001574 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001575 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001576 cbFrameBodySize);
1577 }
1578 else {
1579 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001580 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001581 }
1582
Andres More1cac4a42013-03-18 20:33:50 -05001583 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001584 pDevice->wSeqCounter++ ;
1585 if (pDevice->wSeqCounter > 0x0fff)
1586 pDevice->wSeqCounter = 0;
1587
1588 if (bIsPSPOLL) {
1589 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001590 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001591 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1592 // in the same place of other packet's Duration-field).
1593 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001594 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001595 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1596 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001597 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001598 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00001599 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001600 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1601 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001602 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1603 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001604 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001605 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1606 }
Forest Bond92b96792009-06-13 07:38:31 -04001607 }
1608
Malcolm Priestleyca347592014-03-22 09:01:28 +00001609 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001610 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001611 pTX_Buffer->byType = 0x00;
1612
1613 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00001614 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001615 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001616
Andres More1cac4a42013-03-18 20:33:50 -05001617 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001618 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1619 &pMACHeader->addr1[0], (u16)cbFrameSize,
1620 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001621 }
1622 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001623 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1624 &pMACHeader->addr3[0], (u16)cbFrameSize,
1625 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001626 }
1627
1628 PIPEnsSendBulkOut(pDevice,pContext);
1629 return CMD_STATUS_PENDING;
1630}
1631
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001632CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1633 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001634{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001635 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001636 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001637 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1638 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001639 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001640 u16 wCurrentRate;
1641 u32 cbFrameBodySize;
1642 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001643 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001644 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001645
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001646 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001647 if (NULL == pContext) {
1648 status = CMD_STATUS_RESOURCES;
1649 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1650 return status ;
1651 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001652
1653 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001654 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001655
1656 cbFrameBodySize = pPacket->cbPayloadLen;
1657
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001658 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001659
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001660 if (pDevice->byBBType == BB_TYPE_11A) {
1661 wCurrentRate = RATE_6M;
1662
1663 /* Get SignalField,ServiceField,Length */
1664 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1665 PK_TYPE_11A, &short_head->ab);
1666
1667 /* Get Duration and TimeStampOff */
1668 short_head->duration = s_uGetDataDuration(pDevice,
1669 PK_TYPE_11A, false);
1670 short_head->time_stamp_off =
1671 vnt_time_stamp_off(pDevice, wCurrentRate);
1672 } else {
1673 wCurrentRate = RATE_1M;
1674 short_head->fifo_ctl |= FIFOCTL_11B;
1675
1676 /* Get SignalField,ServiceField,Length */
1677 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1678 PK_TYPE_11B, &short_head->ab);
1679
1680 /* Get Duration and TimeStampOff */
1681 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001682 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001683 short_head->time_stamp_off =
1684 vnt_time_stamp_off(pDevice, wCurrentRate);
1685 }
1686
Forest Bond92b96792009-06-13 07:38:31 -04001687
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001688 /* Generate Beacon Header */
1689 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001690
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001691 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1692
1693 pMACHeader->duration_id = 0;
1694 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1695 pDevice->wSeqCounter++;
1696 if (pDevice->wSeqCounter > 0x0fff)
1697 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001698
1699 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1700
Malcolm Priestleyfad8e4a2014-03-22 09:01:29 +00001701 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)cbReqCount);
Andres Moreb902fbf2013-02-25 20:32:51 -05001702 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001703 pTX_Buffer->byType = 0x01;
1704
1705 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00001706 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001707 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001708
1709 PIPEnsSendBulkOut(pDevice,pContext);
1710 return CMD_STATUS_PENDING;
1711
1712}
1713
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001714void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1715{
1716 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001717 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001718 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001719 u8 byPktType;
1720 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001721 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001722 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001723 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001724 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001725 u32 cbFrameSize;
1726 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1727 u32 uPadding = 0;
1728 u32 cbMICHDR = 0, uLength = 0;
1729 u32 dwMICKey0, dwMICKey1;
1730 u32 dwMIC_Priority;
1731 u32 *pdwMIC_L, *pdwMIC_R;
1732 u16 wTxBufSize;
1733 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001734 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001735 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001736 u32 wCurrentRate = RATE_1M;
1737 PUWLAN_80211HDR p80211Header;
1738 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001739 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001740 SKeyItem STempKey;
1741 PSKeyItem pTransmitKey = NULL;
1742 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1743 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001744 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001745
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001746 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001747
1748 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1749 cbFrameBodySize = 0;
1750 }
1751 else {
1752 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1753 }
1754 p80211Header = (PUWLAN_80211HDR)skb->data;
1755
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001756 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001757
1758 if (NULL == pContext) {
1759 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1760 dev_kfree_skb_irq(skb);
1761 return ;
1762 }
1763
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001764 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001765 pTxBufHead = &pTX_Buffer->fifo_head;
1766 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1767 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001768
1769 if (pDevice->byBBType == BB_TYPE_11A) {
1770 wCurrentRate = RATE_6M;
1771 byPktType = PK_TYPE_11A;
1772 } else {
1773 wCurrentRate = RATE_1M;
1774 byPktType = PK_TYPE_11B;
1775 }
1776
1777 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1778 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1779 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1780 // to set power here.
1781 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1782 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1783 } else {
1784 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1785 }
1786
1787 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1788
1789 //Set packet type
1790 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1791 pTxBufHead->wFIFOCtl = 0;
1792 }
1793 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1794 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1795 }
1796 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1797 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1798 }
1799 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1800 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1801 }
1802
1803 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
Malcolm Priestley58462512014-03-22 09:01:27 +00001804 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001805
Andres More22040bb2010-08-02 20:21:44 -03001806 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001807 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001808 if (pDevice->bEnableHostWEP) {
1809 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001810 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001811 }
Forest Bond92b96792009-06-13 07:38:31 -04001812 }
1813 else {
1814 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001815 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001816 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001817 }
Andres More4e9b5e22013-02-12 20:36:30 -05001818 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001819 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1820 };
1821
1822 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1823 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1824
1825 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1826 //Set Preamble type always long
1827 //pDevice->byPreambleType = PREAMBLE_LONG;
1828
1829 // probe-response don't retry
1830 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001831 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001832 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1833 //}
1834 }
1835
1836 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1837
1838 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001839 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001840 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1841 } else {
1842 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1843 }
1844
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001845 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001846 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1847
1848 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1849 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1850 }
1851
1852 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1853 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1854 }
1855
1856 if (cbExtSuppRate >0) {
1857 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1858 }
1859 }
1860
Forest Bond92b96792009-06-13 07:38:31 -04001861 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001862 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001863
1864 // Notes:
1865 // Although spec says MMPDU can be fragmented; In most case,
1866 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001867
Forest Bond92b96792009-06-13 07:38:31 -04001868 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1869 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1870 cbIVlen = 4;
1871 cbICVlen = 4;
1872 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1873 }
1874 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1875 cbIVlen = 8;//IV+ExtIV
1876 cbMIClen = 8;
1877 cbICVlen = 4;
1878 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1879 //We need to get seed here for filling TxKey entry.
1880 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1881 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1882 }
1883 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1884 cbIVlen = 8;//RSN Header
1885 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001886 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001887 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001888 }
1889 //MAC Header should be padding 0 to DW alignment.
1890 uPadding = 4 - (cbMacHdLen%4);
1891 uPadding %= 4;
1892 }
1893
1894 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1895
1896 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001897 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001898 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1899 }
1900 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1901
Forest Bond92b96792009-06-13 07:38:31 -04001902 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001903 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001904 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001905
1906 }
1907 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001908 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001909 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001910 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001911 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001912 &(p80211Header->sA3.abyAddr1[0]),
1913 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001914 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001915 &(p80211Header->sA3.abyAddr2[0]),
1916 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001917 //=========================
1918 // No Fragmentation
1919 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001920 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001921
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001922 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001923 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001924 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001925 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001926
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001927 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001928
1929 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1930
Andres Moreb902fbf2013-02-25 20:32:51 -05001931 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1932 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1933 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001934
1935 // Copy the Packet into a tx Buffer
1936 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1937
1938 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001939 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001940 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1941
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001942 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001943 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1944 if (cbExtSuppRate != 0) {
1945 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1946 memcpy((pbyPayloadHead + cbFrameBodySize),
1947 pMgmt->abyCurrSuppRates,
1948 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1949 );
1950 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1951 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1952 pMgmt->abyCurrExtSuppRates,
1953 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1954 );
1955 }
1956 }
1957
1958 // Set wep
1959 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1960
1961 if (pDevice->bEnableHostWEP) {
1962 pTransmitKey = &STempKey;
1963 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1964 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1965 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1966 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1967 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1968 memcpy(pTransmitKey->abyKey,
1969 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1970 pTransmitKey->uKeyLength
1971 );
1972 }
1973
1974 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1975
Andres More52a7e642013-02-25 20:32:53 -05001976 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1977 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001978
1979 // DO Software Michael
1980 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001981 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001982 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001983 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001984 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1985 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001986
1987 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1988
1989 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1990
Andres More52a7e642013-02-25 20:32:53 -05001991 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1992 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001993
1994 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1995 MIC_vUnInit();
1996
Andres More4e9b5e22013-02-12 20:36:30 -05001997 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001998 *pdwMIC_L = 0;
1999 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002000 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002001 }
2002
2003 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2004 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002005 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2006 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002007
2008 }
2009
Malcolm Priestley3ba09382013-10-15 21:41:38 +01002010 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002011 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002012
2013 if (pDevice->bEnableHostWEP) {
2014 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2015 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2016 }
2017
2018 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002019 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002020 }
2021 }
2022
Andres More1cac4a42013-03-18 20:33:50 -05002023 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002024 pDevice->wSeqCounter++ ;
2025 if (pDevice->wSeqCounter > 0x0fff)
2026 pDevice->wSeqCounter = 0;
2027
Forest Bond92b96792009-06-13 07:38:31 -04002028 if (bIsPSPOLL) {
2029 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2030 // of FIFO control header.
2031 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2032 // in the same place of other packet's Duration-field).
2033 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002034 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002035 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2036 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00002037 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002038 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00002039 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002040 cpu_to_le16(p80211Header->sA2.wDurationID);
2041 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002042 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2043 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00002044 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002045 cpu_to_le16(p80211Header->sA2.wDurationID);
2046 }
Forest Bond92b96792009-06-13 07:38:31 -04002047 }
2048
Malcolm Priestleyca347592014-03-22 09:01:28 +00002049 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002050 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002051 pTX_Buffer->byType = 0x00;
2052
2053 pContext->pPacket = skb;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002054 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002055 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002056
Andres More1cac4a42013-03-18 20:33:50 -05002057 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002058 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2059 &pMACHeader->addr1[0], (u16)cbFrameSize,
2060 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002061 }
2062 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002063 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2064 &pMACHeader->addr3[0], (u16)cbFrameSize,
2065 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002066 }
2067 PIPEnsSendBulkOut(pDevice,pContext);
2068 return ;
2069
2070}
2071
Forest Bond92b96792009-06-13 07:38:31 -04002072//TYPE_AC0DMA data tx
2073/*
2074 * Description:
2075 * Tx packet via AC0DMA(DMA1)
2076 *
2077 * Parameters:
2078 * In:
2079 * pDevice - Pointer to the adapter
2080 * skb - Pointer to tx skb packet
2081 * Out:
2082 * void
2083 *
2084 * Return Value: NULL
2085 */
2086
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002087int nsDMA_tx_packet(struct vnt_private *pDevice,
2088 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002089{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002090 struct net_device_stats *pStats = &pDevice->stats;
2091 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002092 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002093 u32 BytesToWrite = 0, uHeaderLen = 0;
2094 u32 uNodeIndex = 0;
2095 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2096 u16 wAID;
2097 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002098 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002099 PSKeyItem pTransmitKey = NULL;
2100 SKeyItem STempKey;
2101 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002102 int bTKIP_UseGTK = false;
2103 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002104 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002105 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002106 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002107 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002108 u32 status;
2109 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002110 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002111
Forest Bond92b96792009-06-13 07:38:31 -04002112 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2113
2114 if (pDevice->uAssocCount == 0) {
2115 dev_kfree_skb_irq(skb);
2116 return 0;
2117 }
2118
Andres Moreb902fbf2013-02-25 20:32:51 -05002119 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002120 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002121 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002122 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2123
2124 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2125 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2126 // set tx map
2127 pMgmt->abyPSTxMap[0] |= byMask[0];
2128 return 0;
2129 }
Masanari Iida93184692012-08-13 21:21:50 +09002130 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002131
2132 if (pDevice->byBBType != BB_TYPE_11A)
2133 pDevice->wCurrentRate = RATE_2M;
2134 else
2135 pDevice->wCurrentRate = RATE_24M;
2136 // long preamble type
2137 pDevice->byPreambleType = PREAMBLE_SHORT;
2138
2139 }else {
2140
Andres Moreb902fbf2013-02-25 20:32:51 -05002141 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002142
2143 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2144
2145 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2146
2147 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2148 // set tx map
2149 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2150 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2151 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2152 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2153
2154 return 0;
2155 }
2156 // AP rate decided from node
2157 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2158 // tx preamble decided from node
2159
2160 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2161 pDevice->byPreambleType = pDevice->byShortPreamble;
2162
2163 }else {
2164 pDevice->byPreambleType = PREAMBLE_LONG;
2165 }
Andres More4e9b5e22013-02-12 20:36:30 -05002166 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002167 }
2168 }
2169
Andres Moree269fc22013-02-12 20:36:29 -05002170 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002171 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2172 dev_kfree_skb_irq(skb);
2173 return 0;
2174 }
2175 }
2176
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002177 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002178
2179 if (pContext == NULL) {
2180 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2181 dev_kfree_skb_irq(skb);
2182 return STATUS_RESOURCES;
2183 }
2184
Andres Moreceb8c5d2013-03-18 20:33:49 -05002185 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002186
2187//mike add:station mode check eapol-key challenge--->
2188{
Andres Moreb902fbf2013-02-25 20:32:51 -05002189 u8 Protocol_Version; //802.1x Authentication
2190 u8 Packet_Type; //802.1x Authentication
2191 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002192 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002193
Charles Clément21ec51f2010-05-18 10:08:14 -07002194 Protocol_Version = skb->data[ETH_HLEN];
2195 Packet_Type = skb->data[ETH_HLEN+1];
2196 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2197 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 -05002198 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002199 /* 802.1x OR eapol-key challenge frame transfer */
2200 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2201 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002202 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002203 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2204 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2205 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002206 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002207 PRINT_K("WPA ");
2208 }
2209 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002210 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002211 PRINT_K("WPA2(re-keying) ");
2212 }
2213 PRINT_K("Authentication completed!!\n");
2214 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002215 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002216 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002217 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002218 PRINT_K("WPA2 Authentication completed!!\n");
2219 }
2220 }
2221 }
2222}
2223//mike add:station mode check eapol-key challenge<---
2224
Andres More4e9b5e22013-02-12 20:36:30 -05002225 if (pDevice->bEncryptionEnable == true) {
2226 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002227 // get Transmit key
2228 do {
2229 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2230 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2231 pbyBSSID = pDevice->abyBSSID;
2232 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002233 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002234 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002235 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2236 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2238 break;
2239 }
2240 } else {
2241 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2242 break;
2243 }
2244 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002245 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2246 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2248 for (ii = 0; ii< 6; ii++)
2249 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2250 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2251
2252 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002253 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002254 break;
2255 }
2256 // get group key
2257 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002258 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002259 pTransmitKey = NULL;
2260 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2262 }
2263 else
2264 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2265 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002266 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2268 }
Andres Moree269fc22013-02-12 20:36:29 -05002269 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002270 }
2271
2272 if (pDevice->bEnableHostWEP) {
2273 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002274 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002275 pTransmitKey = &STempKey;
2276 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2277 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2278 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2279 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2280 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2281 memcpy(pTransmitKey->abyKey,
2282 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2283 pTransmitKey->uKeyLength
2284 );
2285 }
2286 }
2287
Andres Moreb902fbf2013-02-25 20:32:51 -05002288 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002289
2290 if (pDevice->bFixRate) {
2291 if (pDevice->byBBType == BB_TYPE_11B) {
2292 if (pDevice->uConnectionRate >= RATE_11M) {
2293 pDevice->wCurrentRate = RATE_11M;
2294 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002295 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002296 }
2297 } else {
2298 if ((pDevice->byBBType == BB_TYPE_11A) &&
2299 (pDevice->uConnectionRate <= RATE_6M)) {
2300 pDevice->wCurrentRate = RATE_6M;
2301 } else {
2302 if (pDevice->uConnectionRate >= RATE_54M)
2303 pDevice->wCurrentRate = RATE_54M;
2304 else
Andres More3eaca0d2013-02-25 20:32:52 -05002305 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002306 }
2307 }
2308 }
2309 else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00002310 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Forest Bond92b96792009-06-13 07:38:31 -04002311 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002312 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002313 // Multicast use highest data rate
2314 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2315 // preamble type
2316 pDevice->byPreambleType = pDevice->byShortPreamble;
2317 }
2318 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002319 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002320 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2321 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2322 pDevice->byPreambleType = pDevice->byShortPreamble;
2323
2324 }
2325 else {
2326 pDevice->byPreambleType = PREAMBLE_LONG;
2327 }
2328 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2329 }
2330 else {
2331 if (pDevice->byBBType != BB_TYPE_11A)
2332 pDevice->wCurrentRate = RATE_2M;
2333 else
2334 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2335 // abyCurrExtSuppRates[]
2336 pDevice->byPreambleType = PREAMBLE_SHORT;
2337 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2338 }
2339 }
2340 }
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00002341 if (pDevice->op_mode == NL80211_IFTYPE_STATION) {
Forest Bond92b96792009-06-13 07:38:31 -04002342 // Infra STA rate decided from AP Node, index = 0
2343 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2344 }
2345 }
2346
Andres Moreceb8c5d2013-03-18 20:33:49 -05002347 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002348 if (pDevice->byBBType != BB_TYPE_11A) {
2349 pDevice->wCurrentRate = RATE_1M;
2350 pDevice->byACKRate = RATE_1M;
2351 pDevice->byTopCCKBasicRate = RATE_1M;
2352 pDevice->byTopOFDMBasicRate = RATE_6M;
2353 } else {
2354 pDevice->wCurrentRate = RATE_6M;
2355 pDevice->byACKRate = RATE_6M;
2356 pDevice->byTopCCKBasicRate = RATE_1M;
2357 pDevice->byTopOFDMBasicRate = RATE_6M;
2358 }
2359 }
Forest Bond92b96792009-06-13 07:38:31 -04002360
Andres More0cbd8d92010-05-06 20:34:29 -03002361 DBG_PRT(MSG_LEVEL_DEBUG,
2362 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2363 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002364
2365 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002366 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002367 }
2368
2369 if (pDevice->wCurrentRate <= RATE_11M) {
2370 byPktType = PK_TYPE_11B;
2371 }
2372
Andres More4e9b5e22013-02-12 20:36:30 -05002373 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002374 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2375 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002376 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002377 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002378 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2379 if (pTransmitKey == NULL) {
2380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2381 }
2382 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002383 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2385 }
2386 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002387 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2388 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002389 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002390 }
2391 }
2392 }
2393
Forest Bond92b96792009-06-13 07:38:31 -04002394 if (pDevice->bEnableHostWEP) {
2395 if ((uNodeIndex != 0) &&
2396 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002397 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2398 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002399 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002400 }
2401 }
2402 }
2403 else {
2404
Forest Bond92b96792009-06-13 07:38:31 -04002405 if (pTransmitKey == NULL) {
2406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002407 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002408 dev_kfree_skb_irq(skb);
2409 pStats->tx_dropped++;
2410 return STATUS_FAILURE;
2411 }
Forest Bond92b96792009-06-13 07:38:31 -04002412 }
2413 }
2414
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002415 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2416
Forest Bond92b96792009-06-13 07:38:31 -04002417 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002418 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002419 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002420 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002421 pDevice->wCurrentRate,
2422 &uHeaderLen, &BytesToWrite
2423 );
2424
Andres Moree269fc22013-02-12 20:36:29 -05002425 if (fConvertedPacket == false) {
2426 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002427 dev_kfree_skb_irq(skb);
2428 return STATUS_FAILURE;
2429 }
2430
Andres More4e9b5e22013-02-12 20:36:30 -05002431 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002432 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002433 bScheduleCommand((void *) pDevice,
2434 WLAN_CMD_MAC_DISPOWERSAVING,
2435 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002436 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002437 }
2438 }
2439
Andres Moreb902fbf2013-02-25 20:32:51 -05002440 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Malcolm Priestleyca347592014-03-22 09:01:28 +00002441 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite);
Forest Bond92b96792009-06-13 07:38:31 -04002442
2443 pContext->pPacket = skb;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002444 pContext->type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002445 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002446
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002447 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002448 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002449 (u16)(BytesToWrite-uHeaderLen),
2450 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002451
2452 status = PIPEnsSendBulkOut(pDevice,pContext);
2453
Andres More4e9b5e22013-02-12 20:36:30 -05002454 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002455 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002456
Andres Moreb902fbf2013-02-25 20:32:51 -05002457 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002458 }
2459
2460 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002461 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002462 dev_kfree_skb_irq(skb);
2463 return STATUS_FAILURE;
2464 }
2465 else
2466 return 0;
2467
2468}
2469
Forest Bond92b96792009-06-13 07:38:31 -04002470/*
2471 * Description:
2472 * Relay packet send (AC1DMA) from rx dpc.
2473 *
2474 * Parameters:
2475 * In:
2476 * pDevice - Pointer to the adapter
2477 * pPacket - Pointer to rx packet
2478 * cbPacketSize - rx ethernet frame size
2479 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002480 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002481 *
Andres More4e9b5e22013-02-12 20:36:30 -05002482 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002483 */
2484
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002485int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2486 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002487{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002488 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002489 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002490 u32 BytesToWrite = 0, uHeaderLen = 0;
2491 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002492 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002493 SKeyItem STempKey;
2494 PSKeyItem pTransmitKey = NULL;
2495 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002496 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002497 u8 byPktTyp;
2498 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002499 u32 status;
2500 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002501
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002502 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002503
2504 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002505 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002506 }
2507
Andres Moreceb8c5d2013-03-18 20:33:49 -05002508 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002509
Andres More4e9b5e22013-02-12 20:36:30 -05002510 if (pDevice->bEncryptionEnable == true) {
2511 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002512 // get group key
2513 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002514 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002515 pTransmitKey = NULL;
2516 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2517 } else {
2518 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2519 }
2520 }
2521
2522 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002523 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002524 pTransmitKey = &STempKey;
2525 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2526 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2527 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2528 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2529 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2530 memcpy(pTransmitKey->abyKey,
2531 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2532 pTransmitKey->uKeyLength
2533 );
2534 }
2535 }
2536
2537 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002538 pContext->bBoolInUse = false;
2539 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002540 }
2541
Andres Moreb902fbf2013-02-25 20:32:51 -05002542 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002543
2544 if (pDevice->bFixRate) {
2545 if (pDevice->byBBType == BB_TYPE_11B) {
2546 if (pDevice->uConnectionRate >= RATE_11M) {
2547 pDevice->wCurrentRate = RATE_11M;
2548 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002549 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002550 }
2551 } else {
2552 if ((pDevice->byBBType == BB_TYPE_11A) &&
2553 (pDevice->uConnectionRate <= RATE_6M)) {
2554 pDevice->wCurrentRate = RATE_6M;
2555 } else {
2556 if (pDevice->uConnectionRate >= RATE_54M)
2557 pDevice->wCurrentRate = RATE_54M;
2558 else
Andres More3eaca0d2013-02-25 20:32:52 -05002559 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002560 }
2561 }
2562 }
2563 else {
2564 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2565 }
2566
Forest Bond92b96792009-06-13 07:38:31 -04002567 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002568 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002569 }
2570
2571 if (pDevice->wCurrentRate <= RATE_11M)
2572 byPktType = PK_TYPE_11B;
2573
Andres Moreabad19d2010-07-12 16:28:32 -03002574 BytesToWrite = uDataLen + ETH_FCS_LEN;
2575
Forest Bond92b96792009-06-13 07:38:31 -04002576 // Convert the packet to an usb frame and copy into our buffer
2577 // and send the irp.
2578
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002579 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2580
Forest Bond92b96792009-06-13 07:38:31 -04002581 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002582 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002583 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2584 pbySkbData, pTransmitKey, uNodeIndex,
2585 pDevice->wCurrentRate,
2586 &uHeaderLen, &BytesToWrite
2587 );
2588
Andres Moree269fc22013-02-12 20:36:29 -05002589 if (fConvertedPacket == false) {
2590 pContext->bBoolInUse = false;
2591 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002592 }
2593
Andres Moreb902fbf2013-02-25 20:32:51 -05002594 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Malcolm Priestleyca347592014-03-22 09:01:28 +00002595 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite);
Forest Bond92b96792009-06-13 07:38:31 -04002596
2597 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002598 pContext->type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002599 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002600
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002601 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002602 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002603 (u16)(BytesToWrite - uHeaderLen),
2604 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002605
2606 status = PIPEnsSendBulkOut(pDevice,pContext);
2607
Andres More4e9b5e22013-02-12 20:36:30 -05002608 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002609}
2610