blob: 742559de64ec6d036ff71c2f650800e0f5b70b1f [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 Priestley0a0f4b62013-10-01 15:50:24 +010099static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
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 Priestley05cc6172014-04-30 21:31:12 +0100122static u16 s_vFillCTSHead(struct vnt_private *pDevice,
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 Priestley0a0f4b62013-10-01 15:50:24 +0100126static u16 s_vFillRTSHead(struct vnt_private *pDevice, 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 Priestley95bfb1a2013-08-27 12:29:10 +0100207 memcpy(pbyBuf+11, pTransmitKey->abyKey,
208 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 Priestley78363fd2013-10-01 15:52:16 +0100473static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
474 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
475{
476 /* Get SignalField,ServiceField,Length */
477 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
478 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
479 PK_TYPE_11B, &buf->b);
480
481 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000482 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
483 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100484
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000485 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
486 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100487 priv->byTopCCKBasicRate);
488
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000489 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100490}
491
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100492static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
493 u16 rate, struct vnt_tx_datahead_g_fb *buf,
494 u32 frame_len, int need_ack)
495{
496 /* Get SignalField,ServiceField,Length */
497 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
498
499 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
500 PK_TYPE_11B, &buf->b);
501
502 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000503 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
504 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100505
Malcolm Priestley4e011172014-03-18 19:24:55 +0000506 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
507 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100508
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000509 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
510 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100511 priv->byTopCCKBasicRate);
512
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000513 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100514}
515
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100516static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
517 u16 rate, struct vnt_tx_datahead_a_fb *buf,
518 u32 frame_len, int need_ack)
519{
520 /* Get SignalField,ServiceField,Length */
521 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
522 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000523 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100524
Malcolm Priestley4e011172014-03-18 19:24:55 +0000525 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
526 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100527
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000528 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100529
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000530 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100531}
532
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100533static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
534 u16 rate, struct vnt_tx_datahead_ab *buf,
535 u32 frame_len, int need_ack)
536{
537 /* Get SignalField,ServiceField,Length */
538 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
539 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000540 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100541
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000542 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100543
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000544 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100545}
546
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100547static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
548 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000549 __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100550{
551 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000552 rts->frame_control =
553 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100554
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000555 if (priv->op_mode == NL80211_IFTYPE_ADHOC ||
556 priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100557 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
558 else
559 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
560
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000561 if (priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100562 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
563 else
564 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
565
566 return 0;
567}
568
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100569static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100570 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
571 u8 pkt_type, u32 frame_len, int need_ack,
572 u16 current_rate, u8 fb_option)
573{
574 u16 rts_frame_len = 20;
575
576 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
577 PK_TYPE_11B, &buf->b);
578 BBvCalculateParameter(priv, rts_frame_len,
579 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
580
Malcolm Priestley4e011172014-03-18 19:24:55 +0000581 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100582 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000583 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100584 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000585 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100586 pkt_type, current_rate, need_ack, fb_option);
587
Malcolm Priestley4e011172014-03-18 19:24:55 +0000588 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100589
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100590 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
591 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100592}
593
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100594static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100595 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
596 u8 pkt_type, u32 frame_len, int need_ack,
597 u16 current_rate, u8 fb_option)
598{
599 u16 rts_frame_len = 20;
600
601 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
602 PK_TYPE_11B, &buf->b);
603 BBvCalculateParameter(priv, rts_frame_len,
604 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
605
606
Malcolm Priestley4e011172014-03-18 19:24:55 +0000607 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100608 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000609 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100610 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000611 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100612 pkt_type, current_rate, need_ack, fb_option);
613
614
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000615 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100616 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000617 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100618 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000619 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100620 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000621 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100622 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100623
Malcolm Priestley4e011172014-03-18 19:24:55 +0000624 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100625
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100626 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
627 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100628}
629
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100630static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100631 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
632 u8 pkt_type, u32 frame_len, int need_ack,
633 u16 current_rate, u8 fb_option)
634{
635 u16 rts_frame_len = 20;
636
637 BBvCalculateParameter(priv, rts_frame_len,
638 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
639
Malcolm Priestley4e011172014-03-18 19:24:55 +0000640 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100641 pkt_type, current_rate, need_ack, fb_option);
642
Malcolm Priestley4e011172014-03-18 19:24:55 +0000643 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100644
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100645 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
646 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100647}
648
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100649static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100650 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
651 u8 pkt_type, u32 frame_len, int need_ack,
652 u16 current_rate, u8 fb_option)
653{
654 u16 rts_frame_len = 20;
655
656 BBvCalculateParameter(priv, rts_frame_len,
657 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
658
Malcolm Priestley4e011172014-03-18 19:24:55 +0000659 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100660 pkt_type, current_rate, need_ack, fb_option);
661
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000662 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100663 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100664
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000665 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100666 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100667
Malcolm Priestley4e011172014-03-18 19:24:55 +0000668 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100669
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100670 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
671 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100672}
673
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100674static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100675 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500676 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400677{
Forest Bond92b96792009-06-13 07:38:31 -0400678
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100679 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100680 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400681
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100682 /* Note: So far RTSHead doesn't appear in ATIM
683 * & Beacom DMA, so we don't need to take them
684 * into account.
685 * Otherwise, we need to modified codes for them.
686 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100687 switch (byPktType) {
688 case PK_TYPE_11GB:
689 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100690 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100691 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100692 psEthHeader, byPktType, cbFrameLength,
693 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100694 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100695 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100696 psEthHeader, byPktType, cbFrameLength,
697 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100698 break;
699 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100700 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100701 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100702 psEthHeader, byPktType, cbFrameLength,
703 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100704 break;
705 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100706 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100707 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100708 psEthHeader, byPktType, cbFrameLength,
709 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100710 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100711
712 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400713}
714
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100715static u16 s_vFillCTSHead(struct vnt_private *pDevice,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100716 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
717 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400718{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000719 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400720
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100721 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100722 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400723
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100724 if (byFBOption != AUTO_FB_NONE) {
725 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100726 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100727 /* Get SignalField,ServiceField,Length */
728 BBvCalculateParameter(pDevice, uCTSFrameLen,
729 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000730 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100731 cbFrameLength, byPktType,
732 wCurrentRate, bNeedAck, byFBOption);
733 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000734 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100735 CTSDUR_BA_F0, cbFrameLength, byPktType,
736 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100737 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000738 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100739 CTSDUR_BA_F1, cbFrameLength, byPktType,
740 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100741 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000742 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000743 pBuf->data.frame_control =
744 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
745
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100746 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100747
748 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
749 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100750 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100751 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100752 /* Get SignalField,ServiceField,Length */
753 BBvCalculateParameter(pDevice, uCTSFrameLen,
754 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100755 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000756 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100757 CTSDUR_BA, cbFrameLength, byPktType,
758 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100759 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000760 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000761 pBuf->data.frame_control =
762 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
763
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100764 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100765
766 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
767 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400768 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100769
770 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400771}
772
Forest Bond92b96792009-06-13 07:38:31 -0400773/*+
774 *
775 * Description:
776 * Generate FIFO control for MAC & Baseband controller
777 *
778 * Parameters:
779 * In:
780 * pDevice - Pointer to adpater
781 * pTxDataHead - Transmit Data Buffer
782 * pTxBufHead - pTxBufHead
783 * pvRrvTime - pvRrvTime
784 * pvRTS - RTS Buffer
785 * pCTS - CTS Buffer
786 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
787 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400788 * Out:
789 * none
790 *
791 * Return Value: none
792 *
793-*/
Andres Morecc856e62010-05-17 21:34:01 -0300794
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100795static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100796 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100797 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100798 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400799{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100800 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100801 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000802 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000803 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400804
Malcolm Priestley03a9cf32014-03-22 09:01:30 +0000805 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100806 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400807
Malcolm Priestley92928f12013-10-07 20:14:01 +0100808 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
809 byFBOption = AUTO_FB_0;
810 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
811 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400812
Malcolm Priestley92928f12013-10-07 20:14:01 +0100813 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
814 if (need_rts) {
815 struct vnt_rrv_time_rts *pBuf =
816 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100817
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000818 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100819 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000820 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100821 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000822 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100823 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100824
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000825 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100826 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000827 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100828 PK_TYPE_11B, cbFrameSize,
829 pDevice->byTopCCKBasicRate, bNeedACK);
830
831 if (need_mic) {
832 *mic_hdr = &tx_buffer->
833 tx_head.tx_rts.tx.mic.hdr;
834 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
835 } else {
836 head = &tx_buffer->tx_head.tx_rts.tx.head;
837 }
838
839 /* Fill RTS */
840 return s_vFillRTSHead(pDevice, byPktType, head,
841 cbFrameSize, bNeedACK, psEthHeader,
842 wCurrentRate, byFBOption);
843
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100844 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100845 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
846 tx_head.tx_cts.cts;
847
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000848 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100849 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000850 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100851 PK_TYPE_11B, cbFrameSize,
852 pDevice->byTopCCKBasicRate, bNeedACK);
853
Malcolm Priestley372108e2014-03-18 19:25:00 +0000854 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100855 byPktType, cbFrameSize, wCurrentRate);
856
857 if (need_mic) {
858 *mic_hdr = &tx_buffer->
859 tx_head.tx_cts.tx.mic.hdr;
860 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
861 } else {
862 head = &tx_buffer->tx_head.tx_cts.tx.head;
863 }
864
865 /* Fill CTS */
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100866 return s_vFillCTSHead(pDevice, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100867 head, cbFrameSize, bNeedACK, wCurrentRate,
868 byFBOption);
869 }
870 } else if (byPktType == PK_TYPE_11A) {
871 if (need_mic) {
872 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
873 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
874 } else {
875 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100876 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100877
Malcolm Priestley92928f12013-10-07 20:14:01 +0100878 if (need_rts) {
879 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
880 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100881
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000882 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100883 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100884
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000885 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100886 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
887
888 /* Fill RTS */
889 return s_vFillRTSHead(pDevice, byPktType, head,
890 cbFrameSize, bNeedACK, psEthHeader,
891 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100892 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100893 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
894 tx_head.tx_ab.ab;
895
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000896 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100897 PK_TYPE_11A, cbFrameSize,
898 wCurrentRate, bNeedACK);
899
900 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
901 wCurrentRate, &head->data_head_a_fb,
902 cbFrameSize, bNeedACK);
903 }
904 } else if (byPktType == PK_TYPE_11B) {
905 if (need_mic) {
906 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
907 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
908 } else {
909 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100910 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100911
Malcolm Priestley92928f12013-10-07 20:14:01 +0100912 if (need_rts) {
913 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
914 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100915
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000916 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100917 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100918
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000919 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100920 PK_TYPE_11B, cbFrameSize, wCurrentRate,
921 bNeedACK);
922
923 /* Fill RTS */
924 return s_vFillRTSHead(pDevice, byPktType, head,
925 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100926 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100927 } else {
928 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
929 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100930
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000931 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100932 PK_TYPE_11B, cbFrameSize,
933 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100934
Malcolm Priestley92928f12013-10-07 20:14:01 +0100935 return vnt_rxtx_datahead_ab(pDevice, byPktType,
936 wCurrentRate, &head->data_head_ab,
937 cbFrameSize, bNeedACK);
938 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100939 }
940
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100941 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400942}
943/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500944 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500945 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300946 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400947*/
948
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000949static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100950 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100951 u32 uSkbPacketLen, struct ethhdr *psEthHeader,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100952 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
953 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400954{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100955 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000956 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000957 u32 cb802_1_H_len;
958 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
959 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100960 int bNeedACK;
961 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000962 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
963 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
964 u8 abySNAP_Bridgetunnel[ETH_ALEN]
965 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
966 u32 uDuration;
967 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100968 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000969 u8 byFBOption = AUTO_FB_NONE, byFragType;
970 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100971 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000972 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500973 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100974
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100975 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400976
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000977 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500978 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
979 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000980 }
Forest Bond92b96792009-06-13 07:38:31 -0400981
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000982 /* Get pkt type */
983 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
984 cb802_1_H_len = 8;
985 else
986 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400987
Charles Clément21ec51f2010-05-18 10:08:14 -0700988 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400989
990 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500991 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400992
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000993 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC ||
994 pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500995 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500996 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -0300997 pTxBufHead->wFIFOCtl =
998 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
999 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001000 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001001 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1002 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001003 } else {
1004 /* MSDUs in Infra mode always need ACK */
1005 bNeedACK = true;
1006 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1007 }
Forest Bond92b96792009-06-13 07:38:31 -04001008
Malcolm Priestley58462512014-03-22 09:01:27 +00001009 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001010
Forest Bond92b96792009-06-13 07:38:31 -04001011 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001012 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1013
Andres More3eaca0d2013-02-25 20:32:52 -05001014 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001015
1016 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001017 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001018 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1019 }
1020
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001021 /* Set Auto Fallback Ctl */
1022 if (wCurrentRate >= RATE_18M) {
1023 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1024 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1025
1026 pDevice->tx_rate_fb0 =
1027 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1028 pDevice->tx_rate_fb1 =
1029 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1030
1031 byFBOption = AUTO_FB_0;
1032 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1033 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1034 pDevice->tx_rate_fb0 =
1035 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1036 pDevice->tx_rate_fb1 =
1037 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1038
1039 byFBOption = AUTO_FB_1;
1040 }
1041 }
Forest Bond92b96792009-06-13 07:38:31 -04001042
Andres More4e9b5e22013-02-12 20:36:30 -05001043 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001044 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1045 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1046 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1047 }
1048 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1049 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1050 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1051 }
1052 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1053 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1054 }
1055 }
1056 }
1057
Forest Bond92b96792009-06-13 07:38:31 -04001058 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1059 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1060 cbIVlen = 4;
1061 cbICVlen = 4;
1062 }
1063 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1064 cbIVlen = 8;//IV+ExtIV
1065 cbMIClen = 8;
1066 cbICVlen = 4;
1067 }
1068 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1069 cbIVlen = 8;//RSN Header
1070 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001071 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001072 }
Andres Moree269fc22013-02-12 20:36:29 -05001073 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001074 //MAC Header should be padding 0 to DW alignment.
1075 uPadding = 4 - (cbMACHdLen%4);
1076 uPadding %= 4;
1077 }
1078 }
1079
1080 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1081
Andres Moree269fc22013-02-12 20:36:29 -05001082 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1083 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001084 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001085 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001086 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1087 }
1088
Andres Moreb902fbf2013-02-25 20:32:51 -05001089 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001090 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1091
Forest Bond92b96792009-06-13 07:38:31 -04001092 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1093 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001094 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001095 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001096 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001097 }
1098 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001099 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001100 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001101 }
1102 } else {
1103 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001104 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001105 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001106 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001107 }
Andres Moree269fc22013-02-12 20:36:29 -05001108 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001109 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001110 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001111 }
1112 } // Auto Fall Back
1113 }
1114 else {//802.11a/b packet
1115 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001116 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001117 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001118 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001119 }
Andres Moree269fc22013-02-12 20:36:29 -05001120 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001121 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001122 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001123 }
1124 } else {
1125 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001126 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001127 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001128 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001129 }
Andres Moree269fc22013-02-12 20:36:29 -05001130 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001131 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001132 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001133 }
1134 } // Auto Fall Back
1135 }
1136
Andres Moreb902fbf2013-02-25 20:32:51 -05001137 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1138 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1139 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001140
Forest Bond92b96792009-06-13 07:38:31 -04001141 //=========================
1142 // No Fragmentation
1143 //=========================
1144 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1145 byFragType = FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001146 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1147
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001148 /* Fill FIFO, RrvTime, RTS and CTS */
1149 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1150 tx_buffer, &pMICHDR, cbMICHDR,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001151 cbFrameSize, bNeedACK, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001152
Forest Bond92b96792009-06-13 07:38:31 -04001153 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001154 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001155 byFragType, 0);
Forest Bond92b96792009-06-13 07:38:31 -04001156
Andres More4e9b5e22013-02-12 20:36:30 -05001157 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001158 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001159 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001160 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001161 }
1162
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001163 /* 802.1H */
1164 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001165 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001166 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001167 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001168 abySNAP_Bridgetunnel, 6);
1169 else
1170 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001171
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001172 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001173
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001174 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1175 }
Forest Bond92b96792009-06-13 07:38:31 -04001176
Forest Bond92b96792009-06-13 07:38:31 -04001177 if (pPacket != NULL) {
1178 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001179 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001180 (pPacket + ETH_HLEN),
1181 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001182 );
1183
1184 } else {
1185 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001186 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001187 }
1188
Andres More4e9b5e22013-02-12 20:36:30 -05001189 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001190
1191 ///////////////////////////////////////////////////////////////////
1192
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001193 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1194 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1195 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1196 }
Forest Bond92b96792009-06-13 07:38:31 -04001197 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001198 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1199 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001200 }
1201 else {
Andres More52a7e642013-02-25 20:32:53 -05001202 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1203 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001204 }
1205 // DO Software Michael
1206 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001207 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001208 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001209 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001210 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1211 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001212
1213 ///////////////////////////////////////////////////////////////////
1214
1215 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1216 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001217 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001218 //}
1219 //DBG_PRN_GRP12(("\n\n\n"));
1220
1221 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1222
Andres More52a7e642013-02-25 20:32:53 -05001223 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1224 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001225
1226 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1227 MIC_vUnInit();
1228
Andres More4e9b5e22013-02-12 20:36:30 -05001229 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001230 *pdwMIC_L = 0;
1231 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001232 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001233 }
1234 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1235 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1236 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1237 }
1238
Andres More4e9b5e22013-02-12 20:36:30 -05001239 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001240
Andres More3eaca0d2013-02-25 20:32:52 -05001241 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001242
Andres More4e9b5e22013-02-12 20:36:30 -05001243 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1244 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1245 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001246 cbFrameSize -= cbICVlen;
1247 }
1248
Forest Bond92b96792009-06-13 07:38:31 -04001249 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001250
1251 *pcbHeaderLen = cbHeaderLength;
1252 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1253
Forest Bond92b96792009-06-13 07:38:31 -04001254 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001255 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001256
Andres More4e9b5e22013-02-12 20:36:30 -05001257 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001258
1259}
1260
Forest Bond92b96792009-06-13 07:38:31 -04001261/*+
1262 *
1263 * Description:
1264 * Translate 802.3 to 802.11 header
1265 *
1266 * Parameters:
1267 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001268 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001269 * dwTxBufferAddr - Transmit Buffer
1270 * pPacket - Packet from upper layer
1271 * cbPacketSize - Transmit Data Length
1272 * Out:
1273 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1274 * pcbAppendPayload - size of append payload for 802.1H translation
1275 *
1276 * Return Value: none
1277 *
1278-*/
1279
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001280static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001281 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001282 int bNeedEncrypt, u16 wFragType, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001283{
Andres More1cac4a42013-03-18 20:33:50 -05001284 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001285
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001286 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001287
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001288 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001289 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001290 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001291 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001292 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1293 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001294 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001295 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001296 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001297 } else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001298 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001299 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001300 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001301 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001302 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001303 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001304 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001305 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001306 &(pDevice->abyBSSID[0]),
1307 ETH_ALEN);
1308 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001309 memcpy(&(pMACHeader->addr3[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]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001313 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001314 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001315 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001316 &(pDevice->abyBSSID[0]),
1317 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001318 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001319 }
1320 }
1321
1322 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001323 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001324
Andres More1cac4a42013-03-18 20:33:50 -05001325 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001326
Andres More1cac4a42013-03-18 20:33:50 -05001327 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001328
1329 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001330 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001331
1332 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1333 pDevice->wSeqCounter++;
1334 if (pDevice->wSeqCounter > 0x0fff)
1335 pDevice->wSeqCounter = 0;
1336 }
1337
1338 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001339 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001340 }
1341}
1342
Forest Bond92b96792009-06-13 07:38:31 -04001343/*+
1344 *
1345 * Description:
1346 * Request instructs a MAC to transmit a 802.11 management packet through
1347 * the adapter onto the medium.
1348 *
1349 * Parameters:
1350 * In:
1351 * hDeviceContext - Pointer to the adapter
1352 * pPacket - A pointer to a descriptor for the packet to transmit
1353 * Out:
1354 * none
1355 *
Andres Moree269fc22013-02-12 20:36:29 -05001356 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001357 *
1358-*/
1359
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001360CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1361 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001362{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001363 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001364 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001365 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001366 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001367 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001368 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001369 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001370 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001371 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001372 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001373 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1374 u32 uPadding = 0;
1375 u16 wTxBufSize;
1376 u32 cbMacHdLen;
1377 u16 wCurrentRate = RATE_1M;
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001378 unsigned long flags;
1379
1380 if (pDevice->byBBType == BB_TYPE_11A) {
1381 wCurrentRate = RATE_6M;
1382 byPktType = PK_TYPE_11A;
1383 } else {
1384 wCurrentRate = RATE_1M;
1385 byPktType = PK_TYPE_11B;
1386 }
1387
1388 if (pMgmt->eScanState != WMAC_NO_SCANNING)
1389 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1390 else
1391 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1392
1393 pDevice->wCurrentRate = wCurrentRate;
1394
1395 spin_lock_irqsave(&pDevice->lock, flags);
Forest Bond92b96792009-06-13 07:38:31 -04001396
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001397 pContext = s_vGetFreeContext(pDevice);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001398 if (!pContext) {
1399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1400 "ManagementSend TX...NO CONTEXT!\n");
1401 spin_unlock_irqrestore(&pDevice->lock, flags);
1402 return CMD_STATUS_RESOURCES;
1403 }
Forest Bond92b96792009-06-13 07:38:31 -04001404
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001405 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001406 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001407 pTxBufHead = &pTX_Buffer->fifo_head;
1408 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1409 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001410
Forest Bond92b96792009-06-13 07:38:31 -04001411
Forest Bond92b96792009-06-13 07:38:31 -04001412 //Set packet type
1413 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1414 pTxBufHead->wFIFOCtl = 0;
1415 }
1416 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1417 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1418 }
1419 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1420 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1421 }
1422 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1423 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1424 }
1425
1426 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
Malcolm Priestley58462512014-03-22 09:01:27 +00001427 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001428
Andres More22040bb2010-08-02 20:21:44 -03001429 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001430 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001431 }
1432 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001433 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001434 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1435 };
1436
1437 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1438 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1439
1440 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1441 //Set Preamble type always long
1442 //pDevice->byPreambleType = PREAMBLE_LONG;
1443 // probe-response don't retry
1444 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001445 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001446 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1447 //}
1448 }
1449
1450 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1451
1452 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001453 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001454 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1455 } else {
1456 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1457 }
1458
1459 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001460 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001461
1462 // Notes:
1463 // Although spec says MMPDU can be fragmented; In most case,
1464 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001465
1466 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1467 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1468 cbIVlen = 4;
1469 cbICVlen = 4;
1470 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1471 }
1472 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1473 cbIVlen = 8;//IV+ExtIV
1474 cbMIClen = 8;
1475 cbICVlen = 4;
1476 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1477 //We need to get seed here for filling TxKey entry.
1478 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1479 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1480 }
1481 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1482 cbIVlen = 8;//RSN Header
1483 cbICVlen = 8;//MIC
1484 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001485 }
1486 //MAC Header should be padding 0 to DW alignment.
1487 uPadding = 4 - (cbMacHdLen%4);
1488 uPadding %= 4;
1489 }
1490
1491 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1492
1493 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001494 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001495 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1496 }
1497 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1498
1499 //Set RrvTime/RTS/CTS Buffer
1500 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001501 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001502 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001503 }
1504 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001505 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001506 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001507 }
1508
Andres Moreceb8c5d2013-03-18 20:33:49 -05001509 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001510 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1511 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001512 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001513 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1514 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001515 //=========================
1516 // No Fragmentation
1517 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001518 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001519
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001520 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001521 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001522 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001523 cbFrameSize, bNeedACK, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001524
Andres More1cac4a42013-03-18 20:33:50 -05001525 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001526
1527 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1528
1529 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001530 u8 * pbyIVHead;
1531 u8 * pbyPayloadHead;
1532 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001533 PSKeyItem pTransmitKey = NULL;
1534
Andres Moreb902fbf2013-02-25 20:32:51 -05001535 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1536 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001537 do {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001538 if (pDevice->op_mode == NL80211_IFTYPE_STATION &&
1539 pDevice->bLinkPass == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001540 pbyBSSID = pDevice->abyBSSID;
1541 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001542 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001543 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001544 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1546 break;
1547 }
1548 } else {
1549 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1550 break;
1551 }
1552 }
1553 // get group key
1554 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001555 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001556 pTransmitKey = NULL;
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode);
Forest Bond92b96792009-06-13 07:38:31 -04001558 } else {
1559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1560 }
Andres Moree269fc22013-02-12 20:36:29 -05001561 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001562 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001563 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001564 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001565
Jim Lieb3e362592009-08-12 14:54:11 -07001566 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001567 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001568 cbFrameBodySize);
1569 }
1570 else {
1571 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001572 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001573 }
1574
Andres More1cac4a42013-03-18 20:33:50 -05001575 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001576 pDevice->wSeqCounter++ ;
1577 if (pDevice->wSeqCounter > 0x0fff)
1578 pDevice->wSeqCounter = 0;
1579
1580 if (bIsPSPOLL) {
1581 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001582 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001583 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1584 // in the same place of other packet's Duration-field).
1585 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001586 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001587 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1588 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001589 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001590 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00001591 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001592 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1593 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001594 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1595 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001596 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001597 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1598 }
Forest Bond92b96792009-06-13 07:38:31 -04001599 }
1600
Malcolm Priestleyca347592014-03-22 09:01:28 +00001601 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001602 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001603 pTX_Buffer->byType = 0x00;
1604
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001605 pContext->skb = NULL;
1606 pContext->type = CONTEXT_MGMT_PACKET;
1607 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04001608
Andres More1cac4a42013-03-18 20:33:50 -05001609 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001610 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1611 &pMACHeader->addr1[0], (u16)cbFrameSize,
1612 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001613 }
1614 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001615 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1616 &pMACHeader->addr3[0], (u16)cbFrameSize,
1617 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001618 }
1619
1620 PIPEnsSendBulkOut(pDevice,pContext);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001621
1622 spin_unlock_irqrestore(&pDevice->lock, flags);
1623
Forest Bond92b96792009-06-13 07:38:31 -04001624 return CMD_STATUS_PENDING;
1625}
1626
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001627CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1628 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001629{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001630 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001631 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001632 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1633 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001634 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001635 u16 wCurrentRate;
1636 u32 cbFrameBodySize;
1637 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001638 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001639 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001640
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001641 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001642 if (NULL == pContext) {
1643 status = CMD_STATUS_RESOURCES;
1644 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1645 return status ;
1646 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001647
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001648 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001649 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001650
1651 cbFrameBodySize = pPacket->cbPayloadLen;
1652
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001653 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001654
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001655 if (pDevice->byBBType == BB_TYPE_11A) {
1656 wCurrentRate = RATE_6M;
1657
1658 /* Get SignalField,ServiceField,Length */
1659 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1660 PK_TYPE_11A, &short_head->ab);
1661
1662 /* Get Duration and TimeStampOff */
1663 short_head->duration = s_uGetDataDuration(pDevice,
1664 PK_TYPE_11A, false);
1665 short_head->time_stamp_off =
1666 vnt_time_stamp_off(pDevice, wCurrentRate);
1667 } else {
1668 wCurrentRate = RATE_1M;
1669 short_head->fifo_ctl |= FIFOCTL_11B;
1670
1671 /* Get SignalField,ServiceField,Length */
1672 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1673 PK_TYPE_11B, &short_head->ab);
1674
1675 /* Get Duration and TimeStampOff */
1676 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001677 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001678 short_head->time_stamp_off =
1679 vnt_time_stamp_off(pDevice, wCurrentRate);
1680 }
1681
Forest Bond92b96792009-06-13 07:38:31 -04001682
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001683 /* Generate Beacon Header */
1684 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001685
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001686 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1687
1688 pMACHeader->duration_id = 0;
1689 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1690 pDevice->wSeqCounter++;
1691 if (pDevice->wSeqCounter > 0x0fff)
1692 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001693
1694 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1695
Malcolm Priestleyfad8e4a2014-03-22 09:01:29 +00001696 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)cbReqCount);
Andres Moreb902fbf2013-02-25 20:32:51 -05001697 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001698 pTX_Buffer->byType = 0x01;
1699
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001700 pContext->skb = NULL;
1701 pContext->type = CONTEXT_MGMT_PACKET;
1702 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04001703
1704 PIPEnsSendBulkOut(pDevice,pContext);
1705 return CMD_STATUS_PENDING;
1706
1707}
1708
Forest Bond92b96792009-06-13 07:38:31 -04001709//TYPE_AC0DMA data tx
1710/*
1711 * Description:
1712 * Tx packet via AC0DMA(DMA1)
1713 *
1714 * Parameters:
1715 * In:
1716 * pDevice - Pointer to the adapter
1717 * skb - Pointer to tx skb packet
1718 * Out:
1719 * void
1720 *
1721 * Return Value: NULL
1722 */
1723
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001724int nsDMA_tx_packet(struct vnt_private *pDevice, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04001725{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001726 struct net_device_stats *pStats = &pDevice->stats;
1727 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001728 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001729 u32 BytesToWrite = 0, uHeaderLen = 0;
1730 u32 uNodeIndex = 0;
1731 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1732 u16 wAID;
1733 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05001734 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001735 PSKeyItem pTransmitKey = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001736 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05001737 int bTKIP_UseGTK = false;
1738 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001739 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05001740 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001741 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05001742 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001743 u32 status;
1744 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05001745 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04001746
Forest Bond92b96792009-06-13 07:38:31 -04001747 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1748
1749 if (pDevice->uAssocCount == 0) {
1750 dev_kfree_skb_irq(skb);
1751 return 0;
1752 }
1753
Andres Moreb902fbf2013-02-25 20:32:51 -05001754 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04001755 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001756 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04001757 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1758
1759 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1760 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1761 // set tx map
1762 pMgmt->abyPSTxMap[0] |= byMask[0];
1763 return 0;
1764 }
Masanari Iida93184692012-08-13 21:21:50 +09001765 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04001766
1767 if (pDevice->byBBType != BB_TYPE_11A)
1768 pDevice->wCurrentRate = RATE_2M;
1769 else
1770 pDevice->wCurrentRate = RATE_24M;
1771 // long preamble type
1772 pDevice->byPreambleType = PREAMBLE_SHORT;
1773
1774 }else {
1775
Andres Moreb902fbf2013-02-25 20:32:51 -05001776 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04001777
1778 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1779
1780 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1781
1782 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1783 // set tx map
1784 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1785 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1786 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
1787 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1788
1789 return 0;
1790 }
1791 // AP rate decided from node
1792 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1793 // tx preamble decided from node
1794
1795 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1796 pDevice->byPreambleType = pDevice->byShortPreamble;
1797
1798 }else {
1799 pDevice->byPreambleType = PREAMBLE_LONG;
1800 }
Andres More4e9b5e22013-02-12 20:36:30 -05001801 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04001802 }
1803 }
1804
Andres Moree269fc22013-02-12 20:36:29 -05001805 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001806 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
1807 dev_kfree_skb_irq(skb);
1808 return 0;
1809 }
1810 }
1811
Tobias Klauser838c2d62014-04-25 11:53:58 +02001812 memcpy(&pDevice->sTxEthHeader, skb->data, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001813
1814//mike add:station mode check eapol-key challenge--->
1815{
Andres Moreb902fbf2013-02-25 20:32:51 -05001816 u8 Protocol_Version; //802.1x Authentication
1817 u8 Packet_Type; //802.1x Authentication
1818 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05001819 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04001820
Charles Clément21ec51f2010-05-18 10:08:14 -07001821 Protocol_Version = skb->data[ETH_HLEN];
1822 Packet_Type = skb->data[ETH_HLEN+1];
1823 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
1824 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 -05001825 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001826 /* 802.1x OR eapol-key challenge frame transfer */
1827 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
1828 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05001829 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04001830 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
1831 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
1832 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05001833 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001834 PRINT_K("WPA ");
1835 }
1836 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001837 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001838 PRINT_K("WPA2(re-keying) ");
1839 }
1840 PRINT_K("Authentication completed!!\n");
1841 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001842 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04001843 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05001844 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001845 PRINT_K("WPA2 Authentication completed!!\n");
1846 }
1847 }
1848 }
1849}
1850//mike add:station mode check eapol-key challenge<---
1851
Andres More4e9b5e22013-02-12 20:36:30 -05001852 if (pDevice->bEncryptionEnable == true) {
1853 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04001854 // get Transmit key
1855 do {
1856 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1857 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1858 pbyBSSID = pDevice->abyBSSID;
1859 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001860 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001861 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001862 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1863 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001864 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1865 break;
1866 }
1867 } else {
1868 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
1869 break;
1870 }
1871 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001872 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
1873 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04001874 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
1875 for (ii = 0; ii< 6; ii++)
1876 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
1877 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
1878
1879 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05001880 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04001881 break;
1882 }
1883 // get group key
1884 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001885 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001886 pTransmitKey = NULL;
1887 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1888 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1889 }
1890 else
1891 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1892 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001893 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001894 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1895 }
Andres Moree269fc22013-02-12 20:36:29 -05001896 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001897 }
1898
Andres Moreb902fbf2013-02-25 20:32:51 -05001899 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04001900
1901 if (pDevice->bFixRate) {
1902 if (pDevice->byBBType == BB_TYPE_11B) {
1903 if (pDevice->uConnectionRate >= RATE_11M) {
1904 pDevice->wCurrentRate = RATE_11M;
1905 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05001906 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04001907 }
1908 } else {
1909 if ((pDevice->byBBType == BB_TYPE_11A) &&
1910 (pDevice->uConnectionRate <= RATE_6M)) {
1911 pDevice->wCurrentRate = RATE_6M;
1912 } else {
1913 if (pDevice->uConnectionRate >= RATE_54M)
1914 pDevice->wCurrentRate = RATE_54M;
1915 else
Andres More3eaca0d2013-02-25 20:32:52 -05001916 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04001917 }
1918 }
1919 }
1920 else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001921 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Forest Bond92b96792009-06-13 07:38:31 -04001922 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05001923 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04001924 // Multicast use highest data rate
1925 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1926 // preamble type
1927 pDevice->byPreambleType = pDevice->byShortPreamble;
1928 }
1929 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001930 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04001931 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1932 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1933 pDevice->byPreambleType = pDevice->byShortPreamble;
1934
1935 }
1936 else {
1937 pDevice->byPreambleType = PREAMBLE_LONG;
1938 }
1939 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
1940 }
1941 else {
1942 if (pDevice->byBBType != BB_TYPE_11A)
1943 pDevice->wCurrentRate = RATE_2M;
1944 else
1945 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
1946 // abyCurrExtSuppRates[]
1947 pDevice->byPreambleType = PREAMBLE_SHORT;
1948 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
1949 }
1950 }
1951 }
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001952 if (pDevice->op_mode == NL80211_IFTYPE_STATION) {
Forest Bond92b96792009-06-13 07:38:31 -04001953 // Infra STA rate decided from AP Node, index = 0
1954 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1955 }
1956 }
1957
Andres Moreceb8c5d2013-03-18 20:33:49 -05001958 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001959 if (pDevice->byBBType != BB_TYPE_11A) {
1960 pDevice->wCurrentRate = RATE_1M;
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001961 pDevice->byTopCCKBasicRate = RATE_1M;
1962 pDevice->byTopOFDMBasicRate = RATE_6M;
1963 } else {
1964 pDevice->wCurrentRate = RATE_6M;
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001965 pDevice->byTopCCKBasicRate = RATE_1M;
1966 pDevice->byTopOFDMBasicRate = RATE_6M;
1967 }
1968 }
Forest Bond92b96792009-06-13 07:38:31 -04001969
Andres More0cbd8d92010-05-06 20:34:29 -03001970 DBG_PRT(MSG_LEVEL_DEBUG,
1971 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
1972 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04001973
1974 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03001975 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001976 }
1977
1978 if (pDevice->wCurrentRate <= RATE_11M) {
1979 byPktType = PK_TYPE_11B;
1980 }
1981
Andres More4e9b5e22013-02-12 20:36:30 -05001982 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001983 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
1984 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05001985 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001986 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04001987 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1988 if (pTransmitKey == NULL) {
1989 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
1990 }
1991 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001992 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001993 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
1994 }
1995 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001996 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
1997 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05001998 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04001999 }
2000 }
2001 }
Forest Bond92b96792009-06-13 07:38:31 -04002002 }
2003 else {
2004
Forest Bond92b96792009-06-13 07:38:31 -04002005 if (pTransmitKey == NULL) {
2006 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2007 dev_kfree_skb_irq(skb);
2008 pStats->tx_dropped++;
2009 return STATUS_FAILURE;
2010 }
Forest Bond92b96792009-06-13 07:38:31 -04002011 }
2012 }
2013
Malcolm Priestleyb674ee12014-05-15 22:49:10 +01002014 pContext = s_vGetFreeContext(pDevice);
2015 if (!pContext) {
2016 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2017 dev_kfree_skb_irq(skb);
2018 return STATUS_RESOURCES;
2019 }
2020
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002021 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002022
Forest Bond92b96792009-06-13 07:38:31 -04002023 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002024 pTX_Buffer, bNeedEncryption,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01002025 skb->len, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002026 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002027 pDevice->wCurrentRate,
2028 &uHeaderLen, &BytesToWrite
2029 );
2030
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002031 if (fConvertedPacket == false) {
2032 pContext->in_use = false;
2033 dev_kfree_skb_irq(skb);
2034 return STATUS_FAILURE;
2035 }
Forest Bond92b96792009-06-13 07:38:31 -04002036
Andres More4e9b5e22013-02-12 20:36:30 -05002037 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002038 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002039 bScheduleCommand((void *) pDevice,
2040 WLAN_CMD_MAC_DISPOWERSAVING,
2041 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002042 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002043 }
2044 }
2045
Andres Moreb902fbf2013-02-25 20:32:51 -05002046 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Malcolm Priestleyca347592014-03-22 09:01:28 +00002047 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite);
Forest Bond92b96792009-06-13 07:38:31 -04002048
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002049 pContext->skb = skb;
2050 pContext->type = CONTEXT_DATA_PACKET;
2051 pContext->buf_len = (u16)BytesToWrite + 4 ; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04002052
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002053 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002054 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002055 (u16)(BytesToWrite-uHeaderLen),
2056 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002057
2058 status = PIPEnsSendBulkOut(pDevice,pContext);
2059
Andres More4e9b5e22013-02-12 20:36:30 -05002060 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002061 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002062
Andres Moreb902fbf2013-02-25 20:32:51 -05002063 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002064 }
2065
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002066 if (status != STATUS_PENDING) {
2067 pContext->in_use = false;
2068 dev_kfree_skb_irq(skb);
2069 return STATUS_FAILURE;
2070 }
Forest Bond92b96792009-06-13 07:38:31 -04002071
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002072
2073 return 0;
Forest Bond92b96792009-06-13 07:38:31 -04002074}