blob: fa048946d309946797451e33eec8c85ed1ba1be2 [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 "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070062
Mariano Reingart4a499de2010-10-29 19:15:26 -030063static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040064
Valentina Manea3b138852013-11-04 10:44:02 +020065static const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040066 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
67 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
68 };
69
Valentina Manea3b138852013-11-04 10:44:02 +020070static const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040071 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
72 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
73 };
Valentina Manea3b138852013-11-04 10:44:02 +020074static const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040075 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
76 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
77 };
78
Forest Bond92b96792009-06-13 07:38:31 -040079#define RTSDUR_BB 0
80#define RTSDUR_BA 1
81#define RTSDUR_AA 2
82#define CTSDUR_BA 3
83#define RTSDUR_BA_F0 4
84#define RTSDUR_AA_F0 5
85#define RTSDUR_BA_F1 6
86#define RTSDUR_AA_F1 7
87#define CTSDUR_BA_F0 8
88#define CTSDUR_BA_F1 9
89#define DATADUR_B 10
90#define DATADUR_A 11
91#define DATADUR_A_F0 12
92#define DATADUR_A_F1 13
93
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000094static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
95 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040096
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000097static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000098
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +010099static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100100 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100101 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100102 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000103
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000104static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500105 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100106 int bNeedEncrypt, u16 wFragType, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400107
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100108static void s_vFillTxKey(struct vnt_private *pDevice,
109 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
110 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100111 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400112
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000113static void s_vSWencryption(struct vnt_private *pDevice,
114 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400115
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000116static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
117 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400118
Malcolm Priestley20338012014-03-18 19:25:08 +0000119static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100120 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400121
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100122static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100123 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
124 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400125
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100126static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100127 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500128 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400129
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000130static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100131 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400132
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000133static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000134 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
135 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400136
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000137static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000138 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400139{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000140 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000141 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400142
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000143 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400144
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000145 for (ii = 0; ii < priv->cbTD; ii++) {
146 if (!priv->apTD[ii])
147 return NULL;
148
149 context = priv->apTD[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100150 if (context->in_use == false) {
151 context->in_use = true;
152 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000153 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
154 return context;
155 }
156 }
157
158 if (ii == priv->cbTD)
159 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000160
Malcolm Priestley5c851382013-11-26 19:12:38 +0000161 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400162}
163
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000164static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
165 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400166{
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000167 struct net_device_stats *stats = &pDevice->stats;
Malcolm Priestley51934e72013-12-09 22:30:14 +0000168 struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info;
Forest Bond92b96792009-06-13 07:38:31 -0400169
Malcolm Priestley51934e72013-12-09 22:30:14 +0000170 pkt_info[byPktNum].fifo_ctl = wFIFOCtl;
171 memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN);
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000172
173 stats->tx_bytes += wPktLength;
Forest Bond92b96792009-06-13 07:38:31 -0400174}
175
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100176static void s_vFillTxKey(struct vnt_private *pDevice,
177 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
178 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
179 struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400180{
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100181 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000182 __le32 *pdwIV = (__le32 *)pbyIVHead;
Malcolm Priestley2fbb2302014-03-22 09:01:25 +0000183 __le32 *pdwExtIV = (__le32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500184 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000185 __le32 rev_iv_counter;
Forest Bond92b96792009-06-13 07:38:31 -0400186
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100187 /* Fill TXKEY */
188 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100189 return;
Forest Bond92b96792009-06-13 07:38:31 -0400190
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000191 rev_iv_counter = cpu_to_le32(pDevice->dwIVCounter);
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000192 *pdwIV = cpu_to_le32(pDevice->dwIVCounter);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100193 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400194
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100195 switch (pTransmitKey->byCipherSuite) {
196 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100197 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000198 memcpy(pDevice->abyPRNG, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100199 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
200 pTransmitKey->uKeyLength);
201 } else {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000202 memcpy(pbyBuf, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100203 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
204 pTransmitKey->uKeyLength);
205 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000206 memcpy(pbyBuf+8, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley5cb5bff72014-05-25 21:36:28 +0100207 memcpy(pbyBuf+11, pTransmitKey->abyKey,
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100208 pTransmitKey->uKeyLength);
209 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100210
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100211 memcpy(pDevice->abyPRNG, pbyBuf, 16);
212 }
213 /* Append IV after Mac Header */
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000214 *pdwIV &= cpu_to_le32(WEP_IV_MASK);
215 *pdwIV |= cpu_to_le32((u32)pDevice->byKeyIndex << 30);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100216
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100217 pDevice->dwIVCounter++;
218 if (pDevice->dwIVCounter > WEP_IV_MASK)
219 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100220
221 break;
222 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100223 pTransmitKey->wTSC15_0++;
224 if (pTransmitKey->wTSC15_0 == 0)
225 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100226
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100227 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
228 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
229 pDevice->abyPRNG);
230 memcpy(pbyBuf, pDevice->abyPRNG, 16);
231
232 /* Make IV */
233 memcpy(pdwIV, pDevice->abyPRNG, 3);
234
235 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
236 0xc0) | 0x20);
237 /* Append IV&ExtIV after Mac Header */
238 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
239
240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
241 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
242
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100243 break;
244 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100245 pTransmitKey->wTSC15_0++;
246 if (pTransmitKey->wTSC15_0 == 0)
247 pTransmitKey->dwTSC47_16++;
248
249 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
250
251 /* Make IV */
252 *pdwIV = 0;
253 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
254 0xc0) | 0x20);
255
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000256 *pdwIV |= cpu_to_le32((u32)(pTransmitKey->wTSC15_0));
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100257
258 /* Append IV&ExtIV after Mac Header */
259 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
260
261 if (!mic_hdr)
262 return;
263
264 /* MICHDR0 */
265 mic_hdr->id = 0x59;
266 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
267 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
268
269 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
270 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
271
272 /* MICHDR1 */
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000273 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100274 mic_hdr->hlen = cpu_to_be16(28);
275 else
276 mic_hdr->hlen = cpu_to_be16(22);
277
278 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
279 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
280
281 /* MICHDR2 */
282 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
Malcolm Priestley5d4fe752014-03-22 09:01:26 +0000283 mic_hdr->frame_control = cpu_to_le16(
284 le16_to_cpu(pMACHeader->frame_control) & 0xc78f);
285 mic_hdr->seq_ctrl = cpu_to_le16(
286 le16_to_cpu(pMACHeader->seq_ctrl) & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100287
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000288 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100289 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
290 }
Forest Bond92b96792009-06-13 07:38:31 -0400291}
292
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000293static void s_vSWencryption(struct vnt_private *pDevice,
294 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400295{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000296 u32 cbICVlen = 4;
297 u32 dwICV = 0xffffffff;
298 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400299
300 if (pTransmitKey == NULL)
301 return;
302
303 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
304 //=======================================================================
305 // Append ICV after payload
Malcolm Priestley929cb312014-05-21 21:09:42 +0100306 dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead);
Andres More52a7e642013-02-25 20:32:53 -0500307 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400308 // finally, we must invert dwCRC to get the correct answer
309 *pdwICV = cpu_to_le32(~dwICV);
310 // RC4 encryption
311 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
312 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
313 //=======================================================================
314 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
315 //=======================================================================
316 //Append ICV after payload
Malcolm Priestley929cb312014-05-21 21:09:42 +0100317 dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead);
Andres More52a7e642013-02-25 20:32:53 -0500318 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400319 // finally, we must invert dwCRC to get the correct answer
320 *pdwICV = cpu_to_le32(~dwICV);
321 // RC4 encryption
322 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
323 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
324 //=======================================================================
325 }
326}
327
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000328static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100329{
330 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
331 [rate % MAX_RATE]);
332}
333
Forest Bond92b96792009-06-13 07:38:31 -0400334/*byPktType : PK_TYPE_11A 0
335 PK_TYPE_11B 1
336 PK_TYPE_11GB 2
337 PK_TYPE_11GA 3
338*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000339static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
340 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400341{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000342 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400343
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000344 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
345 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400346
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000347 if (pkt_type == PK_TYPE_11B)
348 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
349 (u16)priv->byTopCCKBasicRate);
350 else
351 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
352 (u16)priv->byTopOFDMBasicRate);
353
354 if (need_ack)
355 return data_time + priv->uSIFS + ack_time;
356
357 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400358}
359
Malcolm Priestley2075f652014-03-18 19:25:07 +0000360static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100361 u32 frame_length, u16 rate, int need_ack)
362{
363 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
364 frame_length, rate, need_ack));
365}
366
Forest Bond92b96792009-06-13 07:38:31 -0400367//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000368static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100369 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400370{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000371 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400372
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000373 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400374
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000375 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100376 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400377
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000378 if (rsv_type == 0) {
379 rts_time = BBuGetFrameTime(priv->byPreambleType,
380 pkt_type, 20, priv->byTopCCKBasicRate);
381 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
382 pkt_type, 14, priv->byTopCCKBasicRate);
383 } else if (rsv_type == 1) {
384 rts_time = BBuGetFrameTime(priv->byPreambleType,
385 pkt_type, 20, priv->byTopCCKBasicRate);
386 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
387 14, priv->byTopCCKBasicRate);
388 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
389 14, priv->byTopOFDMBasicRate);
390 } else if (rsv_type == 2) {
391 rts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
392 20, priv->byTopOFDMBasicRate);
393 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
394 pkt_type, 14, priv->byTopOFDMBasicRate);
395 } else if (rsv_type == 3) {
396 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
397 14, priv->byTopCCKBasicRate);
398 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
399 14, priv->byTopOFDMBasicRate);
400
401 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
402
Malcolm Priestley20338012014-03-18 19:25:08 +0000403 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000404 }
405
406 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
407
408 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400409}
410
411//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000412static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100413 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400414{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100415 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400416
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100417 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100418 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100419 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
420 byPktType, 14, pDevice->byTopCCKBasicRate);
421 else
422 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
423 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100424 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100425 }
Forest Bond92b96792009-06-13 07:38:31 -0400426
Forest Bond92b96792009-06-13 07:38:31 -0400427 return 0;
428}
429
Forest Bond92b96792009-06-13 07:38:31 -0400430//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000431static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000432 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
433 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400434{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000435 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400436
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100437 switch (byDurType) {
438 case RTSDUR_BB:
439 case RTSDUR_BA:
440 case RTSDUR_BA_F0:
441 case RTSDUR_BA_F1:
442 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
443 14, pDevice->byTopCCKBasicRate);
444 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
445 s_uGetTxRsvTime(pDevice, byPktType,
446 cbFrameLength, wRate, bNeedAck);
447 break;
Forest Bond92b96792009-06-13 07:38:31 -0400448
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100449 case RTSDUR_AA:
450 case RTSDUR_AA_F0:
451 case RTSDUR_AA_F1:
452 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
453 14, pDevice->byTopOFDMBasicRate);
454 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
455 s_uGetTxRsvTime(pDevice, byPktType,
456 cbFrameLength, wRate, bNeedAck);
457 break;
Forest Bond92b96792009-06-13 07:38:31 -0400458
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100459 case CTSDUR_BA:
460 case CTSDUR_BA_F0:
461 case CTSDUR_BA_F1:
462 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100463 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100464 break;
Forest Bond92b96792009-06-13 07:38:31 -0400465
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100466 default:
467 break;
468 }
Forest Bond92b96792009-06-13 07:38:31 -0400469
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100470 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400471}
472
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100473static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
474 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
475 u32 frame_len, int need_ack)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100476{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100477
478 struct vnt_private *priv = tx_context->priv;
479
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100480 /* Get SignalField,ServiceField,Length */
481 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
482 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
483 PK_TYPE_11B, &buf->b);
484
485 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000486 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
487 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100488
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000489 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
490 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100491 priv->byTopCCKBasicRate);
492
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000493 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100494}
495
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100496static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
497 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100498 u32 frame_len, int need_ack)
499{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100500 struct vnt_private *priv = tx_context->priv;
501
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100502 /* Get SignalField,ServiceField,Length */
503 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
504
505 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
506 PK_TYPE_11B, &buf->b);
507
508 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000509 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
510 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100511
Malcolm Priestley4e011172014-03-18 19:24:55 +0000512 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
513 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100514
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000515 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
516 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100517 priv->byTopCCKBasicRate);
518
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000519 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100520}
521
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100522static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
523 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100524 u32 frame_len, int need_ack)
525{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100526 struct vnt_private *priv = tx_context->priv;
527
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100528 /* Get SignalField,ServiceField,Length */
529 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
530 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000531 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100532
Malcolm Priestley4e011172014-03-18 19:24:55 +0000533 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
534 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100535
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000536 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100537
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000538 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100539}
540
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100541static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
542 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100543 u32 frame_len, int need_ack)
544{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100545 struct vnt_private *priv = tx_context->priv;
546
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100547 /* Get SignalField,ServiceField,Length */
548 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
549 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000550 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100551
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000552 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100553
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000554 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100555}
556
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100557static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
558 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000559 __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100560{
561 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000562 rts->frame_control =
563 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100564
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000565 if (priv->op_mode == NL80211_IFTYPE_ADHOC ||
566 priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100567 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
568 else
569 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
570
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000571 if (priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100572 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
573 else
574 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
575
576 return 0;
577}
578
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100579static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100580 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
581 u8 pkt_type, u32 frame_len, int need_ack,
582 u16 current_rate, u8 fb_option)
583{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100584 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100585 u16 rts_frame_len = 20;
586
587 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
588 PK_TYPE_11B, &buf->b);
589 BBvCalculateParameter(priv, rts_frame_len,
590 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
591
Malcolm Priestley4e011172014-03-18 19:24:55 +0000592 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100593 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000594 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100595 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000596 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100597 pkt_type, current_rate, need_ack, fb_option);
598
Malcolm Priestley4e011172014-03-18 19:24:55 +0000599 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100600
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100601 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100602 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100603}
604
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100605static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100606 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
607 u8 pkt_type, u32 frame_len, int need_ack,
608 u16 current_rate, u8 fb_option)
609{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100610 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100611 u16 rts_frame_len = 20;
612
613 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
614 PK_TYPE_11B, &buf->b);
615 BBvCalculateParameter(priv, rts_frame_len,
616 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
617
618
Malcolm Priestley4e011172014-03-18 19:24:55 +0000619 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100620 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000621 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100622 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000623 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100624 pkt_type, current_rate, need_ack, fb_option);
625
626
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000627 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100628 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000629 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100630 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000631 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100632 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000633 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100634 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100635
Malcolm Priestley4e011172014-03-18 19:24:55 +0000636 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100637
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100638 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100639 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100640}
641
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100642static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley17126332013-08-26 11:09:38 +0100643 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
644 u8 pkt_type, u32 frame_len, int need_ack,
645 u16 current_rate, u8 fb_option)
646{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100647 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley17126332013-08-26 11:09:38 +0100648 u16 rts_frame_len = 20;
649
650 BBvCalculateParameter(priv, rts_frame_len,
651 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
652
Malcolm Priestley4e011172014-03-18 19:24:55 +0000653 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100654 pkt_type, current_rate, need_ack, fb_option);
655
Malcolm Priestley4e011172014-03-18 19:24:55 +0000656 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100657
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100658 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100659 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100660}
661
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100662static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100663 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
664 u8 pkt_type, u32 frame_len, int need_ack,
665 u16 current_rate, u8 fb_option)
666{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100667 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100668 u16 rts_frame_len = 20;
669
670 BBvCalculateParameter(priv, rts_frame_len,
671 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
672
Malcolm Priestley4e011172014-03-18 19:24:55 +0000673 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100674 pkt_type, current_rate, need_ack, fb_option);
675
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000676 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100677 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100678
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000679 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100680 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100681
Malcolm Priestley4e011172014-03-18 19:24:55 +0000682 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100683
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100684 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100685 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100686}
687
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100688static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100689 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500690 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400691{
Forest Bond92b96792009-06-13 07:38:31 -0400692
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100693 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100694 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400695
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100696 /* Note: So far RTSHead doesn't appear in ATIM
697 * & Beacom DMA, so we don't need to take them
698 * into account.
699 * Otherwise, we need to modified codes for them.
700 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100701 switch (byPktType) {
702 case PK_TYPE_11GB:
703 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100704 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100705 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100706 psEthHeader, byPktType, cbFrameLength,
707 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100708 else
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100709 return vnt_rxtx_rts_g_fb_head(tx_context,
710 &head->rts_g_fb, psEthHeader, byPktType,
711 cbFrameLength, bNeedAck, wCurrentRate,
712 byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100713 break;
714 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100715 if (byFBOption) {
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100716 return vnt_rxtx_rts_a_fb_head(tx_context,
717 &head->rts_a_fb, psEthHeader, byPktType,
718 cbFrameLength, bNeedAck, wCurrentRate,
719 byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100720 break;
721 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100722 case PK_TYPE_11B:
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100723 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100724 psEthHeader, byPktType, cbFrameLength,
725 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100726 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100727
728 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400729}
730
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100731static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100732 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
733 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400734{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100735 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000736 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400737
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100738 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100739 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400740
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100741 if (byFBOption != AUTO_FB_NONE) {
742 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100743 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100744 /* Get SignalField,ServiceField,Length */
745 BBvCalculateParameter(pDevice, uCTSFrameLen,
746 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000747 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100748 cbFrameLength, byPktType,
749 wCurrentRate, bNeedAck, byFBOption);
750 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000751 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100752 CTSDUR_BA_F0, cbFrameLength, byPktType,
753 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100754 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000755 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100756 CTSDUR_BA_F1, cbFrameLength, byPktType,
757 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100758 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000759 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000760 pBuf->data.frame_control =
761 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
762
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100763 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100764
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100765 return vnt_rxtx_datahead_g_fb(tx_context, byPktType,
766 wCurrentRate, &pBuf->data_head, cbFrameLength,
767 bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100768 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100769 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100770 /* Get SignalField,ServiceField,Length */
771 BBvCalculateParameter(pDevice, uCTSFrameLen,
772 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100773 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000774 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100775 CTSDUR_BA, cbFrameLength, byPktType,
776 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100777 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000778 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000779 pBuf->data.frame_control =
780 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
781
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100782 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100783
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100784 return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100785 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400786 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100787
788 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400789}
790
Forest Bond92b96792009-06-13 07:38:31 -0400791/*+
792 *
793 * Description:
794 * Generate FIFO control for MAC & Baseband controller
795 *
796 * Parameters:
797 * In:
798 * pDevice - Pointer to adpater
799 * pTxDataHead - Transmit Data Buffer
800 * pTxBufHead - pTxBufHead
801 * pvRrvTime - pvRrvTime
802 * pvRTS - RTS Buffer
803 * pCTS - CTS Buffer
804 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
805 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400806 * Out:
807 * none
808 *
809 * Return Value: none
810 *
811-*/
Andres Morecc856e62010-05-17 21:34:01 -0300812
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100813static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100814 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100815 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100816 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400817{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100818 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100819 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100820 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000821 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000822 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400823
Malcolm Priestley03a9cf32014-03-22 09:01:30 +0000824 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100825 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400826
Malcolm Priestley92928f12013-10-07 20:14:01 +0100827 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
828 byFBOption = AUTO_FB_0;
829 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
830 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400831
Malcolm Priestley92928f12013-10-07 20:14:01 +0100832 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
833 if (need_rts) {
834 struct vnt_rrv_time_rts *pBuf =
835 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100836
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000837 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100838 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000839 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100840 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000841 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100842 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100843
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000844 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100845 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000846 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100847 PK_TYPE_11B, cbFrameSize,
848 pDevice->byTopCCKBasicRate, bNeedACK);
849
850 if (need_mic) {
851 *mic_hdr = &tx_buffer->
852 tx_head.tx_rts.tx.mic.hdr;
853 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
854 } else {
855 head = &tx_buffer->tx_head.tx_rts.tx.head;
856 }
857
858 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100859 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100860 cbFrameSize, bNeedACK, psEthHeader,
861 wCurrentRate, byFBOption);
862
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100863 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100864 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
865 tx_head.tx_cts.cts;
866
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000867 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100868 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000869 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100870 PK_TYPE_11B, cbFrameSize,
871 pDevice->byTopCCKBasicRate, bNeedACK);
872
Malcolm Priestley372108e2014-03-18 19:25:00 +0000873 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100874 byPktType, cbFrameSize, wCurrentRate);
875
876 if (need_mic) {
877 *mic_hdr = &tx_buffer->
878 tx_head.tx_cts.tx.mic.hdr;
879 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
880 } else {
881 head = &tx_buffer->tx_head.tx_cts.tx.head;
882 }
883
884 /* Fill CTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100885 return s_vFillCTSHead(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100886 head, cbFrameSize, bNeedACK, wCurrentRate,
887 byFBOption);
888 }
889 } else if (byPktType == PK_TYPE_11A) {
890 if (need_mic) {
891 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
892 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
893 } else {
894 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100895 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100896
Malcolm Priestley92928f12013-10-07 20:14:01 +0100897 if (need_rts) {
898 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
899 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100900
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000901 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100902 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100903
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000904 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100905 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
906
907 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100908 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100909 cbFrameSize, bNeedACK, psEthHeader,
910 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100911 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100912 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
913 tx_head.tx_ab.ab;
914
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000915 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100916 PK_TYPE_11A, cbFrameSize,
917 wCurrentRate, bNeedACK);
918
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100919 return vnt_rxtx_datahead_a_fb(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100920 wCurrentRate, &head->data_head_a_fb,
921 cbFrameSize, bNeedACK);
922 }
923 } else if (byPktType == PK_TYPE_11B) {
924 if (need_mic) {
925 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
926 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
927 } else {
928 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100929 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100930
Malcolm Priestley92928f12013-10-07 20:14:01 +0100931 if (need_rts) {
932 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
933 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100934
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000935 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100936 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100937
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000938 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100939 PK_TYPE_11B, cbFrameSize, wCurrentRate,
940 bNeedACK);
941
942 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100943 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100944 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100945 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100946 } else {
947 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
948 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100949
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000950 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100951 PK_TYPE_11B, cbFrameSize,
952 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100953
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100954 return vnt_rxtx_datahead_ab(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100955 wCurrentRate, &head->data_head_ab,
956 cbFrameSize, bNeedACK);
957 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100958 }
959
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100960 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400961}
962/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500963 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500964 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300965 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400966*/
967
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100968static int s_bPacketToWirelessUsb(struct vnt_usb_send_context *tx_context,
969 u8 byPktType, struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100970 u32 uSkbPacketLen, struct ethhdr *psEthHeader,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100971 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
972 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400973{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100974 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100975 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000976 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000977 u32 cb802_1_H_len;
978 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
979 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100980 int bNeedACK;
981 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000982 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
983 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
984 u8 abySNAP_Bridgetunnel[ETH_ALEN]
985 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
986 u32 uDuration;
987 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100988 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000989 u8 byFBOption = AUTO_FB_NONE, byFragType;
990 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100991 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000992 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500993 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100994
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100995 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400996
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000997 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500998 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
999 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001000 }
Forest Bond92b96792009-06-13 07:38:31 -04001001
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001002 /* Get pkt type */
1003 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
1004 cb802_1_H_len = 8;
1005 else
1006 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001007
Charles Clément21ec51f2010-05-18 10:08:14 -07001008 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001009
1010 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001011 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001012
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001013 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC ||
1014 pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001015 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001016 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001017 pTxBufHead->wFIFOCtl =
1018 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1019 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001020 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001021 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1022 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001023 } else {
1024 /* MSDUs in Infra mode always need ACK */
1025 bNeedACK = true;
1026 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1027 }
Forest Bond92b96792009-06-13 07:38:31 -04001028
Malcolm Priestley58462512014-03-22 09:01:27 +00001029 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001030
Forest Bond92b96792009-06-13 07:38:31 -04001031 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001032 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1033
Andres More3eaca0d2013-02-25 20:32:52 -05001034 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001035
1036 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001037 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001038 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1039 }
1040
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001041 /* Set Auto Fallback Ctl */
1042 if (wCurrentRate >= RATE_18M) {
1043 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1044 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1045
1046 pDevice->tx_rate_fb0 =
1047 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1048 pDevice->tx_rate_fb1 =
1049 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1050
1051 byFBOption = AUTO_FB_0;
1052 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1053 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1054 pDevice->tx_rate_fb0 =
1055 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1056 pDevice->tx_rate_fb1 =
1057 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1058
1059 byFBOption = AUTO_FB_1;
1060 }
1061 }
Forest Bond92b96792009-06-13 07:38:31 -04001062
Andres More4e9b5e22013-02-12 20:36:30 -05001063 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001064 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1065 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1066 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1067 }
1068 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1069 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1070 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1071 }
1072 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1073 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1074 }
1075 }
1076 }
1077
Forest Bond92b96792009-06-13 07:38:31 -04001078 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1079 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1080 cbIVlen = 4;
1081 cbICVlen = 4;
1082 }
1083 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1084 cbIVlen = 8;//IV+ExtIV
1085 cbMIClen = 8;
1086 cbICVlen = 4;
1087 }
1088 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1089 cbIVlen = 8;//RSN Header
1090 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001091 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001092 }
Andres Moree269fc22013-02-12 20:36:29 -05001093 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001094 //MAC Header should be padding 0 to DW alignment.
1095 uPadding = 4 - (cbMACHdLen%4);
1096 uPadding %= 4;
1097 }
1098 }
1099
1100 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1101
Andres Moree269fc22013-02-12 20:36:29 -05001102 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1103 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001104 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001105 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001106 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1107 }
1108
Andres Moreb902fbf2013-02-25 20:32:51 -05001109 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001110 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1111
Forest Bond92b96792009-06-13 07:38:31 -04001112 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1113 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001114 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001115 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001116 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001117 }
1118 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001119 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001120 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001121 }
1122 } else {
1123 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001124 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001125 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001126 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001127 }
Andres Moree269fc22013-02-12 20:36:29 -05001128 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001129 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001130 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001131 }
1132 } // Auto Fall Back
1133 }
1134 else {//802.11a/b packet
1135 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001136 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001137 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001138 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001139 }
Andres Moree269fc22013-02-12 20:36:29 -05001140 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001141 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001142 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001143 }
1144 } else {
1145 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001146 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001147 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001148 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001149 }
Andres Moree269fc22013-02-12 20:36:29 -05001150 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001151 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001152 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001153 }
1154 } // Auto Fall Back
1155 }
1156
Andres Moreb902fbf2013-02-25 20:32:51 -05001157 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1158 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1159 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001160
Forest Bond92b96792009-06-13 07:38:31 -04001161 //=========================
1162 // No Fragmentation
1163 //=========================
1164 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1165 byFragType = FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001166 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1167
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001168 /* Fill FIFO, RrvTime, RTS and CTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01001169 uDuration = s_vGenerateTxParameter(tx_context, byPktType, wCurrentRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001170 tx_buffer, &pMICHDR, cbMICHDR,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001171 cbFrameSize, bNeedACK, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001172
Forest Bond92b96792009-06-13 07:38:31 -04001173 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001174 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001175 byFragType, 0);
Forest Bond92b96792009-06-13 07:38:31 -04001176
Andres More4e9b5e22013-02-12 20:36:30 -05001177 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001178 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001179 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001180 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001181 }
1182
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001183 /* 802.1H */
1184 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001185 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001186 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001187 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001188 abySNAP_Bridgetunnel, 6);
1189 else
1190 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001191
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001192 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001193
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001194 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1195 }
Forest Bond92b96792009-06-13 07:38:31 -04001196
Forest Bond92b96792009-06-13 07:38:31 -04001197 if (pPacket != NULL) {
1198 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001199 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001200 (pPacket + ETH_HLEN),
1201 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001202 );
1203
1204 } else {
1205 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001206 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001207 }
1208
Andres More4e9b5e22013-02-12 20:36:30 -05001209 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001210
1211 ///////////////////////////////////////////////////////////////////
1212
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001213 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1214 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1215 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1216 }
Forest Bond92b96792009-06-13 07:38:31 -04001217 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001218 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1219 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001220 }
1221 else {
Andres More52a7e642013-02-25 20:32:53 -05001222 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1223 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001224 }
1225 // DO Software Michael
1226 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001227 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001228 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001229 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001230 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1231 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001232
1233 ///////////////////////////////////////////////////////////////////
1234
1235 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1236 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001237 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001238 //}
1239 //DBG_PRN_GRP12(("\n\n\n"));
1240
1241 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1242
Andres More52a7e642013-02-25 20:32:53 -05001243 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1244 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001245
1246 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1247 MIC_vUnInit();
1248
Andres More4e9b5e22013-02-12 20:36:30 -05001249 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001250 *pdwMIC_L = 0;
1251 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001252 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001253 }
1254 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1255 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1256 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1257 }
1258
Andres More4e9b5e22013-02-12 20:36:30 -05001259 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001260
Andres More3eaca0d2013-02-25 20:32:52 -05001261 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001262
Andres More4e9b5e22013-02-12 20:36:30 -05001263 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1264 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1265 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001266 cbFrameSize -= cbICVlen;
1267 }
1268
Forest Bond92b96792009-06-13 07:38:31 -04001269 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001270
1271 *pcbHeaderLen = cbHeaderLength;
1272 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1273
Forest Bond92b96792009-06-13 07:38:31 -04001274 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001275 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001276
Andres More4e9b5e22013-02-12 20:36:30 -05001277 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001278
1279}
1280
Forest Bond92b96792009-06-13 07:38:31 -04001281/*+
1282 *
1283 * Description:
1284 * Translate 802.3 to 802.11 header
1285 *
1286 * Parameters:
1287 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001288 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001289 * dwTxBufferAddr - Transmit Buffer
1290 * pPacket - Packet from upper layer
1291 * cbPacketSize - Transmit Data Length
1292 * Out:
1293 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1294 * pcbAppendPayload - size of append payload for 802.1H translation
1295 *
1296 * Return Value: none
1297 *
1298-*/
1299
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001300static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001301 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001302 int bNeedEncrypt, u16 wFragType, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001303{
Andres More1cac4a42013-03-18 20:33:50 -05001304 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001305
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001306 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001307
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001308 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001309 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001310 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001311 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001312 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1313 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001314 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001315 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001316 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001317 } else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001318 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001319 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001320 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001321 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001322 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001323 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001324 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001325 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001326 &(pDevice->abyBSSID[0]),
1327 ETH_ALEN);
1328 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001329 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001330 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001331 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001332 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001333 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001334 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001335 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001336 &(pDevice->abyBSSID[0]),
1337 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001338 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001339 }
1340 }
1341
1342 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001343 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001344
Andres More1cac4a42013-03-18 20:33:50 -05001345 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001346
Andres More1cac4a42013-03-18 20:33:50 -05001347 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001348
1349 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001350 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001351
1352 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1353 pDevice->wSeqCounter++;
1354 if (pDevice->wSeqCounter > 0x0fff)
1355 pDevice->wSeqCounter = 0;
1356 }
1357
1358 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001359 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001360 }
1361}
1362
Forest Bond92b96792009-06-13 07:38:31 -04001363/*+
1364 *
1365 * Description:
1366 * Request instructs a MAC to transmit a 802.11 management packet through
1367 * the adapter onto the medium.
1368 *
1369 * Parameters:
1370 * In:
1371 * hDeviceContext - Pointer to the adapter
1372 * pPacket - A pointer to a descriptor for the packet to transmit
1373 * Out:
1374 * none
1375 *
Andres Moree269fc22013-02-12 20:36:29 -05001376 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001377 *
1378-*/
1379
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001380CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1381 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001382{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001383 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001384 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001385 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001386 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001387 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001388 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001389 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001390 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001391 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001392 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001393 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1394 u32 uPadding = 0;
1395 u16 wTxBufSize;
1396 u32 cbMacHdLen;
1397 u16 wCurrentRate = RATE_1M;
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001398 unsigned long flags;
1399
1400 if (pDevice->byBBType == BB_TYPE_11A) {
1401 wCurrentRate = RATE_6M;
1402 byPktType = PK_TYPE_11A;
1403 } else {
1404 wCurrentRate = RATE_1M;
1405 byPktType = PK_TYPE_11B;
1406 }
1407
1408 if (pMgmt->eScanState != WMAC_NO_SCANNING)
Malcolm Priestley4f5290e2014-05-27 21:05:21 +01001409 vnt_rf_setpower(pDevice, wCurrentRate, pDevice->byCurrentCh);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001410 else
Malcolm Priestley4f5290e2014-05-27 21:05:21 +01001411 vnt_rf_setpower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001412
1413 pDevice->wCurrentRate = wCurrentRate;
1414
1415 spin_lock_irqsave(&pDevice->lock, flags);
Forest Bond92b96792009-06-13 07:38:31 -04001416
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001417 pContext = s_vGetFreeContext(pDevice);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001418 if (!pContext) {
1419 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1420 "ManagementSend TX...NO CONTEXT!\n");
1421 spin_unlock_irqrestore(&pDevice->lock, flags);
1422 return CMD_STATUS_RESOURCES;
1423 }
Forest Bond92b96792009-06-13 07:38:31 -04001424
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001425 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001426 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001427 pTxBufHead = &pTX_Buffer->fifo_head;
1428 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1429 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001430
Forest Bond92b96792009-06-13 07:38:31 -04001431
Forest Bond92b96792009-06-13 07:38:31 -04001432 //Set packet type
1433 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1434 pTxBufHead->wFIFOCtl = 0;
1435 }
1436 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1437 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1438 }
1439 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1440 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1441 }
1442 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1443 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1444 }
1445
1446 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
Malcolm Priestley58462512014-03-22 09:01:27 +00001447 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001448
Andres More22040bb2010-08-02 20:21:44 -03001449 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001450 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001451 }
1452 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001453 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001454 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1455 };
1456
1457 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1458 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1459
1460 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1461 //Set Preamble type always long
1462 //pDevice->byPreambleType = PREAMBLE_LONG;
1463 // probe-response don't retry
1464 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001465 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001466 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1467 //}
1468 }
1469
1470 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1471
1472 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001473 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001474 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1475 } else {
1476 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1477 }
1478
1479 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001480 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001481
1482 // Notes:
1483 // Although spec says MMPDU can be fragmented; In most case,
1484 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001485
1486 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1487 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1488 cbIVlen = 4;
1489 cbICVlen = 4;
1490 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1491 }
1492 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1493 cbIVlen = 8;//IV+ExtIV
1494 cbMIClen = 8;
1495 cbICVlen = 4;
1496 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1497 //We need to get seed here for filling TxKey entry.
1498 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1499 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1500 }
1501 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1502 cbIVlen = 8;//RSN Header
1503 cbICVlen = 8;//MIC
1504 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001505 }
1506 //MAC Header should be padding 0 to DW alignment.
1507 uPadding = 4 - (cbMacHdLen%4);
1508 uPadding %= 4;
1509 }
1510
1511 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1512
1513 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001514 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001515 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1516 }
1517 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1518
1519 //Set RrvTime/RTS/CTS Buffer
1520 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001521 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001522 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001523 }
1524 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001525 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001526 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001527 }
1528
Andres Moreceb8c5d2013-03-18 20:33:49 -05001529 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001530 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1531 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001532 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001533 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1534 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001535 //=========================
1536 // No Fragmentation
1537 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001538 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001539
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001540 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01001541 uDuration = s_vGenerateTxParameter(pContext, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001542 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001543 cbFrameSize, bNeedACK, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001544
Andres More1cac4a42013-03-18 20:33:50 -05001545 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001546
1547 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1548
1549 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001550 u8 * pbyIVHead;
1551 u8 * pbyPayloadHead;
1552 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001553 PSKeyItem pTransmitKey = NULL;
1554
Andres Moreb902fbf2013-02-25 20:32:51 -05001555 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1556 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001557 do {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001558 if (pDevice->op_mode == NL80211_IFTYPE_STATION &&
1559 pDevice->bLinkPass == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001560 pbyBSSID = pDevice->abyBSSID;
1561 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001562 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001563 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001564 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001565 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1566 break;
1567 }
1568 } else {
1569 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1570 break;
1571 }
1572 }
1573 // get group key
1574 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001575 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001576 pTransmitKey = NULL;
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001577 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode);
Forest Bond92b96792009-06-13 07:38:31 -04001578 } else {
1579 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1580 }
Andres Moree269fc22013-02-12 20:36:29 -05001581 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001582 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001583 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001584 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001585
Jim Lieb3e362592009-08-12 14:54:11 -07001586 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001587 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001588 cbFrameBodySize);
1589 }
1590 else {
1591 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001592 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001593 }
1594
Andres More1cac4a42013-03-18 20:33:50 -05001595 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001596 pDevice->wSeqCounter++ ;
1597 if (pDevice->wSeqCounter > 0x0fff)
1598 pDevice->wSeqCounter = 0;
1599
1600 if (bIsPSPOLL) {
1601 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001602 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001603 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1604 // in the same place of other packet's Duration-field).
1605 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001606 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001607 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1608 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001609 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001610 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00001611 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001612 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1613 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001614 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1615 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001616 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001617 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1618 }
Forest Bond92b96792009-06-13 07:38:31 -04001619 }
1620
Malcolm Priestleyca347592014-03-22 09:01:28 +00001621 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001622 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001623 pTX_Buffer->byType = 0x00;
1624
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001625 pContext->skb = NULL;
1626 pContext->type = CONTEXT_MGMT_PACKET;
1627 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04001628
Andres More1cac4a42013-03-18 20:33:50 -05001629 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001630 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1631 &pMACHeader->addr1[0], (u16)cbFrameSize,
1632 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001633 }
1634 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001635 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1636 &pMACHeader->addr3[0], (u16)cbFrameSize,
1637 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001638 }
1639
1640 PIPEnsSendBulkOut(pDevice,pContext);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001641
1642 spin_unlock_irqrestore(&pDevice->lock, flags);
1643
Forest Bond92b96792009-06-13 07:38:31 -04001644 return CMD_STATUS_PENDING;
1645}
1646
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001647CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1648 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001649{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001650 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001651 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001652 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1653 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001654 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001655 u16 wCurrentRate;
1656 u32 cbFrameBodySize;
1657 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001658 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001659 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001660
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001661 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001662 if (NULL == pContext) {
1663 status = CMD_STATUS_RESOURCES;
1664 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1665 return status ;
1666 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001667
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001668 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001669 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001670
1671 cbFrameBodySize = pPacket->cbPayloadLen;
1672
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001673 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001674
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001675 if (pDevice->byBBType == BB_TYPE_11A) {
1676 wCurrentRate = RATE_6M;
1677
1678 /* Get SignalField,ServiceField,Length */
1679 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1680 PK_TYPE_11A, &short_head->ab);
1681
1682 /* Get Duration and TimeStampOff */
1683 short_head->duration = s_uGetDataDuration(pDevice,
1684 PK_TYPE_11A, false);
1685 short_head->time_stamp_off =
1686 vnt_time_stamp_off(pDevice, wCurrentRate);
1687 } else {
1688 wCurrentRate = RATE_1M;
1689 short_head->fifo_ctl |= FIFOCTL_11B;
1690
1691 /* Get SignalField,ServiceField,Length */
1692 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1693 PK_TYPE_11B, &short_head->ab);
1694
1695 /* Get Duration and TimeStampOff */
1696 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001697 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001698 short_head->time_stamp_off =
1699 vnt_time_stamp_off(pDevice, wCurrentRate);
1700 }
1701
Forest Bond92b96792009-06-13 07:38:31 -04001702
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001703 /* Generate Beacon Header */
1704 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001705
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001706 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1707
1708 pMACHeader->duration_id = 0;
1709 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1710 pDevice->wSeqCounter++;
1711 if (pDevice->wSeqCounter > 0x0fff)
1712 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001713
1714 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1715
Malcolm Priestleyfad8e4a2014-03-22 09:01:29 +00001716 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)cbReqCount);
Andres Moreb902fbf2013-02-25 20:32:51 -05001717 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001718 pTX_Buffer->byType = 0x01;
1719
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001720 pContext->skb = NULL;
1721 pContext->type = CONTEXT_MGMT_PACKET;
1722 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04001723
1724 PIPEnsSendBulkOut(pDevice,pContext);
1725 return CMD_STATUS_PENDING;
1726
1727}
1728
Forest Bond92b96792009-06-13 07:38:31 -04001729//TYPE_AC0DMA data tx
1730/*
1731 * Description:
1732 * Tx packet via AC0DMA(DMA1)
1733 *
1734 * Parameters:
1735 * In:
1736 * pDevice - Pointer to the adapter
1737 * skb - Pointer to tx skb packet
1738 * Out:
1739 * void
1740 *
1741 * Return Value: NULL
1742 */
1743
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001744int nsDMA_tx_packet(struct vnt_private *pDevice, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04001745{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001746 struct net_device_stats *pStats = &pDevice->stats;
1747 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001748 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001749 u32 BytesToWrite = 0, uHeaderLen = 0;
1750 u32 uNodeIndex = 0;
1751 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1752 u16 wAID;
1753 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05001754 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001755 PSKeyItem pTransmitKey = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001756 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05001757 int bTKIP_UseGTK = false;
1758 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001759 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05001760 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001761 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05001762 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001763 u32 status;
1764 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05001765 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04001766
Forest Bond92b96792009-06-13 07:38:31 -04001767 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1768
1769 if (pDevice->uAssocCount == 0) {
1770 dev_kfree_skb_irq(skb);
1771 return 0;
1772 }
1773
Andres Moreb902fbf2013-02-25 20:32:51 -05001774 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04001775 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001776 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04001777 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1778
1779 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1780 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1781 // set tx map
1782 pMgmt->abyPSTxMap[0] |= byMask[0];
1783 return 0;
1784 }
Masanari Iida93184692012-08-13 21:21:50 +09001785 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04001786
1787 if (pDevice->byBBType != BB_TYPE_11A)
1788 pDevice->wCurrentRate = RATE_2M;
1789 else
1790 pDevice->wCurrentRate = RATE_24M;
1791 // long preamble type
1792 pDevice->byPreambleType = PREAMBLE_SHORT;
1793
1794 }else {
1795
Andres Moreb902fbf2013-02-25 20:32:51 -05001796 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04001797
1798 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1799
1800 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1801
1802 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1803 // set tx map
1804 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1805 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1806 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
1807 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1808
1809 return 0;
1810 }
1811 // AP rate decided from node
1812 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1813 // tx preamble decided from node
1814
1815 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1816 pDevice->byPreambleType = pDevice->byShortPreamble;
1817
1818 }else {
1819 pDevice->byPreambleType = PREAMBLE_LONG;
1820 }
Andres More4e9b5e22013-02-12 20:36:30 -05001821 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04001822 }
1823 }
1824
Andres Moree269fc22013-02-12 20:36:29 -05001825 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001826 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
1827 dev_kfree_skb_irq(skb);
1828 return 0;
1829 }
1830 }
1831
Tobias Klauser838c2d62014-04-25 11:53:58 +02001832 memcpy(&pDevice->sTxEthHeader, skb->data, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001833
1834//mike add:station mode check eapol-key challenge--->
1835{
Andres Moreb902fbf2013-02-25 20:32:51 -05001836 u8 Protocol_Version; //802.1x Authentication
1837 u8 Packet_Type; //802.1x Authentication
1838 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05001839 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04001840
Charles Clément21ec51f2010-05-18 10:08:14 -07001841 Protocol_Version = skb->data[ETH_HLEN];
1842 Packet_Type = skb->data[ETH_HLEN+1];
1843 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
1844 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 -05001845 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001846 /* 802.1x OR eapol-key challenge frame transfer */
1847 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
1848 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05001849 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04001850 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
1851 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
1852 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05001853 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001854 PRINT_K("WPA ");
1855 }
1856 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001857 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001858 PRINT_K("WPA2(re-keying) ");
1859 }
1860 PRINT_K("Authentication completed!!\n");
1861 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001862 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04001863 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05001864 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001865 PRINT_K("WPA2 Authentication completed!!\n");
1866 }
1867 }
1868 }
1869}
1870//mike add:station mode check eapol-key challenge<---
1871
Andres More4e9b5e22013-02-12 20:36:30 -05001872 if (pDevice->bEncryptionEnable == true) {
1873 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04001874 // get Transmit key
1875 do {
1876 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1877 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1878 pbyBSSID = pDevice->abyBSSID;
1879 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001880 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001881 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001882 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1883 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001884 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1885 break;
1886 }
1887 } else {
1888 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
1889 break;
1890 }
1891 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001892 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
1893 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04001894 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
1895 for (ii = 0; ii< 6; ii++)
1896 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
1897 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
1898
1899 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05001900 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04001901 break;
1902 }
1903 // get group key
1904 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001905 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001906 pTransmitKey = NULL;
1907 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1908 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1909 }
1910 else
1911 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1912 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001913 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001914 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1915 }
Andres Moree269fc22013-02-12 20:36:29 -05001916 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001917 }
1918
Andres Moreb902fbf2013-02-25 20:32:51 -05001919 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04001920
1921 if (pDevice->bFixRate) {
1922 if (pDevice->byBBType == BB_TYPE_11B) {
1923 if (pDevice->uConnectionRate >= RATE_11M) {
1924 pDevice->wCurrentRate = RATE_11M;
1925 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05001926 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04001927 }
1928 } else {
1929 if ((pDevice->byBBType == BB_TYPE_11A) &&
1930 (pDevice->uConnectionRate <= RATE_6M)) {
1931 pDevice->wCurrentRate = RATE_6M;
1932 } else {
1933 if (pDevice->uConnectionRate >= RATE_54M)
1934 pDevice->wCurrentRate = RATE_54M;
1935 else
Andres More3eaca0d2013-02-25 20:32:52 -05001936 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04001937 }
1938 }
1939 }
1940 else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001941 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Forest Bond92b96792009-06-13 07:38:31 -04001942 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05001943 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04001944 // Multicast use highest data rate
1945 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1946 // preamble type
1947 pDevice->byPreambleType = pDevice->byShortPreamble;
1948 }
1949 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001950 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04001951 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1952 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1953 pDevice->byPreambleType = pDevice->byShortPreamble;
1954
1955 }
1956 else {
1957 pDevice->byPreambleType = PREAMBLE_LONG;
1958 }
1959 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
1960 }
1961 else {
1962 if (pDevice->byBBType != BB_TYPE_11A)
1963 pDevice->wCurrentRate = RATE_2M;
1964 else
1965 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
1966 // abyCurrExtSuppRates[]
1967 pDevice->byPreambleType = PREAMBLE_SHORT;
1968 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
1969 }
1970 }
1971 }
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001972 if (pDevice->op_mode == NL80211_IFTYPE_STATION) {
Forest Bond92b96792009-06-13 07:38:31 -04001973 // Infra STA rate decided from AP Node, index = 0
1974 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1975 }
1976 }
1977
Andres Moreceb8c5d2013-03-18 20:33:49 -05001978 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001979 if (pDevice->byBBType != BB_TYPE_11A) {
1980 pDevice->wCurrentRate = RATE_1M;
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001981 pDevice->byTopCCKBasicRate = RATE_1M;
1982 pDevice->byTopOFDMBasicRate = RATE_6M;
1983 } else {
1984 pDevice->wCurrentRate = RATE_6M;
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001985 pDevice->byTopCCKBasicRate = RATE_1M;
1986 pDevice->byTopOFDMBasicRate = RATE_6M;
1987 }
1988 }
Forest Bond92b96792009-06-13 07:38:31 -04001989
Andres More0cbd8d92010-05-06 20:34:29 -03001990 DBG_PRT(MSG_LEVEL_DEBUG,
1991 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
1992 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04001993
1994 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03001995 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001996 }
1997
1998 if (pDevice->wCurrentRate <= RATE_11M) {
1999 byPktType = PK_TYPE_11B;
2000 }
2001
Andres More4e9b5e22013-02-12 20:36:30 -05002002 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002003 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2004 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002005 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002006 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002007 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2008 if (pTransmitKey == NULL) {
2009 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2010 }
2011 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002012 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002013 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2014 }
2015 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002016 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2017 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002018 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002019 }
2020 }
2021 }
Forest Bond92b96792009-06-13 07:38:31 -04002022 }
2023 else {
2024
Forest Bond92b96792009-06-13 07:38:31 -04002025 if (pTransmitKey == NULL) {
2026 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2027 dev_kfree_skb_irq(skb);
2028 pStats->tx_dropped++;
2029 return STATUS_FAILURE;
2030 }
Forest Bond92b96792009-06-13 07:38:31 -04002031 }
2032 }
2033
Malcolm Priestleyb674ee12014-05-15 22:49:10 +01002034 pContext = s_vGetFreeContext(pDevice);
2035 if (!pContext) {
2036 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2037 dev_kfree_skb_irq(skb);
2038 return STATUS_RESOURCES;
2039 }
2040
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002041 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002042
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01002043 fConvertedPacket = s_bPacketToWirelessUsb(pContext, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002044 pTX_Buffer, bNeedEncryption,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01002045 skb->len, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002046 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002047 pDevice->wCurrentRate,
2048 &uHeaderLen, &BytesToWrite
2049 );
2050
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002051 if (fConvertedPacket == false) {
2052 pContext->in_use = false;
2053 dev_kfree_skb_irq(skb);
2054 return STATUS_FAILURE;
2055 }
Forest Bond92b96792009-06-13 07:38:31 -04002056
Andres More4e9b5e22013-02-12 20:36:30 -05002057 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002058 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002059 bScheduleCommand((void *) pDevice,
2060 WLAN_CMD_MAC_DISPOWERSAVING,
2061 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002062 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002063 }
2064 }
2065
Andres Moreb902fbf2013-02-25 20:32:51 -05002066 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Malcolm Priestleyca347592014-03-22 09:01:28 +00002067 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite);
Forest Bond92b96792009-06-13 07:38:31 -04002068
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002069 pContext->skb = skb;
2070 pContext->type = CONTEXT_DATA_PACKET;
2071 pContext->buf_len = (u16)BytesToWrite + 4 ; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04002072
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002073 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002074 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002075 (u16)(BytesToWrite-uHeaderLen),
2076 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002077
2078 status = PIPEnsSendBulkOut(pDevice,pContext);
2079
Andres More4e9b5e22013-02-12 20:36:30 -05002080 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002081 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002082
Andres Moreb902fbf2013-02-25 20:32:51 -05002083 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002084 }
2085
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002086 if (status != STATUS_PENDING) {
2087 pContext->in_use = false;
2088 dev_kfree_skb_irq(skb);
2089 return STATUS_FAILURE;
2090 }
Forest Bond92b96792009-06-13 07:38:31 -04002091
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002092
2093 return 0;
Forest Bond92b96792009-06-13 07:38:31 -04002094}