blob: f2f96ee3507380884c04b0f6aaf7d61d5eed8128 [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 Priestleyd56131d2013-01-17 23:15:22 +0000185 u32 *pdwExtIV = (u32 *)((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);
285 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100286 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100287 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100288
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000289 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100290 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
291 }
Forest Bond92b96792009-06-13 07:38:31 -0400292}
293
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000294static void s_vSWencryption(struct vnt_private *pDevice,
295 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400296{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000297 u32 cbICVlen = 4;
298 u32 dwICV = 0xffffffff;
299 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400300
301 if (pTransmitKey == NULL)
302 return;
303
304 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
305 //=======================================================================
306 // Append ICV after payload
307 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500308 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400309 // finally, we must invert dwCRC to get the correct answer
310 *pdwICV = cpu_to_le32(~dwICV);
311 // RC4 encryption
312 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
313 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
314 //=======================================================================
315 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
316 //=======================================================================
317 //Append ICV after payload
318 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500319 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400320 // finally, we must invert dwCRC to get the correct answer
321 *pdwICV = cpu_to_le32(~dwICV);
322 // RC4 encryption
323 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
324 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
325 //=======================================================================
326 }
327}
328
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000329static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100330{
331 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
332 [rate % MAX_RATE]);
333}
334
Forest Bond92b96792009-06-13 07:38:31 -0400335/*byPktType : PK_TYPE_11A 0
336 PK_TYPE_11B 1
337 PK_TYPE_11GB 2
338 PK_TYPE_11GA 3
339*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000340static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
341 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400342{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000343 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400344
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000345 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
346 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400347
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000348 if (pkt_type == PK_TYPE_11B)
349 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
350 (u16)priv->byTopCCKBasicRate);
351 else
352 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
353 (u16)priv->byTopOFDMBasicRate);
354
355 if (need_ack)
356 return data_time + priv->uSIFS + ack_time;
357
358 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400359}
360
Malcolm Priestley2075f652014-03-18 19:25:07 +0000361static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100362 u32 frame_length, u16 rate, int need_ack)
363{
364 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
365 frame_length, rate, need_ack));
366}
367
Forest Bond92b96792009-06-13 07:38:31 -0400368//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000369static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000370 u8 rsv_type, u8 pkt_type, u32 frame_lenght, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400371{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000372 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400373
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000374 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400375
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000376 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
377 frame_lenght, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400378
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000379 if (rsv_type == 0) {
380 rts_time = BBuGetFrameTime(priv->byPreambleType,
381 pkt_type, 20, priv->byTopCCKBasicRate);
382 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
383 pkt_type, 14, priv->byTopCCKBasicRate);
384 } else if (rsv_type == 1) {
385 rts_time = BBuGetFrameTime(priv->byPreambleType,
386 pkt_type, 20, priv->byTopCCKBasicRate);
387 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
388 14, priv->byTopCCKBasicRate);
389 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
390 14, priv->byTopOFDMBasicRate);
391 } else if (rsv_type == 2) {
392 rts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
393 20, priv->byTopOFDMBasicRate);
394 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
395 pkt_type, 14, priv->byTopOFDMBasicRate);
396 } else if (rsv_type == 3) {
397 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
398 14, priv->byTopCCKBasicRate);
399 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
400 14, priv->byTopOFDMBasicRate);
401
402 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
403
Malcolm Priestley20338012014-03-18 19:25:08 +0000404 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000405 }
406
407 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
408
409 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400410}
411
412//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000413static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100414 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400415{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100416 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400417
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100418 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100419 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100420 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
421 byPktType, 14, pDevice->byTopCCKBasicRate);
422 else
423 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
424 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100425 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100426 }
Forest Bond92b96792009-06-13 07:38:31 -0400427
Forest Bond92b96792009-06-13 07:38:31 -0400428 return 0;
429}
430
Forest Bond92b96792009-06-13 07:38:31 -0400431//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000432static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000433 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
434 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400435{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000436 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400437
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100438 switch (byDurType) {
439 case RTSDUR_BB:
440 case RTSDUR_BA:
441 case RTSDUR_BA_F0:
442 case RTSDUR_BA_F1:
443 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
444 14, pDevice->byTopCCKBasicRate);
445 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
446 s_uGetTxRsvTime(pDevice, byPktType,
447 cbFrameLength, wRate, bNeedAck);
448 break;
Forest Bond92b96792009-06-13 07:38:31 -0400449
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100450 case RTSDUR_AA:
451 case RTSDUR_AA_F0:
452 case RTSDUR_AA_F1:
453 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
454 14, pDevice->byTopOFDMBasicRate);
455 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
456 s_uGetTxRsvTime(pDevice, byPktType,
457 cbFrameLength, wRate, bNeedAck);
458 break;
Forest Bond92b96792009-06-13 07:38:31 -0400459
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100460 case CTSDUR_BA:
461 case CTSDUR_BA_F0:
462 case CTSDUR_BA_F1:
463 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100464 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100465 break;
Forest Bond92b96792009-06-13 07:38:31 -0400466
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100467 default:
468 break;
469 }
Forest Bond92b96792009-06-13 07:38:31 -0400470
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100471 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400472}
473
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100474static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
475 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
476{
477 /* Get SignalField,ServiceField,Length */
478 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
479 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
480 PK_TYPE_11B, &buf->b);
481
482 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000483 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
484 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100485
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000486 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
487 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100488 priv->byTopCCKBasicRate);
489
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000490 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100491}
492
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100493static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
494 u16 rate, struct vnt_tx_datahead_g_fb *buf,
495 u32 frame_len, int need_ack)
496{
497 /* Get SignalField,ServiceField,Length */
498 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
499
500 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
501 PK_TYPE_11B, &buf->b);
502
503 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000504 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
505 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100506
Malcolm Priestley4e011172014-03-18 19:24:55 +0000507 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
508 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100509
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000510 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
511 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100512 priv->byTopCCKBasicRate);
513
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000514 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100515}
516
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100517static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
518 u16 rate, struct vnt_tx_datahead_a_fb *buf,
519 u32 frame_len, int need_ack)
520{
521 /* Get SignalField,ServiceField,Length */
522 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
523 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000524 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100525
Malcolm Priestley4e011172014-03-18 19:24:55 +0000526 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
527 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100528
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000529 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100530
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000531 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100532}
533
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100534static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
535 u16 rate, struct vnt_tx_datahead_ab *buf,
536 u32 frame_len, int need_ack)
537{
538 /* Get SignalField,ServiceField,Length */
539 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
540 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000541 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100542
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000543 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100544
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000545 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100546}
547
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100548static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
549 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000550 __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100551{
552 rts->duration = duration;
553 rts->frame_control = TYPE_CTL_RTS;
554
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000555 if (priv->op_mode == NL80211_IFTYPE_ADHOC ||
556 priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100557 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
558 else
559 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
560
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000561 if (priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100562 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
563 else
564 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
565
566 return 0;
567}
568
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100569static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100570 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
571 u8 pkt_type, u32 frame_len, int need_ack,
572 u16 current_rate, u8 fb_option)
573{
574 u16 rts_frame_len = 20;
575
576 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
577 PK_TYPE_11B, &buf->b);
578 BBvCalculateParameter(priv, rts_frame_len,
579 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
580
Malcolm Priestley4e011172014-03-18 19:24:55 +0000581 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100582 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000583 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100584 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000585 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100586 pkt_type, current_rate, need_ack, fb_option);
587
Malcolm Priestley4e011172014-03-18 19:24:55 +0000588 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100589
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100590 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
591 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100592}
593
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100594static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100595 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
596 u8 pkt_type, u32 frame_len, int need_ack,
597 u16 current_rate, u8 fb_option)
598{
599 u16 rts_frame_len = 20;
600
601 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
602 PK_TYPE_11B, &buf->b);
603 BBvCalculateParameter(priv, rts_frame_len,
604 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
605
606
Malcolm Priestley4e011172014-03-18 19:24:55 +0000607 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100608 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000609 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100610 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000611 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100612 pkt_type, current_rate, need_ack, fb_option);
613
614
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000615 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100616 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000617 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_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_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100620 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000621 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100622 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100623
Malcolm Priestley4e011172014-03-18 19:24:55 +0000624 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100625
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100626 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
627 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100628}
629
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100630static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100631 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
632 u8 pkt_type, u32 frame_len, int need_ack,
633 u16 current_rate, u8 fb_option)
634{
635 u16 rts_frame_len = 20;
636
637 BBvCalculateParameter(priv, rts_frame_len,
638 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
639
Malcolm Priestley4e011172014-03-18 19:24:55 +0000640 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100641 pkt_type, current_rate, need_ack, fb_option);
642
Malcolm Priestley4e011172014-03-18 19:24:55 +0000643 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100644
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100645 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
646 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100647}
648
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100649static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100650 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
651 u8 pkt_type, u32 frame_len, int need_ack,
652 u16 current_rate, u8 fb_option)
653{
654 u16 rts_frame_len = 20;
655
656 BBvCalculateParameter(priv, rts_frame_len,
657 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
658
Malcolm Priestley4e011172014-03-18 19:24:55 +0000659 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100660 pkt_type, current_rate, need_ack, fb_option);
661
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000662 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100663 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100664
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000665 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100666 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100667
Malcolm Priestley4e011172014-03-18 19:24:55 +0000668 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100669
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100670 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
671 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100672}
673
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100674static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100675 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500676 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400677{
Forest Bond92b96792009-06-13 07:38:31 -0400678
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100679 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100680 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400681
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100682 /* Note: So far RTSHead doesn't appear in ATIM
683 * & Beacom DMA, so we don't need to take them
684 * into account.
685 * Otherwise, we need to modified codes for them.
686 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100687 switch (byPktType) {
688 case PK_TYPE_11GB:
689 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100690 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100691 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100692 psEthHeader, byPktType, cbFrameLength,
693 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100694 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100695 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100696 psEthHeader, byPktType, cbFrameLength,
697 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100698 break;
699 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100700 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100701 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100702 psEthHeader, byPktType, cbFrameLength,
703 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100704 break;
705 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100706 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100707 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100708 psEthHeader, byPktType, cbFrameLength,
709 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100710 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100711
712 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400713}
714
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100715static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100716 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
717 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400718{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000719 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400720
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100721 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100722 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400723
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100724 if (byFBOption != AUTO_FB_NONE) {
725 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100726 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100727 /* Get SignalField,ServiceField,Length */
728 BBvCalculateParameter(pDevice, uCTSFrameLen,
729 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000730 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100731 cbFrameLength, byPktType,
732 wCurrentRate, bNeedAck, byFBOption);
733 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000734 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100735 CTSDUR_BA_F0, cbFrameLength, byPktType,
736 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100737 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000738 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100739 CTSDUR_BA_F1, cbFrameLength, byPktType,
740 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100741 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000742 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100743 pBuf->data.frame_control = TYPE_CTL_CTS;
744 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100745
746 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
747 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100748 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100749 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100750 /* Get SignalField,ServiceField,Length */
751 BBvCalculateParameter(pDevice, uCTSFrameLen,
752 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100753 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000754 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100755 CTSDUR_BA, cbFrameLength, byPktType,
756 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100757 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000758 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100759 pBuf->data.frame_control = TYPE_CTL_CTS;
760 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100761
762 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
763 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400764 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100765
766 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400767}
768
Forest Bond92b96792009-06-13 07:38:31 -0400769/*+
770 *
771 * Description:
772 * Generate FIFO control for MAC & Baseband controller
773 *
774 * Parameters:
775 * In:
776 * pDevice - Pointer to adpater
777 * pTxDataHead - Transmit Data Buffer
778 * pTxBufHead - pTxBufHead
779 * pvRrvTime - pvRrvTime
780 * pvRTS - RTS Buffer
781 * pCTS - CTS Buffer
782 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
783 * bNeedACK - If need ACK
784 * uDMAIdx - DMA Index
785 * Out:
786 * none
787 *
788 * Return Value: none
789 *
790-*/
Andres Morecc856e62010-05-17 21:34:01 -0300791
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100792static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100793 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100794 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
795 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400796{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100797 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100798 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000799 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000800 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400801
Malcolm Priestley92928f12013-10-07 20:14:01 +0100802 pFifoHead->wReserved = wCurrentRate;
803 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400804
Malcolm Priestley92928f12013-10-07 20:14:01 +0100805 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
806 byFBOption = AUTO_FB_0;
807 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
808 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400809
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100810 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100811 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100812
Malcolm Priestley92928f12013-10-07 20:14:01 +0100813 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
814 if (need_rts) {
815 struct vnt_rrv_time_rts *pBuf =
816 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100817
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000818 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100819 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000820 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100821 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000822 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100823 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100824
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000825 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100826 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000827 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100828 PK_TYPE_11B, cbFrameSize,
829 pDevice->byTopCCKBasicRate, bNeedACK);
830
831 if (need_mic) {
832 *mic_hdr = &tx_buffer->
833 tx_head.tx_rts.tx.mic.hdr;
834 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
835 } else {
836 head = &tx_buffer->tx_head.tx_rts.tx.head;
837 }
838
839 /* Fill RTS */
840 return s_vFillRTSHead(pDevice, byPktType, head,
841 cbFrameSize, bNeedACK, psEthHeader,
842 wCurrentRate, byFBOption);
843
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100844 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100845 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
846 tx_head.tx_cts.cts;
847
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000848 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100849 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000850 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100851 PK_TYPE_11B, cbFrameSize,
852 pDevice->byTopCCKBasicRate, bNeedACK);
853
Malcolm Priestley372108e2014-03-18 19:25:00 +0000854 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100855 byPktType, cbFrameSize, wCurrentRate);
856
857 if (need_mic) {
858 *mic_hdr = &tx_buffer->
859 tx_head.tx_cts.tx.mic.hdr;
860 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
861 } else {
862 head = &tx_buffer->tx_head.tx_cts.tx.head;
863 }
864
865 /* Fill CTS */
866 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
867 head, cbFrameSize, bNeedACK, wCurrentRate,
868 byFBOption);
869 }
870 } else if (byPktType == PK_TYPE_11A) {
871 if (need_mic) {
872 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
873 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
874 } else {
875 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100876 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100877
Malcolm Priestley92928f12013-10-07 20:14:01 +0100878 if (need_rts) {
879 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
880 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100881
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000882 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100883 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100884
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000885 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100886 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
887
888 /* Fill RTS */
889 return s_vFillRTSHead(pDevice, byPktType, head,
890 cbFrameSize, bNeedACK, psEthHeader,
891 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100892 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100893 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
894 tx_head.tx_ab.ab;
895
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000896 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100897 PK_TYPE_11A, cbFrameSize,
898 wCurrentRate, bNeedACK);
899
900 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
901 wCurrentRate, &head->data_head_a_fb,
902 cbFrameSize, bNeedACK);
903 }
904 } else if (byPktType == PK_TYPE_11B) {
905 if (need_mic) {
906 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
907 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
908 } else {
909 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100910 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100911
Malcolm Priestley92928f12013-10-07 20:14:01 +0100912 if (need_rts) {
913 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
914 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100915
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000916 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100917 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100918
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000919 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100920 PK_TYPE_11B, cbFrameSize, wCurrentRate,
921 bNeedACK);
922
923 /* Fill RTS */
924 return s_vFillRTSHead(pDevice, byPktType, head,
925 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100926 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100927 } else {
928 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
929 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100930
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000931 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100932 PK_TYPE_11B, cbFrameSize,
933 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100934
Malcolm Priestley92928f12013-10-07 20:14:01 +0100935 return vnt_rxtx_datahead_ab(pDevice, byPktType,
936 wCurrentRate, &head->data_head_ab,
937 cbFrameSize, bNeedACK);
938 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100939 }
940
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100941 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400942}
943/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500944 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500945 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300946 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400947*/
948
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000949static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100950 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100951 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
952 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
953 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400954{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100955 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000956 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
957 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000958 u32 cb802_1_H_len;
959 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
960 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100961 int bNeedACK;
962 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000963 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
964 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
965 u8 abySNAP_Bridgetunnel[ETH_ALEN]
966 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
967 u32 uDuration;
968 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100969 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000970 u8 byFBOption = AUTO_FB_NONE, byFragType;
971 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100972 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000973 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500974 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100975
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100976 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400977
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000978 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500979 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
980 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000981 }
Forest Bond92b96792009-06-13 07:38:31 -0400982
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000983 /* Get pkt type */
984 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
985 cb802_1_H_len = 8;
986 else
987 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400988
Charles Clément21ec51f2010-05-18 10:08:14 -0700989 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400990
991 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500992 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400993
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000994 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC ||
995 pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500996 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500997 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -0300998 pTxBufHead->wFIFOCtl =
999 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1000 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001001 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001002 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1003 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001004 } else {
1005 /* MSDUs in Infra mode always need ACK */
1006 bNeedACK = true;
1007 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1008 }
Forest Bond92b96792009-06-13 07:38:31 -04001009
1010 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1011
Forest Bond92b96792009-06-13 07:38:31 -04001012 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001013 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1014
Andres More3eaca0d2013-02-25 20:32:52 -05001015 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001016
1017 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001018 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001019 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1020 }
1021
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001022 /* Set Auto Fallback Ctl */
1023 if (wCurrentRate >= RATE_18M) {
1024 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1025 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1026
1027 pDevice->tx_rate_fb0 =
1028 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1029 pDevice->tx_rate_fb1 =
1030 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1031
1032 byFBOption = AUTO_FB_0;
1033 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1034 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1035 pDevice->tx_rate_fb0 =
1036 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1037 pDevice->tx_rate_fb1 =
1038 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1039
1040 byFBOption = AUTO_FB_1;
1041 }
1042 }
Forest Bond92b96792009-06-13 07:38:31 -04001043
Andres More4e9b5e22013-02-12 20:36:30 -05001044 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001045 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1046 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1047 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1048 }
1049 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1050 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1051 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1052 }
1053 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1054 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1055 }
1056 }
1057 }
1058
Forest Bond92b96792009-06-13 07:38:31 -04001059 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1060 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1061 cbIVlen = 4;
1062 cbICVlen = 4;
1063 }
1064 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1065 cbIVlen = 8;//IV+ExtIV
1066 cbMIClen = 8;
1067 cbICVlen = 4;
1068 }
1069 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1070 cbIVlen = 8;//RSN Header
1071 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001072 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001073 }
Andres Moree269fc22013-02-12 20:36:29 -05001074 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001075 //MAC Header should be padding 0 to DW alignment.
1076 uPadding = 4 - (cbMACHdLen%4);
1077 uPadding %= 4;
1078 }
1079 }
1080
1081 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1082
Andres Moree269fc22013-02-12 20:36:29 -05001083 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1084 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001085 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001086 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001087 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1088 }
1089
Andres Moreb902fbf2013-02-25 20:32:51 -05001090 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001091 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1092
Forest Bond92b96792009-06-13 07:38:31 -04001093 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1094 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001095 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001096 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001097 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001098 }
1099 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001100 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001101 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001102 }
1103 } else {
1104 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001105 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001106 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001107 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001108 }
Andres Moree269fc22013-02-12 20:36:29 -05001109 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001110 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001111 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001112 }
1113 } // Auto Fall Back
1114 }
1115 else {//802.11a/b packet
1116 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001117 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001118 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001119 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001120 }
Andres Moree269fc22013-02-12 20:36:29 -05001121 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001122 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001123 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001124 }
1125 } else {
1126 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001127 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001128 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001129 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001130 }
Andres Moree269fc22013-02-12 20:36:29 -05001131 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001132 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001133 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001134 }
1135 } // Auto Fall Back
1136 }
1137
Andres Moreb902fbf2013-02-25 20:32:51 -05001138 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1139 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1140 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001141
Forest Bond92b96792009-06-13 07:38:31 -04001142 //=========================
1143 // No Fragmentation
1144 //=========================
1145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1146 byFragType = FRAGCTL_NONFRAG;
1147 //uDMAIdx = TYPE_AC0DMA;
1148 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1149
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001150 /* Fill FIFO, RrvTime, RTS and CTS */
1151 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1152 tx_buffer, &pMICHDR, cbMICHDR,
1153 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001154
Forest Bond92b96792009-06-13 07:38:31 -04001155 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001156 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001157 byFragType, uDMAIdx, 0);
1158
Andres More4e9b5e22013-02-12 20:36:30 -05001159 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001160 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001161 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001162 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001163
1164 if (pDevice->bEnableHostWEP) {
1165 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1166 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1167 }
1168 }
1169
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001170 /* 802.1H */
1171 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001172 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001173 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001174 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001175 abySNAP_Bridgetunnel, 6);
1176 else
1177 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001178
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001179 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001180
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001181 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1182 }
Forest Bond92b96792009-06-13 07:38:31 -04001183
Forest Bond92b96792009-06-13 07:38:31 -04001184 if (pPacket != NULL) {
1185 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001186 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001187 (pPacket + ETH_HLEN),
1188 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001189 );
1190
1191 } else {
1192 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001193 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001194 }
1195
Andres More4e9b5e22013-02-12 20:36:30 -05001196 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001197
1198 ///////////////////////////////////////////////////////////////////
1199
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001200 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1201 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1202 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1203 }
Forest Bond92b96792009-06-13 07:38:31 -04001204 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001205 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1206 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001207 }
1208 else {
Andres More52a7e642013-02-25 20:32:53 -05001209 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1210 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001211 }
1212 // DO Software Michael
1213 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001214 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001215 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001216 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001217 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1218 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001219
1220 ///////////////////////////////////////////////////////////////////
1221
1222 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1223 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001224 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001225 //}
1226 //DBG_PRN_GRP12(("\n\n\n"));
1227
1228 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1229
Andres More52a7e642013-02-25 20:32:53 -05001230 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1231 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001232
1233 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1234 MIC_vUnInit();
1235
Andres More4e9b5e22013-02-12 20:36:30 -05001236 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001237 *pdwMIC_L = 0;
1238 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001239 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001240 }
1241 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1242 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1243 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1244 }
1245
Andres More4e9b5e22013-02-12 20:36:30 -05001246 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001247
Andres More3eaca0d2013-02-25 20:32:52 -05001248 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001249
Andres More4e9b5e22013-02-12 20:36:30 -05001250 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1251 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1252 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001253 cbFrameSize -= cbICVlen;
1254 }
1255
Forest Bond92b96792009-06-13 07:38:31 -04001256 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001257
1258 *pcbHeaderLen = cbHeaderLength;
1259 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1260
Forest Bond92b96792009-06-13 07:38:31 -04001261 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001262 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001263
Andres More4e9b5e22013-02-12 20:36:30 -05001264 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001265
1266}
1267
Forest Bond92b96792009-06-13 07:38:31 -04001268/*+
1269 *
1270 * Description:
1271 * Translate 802.3 to 802.11 header
1272 *
1273 * Parameters:
1274 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001275 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001276 * dwTxBufferAddr - Transmit Buffer
1277 * pPacket - Packet from upper layer
1278 * cbPacketSize - Transmit Data Length
1279 * Out:
1280 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1281 * pcbAppendPayload - size of append payload for 802.1H translation
1282 *
1283 * Return Value: none
1284 *
1285-*/
1286
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001287static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001288 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001289 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001290{
Andres More1cac4a42013-03-18 20:33:50 -05001291 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001292
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001293 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001294
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001295 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001296 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001297 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001298 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001299 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1300 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001301 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001302 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001303 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001304 } else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001305 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001306 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001307 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001308 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001309 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001310 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001311 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001312 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001313 &(pDevice->abyBSSID[0]),
1314 ETH_ALEN);
1315 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001316 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001317 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001318 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001319 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001320 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001321 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001322 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001323 &(pDevice->abyBSSID[0]),
1324 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001325 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001326 }
1327 }
1328
1329 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001330 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001331
Andres More1cac4a42013-03-18 20:33:50 -05001332 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001333
Andres More1cac4a42013-03-18 20:33:50 -05001334 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001335
1336 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001337 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001338
1339 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1340 pDevice->wSeqCounter++;
1341 if (pDevice->wSeqCounter > 0x0fff)
1342 pDevice->wSeqCounter = 0;
1343 }
1344
1345 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001346 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001347 }
1348}
1349
Forest Bond92b96792009-06-13 07:38:31 -04001350/*+
1351 *
1352 * Description:
1353 * Request instructs a MAC to transmit a 802.11 management packet through
1354 * the adapter onto the medium.
1355 *
1356 * Parameters:
1357 * In:
1358 * hDeviceContext - Pointer to the adapter
1359 * pPacket - A pointer to a descriptor for the packet to transmit
1360 * Out:
1361 * none
1362 *
Andres Moree269fc22013-02-12 20:36:29 -05001363 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001364 *
1365-*/
1366
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001367CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1368 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001369{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001370 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001371 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001372 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001373 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001374 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001375 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001376 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001377 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001378 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001379 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001380 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1381 u32 uPadding = 0;
1382 u16 wTxBufSize;
1383 u32 cbMacHdLen;
1384 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001385
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001386 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001387
1388 if (NULL == pContext) {
1389 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1390 return CMD_STATUS_RESOURCES;
1391 }
1392
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001393 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001394 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001395 pTxBufHead = &pTX_Buffer->fifo_head;
1396 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1397 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001398
1399 if (pDevice->byBBType == BB_TYPE_11A) {
1400 wCurrentRate = RATE_6M;
1401 byPktType = PK_TYPE_11A;
1402 } else {
1403 wCurrentRate = RATE_1M;
1404 byPktType = PK_TYPE_11B;
1405 }
1406
1407 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1408 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1409 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1410 // to set power here.
1411 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1412 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1413 } else {
1414 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1415 }
1416 pDevice->wCurrentRate = wCurrentRate;
1417
Forest Bond92b96792009-06-13 07:38:31 -04001418 //Set packet type
1419 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1420 pTxBufHead->wFIFOCtl = 0;
1421 }
1422 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1423 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1424 }
1425 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1426 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1427 }
1428 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1429 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1430 }
1431
1432 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1433 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1434
Andres More22040bb2010-08-02 20:21:44 -03001435 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001436 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001437 }
1438 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001439 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001440 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1441 };
1442
1443 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1444 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1445
1446 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1447 //Set Preamble type always long
1448 //pDevice->byPreambleType = PREAMBLE_LONG;
1449 // probe-response don't retry
1450 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001451 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001452 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1453 //}
1454 }
1455
1456 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1457
1458 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001459 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001460 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1461 } else {
1462 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1463 }
1464
1465 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001466 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001467
1468 // Notes:
1469 // Although spec says MMPDU can be fragmented; In most case,
1470 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001471
1472 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1473 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1474 cbIVlen = 4;
1475 cbICVlen = 4;
1476 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1477 }
1478 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1479 cbIVlen = 8;//IV+ExtIV
1480 cbMIClen = 8;
1481 cbICVlen = 4;
1482 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1483 //We need to get seed here for filling TxKey entry.
1484 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1485 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1486 }
1487 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1488 cbIVlen = 8;//RSN Header
1489 cbICVlen = 8;//MIC
1490 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001491 }
1492 //MAC Header should be padding 0 to DW alignment.
1493 uPadding = 4 - (cbMacHdLen%4);
1494 uPadding %= 4;
1495 }
1496
1497 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1498
1499 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001500 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001501 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1502 }
1503 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1504
1505 //Set RrvTime/RTS/CTS Buffer
1506 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001507 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001508 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001509 }
1510 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001511 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001512 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001513 }
1514
Andres Moreceb8c5d2013-03-18 20:33:49 -05001515 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001516 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1517 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001518 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001519 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1520 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001521 //=========================
1522 // No Fragmentation
1523 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001524 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001525
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001526 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001527 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001528 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001529 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001530
Andres More1cac4a42013-03-18 20:33:50 -05001531 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001532
1533 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1534
1535 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001536 u8 * pbyIVHead;
1537 u8 * pbyPayloadHead;
1538 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001539 PSKeyItem pTransmitKey = NULL;
1540
Andres Moreb902fbf2013-02-25 20:32:51 -05001541 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1542 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001543 do {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001544 if (pDevice->op_mode == NL80211_IFTYPE_STATION &&
1545 pDevice->bLinkPass == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001546 pbyBSSID = pDevice->abyBSSID;
1547 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001548 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001549 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001550 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001551 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1552 break;
1553 }
1554 } else {
1555 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1556 break;
1557 }
1558 }
1559 // get group key
1560 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001561 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001562 pTransmitKey = NULL;
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001563 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode);
Forest Bond92b96792009-06-13 07:38:31 -04001564 } else {
1565 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1566 }
Andres Moree269fc22013-02-12 20:36:29 -05001567 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001568 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001569 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001570 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001571
Jim Lieb3e362592009-08-12 14:54:11 -07001572 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001573 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001574 cbFrameBodySize);
1575 }
1576 else {
1577 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001578 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001579 }
1580
Andres More1cac4a42013-03-18 20:33:50 -05001581 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001582 pDevice->wSeqCounter++ ;
1583 if (pDevice->wSeqCounter > 0x0fff)
1584 pDevice->wSeqCounter = 0;
1585
1586 if (bIsPSPOLL) {
1587 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001588 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001589 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1590 // in the same place of other packet's Duration-field).
1591 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001592 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001593 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1594 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001595 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001596 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00001597 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001598 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1599 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001600 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1601 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001602 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001603 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1604 }
Forest Bond92b96792009-06-13 07:38:31 -04001605 }
1606
Andres More3eaca0d2013-02-25 20:32:52 -05001607 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001608 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001609 pTX_Buffer->byType = 0x00;
1610
1611 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00001612 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001613 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001614
Andres More1cac4a42013-03-18 20:33:50 -05001615 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001616 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1617 &pMACHeader->addr1[0], (u16)cbFrameSize,
1618 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001619 }
1620 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001621 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1622 &pMACHeader->addr3[0], (u16)cbFrameSize,
1623 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001624 }
1625
1626 PIPEnsSendBulkOut(pDevice,pContext);
1627 return CMD_STATUS_PENDING;
1628}
1629
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001630CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1631 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001632{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001633 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001634 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001635 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1636 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001637 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001638 u16 wCurrentRate;
1639 u32 cbFrameBodySize;
1640 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001641 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001642 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001643
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001644 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001645 if (NULL == pContext) {
1646 status = CMD_STATUS_RESOURCES;
1647 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1648 return status ;
1649 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001650
1651 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001652 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001653
1654 cbFrameBodySize = pPacket->cbPayloadLen;
1655
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001656 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001657
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001658 if (pDevice->byBBType == BB_TYPE_11A) {
1659 wCurrentRate = RATE_6M;
1660
1661 /* Get SignalField,ServiceField,Length */
1662 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1663 PK_TYPE_11A, &short_head->ab);
1664
1665 /* Get Duration and TimeStampOff */
1666 short_head->duration = s_uGetDataDuration(pDevice,
1667 PK_TYPE_11A, false);
1668 short_head->time_stamp_off =
1669 vnt_time_stamp_off(pDevice, wCurrentRate);
1670 } else {
1671 wCurrentRate = RATE_1M;
1672 short_head->fifo_ctl |= FIFOCTL_11B;
1673
1674 /* Get SignalField,ServiceField,Length */
1675 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1676 PK_TYPE_11B, &short_head->ab);
1677
1678 /* Get Duration and TimeStampOff */
1679 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001680 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001681 short_head->time_stamp_off =
1682 vnt_time_stamp_off(pDevice, wCurrentRate);
1683 }
1684
Forest Bond92b96792009-06-13 07:38:31 -04001685
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001686 /* Generate Beacon Header */
1687 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001688
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001689 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1690
1691 pMACHeader->duration_id = 0;
1692 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1693 pDevice->wSeqCounter++;
1694 if (pDevice->wSeqCounter > 0x0fff)
1695 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001696
1697 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1698
Andres More3eaca0d2013-02-25 20:32:52 -05001699 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001700 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001701 pTX_Buffer->byType = 0x01;
1702
1703 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00001704 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001705 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001706
1707 PIPEnsSendBulkOut(pDevice,pContext);
1708 return CMD_STATUS_PENDING;
1709
1710}
1711
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001712void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1713{
1714 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001715 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001716 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001717 u8 byPktType;
1718 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001719 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001720 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001721 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001722 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001723 u32 cbFrameSize;
1724 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1725 u32 uPadding = 0;
1726 u32 cbMICHDR = 0, uLength = 0;
1727 u32 dwMICKey0, dwMICKey1;
1728 u32 dwMIC_Priority;
1729 u32 *pdwMIC_L, *pdwMIC_R;
1730 u16 wTxBufSize;
1731 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001732 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001733 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001734 u32 wCurrentRate = RATE_1M;
1735 PUWLAN_80211HDR p80211Header;
1736 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001737 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001738 SKeyItem STempKey;
1739 PSKeyItem pTransmitKey = NULL;
1740 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1741 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001742 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001743
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001744 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001745
1746 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1747 cbFrameBodySize = 0;
1748 }
1749 else {
1750 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1751 }
1752 p80211Header = (PUWLAN_80211HDR)skb->data;
1753
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001754 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001755
1756 if (NULL == pContext) {
1757 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1758 dev_kfree_skb_irq(skb);
1759 return ;
1760 }
1761
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001762 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001763 pTxBufHead = &pTX_Buffer->fifo_head;
1764 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1765 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001766
1767 if (pDevice->byBBType == BB_TYPE_11A) {
1768 wCurrentRate = RATE_6M;
1769 byPktType = PK_TYPE_11A;
1770 } else {
1771 wCurrentRate = RATE_1M;
1772 byPktType = PK_TYPE_11B;
1773 }
1774
1775 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1776 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1777 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1778 // to set power here.
1779 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1780 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1781 } else {
1782 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1783 }
1784
1785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1786
1787 //Set packet type
1788 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1789 pTxBufHead->wFIFOCtl = 0;
1790 }
1791 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1792 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1793 }
1794 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1795 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1796 }
1797 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1798 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1799 }
1800
1801 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1802 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1803
Andres More22040bb2010-08-02 20:21:44 -03001804 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001805 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001806 if (pDevice->bEnableHostWEP) {
1807 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001808 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001809 }
Forest Bond92b96792009-06-13 07:38:31 -04001810 }
1811 else {
1812 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001813 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001814 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001815 }
Andres More4e9b5e22013-02-12 20:36:30 -05001816 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001817 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1818 };
1819
1820 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1821 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1822
1823 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1824 //Set Preamble type always long
1825 //pDevice->byPreambleType = PREAMBLE_LONG;
1826
1827 // probe-response don't retry
1828 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001829 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001830 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1831 //}
1832 }
1833
1834 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1835
1836 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001837 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001838 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1839 } else {
1840 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1841 }
1842
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001843 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001844 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1845
1846 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1847 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1848 }
1849
1850 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1851 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1852 }
1853
1854 if (cbExtSuppRate >0) {
1855 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1856 }
1857 }
1858
Forest Bond92b96792009-06-13 07:38:31 -04001859 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001860 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001861
1862 // Notes:
1863 // Although spec says MMPDU can be fragmented; In most case,
1864 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001865
Forest Bond92b96792009-06-13 07:38:31 -04001866 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1867 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1868 cbIVlen = 4;
1869 cbICVlen = 4;
1870 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1871 }
1872 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1873 cbIVlen = 8;//IV+ExtIV
1874 cbMIClen = 8;
1875 cbICVlen = 4;
1876 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1877 //We need to get seed here for filling TxKey entry.
1878 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1879 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1880 }
1881 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1882 cbIVlen = 8;//RSN Header
1883 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001884 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001885 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001886 }
1887 //MAC Header should be padding 0 to DW alignment.
1888 uPadding = 4 - (cbMacHdLen%4);
1889 uPadding %= 4;
1890 }
1891
1892 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1893
1894 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001895 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001896 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1897 }
1898 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1899
Forest Bond92b96792009-06-13 07:38:31 -04001900 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001901 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001902 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001903
1904 }
1905 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001906 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001907 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001908 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001909 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001910 &(p80211Header->sA3.abyAddr1[0]),
1911 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001912 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001913 &(p80211Header->sA3.abyAddr2[0]),
1914 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001915 //=========================
1916 // No Fragmentation
1917 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001918 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001919
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001920 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001921 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001922 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001923 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001924
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001925 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001926
1927 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1928
Andres Moreb902fbf2013-02-25 20:32:51 -05001929 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1930 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1931 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001932
1933 // Copy the Packet into a tx Buffer
1934 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1935
1936 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001937 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001938 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1939
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001940 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001941 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1942 if (cbExtSuppRate != 0) {
1943 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1944 memcpy((pbyPayloadHead + cbFrameBodySize),
1945 pMgmt->abyCurrSuppRates,
1946 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1947 );
1948 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1949 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1950 pMgmt->abyCurrExtSuppRates,
1951 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1952 );
1953 }
1954 }
1955
1956 // Set wep
1957 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1958
1959 if (pDevice->bEnableHostWEP) {
1960 pTransmitKey = &STempKey;
1961 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1962 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1963 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1964 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1965 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1966 memcpy(pTransmitKey->abyKey,
1967 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1968 pTransmitKey->uKeyLength
1969 );
1970 }
1971
1972 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1973
Andres More52a7e642013-02-25 20:32:53 -05001974 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1975 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001976
1977 // DO Software Michael
1978 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001979 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001980 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001981 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1983 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001984
1985 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1986
1987 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1988
Andres More52a7e642013-02-25 20:32:53 -05001989 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1990 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001991
1992 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1993 MIC_vUnInit();
1994
Andres More4e9b5e22013-02-12 20:36:30 -05001995 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001996 *pdwMIC_L = 0;
1997 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001998 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001999 }
2000
2001 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2002 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002003 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2004 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002005
2006 }
2007
Malcolm Priestley3ba09382013-10-15 21:41:38 +01002008 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002009 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002010
2011 if (pDevice->bEnableHostWEP) {
2012 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2013 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2014 }
2015
2016 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002017 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002018 }
2019 }
2020
Andres More1cac4a42013-03-18 20:33:50 -05002021 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002022 pDevice->wSeqCounter++ ;
2023 if (pDevice->wSeqCounter > 0x0fff)
2024 pDevice->wSeqCounter = 0;
2025
Forest Bond92b96792009-06-13 07:38:31 -04002026 if (bIsPSPOLL) {
2027 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2028 // of FIFO control header.
2029 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2030 // in the same place of other packet's Duration-field).
2031 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002032 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002033 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2034 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00002035 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002036 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00002037 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002038 cpu_to_le16(p80211Header->sA2.wDurationID);
2039 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002040 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2041 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00002042 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002043 cpu_to_le16(p80211Header->sA2.wDurationID);
2044 }
Forest Bond92b96792009-06-13 07:38:31 -04002045 }
2046
Andres More3eaca0d2013-02-25 20:32:52 -05002047 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002048 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002049 pTX_Buffer->byType = 0x00;
2050
2051 pContext->pPacket = skb;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002052 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002053 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002054
Andres More1cac4a42013-03-18 20:33:50 -05002055 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002056 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2057 &pMACHeader->addr1[0], (u16)cbFrameSize,
2058 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002059 }
2060 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002061 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2062 &pMACHeader->addr3[0], (u16)cbFrameSize,
2063 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002064 }
2065 PIPEnsSendBulkOut(pDevice,pContext);
2066 return ;
2067
2068}
2069
Forest Bond92b96792009-06-13 07:38:31 -04002070//TYPE_AC0DMA data tx
2071/*
2072 * Description:
2073 * Tx packet via AC0DMA(DMA1)
2074 *
2075 * Parameters:
2076 * In:
2077 * pDevice - Pointer to the adapter
2078 * skb - Pointer to tx skb packet
2079 * Out:
2080 * void
2081 *
2082 * Return Value: NULL
2083 */
2084
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002085int nsDMA_tx_packet(struct vnt_private *pDevice,
2086 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002087{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002088 struct net_device_stats *pStats = &pDevice->stats;
2089 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002090 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002091 u32 BytesToWrite = 0, uHeaderLen = 0;
2092 u32 uNodeIndex = 0;
2093 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2094 u16 wAID;
2095 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002096 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002097 PSKeyItem pTransmitKey = NULL;
2098 SKeyItem STempKey;
2099 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002100 int bTKIP_UseGTK = false;
2101 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002102 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002103 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002104 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002105 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002106 u32 status;
2107 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002108 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002109
Forest Bond92b96792009-06-13 07:38:31 -04002110 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2111
2112 if (pDevice->uAssocCount == 0) {
2113 dev_kfree_skb_irq(skb);
2114 return 0;
2115 }
2116
Andres Moreb902fbf2013-02-25 20:32:51 -05002117 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002118 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002119 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002120 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2121
2122 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2123 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2124 // set tx map
2125 pMgmt->abyPSTxMap[0] |= byMask[0];
2126 return 0;
2127 }
Masanari Iida93184692012-08-13 21:21:50 +09002128 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002129
2130 if (pDevice->byBBType != BB_TYPE_11A)
2131 pDevice->wCurrentRate = RATE_2M;
2132 else
2133 pDevice->wCurrentRate = RATE_24M;
2134 // long preamble type
2135 pDevice->byPreambleType = PREAMBLE_SHORT;
2136
2137 }else {
2138
Andres Moreb902fbf2013-02-25 20:32:51 -05002139 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002140
2141 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2142
2143 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2144
2145 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2146 // set tx map
2147 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2148 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2150 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2151
2152 return 0;
2153 }
2154 // AP rate decided from node
2155 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2156 // tx preamble decided from node
2157
2158 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2159 pDevice->byPreambleType = pDevice->byShortPreamble;
2160
2161 }else {
2162 pDevice->byPreambleType = PREAMBLE_LONG;
2163 }
Andres More4e9b5e22013-02-12 20:36:30 -05002164 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002165 }
2166 }
2167
Andres Moree269fc22013-02-12 20:36:29 -05002168 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2170 dev_kfree_skb_irq(skb);
2171 return 0;
2172 }
2173 }
2174
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002175 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002176
2177 if (pContext == NULL) {
2178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2179 dev_kfree_skb_irq(skb);
2180 return STATUS_RESOURCES;
2181 }
2182
Andres Moreceb8c5d2013-03-18 20:33:49 -05002183 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002184
2185//mike add:station mode check eapol-key challenge--->
2186{
Andres Moreb902fbf2013-02-25 20:32:51 -05002187 u8 Protocol_Version; //802.1x Authentication
2188 u8 Packet_Type; //802.1x Authentication
2189 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002190 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002191
Charles Clément21ec51f2010-05-18 10:08:14 -07002192 Protocol_Version = skb->data[ETH_HLEN];
2193 Packet_Type = skb->data[ETH_HLEN+1];
2194 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2195 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 -05002196 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002197 /* 802.1x OR eapol-key challenge frame transfer */
2198 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2199 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002200 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002201 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2202 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2203 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002204 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002205 PRINT_K("WPA ");
2206 }
2207 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002208 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002209 PRINT_K("WPA2(re-keying) ");
2210 }
2211 PRINT_K("Authentication completed!!\n");
2212 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002213 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002214 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002215 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002216 PRINT_K("WPA2 Authentication completed!!\n");
2217 }
2218 }
2219 }
2220}
2221//mike add:station mode check eapol-key challenge<---
2222
Andres More4e9b5e22013-02-12 20:36:30 -05002223 if (pDevice->bEncryptionEnable == true) {
2224 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002225 // get Transmit key
2226 do {
2227 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2228 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2229 pbyBSSID = pDevice->abyBSSID;
2230 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002231 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002232 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002233 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2234 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002235 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2236 break;
2237 }
2238 } else {
2239 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2240 break;
2241 }
2242 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002243 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2244 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002245 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2246 for (ii = 0; ii< 6; ii++)
2247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2248 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2249
2250 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002251 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002252 break;
2253 }
2254 // get group key
2255 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002256 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002257 pTransmitKey = NULL;
2258 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2259 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2260 }
2261 else
2262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2263 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002264 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2266 }
Andres Moree269fc22013-02-12 20:36:29 -05002267 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002268 }
2269
2270 if (pDevice->bEnableHostWEP) {
2271 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002272 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002273 pTransmitKey = &STempKey;
2274 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2275 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2276 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2277 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2278 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2279 memcpy(pTransmitKey->abyKey,
2280 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2281 pTransmitKey->uKeyLength
2282 );
2283 }
2284 }
2285
Andres Moreb902fbf2013-02-25 20:32:51 -05002286 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002287
2288 if (pDevice->bFixRate) {
2289 if (pDevice->byBBType == BB_TYPE_11B) {
2290 if (pDevice->uConnectionRate >= RATE_11M) {
2291 pDevice->wCurrentRate = RATE_11M;
2292 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002293 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002294 }
2295 } else {
2296 if ((pDevice->byBBType == BB_TYPE_11A) &&
2297 (pDevice->uConnectionRate <= RATE_6M)) {
2298 pDevice->wCurrentRate = RATE_6M;
2299 } else {
2300 if (pDevice->uConnectionRate >= RATE_54M)
2301 pDevice->wCurrentRate = RATE_54M;
2302 else
Andres More3eaca0d2013-02-25 20:32:52 -05002303 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002304 }
2305 }
2306 }
2307 else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00002308 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Forest Bond92b96792009-06-13 07:38:31 -04002309 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002310 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002311 // Multicast use highest data rate
2312 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2313 // preamble type
2314 pDevice->byPreambleType = pDevice->byShortPreamble;
2315 }
2316 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002317 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002318 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2319 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2320 pDevice->byPreambleType = pDevice->byShortPreamble;
2321
2322 }
2323 else {
2324 pDevice->byPreambleType = PREAMBLE_LONG;
2325 }
2326 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2327 }
2328 else {
2329 if (pDevice->byBBType != BB_TYPE_11A)
2330 pDevice->wCurrentRate = RATE_2M;
2331 else
2332 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2333 // abyCurrExtSuppRates[]
2334 pDevice->byPreambleType = PREAMBLE_SHORT;
2335 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2336 }
2337 }
2338 }
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00002339 if (pDevice->op_mode == NL80211_IFTYPE_STATION) {
Forest Bond92b96792009-06-13 07:38:31 -04002340 // Infra STA rate decided from AP Node, index = 0
2341 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2342 }
2343 }
2344
Andres Moreceb8c5d2013-03-18 20:33:49 -05002345 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002346 if (pDevice->byBBType != BB_TYPE_11A) {
2347 pDevice->wCurrentRate = RATE_1M;
2348 pDevice->byACKRate = RATE_1M;
2349 pDevice->byTopCCKBasicRate = RATE_1M;
2350 pDevice->byTopOFDMBasicRate = RATE_6M;
2351 } else {
2352 pDevice->wCurrentRate = RATE_6M;
2353 pDevice->byACKRate = RATE_6M;
2354 pDevice->byTopCCKBasicRate = RATE_1M;
2355 pDevice->byTopOFDMBasicRate = RATE_6M;
2356 }
2357 }
Forest Bond92b96792009-06-13 07:38:31 -04002358
Andres More0cbd8d92010-05-06 20:34:29 -03002359 DBG_PRT(MSG_LEVEL_DEBUG,
2360 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2361 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002362
2363 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002364 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002365 }
2366
2367 if (pDevice->wCurrentRate <= RATE_11M) {
2368 byPktType = PK_TYPE_11B;
2369 }
2370
Andres More4e9b5e22013-02-12 20:36:30 -05002371 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2373 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002374 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002376 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2377 if (pTransmitKey == NULL) {
2378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2379 }
2380 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002381 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002382 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2383 }
2384 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2386 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002387 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002388 }
2389 }
2390 }
2391
Forest Bond92b96792009-06-13 07:38:31 -04002392 if (pDevice->bEnableHostWEP) {
2393 if ((uNodeIndex != 0) &&
2394 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002395 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2396 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002397 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002398 }
2399 }
2400 }
2401 else {
2402
Forest Bond92b96792009-06-13 07:38:31 -04002403 if (pTransmitKey == NULL) {
2404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002405 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002406 dev_kfree_skb_irq(skb);
2407 pStats->tx_dropped++;
2408 return STATUS_FAILURE;
2409 }
Forest Bond92b96792009-06-13 07:38:31 -04002410 }
2411 }
2412
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002413 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2414
Forest Bond92b96792009-06-13 07:38:31 -04002415 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002416 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002417 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002418 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002419 pDevice->wCurrentRate,
2420 &uHeaderLen, &BytesToWrite
2421 );
2422
Andres Moree269fc22013-02-12 20:36:29 -05002423 if (fConvertedPacket == false) {
2424 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002425 dev_kfree_skb_irq(skb);
2426 return STATUS_FAILURE;
2427 }
2428
Andres More4e9b5e22013-02-12 20:36:30 -05002429 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002430 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002431 bScheduleCommand((void *) pDevice,
2432 WLAN_CMD_MAC_DISPOWERSAVING,
2433 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002434 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002435 }
2436 }
2437
Andres Moreb902fbf2013-02-25 20:32:51 -05002438 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002439 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002440
2441 pContext->pPacket = skb;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002442 pContext->type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002443 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002444
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002445 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002446 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002447 (u16)(BytesToWrite-uHeaderLen),
2448 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002449
2450 status = PIPEnsSendBulkOut(pDevice,pContext);
2451
Andres More4e9b5e22013-02-12 20:36:30 -05002452 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002453 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002454
Andres Moreb902fbf2013-02-25 20:32:51 -05002455 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002456 }
2457
2458 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002459 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002460 dev_kfree_skb_irq(skb);
2461 return STATUS_FAILURE;
2462 }
2463 else
2464 return 0;
2465
2466}
2467
Forest Bond92b96792009-06-13 07:38:31 -04002468/*
2469 * Description:
2470 * Relay packet send (AC1DMA) from rx dpc.
2471 *
2472 * Parameters:
2473 * In:
2474 * pDevice - Pointer to the adapter
2475 * pPacket - Pointer to rx packet
2476 * cbPacketSize - rx ethernet frame size
2477 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002478 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002479 *
Andres More4e9b5e22013-02-12 20:36:30 -05002480 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002481 */
2482
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002483int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2484 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002485{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002486 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002487 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002488 u32 BytesToWrite = 0, uHeaderLen = 0;
2489 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002490 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002491 SKeyItem STempKey;
2492 PSKeyItem pTransmitKey = NULL;
2493 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002494 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002495 u8 byPktTyp;
2496 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002497 u32 status;
2498 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002499
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002500 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002501
2502 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002503 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002504 }
2505
Andres Moreceb8c5d2013-03-18 20:33:49 -05002506 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002507
Andres More4e9b5e22013-02-12 20:36:30 -05002508 if (pDevice->bEncryptionEnable == true) {
2509 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002510 // get group key
2511 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002512 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002513 pTransmitKey = NULL;
2514 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2515 } else {
2516 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2517 }
2518 }
2519
2520 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002521 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002522 pTransmitKey = &STempKey;
2523 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2524 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2525 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2526 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2527 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2528 memcpy(pTransmitKey->abyKey,
2529 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2530 pTransmitKey->uKeyLength
2531 );
2532 }
2533 }
2534
2535 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002536 pContext->bBoolInUse = false;
2537 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002538 }
2539
Andres Moreb902fbf2013-02-25 20:32:51 -05002540 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002541
2542 if (pDevice->bFixRate) {
2543 if (pDevice->byBBType == BB_TYPE_11B) {
2544 if (pDevice->uConnectionRate >= RATE_11M) {
2545 pDevice->wCurrentRate = RATE_11M;
2546 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002547 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002548 }
2549 } else {
2550 if ((pDevice->byBBType == BB_TYPE_11A) &&
2551 (pDevice->uConnectionRate <= RATE_6M)) {
2552 pDevice->wCurrentRate = RATE_6M;
2553 } else {
2554 if (pDevice->uConnectionRate >= RATE_54M)
2555 pDevice->wCurrentRate = RATE_54M;
2556 else
Andres More3eaca0d2013-02-25 20:32:52 -05002557 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002558 }
2559 }
2560 }
2561 else {
2562 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2563 }
2564
Forest Bond92b96792009-06-13 07:38:31 -04002565 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002566 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002567 }
2568
2569 if (pDevice->wCurrentRate <= RATE_11M)
2570 byPktType = PK_TYPE_11B;
2571
Andres Moreabad19d2010-07-12 16:28:32 -03002572 BytesToWrite = uDataLen + ETH_FCS_LEN;
2573
Forest Bond92b96792009-06-13 07:38:31 -04002574 // Convert the packet to an usb frame and copy into our buffer
2575 // and send the irp.
2576
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002577 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2578
Forest Bond92b96792009-06-13 07:38:31 -04002579 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002580 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002581 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2582 pbySkbData, pTransmitKey, uNodeIndex,
2583 pDevice->wCurrentRate,
2584 &uHeaderLen, &BytesToWrite
2585 );
2586
Andres Moree269fc22013-02-12 20:36:29 -05002587 if (fConvertedPacket == false) {
2588 pContext->bBoolInUse = false;
2589 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002590 }
2591
Andres Moreb902fbf2013-02-25 20:32:51 -05002592 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002593 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002594
2595 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002596 pContext->type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002597 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002598
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002599 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002600 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002601 (u16)(BytesToWrite - uHeaderLen),
2602 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002603
2604 status = PIPEnsSendBulkOut(pDevice,pContext);
2605
Andres More4e9b5e22013-02-12 20:36:30 -05002606 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002607}
2608