blob: 61028225e2a4963fdc3476a975b8c936795ef1de [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 Priestleycfabe4b2013-08-22 21:03:40 +0100121static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000122 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
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 Priestleyf115e762013-08-23 11:48:46 +0100330static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
331{
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 Priestleycfabe4b2013-08-22 21:03:40 +0100370static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000371 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400372{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000373 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400374
375 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
376
Forest Bond92b96792009-06-13 07:38:31 -0400377 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
378 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
379 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
380 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
381 }
382 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
383 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
384 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
385 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
386 }
387 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
388 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
389 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
390 }
391 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
392 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
393 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
394 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
395 return uRrvTime;
396 }
397
398 //RTSRrvTime
399 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100400 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400401}
402
403//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100404static u16 s_uGetDataDuration(struct vnt_private *pDevice,
405 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400406{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100407 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400408
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100409 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100410 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100411 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
412 byPktType, 14, pDevice->byTopCCKBasicRate);
413 else
414 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
415 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100416 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100417 }
Forest Bond92b96792009-06-13 07:38:31 -0400418
Forest Bond92b96792009-06-13 07:38:31 -0400419 return 0;
420}
421
Forest Bond92b96792009-06-13 07:38:31 -0400422//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100423static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000424 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
425 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400426{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000427 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400428
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100429 switch (byDurType) {
430 case RTSDUR_BB:
431 case RTSDUR_BA:
432 case RTSDUR_BA_F0:
433 case RTSDUR_BA_F1:
434 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
435 14, pDevice->byTopCCKBasicRate);
436 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
437 s_uGetTxRsvTime(pDevice, byPktType,
438 cbFrameLength, wRate, bNeedAck);
439 break;
Forest Bond92b96792009-06-13 07:38:31 -0400440
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100441 case RTSDUR_AA:
442 case RTSDUR_AA_F0:
443 case RTSDUR_AA_F1:
444 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
445 14, pDevice->byTopOFDMBasicRate);
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 CTSDUR_BA:
452 case CTSDUR_BA_F0:
453 case CTSDUR_BA_F1:
454 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100455 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100456 break;
Forest Bond92b96792009-06-13 07:38:31 -0400457
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100458 default:
459 break;
460 }
Forest Bond92b96792009-06-13 07:38:31 -0400461
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100462 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400463}
464
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100465static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
466 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
467{
468 /* Get SignalField,ServiceField,Length */
469 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
470 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
471 PK_TYPE_11B, &buf->b);
472
473 /* Get Duration and TimeStamp */
474 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
475 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
476
477 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
478 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
479 priv->byTopCCKBasicRate);
480
481 return buf->wDuration_a;
482}
483
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100484static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
485 u16 rate, struct vnt_tx_datahead_g_fb *buf,
486 u32 frame_len, int need_ack)
487{
488 /* Get SignalField,ServiceField,Length */
489 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
490
491 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
492 PK_TYPE_11B, &buf->b);
493
494 /* Get Duration and TimeStamp */
495 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
496 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
497
498 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
499 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
500
501 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
502 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
503 priv->byTopCCKBasicRate);
504
505 return buf->wDuration_a;
506}
507
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100508static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
509 u16 rate, struct vnt_tx_datahead_a_fb *buf,
510 u32 frame_len, int need_ack)
511{
512 /* Get SignalField,ServiceField,Length */
513 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
514 /* Get Duration and TimeStampOff */
515 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
516
517 buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
518 buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
519
520 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
521
522 return buf->wDuration;
523}
524
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100525static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
526 u16 rate, struct vnt_tx_datahead_ab *buf,
527 u32 frame_len, int need_ack)
528{
529 /* Get SignalField,ServiceField,Length */
530 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
531 /* Get Duration and TimeStampOff */
532 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
533
534 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
535
536 return buf->wDuration;
537}
538
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100539static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
540 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
541 u16 duration)
542{
543 rts->duration = duration;
544 rts->frame_control = TYPE_CTL_RTS;
545
546 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
547 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
548 else
549 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
550
551 if (priv->eOPMode == OP_MODE_AP)
552 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
553 else
554 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
555
556 return 0;
557}
558
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100559static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100560 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
561 u8 pkt_type, u32 frame_len, int need_ack,
562 u16 current_rate, u8 fb_option)
563{
564 u16 rts_frame_len = 20;
565
566 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
567 PK_TYPE_11B, &buf->b);
568 BBvCalculateParameter(priv, rts_frame_len,
569 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
570
571 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
572 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
573 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
574 pkt_type, current_rate, need_ack, fb_option);
575 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
576 pkt_type, current_rate, need_ack, fb_option);
577
578 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
579
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100580 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
581 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100582}
583
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100584static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100585 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
586 u8 pkt_type, u32 frame_len, int need_ack,
587 u16 current_rate, u8 fb_option)
588{
589 u16 rts_frame_len = 20;
590
591 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
592 PK_TYPE_11B, &buf->b);
593 BBvCalculateParameter(priv, rts_frame_len,
594 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
595
596
597 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
598 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
599 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
600 pkt_type, current_rate, need_ack, fb_option);
601 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
602 pkt_type, current_rate, need_ack, fb_option);
603
604
605 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100606 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100607 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100608 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100609 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100610 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100611 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100612 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100613
614 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
615
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100616 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
617 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100618}
619
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100620static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100621 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
622 u8 pkt_type, u32 frame_len, int need_ack,
623 u16 current_rate, u8 fb_option)
624{
625 u16 rts_frame_len = 20;
626
627 BBvCalculateParameter(priv, rts_frame_len,
628 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
629
630 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
631 pkt_type, current_rate, need_ack, fb_option);
632
633 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
634
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100635 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
636 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100637}
638
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100639static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100640 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
641 u8 pkt_type, u32 frame_len, int need_ack,
642 u16 current_rate, u8 fb_option)
643{
644 u16 rts_frame_len = 20;
645
646 BBvCalculateParameter(priv, rts_frame_len,
647 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
648
649 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
650 pkt_type, current_rate, need_ack, fb_option);
651
652 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100653 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100654
655 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100656 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100657
658 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
659
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100660 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
661 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100662}
663
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100664static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100665 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500666 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400667{
Forest Bond92b96792009-06-13 07:38:31 -0400668
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100669 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100670 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400671
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100672 /* Note: So far RTSHead doesn't appear in ATIM
673 * & Beacom DMA, so we don't need to take them
674 * into account.
675 * Otherwise, we need to modified codes for them.
676 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100677 switch (byPktType) {
678 case PK_TYPE_11GB:
679 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100680 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100681 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100682 psEthHeader, byPktType, cbFrameLength,
683 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100684 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100685 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100686 psEthHeader, byPktType, cbFrameLength,
687 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100688 break;
689 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100690 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100691 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100692 psEthHeader, byPktType, cbFrameLength,
693 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100694 break;
695 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100696 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100697 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100698 psEthHeader, byPktType, cbFrameLength,
699 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100700 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100701
702 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400703}
704
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100705static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100706 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
707 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400708{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000709 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400710
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100711 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100712 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400713
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100714 if (byFBOption != AUTO_FB_NONE) {
715 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100716 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100717 /* Get SignalField,ServiceField,Length */
718 BBvCalculateParameter(pDevice, uCTSFrameLen,
719 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100720 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
721 cbFrameLength, byPktType,
722 wCurrentRate, bNeedAck, byFBOption);
723 /* Get CTSDuration_ba_f0 */
724 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100725 CTSDUR_BA_F0, cbFrameLength, byPktType,
726 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100727 /* Get CTSDuration_ba_f1 */
728 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100729 CTSDUR_BA_F1, cbFrameLength, byPktType,
730 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100731 /* Get CTS Frame body */
732 pBuf->data.duration = pBuf->wDuration_ba;
733 pBuf->data.frame_control = TYPE_CTL_CTS;
734 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100735
736 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
737 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100738 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100739 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100740 /* Get SignalField,ServiceField,Length */
741 BBvCalculateParameter(pDevice, uCTSFrameLen,
742 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100743 /* Get CTSDuration_ba */
744 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
745 CTSDUR_BA, cbFrameLength, byPktType,
746 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100747 /*Get CTS Frame body*/
748 pBuf->data.duration = pBuf->wDuration_ba;
749 pBuf->data.frame_control = TYPE_CTL_CTS;
750 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100751
752 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
753 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400754 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100755
756 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400757}
758
Forest Bond92b96792009-06-13 07:38:31 -0400759/*+
760 *
761 * Description:
762 * Generate FIFO control for MAC & Baseband controller
763 *
764 * Parameters:
765 * In:
766 * pDevice - Pointer to adpater
767 * pTxDataHead - Transmit Data Buffer
768 * pTxBufHead - pTxBufHead
769 * pvRrvTime - pvRrvTime
770 * pvRTS - RTS Buffer
771 * pCTS - CTS Buffer
772 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
773 * bNeedACK - If need ACK
774 * uDMAIdx - DMA Index
775 * Out:
776 * none
777 *
778 * Return Value: none
779 *
780-*/
Andres Morecc856e62010-05-17 21:34:01 -0300781
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100782static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100783 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100784 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
785 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400786{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100787 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100788 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000789 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000790 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400791
Malcolm Priestley92928f12013-10-07 20:14:01 +0100792 pFifoHead->wReserved = wCurrentRate;
793 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400794
Malcolm Priestley92928f12013-10-07 20:14:01 +0100795 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
796 byFBOption = AUTO_FB_0;
797 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
798 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400799
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100800 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100801 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100802
Malcolm Priestley92928f12013-10-07 20:14:01 +0100803 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
804 if (need_rts) {
805 struct vnt_rrv_time_rts *pBuf =
806 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100807
Malcolm Priestley92928f12013-10-07 20:14:01 +0100808 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
809 byPktType, cbFrameSize, wCurrentRate);
810 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
811 byPktType, cbFrameSize, wCurrentRate);
812 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100813 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100814
Malcolm Priestley92928f12013-10-07 20:14:01 +0100815 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
816 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
817 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
818 PK_TYPE_11B, cbFrameSize,
819 pDevice->byTopCCKBasicRate, bNeedACK);
820
821 if (need_mic) {
822 *mic_hdr = &tx_buffer->
823 tx_head.tx_rts.tx.mic.hdr;
824 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
825 } else {
826 head = &tx_buffer->tx_head.tx_rts.tx.head;
827 }
828
829 /* Fill RTS */
830 return s_vFillRTSHead(pDevice, byPktType, head,
831 cbFrameSize, bNeedACK, psEthHeader,
832 wCurrentRate, byFBOption);
833
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100834 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100835 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
836 tx_head.tx_cts.cts;
837
838 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
839 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
840 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
841 PK_TYPE_11B, cbFrameSize,
842 pDevice->byTopCCKBasicRate, bNeedACK);
843
844 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
845 byPktType, cbFrameSize, wCurrentRate);
846
847 if (need_mic) {
848 *mic_hdr = &tx_buffer->
849 tx_head.tx_cts.tx.mic.hdr;
850 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
851 } else {
852 head = &tx_buffer->tx_head.tx_cts.tx.head;
853 }
854
855 /* Fill CTS */
856 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
857 head, cbFrameSize, bNeedACK, wCurrentRate,
858 byFBOption);
859 }
860 } else if (byPktType == PK_TYPE_11A) {
861 if (need_mic) {
862 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
863 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
864 } else {
865 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100866 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100867
Malcolm Priestley92928f12013-10-07 20:14:01 +0100868 if (need_rts) {
869 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
870 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100871
Malcolm Priestley92928f12013-10-07 20:14:01 +0100872 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100873 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100874
Malcolm Priestley92928f12013-10-07 20:14:01 +0100875 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
876 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
877
878 /* Fill RTS */
879 return s_vFillRTSHead(pDevice, byPktType, head,
880 cbFrameSize, bNeedACK, psEthHeader,
881 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100882 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100883 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
884 tx_head.tx_ab.ab;
885
886 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
887 PK_TYPE_11A, cbFrameSize,
888 wCurrentRate, bNeedACK);
889
890 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
891 wCurrentRate, &head->data_head_a_fb,
892 cbFrameSize, bNeedACK);
893 }
894 } else if (byPktType == PK_TYPE_11B) {
895 if (need_mic) {
896 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
897 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
898 } else {
899 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100900 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100901
Malcolm Priestley92928f12013-10-07 20:14:01 +0100902 if (need_rts) {
903 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
904 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100905
Malcolm Priestley92928f12013-10-07 20:14:01 +0100906 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100907 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100908
Malcolm Priestley92928f12013-10-07 20:14:01 +0100909 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
910 PK_TYPE_11B, cbFrameSize, wCurrentRate,
911 bNeedACK);
912
913 /* Fill RTS */
914 return s_vFillRTSHead(pDevice, byPktType, head,
915 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100916 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100917 } else {
918 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
919 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100920
Malcolm Priestley92928f12013-10-07 20:14:01 +0100921 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
922 PK_TYPE_11B, cbFrameSize,
923 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100924
Malcolm Priestley92928f12013-10-07 20:14:01 +0100925 return vnt_rxtx_datahead_ab(pDevice, byPktType,
926 wCurrentRate, &head->data_head_ab,
927 cbFrameSize, bNeedACK);
928 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100929 }
930
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100931 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400932}
933/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500934 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500935 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300936 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400937*/
938
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000939static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100940 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100941 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
942 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
943 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400944{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100945 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000946 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
947 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000948 u32 cb802_1_H_len;
949 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
950 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100951 int bNeedACK;
952 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000953 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
954 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
955 u8 abySNAP_Bridgetunnel[ETH_ALEN]
956 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
957 u32 uDuration;
958 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100959 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000960 u8 byFBOption = AUTO_FB_NONE, byFragType;
961 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100962 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000963 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500964 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100965
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100966 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400967
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000968 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500969 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
970 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000971 }
Forest Bond92b96792009-06-13 07:38:31 -0400972
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000973 /* Get pkt type */
974 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
975 cb802_1_H_len = 8;
976 else
977 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400978
Charles Clément21ec51f2010-05-18 10:08:14 -0700979 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400980
981 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500982 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400983
Andres More22040bb2010-08-02 20:21:44 -0300984 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000985 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500986 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500987 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -0300988 pTxBufHead->wFIFOCtl =
989 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
990 } else {
Andres More4e9b5e22013-02-12 20:36:30 -0500991 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -0300992 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
993 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000994 } else {
995 /* MSDUs in Infra mode always need ACK */
996 bNeedACK = true;
997 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
998 }
Forest Bond92b96792009-06-13 07:38:31 -0400999
1000 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1001
Forest Bond92b96792009-06-13 07:38:31 -04001002 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001003 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1004
Andres More3eaca0d2013-02-25 20:32:52 -05001005 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001006
1007 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001008 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001009 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1010 }
1011
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001012 /* Set Auto Fallback Ctl */
1013 if (wCurrentRate >= RATE_18M) {
1014 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1015 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1016
1017 pDevice->tx_rate_fb0 =
1018 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1019 pDevice->tx_rate_fb1 =
1020 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1021
1022 byFBOption = AUTO_FB_0;
1023 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1024 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1025 pDevice->tx_rate_fb0 =
1026 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1027 pDevice->tx_rate_fb1 =
1028 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1029
1030 byFBOption = AUTO_FB_1;
1031 }
1032 }
Forest Bond92b96792009-06-13 07:38:31 -04001033
Andres More4e9b5e22013-02-12 20:36:30 -05001034 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001035 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1036 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1037 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1038 }
1039 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1040 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1041 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1042 }
1043 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1044 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1045 }
1046 }
1047 }
1048
Forest Bond92b96792009-06-13 07:38:31 -04001049 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1050 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1051 cbIVlen = 4;
1052 cbICVlen = 4;
1053 }
1054 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1055 cbIVlen = 8;//IV+ExtIV
1056 cbMIClen = 8;
1057 cbICVlen = 4;
1058 }
1059 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1060 cbIVlen = 8;//RSN Header
1061 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001062 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001063 }
Andres Moree269fc22013-02-12 20:36:29 -05001064 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001065 //MAC Header should be padding 0 to DW alignment.
1066 uPadding = 4 - (cbMACHdLen%4);
1067 uPadding %= 4;
1068 }
1069 }
1070
1071 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1072
Andres Moree269fc22013-02-12 20:36:29 -05001073 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1074 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001075 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001076 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001077 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1078 }
1079
Andres Moreb902fbf2013-02-25 20:32:51 -05001080 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001081 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1082
Forest Bond92b96792009-06-13 07:38:31 -04001083 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1084 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001085 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001086 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001087 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001088 }
1089 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001090 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001091 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001092 }
1093 } else {
1094 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001095 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001096 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001097 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001098 }
Andres Moree269fc22013-02-12 20:36:29 -05001099 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001100 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001101 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001102 }
1103 } // Auto Fall Back
1104 }
1105 else {//802.11a/b packet
1106 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001107 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001108 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001109 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001110 }
Andres Moree269fc22013-02-12 20:36:29 -05001111 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001112 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001113 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001114 }
1115 } else {
1116 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001117 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001118 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001119 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001120 }
Andres Moree269fc22013-02-12 20:36:29 -05001121 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001122 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001123 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001124 }
1125 } // Auto Fall Back
1126 }
1127
Andres Moreb902fbf2013-02-25 20:32:51 -05001128 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1129 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1130 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001131
Forest Bond92b96792009-06-13 07:38:31 -04001132 //=========================
1133 // No Fragmentation
1134 //=========================
1135 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1136 byFragType = FRAGCTL_NONFRAG;
1137 //uDMAIdx = TYPE_AC0DMA;
1138 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1139
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001140 /* Fill FIFO, RrvTime, RTS and CTS */
1141 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1142 tx_buffer, &pMICHDR, cbMICHDR,
1143 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001144
Forest Bond92b96792009-06-13 07:38:31 -04001145 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001146 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001147 byFragType, uDMAIdx, 0);
1148
Andres More4e9b5e22013-02-12 20:36:30 -05001149 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001150 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001151 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001152 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001153
1154 if (pDevice->bEnableHostWEP) {
1155 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1156 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1157 }
1158 }
1159
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001160 /* 802.1H */
1161 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001162 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001163 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001164 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001165 abySNAP_Bridgetunnel, 6);
1166 else
1167 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001168
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001169 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001170
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001171 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1172 }
Forest Bond92b96792009-06-13 07:38:31 -04001173
Forest Bond92b96792009-06-13 07:38:31 -04001174 if (pPacket != NULL) {
1175 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001176 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001177 (pPacket + ETH_HLEN),
1178 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001179 );
1180
1181 } else {
1182 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001183 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001184 }
1185
Andres More4e9b5e22013-02-12 20:36:30 -05001186 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001187
1188 ///////////////////////////////////////////////////////////////////
1189
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001190 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1191 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1192 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1193 }
Forest Bond92b96792009-06-13 07:38:31 -04001194 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001195 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1196 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001197 }
1198 else {
Andres More52a7e642013-02-25 20:32:53 -05001199 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1200 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001201 }
1202 // DO Software Michael
1203 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001204 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001205 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001206 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001207 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1208 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001209
1210 ///////////////////////////////////////////////////////////////////
1211
1212 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1213 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001214 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001215 //}
1216 //DBG_PRN_GRP12(("\n\n\n"));
1217
1218 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1219
Andres More52a7e642013-02-25 20:32:53 -05001220 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1221 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001222
1223 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1224 MIC_vUnInit();
1225
Andres More4e9b5e22013-02-12 20:36:30 -05001226 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001227 *pdwMIC_L = 0;
1228 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001229 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001230 }
1231 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1232 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1233 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1234 }
1235
Andres More4e9b5e22013-02-12 20:36:30 -05001236 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001237
Andres More3eaca0d2013-02-25 20:32:52 -05001238 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001239
Andres More4e9b5e22013-02-12 20:36:30 -05001240 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1241 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1242 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001243 cbFrameSize -= cbICVlen;
1244 }
1245
Forest Bond92b96792009-06-13 07:38:31 -04001246 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001247
1248 *pcbHeaderLen = cbHeaderLength;
1249 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1250
Forest Bond92b96792009-06-13 07:38:31 -04001251 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001252 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001253
Andres More4e9b5e22013-02-12 20:36:30 -05001254 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001255
1256}
1257
Forest Bond92b96792009-06-13 07:38:31 -04001258/*+
1259 *
1260 * Description:
1261 * Translate 802.3 to 802.11 header
1262 *
1263 * Parameters:
1264 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001265 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001266 * dwTxBufferAddr - Transmit Buffer
1267 * pPacket - Packet from upper layer
1268 * cbPacketSize - Transmit Data Length
1269 * Out:
1270 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1271 * pcbAppendPayload - size of append payload for 802.1H translation
1272 *
1273 * Return Value: none
1274 *
1275-*/
1276
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001277static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001278 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001279 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001280{
Andres More1cac4a42013-03-18 20:33:50 -05001281 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001282
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001283 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001284
1285 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001286 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001287 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001288 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001289 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1290 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001291 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001292 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001293 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001294 } else {
1295 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001296 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001297 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001298 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001299 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001300 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001301 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001302 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001303 &(pDevice->abyBSSID[0]),
1304 ETH_ALEN);
1305 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001306 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001307 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001308 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001309 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001310 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001311 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001312 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001313 &(pDevice->abyBSSID[0]),
1314 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001315 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001316 }
1317 }
1318
1319 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001320 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001321
Andres More1cac4a42013-03-18 20:33:50 -05001322 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001323
Andres More1cac4a42013-03-18 20:33:50 -05001324 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001325
1326 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001327 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001328
1329 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1330 pDevice->wSeqCounter++;
1331 if (pDevice->wSeqCounter > 0x0fff)
1332 pDevice->wSeqCounter = 0;
1333 }
1334
1335 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001336 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001337 }
1338}
1339
Forest Bond92b96792009-06-13 07:38:31 -04001340/*+
1341 *
1342 * Description:
1343 * Request instructs a MAC to transmit a 802.11 management packet through
1344 * the adapter onto the medium.
1345 *
1346 * Parameters:
1347 * In:
1348 * hDeviceContext - Pointer to the adapter
1349 * pPacket - A pointer to a descriptor for the packet to transmit
1350 * Out:
1351 * none
1352 *
Andres Moree269fc22013-02-12 20:36:29 -05001353 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001354 *
1355-*/
1356
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001357CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1358 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001359{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001360 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001361 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001362 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001363 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001364 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001365 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001366 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001367 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001368 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001369 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001370 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1371 u32 uPadding = 0;
1372 u16 wTxBufSize;
1373 u32 cbMacHdLen;
1374 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001375
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001376 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001377
1378 if (NULL == pContext) {
1379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1380 return CMD_STATUS_RESOURCES;
1381 }
1382
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001383 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001384 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001385 pTxBufHead = &pTX_Buffer->fifo_head;
1386 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1387 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001388
1389 if (pDevice->byBBType == BB_TYPE_11A) {
1390 wCurrentRate = RATE_6M;
1391 byPktType = PK_TYPE_11A;
1392 } else {
1393 wCurrentRate = RATE_1M;
1394 byPktType = PK_TYPE_11B;
1395 }
1396
1397 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1398 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1399 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1400 // to set power here.
1401 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1402 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1403 } else {
1404 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1405 }
1406 pDevice->wCurrentRate = wCurrentRate;
1407
Forest Bond92b96792009-06-13 07:38:31 -04001408 //Set packet type
1409 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1410 pTxBufHead->wFIFOCtl = 0;
1411 }
1412 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1413 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1414 }
1415 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1416 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1417 }
1418 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1419 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1420 }
1421
1422 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1423 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1424
Andres More22040bb2010-08-02 20:21:44 -03001425 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001426 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001427 }
1428 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001429 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001430 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1431 };
1432
1433 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1434 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1435
1436 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1437 //Set Preamble type always long
1438 //pDevice->byPreambleType = PREAMBLE_LONG;
1439 // probe-response don't retry
1440 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001441 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001442 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1443 //}
1444 }
1445
1446 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1447
1448 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001449 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001450 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1451 } else {
1452 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1453 }
1454
1455 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001456 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001457
1458 // Notes:
1459 // Although spec says MMPDU can be fragmented; In most case,
1460 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001461
1462 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1463 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1464 cbIVlen = 4;
1465 cbICVlen = 4;
1466 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1467 }
1468 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1469 cbIVlen = 8;//IV+ExtIV
1470 cbMIClen = 8;
1471 cbICVlen = 4;
1472 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1473 //We need to get seed here for filling TxKey entry.
1474 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1475 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1476 }
1477 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1478 cbIVlen = 8;//RSN Header
1479 cbICVlen = 8;//MIC
1480 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001481 }
1482 //MAC Header should be padding 0 to DW alignment.
1483 uPadding = 4 - (cbMacHdLen%4);
1484 uPadding %= 4;
1485 }
1486
1487 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1488
1489 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001490 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001491 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1492 }
1493 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1494
1495 //Set RrvTime/RTS/CTS Buffer
1496 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001497 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001498 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001499 }
1500 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001501 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001502 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001503 }
1504
Andres Moreceb8c5d2013-03-18 20:33:49 -05001505 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001506 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1507 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001508 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001509 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1510 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001511 //=========================
1512 // No Fragmentation
1513 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001514 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001515
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001516 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001517 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001518 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001519 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001520
Andres More1cac4a42013-03-18 20:33:50 -05001521 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001522
1523 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1524
1525 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001526 u8 * pbyIVHead;
1527 u8 * pbyPayloadHead;
1528 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001529 PSKeyItem pTransmitKey = NULL;
1530
Andres Moreb902fbf2013-02-25 20:32:51 -05001531 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1532 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001533 do {
1534 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001535 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001536 pbyBSSID = pDevice->abyBSSID;
1537 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001538 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001539 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001540 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001541 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1542 break;
1543 }
1544 } else {
1545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1546 break;
1547 }
1548 }
1549 // get group key
1550 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001551 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001552 pTransmitKey = NULL;
1553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1554 } else {
1555 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1556 }
Andres Moree269fc22013-02-12 20:36:29 -05001557 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001558 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001559 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001560 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001561
Jim Lieb3e362592009-08-12 14:54:11 -07001562 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001563 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001564 cbFrameBodySize);
1565 }
1566 else {
1567 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001568 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001569 }
1570
Andres More1cac4a42013-03-18 20:33:50 -05001571 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001572 pDevice->wSeqCounter++ ;
1573 if (pDevice->wSeqCounter > 0x0fff)
1574 pDevice->wSeqCounter = 0;
1575
1576 if (bIsPSPOLL) {
1577 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001578 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001579 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1580 // in the same place of other packet's Duration-field).
1581 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001582 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001583 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1584 tx_cts.tx.head.cts_g.data_head;
1585 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001586 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001587 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001588 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1589 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001590 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1591 tx_ab.tx.head.data_head_ab;
1592 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001593 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1594 }
Forest Bond92b96792009-06-13 07:38:31 -04001595 }
1596
Andres More3eaca0d2013-02-25 20:32:52 -05001597 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001598 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001599 pTX_Buffer->byType = 0x00;
1600
1601 pContext->pPacket = NULL;
1602 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001603 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001604
Andres More1cac4a42013-03-18 20:33:50 -05001605 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001606 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1607 &pMACHeader->addr1[0], (u16)cbFrameSize,
1608 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001609 }
1610 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001611 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1612 &pMACHeader->addr3[0], (u16)cbFrameSize,
1613 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001614 }
1615
1616 PIPEnsSendBulkOut(pDevice,pContext);
1617 return CMD_STATUS_PENDING;
1618}
1619
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001620CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1621 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001622{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001623 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001624 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001625 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1626 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001627 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001628 u16 wCurrentRate;
1629 u32 cbFrameBodySize;
1630 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001631 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001632 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001633
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001634 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001635 if (NULL == pContext) {
1636 status = CMD_STATUS_RESOURCES;
1637 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1638 return status ;
1639 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001640
1641 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001642 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001643
1644 cbFrameBodySize = pPacket->cbPayloadLen;
1645
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001646 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001647
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001648 if (pDevice->byBBType == BB_TYPE_11A) {
1649 wCurrentRate = RATE_6M;
1650
1651 /* Get SignalField,ServiceField,Length */
1652 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1653 PK_TYPE_11A, &short_head->ab);
1654
1655 /* Get Duration and TimeStampOff */
1656 short_head->duration = s_uGetDataDuration(pDevice,
1657 PK_TYPE_11A, false);
1658 short_head->time_stamp_off =
1659 vnt_time_stamp_off(pDevice, wCurrentRate);
1660 } else {
1661 wCurrentRate = RATE_1M;
1662 short_head->fifo_ctl |= FIFOCTL_11B;
1663
1664 /* Get SignalField,ServiceField,Length */
1665 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1666 PK_TYPE_11B, &short_head->ab);
1667
1668 /* Get Duration and TimeStampOff */
1669 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001670 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001671 short_head->time_stamp_off =
1672 vnt_time_stamp_off(pDevice, wCurrentRate);
1673 }
1674
Forest Bond92b96792009-06-13 07:38:31 -04001675
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001676 /* Generate Beacon Header */
1677 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001678
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001679 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1680
1681 pMACHeader->duration_id = 0;
1682 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1683 pDevice->wSeqCounter++;
1684 if (pDevice->wSeqCounter > 0x0fff)
1685 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001686
1687 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1688
Andres More3eaca0d2013-02-25 20:32:52 -05001689 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001690 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001691 pTX_Buffer->byType = 0x01;
1692
1693 pContext->pPacket = NULL;
1694 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001695 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001696
1697 PIPEnsSendBulkOut(pDevice,pContext);
1698 return CMD_STATUS_PENDING;
1699
1700}
1701
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001702void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1703{
1704 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001705 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001706 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001707 u8 byPktType;
1708 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001709 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001710 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001711 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001712 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001713 u32 cbFrameSize;
1714 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1715 u32 uPadding = 0;
1716 u32 cbMICHDR = 0, uLength = 0;
1717 u32 dwMICKey0, dwMICKey1;
1718 u32 dwMIC_Priority;
1719 u32 *pdwMIC_L, *pdwMIC_R;
1720 u16 wTxBufSize;
1721 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001722 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001723 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001724 u32 wCurrentRate = RATE_1M;
1725 PUWLAN_80211HDR p80211Header;
1726 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001727 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001728 SKeyItem STempKey;
1729 PSKeyItem pTransmitKey = NULL;
1730 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1731 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001732 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001733
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001734 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001735
1736 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1737 cbFrameBodySize = 0;
1738 }
1739 else {
1740 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1741 }
1742 p80211Header = (PUWLAN_80211HDR)skb->data;
1743
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001744 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001745
1746 if (NULL == pContext) {
1747 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1748 dev_kfree_skb_irq(skb);
1749 return ;
1750 }
1751
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001752 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001753 pTxBufHead = &pTX_Buffer->fifo_head;
1754 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1755 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001756
1757 if (pDevice->byBBType == BB_TYPE_11A) {
1758 wCurrentRate = RATE_6M;
1759 byPktType = PK_TYPE_11A;
1760 } else {
1761 wCurrentRate = RATE_1M;
1762 byPktType = PK_TYPE_11B;
1763 }
1764
1765 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1766 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1767 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1768 // to set power here.
1769 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1770 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1771 } else {
1772 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1773 }
1774
1775 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1776
1777 //Set packet type
1778 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1779 pTxBufHead->wFIFOCtl = 0;
1780 }
1781 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1782 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1783 }
1784 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1785 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1786 }
1787 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1788 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1789 }
1790
1791 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1792 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1793
Andres More22040bb2010-08-02 20:21:44 -03001794 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001795 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001796 if (pDevice->bEnableHostWEP) {
1797 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001798 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001799 }
Forest Bond92b96792009-06-13 07:38:31 -04001800 }
1801 else {
1802 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001803 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001804 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001805 }
Andres More4e9b5e22013-02-12 20:36:30 -05001806 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001807 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1808 };
1809
1810 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1811 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1812
1813 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1814 //Set Preamble type always long
1815 //pDevice->byPreambleType = PREAMBLE_LONG;
1816
1817 // probe-response don't retry
1818 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001819 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001820 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1821 //}
1822 }
1823
1824 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1825
1826 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001827 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001828 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1829 } else {
1830 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1831 }
1832
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001833 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001834 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1835
1836 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1837 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1838 }
1839
1840 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1841 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1842 }
1843
1844 if (cbExtSuppRate >0) {
1845 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1846 }
1847 }
1848
Forest Bond92b96792009-06-13 07:38:31 -04001849 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001850 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001851
1852 // Notes:
1853 // Although spec says MMPDU can be fragmented; In most case,
1854 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001855
Forest Bond92b96792009-06-13 07:38:31 -04001856 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1857 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1858 cbIVlen = 4;
1859 cbICVlen = 4;
1860 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1861 }
1862 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1863 cbIVlen = 8;//IV+ExtIV
1864 cbMIClen = 8;
1865 cbICVlen = 4;
1866 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1867 //We need to get seed here for filling TxKey entry.
1868 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1869 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1870 }
1871 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1872 cbIVlen = 8;//RSN Header
1873 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001874 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001875 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001876 }
1877 //MAC Header should be padding 0 to DW alignment.
1878 uPadding = 4 - (cbMacHdLen%4);
1879 uPadding %= 4;
1880 }
1881
1882 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1883
1884 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001885 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001886 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1887 }
1888 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1889
Forest Bond92b96792009-06-13 07:38:31 -04001890 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001891 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001892 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001893
1894 }
1895 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001896 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001897 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001898 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001899 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001900 &(p80211Header->sA3.abyAddr1[0]),
1901 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001902 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001903 &(p80211Header->sA3.abyAddr2[0]),
1904 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001905 //=========================
1906 // No Fragmentation
1907 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001908 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001909
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001910 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001911 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001912 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001913 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001914
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001915 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001916
1917 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1918
Andres Moreb902fbf2013-02-25 20:32:51 -05001919 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1920 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1921 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001922
1923 // Copy the Packet into a tx Buffer
1924 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1925
1926 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001927 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001928 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1929
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001930 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001931 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1932 if (cbExtSuppRate != 0) {
1933 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1934 memcpy((pbyPayloadHead + cbFrameBodySize),
1935 pMgmt->abyCurrSuppRates,
1936 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1937 );
1938 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1939 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1940 pMgmt->abyCurrExtSuppRates,
1941 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1942 );
1943 }
1944 }
1945
1946 // Set wep
1947 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1948
1949 if (pDevice->bEnableHostWEP) {
1950 pTransmitKey = &STempKey;
1951 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1952 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1953 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1954 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1955 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1956 memcpy(pTransmitKey->abyKey,
1957 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1958 pTransmitKey->uKeyLength
1959 );
1960 }
1961
1962 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1963
Andres More52a7e642013-02-25 20:32:53 -05001964 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1965 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001966
1967 // DO Software Michael
1968 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001969 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001970 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001971 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001972 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1973 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001974
1975 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1976
1977 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1978
Andres More52a7e642013-02-25 20:32:53 -05001979 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1980 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001981
1982 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1983 MIC_vUnInit();
1984
Andres More4e9b5e22013-02-12 20:36:30 -05001985 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001986 *pdwMIC_L = 0;
1987 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001988 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001989 }
1990
1991 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1992 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001993 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
1994 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04001995
1996 }
1997
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001998 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001999 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002000
2001 if (pDevice->bEnableHostWEP) {
2002 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2003 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2004 }
2005
2006 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002007 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002008 }
2009 }
2010
Andres More1cac4a42013-03-18 20:33:50 -05002011 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002012 pDevice->wSeqCounter++ ;
2013 if (pDevice->wSeqCounter > 0x0fff)
2014 pDevice->wSeqCounter = 0;
2015
Forest Bond92b96792009-06-13 07:38:31 -04002016 if (bIsPSPOLL) {
2017 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2018 // of FIFO control header.
2019 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2020 // in the same place of other packet's Duration-field).
2021 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002022 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002023 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2024 tx_cts.tx.head.cts_g.data_head;
2025 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002026 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002027 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002028 cpu_to_le16(p80211Header->sA2.wDurationID);
2029 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002030 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2031 tx_ab.tx.head.data_head_ab;
2032 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002033 cpu_to_le16(p80211Header->sA2.wDurationID);
2034 }
Forest Bond92b96792009-06-13 07:38:31 -04002035 }
2036
Andres More3eaca0d2013-02-25 20:32:52 -05002037 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002038 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002039 pTX_Buffer->byType = 0x00;
2040
2041 pContext->pPacket = skb;
2042 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002043 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002044
Andres More1cac4a42013-03-18 20:33:50 -05002045 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002046 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2047 &pMACHeader->addr1[0], (u16)cbFrameSize,
2048 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002049 }
2050 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002051 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2052 &pMACHeader->addr3[0], (u16)cbFrameSize,
2053 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002054 }
2055 PIPEnsSendBulkOut(pDevice,pContext);
2056 return ;
2057
2058}
2059
Forest Bond92b96792009-06-13 07:38:31 -04002060//TYPE_AC0DMA data tx
2061/*
2062 * Description:
2063 * Tx packet via AC0DMA(DMA1)
2064 *
2065 * Parameters:
2066 * In:
2067 * pDevice - Pointer to the adapter
2068 * skb - Pointer to tx skb packet
2069 * Out:
2070 * void
2071 *
2072 * Return Value: NULL
2073 */
2074
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002075int nsDMA_tx_packet(struct vnt_private *pDevice,
2076 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002077{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002078 struct net_device_stats *pStats = &pDevice->stats;
2079 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002080 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002081 u32 BytesToWrite = 0, uHeaderLen = 0;
2082 u32 uNodeIndex = 0;
2083 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2084 u16 wAID;
2085 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002086 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002087 PSKeyItem pTransmitKey = NULL;
2088 SKeyItem STempKey;
2089 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002090 int bTKIP_UseGTK = false;
2091 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002092 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002093 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002094 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002095 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002096 u32 status;
2097 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002098 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002099
Forest Bond92b96792009-06-13 07:38:31 -04002100 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2101
2102 if (pDevice->uAssocCount == 0) {
2103 dev_kfree_skb_irq(skb);
2104 return 0;
2105 }
2106
Andres Moreb902fbf2013-02-25 20:32:51 -05002107 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002108 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002109 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002110 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2111
2112 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2113 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2114 // set tx map
2115 pMgmt->abyPSTxMap[0] |= byMask[0];
2116 return 0;
2117 }
Masanari Iida93184692012-08-13 21:21:50 +09002118 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002119
2120 if (pDevice->byBBType != BB_TYPE_11A)
2121 pDevice->wCurrentRate = RATE_2M;
2122 else
2123 pDevice->wCurrentRate = RATE_24M;
2124 // long preamble type
2125 pDevice->byPreambleType = PREAMBLE_SHORT;
2126
2127 }else {
2128
Andres Moreb902fbf2013-02-25 20:32:51 -05002129 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002130
2131 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2132
2133 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2134
2135 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2136 // set tx map
2137 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2138 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2139 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2140 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2141
2142 return 0;
2143 }
2144 // AP rate decided from node
2145 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2146 // tx preamble decided from node
2147
2148 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2149 pDevice->byPreambleType = pDevice->byShortPreamble;
2150
2151 }else {
2152 pDevice->byPreambleType = PREAMBLE_LONG;
2153 }
Andres More4e9b5e22013-02-12 20:36:30 -05002154 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002155 }
2156 }
2157
Andres Moree269fc22013-02-12 20:36:29 -05002158 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002159 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2160 dev_kfree_skb_irq(skb);
2161 return 0;
2162 }
2163 }
2164
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002165 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002166
2167 if (pContext == NULL) {
2168 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2169 dev_kfree_skb_irq(skb);
2170 return STATUS_RESOURCES;
2171 }
2172
Andres Moreceb8c5d2013-03-18 20:33:49 -05002173 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002174
2175//mike add:station mode check eapol-key challenge--->
2176{
Andres Moreb902fbf2013-02-25 20:32:51 -05002177 u8 Protocol_Version; //802.1x Authentication
2178 u8 Packet_Type; //802.1x Authentication
2179 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002180 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002181
Charles Clément21ec51f2010-05-18 10:08:14 -07002182 Protocol_Version = skb->data[ETH_HLEN];
2183 Packet_Type = skb->data[ETH_HLEN+1];
2184 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2185 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 -05002186 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002187 /* 802.1x OR eapol-key challenge frame transfer */
2188 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2189 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002190 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002191 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2192 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2193 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002194 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002195 PRINT_K("WPA ");
2196 }
2197 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002198 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002199 PRINT_K("WPA2(re-keying) ");
2200 }
2201 PRINT_K("Authentication completed!!\n");
2202 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002203 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002204 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002205 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002206 PRINT_K("WPA2 Authentication completed!!\n");
2207 }
2208 }
2209 }
2210}
2211//mike add:station mode check eapol-key challenge<---
2212
Andres More4e9b5e22013-02-12 20:36:30 -05002213 if (pDevice->bEncryptionEnable == true) {
2214 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002215 // get Transmit key
2216 do {
2217 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2218 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2219 pbyBSSID = pDevice->abyBSSID;
2220 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002221 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002222 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002223 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2224 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002225 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2226 break;
2227 }
2228 } else {
2229 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2230 break;
2231 }
2232 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002233 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2234 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002235 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2236 for (ii = 0; ii< 6; ii++)
2237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2238 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2239
2240 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002241 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002242 break;
2243 }
2244 // get group key
2245 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002246 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002247 pTransmitKey = NULL;
2248 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2249 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2250 }
2251 else
2252 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2253 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002254 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002255 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2256 }
Andres Moree269fc22013-02-12 20:36:29 -05002257 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002258 }
2259
2260 if (pDevice->bEnableHostWEP) {
2261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002262 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002263 pTransmitKey = &STempKey;
2264 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2265 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2266 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2267 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2268 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2269 memcpy(pTransmitKey->abyKey,
2270 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2271 pTransmitKey->uKeyLength
2272 );
2273 }
2274 }
2275
Andres Moreb902fbf2013-02-25 20:32:51 -05002276 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002277
2278 if (pDevice->bFixRate) {
2279 if (pDevice->byBBType == BB_TYPE_11B) {
2280 if (pDevice->uConnectionRate >= RATE_11M) {
2281 pDevice->wCurrentRate = RATE_11M;
2282 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002283 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002284 }
2285 } else {
2286 if ((pDevice->byBBType == BB_TYPE_11A) &&
2287 (pDevice->uConnectionRate <= RATE_6M)) {
2288 pDevice->wCurrentRate = RATE_6M;
2289 } else {
2290 if (pDevice->uConnectionRate >= RATE_54M)
2291 pDevice->wCurrentRate = RATE_54M;
2292 else
Andres More3eaca0d2013-02-25 20:32:52 -05002293 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002294 }
2295 }
2296 }
2297 else {
2298 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2299 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002300 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002301 // Multicast use highest data rate
2302 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2303 // preamble type
2304 pDevice->byPreambleType = pDevice->byShortPreamble;
2305 }
2306 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002307 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002308 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2309 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2310 pDevice->byPreambleType = pDevice->byShortPreamble;
2311
2312 }
2313 else {
2314 pDevice->byPreambleType = PREAMBLE_LONG;
2315 }
2316 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2317 }
2318 else {
2319 if (pDevice->byBBType != BB_TYPE_11A)
2320 pDevice->wCurrentRate = RATE_2M;
2321 else
2322 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2323 // abyCurrExtSuppRates[]
2324 pDevice->byPreambleType = PREAMBLE_SHORT;
2325 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2326 }
2327 }
2328 }
2329 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2330 // Infra STA rate decided from AP Node, index = 0
2331 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2332 }
2333 }
2334
Andres Moreceb8c5d2013-03-18 20:33:49 -05002335 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002336 if (pDevice->byBBType != BB_TYPE_11A) {
2337 pDevice->wCurrentRate = RATE_1M;
2338 pDevice->byACKRate = RATE_1M;
2339 pDevice->byTopCCKBasicRate = RATE_1M;
2340 pDevice->byTopOFDMBasicRate = RATE_6M;
2341 } else {
2342 pDevice->wCurrentRate = RATE_6M;
2343 pDevice->byACKRate = RATE_6M;
2344 pDevice->byTopCCKBasicRate = RATE_1M;
2345 pDevice->byTopOFDMBasicRate = RATE_6M;
2346 }
2347 }
Forest Bond92b96792009-06-13 07:38:31 -04002348
Andres More0cbd8d92010-05-06 20:34:29 -03002349 DBG_PRT(MSG_LEVEL_DEBUG,
2350 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2351 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002352
2353 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002354 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002355 }
2356
2357 if (pDevice->wCurrentRate <= RATE_11M) {
2358 byPktType = PK_TYPE_11B;
2359 }
2360
Andres More4e9b5e22013-02-12 20:36:30 -05002361 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002362 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2363 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002364 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002366 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2367 if (pTransmitKey == NULL) {
2368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2369 }
2370 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002371 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2373 }
2374 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2376 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002377 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002378 }
2379 }
2380 }
2381
Forest Bond92b96792009-06-13 07:38:31 -04002382 if (pDevice->bEnableHostWEP) {
2383 if ((uNodeIndex != 0) &&
2384 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2386 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002387 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002388 }
2389 }
2390 }
2391 else {
2392
Forest Bond92b96792009-06-13 07:38:31 -04002393 if (pTransmitKey == NULL) {
2394 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002395 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002396 dev_kfree_skb_irq(skb);
2397 pStats->tx_dropped++;
2398 return STATUS_FAILURE;
2399 }
Forest Bond92b96792009-06-13 07:38:31 -04002400 }
2401 }
2402
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002403 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2404
Forest Bond92b96792009-06-13 07:38:31 -04002405 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002406 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002407 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002408 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002409 pDevice->wCurrentRate,
2410 &uHeaderLen, &BytesToWrite
2411 );
2412
Andres Moree269fc22013-02-12 20:36:29 -05002413 if (fConvertedPacket == false) {
2414 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002415 dev_kfree_skb_irq(skb);
2416 return STATUS_FAILURE;
2417 }
2418
Andres More4e9b5e22013-02-12 20:36:30 -05002419 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002420 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002421 bScheduleCommand((void *) pDevice,
2422 WLAN_CMD_MAC_DISPOWERSAVING,
2423 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002424 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002425 }
2426 }
2427
Andres Moreb902fbf2013-02-25 20:32:51 -05002428 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002429 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002430
2431 pContext->pPacket = skb;
2432 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002433 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002434
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002435 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2436 &pContext->sEthHeader.h_dest[0],
2437 (u16)(BytesToWrite-uHeaderLen),
2438 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002439
2440 status = PIPEnsSendBulkOut(pDevice,pContext);
2441
Andres More4e9b5e22013-02-12 20:36:30 -05002442 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002443 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002444
Andres Moreb902fbf2013-02-25 20:32:51 -05002445 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002446 }
2447
2448 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002449 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002450 dev_kfree_skb_irq(skb);
2451 return STATUS_FAILURE;
2452 }
2453 else
2454 return 0;
2455
2456}
2457
Forest Bond92b96792009-06-13 07:38:31 -04002458/*
2459 * Description:
2460 * Relay packet send (AC1DMA) from rx dpc.
2461 *
2462 * Parameters:
2463 * In:
2464 * pDevice - Pointer to the adapter
2465 * pPacket - Pointer to rx packet
2466 * cbPacketSize - rx ethernet frame size
2467 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002468 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002469 *
Andres More4e9b5e22013-02-12 20:36:30 -05002470 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002471 */
2472
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002473int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2474 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002475{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002476 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002477 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002478 u32 BytesToWrite = 0, uHeaderLen = 0;
2479 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002480 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002481 SKeyItem STempKey;
2482 PSKeyItem pTransmitKey = NULL;
2483 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002484 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002485 u8 byPktTyp;
2486 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002487 u32 status;
2488 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002489
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002490 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002491
2492 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002493 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002494 }
2495
Andres Moreceb8c5d2013-03-18 20:33:49 -05002496 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002497
Andres More4e9b5e22013-02-12 20:36:30 -05002498 if (pDevice->bEncryptionEnable == true) {
2499 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002500 // get group key
2501 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002502 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002503 pTransmitKey = NULL;
2504 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2505 } else {
2506 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2507 }
2508 }
2509
2510 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002511 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002512 pTransmitKey = &STempKey;
2513 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2514 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2515 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2516 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2517 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2518 memcpy(pTransmitKey->abyKey,
2519 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2520 pTransmitKey->uKeyLength
2521 );
2522 }
2523 }
2524
2525 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002526 pContext->bBoolInUse = false;
2527 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002528 }
2529
Andres Moreb902fbf2013-02-25 20:32:51 -05002530 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002531
2532 if (pDevice->bFixRate) {
2533 if (pDevice->byBBType == BB_TYPE_11B) {
2534 if (pDevice->uConnectionRate >= RATE_11M) {
2535 pDevice->wCurrentRate = RATE_11M;
2536 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002537 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002538 }
2539 } else {
2540 if ((pDevice->byBBType == BB_TYPE_11A) &&
2541 (pDevice->uConnectionRate <= RATE_6M)) {
2542 pDevice->wCurrentRate = RATE_6M;
2543 } else {
2544 if (pDevice->uConnectionRate >= RATE_54M)
2545 pDevice->wCurrentRate = RATE_54M;
2546 else
Andres More3eaca0d2013-02-25 20:32:52 -05002547 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002548 }
2549 }
2550 }
2551 else {
2552 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2553 }
2554
Forest Bond92b96792009-06-13 07:38:31 -04002555 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002556 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002557 }
2558
2559 if (pDevice->wCurrentRate <= RATE_11M)
2560 byPktType = PK_TYPE_11B;
2561
Andres Moreabad19d2010-07-12 16:28:32 -03002562 BytesToWrite = uDataLen + ETH_FCS_LEN;
2563
Forest Bond92b96792009-06-13 07:38:31 -04002564 // Convert the packet to an usb frame and copy into our buffer
2565 // and send the irp.
2566
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002567 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2568
Forest Bond92b96792009-06-13 07:38:31 -04002569 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002570 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002571 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2572 pbySkbData, pTransmitKey, uNodeIndex,
2573 pDevice->wCurrentRate,
2574 &uHeaderLen, &BytesToWrite
2575 );
2576
Andres Moree269fc22013-02-12 20:36:29 -05002577 if (fConvertedPacket == false) {
2578 pContext->bBoolInUse = false;
2579 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002580 }
2581
Andres Moreb902fbf2013-02-25 20:32:51 -05002582 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002583 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002584
2585 pContext->pPacket = NULL;
2586 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002587 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002588
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002589 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2590 &pContext->sEthHeader.h_dest[0],
2591 (u16)(BytesToWrite - uHeaderLen),
2592 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002593
2594 status = PIPEnsSendBulkOut(pDevice,pContext);
2595
Andres More4e9b5e22013-02-12 20:36:30 -05002596 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002597}
2598