blob: 1ff14469df9967b4f26494ebe638655b05e7984c [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Valentina Manea3b138852013-11-04 10:44:02 +020067static const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Valentina Manea3b138852013-11-04 10:44:02 +020072static const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Valentina Manea3b138852013-11-04 10:44:02 +020076static const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000099static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000100
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100101static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100102 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100103 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
104 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000106static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500107 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000108 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100110static void s_vFillTxKey(struct vnt_private *pDevice,
111 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
112 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100113 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400114
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000115static void s_vSWencryption(struct vnt_private *pDevice,
116 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
119 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestley20338012014-03-18 19:25:08 +0000121static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000122 u8 rsv_type, u8 pkt_type, u32 frame_lenght, u16 current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100124static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100125 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
126 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400127
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100128static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100129 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500130 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400131
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000132static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100133 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000135static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000136 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
137 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400138
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000139static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000140 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400141{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000142 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000143 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400144
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400146
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000147 for (ii = 0; ii < priv->cbTD; ii++) {
148 if (!priv->apTD[ii])
149 return NULL;
150
151 context = priv->apTD[ii];
152 if (context->bBoolInUse == false) {
153 context->bBoolInUse = true;
154 memset(context->Data, 0,
155 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
156 return context;
157 }
158 }
159
160 if (ii == priv->cbTD)
161 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000162
Malcolm Priestley5c851382013-11-26 19:12:38 +0000163 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400164}
165
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000166static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
167 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400168{
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000169 struct net_device_stats *stats = &pDevice->stats;
Malcolm Priestley51934e72013-12-09 22:30:14 +0000170 struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info;
Forest Bond92b96792009-06-13 07:38:31 -0400171
Malcolm Priestley51934e72013-12-09 22:30:14 +0000172 pkt_info[byPktNum].fifo_ctl = wFIFOCtl;
173 memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN);
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000174
175 stats->tx_bytes += wPktLength;
Forest Bond92b96792009-06-13 07:38:31 -0400176}
177
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100178static void s_vFillTxKey(struct vnt_private *pDevice,
179 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
180 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
181 struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400182{
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100183 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000184 __le32 *pdwIV = (__le32 *)pbyIVHead;
Malcolm Priestley2fbb2302014-03-22 09:01:25 +0000185 __le32 *pdwExtIV = (__le32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500186 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000187 __le32 rev_iv_counter;
Forest Bond92b96792009-06-13 07:38:31 -0400188
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100189 /* Fill TXKEY */
190 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100191 return;
Forest Bond92b96792009-06-13 07:38:31 -0400192
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000193 rev_iv_counter = cpu_to_le32(pDevice->dwIVCounter);
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000194 *pdwIV = cpu_to_le32(pDevice->dwIVCounter);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100195 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400196
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100197 switch (pTransmitKey->byCipherSuite) {
198 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100199 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000200 memcpy(pDevice->abyPRNG, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100201 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
202 pTransmitKey->uKeyLength);
203 } else {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000204 memcpy(pbyBuf, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100205 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
206 pTransmitKey->uKeyLength);
207 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000208 memcpy(pbyBuf+8, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100209 memcpy(pbyBuf+11, pTransmitKey->abyKey,
210 pTransmitKey->uKeyLength);
211 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100212
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100213 memcpy(pDevice->abyPRNG, pbyBuf, 16);
214 }
215 /* Append IV after Mac Header */
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000216 *pdwIV &= cpu_to_le32(WEP_IV_MASK);
217 *pdwIV |= cpu_to_le32((u32)pDevice->byKeyIndex << 30);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100218
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100219 pDevice->dwIVCounter++;
220 if (pDevice->dwIVCounter > WEP_IV_MASK)
221 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100222
223 break;
224 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100225 pTransmitKey->wTSC15_0++;
226 if (pTransmitKey->wTSC15_0 == 0)
227 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100228
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100229 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
230 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
231 pDevice->abyPRNG);
232 memcpy(pbyBuf, pDevice->abyPRNG, 16);
233
234 /* Make IV */
235 memcpy(pdwIV, pDevice->abyPRNG, 3);
236
237 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
238 0xc0) | 0x20);
239 /* Append IV&ExtIV after Mac Header */
240 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
241
242 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
243 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
244
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100245 break;
246 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100247 pTransmitKey->wTSC15_0++;
248 if (pTransmitKey->wTSC15_0 == 0)
249 pTransmitKey->dwTSC47_16++;
250
251 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
252
253 /* Make IV */
254 *pdwIV = 0;
255 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
256 0xc0) | 0x20);
257
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000258 *pdwIV |= cpu_to_le32((u32)(pTransmitKey->wTSC15_0));
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100259
260 /* Append IV&ExtIV after Mac Header */
261 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
262
263 if (!mic_hdr)
264 return;
265
266 /* MICHDR0 */
267 mic_hdr->id = 0x59;
268 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
269 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
270
271 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
272 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
273
274 /* MICHDR1 */
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000275 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100276 mic_hdr->hlen = cpu_to_be16(28);
277 else
278 mic_hdr->hlen = cpu_to_be16(22);
279
280 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
281 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
282
283 /* MICHDR2 */
284 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
Malcolm Priestley5d4fe752014-03-22 09:01:26 +0000285 mic_hdr->frame_control = cpu_to_le16(
286 le16_to_cpu(pMACHeader->frame_control) & 0xc78f);
287 mic_hdr->seq_ctrl = cpu_to_le16(
288 le16_to_cpu(pMACHeader->seq_ctrl) & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100289
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000290 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100291 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
292 }
Forest Bond92b96792009-06-13 07:38:31 -0400293}
294
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000295static void s_vSWencryption(struct vnt_private *pDevice,
296 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400297{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000298 u32 cbICVlen = 4;
299 u32 dwICV = 0xffffffff;
300 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400301
302 if (pTransmitKey == NULL)
303 return;
304
305 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
306 //=======================================================================
307 // Append ICV after payload
308 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500309 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400310 // finally, we must invert dwCRC to get the correct answer
311 *pdwICV = cpu_to_le32(~dwICV);
312 // RC4 encryption
313 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
317 //=======================================================================
318 //Append ICV after payload
319 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500320 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400321 // finally, we must invert dwCRC to get the correct answer
322 *pdwICV = cpu_to_le32(~dwICV);
323 // RC4 encryption
324 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
325 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
326 //=======================================================================
327 }
328}
329
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000330static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100331{
332 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
333 [rate % MAX_RATE]);
334}
335
Forest Bond92b96792009-06-13 07:38:31 -0400336/*byPktType : PK_TYPE_11A 0
337 PK_TYPE_11B 1
338 PK_TYPE_11GB 2
339 PK_TYPE_11GA 3
340*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000341static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
342 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400343{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000344 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400345
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000346 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
347 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400348
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000349 if (pkt_type == PK_TYPE_11B)
350 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
351 (u16)priv->byTopCCKBasicRate);
352 else
353 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
354 (u16)priv->byTopOFDMBasicRate);
355
356 if (need_ack)
357 return data_time + priv->uSIFS + ack_time;
358
359 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400360}
361
Malcolm Priestley2075f652014-03-18 19:25:07 +0000362static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100363 u32 frame_length, u16 rate, int need_ack)
364{
365 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
366 frame_length, rate, need_ack));
367}
368
Forest Bond92b96792009-06-13 07:38:31 -0400369//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000370static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000371 u8 rsv_type, u8 pkt_type, u32 frame_lenght, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400372{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000373 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400374
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000375 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400376
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000377 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
378 frame_lenght, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400379
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000380 if (rsv_type == 0) {
381 rts_time = BBuGetFrameTime(priv->byPreambleType,
382 pkt_type, 20, priv->byTopCCKBasicRate);
383 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
384 pkt_type, 14, priv->byTopCCKBasicRate);
385 } else if (rsv_type == 1) {
386 rts_time = BBuGetFrameTime(priv->byPreambleType,
387 pkt_type, 20, priv->byTopCCKBasicRate);
388 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
389 14, priv->byTopCCKBasicRate);
390 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
391 14, priv->byTopOFDMBasicRate);
392 } else if (rsv_type == 2) {
393 rts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
394 20, priv->byTopOFDMBasicRate);
395 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
396 pkt_type, 14, priv->byTopOFDMBasicRate);
397 } else if (rsv_type == 3) {
398 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
399 14, priv->byTopCCKBasicRate);
400 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
401 14, priv->byTopOFDMBasicRate);
402
403 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
404
Malcolm Priestley20338012014-03-18 19:25:08 +0000405 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000406 }
407
408 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
409
410 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400411}
412
413//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000414static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100415 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400416{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100417 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400418
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100419 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100420 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100421 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
422 byPktType, 14, pDevice->byTopCCKBasicRate);
423 else
424 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
425 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100426 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100427 }
Forest Bond92b96792009-06-13 07:38:31 -0400428
Forest Bond92b96792009-06-13 07:38:31 -0400429 return 0;
430}
431
Forest Bond92b96792009-06-13 07:38:31 -0400432//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000433static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000434 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
435 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400436{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000437 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400438
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100439 switch (byDurType) {
440 case RTSDUR_BB:
441 case RTSDUR_BA:
442 case RTSDUR_BA_F0:
443 case RTSDUR_BA_F1:
444 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
445 14, pDevice->byTopCCKBasicRate);
446 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
447 s_uGetTxRsvTime(pDevice, byPktType,
448 cbFrameLength, wRate, bNeedAck);
449 break;
Forest Bond92b96792009-06-13 07:38:31 -0400450
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100451 case RTSDUR_AA:
452 case RTSDUR_AA_F0:
453 case RTSDUR_AA_F1:
454 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
455 14, pDevice->byTopOFDMBasicRate);
456 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
457 s_uGetTxRsvTime(pDevice, byPktType,
458 cbFrameLength, wRate, bNeedAck);
459 break;
Forest Bond92b96792009-06-13 07:38:31 -0400460
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100461 case CTSDUR_BA:
462 case CTSDUR_BA_F0:
463 case CTSDUR_BA_F1:
464 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100465 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100466 break;
Forest Bond92b96792009-06-13 07:38:31 -0400467
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100468 default:
469 break;
470 }
Forest Bond92b96792009-06-13 07:38:31 -0400471
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100472 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400473}
474
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100475static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
476 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
477{
478 /* Get SignalField,ServiceField,Length */
479 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
480 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
481 PK_TYPE_11B, &buf->b);
482
483 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000484 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
485 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100486
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000487 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
488 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100489 priv->byTopCCKBasicRate);
490
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000491 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100492}
493
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100494static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
495 u16 rate, struct vnt_tx_datahead_g_fb *buf,
496 u32 frame_len, int need_ack)
497{
498 /* Get SignalField,ServiceField,Length */
499 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
500
501 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
502 PK_TYPE_11B, &buf->b);
503
504 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000505 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
506 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100507
Malcolm Priestley4e011172014-03-18 19:24:55 +0000508 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
509 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100510
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000511 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
512 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100513 priv->byTopCCKBasicRate);
514
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000515 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100516}
517
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100518static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
519 u16 rate, struct vnt_tx_datahead_a_fb *buf,
520 u32 frame_len, int need_ack)
521{
522 /* Get SignalField,ServiceField,Length */
523 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
524 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000525 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100526
Malcolm Priestley4e011172014-03-18 19:24:55 +0000527 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
528 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100529
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000530 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100531
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000532 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100533}
534
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100535static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
536 u16 rate, struct vnt_tx_datahead_ab *buf,
537 u32 frame_len, int need_ack)
538{
539 /* Get SignalField,ServiceField,Length */
540 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
541 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000542 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100543
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000544 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100545
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000546 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100547}
548
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100549static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
550 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000551 __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100552{
553 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000554 rts->frame_control =
555 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100556
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000557 if (priv->op_mode == NL80211_IFTYPE_ADHOC ||
558 priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100559 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
560 else
561 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
562
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000563 if (priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100564 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
565 else
566 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
567
568 return 0;
569}
570
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100571static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100572 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
573 u8 pkt_type, u32 frame_len, int need_ack,
574 u16 current_rate, u8 fb_option)
575{
576 u16 rts_frame_len = 20;
577
578 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
579 PK_TYPE_11B, &buf->b);
580 BBvCalculateParameter(priv, rts_frame_len,
581 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
582
Malcolm Priestley4e011172014-03-18 19:24:55 +0000583 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100584 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000585 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100586 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000587 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100588 pkt_type, current_rate, need_ack, fb_option);
589
Malcolm Priestley4e011172014-03-18 19:24:55 +0000590 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100591
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100592 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
593 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100594}
595
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100596static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100597 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
598 u8 pkt_type, u32 frame_len, int need_ack,
599 u16 current_rate, u8 fb_option)
600{
601 u16 rts_frame_len = 20;
602
603 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
604 PK_TYPE_11B, &buf->b);
605 BBvCalculateParameter(priv, rts_frame_len,
606 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
607
608
Malcolm Priestley4e011172014-03-18 19:24:55 +0000609 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100610 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000611 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100612 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000613 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100614 pkt_type, current_rate, need_ack, fb_option);
615
616
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000617 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100618 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000619 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100620 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000621 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100622 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000623 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100624 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100625
Malcolm Priestley4e011172014-03-18 19:24:55 +0000626 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100627
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100628 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
629 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100630}
631
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100632static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100633 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
634 u8 pkt_type, u32 frame_len, int need_ack,
635 u16 current_rate, u8 fb_option)
636{
637 u16 rts_frame_len = 20;
638
639 BBvCalculateParameter(priv, rts_frame_len,
640 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
641
Malcolm Priestley4e011172014-03-18 19:24:55 +0000642 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100643 pkt_type, current_rate, need_ack, fb_option);
644
Malcolm Priestley4e011172014-03-18 19:24:55 +0000645 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100646
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100647 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
648 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100649}
650
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100651static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100652 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
653 u8 pkt_type, u32 frame_len, int need_ack,
654 u16 current_rate, u8 fb_option)
655{
656 u16 rts_frame_len = 20;
657
658 BBvCalculateParameter(priv, rts_frame_len,
659 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
660
Malcolm Priestley4e011172014-03-18 19:24:55 +0000661 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100662 pkt_type, current_rate, need_ack, fb_option);
663
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000664 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100665 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100666
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000667 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100668 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100669
Malcolm Priestley4e011172014-03-18 19:24:55 +0000670 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100671
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100672 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
673 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100674}
675
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100676static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100677 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500678 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400679{
Forest Bond92b96792009-06-13 07:38:31 -0400680
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100681 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100682 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400683
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100684 /* Note: So far RTSHead doesn't appear in ATIM
685 * & Beacom DMA, so we don't need to take them
686 * into account.
687 * Otherwise, we need to modified codes for them.
688 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100689 switch (byPktType) {
690 case PK_TYPE_11GB:
691 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100692 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100693 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100694 psEthHeader, byPktType, cbFrameLength,
695 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100696 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100697 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100698 psEthHeader, byPktType, cbFrameLength,
699 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100700 break;
701 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100702 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100703 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100704 psEthHeader, byPktType, cbFrameLength,
705 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100706 break;
707 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100708 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100709 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100710 psEthHeader, byPktType, cbFrameLength,
711 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100712 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100713
714 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400715}
716
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100717static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100718 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
719 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400720{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000721 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400722
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100723 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100724 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400725
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100726 if (byFBOption != AUTO_FB_NONE) {
727 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100728 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100729 /* Get SignalField,ServiceField,Length */
730 BBvCalculateParameter(pDevice, uCTSFrameLen,
731 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000732 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100733 cbFrameLength, byPktType,
734 wCurrentRate, bNeedAck, byFBOption);
735 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000736 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100737 CTSDUR_BA_F0, cbFrameLength, byPktType,
738 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100739 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000740 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100741 CTSDUR_BA_F1, cbFrameLength, byPktType,
742 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100743 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000744 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000745 pBuf->data.frame_control =
746 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
747
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100748 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100749
750 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
751 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100752 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100753 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100754 /* Get SignalField,ServiceField,Length */
755 BBvCalculateParameter(pDevice, uCTSFrameLen,
756 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100757 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000758 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100759 CTSDUR_BA, cbFrameLength, byPktType,
760 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100761 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000762 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000763 pBuf->data.frame_control =
764 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
765
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100766 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100767
768 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
769 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400770 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100771
772 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400773}
774
Forest Bond92b96792009-06-13 07:38:31 -0400775/*+
776 *
777 * Description:
778 * Generate FIFO control for MAC & Baseband controller
779 *
780 * Parameters:
781 * In:
782 * pDevice - Pointer to adpater
783 * pTxDataHead - Transmit Data Buffer
784 * pTxBufHead - pTxBufHead
785 * pvRrvTime - pvRrvTime
786 * pvRTS - RTS Buffer
787 * pCTS - CTS Buffer
788 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
789 * bNeedACK - If need ACK
790 * uDMAIdx - DMA Index
791 * Out:
792 * none
793 *
794 * Return Value: none
795 *
796-*/
Andres Morecc856e62010-05-17 21:34:01 -0300797
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100798static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100799 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100800 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
801 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400802{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100803 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100804 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000805 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000806 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400807
Malcolm Priestley03a9cf32014-03-22 09:01:30 +0000808 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100809 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400810
Malcolm Priestley92928f12013-10-07 20:14:01 +0100811 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
812 byFBOption = AUTO_FB_0;
813 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
814 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400815
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100816 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100817 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100818
Malcolm Priestley92928f12013-10-07 20:14:01 +0100819 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
820 if (need_rts) {
821 struct vnt_rrv_time_rts *pBuf =
822 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100823
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000824 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100825 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000826 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100827 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000828 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100829 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100830
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000831 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100832 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000833 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100834 PK_TYPE_11B, cbFrameSize,
835 pDevice->byTopCCKBasicRate, bNeedACK);
836
837 if (need_mic) {
838 *mic_hdr = &tx_buffer->
839 tx_head.tx_rts.tx.mic.hdr;
840 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
841 } else {
842 head = &tx_buffer->tx_head.tx_rts.tx.head;
843 }
844
845 /* Fill RTS */
846 return s_vFillRTSHead(pDevice, byPktType, head,
847 cbFrameSize, bNeedACK, psEthHeader,
848 wCurrentRate, byFBOption);
849
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100850 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100851 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
852 tx_head.tx_cts.cts;
853
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000854 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100855 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000856 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100857 PK_TYPE_11B, cbFrameSize,
858 pDevice->byTopCCKBasicRate, bNeedACK);
859
Malcolm Priestley372108e2014-03-18 19:25:00 +0000860 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100861 byPktType, cbFrameSize, wCurrentRate);
862
863 if (need_mic) {
864 *mic_hdr = &tx_buffer->
865 tx_head.tx_cts.tx.mic.hdr;
866 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
867 } else {
868 head = &tx_buffer->tx_head.tx_cts.tx.head;
869 }
870
871 /* Fill CTS */
872 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
873 head, cbFrameSize, bNeedACK, wCurrentRate,
874 byFBOption);
875 }
876 } else if (byPktType == PK_TYPE_11A) {
877 if (need_mic) {
878 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
879 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
880 } else {
881 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100882 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100883
Malcolm Priestley92928f12013-10-07 20:14:01 +0100884 if (need_rts) {
885 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
886 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100887
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000888 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100889 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100890
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000891 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100892 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
893
894 /* Fill RTS */
895 return s_vFillRTSHead(pDevice, byPktType, head,
896 cbFrameSize, bNeedACK, psEthHeader,
897 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100898 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100899 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
900 tx_head.tx_ab.ab;
901
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000902 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100903 PK_TYPE_11A, cbFrameSize,
904 wCurrentRate, bNeedACK);
905
906 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
907 wCurrentRate, &head->data_head_a_fb,
908 cbFrameSize, bNeedACK);
909 }
910 } else if (byPktType == PK_TYPE_11B) {
911 if (need_mic) {
912 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
913 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
914 } else {
915 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100916 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100917
Malcolm Priestley92928f12013-10-07 20:14:01 +0100918 if (need_rts) {
919 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
920 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100921
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000922 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100923 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100924
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000925 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100926 PK_TYPE_11B, cbFrameSize, wCurrentRate,
927 bNeedACK);
928
929 /* Fill RTS */
930 return s_vFillRTSHead(pDevice, byPktType, head,
931 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100932 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100933 } else {
934 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
935 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100936
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000937 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100938 PK_TYPE_11B, cbFrameSize,
939 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100940
Malcolm Priestley92928f12013-10-07 20:14:01 +0100941 return vnt_rxtx_datahead_ab(pDevice, byPktType,
942 wCurrentRate, &head->data_head_ab,
943 cbFrameSize, bNeedACK);
944 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100945 }
946
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100947 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400948}
949/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500950 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500951 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300952 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400953*/
954
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000955static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100956 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100957 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
958 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
959 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400960{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100961 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000962 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
963 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000964 u32 cb802_1_H_len;
965 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
966 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100967 int bNeedACK;
968 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000969 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
970 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
971 u8 abySNAP_Bridgetunnel[ETH_ALEN]
972 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
973 u32 uDuration;
974 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100975 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000976 u8 byFBOption = AUTO_FB_NONE, byFragType;
977 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100978 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000979 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500980 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100981
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100982 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400983
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000984 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500985 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
986 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000987 }
Forest Bond92b96792009-06-13 07:38:31 -0400988
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000989 /* Get pkt type */
990 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
991 cb802_1_H_len = 8;
992 else
993 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400994
Charles Clément21ec51f2010-05-18 10:08:14 -0700995 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400996
997 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500998 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400999
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001000 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC ||
1001 pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001002 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001003 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001004 pTxBufHead->wFIFOCtl =
1005 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1006 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001007 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001008 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1009 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001010 } else {
1011 /* MSDUs in Infra mode always need ACK */
1012 bNeedACK = true;
1013 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1014 }
Forest Bond92b96792009-06-13 07:38:31 -04001015
Malcolm Priestley58462512014-03-22 09:01:27 +00001016 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001017
Forest Bond92b96792009-06-13 07:38:31 -04001018 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001019 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1020
Andres More3eaca0d2013-02-25 20:32:52 -05001021 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001022
1023 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001024 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001025 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1026 }
1027
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001028 /* Set Auto Fallback Ctl */
1029 if (wCurrentRate >= RATE_18M) {
1030 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1031 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1032
1033 pDevice->tx_rate_fb0 =
1034 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1035 pDevice->tx_rate_fb1 =
1036 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1037
1038 byFBOption = AUTO_FB_0;
1039 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1040 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1041 pDevice->tx_rate_fb0 =
1042 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1043 pDevice->tx_rate_fb1 =
1044 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1045
1046 byFBOption = AUTO_FB_1;
1047 }
1048 }
Forest Bond92b96792009-06-13 07:38:31 -04001049
Andres More4e9b5e22013-02-12 20:36:30 -05001050 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001051 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1052 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1053 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1054 }
1055 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1056 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1057 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1058 }
1059 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1060 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1061 }
1062 }
1063 }
1064
Forest Bond92b96792009-06-13 07:38:31 -04001065 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1066 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1067 cbIVlen = 4;
1068 cbICVlen = 4;
1069 }
1070 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1071 cbIVlen = 8;//IV+ExtIV
1072 cbMIClen = 8;
1073 cbICVlen = 4;
1074 }
1075 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1076 cbIVlen = 8;//RSN Header
1077 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001078 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001079 }
Andres Moree269fc22013-02-12 20:36:29 -05001080 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001081 //MAC Header should be padding 0 to DW alignment.
1082 uPadding = 4 - (cbMACHdLen%4);
1083 uPadding %= 4;
1084 }
1085 }
1086
1087 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1088
Andres Moree269fc22013-02-12 20:36:29 -05001089 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1090 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001091 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001092 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001093 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1094 }
1095
Andres Moreb902fbf2013-02-25 20:32:51 -05001096 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001097 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1098
Forest Bond92b96792009-06-13 07:38:31 -04001099 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1100 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001101 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001102 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001103 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001104 }
1105 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001106 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001107 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001108 }
1109 } else {
1110 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001111 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001112 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001113 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001114 }
Andres Moree269fc22013-02-12 20:36:29 -05001115 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001116 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001117 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001118 }
1119 } // Auto Fall Back
1120 }
1121 else {//802.11a/b packet
1122 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001123 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001124 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001125 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001126 }
Andres Moree269fc22013-02-12 20:36:29 -05001127 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001128 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001129 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001130 }
1131 } else {
1132 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001133 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001134 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001135 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001136 }
Andres Moree269fc22013-02-12 20:36:29 -05001137 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001138 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001139 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001140 }
1141 } // Auto Fall Back
1142 }
1143
Andres Moreb902fbf2013-02-25 20:32:51 -05001144 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1145 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1146 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001147
Forest Bond92b96792009-06-13 07:38:31 -04001148 //=========================
1149 // No Fragmentation
1150 //=========================
1151 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1152 byFragType = FRAGCTL_NONFRAG;
1153 //uDMAIdx = TYPE_AC0DMA;
1154 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1155
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001156 /* Fill FIFO, RrvTime, RTS and CTS */
1157 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1158 tx_buffer, &pMICHDR, cbMICHDR,
1159 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001160
Forest Bond92b96792009-06-13 07:38:31 -04001161 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001162 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001163 byFragType, uDMAIdx, 0);
1164
Andres More4e9b5e22013-02-12 20:36:30 -05001165 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001166 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001167 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001168 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001169
1170 if (pDevice->bEnableHostWEP) {
1171 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1172 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1173 }
1174 }
1175
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001176 /* 802.1H */
1177 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001178 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001179 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001180 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001181 abySNAP_Bridgetunnel, 6);
1182 else
1183 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001184
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001185 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001186
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001187 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1188 }
Forest Bond92b96792009-06-13 07:38:31 -04001189
Forest Bond92b96792009-06-13 07:38:31 -04001190 if (pPacket != NULL) {
1191 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001192 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001193 (pPacket + ETH_HLEN),
1194 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001195 );
1196
1197 } else {
1198 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001199 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001200 }
1201
Andres More4e9b5e22013-02-12 20:36:30 -05001202 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001203
1204 ///////////////////////////////////////////////////////////////////
1205
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001206 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1207 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1208 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1209 }
Forest Bond92b96792009-06-13 07:38:31 -04001210 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001211 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1212 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001213 }
1214 else {
Andres More52a7e642013-02-25 20:32:53 -05001215 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1216 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001217 }
1218 // DO Software Michael
1219 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001220 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001221 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001222 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001223 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1224 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001225
1226 ///////////////////////////////////////////////////////////////////
1227
1228 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1229 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001230 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001231 //}
1232 //DBG_PRN_GRP12(("\n\n\n"));
1233
1234 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1235
Andres More52a7e642013-02-25 20:32:53 -05001236 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1237 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001238
1239 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1240 MIC_vUnInit();
1241
Andres More4e9b5e22013-02-12 20:36:30 -05001242 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001243 *pdwMIC_L = 0;
1244 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001245 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001246 }
1247 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1248 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1249 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1250 }
1251
Andres More4e9b5e22013-02-12 20:36:30 -05001252 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001253
Andres More3eaca0d2013-02-25 20:32:52 -05001254 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001255
Andres More4e9b5e22013-02-12 20:36:30 -05001256 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1257 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1258 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001259 cbFrameSize -= cbICVlen;
1260 }
1261
Forest Bond92b96792009-06-13 07:38:31 -04001262 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001263
1264 *pcbHeaderLen = cbHeaderLength;
1265 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1266
Forest Bond92b96792009-06-13 07:38:31 -04001267 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001268 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001269
Andres More4e9b5e22013-02-12 20:36:30 -05001270 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001271
1272}
1273
Forest Bond92b96792009-06-13 07:38:31 -04001274/*+
1275 *
1276 * Description:
1277 * Translate 802.3 to 802.11 header
1278 *
1279 * Parameters:
1280 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001281 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001282 * dwTxBufferAddr - Transmit Buffer
1283 * pPacket - Packet from upper layer
1284 * cbPacketSize - Transmit Data Length
1285 * Out:
1286 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1287 * pcbAppendPayload - size of append payload for 802.1H translation
1288 *
1289 * Return Value: none
1290 *
1291-*/
1292
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001293static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001294 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001295 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001296{
Andres More1cac4a42013-03-18 20:33:50 -05001297 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001298
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001299 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001300
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001301 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001302 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001303 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001304 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001305 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1306 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001307 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001308 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001309 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001310 } else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001311 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001312 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001313 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001314 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001315 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001316 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001317 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001318 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001319 &(pDevice->abyBSSID[0]),
1320 ETH_ALEN);
1321 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001322 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001323 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001324 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001325 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001326 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001327 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001328 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001329 &(pDevice->abyBSSID[0]),
1330 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001331 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001332 }
1333 }
1334
1335 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001336 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001337
Andres More1cac4a42013-03-18 20:33:50 -05001338 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001339
Andres More1cac4a42013-03-18 20:33:50 -05001340 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001341
1342 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001343 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001344
1345 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1346 pDevice->wSeqCounter++;
1347 if (pDevice->wSeqCounter > 0x0fff)
1348 pDevice->wSeqCounter = 0;
1349 }
1350
1351 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001352 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001353 }
1354}
1355
Forest Bond92b96792009-06-13 07:38:31 -04001356/*+
1357 *
1358 * Description:
1359 * Request instructs a MAC to transmit a 802.11 management packet through
1360 * the adapter onto the medium.
1361 *
1362 * Parameters:
1363 * In:
1364 * hDeviceContext - Pointer to the adapter
1365 * pPacket - A pointer to a descriptor for the packet to transmit
1366 * Out:
1367 * none
1368 *
Andres Moree269fc22013-02-12 20:36:29 -05001369 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001370 *
1371-*/
1372
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001373CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1374 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001375{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001376 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001377 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001378 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001379 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001380 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001381 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001382 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001383 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001384 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001385 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001386 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1387 u32 uPadding = 0;
1388 u16 wTxBufSize;
1389 u32 cbMacHdLen;
1390 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001391
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001392 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001393
1394 if (NULL == pContext) {
1395 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1396 return CMD_STATUS_RESOURCES;
1397 }
1398
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001399 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001400 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001401 pTxBufHead = &pTX_Buffer->fifo_head;
1402 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1403 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001404
1405 if (pDevice->byBBType == BB_TYPE_11A) {
1406 wCurrentRate = RATE_6M;
1407 byPktType = PK_TYPE_11A;
1408 } else {
1409 wCurrentRate = RATE_1M;
1410 byPktType = PK_TYPE_11B;
1411 }
1412
1413 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1414 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1415 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1416 // to set power here.
1417 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1418 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1419 } else {
1420 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1421 }
1422 pDevice->wCurrentRate = wCurrentRate;
1423
Forest Bond92b96792009-06-13 07:38:31 -04001424 //Set packet type
1425 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1426 pTxBufHead->wFIFOCtl = 0;
1427 }
1428 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1429 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1430 }
1431 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1432 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1433 }
1434 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1435 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1436 }
1437
1438 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
Malcolm Priestley58462512014-03-22 09:01:27 +00001439 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001440
Andres More22040bb2010-08-02 20:21:44 -03001441 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001442 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001443 }
1444 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001445 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001446 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1447 };
1448
1449 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1450 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1451
1452 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1453 //Set Preamble type always long
1454 //pDevice->byPreambleType = PREAMBLE_LONG;
1455 // probe-response don't retry
1456 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001457 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001458 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1459 //}
1460 }
1461
1462 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1463
1464 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001465 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001466 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1467 } else {
1468 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1469 }
1470
1471 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001472 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001473
1474 // Notes:
1475 // Although spec says MMPDU can be fragmented; In most case,
1476 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001477
1478 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1479 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1480 cbIVlen = 4;
1481 cbICVlen = 4;
1482 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1483 }
1484 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1485 cbIVlen = 8;//IV+ExtIV
1486 cbMIClen = 8;
1487 cbICVlen = 4;
1488 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1489 //We need to get seed here for filling TxKey entry.
1490 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1491 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1492 }
1493 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1494 cbIVlen = 8;//RSN Header
1495 cbICVlen = 8;//MIC
1496 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001497 }
1498 //MAC Header should be padding 0 to DW alignment.
1499 uPadding = 4 - (cbMacHdLen%4);
1500 uPadding %= 4;
1501 }
1502
1503 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1504
1505 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001506 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001507 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1508 }
1509 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1510
1511 //Set RrvTime/RTS/CTS Buffer
1512 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001513 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001514 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001515 }
1516 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001517 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001518 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001519 }
1520
Andres Moreceb8c5d2013-03-18 20:33:49 -05001521 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001522 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1523 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001524 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001525 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1526 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001527 //=========================
1528 // No Fragmentation
1529 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001530 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001531
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001532 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001533 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001534 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001535 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001536
Andres More1cac4a42013-03-18 20:33:50 -05001537 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001538
1539 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1540
1541 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001542 u8 * pbyIVHead;
1543 u8 * pbyPayloadHead;
1544 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001545 PSKeyItem pTransmitKey = NULL;
1546
Andres Moreb902fbf2013-02-25 20:32:51 -05001547 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1548 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001549 do {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001550 if (pDevice->op_mode == NL80211_IFTYPE_STATION &&
1551 pDevice->bLinkPass == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001552 pbyBSSID = pDevice->abyBSSID;
1553 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001554 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001555 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001556 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1558 break;
1559 }
1560 } else {
1561 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1562 break;
1563 }
1564 }
1565 // get group key
1566 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001567 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001568 pTransmitKey = NULL;
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001569 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode);
Forest Bond92b96792009-06-13 07:38:31 -04001570 } else {
1571 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1572 }
Andres Moree269fc22013-02-12 20:36:29 -05001573 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001574 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001575 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001576 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001577
Jim Lieb3e362592009-08-12 14:54:11 -07001578 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001579 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001580 cbFrameBodySize);
1581 }
1582 else {
1583 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001584 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001585 }
1586
Andres More1cac4a42013-03-18 20:33:50 -05001587 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001588 pDevice->wSeqCounter++ ;
1589 if (pDevice->wSeqCounter > 0x0fff)
1590 pDevice->wSeqCounter = 0;
1591
1592 if (bIsPSPOLL) {
1593 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001594 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001595 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1596 // in the same place of other packet's Duration-field).
1597 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001598 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001599 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1600 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001601 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001602 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00001603 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001604 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1605 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001606 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1607 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001608 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001609 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1610 }
Forest Bond92b96792009-06-13 07:38:31 -04001611 }
1612
Malcolm Priestleyca347592014-03-22 09:01:28 +00001613 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001614 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001615 pTX_Buffer->byType = 0x00;
1616
1617 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00001618 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001619 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001620
Andres More1cac4a42013-03-18 20:33:50 -05001621 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001622 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1623 &pMACHeader->addr1[0], (u16)cbFrameSize,
1624 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001625 }
1626 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001627 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1628 &pMACHeader->addr3[0], (u16)cbFrameSize,
1629 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001630 }
1631
1632 PIPEnsSendBulkOut(pDevice,pContext);
1633 return CMD_STATUS_PENDING;
1634}
1635
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001636CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1637 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001638{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001639 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001640 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001641 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1642 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001643 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001644 u16 wCurrentRate;
1645 u32 cbFrameBodySize;
1646 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001647 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001648 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001649
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001650 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001651 if (NULL == pContext) {
1652 status = CMD_STATUS_RESOURCES;
1653 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1654 return status ;
1655 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001656
1657 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001658 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001659
1660 cbFrameBodySize = pPacket->cbPayloadLen;
1661
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001662 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001663
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001664 if (pDevice->byBBType == BB_TYPE_11A) {
1665 wCurrentRate = RATE_6M;
1666
1667 /* Get SignalField,ServiceField,Length */
1668 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1669 PK_TYPE_11A, &short_head->ab);
1670
1671 /* Get Duration and TimeStampOff */
1672 short_head->duration = s_uGetDataDuration(pDevice,
1673 PK_TYPE_11A, false);
1674 short_head->time_stamp_off =
1675 vnt_time_stamp_off(pDevice, wCurrentRate);
1676 } else {
1677 wCurrentRate = RATE_1M;
1678 short_head->fifo_ctl |= FIFOCTL_11B;
1679
1680 /* Get SignalField,ServiceField,Length */
1681 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1682 PK_TYPE_11B, &short_head->ab);
1683
1684 /* Get Duration and TimeStampOff */
1685 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001686 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001687 short_head->time_stamp_off =
1688 vnt_time_stamp_off(pDevice, wCurrentRate);
1689 }
1690
Forest Bond92b96792009-06-13 07:38:31 -04001691
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001692 /* Generate Beacon Header */
1693 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001694
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001695 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1696
1697 pMACHeader->duration_id = 0;
1698 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1699 pDevice->wSeqCounter++;
1700 if (pDevice->wSeqCounter > 0x0fff)
1701 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001702
1703 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1704
Malcolm Priestleyfad8e4a2014-03-22 09:01:29 +00001705 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)cbReqCount);
Andres Moreb902fbf2013-02-25 20:32:51 -05001706 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001707 pTX_Buffer->byType = 0x01;
1708
1709 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00001710 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001711 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001712
1713 PIPEnsSendBulkOut(pDevice,pContext);
1714 return CMD_STATUS_PENDING;
1715
1716}
1717
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001718void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1719{
1720 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001721 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001722 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001723 u8 byPktType;
1724 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001725 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001726 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001727 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001728 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001729 u32 cbFrameSize;
1730 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1731 u32 uPadding = 0;
1732 u32 cbMICHDR = 0, uLength = 0;
1733 u32 dwMICKey0, dwMICKey1;
1734 u32 dwMIC_Priority;
1735 u32 *pdwMIC_L, *pdwMIC_R;
1736 u16 wTxBufSize;
1737 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001738 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001739 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001740 u32 wCurrentRate = RATE_1M;
1741 PUWLAN_80211HDR p80211Header;
1742 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001743 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001744 SKeyItem STempKey;
1745 PSKeyItem pTransmitKey = NULL;
1746 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1747 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001748 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001749
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001750 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001751
1752 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1753 cbFrameBodySize = 0;
1754 }
1755 else {
1756 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1757 }
1758 p80211Header = (PUWLAN_80211HDR)skb->data;
1759
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001760 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001761
1762 if (NULL == pContext) {
1763 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1764 dev_kfree_skb_irq(skb);
1765 return ;
1766 }
1767
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001768 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001769 pTxBufHead = &pTX_Buffer->fifo_head;
1770 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1771 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001772
1773 if (pDevice->byBBType == BB_TYPE_11A) {
1774 wCurrentRate = RATE_6M;
1775 byPktType = PK_TYPE_11A;
1776 } else {
1777 wCurrentRate = RATE_1M;
1778 byPktType = PK_TYPE_11B;
1779 }
1780
1781 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1782 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1783 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1784 // to set power here.
1785 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1786 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1787 } else {
1788 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1789 }
1790
1791 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1792
1793 //Set packet type
1794 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1795 pTxBufHead->wFIFOCtl = 0;
1796 }
1797 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1798 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1799 }
1800 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1801 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1802 }
1803 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1804 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1805 }
1806
1807 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
Malcolm Priestley58462512014-03-22 09:01:27 +00001808 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001809
Andres More22040bb2010-08-02 20:21:44 -03001810 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001811 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001812 if (pDevice->bEnableHostWEP) {
1813 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001814 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001815 }
Forest Bond92b96792009-06-13 07:38:31 -04001816 }
1817 else {
1818 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001819 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001820 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001821 }
Andres More4e9b5e22013-02-12 20:36:30 -05001822 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001823 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1824 };
1825
1826 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1827 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1828
1829 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1830 //Set Preamble type always long
1831 //pDevice->byPreambleType = PREAMBLE_LONG;
1832
1833 // probe-response don't retry
1834 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001835 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001836 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1837 //}
1838 }
1839
1840 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1841
1842 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001843 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001844 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1845 } else {
1846 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1847 }
1848
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001849 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001850 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1851
1852 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1853 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1854 }
1855
1856 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1857 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1858 }
1859
1860 if (cbExtSuppRate >0) {
1861 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1862 }
1863 }
1864
Forest Bond92b96792009-06-13 07:38:31 -04001865 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001866 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001867
1868 // Notes:
1869 // Although spec says MMPDU can be fragmented; In most case,
1870 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001871
Forest Bond92b96792009-06-13 07:38:31 -04001872 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1873 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1874 cbIVlen = 4;
1875 cbICVlen = 4;
1876 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1877 }
1878 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1879 cbIVlen = 8;//IV+ExtIV
1880 cbMIClen = 8;
1881 cbICVlen = 4;
1882 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1883 //We need to get seed here for filling TxKey entry.
1884 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1885 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1886 }
1887 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1888 cbIVlen = 8;//RSN Header
1889 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001890 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001891 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001892 }
1893 //MAC Header should be padding 0 to DW alignment.
1894 uPadding = 4 - (cbMacHdLen%4);
1895 uPadding %= 4;
1896 }
1897
1898 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1899
1900 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001901 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001902 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1903 }
1904 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1905
Forest Bond92b96792009-06-13 07:38:31 -04001906 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001907 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001908 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001909
1910 }
1911 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001912 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001913 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001914 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001915 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001916 &(p80211Header->sA3.abyAddr1[0]),
1917 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001918 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001919 &(p80211Header->sA3.abyAddr2[0]),
1920 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001921 //=========================
1922 // No Fragmentation
1923 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001924 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001925
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001926 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001927 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001928 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001929 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001930
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001931 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001932
1933 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1934
Andres Moreb902fbf2013-02-25 20:32:51 -05001935 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1936 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1937 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001938
1939 // Copy the Packet into a tx Buffer
1940 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1941
1942 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001943 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001944 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1945
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001946 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001947 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1948 if (cbExtSuppRate != 0) {
1949 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1950 memcpy((pbyPayloadHead + cbFrameBodySize),
1951 pMgmt->abyCurrSuppRates,
1952 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1953 );
1954 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1955 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1956 pMgmt->abyCurrExtSuppRates,
1957 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1958 );
1959 }
1960 }
1961
1962 // Set wep
1963 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1964
1965 if (pDevice->bEnableHostWEP) {
1966 pTransmitKey = &STempKey;
1967 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1968 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1969 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1970 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1971 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1972 memcpy(pTransmitKey->abyKey,
1973 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1974 pTransmitKey->uKeyLength
1975 );
1976 }
1977
1978 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1979
Andres More52a7e642013-02-25 20:32:53 -05001980 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1981 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001982
1983 // DO Software Michael
1984 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001985 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001986 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001987 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001988 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1989 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001990
1991 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1992
1993 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1994
Andres More52a7e642013-02-25 20:32:53 -05001995 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1996 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001997
1998 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1999 MIC_vUnInit();
2000
Andres More4e9b5e22013-02-12 20:36:30 -05002001 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002002 *pdwMIC_L = 0;
2003 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002004 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002005 }
2006
2007 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2008 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002009 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2010 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002011
2012 }
2013
Malcolm Priestley3ba09382013-10-15 21:41:38 +01002014 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002015 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002016
2017 if (pDevice->bEnableHostWEP) {
2018 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2019 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2020 }
2021
2022 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002023 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002024 }
2025 }
2026
Andres More1cac4a42013-03-18 20:33:50 -05002027 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002028 pDevice->wSeqCounter++ ;
2029 if (pDevice->wSeqCounter > 0x0fff)
2030 pDevice->wSeqCounter = 0;
2031
Forest Bond92b96792009-06-13 07:38:31 -04002032 if (bIsPSPOLL) {
2033 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2034 // of FIFO control header.
2035 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2036 // in the same place of other packet's Duration-field).
2037 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002038 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002039 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2040 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00002041 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002042 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00002043 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002044 cpu_to_le16(p80211Header->sA2.wDurationID);
2045 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002046 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2047 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00002048 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002049 cpu_to_le16(p80211Header->sA2.wDurationID);
2050 }
Forest Bond92b96792009-06-13 07:38:31 -04002051 }
2052
Malcolm Priestleyca347592014-03-22 09:01:28 +00002053 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002054 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002055 pTX_Buffer->byType = 0x00;
2056
2057 pContext->pPacket = skb;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002058 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002059 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002060
Andres More1cac4a42013-03-18 20:33:50 -05002061 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002062 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2063 &pMACHeader->addr1[0], (u16)cbFrameSize,
2064 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002065 }
2066 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002067 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2068 &pMACHeader->addr3[0], (u16)cbFrameSize,
2069 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002070 }
2071 PIPEnsSendBulkOut(pDevice,pContext);
2072 return ;
2073
2074}
2075
Forest Bond92b96792009-06-13 07:38:31 -04002076//TYPE_AC0DMA data tx
2077/*
2078 * Description:
2079 * Tx packet via AC0DMA(DMA1)
2080 *
2081 * Parameters:
2082 * In:
2083 * pDevice - Pointer to the adapter
2084 * skb - Pointer to tx skb packet
2085 * Out:
2086 * void
2087 *
2088 * Return Value: NULL
2089 */
2090
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002091int nsDMA_tx_packet(struct vnt_private *pDevice,
2092 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002093{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002094 struct net_device_stats *pStats = &pDevice->stats;
2095 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002096 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002097 u32 BytesToWrite = 0, uHeaderLen = 0;
2098 u32 uNodeIndex = 0;
2099 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2100 u16 wAID;
2101 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002102 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002103 PSKeyItem pTransmitKey = NULL;
2104 SKeyItem STempKey;
2105 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002106 int bTKIP_UseGTK = false;
2107 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002108 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002109 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002110 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002111 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002112 u32 status;
2113 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002114 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002115
Forest Bond92b96792009-06-13 07:38:31 -04002116 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2117
2118 if (pDevice->uAssocCount == 0) {
2119 dev_kfree_skb_irq(skb);
2120 return 0;
2121 }
2122
Andres Moreb902fbf2013-02-25 20:32:51 -05002123 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002124 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002125 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002126 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2127
2128 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2129 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2130 // set tx map
2131 pMgmt->abyPSTxMap[0] |= byMask[0];
2132 return 0;
2133 }
Masanari Iida93184692012-08-13 21:21:50 +09002134 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002135
2136 if (pDevice->byBBType != BB_TYPE_11A)
2137 pDevice->wCurrentRate = RATE_2M;
2138 else
2139 pDevice->wCurrentRate = RATE_24M;
2140 // long preamble type
2141 pDevice->byPreambleType = PREAMBLE_SHORT;
2142
2143 }else {
2144
Andres Moreb902fbf2013-02-25 20:32:51 -05002145 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002146
2147 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2148
2149 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2150
2151 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2152 // set tx map
2153 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2154 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2155 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2156 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2157
2158 return 0;
2159 }
2160 // AP rate decided from node
2161 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2162 // tx preamble decided from node
2163
2164 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2165 pDevice->byPreambleType = pDevice->byShortPreamble;
2166
2167 }else {
2168 pDevice->byPreambleType = PREAMBLE_LONG;
2169 }
Andres More4e9b5e22013-02-12 20:36:30 -05002170 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002171 }
2172 }
2173
Andres Moree269fc22013-02-12 20:36:29 -05002174 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002175 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2176 dev_kfree_skb_irq(skb);
2177 return 0;
2178 }
2179 }
2180
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002181 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002182
2183 if (pContext == NULL) {
2184 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2185 dev_kfree_skb_irq(skb);
2186 return STATUS_RESOURCES;
2187 }
2188
Andres Moreceb8c5d2013-03-18 20:33:49 -05002189 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002190
2191//mike add:station mode check eapol-key challenge--->
2192{
Andres Moreb902fbf2013-02-25 20:32:51 -05002193 u8 Protocol_Version; //802.1x Authentication
2194 u8 Packet_Type; //802.1x Authentication
2195 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002196 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002197
Charles Clément21ec51f2010-05-18 10:08:14 -07002198 Protocol_Version = skb->data[ETH_HLEN];
2199 Packet_Type = skb->data[ETH_HLEN+1];
2200 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2201 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 -05002202 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002203 /* 802.1x OR eapol-key challenge frame transfer */
2204 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2205 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002206 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002207 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2208 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2209 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002210 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002211 PRINT_K("WPA ");
2212 }
2213 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002214 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002215 PRINT_K("WPA2(re-keying) ");
2216 }
2217 PRINT_K("Authentication completed!!\n");
2218 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002219 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002220 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002221 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002222 PRINT_K("WPA2 Authentication completed!!\n");
2223 }
2224 }
2225 }
2226}
2227//mike add:station mode check eapol-key challenge<---
2228
Andres More4e9b5e22013-02-12 20:36:30 -05002229 if (pDevice->bEncryptionEnable == true) {
2230 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002231 // get Transmit key
2232 do {
2233 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2234 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2235 pbyBSSID = pDevice->abyBSSID;
2236 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002237 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002238 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002239 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2240 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002241 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2242 break;
2243 }
2244 } else {
2245 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2246 break;
2247 }
2248 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002249 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2250 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002251 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2252 for (ii = 0; ii< 6; ii++)
2253 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2254 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2255
2256 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002257 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002258 break;
2259 }
2260 // get group key
2261 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002262 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002263 pTransmitKey = NULL;
2264 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2266 }
2267 else
2268 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2269 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002270 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002271 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2272 }
Andres Moree269fc22013-02-12 20:36:29 -05002273 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002274 }
2275
2276 if (pDevice->bEnableHostWEP) {
2277 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002278 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002279 pTransmitKey = &STempKey;
2280 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2281 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2282 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2283 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2284 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2285 memcpy(pTransmitKey->abyKey,
2286 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2287 pTransmitKey->uKeyLength
2288 );
2289 }
2290 }
2291
Andres Moreb902fbf2013-02-25 20:32:51 -05002292 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002293
2294 if (pDevice->bFixRate) {
2295 if (pDevice->byBBType == BB_TYPE_11B) {
2296 if (pDevice->uConnectionRate >= RATE_11M) {
2297 pDevice->wCurrentRate = RATE_11M;
2298 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002299 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002300 }
2301 } else {
2302 if ((pDevice->byBBType == BB_TYPE_11A) &&
2303 (pDevice->uConnectionRate <= RATE_6M)) {
2304 pDevice->wCurrentRate = RATE_6M;
2305 } else {
2306 if (pDevice->uConnectionRate >= RATE_54M)
2307 pDevice->wCurrentRate = RATE_54M;
2308 else
Andres More3eaca0d2013-02-25 20:32:52 -05002309 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002310 }
2311 }
2312 }
2313 else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00002314 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Forest Bond92b96792009-06-13 07:38:31 -04002315 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002316 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002317 // Multicast use highest data rate
2318 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2319 // preamble type
2320 pDevice->byPreambleType = pDevice->byShortPreamble;
2321 }
2322 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002323 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002324 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2325 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2326 pDevice->byPreambleType = pDevice->byShortPreamble;
2327
2328 }
2329 else {
2330 pDevice->byPreambleType = PREAMBLE_LONG;
2331 }
2332 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2333 }
2334 else {
2335 if (pDevice->byBBType != BB_TYPE_11A)
2336 pDevice->wCurrentRate = RATE_2M;
2337 else
2338 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2339 // abyCurrExtSuppRates[]
2340 pDevice->byPreambleType = PREAMBLE_SHORT;
2341 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2342 }
2343 }
2344 }
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00002345 if (pDevice->op_mode == NL80211_IFTYPE_STATION) {
Forest Bond92b96792009-06-13 07:38:31 -04002346 // Infra STA rate decided from AP Node, index = 0
2347 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2348 }
2349 }
2350
Andres Moreceb8c5d2013-03-18 20:33:49 -05002351 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002352 if (pDevice->byBBType != BB_TYPE_11A) {
2353 pDevice->wCurrentRate = RATE_1M;
2354 pDevice->byACKRate = RATE_1M;
2355 pDevice->byTopCCKBasicRate = RATE_1M;
2356 pDevice->byTopOFDMBasicRate = RATE_6M;
2357 } else {
2358 pDevice->wCurrentRate = RATE_6M;
2359 pDevice->byACKRate = RATE_6M;
2360 pDevice->byTopCCKBasicRate = RATE_1M;
2361 pDevice->byTopOFDMBasicRate = RATE_6M;
2362 }
2363 }
Forest Bond92b96792009-06-13 07:38:31 -04002364
Andres More0cbd8d92010-05-06 20:34:29 -03002365 DBG_PRT(MSG_LEVEL_DEBUG,
2366 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2367 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002368
2369 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002370 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002371 }
2372
2373 if (pDevice->wCurrentRate <= RATE_11M) {
2374 byPktType = PK_TYPE_11B;
2375 }
2376
Andres More4e9b5e22013-02-12 20:36:30 -05002377 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2379 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002380 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002382 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2383 if (pTransmitKey == NULL) {
2384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2385 }
2386 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002387 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2389 }
2390 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2392 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002393 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002394 }
2395 }
2396 }
2397
Forest Bond92b96792009-06-13 07:38:31 -04002398 if (pDevice->bEnableHostWEP) {
2399 if ((uNodeIndex != 0) &&
2400 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002401 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2402 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002403 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002404 }
2405 }
2406 }
2407 else {
2408
Forest Bond92b96792009-06-13 07:38:31 -04002409 if (pTransmitKey == NULL) {
2410 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002411 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002412 dev_kfree_skb_irq(skb);
2413 pStats->tx_dropped++;
2414 return STATUS_FAILURE;
2415 }
Forest Bond92b96792009-06-13 07:38:31 -04002416 }
2417 }
2418
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002419 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2420
Forest Bond92b96792009-06-13 07:38:31 -04002421 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002422 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002423 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002424 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002425 pDevice->wCurrentRate,
2426 &uHeaderLen, &BytesToWrite
2427 );
2428
Andres Moree269fc22013-02-12 20:36:29 -05002429 if (fConvertedPacket == false) {
2430 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002431 dev_kfree_skb_irq(skb);
2432 return STATUS_FAILURE;
2433 }
2434
Andres More4e9b5e22013-02-12 20:36:30 -05002435 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002436 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002437 bScheduleCommand((void *) pDevice,
2438 WLAN_CMD_MAC_DISPOWERSAVING,
2439 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002440 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002441 }
2442 }
2443
Andres Moreb902fbf2013-02-25 20:32:51 -05002444 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Malcolm Priestleyca347592014-03-22 09:01:28 +00002445 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite);
Forest Bond92b96792009-06-13 07:38:31 -04002446
2447 pContext->pPacket = skb;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002448 pContext->type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002449 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002450
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002451 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002452 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002453 (u16)(BytesToWrite-uHeaderLen),
2454 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002455
2456 status = PIPEnsSendBulkOut(pDevice,pContext);
2457
Andres More4e9b5e22013-02-12 20:36:30 -05002458 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002459 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002460
Andres Moreb902fbf2013-02-25 20:32:51 -05002461 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002462 }
2463
2464 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002465 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002466 dev_kfree_skb_irq(skb);
2467 return STATUS_FAILURE;
2468 }
2469 else
2470 return 0;
2471
2472}
2473
Forest Bond92b96792009-06-13 07:38:31 -04002474/*
2475 * Description:
2476 * Relay packet send (AC1DMA) from rx dpc.
2477 *
2478 * Parameters:
2479 * In:
2480 * pDevice - Pointer to the adapter
2481 * pPacket - Pointer to rx packet
2482 * cbPacketSize - rx ethernet frame size
2483 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002484 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002485 *
Andres More4e9b5e22013-02-12 20:36:30 -05002486 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002487 */
2488
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002489int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2490 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002491{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002492 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002493 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002494 u32 BytesToWrite = 0, uHeaderLen = 0;
2495 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002496 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002497 SKeyItem STempKey;
2498 PSKeyItem pTransmitKey = NULL;
2499 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002500 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002501 u8 byPktTyp;
2502 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002503 u32 status;
2504 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002505
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002506 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002507
2508 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002509 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002510 }
2511
Andres Moreceb8c5d2013-03-18 20:33:49 -05002512 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002513
Andres More4e9b5e22013-02-12 20:36:30 -05002514 if (pDevice->bEncryptionEnable == true) {
2515 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002516 // get group key
2517 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002518 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002519 pTransmitKey = NULL;
2520 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2521 } else {
2522 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2523 }
2524 }
2525
2526 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002527 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002528 pTransmitKey = &STempKey;
2529 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2530 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2531 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2532 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2533 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2534 memcpy(pTransmitKey->abyKey,
2535 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2536 pTransmitKey->uKeyLength
2537 );
2538 }
2539 }
2540
2541 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002542 pContext->bBoolInUse = false;
2543 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002544 }
2545
Andres Moreb902fbf2013-02-25 20:32:51 -05002546 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002547
2548 if (pDevice->bFixRate) {
2549 if (pDevice->byBBType == BB_TYPE_11B) {
2550 if (pDevice->uConnectionRate >= RATE_11M) {
2551 pDevice->wCurrentRate = RATE_11M;
2552 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002553 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002554 }
2555 } else {
2556 if ((pDevice->byBBType == BB_TYPE_11A) &&
2557 (pDevice->uConnectionRate <= RATE_6M)) {
2558 pDevice->wCurrentRate = RATE_6M;
2559 } else {
2560 if (pDevice->uConnectionRate >= RATE_54M)
2561 pDevice->wCurrentRate = RATE_54M;
2562 else
Andres More3eaca0d2013-02-25 20:32:52 -05002563 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002564 }
2565 }
2566 }
2567 else {
2568 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2569 }
2570
Forest Bond92b96792009-06-13 07:38:31 -04002571 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002572 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002573 }
2574
2575 if (pDevice->wCurrentRate <= RATE_11M)
2576 byPktType = PK_TYPE_11B;
2577
Andres Moreabad19d2010-07-12 16:28:32 -03002578 BytesToWrite = uDataLen + ETH_FCS_LEN;
2579
Forest Bond92b96792009-06-13 07:38:31 -04002580 // Convert the packet to an usb frame and copy into our buffer
2581 // and send the irp.
2582
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002583 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2584
Forest Bond92b96792009-06-13 07:38:31 -04002585 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002586 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002587 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2588 pbySkbData, pTransmitKey, uNodeIndex,
2589 pDevice->wCurrentRate,
2590 &uHeaderLen, &BytesToWrite
2591 );
2592
Andres Moree269fc22013-02-12 20:36:29 -05002593 if (fConvertedPacket == false) {
2594 pContext->bBoolInUse = false;
2595 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002596 }
2597
Andres Moreb902fbf2013-02-25 20:32:51 -05002598 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Malcolm Priestleyca347592014-03-22 09:01:28 +00002599 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite);
Forest Bond92b96792009-06-13 07:38:31 -04002600
2601 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002602 pContext->type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002603 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002604
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002605 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002606 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002607 (u16)(BytesToWrite - uHeaderLen),
2608 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002609
2610 status = PIPEnsSendBulkOut(pDevice,pContext);
2611
Andres More4e9b5e22013-02-12 20:36:30 -05002612 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002613}
2614