blob: 4ae8c9cabc5497c9a160ea9fcc90695c621f9cb1 [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Valentina Manea3b138852013-11-04 10:44:02 +020067static const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Valentina Manea3b138852013-11-04 10:44:02 +020072static const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Valentina Manea3b138852013-11-04 10:44:02 +020076static const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000099static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000100
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100101static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100102 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100103 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
104 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000106static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500107 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000108 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100110static void s_vFillTxKey(struct vnt_private *pDevice,
111 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
112 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100113 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400114
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000115static void s_vSWencryption(struct vnt_private *pDevice,
116 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
119 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000121static u16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
122 u8 rsv_type, u8 pkt_type, u32 frame_lenght, u16 current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100124static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100125 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
126 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400127
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100128static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100129 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500130 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400131
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100132static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100133 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100135static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000136 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
137 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400138
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000139static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000140 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400141{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000142 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000143 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400144
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400146
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000147 for (ii = 0; ii < priv->cbTD; ii++) {
148 if (!priv->apTD[ii])
149 return NULL;
150
151 context = priv->apTD[ii];
152 if (context->bBoolInUse == false) {
153 context->bBoolInUse = true;
154 memset(context->Data, 0,
155 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
156 return context;
157 }
158 }
159
160 if (ii == priv->cbTD)
161 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000162
Malcolm Priestley5c851382013-11-26 19:12:38 +0000163 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400164}
165
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000166static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
167 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400168{
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000169 struct net_device_stats *stats = &pDevice->stats;
Malcolm Priestley51934e72013-12-09 22:30:14 +0000170 struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info;
Forest Bond92b96792009-06-13 07:38:31 -0400171
Malcolm Priestley51934e72013-12-09 22:30:14 +0000172 pkt_info[byPktNum].fifo_ctl = wFIFOCtl;
173 memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN);
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000174
175 stats->tx_bytes += wPktLength;
Forest Bond92b96792009-06-13 07:38:31 -0400176}
177
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100178static void s_vFillTxKey(struct vnt_private *pDevice,
179 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
180 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
181 struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400182{
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100183 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000184 u32 *pdwIV = (u32 *)pbyIVHead;
185 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500186 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000187 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400188
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100189 /* Fill TXKEY */
190 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100191 return;
Forest Bond92b96792009-06-13 07:38:31 -0400192
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100193 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
194 *pdwIV = pDevice->dwIVCounter;
195 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400196
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100197 switch (pTransmitKey->byCipherSuite) {
198 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100199 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
200 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
201 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
202 pTransmitKey->uKeyLength);
203 } else {
204 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
205 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
206 pTransmitKey->uKeyLength);
207 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
208 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
209 memcpy(pbyBuf+11, pTransmitKey->abyKey,
210 pTransmitKey->uKeyLength);
211 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100212
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100213 memcpy(pDevice->abyPRNG, pbyBuf, 16);
214 }
215 /* Append IV after Mac Header */
216 *pdwIV &= WEP_IV_MASK;
217 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
218 *pdwIV = cpu_to_le32(*pdwIV);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100219
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100220 pDevice->dwIVCounter++;
221 if (pDevice->dwIVCounter > WEP_IV_MASK)
222 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100223
224 break;
225 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100226 pTransmitKey->wTSC15_0++;
227 if (pTransmitKey->wTSC15_0 == 0)
228 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100229
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100230 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
231 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
232 pDevice->abyPRNG);
233 memcpy(pbyBuf, pDevice->abyPRNG, 16);
234
235 /* Make IV */
236 memcpy(pdwIV, pDevice->abyPRNG, 3);
237
238 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
239 0xc0) | 0x20);
240 /* Append IV&ExtIV after Mac Header */
241 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
242
243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
244 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
245
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100246 break;
247 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100248 pTransmitKey->wTSC15_0++;
249 if (pTransmitKey->wTSC15_0 == 0)
250 pTransmitKey->dwTSC47_16++;
251
252 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
253
254 /* Make IV */
255 *pdwIV = 0;
256 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
257 0xc0) | 0x20);
258
259 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
260
261 /* Append IV&ExtIV after Mac Header */
262 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
263
264 if (!mic_hdr)
265 return;
266
267 /* MICHDR0 */
268 mic_hdr->id = 0x59;
269 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
270 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
271
272 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
273 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
274
275 /* MICHDR1 */
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000276 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100277 mic_hdr->hlen = cpu_to_be16(28);
278 else
279 mic_hdr->hlen = cpu_to_be16(22);
280
281 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
282 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
283
284 /* MICHDR2 */
285 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
286 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100287 & 0xc78f);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100288 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100289
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000290 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100291 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
292 }
Forest Bond92b96792009-06-13 07:38:31 -0400293}
294
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000295static void s_vSWencryption(struct vnt_private *pDevice,
296 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400297{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000298 u32 cbICVlen = 4;
299 u32 dwICV = 0xffffffff;
300 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400301
302 if (pTransmitKey == NULL)
303 return;
304
305 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
306 //=======================================================================
307 // Append ICV after payload
308 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500309 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400310 // finally, we must invert dwCRC to get the correct answer
311 *pdwICV = cpu_to_le32(~dwICV);
312 // RC4 encryption
313 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
317 //=======================================================================
318 //Append ICV after payload
319 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500320 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400321 // finally, we must invert dwCRC to get the correct answer
322 *pdwICV = cpu_to_le32(~dwICV);
323 // RC4 encryption
324 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
325 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
326 //=======================================================================
327 }
328}
329
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000330static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100331{
332 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
333 [rate % MAX_RATE]);
334}
335
Forest Bond92b96792009-06-13 07:38:31 -0400336/*byPktType : PK_TYPE_11A 0
337 PK_TYPE_11B 1
338 PK_TYPE_11GB 2
339 PK_TYPE_11GA 3
340*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000341static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
342 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400343{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000344 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400345
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000346 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
347 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400348
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000349 if (pkt_type == PK_TYPE_11B)
350 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
351 (u16)priv->byTopCCKBasicRate);
352 else
353 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
354 (u16)priv->byTopOFDMBasicRate);
355
356 if (need_ack)
357 return data_time + priv->uSIFS + ack_time;
358
359 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400360}
361
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100362static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
363 u32 frame_length, u16 rate, int need_ack)
364{
365 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
366 frame_length, rate, need_ack));
367}
368
Forest Bond92b96792009-06-13 07:38:31 -0400369//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000370static u16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
371 u8 rsv_type, u8 pkt_type, u32 frame_lenght, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400372{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000373 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400374
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000375 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400376
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000377 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
378 frame_lenght, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400379
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000380 if (rsv_type == 0) {
381 rts_time = BBuGetFrameTime(priv->byPreambleType,
382 pkt_type, 20, priv->byTopCCKBasicRate);
383 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
384 pkt_type, 14, priv->byTopCCKBasicRate);
385 } else if (rsv_type == 1) {
386 rts_time = BBuGetFrameTime(priv->byPreambleType,
387 pkt_type, 20, priv->byTopCCKBasicRate);
388 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
389 14, priv->byTopCCKBasicRate);
390 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
391 14, priv->byTopOFDMBasicRate);
392 } else if (rsv_type == 2) {
393 rts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
394 20, priv->byTopOFDMBasicRate);
395 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
396 pkt_type, 14, priv->byTopOFDMBasicRate);
397 } else if (rsv_type == 3) {
398 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
399 14, priv->byTopCCKBasicRate);
400 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
401 14, priv->byTopOFDMBasicRate);
402
403 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
404
405 return rrv_time;
406 }
407
408 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
409
410 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400411}
412
413//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100414static u16 s_uGetDataDuration(struct vnt_private *pDevice,
415 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400416{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100417 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400418
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100419 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100420 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100421 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
422 byPktType, 14, pDevice->byTopCCKBasicRate);
423 else
424 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
425 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100426 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100427 }
Forest Bond92b96792009-06-13 07:38:31 -0400428
Forest Bond92b96792009-06-13 07:38:31 -0400429 return 0;
430}
431
Forest Bond92b96792009-06-13 07:38:31 -0400432//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100433static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000434 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
435 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400436{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000437 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400438
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100439 switch (byDurType) {
440 case RTSDUR_BB:
441 case RTSDUR_BA:
442 case RTSDUR_BA_F0:
443 case RTSDUR_BA_F1:
444 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
445 14, pDevice->byTopCCKBasicRate);
446 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
447 s_uGetTxRsvTime(pDevice, byPktType,
448 cbFrameLength, wRate, bNeedAck);
449 break;
Forest Bond92b96792009-06-13 07:38:31 -0400450
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100451 case RTSDUR_AA:
452 case RTSDUR_AA_F0:
453 case RTSDUR_AA_F1:
454 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
455 14, pDevice->byTopOFDMBasicRate);
456 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
457 s_uGetTxRsvTime(pDevice, byPktType,
458 cbFrameLength, wRate, bNeedAck);
459 break;
Forest Bond92b96792009-06-13 07:38:31 -0400460
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100461 case CTSDUR_BA:
462 case CTSDUR_BA_F0:
463 case CTSDUR_BA_F1:
464 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100465 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100466 break;
Forest Bond92b96792009-06-13 07:38:31 -0400467
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100468 default:
469 break;
470 }
Forest Bond92b96792009-06-13 07:38:31 -0400471
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100472 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400473}
474
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100475static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
476 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
477{
478 /* Get SignalField,ServiceField,Length */
479 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
480 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
481 PK_TYPE_11B, &buf->b);
482
483 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000484 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
485 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100486
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000487 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
488 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100489 priv->byTopCCKBasicRate);
490
Malcolm Priestley4e011172014-03-18 19:24:55 +0000491 return buf->duration_a;
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100492}
493
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100494static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
495 u16 rate, struct vnt_tx_datahead_g_fb *buf,
496 u32 frame_len, int need_ack)
497{
498 /* Get SignalField,ServiceField,Length */
499 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
500
501 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
502 PK_TYPE_11B, &buf->b);
503
504 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000505 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
506 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100507
Malcolm Priestley4e011172014-03-18 19:24:55 +0000508 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
509 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100510
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000511 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
512 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100513 priv->byTopCCKBasicRate);
514
Malcolm Priestley4e011172014-03-18 19:24:55 +0000515 return buf->duration_a;
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100516}
517
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100518static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
519 u16 rate, struct vnt_tx_datahead_a_fb *buf,
520 u32 frame_len, int need_ack)
521{
522 /* Get SignalField,ServiceField,Length */
523 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
524 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000525 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100526
Malcolm Priestley4e011172014-03-18 19:24:55 +0000527 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
528 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100529
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000530 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100531
Malcolm Priestley4e011172014-03-18 19:24:55 +0000532 return buf->duration;
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100533}
534
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100535static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
536 u16 rate, struct vnt_tx_datahead_ab *buf,
537 u32 frame_len, int need_ack)
538{
539 /* Get SignalField,ServiceField,Length */
540 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
541 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000542 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100543
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000544 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100545
Malcolm Priestley4e011172014-03-18 19:24:55 +0000546 return buf->duration;
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100547}
548
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100549static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
550 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000551 __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100552{
553 rts->duration = duration;
554 rts->frame_control = TYPE_CTL_RTS;
555
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000556 if (priv->op_mode == NL80211_IFTYPE_ADHOC ||
557 priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100558 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
559 else
560 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
561
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000562 if (priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100563 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
564 else
565 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
566
567 return 0;
568}
569
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100570static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100571 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
572 u8 pkt_type, u32 frame_len, int need_ack,
573 u16 current_rate, u8 fb_option)
574{
575 u16 rts_frame_len = 20;
576
577 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
578 PK_TYPE_11B, &buf->b);
579 BBvCalculateParameter(priv, rts_frame_len,
580 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
581
Malcolm Priestley4e011172014-03-18 19:24:55 +0000582 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100583 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000584 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100585 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000586 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100587 pkt_type, current_rate, need_ack, fb_option);
588
Malcolm Priestley4e011172014-03-18 19:24:55 +0000589 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100590
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100591 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
592 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100593}
594
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100595static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100596 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
597 u8 pkt_type, u32 frame_len, int need_ack,
598 u16 current_rate, u8 fb_option)
599{
600 u16 rts_frame_len = 20;
601
602 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
603 PK_TYPE_11B, &buf->b);
604 BBvCalculateParameter(priv, rts_frame_len,
605 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
606
607
Malcolm Priestley4e011172014-03-18 19:24:55 +0000608 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100609 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000610 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100611 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000612 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100613 pkt_type, current_rate, need_ack, fb_option);
614
615
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000616 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100617 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000618 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100619 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000620 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100621 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000622 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100623 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100624
Malcolm Priestley4e011172014-03-18 19:24:55 +0000625 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100626
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100627 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
628 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100629}
630
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100631static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100632 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
633 u8 pkt_type, u32 frame_len, int need_ack,
634 u16 current_rate, u8 fb_option)
635{
636 u16 rts_frame_len = 20;
637
638 BBvCalculateParameter(priv, rts_frame_len,
639 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
640
Malcolm Priestley4e011172014-03-18 19:24:55 +0000641 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100642 pkt_type, current_rate, need_ack, fb_option);
643
Malcolm Priestley4e011172014-03-18 19:24:55 +0000644 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100645
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100646 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
647 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100648}
649
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100650static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100651 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
652 u8 pkt_type, u32 frame_len, int need_ack,
653 u16 current_rate, u8 fb_option)
654{
655 u16 rts_frame_len = 20;
656
657 BBvCalculateParameter(priv, rts_frame_len,
658 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
659
Malcolm Priestley4e011172014-03-18 19:24:55 +0000660 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100661 pkt_type, current_rate, need_ack, fb_option);
662
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000663 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100664 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100665
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000666 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100667 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100668
Malcolm Priestley4e011172014-03-18 19:24:55 +0000669 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100670
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100671 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
672 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100673}
674
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100675static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100676 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500677 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400678{
Forest Bond92b96792009-06-13 07:38:31 -0400679
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100680 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100681 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400682
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100683 /* Note: So far RTSHead doesn't appear in ATIM
684 * & Beacom DMA, so we don't need to take them
685 * into account.
686 * Otherwise, we need to modified codes for them.
687 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100688 switch (byPktType) {
689 case PK_TYPE_11GB:
690 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100691 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100692 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100693 psEthHeader, byPktType, cbFrameLength,
694 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100695 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100696 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100697 psEthHeader, byPktType, cbFrameLength,
698 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100699 break;
700 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100701 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100702 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100703 psEthHeader, byPktType, cbFrameLength,
704 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100705 break;
706 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100707 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100708 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100709 psEthHeader, byPktType, cbFrameLength,
710 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100711 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100712
713 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400714}
715
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100716static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100717 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
718 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400719{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000720 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400721
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100722 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100723 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400724
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100725 if (byFBOption != AUTO_FB_NONE) {
726 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100727 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100728 /* Get SignalField,ServiceField,Length */
729 BBvCalculateParameter(pDevice, uCTSFrameLen,
730 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000731 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100732 cbFrameLength, byPktType,
733 wCurrentRate, bNeedAck, byFBOption);
734 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000735 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100736 CTSDUR_BA_F0, cbFrameLength, byPktType,
737 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100738 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000739 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100740 CTSDUR_BA_F1, cbFrameLength, byPktType,
741 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100742 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000743 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100744 pBuf->data.frame_control = TYPE_CTL_CTS;
745 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100746
747 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
748 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100749 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100750 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100751 /* Get SignalField,ServiceField,Length */
752 BBvCalculateParameter(pDevice, uCTSFrameLen,
753 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100754 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000755 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100756 CTSDUR_BA, cbFrameLength, byPktType,
757 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100758 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000759 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100760 pBuf->data.frame_control = TYPE_CTL_CTS;
761 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100762
763 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
764 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400765 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100766
767 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400768}
769
Forest Bond92b96792009-06-13 07:38:31 -0400770/*+
771 *
772 * Description:
773 * Generate FIFO control for MAC & Baseband controller
774 *
775 * Parameters:
776 * In:
777 * pDevice - Pointer to adpater
778 * pTxDataHead - Transmit Data Buffer
779 * pTxBufHead - pTxBufHead
780 * pvRrvTime - pvRrvTime
781 * pvRTS - RTS Buffer
782 * pCTS - CTS Buffer
783 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
784 * bNeedACK - If need ACK
785 * uDMAIdx - DMA Index
786 * Out:
787 * none
788 *
789 * Return Value: none
790 *
791-*/
Andres Morecc856e62010-05-17 21:34:01 -0300792
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100793static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100794 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100795 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
796 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400797{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100798 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100799 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000800 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000801 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400802
Malcolm Priestley92928f12013-10-07 20:14:01 +0100803 pFifoHead->wReserved = wCurrentRate;
804 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400805
Malcolm Priestley92928f12013-10-07 20:14:01 +0100806 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
807 byFBOption = AUTO_FB_0;
808 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
809 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400810
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100811 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100812 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100813
Malcolm Priestley92928f12013-10-07 20:14:01 +0100814 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
815 if (need_rts) {
816 struct vnt_rrv_time_rts *pBuf =
817 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100818
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000819 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100820 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000821 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100822 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000823 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100824 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100825
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000826 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100827 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000828 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100829 PK_TYPE_11B, cbFrameSize,
830 pDevice->byTopCCKBasicRate, bNeedACK);
831
832 if (need_mic) {
833 *mic_hdr = &tx_buffer->
834 tx_head.tx_rts.tx.mic.hdr;
835 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
836 } else {
837 head = &tx_buffer->tx_head.tx_rts.tx.head;
838 }
839
840 /* Fill RTS */
841 return s_vFillRTSHead(pDevice, byPktType, head,
842 cbFrameSize, bNeedACK, psEthHeader,
843 wCurrentRate, byFBOption);
844
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100845 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100846 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
847 tx_head.tx_cts.cts;
848
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000849 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100850 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000851 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100852 PK_TYPE_11B, cbFrameSize,
853 pDevice->byTopCCKBasicRate, bNeedACK);
854
Malcolm Priestley372108e2014-03-18 19:25:00 +0000855 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100856 byPktType, cbFrameSize, wCurrentRate);
857
858 if (need_mic) {
859 *mic_hdr = &tx_buffer->
860 tx_head.tx_cts.tx.mic.hdr;
861 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
862 } else {
863 head = &tx_buffer->tx_head.tx_cts.tx.head;
864 }
865
866 /* Fill CTS */
867 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
868 head, cbFrameSize, bNeedACK, wCurrentRate,
869 byFBOption);
870 }
871 } else if (byPktType == PK_TYPE_11A) {
872 if (need_mic) {
873 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
874 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
875 } else {
876 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100877 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100878
Malcolm Priestley92928f12013-10-07 20:14:01 +0100879 if (need_rts) {
880 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
881 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100882
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000883 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100884 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100885
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000886 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100887 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
888
889 /* Fill RTS */
890 return s_vFillRTSHead(pDevice, byPktType, head,
891 cbFrameSize, bNeedACK, psEthHeader,
892 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100893 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100894 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
895 tx_head.tx_ab.ab;
896
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000897 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100898 PK_TYPE_11A, cbFrameSize,
899 wCurrentRate, bNeedACK);
900
901 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
902 wCurrentRate, &head->data_head_a_fb,
903 cbFrameSize, bNeedACK);
904 }
905 } else if (byPktType == PK_TYPE_11B) {
906 if (need_mic) {
907 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
908 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
909 } else {
910 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100911 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100912
Malcolm Priestley92928f12013-10-07 20:14:01 +0100913 if (need_rts) {
914 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
915 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100916
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000917 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100918 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100919
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000920 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100921 PK_TYPE_11B, cbFrameSize, wCurrentRate,
922 bNeedACK);
923
924 /* Fill RTS */
925 return s_vFillRTSHead(pDevice, byPktType, head,
926 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100927 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100928 } else {
929 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
930 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100931
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000932 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100933 PK_TYPE_11B, cbFrameSize,
934 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100935
Malcolm Priestley92928f12013-10-07 20:14:01 +0100936 return vnt_rxtx_datahead_ab(pDevice, byPktType,
937 wCurrentRate, &head->data_head_ab,
938 cbFrameSize, bNeedACK);
939 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100940 }
941
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100942 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400943}
944/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500945 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500946 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300947 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400948*/
949
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000950static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100951 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100952 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
953 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
954 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400955{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100956 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000957 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
958 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000959 u32 cb802_1_H_len;
960 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
961 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100962 int bNeedACK;
963 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000964 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
965 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
966 u8 abySNAP_Bridgetunnel[ETH_ALEN]
967 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
968 u32 uDuration;
969 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100970 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000971 u8 byFBOption = AUTO_FB_NONE, byFragType;
972 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100973 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000974 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500975 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100976
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100977 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400978
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000979 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500980 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
981 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000982 }
Forest Bond92b96792009-06-13 07:38:31 -0400983
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000984 /* Get pkt type */
985 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
986 cb802_1_H_len = 8;
987 else
988 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400989
Charles Clément21ec51f2010-05-18 10:08:14 -0700990 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400991
992 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500993 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400994
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000995 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC ||
996 pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500997 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500998 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -0300999 pTxBufHead->wFIFOCtl =
1000 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1001 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001002 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001003 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1004 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001005 } else {
1006 /* MSDUs in Infra mode always need ACK */
1007 bNeedACK = true;
1008 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1009 }
Forest Bond92b96792009-06-13 07:38:31 -04001010
1011 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1012
Forest Bond92b96792009-06-13 07:38:31 -04001013 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001014 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1015
Andres More3eaca0d2013-02-25 20:32:52 -05001016 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001017
1018 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001019 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001020 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1021 }
1022
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001023 /* Set Auto Fallback Ctl */
1024 if (wCurrentRate >= RATE_18M) {
1025 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1026 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1027
1028 pDevice->tx_rate_fb0 =
1029 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1030 pDevice->tx_rate_fb1 =
1031 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1032
1033 byFBOption = AUTO_FB_0;
1034 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1035 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1036 pDevice->tx_rate_fb0 =
1037 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1038 pDevice->tx_rate_fb1 =
1039 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1040
1041 byFBOption = AUTO_FB_1;
1042 }
1043 }
Forest Bond92b96792009-06-13 07:38:31 -04001044
Andres More4e9b5e22013-02-12 20:36:30 -05001045 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001046 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1047 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1048 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1049 }
1050 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1051 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1052 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1053 }
1054 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1055 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1056 }
1057 }
1058 }
1059
Forest Bond92b96792009-06-13 07:38:31 -04001060 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1061 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1062 cbIVlen = 4;
1063 cbICVlen = 4;
1064 }
1065 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1066 cbIVlen = 8;//IV+ExtIV
1067 cbMIClen = 8;
1068 cbICVlen = 4;
1069 }
1070 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1071 cbIVlen = 8;//RSN Header
1072 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001073 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001074 }
Andres Moree269fc22013-02-12 20:36:29 -05001075 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001076 //MAC Header should be padding 0 to DW alignment.
1077 uPadding = 4 - (cbMACHdLen%4);
1078 uPadding %= 4;
1079 }
1080 }
1081
1082 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1083
Andres Moree269fc22013-02-12 20:36:29 -05001084 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1085 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001086 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001087 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001088 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1089 }
1090
Andres Moreb902fbf2013-02-25 20:32:51 -05001091 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001092 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1093
Forest Bond92b96792009-06-13 07:38:31 -04001094 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1095 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001096 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001097 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001098 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001099 }
1100 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001101 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001102 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001103 }
1104 } else {
1105 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001106 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001107 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001108 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001109 }
Andres Moree269fc22013-02-12 20:36:29 -05001110 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001111 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001112 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001113 }
1114 } // Auto Fall Back
1115 }
1116 else {//802.11a/b packet
1117 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001118 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001119 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001120 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001121 }
Andres Moree269fc22013-02-12 20:36:29 -05001122 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001123 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001124 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001125 }
1126 } else {
1127 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001128 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001129 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001130 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001131 }
Andres Moree269fc22013-02-12 20:36:29 -05001132 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001133 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001134 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001135 }
1136 } // Auto Fall Back
1137 }
1138
Andres Moreb902fbf2013-02-25 20:32:51 -05001139 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1140 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1141 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001142
Forest Bond92b96792009-06-13 07:38:31 -04001143 //=========================
1144 // No Fragmentation
1145 //=========================
1146 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1147 byFragType = FRAGCTL_NONFRAG;
1148 //uDMAIdx = TYPE_AC0DMA;
1149 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1150
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001151 /* Fill FIFO, RrvTime, RTS and CTS */
1152 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1153 tx_buffer, &pMICHDR, cbMICHDR,
1154 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001155
Forest Bond92b96792009-06-13 07:38:31 -04001156 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001157 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001158 byFragType, uDMAIdx, 0);
1159
Andres More4e9b5e22013-02-12 20:36:30 -05001160 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001161 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001162 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001163 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001164
1165 if (pDevice->bEnableHostWEP) {
1166 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1167 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1168 }
1169 }
1170
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001171 /* 802.1H */
1172 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001173 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001174 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001175 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001176 abySNAP_Bridgetunnel, 6);
1177 else
1178 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001179
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001180 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001181
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001182 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1183 }
Forest Bond92b96792009-06-13 07:38:31 -04001184
Forest Bond92b96792009-06-13 07:38:31 -04001185 if (pPacket != NULL) {
1186 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001187 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001188 (pPacket + ETH_HLEN),
1189 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001190 );
1191
1192 } else {
1193 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001194 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001195 }
1196
Andres More4e9b5e22013-02-12 20:36:30 -05001197 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001198
1199 ///////////////////////////////////////////////////////////////////
1200
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001201 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1202 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1203 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1204 }
Forest Bond92b96792009-06-13 07:38:31 -04001205 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001206 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1207 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001208 }
1209 else {
Andres More52a7e642013-02-25 20:32:53 -05001210 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1211 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001212 }
1213 // DO Software Michael
1214 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001215 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001216 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001217 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001218 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1219 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001220
1221 ///////////////////////////////////////////////////////////////////
1222
1223 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1224 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001225 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001226 //}
1227 //DBG_PRN_GRP12(("\n\n\n"));
1228
1229 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1230
Andres More52a7e642013-02-25 20:32:53 -05001231 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1232 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001233
1234 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1235 MIC_vUnInit();
1236
Andres More4e9b5e22013-02-12 20:36:30 -05001237 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001238 *pdwMIC_L = 0;
1239 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001240 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001241 }
1242 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1243 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1244 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1245 }
1246
Andres More4e9b5e22013-02-12 20:36:30 -05001247 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001248
Andres More3eaca0d2013-02-25 20:32:52 -05001249 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001250
Andres More4e9b5e22013-02-12 20:36:30 -05001251 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1252 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1253 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001254 cbFrameSize -= cbICVlen;
1255 }
1256
Forest Bond92b96792009-06-13 07:38:31 -04001257 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001258
1259 *pcbHeaderLen = cbHeaderLength;
1260 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1261
Forest Bond92b96792009-06-13 07:38:31 -04001262 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001263 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001264
Andres More4e9b5e22013-02-12 20:36:30 -05001265 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001266
1267}
1268
Forest Bond92b96792009-06-13 07:38:31 -04001269/*+
1270 *
1271 * Description:
1272 * Translate 802.3 to 802.11 header
1273 *
1274 * Parameters:
1275 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001276 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001277 * dwTxBufferAddr - Transmit Buffer
1278 * pPacket - Packet from upper layer
1279 * cbPacketSize - Transmit Data Length
1280 * Out:
1281 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1282 * pcbAppendPayload - size of append payload for 802.1H translation
1283 *
1284 * Return Value: none
1285 *
1286-*/
1287
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001288static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001289 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001290 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001291{
Andres More1cac4a42013-03-18 20:33:50 -05001292 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001293
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001294 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001295
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001296 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001297 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001298 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001299 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001300 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1301 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001302 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001303 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001304 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001305 } else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001306 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001307 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001308 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001309 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001310 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001311 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001312 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001313 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001314 &(pDevice->abyBSSID[0]),
1315 ETH_ALEN);
1316 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001317 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001318 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001319 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001320 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001321 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001322 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001323 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001324 &(pDevice->abyBSSID[0]),
1325 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001326 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001327 }
1328 }
1329
1330 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001331 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001332
Andres More1cac4a42013-03-18 20:33:50 -05001333 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001334
Andres More1cac4a42013-03-18 20:33:50 -05001335 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001336
1337 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001338 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001339
1340 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1341 pDevice->wSeqCounter++;
1342 if (pDevice->wSeqCounter > 0x0fff)
1343 pDevice->wSeqCounter = 0;
1344 }
1345
1346 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001347 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001348 }
1349}
1350
Forest Bond92b96792009-06-13 07:38:31 -04001351/*+
1352 *
1353 * Description:
1354 * Request instructs a MAC to transmit a 802.11 management packet through
1355 * the adapter onto the medium.
1356 *
1357 * Parameters:
1358 * In:
1359 * hDeviceContext - Pointer to the adapter
1360 * pPacket - A pointer to a descriptor for the packet to transmit
1361 * Out:
1362 * none
1363 *
Andres Moree269fc22013-02-12 20:36:29 -05001364 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001365 *
1366-*/
1367
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001368CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1369 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001370{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001371 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001372 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001373 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001374 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001375 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001376 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001377 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001378 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001379 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001380 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001381 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1382 u32 uPadding = 0;
1383 u16 wTxBufSize;
1384 u32 cbMacHdLen;
1385 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001386
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001387 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001388
1389 if (NULL == pContext) {
1390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1391 return CMD_STATUS_RESOURCES;
1392 }
1393
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001394 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001395 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001396 pTxBufHead = &pTX_Buffer->fifo_head;
1397 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1398 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001399
1400 if (pDevice->byBBType == BB_TYPE_11A) {
1401 wCurrentRate = RATE_6M;
1402 byPktType = PK_TYPE_11A;
1403 } else {
1404 wCurrentRate = RATE_1M;
1405 byPktType = PK_TYPE_11B;
1406 }
1407
1408 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1409 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1410 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1411 // to set power here.
1412 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1413 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1414 } else {
1415 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1416 }
1417 pDevice->wCurrentRate = wCurrentRate;
1418
Forest Bond92b96792009-06-13 07:38:31 -04001419 //Set packet type
1420 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1421 pTxBufHead->wFIFOCtl = 0;
1422 }
1423 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1424 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1425 }
1426 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1427 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1428 }
1429 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1430 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1431 }
1432
1433 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1434 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1435
Andres More22040bb2010-08-02 20:21:44 -03001436 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001437 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001438 }
1439 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001440 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001441 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1442 };
1443
1444 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1445 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1446
1447 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1448 //Set Preamble type always long
1449 //pDevice->byPreambleType = PREAMBLE_LONG;
1450 // probe-response don't retry
1451 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001452 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001453 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1454 //}
1455 }
1456
1457 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1458
1459 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001460 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001461 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1462 } else {
1463 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1464 }
1465
1466 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001467 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001468
1469 // Notes:
1470 // Although spec says MMPDU can be fragmented; In most case,
1471 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001472
1473 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1474 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1475 cbIVlen = 4;
1476 cbICVlen = 4;
1477 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1478 }
1479 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1480 cbIVlen = 8;//IV+ExtIV
1481 cbMIClen = 8;
1482 cbICVlen = 4;
1483 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1484 //We need to get seed here for filling TxKey entry.
1485 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1486 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1487 }
1488 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1489 cbIVlen = 8;//RSN Header
1490 cbICVlen = 8;//MIC
1491 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001492 }
1493 //MAC Header should be padding 0 to DW alignment.
1494 uPadding = 4 - (cbMacHdLen%4);
1495 uPadding %= 4;
1496 }
1497
1498 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1499
1500 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001501 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001502 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1503 }
1504 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1505
1506 //Set RrvTime/RTS/CTS Buffer
1507 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001508 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001509 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001510 }
1511 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001512 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001513 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001514 }
1515
Andres Moreceb8c5d2013-03-18 20:33:49 -05001516 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001517 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1518 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001519 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001520 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1521 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001522 //=========================
1523 // No Fragmentation
1524 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001525 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001526
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001527 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001528 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001529 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001530 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001531
Andres More1cac4a42013-03-18 20:33:50 -05001532 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001533
1534 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1535
1536 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001537 u8 * pbyIVHead;
1538 u8 * pbyPayloadHead;
1539 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001540 PSKeyItem pTransmitKey = NULL;
1541
Andres Moreb902fbf2013-02-25 20:32:51 -05001542 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1543 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001544 do {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001545 if (pDevice->op_mode == NL80211_IFTYPE_STATION &&
1546 pDevice->bLinkPass == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001547 pbyBSSID = pDevice->abyBSSID;
1548 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001549 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001550 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001551 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001552 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1553 break;
1554 }
1555 } else {
1556 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1557 break;
1558 }
1559 }
1560 // get group key
1561 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001562 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001563 pTransmitKey = NULL;
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode);
Forest Bond92b96792009-06-13 07:38:31 -04001565 } else {
1566 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1567 }
Andres Moree269fc22013-02-12 20:36:29 -05001568 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001569 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001570 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001571 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001572
Jim Lieb3e362592009-08-12 14:54:11 -07001573 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001574 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001575 cbFrameBodySize);
1576 }
1577 else {
1578 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001579 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001580 }
1581
Andres More1cac4a42013-03-18 20:33:50 -05001582 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001583 pDevice->wSeqCounter++ ;
1584 if (pDevice->wSeqCounter > 0x0fff)
1585 pDevice->wSeqCounter = 0;
1586
1587 if (bIsPSPOLL) {
1588 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001589 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001590 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1591 // in the same place of other packet's Duration-field).
1592 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001593 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001594 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1595 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001596 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001597 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00001598 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001599 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1600 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001601 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1602 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001603 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001604 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1605 }
Forest Bond92b96792009-06-13 07:38:31 -04001606 }
1607
Andres More3eaca0d2013-02-25 20:32:52 -05001608 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001609 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001610 pTX_Buffer->byType = 0x00;
1611
1612 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00001613 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001614 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001615
Andres More1cac4a42013-03-18 20:33:50 -05001616 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001617 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1618 &pMACHeader->addr1[0], (u16)cbFrameSize,
1619 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001620 }
1621 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001622 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1623 &pMACHeader->addr3[0], (u16)cbFrameSize,
1624 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001625 }
1626
1627 PIPEnsSendBulkOut(pDevice,pContext);
1628 return CMD_STATUS_PENDING;
1629}
1630
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001631CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1632 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001633{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001634 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001635 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001636 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1637 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001638 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001639 u16 wCurrentRate;
1640 u32 cbFrameBodySize;
1641 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001642 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001643 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001644
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001645 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001646 if (NULL == pContext) {
1647 status = CMD_STATUS_RESOURCES;
1648 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1649 return status ;
1650 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001651
1652 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001653 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001654
1655 cbFrameBodySize = pPacket->cbPayloadLen;
1656
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001657 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001658
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001659 if (pDevice->byBBType == BB_TYPE_11A) {
1660 wCurrentRate = RATE_6M;
1661
1662 /* Get SignalField,ServiceField,Length */
1663 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1664 PK_TYPE_11A, &short_head->ab);
1665
1666 /* Get Duration and TimeStampOff */
1667 short_head->duration = s_uGetDataDuration(pDevice,
1668 PK_TYPE_11A, false);
1669 short_head->time_stamp_off =
1670 vnt_time_stamp_off(pDevice, wCurrentRate);
1671 } else {
1672 wCurrentRate = RATE_1M;
1673 short_head->fifo_ctl |= FIFOCTL_11B;
1674
1675 /* Get SignalField,ServiceField,Length */
1676 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1677 PK_TYPE_11B, &short_head->ab);
1678
1679 /* Get Duration and TimeStampOff */
1680 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001681 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001682 short_head->time_stamp_off =
1683 vnt_time_stamp_off(pDevice, wCurrentRate);
1684 }
1685
Forest Bond92b96792009-06-13 07:38:31 -04001686
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001687 /* Generate Beacon Header */
1688 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001689
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001690 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1691
1692 pMACHeader->duration_id = 0;
1693 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1694 pDevice->wSeqCounter++;
1695 if (pDevice->wSeqCounter > 0x0fff)
1696 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001697
1698 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1699
Andres More3eaca0d2013-02-25 20:32:52 -05001700 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001701 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001702 pTX_Buffer->byType = 0x01;
1703
1704 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00001705 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001706 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001707
1708 PIPEnsSendBulkOut(pDevice,pContext);
1709 return CMD_STATUS_PENDING;
1710
1711}
1712
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001713void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1714{
1715 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001716 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001717 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001718 u8 byPktType;
1719 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001720 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001721 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001722 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001723 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001724 u32 cbFrameSize;
1725 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1726 u32 uPadding = 0;
1727 u32 cbMICHDR = 0, uLength = 0;
1728 u32 dwMICKey0, dwMICKey1;
1729 u32 dwMIC_Priority;
1730 u32 *pdwMIC_L, *pdwMIC_R;
1731 u16 wTxBufSize;
1732 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001733 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001734 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001735 u32 wCurrentRate = RATE_1M;
1736 PUWLAN_80211HDR p80211Header;
1737 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001738 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001739 SKeyItem STempKey;
1740 PSKeyItem pTransmitKey = NULL;
1741 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1742 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001743 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001744
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001745 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001746
1747 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1748 cbFrameBodySize = 0;
1749 }
1750 else {
1751 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1752 }
1753 p80211Header = (PUWLAN_80211HDR)skb->data;
1754
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001755 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001756
1757 if (NULL == pContext) {
1758 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1759 dev_kfree_skb_irq(skb);
1760 return ;
1761 }
1762
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001763 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001764 pTxBufHead = &pTX_Buffer->fifo_head;
1765 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1766 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001767
1768 if (pDevice->byBBType == BB_TYPE_11A) {
1769 wCurrentRate = RATE_6M;
1770 byPktType = PK_TYPE_11A;
1771 } else {
1772 wCurrentRate = RATE_1M;
1773 byPktType = PK_TYPE_11B;
1774 }
1775
1776 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1777 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1778 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1779 // to set power here.
1780 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1781 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1782 } else {
1783 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1784 }
1785
1786 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1787
1788 //Set packet type
1789 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1790 pTxBufHead->wFIFOCtl = 0;
1791 }
1792 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1793 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1794 }
1795 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1796 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1797 }
1798 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1799 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1800 }
1801
1802 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1803 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1804
Andres More22040bb2010-08-02 20:21:44 -03001805 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001806 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001807 if (pDevice->bEnableHostWEP) {
1808 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001809 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001810 }
Forest Bond92b96792009-06-13 07:38:31 -04001811 }
1812 else {
1813 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001814 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001815 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001816 }
Andres More4e9b5e22013-02-12 20:36:30 -05001817 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001818 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1819 };
1820
1821 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1822 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1823
1824 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1825 //Set Preamble type always long
1826 //pDevice->byPreambleType = PREAMBLE_LONG;
1827
1828 // probe-response don't retry
1829 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001830 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001831 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1832 //}
1833 }
1834
1835 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1836
1837 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001838 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001839 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1840 } else {
1841 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1842 }
1843
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001844 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001845 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1846
1847 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1848 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1849 }
1850
1851 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1852 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1853 }
1854
1855 if (cbExtSuppRate >0) {
1856 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1857 }
1858 }
1859
Forest Bond92b96792009-06-13 07:38:31 -04001860 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001861 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001862
1863 // Notes:
1864 // Although spec says MMPDU can be fragmented; In most case,
1865 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001866
Forest Bond92b96792009-06-13 07:38:31 -04001867 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1868 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1869 cbIVlen = 4;
1870 cbICVlen = 4;
1871 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1872 }
1873 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1874 cbIVlen = 8;//IV+ExtIV
1875 cbMIClen = 8;
1876 cbICVlen = 4;
1877 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1878 //We need to get seed here for filling TxKey entry.
1879 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1880 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1881 }
1882 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1883 cbIVlen = 8;//RSN Header
1884 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001885 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001886 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001887 }
1888 //MAC Header should be padding 0 to DW alignment.
1889 uPadding = 4 - (cbMacHdLen%4);
1890 uPadding %= 4;
1891 }
1892
1893 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1894
1895 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001896 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001897 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1898 }
1899 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1900
Forest Bond92b96792009-06-13 07:38:31 -04001901 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001902 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001903 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001904
1905 }
1906 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001907 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001908 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001909 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001910 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001911 &(p80211Header->sA3.abyAddr1[0]),
1912 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001913 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001914 &(p80211Header->sA3.abyAddr2[0]),
1915 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001916 //=========================
1917 // No Fragmentation
1918 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001919 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001920
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001921 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001922 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001923 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001924 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001925
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001926 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001927
1928 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1929
Andres Moreb902fbf2013-02-25 20:32:51 -05001930 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1931 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1932 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001933
1934 // Copy the Packet into a tx Buffer
1935 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1936
1937 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001938 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001939 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1940
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001941 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001942 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1943 if (cbExtSuppRate != 0) {
1944 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1945 memcpy((pbyPayloadHead + cbFrameBodySize),
1946 pMgmt->abyCurrSuppRates,
1947 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1948 );
1949 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1950 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1951 pMgmt->abyCurrExtSuppRates,
1952 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1953 );
1954 }
1955 }
1956
1957 // Set wep
1958 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1959
1960 if (pDevice->bEnableHostWEP) {
1961 pTransmitKey = &STempKey;
1962 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1963 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1964 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1965 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1966 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1967 memcpy(pTransmitKey->abyKey,
1968 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1969 pTransmitKey->uKeyLength
1970 );
1971 }
1972
1973 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1974
Andres More52a7e642013-02-25 20:32:53 -05001975 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1976 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001977
1978 // DO Software Michael
1979 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001980 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001981 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001982 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001983 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1984 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001985
1986 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1987
1988 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1989
Andres More52a7e642013-02-25 20:32:53 -05001990 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1991 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001992
1993 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1994 MIC_vUnInit();
1995
Andres More4e9b5e22013-02-12 20:36:30 -05001996 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001997 *pdwMIC_L = 0;
1998 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001999 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002000 }
2001
2002 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2003 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002004 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2005 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002006
2007 }
2008
Malcolm Priestley3ba09382013-10-15 21:41:38 +01002009 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002010 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002011
2012 if (pDevice->bEnableHostWEP) {
2013 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2014 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2015 }
2016
2017 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002018 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002019 }
2020 }
2021
Andres More1cac4a42013-03-18 20:33:50 -05002022 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002023 pDevice->wSeqCounter++ ;
2024 if (pDevice->wSeqCounter > 0x0fff)
2025 pDevice->wSeqCounter = 0;
2026
Forest Bond92b96792009-06-13 07:38:31 -04002027 if (bIsPSPOLL) {
2028 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2029 // of FIFO control header.
2030 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2031 // in the same place of other packet's Duration-field).
2032 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002033 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002034 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2035 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00002036 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002037 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00002038 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002039 cpu_to_le16(p80211Header->sA2.wDurationID);
2040 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002041 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2042 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00002043 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002044 cpu_to_le16(p80211Header->sA2.wDurationID);
2045 }
Forest Bond92b96792009-06-13 07:38:31 -04002046 }
2047
Andres More3eaca0d2013-02-25 20:32:52 -05002048 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002049 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002050 pTX_Buffer->byType = 0x00;
2051
2052 pContext->pPacket = skb;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002053 pContext->type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002054 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002055
Andres More1cac4a42013-03-18 20:33:50 -05002056 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002057 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2058 &pMACHeader->addr1[0], (u16)cbFrameSize,
2059 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002060 }
2061 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002062 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2063 &pMACHeader->addr3[0], (u16)cbFrameSize,
2064 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002065 }
2066 PIPEnsSendBulkOut(pDevice,pContext);
2067 return ;
2068
2069}
2070
Forest Bond92b96792009-06-13 07:38:31 -04002071//TYPE_AC0DMA data tx
2072/*
2073 * Description:
2074 * Tx packet via AC0DMA(DMA1)
2075 *
2076 * Parameters:
2077 * In:
2078 * pDevice - Pointer to the adapter
2079 * skb - Pointer to tx skb packet
2080 * Out:
2081 * void
2082 *
2083 * Return Value: NULL
2084 */
2085
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002086int nsDMA_tx_packet(struct vnt_private *pDevice,
2087 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002088{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002089 struct net_device_stats *pStats = &pDevice->stats;
2090 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002091 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002092 u32 BytesToWrite = 0, uHeaderLen = 0;
2093 u32 uNodeIndex = 0;
2094 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2095 u16 wAID;
2096 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002097 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002098 PSKeyItem pTransmitKey = NULL;
2099 SKeyItem STempKey;
2100 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002101 int bTKIP_UseGTK = false;
2102 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002103 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002104 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002105 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002106 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002107 u32 status;
2108 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002109 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002110
Forest Bond92b96792009-06-13 07:38:31 -04002111 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2112
2113 if (pDevice->uAssocCount == 0) {
2114 dev_kfree_skb_irq(skb);
2115 return 0;
2116 }
2117
Andres Moreb902fbf2013-02-25 20:32:51 -05002118 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002119 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002120 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002121 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2122
2123 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2124 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2125 // set tx map
2126 pMgmt->abyPSTxMap[0] |= byMask[0];
2127 return 0;
2128 }
Masanari Iida93184692012-08-13 21:21:50 +09002129 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002130
2131 if (pDevice->byBBType != BB_TYPE_11A)
2132 pDevice->wCurrentRate = RATE_2M;
2133 else
2134 pDevice->wCurrentRate = RATE_24M;
2135 // long preamble type
2136 pDevice->byPreambleType = PREAMBLE_SHORT;
2137
2138 }else {
2139
Andres Moreb902fbf2013-02-25 20:32:51 -05002140 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002141
2142 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2143
2144 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2145
2146 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2147 // set tx map
2148 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2149 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2150 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2151 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2152
2153 return 0;
2154 }
2155 // AP rate decided from node
2156 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2157 // tx preamble decided from node
2158
2159 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2160 pDevice->byPreambleType = pDevice->byShortPreamble;
2161
2162 }else {
2163 pDevice->byPreambleType = PREAMBLE_LONG;
2164 }
Andres More4e9b5e22013-02-12 20:36:30 -05002165 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002166 }
2167 }
2168
Andres Moree269fc22013-02-12 20:36:29 -05002169 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002170 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2171 dev_kfree_skb_irq(skb);
2172 return 0;
2173 }
2174 }
2175
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002176 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002177
2178 if (pContext == NULL) {
2179 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2180 dev_kfree_skb_irq(skb);
2181 return STATUS_RESOURCES;
2182 }
2183
Andres Moreceb8c5d2013-03-18 20:33:49 -05002184 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002185
2186//mike add:station mode check eapol-key challenge--->
2187{
Andres Moreb902fbf2013-02-25 20:32:51 -05002188 u8 Protocol_Version; //802.1x Authentication
2189 u8 Packet_Type; //802.1x Authentication
2190 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002191 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002192
Charles Clément21ec51f2010-05-18 10:08:14 -07002193 Protocol_Version = skb->data[ETH_HLEN];
2194 Packet_Type = skb->data[ETH_HLEN+1];
2195 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2196 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 -05002197 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002198 /* 802.1x OR eapol-key challenge frame transfer */
2199 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2200 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002201 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002202 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2203 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2204 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002205 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002206 PRINT_K("WPA ");
2207 }
2208 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002209 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002210 PRINT_K("WPA2(re-keying) ");
2211 }
2212 PRINT_K("Authentication completed!!\n");
2213 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002214 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002215 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002216 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002217 PRINT_K("WPA2 Authentication completed!!\n");
2218 }
2219 }
2220 }
2221}
2222//mike add:station mode check eapol-key challenge<---
2223
Andres More4e9b5e22013-02-12 20:36:30 -05002224 if (pDevice->bEncryptionEnable == true) {
2225 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002226 // get Transmit key
2227 do {
2228 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2229 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2230 pbyBSSID = pDevice->abyBSSID;
2231 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002232 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002233 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002234 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2235 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2237 break;
2238 }
2239 } else {
2240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2241 break;
2242 }
2243 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002244 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2245 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2247 for (ii = 0; ii< 6; ii++)
2248 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2249 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2250
2251 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002252 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002253 break;
2254 }
2255 // get group key
2256 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002257 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002258 pTransmitKey = NULL;
2259 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2260 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2261 }
2262 else
2263 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2264 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002265 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002266 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2267 }
Andres Moree269fc22013-02-12 20:36:29 -05002268 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002269 }
2270
2271 if (pDevice->bEnableHostWEP) {
2272 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002273 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002274 pTransmitKey = &STempKey;
2275 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2276 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2277 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2278 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2279 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2280 memcpy(pTransmitKey->abyKey,
2281 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2282 pTransmitKey->uKeyLength
2283 );
2284 }
2285 }
2286
Andres Moreb902fbf2013-02-25 20:32:51 -05002287 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002288
2289 if (pDevice->bFixRate) {
2290 if (pDevice->byBBType == BB_TYPE_11B) {
2291 if (pDevice->uConnectionRate >= RATE_11M) {
2292 pDevice->wCurrentRate = RATE_11M;
2293 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002294 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002295 }
2296 } else {
2297 if ((pDevice->byBBType == BB_TYPE_11A) &&
2298 (pDevice->uConnectionRate <= RATE_6M)) {
2299 pDevice->wCurrentRate = RATE_6M;
2300 } else {
2301 if (pDevice->uConnectionRate >= RATE_54M)
2302 pDevice->wCurrentRate = RATE_54M;
2303 else
Andres More3eaca0d2013-02-25 20:32:52 -05002304 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002305 }
2306 }
2307 }
2308 else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00002309 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Forest Bond92b96792009-06-13 07:38:31 -04002310 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002311 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002312 // Multicast use highest data rate
2313 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2314 // preamble type
2315 pDevice->byPreambleType = pDevice->byShortPreamble;
2316 }
2317 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002318 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002319 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2320 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2321 pDevice->byPreambleType = pDevice->byShortPreamble;
2322
2323 }
2324 else {
2325 pDevice->byPreambleType = PREAMBLE_LONG;
2326 }
2327 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2328 }
2329 else {
2330 if (pDevice->byBBType != BB_TYPE_11A)
2331 pDevice->wCurrentRate = RATE_2M;
2332 else
2333 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2334 // abyCurrExtSuppRates[]
2335 pDevice->byPreambleType = PREAMBLE_SHORT;
2336 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2337 }
2338 }
2339 }
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00002340 if (pDevice->op_mode == NL80211_IFTYPE_STATION) {
Forest Bond92b96792009-06-13 07:38:31 -04002341 // Infra STA rate decided from AP Node, index = 0
2342 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2343 }
2344 }
2345
Andres Moreceb8c5d2013-03-18 20:33:49 -05002346 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002347 if (pDevice->byBBType != BB_TYPE_11A) {
2348 pDevice->wCurrentRate = RATE_1M;
2349 pDevice->byACKRate = RATE_1M;
2350 pDevice->byTopCCKBasicRate = RATE_1M;
2351 pDevice->byTopOFDMBasicRate = RATE_6M;
2352 } else {
2353 pDevice->wCurrentRate = RATE_6M;
2354 pDevice->byACKRate = RATE_6M;
2355 pDevice->byTopCCKBasicRate = RATE_1M;
2356 pDevice->byTopOFDMBasicRate = RATE_6M;
2357 }
2358 }
Forest Bond92b96792009-06-13 07:38:31 -04002359
Andres More0cbd8d92010-05-06 20:34:29 -03002360 DBG_PRT(MSG_LEVEL_DEBUG,
2361 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2362 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002363
2364 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002365 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002366 }
2367
2368 if (pDevice->wCurrentRate <= RATE_11M) {
2369 byPktType = PK_TYPE_11B;
2370 }
2371
Andres More4e9b5e22013-02-12 20:36:30 -05002372 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2374 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002375 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002377 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2378 if (pTransmitKey == NULL) {
2379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2380 }
2381 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002382 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002383 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2384 }
2385 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002386 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2387 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002388 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002389 }
2390 }
2391 }
2392
Forest Bond92b96792009-06-13 07:38:31 -04002393 if (pDevice->bEnableHostWEP) {
2394 if ((uNodeIndex != 0) &&
2395 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002396 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2397 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002398 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002399 }
2400 }
2401 }
2402 else {
2403
Forest Bond92b96792009-06-13 07:38:31 -04002404 if (pTransmitKey == NULL) {
2405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002406 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002407 dev_kfree_skb_irq(skb);
2408 pStats->tx_dropped++;
2409 return STATUS_FAILURE;
2410 }
Forest Bond92b96792009-06-13 07:38:31 -04002411 }
2412 }
2413
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002414 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2415
Forest Bond92b96792009-06-13 07:38:31 -04002416 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002417 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002418 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002419 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002420 pDevice->wCurrentRate,
2421 &uHeaderLen, &BytesToWrite
2422 );
2423
Andres Moree269fc22013-02-12 20:36:29 -05002424 if (fConvertedPacket == false) {
2425 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002426 dev_kfree_skb_irq(skb);
2427 return STATUS_FAILURE;
2428 }
2429
Andres More4e9b5e22013-02-12 20:36:30 -05002430 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002431 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002432 bScheduleCommand((void *) pDevice,
2433 WLAN_CMD_MAC_DISPOWERSAVING,
2434 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002435 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002436 }
2437 }
2438
Andres Moreb902fbf2013-02-25 20:32:51 -05002439 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002440 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002441
2442 pContext->pPacket = skb;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002443 pContext->type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002444 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002445
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002446 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002447 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002448 (u16)(BytesToWrite-uHeaderLen),
2449 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002450
2451 status = PIPEnsSendBulkOut(pDevice,pContext);
2452
Andres More4e9b5e22013-02-12 20:36:30 -05002453 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002454 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002455
Andres Moreb902fbf2013-02-25 20:32:51 -05002456 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002457 }
2458
2459 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002460 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002461 dev_kfree_skb_irq(skb);
2462 return STATUS_FAILURE;
2463 }
2464 else
2465 return 0;
2466
2467}
2468
Forest Bond92b96792009-06-13 07:38:31 -04002469/*
2470 * Description:
2471 * Relay packet send (AC1DMA) from rx dpc.
2472 *
2473 * Parameters:
2474 * In:
2475 * pDevice - Pointer to the adapter
2476 * pPacket - Pointer to rx packet
2477 * cbPacketSize - rx ethernet frame size
2478 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002479 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002480 *
Andres More4e9b5e22013-02-12 20:36:30 -05002481 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002482 */
2483
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002484int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2485 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002486{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002487 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002488 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002489 u32 BytesToWrite = 0, uHeaderLen = 0;
2490 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002491 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002492 SKeyItem STempKey;
2493 PSKeyItem pTransmitKey = NULL;
2494 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002495 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002496 u8 byPktTyp;
2497 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002498 u32 status;
2499 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002500
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002501 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002502
2503 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002504 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002505 }
2506
Andres Moreceb8c5d2013-03-18 20:33:49 -05002507 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002508
Andres More4e9b5e22013-02-12 20:36:30 -05002509 if (pDevice->bEncryptionEnable == true) {
2510 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002511 // get group key
2512 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002513 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002514 pTransmitKey = NULL;
2515 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2516 } else {
2517 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2518 }
2519 }
2520
2521 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002522 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002523 pTransmitKey = &STempKey;
2524 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2525 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2526 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2527 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2528 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2529 memcpy(pTransmitKey->abyKey,
2530 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2531 pTransmitKey->uKeyLength
2532 );
2533 }
2534 }
2535
2536 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002537 pContext->bBoolInUse = false;
2538 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002539 }
2540
Andres Moreb902fbf2013-02-25 20:32:51 -05002541 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002542
2543 if (pDevice->bFixRate) {
2544 if (pDevice->byBBType == BB_TYPE_11B) {
2545 if (pDevice->uConnectionRate >= RATE_11M) {
2546 pDevice->wCurrentRate = RATE_11M;
2547 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002548 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002549 }
2550 } else {
2551 if ((pDevice->byBBType == BB_TYPE_11A) &&
2552 (pDevice->uConnectionRate <= RATE_6M)) {
2553 pDevice->wCurrentRate = RATE_6M;
2554 } else {
2555 if (pDevice->uConnectionRate >= RATE_54M)
2556 pDevice->wCurrentRate = RATE_54M;
2557 else
Andres More3eaca0d2013-02-25 20:32:52 -05002558 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002559 }
2560 }
2561 }
2562 else {
2563 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2564 }
2565
Forest Bond92b96792009-06-13 07:38:31 -04002566 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002567 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002568 }
2569
2570 if (pDevice->wCurrentRate <= RATE_11M)
2571 byPktType = PK_TYPE_11B;
2572
Andres Moreabad19d2010-07-12 16:28:32 -03002573 BytesToWrite = uDataLen + ETH_FCS_LEN;
2574
Forest Bond92b96792009-06-13 07:38:31 -04002575 // Convert the packet to an usb frame and copy into our buffer
2576 // and send the irp.
2577
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002578 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2579
Forest Bond92b96792009-06-13 07:38:31 -04002580 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002581 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002582 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2583 pbySkbData, pTransmitKey, uNodeIndex,
2584 pDevice->wCurrentRate,
2585 &uHeaderLen, &BytesToWrite
2586 );
2587
Andres Moree269fc22013-02-12 20:36:29 -05002588 if (fConvertedPacket == false) {
2589 pContext->bBoolInUse = false;
2590 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002591 }
2592
Andres Moreb902fbf2013-02-25 20:32:51 -05002593 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002594 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002595
2596 pContext->pPacket = NULL;
Malcolm Priestley1450ba62014-02-19 21:56:33 +00002597 pContext->type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002598 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002599
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002600 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002601 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002602 (u16)(BytesToWrite - uHeaderLen),
2603 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002604
2605 status = PIPEnsSendBulkOut(pDevice,pContext);
2606
Andres More4e9b5e22013-02-12 20:36:30 -05002607 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002608}
2609