blob: 3186971eaa3fa8380b4c02d7964923bf436ab326 [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 Priestleyd56131d2013-01-17 23:15:22 +0000341static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
342 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400343{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000344 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400345
346 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
347 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500348 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400349 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500350 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400351 }
352
353 if (bNeedAck) {
354 return (uDataTime + pDevice->uSIFS + uAckTime);
355 }
356 else {
357 return uDataTime;
358 }
359}
360
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100361static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
362 u32 frame_length, u16 rate, int need_ack)
363{
364 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
365 frame_length, rate, need_ack));
366}
367
Forest Bond92b96792009-06-13 07:38:31 -0400368//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100369static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000370 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400371{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000372 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400373
374 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
375
Forest Bond92b96792009-06-13 07:38:31 -0400376 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
377 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
378 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
379 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
380 }
381 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
382 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
383 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
384 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
385 }
386 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
387 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
388 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
389 }
390 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
391 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
392 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
393 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
394 return uRrvTime;
395 }
396
397 //RTSRrvTime
398 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100399 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400400}
401
402//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100403static u16 s_uGetDataDuration(struct vnt_private *pDevice,
404 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400405{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100406 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400407
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100408 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100409 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100410 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
411 byPktType, 14, pDevice->byTopCCKBasicRate);
412 else
413 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
414 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100415 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100416 }
Forest Bond92b96792009-06-13 07:38:31 -0400417
Forest Bond92b96792009-06-13 07:38:31 -0400418 return 0;
419}
420
Forest Bond92b96792009-06-13 07:38:31 -0400421//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100422static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000423 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
424 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400425{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000426 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400427
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100428 switch (byDurType) {
429 case RTSDUR_BB:
430 case RTSDUR_BA:
431 case RTSDUR_BA_F0:
432 case RTSDUR_BA_F1:
433 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
434 14, pDevice->byTopCCKBasicRate);
435 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
436 s_uGetTxRsvTime(pDevice, byPktType,
437 cbFrameLength, wRate, bNeedAck);
438 break;
Forest Bond92b96792009-06-13 07:38:31 -0400439
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100440 case RTSDUR_AA:
441 case RTSDUR_AA_F0:
442 case RTSDUR_AA_F1:
443 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
444 14, pDevice->byTopOFDMBasicRate);
445 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
446 s_uGetTxRsvTime(pDevice, byPktType,
447 cbFrameLength, wRate, bNeedAck);
448 break;
Forest Bond92b96792009-06-13 07:38:31 -0400449
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100450 case CTSDUR_BA:
451 case CTSDUR_BA_F0:
452 case CTSDUR_BA_F1:
453 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100454 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100455 break;
Forest Bond92b96792009-06-13 07:38:31 -0400456
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100457 default:
458 break;
459 }
Forest Bond92b96792009-06-13 07:38:31 -0400460
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100461 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400462}
463
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100464static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
465 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
466{
467 /* Get SignalField,ServiceField,Length */
468 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
469 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
470 PK_TYPE_11B, &buf->b);
471
472 /* Get Duration and TimeStamp */
473 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
474 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
475
476 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
477 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
478 priv->byTopCCKBasicRate);
479
480 return buf->wDuration_a;
481}
482
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100483static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
484 u16 rate, struct vnt_tx_datahead_g_fb *buf,
485 u32 frame_len, int need_ack)
486{
487 /* Get SignalField,ServiceField,Length */
488 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
489
490 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
491 PK_TYPE_11B, &buf->b);
492
493 /* Get Duration and TimeStamp */
494 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
495 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
496
497 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
498 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
499
500 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
501 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
502 priv->byTopCCKBasicRate);
503
504 return buf->wDuration_a;
505}
506
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100507static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
508 u16 rate, struct vnt_tx_datahead_a_fb *buf,
509 u32 frame_len, int need_ack)
510{
511 /* Get SignalField,ServiceField,Length */
512 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
513 /* Get Duration and TimeStampOff */
514 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
515
516 buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
517 buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
518
519 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
520
521 return buf->wDuration;
522}
523
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100524static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
525 u16 rate, struct vnt_tx_datahead_ab *buf,
526 u32 frame_len, int need_ack)
527{
528 /* Get SignalField,ServiceField,Length */
529 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
530 /* Get Duration and TimeStampOff */
531 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
532
533 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
534
535 return buf->wDuration;
536}
537
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100538static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
539 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
540 u16 duration)
541{
542 rts->duration = duration;
543 rts->frame_control = TYPE_CTL_RTS;
544
545 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
546 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
547 else
548 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
549
550 if (priv->eOPMode == OP_MODE_AP)
551 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
552 else
553 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
554
555 return 0;
556}
557
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100558static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100559 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
560 u8 pkt_type, u32 frame_len, int need_ack,
561 u16 current_rate, u8 fb_option)
562{
563 u16 rts_frame_len = 20;
564
565 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
566 PK_TYPE_11B, &buf->b);
567 BBvCalculateParameter(priv, rts_frame_len,
568 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
569
570 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
571 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
572 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
573 pkt_type, current_rate, need_ack, fb_option);
574 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
575 pkt_type, current_rate, need_ack, fb_option);
576
577 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
578
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100579 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
580 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100581}
582
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100583static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100584 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
585 u8 pkt_type, u32 frame_len, int need_ack,
586 u16 current_rate, u8 fb_option)
587{
588 u16 rts_frame_len = 20;
589
590 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
591 PK_TYPE_11B, &buf->b);
592 BBvCalculateParameter(priv, rts_frame_len,
593 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
594
595
596 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
597 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
598 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
599 pkt_type, current_rate, need_ack, fb_option);
600 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
601 pkt_type, current_rate, need_ack, fb_option);
602
603
604 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100605 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100606 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100607 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100608 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100609 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100610 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100611 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100612
613 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
614
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100615 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
616 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100617}
618
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100619static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
Malcolm Priestley17126332013-08-26 11:09:38 +0100620 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
621 u8 pkt_type, u32 frame_len, int need_ack,
622 u16 current_rate, u8 fb_option)
623{
624 u16 rts_frame_len = 20;
625
626 BBvCalculateParameter(priv, rts_frame_len,
627 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
628
629 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
630 pkt_type, current_rate, need_ack, fb_option);
631
632 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
633
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100634 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
635 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100636}
637
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100638static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100639 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
640 u8 pkt_type, u32 frame_len, int need_ack,
641 u16 current_rate, u8 fb_option)
642{
643 u16 rts_frame_len = 20;
644
645 BBvCalculateParameter(priv, rts_frame_len,
646 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
647
648 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
649 pkt_type, current_rate, need_ack, fb_option);
650
651 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100652 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100653
654 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100655 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100656
657 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
658
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100659 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
660 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100661}
662
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100663static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100664 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500665 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400666{
Forest Bond92b96792009-06-13 07:38:31 -0400667
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100668 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100669 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400670
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100671 /* Note: So far RTSHead doesn't appear in ATIM
672 * & Beacom DMA, so we don't need to take them
673 * into account.
674 * Otherwise, we need to modified codes for them.
675 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100676 switch (byPktType) {
677 case PK_TYPE_11GB:
678 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100679 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100680 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100681 psEthHeader, byPktType, cbFrameLength,
682 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100683 else
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100684 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100685 psEthHeader, byPktType, cbFrameLength,
686 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100687 break;
688 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100689 if (byFBOption) {
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100690 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100691 psEthHeader, byPktType, cbFrameLength,
692 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100693 break;
694 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100695 case PK_TYPE_11B:
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100696 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100697 psEthHeader, byPktType, cbFrameLength,
698 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100699 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100700
701 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400702}
703
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100704static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100705 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
706 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400707{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000708 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400709
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100710 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100711 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400712
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100713 if (byFBOption != AUTO_FB_NONE) {
714 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100715 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100716 /* Get SignalField,ServiceField,Length */
717 BBvCalculateParameter(pDevice, uCTSFrameLen,
718 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100719 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
720 cbFrameLength, byPktType,
721 wCurrentRate, bNeedAck, byFBOption);
722 /* Get CTSDuration_ba_f0 */
723 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100724 CTSDUR_BA_F0, cbFrameLength, byPktType,
725 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100726 /* Get CTSDuration_ba_f1 */
727 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100728 CTSDUR_BA_F1, cbFrameLength, byPktType,
729 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100730 /* Get CTS Frame body */
731 pBuf->data.duration = pBuf->wDuration_ba;
732 pBuf->data.frame_control = TYPE_CTL_CTS;
733 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100734
735 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
736 &pBuf->data_head, cbFrameLength, bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100737 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100738 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100739 /* Get SignalField,ServiceField,Length */
740 BBvCalculateParameter(pDevice, uCTSFrameLen,
741 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100742 /* Get CTSDuration_ba */
743 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
744 CTSDUR_BA, cbFrameLength, byPktType,
745 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100746 /*Get CTS Frame body*/
747 pBuf->data.duration = pBuf->wDuration_ba;
748 pBuf->data.frame_control = TYPE_CTL_CTS;
749 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100750
751 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
752 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400753 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100754
755 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400756}
757
Forest Bond92b96792009-06-13 07:38:31 -0400758/*+
759 *
760 * Description:
761 * Generate FIFO control for MAC & Baseband controller
762 *
763 * Parameters:
764 * In:
765 * pDevice - Pointer to adpater
766 * pTxDataHead - Transmit Data Buffer
767 * pTxBufHead - pTxBufHead
768 * pvRrvTime - pvRrvTime
769 * pvRTS - RTS Buffer
770 * pCTS - CTS Buffer
771 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
772 * bNeedACK - If need ACK
773 * uDMAIdx - DMA Index
774 * Out:
775 * none
776 *
777 * Return Value: none
778 *
779-*/
Andres Morecc856e62010-05-17 21:34:01 -0300780
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100781static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100782 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100783 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
784 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400785{
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100786 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100787 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000788 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000789 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400790
Malcolm Priestley92928f12013-10-07 20:14:01 +0100791 pFifoHead->wReserved = wCurrentRate;
792 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400793
Malcolm Priestley92928f12013-10-07 20:14:01 +0100794 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
795 byFBOption = AUTO_FB_0;
796 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
797 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400798
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100799 if (!pFifoHead)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100800 return 0;
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100801
Malcolm Priestley92928f12013-10-07 20:14:01 +0100802 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
803 if (need_rts) {
804 struct vnt_rrv_time_rts *pBuf =
805 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100806
Malcolm Priestley92928f12013-10-07 20:14:01 +0100807 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
808 byPktType, cbFrameSize, wCurrentRate);
809 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
810 byPktType, cbFrameSize, wCurrentRate);
811 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100812 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100813
Malcolm Priestley92928f12013-10-07 20:14:01 +0100814 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
815 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
816 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
817 PK_TYPE_11B, cbFrameSize,
818 pDevice->byTopCCKBasicRate, bNeedACK);
819
820 if (need_mic) {
821 *mic_hdr = &tx_buffer->
822 tx_head.tx_rts.tx.mic.hdr;
823 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
824 } else {
825 head = &tx_buffer->tx_head.tx_rts.tx.head;
826 }
827
828 /* Fill RTS */
829 return s_vFillRTSHead(pDevice, byPktType, head,
830 cbFrameSize, bNeedACK, psEthHeader,
831 wCurrentRate, byFBOption);
832
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100833 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100834 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
835 tx_head.tx_cts.cts;
836
837 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
838 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
839 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
840 PK_TYPE_11B, cbFrameSize,
841 pDevice->byTopCCKBasicRate, bNeedACK);
842
843 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
844 byPktType, cbFrameSize, wCurrentRate);
845
846 if (need_mic) {
847 *mic_hdr = &tx_buffer->
848 tx_head.tx_cts.tx.mic.hdr;
849 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
850 } else {
851 head = &tx_buffer->tx_head.tx_cts.tx.head;
852 }
853
854 /* Fill CTS */
855 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
856 head, cbFrameSize, bNeedACK, wCurrentRate,
857 byFBOption);
858 }
859 } else if (byPktType == PK_TYPE_11A) {
860 if (need_mic) {
861 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
862 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
863 } else {
864 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100865 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100866
Malcolm Priestley92928f12013-10-07 20:14:01 +0100867 if (need_rts) {
868 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
869 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100870
Malcolm Priestley92928f12013-10-07 20:14:01 +0100871 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100872 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100873
Malcolm Priestley92928f12013-10-07 20:14:01 +0100874 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
875 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
876
877 /* Fill RTS */
878 return s_vFillRTSHead(pDevice, byPktType, head,
879 cbFrameSize, bNeedACK, psEthHeader,
880 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100881 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100882 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
883 tx_head.tx_ab.ab;
884
885 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
886 PK_TYPE_11A, cbFrameSize,
887 wCurrentRate, bNeedACK);
888
889 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
890 wCurrentRate, &head->data_head_a_fb,
891 cbFrameSize, bNeedACK);
892 }
893 } else if (byPktType == PK_TYPE_11B) {
894 if (need_mic) {
895 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
896 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
897 } else {
898 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100899 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100900
Malcolm Priestley92928f12013-10-07 20:14:01 +0100901 if (need_rts) {
902 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
903 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100904
Malcolm Priestley92928f12013-10-07 20:14:01 +0100905 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100906 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100907
Malcolm Priestley92928f12013-10-07 20:14:01 +0100908 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
909 PK_TYPE_11B, cbFrameSize, wCurrentRate,
910 bNeedACK);
911
912 /* Fill RTS */
913 return s_vFillRTSHead(pDevice, byPktType, head,
914 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100915 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100916 } else {
917 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
918 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100919
Malcolm Priestley92928f12013-10-07 20:14:01 +0100920 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
921 PK_TYPE_11B, cbFrameSize,
922 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100923
Malcolm Priestley92928f12013-10-07 20:14:01 +0100924 return vnt_rxtx_datahead_ab(pDevice, byPktType,
925 wCurrentRate, &head->data_head_ab,
926 cbFrameSize, bNeedACK);
927 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100928 }
929
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100930 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400931}
932/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500933 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500934 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300935 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400936*/
937
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000938static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100939 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100940 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
941 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
942 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400943{
Malcolm Priestleyd66caad2013-09-17 19:54:35 +0100944 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000945 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
946 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000947 u32 cb802_1_H_len;
948 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
949 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100950 int bNeedACK;
951 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000952 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
953 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
954 u8 abySNAP_Bridgetunnel[ETH_ALEN]
955 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
956 u32 uDuration;
957 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100958 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000959 u8 byFBOption = AUTO_FB_NONE, byFragType;
960 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100961 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000962 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500963 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100964
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +0100965 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400966
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000967 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500968 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
969 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000970 }
Forest Bond92b96792009-06-13 07:38:31 -0400971
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000972 /* Get pkt type */
973 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
974 cb802_1_H_len = 8;
975 else
976 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400977
Charles Clément21ec51f2010-05-18 10:08:14 -0700978 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400979
980 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500981 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400982
Andres More22040bb2010-08-02 20:21:44 -0300983 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000984 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -0500985 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -0500986 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -0300987 pTxBufHead->wFIFOCtl =
988 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
989 } else {
Andres More4e9b5e22013-02-12 20:36:30 -0500990 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -0300991 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
992 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +0000993 } else {
994 /* MSDUs in Infra mode always need ACK */
995 bNeedACK = true;
996 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
997 }
Forest Bond92b96792009-06-13 07:38:31 -0400998
999 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1000
Forest Bond92b96792009-06-13 07:38:31 -04001001 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001002 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1003
Andres More3eaca0d2013-02-25 20:32:52 -05001004 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001005
1006 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001007 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001008 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1009 }
1010
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001011 /* Set Auto Fallback Ctl */
1012 if (wCurrentRate >= RATE_18M) {
1013 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1014 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1015
1016 pDevice->tx_rate_fb0 =
1017 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1018 pDevice->tx_rate_fb1 =
1019 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1020
1021 byFBOption = AUTO_FB_0;
1022 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1023 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1024 pDevice->tx_rate_fb0 =
1025 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1026 pDevice->tx_rate_fb1 =
1027 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1028
1029 byFBOption = AUTO_FB_1;
1030 }
1031 }
Forest Bond92b96792009-06-13 07:38:31 -04001032
Andres More4e9b5e22013-02-12 20:36:30 -05001033 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001034 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1035 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1036 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1037 }
1038 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1039 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1040 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1041 }
1042 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1043 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1044 }
1045 }
1046 }
1047
Forest Bond92b96792009-06-13 07:38:31 -04001048 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1049 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1050 cbIVlen = 4;
1051 cbICVlen = 4;
1052 }
1053 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1054 cbIVlen = 8;//IV+ExtIV
1055 cbMIClen = 8;
1056 cbICVlen = 4;
1057 }
1058 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1059 cbIVlen = 8;//RSN Header
1060 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001061 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001062 }
Andres Moree269fc22013-02-12 20:36:29 -05001063 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001064 //MAC Header should be padding 0 to DW alignment.
1065 uPadding = 4 - (cbMACHdLen%4);
1066 uPadding %= 4;
1067 }
1068 }
1069
1070 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1071
Andres Moree269fc22013-02-12 20:36:29 -05001072 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1073 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001074 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001075 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001076 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1077 }
1078
Andres Moreb902fbf2013-02-25 20:32:51 -05001079 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001080 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1081
Forest Bond92b96792009-06-13 07:38:31 -04001082 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1083 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001084 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001085 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001086 cbMICHDR + sizeof(struct vnt_rts_g);
Forest Bond92b96792009-06-13 07:38:31 -04001087 }
1088 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001089 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001090 cbMICHDR + sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001091 }
1092 } else {
1093 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001094 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001095 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001096 cbMICHDR + sizeof(struct vnt_rts_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001097 }
Andres Moree269fc22013-02-12 20:36:29 -05001098 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001099 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley5b852f52013-10-01 15:54:56 +01001100 cbMICHDR + sizeof(struct vnt_cts_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001101 }
1102 } // Auto Fall Back
1103 }
1104 else {//802.11a/b packet
1105 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001106 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001107 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley5634a5a2013-10-01 16:00:20 +01001108 cbMICHDR + sizeof(struct vnt_rts_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001109 }
Andres Moree269fc22013-02-12 20:36:29 -05001110 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001111 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001112 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001113 }
1114 } else {
1115 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001116 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001117 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +01001118 cbMICHDR + sizeof(struct vnt_rts_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001119 }
Andres Moree269fc22013-02-12 20:36:29 -05001120 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001121 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001122 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001123 }
1124 } // Auto Fall Back
1125 }
1126
Andres Moreb902fbf2013-02-25 20:32:51 -05001127 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1128 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1129 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001130
Forest Bond92b96792009-06-13 07:38:31 -04001131 //=========================
1132 // No Fragmentation
1133 //=========================
1134 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1135 byFragType = FRAGCTL_NONFRAG;
1136 //uDMAIdx = TYPE_AC0DMA;
1137 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1138
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001139 /* Fill FIFO, RrvTime, RTS and CTS */
1140 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1141 tx_buffer, &pMICHDR, cbMICHDR,
1142 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001143
Forest Bond92b96792009-06-13 07:38:31 -04001144 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001145 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001146 byFragType, uDMAIdx, 0);
1147
Andres More4e9b5e22013-02-12 20:36:30 -05001148 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001149 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001150 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001151 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001152
1153 if (pDevice->bEnableHostWEP) {
1154 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1155 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1156 }
1157 }
1158
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001159 /* 802.1H */
1160 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001161 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001162 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001163 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001164 abySNAP_Bridgetunnel, 6);
1165 else
1166 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001167
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001168 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001169
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001170 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1171 }
Forest Bond92b96792009-06-13 07:38:31 -04001172
Forest Bond92b96792009-06-13 07:38:31 -04001173 if (pPacket != NULL) {
1174 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001175 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001176 (pPacket + ETH_HLEN),
1177 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001178 );
1179
1180 } else {
1181 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001182 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001183 }
1184
Andres More4e9b5e22013-02-12 20:36:30 -05001185 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001186
1187 ///////////////////////////////////////////////////////////////////
1188
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001189 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1190 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1191 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1192 }
Forest Bond92b96792009-06-13 07:38:31 -04001193 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001194 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1195 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001196 }
1197 else {
Andres More52a7e642013-02-25 20:32:53 -05001198 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1199 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001200 }
1201 // DO Software Michael
1202 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001203 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001204 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001205 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001206 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1207 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001208
1209 ///////////////////////////////////////////////////////////////////
1210
1211 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1212 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001213 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001214 //}
1215 //DBG_PRN_GRP12(("\n\n\n"));
1216
1217 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1218
Andres More52a7e642013-02-25 20:32:53 -05001219 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1220 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001221
1222 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1223 MIC_vUnInit();
1224
Andres More4e9b5e22013-02-12 20:36:30 -05001225 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001226 *pdwMIC_L = 0;
1227 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001228 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001229 }
1230 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1231 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1232 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1233 }
1234
Andres More4e9b5e22013-02-12 20:36:30 -05001235 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001236
Andres More3eaca0d2013-02-25 20:32:52 -05001237 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001238
Andres More4e9b5e22013-02-12 20:36:30 -05001239 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1240 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1241 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001242 cbFrameSize -= cbICVlen;
1243 }
1244
Forest Bond92b96792009-06-13 07:38:31 -04001245 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001246
1247 *pcbHeaderLen = cbHeaderLength;
1248 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1249
Forest Bond92b96792009-06-13 07:38:31 -04001250 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001251 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001252
Andres More4e9b5e22013-02-12 20:36:30 -05001253 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001254
1255}
1256
Forest Bond92b96792009-06-13 07:38:31 -04001257/*+
1258 *
1259 * Description:
1260 * Translate 802.3 to 802.11 header
1261 *
1262 * Parameters:
1263 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001264 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001265 * dwTxBufferAddr - Transmit Buffer
1266 * pPacket - Packet from upper layer
1267 * cbPacketSize - Transmit Data Length
1268 * Out:
1269 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1270 * pcbAppendPayload - size of append payload for 802.1H translation
1271 *
1272 * Return Value: none
1273 *
1274-*/
1275
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001276static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001277 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001278 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001279{
Andres More1cac4a42013-03-18 20:33:50 -05001280 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001281
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001282 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001283
1284 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001285 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001286 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001287 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001288 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1289 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001290 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001291 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001292 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001293 } else {
1294 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001295 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001296 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001297 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001298 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001299 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001300 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001301 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001302 &(pDevice->abyBSSID[0]),
1303 ETH_ALEN);
1304 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001305 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001306 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001307 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001308 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001309 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001310 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001311 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001312 &(pDevice->abyBSSID[0]),
1313 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001314 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001315 }
1316 }
1317
1318 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001319 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001320
Andres More1cac4a42013-03-18 20:33:50 -05001321 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001322
Andres More1cac4a42013-03-18 20:33:50 -05001323 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001324
1325 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001326 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001327
1328 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1329 pDevice->wSeqCounter++;
1330 if (pDevice->wSeqCounter > 0x0fff)
1331 pDevice->wSeqCounter = 0;
1332 }
1333
1334 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001335 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001336 }
1337}
1338
Forest Bond92b96792009-06-13 07:38:31 -04001339/*+
1340 *
1341 * Description:
1342 * Request instructs a MAC to transmit a 802.11 management packet through
1343 * the adapter onto the medium.
1344 *
1345 * Parameters:
1346 * In:
1347 * hDeviceContext - Pointer to the adapter
1348 * pPacket - A pointer to a descriptor for the packet to transmit
1349 * Out:
1350 * none
1351 *
Andres Moree269fc22013-02-12 20:36:29 -05001352 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001353 *
1354-*/
1355
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001356CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1357 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001358{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001359 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001360 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001361 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001362 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001363 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001364 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001365 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001366 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001367 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001368 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001369 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1370 u32 uPadding = 0;
1371 u16 wTxBufSize;
1372 u32 cbMacHdLen;
1373 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001374
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001375 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001376
1377 if (NULL == pContext) {
1378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1379 return CMD_STATUS_RESOURCES;
1380 }
1381
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001382 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001383 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001384 pTxBufHead = &pTX_Buffer->fifo_head;
1385 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1386 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001387
1388 if (pDevice->byBBType == BB_TYPE_11A) {
1389 wCurrentRate = RATE_6M;
1390 byPktType = PK_TYPE_11A;
1391 } else {
1392 wCurrentRate = RATE_1M;
1393 byPktType = PK_TYPE_11B;
1394 }
1395
1396 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1397 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1398 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1399 // to set power here.
1400 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1401 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1402 } else {
1403 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1404 }
1405 pDevice->wCurrentRate = wCurrentRate;
1406
Forest Bond92b96792009-06-13 07:38:31 -04001407 //Set packet type
1408 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1409 pTxBufHead->wFIFOCtl = 0;
1410 }
1411 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1412 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1413 }
1414 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1415 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1416 }
1417 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1418 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1419 }
1420
1421 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1422 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1423
Andres More22040bb2010-08-02 20:21:44 -03001424 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001425 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001426 }
1427 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001428 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001429 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1430 };
1431
1432 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1433 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1434
1435 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1436 //Set Preamble type always long
1437 //pDevice->byPreambleType = PREAMBLE_LONG;
1438 // probe-response don't retry
1439 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001440 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001441 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1442 //}
1443 }
1444
1445 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1446
1447 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001448 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001449 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1450 } else {
1451 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1452 }
1453
1454 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001455 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001456
1457 // Notes:
1458 // Although spec says MMPDU can be fragmented; In most case,
1459 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001460
1461 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1462 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1463 cbIVlen = 4;
1464 cbICVlen = 4;
1465 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1466 }
1467 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1468 cbIVlen = 8;//IV+ExtIV
1469 cbMIClen = 8;
1470 cbICVlen = 4;
1471 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1472 //We need to get seed here for filling TxKey entry.
1473 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1474 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1475 }
1476 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1477 cbIVlen = 8;//RSN Header
1478 cbICVlen = 8;//MIC
1479 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001480 }
1481 //MAC Header should be padding 0 to DW alignment.
1482 uPadding = 4 - (cbMacHdLen%4);
1483 uPadding %= 4;
1484 }
1485
1486 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1487
1488 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001489 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001490 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1491 }
1492 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1493
1494 //Set RrvTime/RTS/CTS Buffer
1495 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001496 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001497 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001498 }
1499 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001500 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001501 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001502 }
1503
Andres Moreceb8c5d2013-03-18 20:33:49 -05001504 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001505 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1506 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001507 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001508 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1509 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001510 //=========================
1511 // No Fragmentation
1512 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001513 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001514
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001515 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001516 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001517 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001518 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001519
Andres More1cac4a42013-03-18 20:33:50 -05001520 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001521
1522 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1523
1524 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001525 u8 * pbyIVHead;
1526 u8 * pbyPayloadHead;
1527 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001528 PSKeyItem pTransmitKey = NULL;
1529
Andres Moreb902fbf2013-02-25 20:32:51 -05001530 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1531 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001532 do {
1533 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001534 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001535 pbyBSSID = pDevice->abyBSSID;
1536 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001537 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001538 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001539 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001540 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1541 break;
1542 }
1543 } else {
1544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1545 break;
1546 }
1547 }
1548 // get group key
1549 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001550 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001551 pTransmitKey = NULL;
1552 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1553 } else {
1554 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1555 }
Andres Moree269fc22013-02-12 20:36:29 -05001556 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001557 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001558 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001559 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001560
Jim Lieb3e362592009-08-12 14:54:11 -07001561 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001562 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001563 cbFrameBodySize);
1564 }
1565 else {
1566 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001567 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001568 }
1569
Andres More1cac4a42013-03-18 20:33:50 -05001570 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001571 pDevice->wSeqCounter++ ;
1572 if (pDevice->wSeqCounter > 0x0fff)
1573 pDevice->wSeqCounter = 0;
1574
1575 if (bIsPSPOLL) {
1576 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001577 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001578 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1579 // in the same place of other packet's Duration-field).
1580 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001581 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001582 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1583 tx_cts.tx.head.cts_g.data_head;
1584 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001585 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001586 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001587 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1588 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001589 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1590 tx_ab.tx.head.data_head_ab;
1591 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001592 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1593 }
Forest Bond92b96792009-06-13 07:38:31 -04001594 }
1595
Andres More3eaca0d2013-02-25 20:32:52 -05001596 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001597 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001598 pTX_Buffer->byType = 0x00;
1599
1600 pContext->pPacket = NULL;
1601 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001602 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001603
Andres More1cac4a42013-03-18 20:33:50 -05001604 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001605 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1606 &pMACHeader->addr1[0], (u16)cbFrameSize,
1607 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001608 }
1609 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001610 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1611 &pMACHeader->addr3[0], (u16)cbFrameSize,
1612 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001613 }
1614
1615 PIPEnsSendBulkOut(pDevice,pContext);
1616 return CMD_STATUS_PENDING;
1617}
1618
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001619CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1620 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001621{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001622 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001623 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001624 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1625 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001626 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001627 u16 wCurrentRate;
1628 u32 cbFrameBodySize;
1629 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001630 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001631 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001632
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001633 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001634 if (NULL == pContext) {
1635 status = CMD_STATUS_RESOURCES;
1636 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1637 return status ;
1638 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001639
1640 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001641 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001642
1643 cbFrameBodySize = pPacket->cbPayloadLen;
1644
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001645 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001646
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001647 if (pDevice->byBBType == BB_TYPE_11A) {
1648 wCurrentRate = RATE_6M;
1649
1650 /* Get SignalField,ServiceField,Length */
1651 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1652 PK_TYPE_11A, &short_head->ab);
1653
1654 /* Get Duration and TimeStampOff */
1655 short_head->duration = s_uGetDataDuration(pDevice,
1656 PK_TYPE_11A, false);
1657 short_head->time_stamp_off =
1658 vnt_time_stamp_off(pDevice, wCurrentRate);
1659 } else {
1660 wCurrentRate = RATE_1M;
1661 short_head->fifo_ctl |= FIFOCTL_11B;
1662
1663 /* Get SignalField,ServiceField,Length */
1664 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1665 PK_TYPE_11B, &short_head->ab);
1666
1667 /* Get Duration and TimeStampOff */
1668 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001669 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001670 short_head->time_stamp_off =
1671 vnt_time_stamp_off(pDevice, wCurrentRate);
1672 }
1673
Forest Bond92b96792009-06-13 07:38:31 -04001674
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001675 /* Generate Beacon Header */
1676 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001677
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001678 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1679
1680 pMACHeader->duration_id = 0;
1681 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1682 pDevice->wSeqCounter++;
1683 if (pDevice->wSeqCounter > 0x0fff)
1684 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001685
1686 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1687
Andres More3eaca0d2013-02-25 20:32:52 -05001688 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001689 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001690 pTX_Buffer->byType = 0x01;
1691
1692 pContext->pPacket = NULL;
1693 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001694 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001695
1696 PIPEnsSendBulkOut(pDevice,pContext);
1697 return CMD_STATUS_PENDING;
1698
1699}
1700
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001701void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1702{
1703 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001704 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001705 struct vnt_tx_fifo_head *pTxBufHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001706 u8 byPktType;
1707 u8 *pbyTxBufferAddr;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001708 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001709 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001710 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001711 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001712 u32 cbFrameSize;
1713 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1714 u32 uPadding = 0;
1715 u32 cbMICHDR = 0, uLength = 0;
1716 u32 dwMICKey0, dwMICKey1;
1717 u32 dwMIC_Priority;
1718 u32 *pdwMIC_L, *pdwMIC_R;
1719 u16 wTxBufSize;
1720 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001721 struct ethhdr sEthHeader;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001722 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001723 u32 wCurrentRate = RATE_1M;
1724 PUWLAN_80211HDR p80211Header;
1725 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001726 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001727 SKeyItem STempKey;
1728 PSKeyItem pTransmitKey = NULL;
1729 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1730 u32 cbExtSuppRate = 0;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001731 struct vnt_usb_send_context *pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001732
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001733 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001734
1735 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1736 cbFrameBodySize = 0;
1737 }
1738 else {
1739 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1740 }
1741 p80211Header = (PUWLAN_80211HDR)skb->data;
1742
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001743 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001744
1745 if (NULL == pContext) {
1746 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1747 dev_kfree_skb_irq(skb);
1748 return ;
1749 }
1750
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001751 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001752 pTxBufHead = &pTX_Buffer->fifo_head;
1753 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1754 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001755
1756 if (pDevice->byBBType == BB_TYPE_11A) {
1757 wCurrentRate = RATE_6M;
1758 byPktType = PK_TYPE_11A;
1759 } else {
1760 wCurrentRate = RATE_1M;
1761 byPktType = PK_TYPE_11B;
1762 }
1763
1764 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1765 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1766 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1767 // to set power here.
1768 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1769 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1770 } else {
1771 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1772 }
1773
1774 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1775
1776 //Set packet type
1777 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1778 pTxBufHead->wFIFOCtl = 0;
1779 }
1780 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1781 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1782 }
1783 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1784 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1785 }
1786 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1787 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1788 }
1789
1790 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1791 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1792
Andres More22040bb2010-08-02 20:21:44 -03001793 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001794 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001795 if (pDevice->bEnableHostWEP) {
1796 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001797 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001798 }
Forest Bond92b96792009-06-13 07:38:31 -04001799 }
1800 else {
1801 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001802 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001803 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001804 }
Andres More4e9b5e22013-02-12 20:36:30 -05001805 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001806 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1807 };
1808
1809 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1810 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1811
1812 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1813 //Set Preamble type always long
1814 //pDevice->byPreambleType = PREAMBLE_LONG;
1815
1816 // probe-response don't retry
1817 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001818 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001819 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1820 //}
1821 }
1822
1823 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1824
1825 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001826 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001827 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1828 } else {
1829 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1830 }
1831
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001832 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001833 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1834
1835 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1836 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1837 }
1838
1839 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1840 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1841 }
1842
1843 if (cbExtSuppRate >0) {
1844 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1845 }
1846 }
1847
Forest Bond92b96792009-06-13 07:38:31 -04001848 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001849 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001850
1851 // Notes:
1852 // Although spec says MMPDU can be fragmented; In most case,
1853 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001854
Forest Bond92b96792009-06-13 07:38:31 -04001855 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1856 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1857 cbIVlen = 4;
1858 cbICVlen = 4;
1859 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1860 }
1861 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1862 cbIVlen = 8;//IV+ExtIV
1863 cbMIClen = 8;
1864 cbICVlen = 4;
1865 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1866 //We need to get seed here for filling TxKey entry.
1867 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1868 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1869 }
1870 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1871 cbIVlen = 8;//RSN Header
1872 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001873 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001874 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001875 }
1876 //MAC Header should be padding 0 to DW alignment.
1877 uPadding = 4 - (cbMacHdLen%4);
1878 uPadding %= 4;
1879 }
1880
1881 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1882
1883 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001884 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001885 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1886 }
1887 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1888
Forest Bond92b96792009-06-13 07:38:31 -04001889 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01001890 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001891 sizeof(struct vnt_cts);
Forest Bond92b96792009-06-13 07:38:31 -04001892
1893 }
1894 else {//802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001895 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001896 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001897 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05001898 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001899 &(p80211Header->sA3.abyAddr1[0]),
1900 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001901 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001902 &(p80211Header->sA3.abyAddr2[0]),
1903 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001904 //=========================
1905 // No Fragmentation
1906 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001907 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001908
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001909 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001910 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001911 pTX_Buffer, &pMICHDR, cbMICHDR,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001912 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001913
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001914 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001915
1916 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1917
Andres Moreb902fbf2013-02-25 20:32:51 -05001918 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1919 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1920 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04001921
1922 // Copy the Packet into a tx Buffer
1923 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1924
1925 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05001926 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04001927 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1928
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001929 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04001930 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1931 if (cbExtSuppRate != 0) {
1932 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1933 memcpy((pbyPayloadHead + cbFrameBodySize),
1934 pMgmt->abyCurrSuppRates,
1935 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1936 );
1937 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1938 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1939 pMgmt->abyCurrExtSuppRates,
1940 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1941 );
1942 }
1943 }
1944
1945 // Set wep
1946 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1947
1948 if (pDevice->bEnableHostWEP) {
1949 pTransmitKey = &STempKey;
1950 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1951 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1952 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1953 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1954 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1955 memcpy(pTransmitKey->abyKey,
1956 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1957 pTransmitKey->uKeyLength
1958 );
1959 }
1960
1961 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1962
Andres More52a7e642013-02-25 20:32:53 -05001963 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1964 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001965
1966 // DO Software Michael
1967 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001968 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001969 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001970 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001971 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1972 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001973
1974 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1975
1976 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1977
Andres More52a7e642013-02-25 20:32:53 -05001978 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1979 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001980
1981 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1982 MIC_vUnInit();
1983
Andres More4e9b5e22013-02-12 20:36:30 -05001984 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001985 *pdwMIC_L = 0;
1986 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001987 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001988 }
1989
1990 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1991 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001992 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
1993 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04001994
1995 }
1996
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001997 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001998 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001999
2000 if (pDevice->bEnableHostWEP) {
2001 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2002 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2003 }
2004
2005 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002006 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002007 }
2008 }
2009
Andres More1cac4a42013-03-18 20:33:50 -05002010 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002011 pDevice->wSeqCounter++ ;
2012 if (pDevice->wSeqCounter > 0x0fff)
2013 pDevice->wSeqCounter = 0;
2014
Forest Bond92b96792009-06-13 07:38:31 -04002015 if (bIsPSPOLL) {
2016 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2017 // of FIFO control header.
2018 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2019 // in the same place of other packet's Duration-field).
2020 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002021 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002022 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2023 tx_cts.tx.head.cts_g.data_head;
2024 data_head->wDuration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002025 cpu_to_le16(p80211Header->sA2.wDurationID);
Malcolm Priestley78363fd2013-10-01 15:52:16 +01002026 data_head->wDuration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002027 cpu_to_le16(p80211Header->sA2.wDurationID);
2028 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01002029 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2030 tx_ab.tx.head.data_head_ab;
2031 data_head->wDuration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01002032 cpu_to_le16(p80211Header->sA2.wDurationID);
2033 }
Forest Bond92b96792009-06-13 07:38:31 -04002034 }
2035
Andres More3eaca0d2013-02-25 20:32:52 -05002036 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002037 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002038 pTX_Buffer->byType = 0x00;
2039
2040 pContext->pPacket = skb;
2041 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002042 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002043
Andres More1cac4a42013-03-18 20:33:50 -05002044 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002045 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2046 &pMACHeader->addr1[0], (u16)cbFrameSize,
2047 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002048 }
2049 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002050 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2051 &pMACHeader->addr3[0], (u16)cbFrameSize,
2052 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002053 }
2054 PIPEnsSendBulkOut(pDevice,pContext);
2055 return ;
2056
2057}
2058
Forest Bond92b96792009-06-13 07:38:31 -04002059//TYPE_AC0DMA data tx
2060/*
2061 * Description:
2062 * Tx packet via AC0DMA(DMA1)
2063 *
2064 * Parameters:
2065 * In:
2066 * pDevice - Pointer to the adapter
2067 * skb - Pointer to tx skb packet
2068 * Out:
2069 * void
2070 *
2071 * Return Value: NULL
2072 */
2073
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002074int nsDMA_tx_packet(struct vnt_private *pDevice,
2075 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002076{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002077 struct net_device_stats *pStats = &pDevice->stats;
2078 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002079 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002080 u32 BytesToWrite = 0, uHeaderLen = 0;
2081 u32 uNodeIndex = 0;
2082 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2083 u16 wAID;
2084 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002085 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002086 PSKeyItem pTransmitKey = NULL;
2087 SKeyItem STempKey;
2088 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002089 int bTKIP_UseGTK = false;
2090 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002091 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002092 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002093 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002094 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002095 u32 status;
2096 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002097 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002098
Forest Bond92b96792009-06-13 07:38:31 -04002099 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2100
2101 if (pDevice->uAssocCount == 0) {
2102 dev_kfree_skb_irq(skb);
2103 return 0;
2104 }
2105
Andres Moreb902fbf2013-02-25 20:32:51 -05002106 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002107 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002108 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002109 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2110
2111 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2112 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2113 // set tx map
2114 pMgmt->abyPSTxMap[0] |= byMask[0];
2115 return 0;
2116 }
Masanari Iida93184692012-08-13 21:21:50 +09002117 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002118
2119 if (pDevice->byBBType != BB_TYPE_11A)
2120 pDevice->wCurrentRate = RATE_2M;
2121 else
2122 pDevice->wCurrentRate = RATE_24M;
2123 // long preamble type
2124 pDevice->byPreambleType = PREAMBLE_SHORT;
2125
2126 }else {
2127
Andres Moreb902fbf2013-02-25 20:32:51 -05002128 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002129
2130 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2131
2132 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2133
2134 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2135 // set tx map
2136 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2137 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2138 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2139 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2140
2141 return 0;
2142 }
2143 // AP rate decided from node
2144 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2145 // tx preamble decided from node
2146
2147 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2148 pDevice->byPreambleType = pDevice->byShortPreamble;
2149
2150 }else {
2151 pDevice->byPreambleType = PREAMBLE_LONG;
2152 }
Andres More4e9b5e22013-02-12 20:36:30 -05002153 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002154 }
2155 }
2156
Andres Moree269fc22013-02-12 20:36:29 -05002157 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2159 dev_kfree_skb_irq(skb);
2160 return 0;
2161 }
2162 }
2163
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002164 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002165
2166 if (pContext == NULL) {
2167 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2168 dev_kfree_skb_irq(skb);
2169 return STATUS_RESOURCES;
2170 }
2171
Andres Moreceb8c5d2013-03-18 20:33:49 -05002172 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002173
2174//mike add:station mode check eapol-key challenge--->
2175{
Andres Moreb902fbf2013-02-25 20:32:51 -05002176 u8 Protocol_Version; //802.1x Authentication
2177 u8 Packet_Type; //802.1x Authentication
2178 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002179 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002180
Charles Clément21ec51f2010-05-18 10:08:14 -07002181 Protocol_Version = skb->data[ETH_HLEN];
2182 Packet_Type = skb->data[ETH_HLEN+1];
2183 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2184 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 -05002185 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002186 /* 802.1x OR eapol-key challenge frame transfer */
2187 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2188 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002189 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002190 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2191 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2192 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002193 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002194 PRINT_K("WPA ");
2195 }
2196 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002197 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002198 PRINT_K("WPA2(re-keying) ");
2199 }
2200 PRINT_K("Authentication completed!!\n");
2201 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002202 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002203 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002204 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002205 PRINT_K("WPA2 Authentication completed!!\n");
2206 }
2207 }
2208 }
2209}
2210//mike add:station mode check eapol-key challenge<---
2211
Andres More4e9b5e22013-02-12 20:36:30 -05002212 if (pDevice->bEncryptionEnable == true) {
2213 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002214 // get Transmit key
2215 do {
2216 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2217 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2218 pbyBSSID = pDevice->abyBSSID;
2219 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002220 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002221 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002222 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2223 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002224 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2225 break;
2226 }
2227 } else {
2228 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2229 break;
2230 }
2231 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002232 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2233 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002234 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2235 for (ii = 0; ii< 6; ii++)
2236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2238
2239 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002240 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002241 break;
2242 }
2243 // get group key
2244 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002245 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002246 pTransmitKey = NULL;
2247 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2248 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2249 }
2250 else
2251 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2252 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002253 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002254 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2255 }
Andres Moree269fc22013-02-12 20:36:29 -05002256 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002257 }
2258
2259 if (pDevice->bEnableHostWEP) {
2260 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002261 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002262 pTransmitKey = &STempKey;
2263 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2264 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2265 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2266 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2267 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2268 memcpy(pTransmitKey->abyKey,
2269 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2270 pTransmitKey->uKeyLength
2271 );
2272 }
2273 }
2274
Andres Moreb902fbf2013-02-25 20:32:51 -05002275 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002276
2277 if (pDevice->bFixRate) {
2278 if (pDevice->byBBType == BB_TYPE_11B) {
2279 if (pDevice->uConnectionRate >= RATE_11M) {
2280 pDevice->wCurrentRate = RATE_11M;
2281 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002282 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002283 }
2284 } else {
2285 if ((pDevice->byBBType == BB_TYPE_11A) &&
2286 (pDevice->uConnectionRate <= RATE_6M)) {
2287 pDevice->wCurrentRate = RATE_6M;
2288 } else {
2289 if (pDevice->uConnectionRate >= RATE_54M)
2290 pDevice->wCurrentRate = RATE_54M;
2291 else
Andres More3eaca0d2013-02-25 20:32:52 -05002292 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002293 }
2294 }
2295 }
2296 else {
2297 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2298 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002299 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002300 // Multicast use highest data rate
2301 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2302 // preamble type
2303 pDevice->byPreambleType = pDevice->byShortPreamble;
2304 }
2305 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002306 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002307 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2308 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2309 pDevice->byPreambleType = pDevice->byShortPreamble;
2310
2311 }
2312 else {
2313 pDevice->byPreambleType = PREAMBLE_LONG;
2314 }
2315 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2316 }
2317 else {
2318 if (pDevice->byBBType != BB_TYPE_11A)
2319 pDevice->wCurrentRate = RATE_2M;
2320 else
2321 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2322 // abyCurrExtSuppRates[]
2323 pDevice->byPreambleType = PREAMBLE_SHORT;
2324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2325 }
2326 }
2327 }
2328 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2329 // Infra STA rate decided from AP Node, index = 0
2330 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2331 }
2332 }
2333
Andres Moreceb8c5d2013-03-18 20:33:49 -05002334 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002335 if (pDevice->byBBType != BB_TYPE_11A) {
2336 pDevice->wCurrentRate = RATE_1M;
2337 pDevice->byACKRate = RATE_1M;
2338 pDevice->byTopCCKBasicRate = RATE_1M;
2339 pDevice->byTopOFDMBasicRate = RATE_6M;
2340 } else {
2341 pDevice->wCurrentRate = RATE_6M;
2342 pDevice->byACKRate = RATE_6M;
2343 pDevice->byTopCCKBasicRate = RATE_1M;
2344 pDevice->byTopOFDMBasicRate = RATE_6M;
2345 }
2346 }
Forest Bond92b96792009-06-13 07:38:31 -04002347
Andres More0cbd8d92010-05-06 20:34:29 -03002348 DBG_PRT(MSG_LEVEL_DEBUG,
2349 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2350 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002351
2352 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002353 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002354 }
2355
2356 if (pDevice->wCurrentRate <= RATE_11M) {
2357 byPktType = PK_TYPE_11B;
2358 }
2359
Andres More4e9b5e22013-02-12 20:36:30 -05002360 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002361 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2362 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002363 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002364 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002365 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2366 if (pTransmitKey == NULL) {
2367 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2368 }
2369 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002370 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2372 }
2373 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002374 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2375 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002376 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002377 }
2378 }
2379 }
2380
Forest Bond92b96792009-06-13 07:38:31 -04002381 if (pDevice->bEnableHostWEP) {
2382 if ((uNodeIndex != 0) &&
2383 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2385 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002386 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002387 }
2388 }
2389 }
2390 else {
2391
Forest Bond92b96792009-06-13 07:38:31 -04002392 if (pTransmitKey == NULL) {
2393 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002394 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002395 dev_kfree_skb_irq(skb);
2396 pStats->tx_dropped++;
2397 return STATUS_FAILURE;
2398 }
Forest Bond92b96792009-06-13 07:38:31 -04002399 }
2400 }
2401
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002402 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2403
Forest Bond92b96792009-06-13 07:38:31 -04002404 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002405 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002406 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002407 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002408 pDevice->wCurrentRate,
2409 &uHeaderLen, &BytesToWrite
2410 );
2411
Andres Moree269fc22013-02-12 20:36:29 -05002412 if (fConvertedPacket == false) {
2413 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002414 dev_kfree_skb_irq(skb);
2415 return STATUS_FAILURE;
2416 }
2417
Andres More4e9b5e22013-02-12 20:36:30 -05002418 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002419 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002420 bScheduleCommand((void *) pDevice,
2421 WLAN_CMD_MAC_DISPOWERSAVING,
2422 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002423 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002424 }
2425 }
2426
Andres Moreb902fbf2013-02-25 20:32:51 -05002427 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002428 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002429
2430 pContext->pPacket = skb;
2431 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002432 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002433
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002434 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2435 &pContext->sEthHeader.h_dest[0],
2436 (u16)(BytesToWrite-uHeaderLen),
2437 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002438
2439 status = PIPEnsSendBulkOut(pDevice,pContext);
2440
Andres More4e9b5e22013-02-12 20:36:30 -05002441 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002442 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002443
Andres Moreb902fbf2013-02-25 20:32:51 -05002444 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002445 }
2446
2447 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002448 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002449 dev_kfree_skb_irq(skb);
2450 return STATUS_FAILURE;
2451 }
2452 else
2453 return 0;
2454
2455}
2456
Forest Bond92b96792009-06-13 07:38:31 -04002457/*
2458 * Description:
2459 * Relay packet send (AC1DMA) from rx dpc.
2460 *
2461 * Parameters:
2462 * In:
2463 * pDevice - Pointer to the adapter
2464 * pPacket - Pointer to rx packet
2465 * cbPacketSize - rx ethernet frame size
2466 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002467 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002468 *
Andres More4e9b5e22013-02-12 20:36:30 -05002469 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002470 */
2471
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002472int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2473 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002474{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002475 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002476 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002477 u32 BytesToWrite = 0, uHeaderLen = 0;
2478 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002479 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002480 SKeyItem STempKey;
2481 PSKeyItem pTransmitKey = NULL;
2482 u8 *pbyBSSID;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01002483 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002484 u8 byPktTyp;
2485 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002486 u32 status;
2487 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002488
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00002489 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04002490
2491 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002492 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002493 }
2494
Andres Moreceb8c5d2013-03-18 20:33:49 -05002495 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002496
Andres More4e9b5e22013-02-12 20:36:30 -05002497 if (pDevice->bEncryptionEnable == true) {
2498 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002499 // get group key
2500 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002501 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002502 pTransmitKey = NULL;
2503 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2504 } else {
2505 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2506 }
2507 }
2508
2509 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002510 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002511 pTransmitKey = &STempKey;
2512 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2513 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2514 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2515 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2516 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2517 memcpy(pTransmitKey->abyKey,
2518 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2519 pTransmitKey->uKeyLength
2520 );
2521 }
2522 }
2523
2524 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002525 pContext->bBoolInUse = false;
2526 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002527 }
2528
Andres Moreb902fbf2013-02-25 20:32:51 -05002529 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002530
2531 if (pDevice->bFixRate) {
2532 if (pDevice->byBBType == BB_TYPE_11B) {
2533 if (pDevice->uConnectionRate >= RATE_11M) {
2534 pDevice->wCurrentRate = RATE_11M;
2535 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002536 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002537 }
2538 } else {
2539 if ((pDevice->byBBType == BB_TYPE_11A) &&
2540 (pDevice->uConnectionRate <= RATE_6M)) {
2541 pDevice->wCurrentRate = RATE_6M;
2542 } else {
2543 if (pDevice->uConnectionRate >= RATE_54M)
2544 pDevice->wCurrentRate = RATE_54M;
2545 else
Andres More3eaca0d2013-02-25 20:32:52 -05002546 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002547 }
2548 }
2549 }
2550 else {
2551 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2552 }
2553
Forest Bond92b96792009-06-13 07:38:31 -04002554 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002555 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002556 }
2557
2558 if (pDevice->wCurrentRate <= RATE_11M)
2559 byPktType = PK_TYPE_11B;
2560
Andres Moreabad19d2010-07-12 16:28:32 -03002561 BytesToWrite = uDataLen + ETH_FCS_LEN;
2562
Forest Bond92b96792009-06-13 07:38:31 -04002563 // Convert the packet to an usb frame and copy into our buffer
2564 // and send the irp.
2565
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002566 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2567
Forest Bond92b96792009-06-13 07:38:31 -04002568 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002569 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002570 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2571 pbySkbData, pTransmitKey, uNodeIndex,
2572 pDevice->wCurrentRate,
2573 &uHeaderLen, &BytesToWrite
2574 );
2575
Andres Moree269fc22013-02-12 20:36:29 -05002576 if (fConvertedPacket == false) {
2577 pContext->bBoolInUse = false;
2578 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002579 }
2580
Andres Moreb902fbf2013-02-25 20:32:51 -05002581 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002582 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002583
2584 pContext->pPacket = NULL;
2585 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002586 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002587
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002588 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2589 &pContext->sEthHeader.h_dest[0],
2590 (u16)(BytesToWrite - uHeaderLen),
2591 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002592
2593 status = PIPEnsSendBulkOut(pDevice,pContext);
2594
Andres More4e9b5e22013-02-12 20:36:30 -05002595 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002596}
2597