Commit | Line | Data |
---|---|---|
92b96797 FB |
1 | /* |
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: | |
f77f13e2 | 28 | * s_vGenerateTxParameter - Generate tx dma required parameter. |
92b96797 FB |
29 | * 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 | |
f77f13e2 | 34 | * s_uGetRTSCTSDuration- get rtx/cts required duration |
92b96797 FB |
35 | * s_uGetRTSCTSRsvTime- get rts/cts reserved time |
36 | * s_uGetTxRsvTime- get frame reserved time | |
37 | * s_vFillCTSHead- fulfill CTS ctl header | |
f77f13e2 | 38 | * s_vFillFragParameter- Set fragment ctl parameter. |
92b96797 FB |
39 | * 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 | ||
92b96797 | 49 | #include "device.h" |
92b96797 | 50 | #include "rxtx.h" |
92b96797 | 51 | #include "tether.h" |
92b96797 | 52 | #include "card.h" |
92b96797 | 53 | #include "bssdb.h" |
92b96797 | 54 | #include "mac.h" |
92b96797 | 55 | #include "michael.h" |
92b96797 | 56 | #include "tkip.h" |
92b96797 | 57 | #include "tcrc.h" |
92b96797 | 58 | #include "wctl.h" |
92b96797 | 59 | #include "hostap.h" |
92b96797 | 60 | #include "rf.h" |
92b96797 | 61 | #include "datarate.h" |
92b96797 | 62 | #include "usbpipe.h" |
92b96797 | 63 | #include "iocmd.h" |
9d26d60f | 64 | |
4a499de2 | 65 | static int msglevel = MSG_LEVEL_INFO; |
92b96797 | 66 | |
3b138851 | 67 | static const u16 wTimeStampOff[2][MAX_RATE] = { |
92b96797 FB |
68 | {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 | ||
3b138851 | 72 | static const u16 wFB_Opt0[2][5] = { |
92b96797 FB |
73 | {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 | }; | |
3b138851 | 76 | static const u16 wFB_Opt1[2][5] = { |
92b96797 FB |
77 | {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 | ||
92b96797 FB |
81 | #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 | ||
d56131de MP |
96 | static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum, |
97 | u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl); | |
98 | ||
b89f3b94 | 99 | static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *); |
d56131de | 100 | |
0a0f4b69 | 101 | static u16 s_vGenerateTxParameter(struct vnt_private *pDevice, |
8e344c88 | 102 | u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer, |
fa57560c MP |
103 | struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize, |
104 | int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts); | |
d56131de | 105 | |
d56131de | 106 | static void s_vGenerateMACHeader(struct vnt_private *pDevice, |
ceb8c5da | 107 | u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader, |
d56131de MP |
108 | int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx); |
109 | ||
3ba0938c MP |
110 | static void s_vFillTxKey(struct vnt_private *pDevice, |
111 | struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead, | |
112 | PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen, | |
ec37d8b6 | 113 | struct vnt_mic_hdr *mic_hdr); |
d56131de MP |
114 | |
115 | static void s_vSWencryption(struct vnt_private *pDevice, | |
116 | PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize); | |
117 | ||
118 | static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType, | |
119 | u32 cbFrameLength, u16 wRate, int bNeedAck); | |
120 | ||
cfabe4b4 | 121 | static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType, |
d56131de MP |
122 | u8 byPktType, u32 cbFrameLength, u16 wCurrentRate); |
123 | ||
0a0f4b69 | 124 | static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx, |
5fb8e412 MP |
125 | u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength, |
126 | int bNeedAck, u16 wCurrentRate, u8 byFBOption); | |
d56131de | 127 | |
0a0f4b69 | 128 | static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType, |
5fb8e412 | 129 | union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck, |
ceb8c5da | 130 | struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption); |
d56131de | 131 | |
6b5ad9d2 | 132 | static u16 s_uGetDataDuration(struct vnt_private *pDevice, |
3ed210ef | 133 | u8 byPktType, int bNeedAck); |
d56131de | 134 | |
e34f9dbe | 135 | static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, |
d56131de MP |
136 | u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate, |
137 | int bNeedAck, u8 byFBOption); | |
92b96797 | 138 | |
aceaf018 | 139 | static struct vnt_usb_send_context |
b89f3b94 | 140 | *s_vGetFreeContext(struct vnt_private *priv) |
92b96797 | 141 | { |
b89f3b94 | 142 | struct vnt_usb_send_context *context = NULL; |
d56131de | 143 | int ii; |
92b96797 | 144 | |
b89f3b94 MP |
145 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n"); |
146 | ||
147 | 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"); | |
aceaf018 | 162 | |
5c851383 | 163 | return NULL; |
92b96797 FB |
164 | } |
165 | ||
d56131de MP |
166 | static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum, |
167 | u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl) | |
92b96797 | 168 | { |
d56131de | 169 | PSStatCounter pStatistic = &pDevice->scStatistic; |
92b96797 | 170 | |
4b50fb40 | 171 | if (is_broadcast_ether_addr(pbyDestAddr)) |
92b96797 | 172 | pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD; |
4b50fb40 | 173 | else if (is_multicast_ether_addr(pbyDestAddr)) |
92b96797 FB |
174 | pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI; |
175 | else | |
176 | pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI; | |
177 | ||
178 | pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength; | |
179 | pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl; | |
9a0e756c AM |
180 | memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr, |
181 | pbyDestAddr, | |
182 | ETH_ALEN); | |
92b96797 FB |
183 | } |
184 | ||
3ba0938c MP |
185 | static void s_vFillTxKey(struct vnt_private *pDevice, |
186 | struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead, | |
187 | PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen, | |
188 | struct vnt_mic_hdr *mic_hdr) | |
92b96797 | 189 | { |
3ba0938c | 190 | u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0]; |
d56131de MP |
191 | u32 *pdwIV = (u32 *)pbyIVHead; |
192 | u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4); | |
1cac4a4b | 193 | struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf; |
d56131de | 194 | u32 dwRevIVCounter; |
92b96797 | 195 | |
95bfb1ae MP |
196 | /* Fill TXKEY */ |
197 | if (pTransmitKey == NULL) | |
ec37d8b6 MP |
198 | return; |
199 | ||
95bfb1ae MP |
200 | dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter); |
201 | *pdwIV = pDevice->dwIVCounter; | |
202 | pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf; | |
203 | ||
f6804f33 MP |
204 | switch (pTransmitKey->byCipherSuite) { |
205 | case KEY_CTL_WEP: | |
95bfb1ae MP |
206 | if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) { |
207 | memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3); | |
208 | memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey, | |
209 | pTransmitKey->uKeyLength); | |
210 | } else { | |
211 | memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3); | |
212 | memcpy(pbyBuf + 3, pTransmitKey->abyKey, | |
213 | pTransmitKey->uKeyLength); | |
214 | if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) { | |
215 | memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3); | |
216 | memcpy(pbyBuf+11, pTransmitKey->abyKey, | |
217 | pTransmitKey->uKeyLength); | |
218 | } | |
219 | ||
220 | memcpy(pDevice->abyPRNG, pbyBuf, 16); | |
221 | } | |
222 | /* Append IV after Mac Header */ | |
223 | *pdwIV &= WEP_IV_MASK; | |
224 | *pdwIV |= (u32)pDevice->byKeyIndex << 30; | |
225 | *pdwIV = cpu_to_le32(*pdwIV); | |
226 | ||
227 | pDevice->dwIVCounter++; | |
228 | if (pDevice->dwIVCounter > WEP_IV_MASK) | |
229 | pDevice->dwIVCounter = 0; | |
f6804f33 MP |
230 | |
231 | break; | |
232 | case KEY_CTL_TKIP: | |
95bfb1ae MP |
233 | pTransmitKey->wTSC15_0++; |
234 | if (pTransmitKey->wTSC15_0 == 0) | |
235 | pTransmitKey->dwTSC47_16++; | |
236 | ||
237 | TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr, | |
238 | pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, | |
239 | pDevice->abyPRNG); | |
240 | memcpy(pbyBuf, pDevice->abyPRNG, 16); | |
241 | ||
242 | /* Make IV */ | |
243 | memcpy(pdwIV, pDevice->abyPRNG, 3); | |
244 | ||
245 | *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & | |
246 | 0xc0) | 0x20); | |
247 | /* Append IV&ExtIV after Mac Header */ | |
248 | *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16); | |
249 | ||
250 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO | |
251 | "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV); | |
252 | ||
f6804f33 MP |
253 | break; |
254 | case KEY_CTL_CCMP: | |
95bfb1ae MP |
255 | pTransmitKey->wTSC15_0++; |
256 | if (pTransmitKey->wTSC15_0 == 0) | |
257 | pTransmitKey->dwTSC47_16++; | |
258 | ||
259 | memcpy(pbyBuf, pTransmitKey->abyKey, 16); | |
260 | ||
261 | /* Make IV */ | |
262 | *pdwIV = 0; | |
263 | *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & | |
264 | 0xc0) | 0x20); | |
265 | ||
266 | *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0)); | |
267 | ||
268 | /* Append IV&ExtIV after Mac Header */ | |
269 | *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16); | |
270 | ||
271 | if (!mic_hdr) | |
272 | return; | |
273 | ||
274 | /* MICHDR0 */ | |
275 | mic_hdr->id = 0x59; | |
276 | mic_hdr->payload_len = cpu_to_be16(wPayloadLen); | |
277 | memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN); | |
278 | ||
279 | mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16); | |
280 | mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0); | |
281 | ||
282 | /* MICHDR1 */ | |
078d0cfd | 283 | if (ieee80211_has_a4(pMACHeader->frame_control)) |
95bfb1ae MP |
284 | mic_hdr->hlen = cpu_to_be16(28); |
285 | else | |
286 | mic_hdr->hlen = cpu_to_be16(22); | |
287 | ||
288 | memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN); | |
289 | memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN); | |
290 | ||
291 | /* MICHDR2 */ | |
292 | memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN); | |
293 | mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control | |
ec37d8b6 | 294 | & 0xc78f); |
95bfb1ae | 295 | mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf); |
ec37d8b6 | 296 | |
078d0cfd | 297 | if (ieee80211_has_a4(pMACHeader->frame_control)) |
95bfb1ae MP |
298 | memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN); |
299 | } | |
92b96797 FB |
300 | } |
301 | ||
d56131de MP |
302 | static void s_vSWencryption(struct vnt_private *pDevice, |
303 | PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize) | |
92b96797 | 304 | { |
d56131de MP |
305 | u32 cbICVlen = 4; |
306 | u32 dwICV = 0xffffffff; | |
307 | u32 *pdwICV; | |
92b96797 FB |
308 | |
309 | if (pTransmitKey == NULL) | |
310 | return; | |
311 | ||
312 | if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { | |
313 | //======================================================================= | |
314 | // Append ICV after payload | |
315 | dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload) | |
52a7e64b | 316 | pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize); |
92b96797 FB |
317 | // finally, we must invert dwCRC to get the correct answer |
318 | *pdwICV = cpu_to_le32(~dwICV); | |
319 | // RC4 encryption | |
320 | rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3); | |
321 | rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen); | |
322 | //======================================================================= | |
323 | } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) { | |
324 | //======================================================================= | |
325 | //Append ICV after payload | |
326 | dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload) | |
52a7e64b | 327 | pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize); |
92b96797 FB |
328 | // finally, we must invert dwCRC to get the correct answer |
329 | *pdwICV = cpu_to_le32(~dwICV); | |
330 | // RC4 encryption | |
331 | rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN); | |
332 | rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen); | |
333 | //======================================================================= | |
334 | } | |
335 | } | |
336 | ||
f115e76a MP |
337 | static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate) |
338 | { | |
339 | return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2] | |
340 | [rate % MAX_RATE]); | |
341 | } | |
342 | ||
92b96797 FB |
343 | /*byPktType : PK_TYPE_11A 0 |
344 | PK_TYPE_11B 1 | |
345 | PK_TYPE_11GB 2 | |
346 | PK_TYPE_11GA 3 | |
347 | */ | |
d56131de MP |
348 | static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType, |
349 | u32 cbFrameLength, u16 wRate, int bNeedAck) | |
92b96797 | 350 | { |
d56131de | 351 | u32 uDataTime, uAckTime; |
92b96797 FB |
352 | |
353 | uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate); | |
354 | if (byPktType == PK_TYPE_11B) {//llb,CCK mode | |
3eaca0d2 | 355 | uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate); |
92b96797 | 356 | } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode |
3eaca0d2 | 357 | uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate); |
92b96797 FB |
358 | } |
359 | ||
360 | if (bNeedAck) { | |
361 | return (uDataTime + pDevice->uSIFS + uAckTime); | |
362 | } | |
363 | else { | |
364 | return uDataTime; | |
365 | } | |
366 | } | |
367 | ||
9c3806d5 MP |
368 | static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type, |
369 | u32 frame_length, u16 rate, int need_ack) | |
370 | { | |
371 | return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type, | |
372 | frame_length, rate, need_ack)); | |
373 | } | |
374 | ||
92b96797 | 375 | //byFreqType: 0=>5GHZ 1=>2.4GHZ |
cfabe4b4 | 376 | static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, |
d56131de | 377 | u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate) |
92b96797 | 378 | { |
d56131de | 379 | u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime; |
92b96797 FB |
380 | |
381 | uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0; | |
382 | ||
92b96797 FB |
383 | uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate); |
384 | if (byRTSRsvType == 0) { //RTSTxRrvTime_bb | |
385 | uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate); | |
386 | uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); | |
387 | } | |
388 | else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ | |
389 | uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate); | |
390 | uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); | |
391 | uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); | |
392 | } | |
393 | else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa | |
394 | uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate); | |
395 | uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); | |
396 | } | |
397 | else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ | |
398 | uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); | |
399 | uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); | |
400 | uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS; | |
401 | return uRrvTime; | |
402 | } | |
403 | ||
404 | //RTSRrvTime | |
405 | uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS; | |
cfabe4b4 | 406 | return cpu_to_le16((u16)uRrvTime); |
92b96797 FB |
407 | } |
408 | ||
409 | //byFreqType 0: 5GHz, 1:2.4Ghz | |
6b5ad9d2 MP |
410 | static u16 s_uGetDataDuration(struct vnt_private *pDevice, |
411 | u8 byPktType, int bNeedAck) | |
92b96797 | 412 | { |
0005cb00 | 413 | u32 uAckTime = 0; |
92b96797 | 414 | |
b02ccd59 | 415 | if (bNeedAck) { |
6b5ad9d2 | 416 | if (byPktType == PK_TYPE_11B) |
b02ccd59 MP |
417 | uAckTime = BBuGetFrameTime(pDevice->byPreambleType, |
418 | byPktType, 14, pDevice->byTopCCKBasicRate); | |
419 | else | |
420 | uAckTime = BBuGetFrameTime(pDevice->byPreambleType, | |
421 | byPktType, 14, pDevice->byTopOFDMBasicRate); | |
d5005955 | 422 | return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime)); |
b02ccd59 | 423 | } |
92b96797 | 424 | |
92b96797 FB |
425 | return 0; |
426 | } | |
427 | ||
92b96797 | 428 | //byFreqType: 0=>5GHZ 1=>2.4GHZ |
e34f9dbe | 429 | static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType, |
d56131de MP |
430 | u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck, |
431 | u8 byFBOption) | |
92b96797 | 432 | { |
d56131de | 433 | u32 uCTSTime = 0, uDurTime = 0; |
92b96797 | 434 | |
ecd80240 MP |
435 | switch (byDurType) { |
436 | case RTSDUR_BB: | |
437 | case RTSDUR_BA: | |
438 | case RTSDUR_BA_F0: | |
439 | case RTSDUR_BA_F1: | |
440 | uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, | |
441 | 14, pDevice->byTopCCKBasicRate); | |
442 | uDurTime = uCTSTime + 2 * pDevice->uSIFS + | |
443 | s_uGetTxRsvTime(pDevice, byPktType, | |
444 | cbFrameLength, wRate, bNeedAck); | |
445 | break; | |
92b96797 | 446 | |
ecd80240 MP |
447 | case RTSDUR_AA: |
448 | case RTSDUR_AA_F0: | |
449 | case RTSDUR_AA_F1: | |
450 | uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, | |
451 | 14, pDevice->byTopOFDMBasicRate); | |
452 | uDurTime = uCTSTime + 2 * pDevice->uSIFS + | |
453 | s_uGetTxRsvTime(pDevice, byPktType, | |
454 | cbFrameLength, wRate, bNeedAck); | |
455 | break; | |
92b96797 | 456 | |
ecd80240 MP |
457 | case CTSDUR_BA: |
458 | case CTSDUR_BA_F0: | |
459 | case CTSDUR_BA_F1: | |
460 | uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, | |
f84cdf65 | 461 | byPktType, cbFrameLength, wRate, bNeedAck); |
ecd80240 | 462 | break; |
92b96797 | 463 | |
ecd80240 MP |
464 | default: |
465 | break; | |
466 | } | |
92b96797 | 467 | |
e34f9dbe | 468 | return cpu_to_le16((u16)uDurTime); |
92b96797 FB |
469 | } |
470 | ||
78363fd1 MP |
471 | static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate, |
472 | struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack) | |
473 | { | |
474 | /* Get SignalField,ServiceField,Length */ | |
475 | BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a); | |
476 | BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate, | |
477 | PK_TYPE_11B, &buf->b); | |
478 | ||
479 | /* Get Duration and TimeStamp */ | |
480 | buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack); | |
481 | buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack); | |
482 | ||
483 | buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate); | |
484 | buf->wTimeStampOff_b = vnt_time_stamp_off(priv, | |
485 | priv->byTopCCKBasicRate); | |
486 | ||
487 | return buf->wDuration_a; | |
488 | } | |
489 | ||
5b852f53 MP |
490 | static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type, |
491 | u16 rate, struct vnt_tx_datahead_g_fb *buf, | |
492 | u32 frame_len, int need_ack) | |
493 | { | |
494 | /* Get SignalField,ServiceField,Length */ | |
495 | BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a); | |
496 | ||
497 | BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate, | |
498 | PK_TYPE_11B, &buf->b); | |
499 | ||
500 | /* Get Duration and TimeStamp */ | |
501 | buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack); | |
502 | buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack); | |
503 | ||
504 | buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack); | |
505 | buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack); | |
506 | ||
507 | buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate); | |
508 | buf->wTimeStampOff_b = vnt_time_stamp_off(priv, | |
509 | priv->byTopCCKBasicRate); | |
510 | ||
511 | return buf->wDuration_a; | |
512 | } | |
513 | ||
bd3f51f1 MP |
514 | static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type, |
515 | u16 rate, struct vnt_tx_datahead_a_fb *buf, | |
516 | u32 frame_len, int need_ack) | |
517 | { | |
518 | /* Get SignalField,ServiceField,Length */ | |
519 | BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a); | |
520 | /* Get Duration and TimeStampOff */ | |
521 | buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack); | |
522 | ||
523 | buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack); | |
524 | buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack); | |
525 | ||
526 | buf->wTimeStampOff = vnt_time_stamp_off(priv, rate); | |
527 | ||
528 | return buf->wDuration; | |
529 | } | |
530 | ||
5634a5ab MP |
531 | static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type, |
532 | u16 rate, struct vnt_tx_datahead_ab *buf, | |
533 | u32 frame_len, int need_ack) | |
534 | { | |
535 | /* Get SignalField,ServiceField,Length */ | |
536 | BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab); | |
537 | /* Get Duration and TimeStampOff */ | |
538 | buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack); | |
539 | ||
540 | buf->wTimeStampOff = vnt_time_stamp_off(priv, rate); | |
541 | ||
542 | return buf->wDuration; | |
543 | } | |
544 | ||
5e67ee49 MP |
545 | static int vnt_fill_ieee80211_rts(struct vnt_private *priv, |
546 | struct ieee80211_rts *rts, struct ethhdr *eth_hdr, | |
547 | u16 duration) | |
548 | { | |
549 | rts->duration = duration; | |
550 | rts->frame_control = TYPE_CTL_RTS; | |
551 | ||
552 | if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP) | |
553 | memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN); | |
554 | else | |
555 | memcpy(rts->ra, priv->abyBSSID, ETH_ALEN); | |
556 | ||
557 | if (priv->eOPMode == OP_MODE_AP) | |
558 | memcpy(rts->ta, priv->abyBSSID, ETH_ALEN); | |
559 | else | |
560 | memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN); | |
561 | ||
562 | return 0; | |
563 | } | |
564 | ||
0a0f4b69 | 565 | static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv, |
5e67ee49 MP |
566 | struct vnt_rts_g *buf, struct ethhdr *eth_hdr, |
567 | u8 pkt_type, u32 frame_len, int need_ack, | |
568 | u16 current_rate, u8 fb_option) | |
569 | { | |
570 | u16 rts_frame_len = 20; | |
571 | ||
572 | BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate, | |
573 | PK_TYPE_11B, &buf->b); | |
574 | BBvCalculateParameter(priv, rts_frame_len, | |
575 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); | |
576 | ||
577 | buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len, | |
578 | PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option); | |
579 | buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, | |
580 | pkt_type, current_rate, need_ack, fb_option); | |
581 | buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len, | |
582 | pkt_type, current_rate, need_ack, fb_option); | |
583 | ||
584 | vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa); | |
585 | ||
78363fd1 MP |
586 | return vnt_rxtx_datahead_g(priv, pkt_type, current_rate, |
587 | &buf->data_head, frame_len, need_ack); | |
5e67ee49 MP |
588 | } |
589 | ||
0a0f4b69 | 590 | static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv, |
ec91713a MP |
591 | struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr, |
592 | u8 pkt_type, u32 frame_len, int need_ack, | |
593 | u16 current_rate, u8 fb_option) | |
594 | { | |
595 | u16 rts_frame_len = 20; | |
596 | ||
597 | BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate, | |
598 | PK_TYPE_11B, &buf->b); | |
599 | BBvCalculateParameter(priv, rts_frame_len, | |
600 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); | |
601 | ||
602 | ||
603 | buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len, | |
604 | PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option); | |
605 | buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, | |
606 | pkt_type, current_rate, need_ack, fb_option); | |
607 | buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len, | |
608 | pkt_type, current_rate, need_ack, fb_option); | |
609 | ||
610 | ||
611 | buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0, | |
f84cdf65 | 612 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
ec91713a | 613 | buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0, |
f84cdf65 | 614 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
ec91713a | 615 | buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1, |
f84cdf65 | 616 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
ec91713a | 617 | buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1, |
f84cdf65 | 618 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
ec91713a MP |
619 | |
620 | vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa); | |
621 | ||
5b852f53 MP |
622 | return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate, |
623 | &buf->data_head, frame_len, need_ack); | |
ec91713a MP |
624 | } |
625 | ||
0a0f4b69 | 626 | static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv, |
1712633d MP |
627 | struct vnt_rts_ab *buf, struct ethhdr *eth_hdr, |
628 | u8 pkt_type, u32 frame_len, int need_ack, | |
629 | u16 current_rate, u8 fb_option) | |
630 | { | |
631 | u16 rts_frame_len = 20; | |
632 | ||
633 | BBvCalculateParameter(priv, rts_frame_len, | |
634 | priv->byTopOFDMBasicRate, pkt_type, &buf->ab); | |
635 | ||
636 | buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, | |
637 | pkt_type, current_rate, need_ack, fb_option); | |
638 | ||
639 | vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration); | |
640 | ||
5634a5ab MP |
641 | return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate, |
642 | &buf->data_head, frame_len, need_ack); | |
1712633d MP |
643 | } |
644 | ||
0a0f4b69 | 645 | static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv, |
9d2578c1 MP |
646 | struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr, |
647 | u8 pkt_type, u32 frame_len, int need_ack, | |
648 | u16 current_rate, u8 fb_option) | |
649 | { | |
650 | u16 rts_frame_len = 20; | |
651 | ||
652 | BBvCalculateParameter(priv, rts_frame_len, | |
653 | priv->byTopOFDMBasicRate, pkt_type, &buf->a); | |
654 | ||
655 | buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len, | |
656 | pkt_type, current_rate, need_ack, fb_option); | |
657 | ||
658 | buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0, | |
f84cdf65 | 659 | frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option); |
9d2578c1 MP |
660 | |
661 | buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1, | |
f84cdf65 | 662 | frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option); |
9d2578c1 MP |
663 | |
664 | vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration); | |
665 | ||
bd3f51f1 MP |
666 | return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate, |
667 | &buf->data_head, frame_len, need_ack); | |
9d2578c1 MP |
668 | } |
669 | ||
0a0f4b69 | 670 | static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType, |
5fb8e412 | 671 | union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck, |
ceb8c5da | 672 | struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption) |
92b96797 | 673 | { |
92b96797 | 674 | |
13fe62ae | 675 | if (!head) |
0a0f4b69 | 676 | return 0; |
92b96797 | 677 | |
9d5829bf MP |
678 | /* Note: So far RTSHead doesn't appear in ATIM |
679 | * & Beacom DMA, so we don't need to take them | |
680 | * into account. | |
681 | * Otherwise, we need to modified codes for them. | |
682 | */ | |
0bddd303 MP |
683 | switch (byPktType) { |
684 | case PK_TYPE_11GB: | |
685 | case PK_TYPE_11GA: | |
9d5829bf | 686 | if (byFBOption == AUTO_FB_NONE) |
78363fd1 | 687 | return vnt_rxtx_rts_g_head(pDevice, &head->rts_g, |
5e67ee49 MP |
688 | psEthHeader, byPktType, cbFrameLength, |
689 | bNeedAck, wCurrentRate, byFBOption); | |
9d5829bf | 690 | else |
5b852f53 | 691 | return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb, |
ec91713a MP |
692 | psEthHeader, byPktType, cbFrameLength, |
693 | bNeedAck, wCurrentRate, byFBOption); | |
0bddd303 MP |
694 | break; |
695 | case PK_TYPE_11A: | |
2b83ebd0 | 696 | if (byFBOption) { |
bd3f51f1 | 697 | return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb, |
9d2578c1 MP |
698 | psEthHeader, byPktType, cbFrameLength, |
699 | bNeedAck, wCurrentRate, byFBOption); | |
2b83ebd0 MP |
700 | break; |
701 | } | |
0bddd303 | 702 | case PK_TYPE_11B: |
5634a5ab | 703 | return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab, |
1712633d MP |
704 | psEthHeader, byPktType, cbFrameLength, |
705 | bNeedAck, wCurrentRate, byFBOption); | |
9d5829bf | 706 | } |
0a0f4b69 MP |
707 | |
708 | return 0; | |
92b96797 FB |
709 | } |
710 | ||
0a0f4b69 | 711 | static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx, |
5fb8e412 MP |
712 | u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength, |
713 | int bNeedAck, u16 wCurrentRate, u8 byFBOption) | |
92b96797 | 714 | { |
d56131de | 715 | u32 uCTSFrameLen = 14; |
92b96797 | 716 | |
27df3ebf | 717 | if (!head) |
0a0f4b69 | 718 | return 0; |
92b96797 | 719 | |
c921cc8c MP |
720 | if (byFBOption != AUTO_FB_NONE) { |
721 | /* Auto Fall back */ | |
27df3ebf | 722 | struct vnt_cts_fb *pBuf = &head->cts_g_fb; |
aed387c7 MP |
723 | /* Get SignalField,ServiceField,Length */ |
724 | BBvCalculateParameter(pDevice, uCTSFrameLen, | |
725 | pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b); | |
e34f9dbe MP |
726 | pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, |
727 | cbFrameLength, byPktType, | |
728 | wCurrentRate, bNeedAck, byFBOption); | |
729 | /* Get CTSDuration_ba_f0 */ | |
730 | pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice, | |
f84cdf65 MP |
731 | CTSDUR_BA_F0, cbFrameLength, byPktType, |
732 | pDevice->tx_rate_fb0, bNeedAck, byFBOption); | |
e34f9dbe MP |
733 | /* Get CTSDuration_ba_f1 */ |
734 | pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice, | |
f84cdf65 MP |
735 | CTSDUR_BA_F1, cbFrameLength, byPktType, |
736 | pDevice->tx_rate_fb1, bNeedAck, byFBOption); | |
14840cdd MP |
737 | /* Get CTS Frame body */ |
738 | pBuf->data.duration = pBuf->wDuration_ba; | |
739 | pBuf->data.frame_control = TYPE_CTL_CTS; | |
740 | memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN); | |
5b852f53 MP |
741 | |
742 | return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate, | |
743 | &pBuf->data_head, cbFrameLength, bNeedAck); | |
c921cc8c | 744 | } else { |
27df3ebf | 745 | struct vnt_cts *pBuf = &head->cts_g; |
aed387c7 MP |
746 | /* Get SignalField,ServiceField,Length */ |
747 | BBvCalculateParameter(pDevice, uCTSFrameLen, | |
748 | pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b); | |
e34f9dbe MP |
749 | /* Get CTSDuration_ba */ |
750 | pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, | |
751 | CTSDUR_BA, cbFrameLength, byPktType, | |
752 | wCurrentRate, bNeedAck, byFBOption); | |
14840cdd MP |
753 | /*Get CTS Frame body*/ |
754 | pBuf->data.duration = pBuf->wDuration_ba; | |
755 | pBuf->data.frame_control = TYPE_CTL_CTS; | |
756 | memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN); | |
78363fd1 MP |
757 | |
758 | return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate, | |
759 | &pBuf->data_head, cbFrameLength, bNeedAck); | |
92b96797 | 760 | } |
0a0f4b69 MP |
761 | |
762 | return 0; | |
92b96797 FB |
763 | } |
764 | ||
92b96797 FB |
765 | /*+ |
766 | * | |
767 | * Description: | |
768 | * Generate FIFO control for MAC & Baseband controller | |
769 | * | |
770 | * Parameters: | |
771 | * In: | |
772 | * pDevice - Pointer to adpater | |
773 | * pTxDataHead - Transmit Data Buffer | |
774 | * pTxBufHead - pTxBufHead | |
775 | * pvRrvTime - pvRrvTime | |
776 | * pvRTS - RTS Buffer | |
777 | * pCTS - CTS Buffer | |
778 | * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS) | |
779 | * bNeedACK - If need ACK | |
780 | * uDMAIdx - DMA Index | |
781 | * Out: | |
782 | * none | |
783 | * | |
784 | * Return Value: none | |
785 | * | |
786 | -*/ | |
cc856e61 | 787 | |
0a0f4b69 | 788 | static u16 s_vGenerateTxParameter(struct vnt_private *pDevice, |
8e344c88 | 789 | u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer, |
fa57560c MP |
790 | struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize, |
791 | int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts) | |
92b96797 | 792 | { |
8e344c88 | 793 | struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head; |
b9cc2fc0 | 794 | union vnt_tx_data_head *head = NULL; |
d56131de | 795 | u16 wFifoCtl; |
d56131de | 796 | u8 byFBOption = AUTO_FB_NONE; |
92b96797 | 797 | |
92928f13 MP |
798 | pFifoHead->wReserved = wCurrentRate; |
799 | wFifoCtl = pFifoHead->wFIFOCtl; | |
92b96797 | 800 | |
92928f13 MP |
801 | if (wFifoCtl & FIFOCTL_AUTO_FB_0) |
802 | byFBOption = AUTO_FB_0; | |
803 | else if (wFifoCtl & FIFOCTL_AUTO_FB_1) | |
804 | byFBOption = AUTO_FB_1; | |
92b96797 | 805 | |
9e38a5c1 | 806 | if (!pFifoHead) |
0a0f4b69 | 807 | return 0; |
2dc22d5a | 808 | |
92928f13 MP |
809 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) { |
810 | if (need_rts) { | |
811 | struct vnt_rrv_time_rts *pBuf = | |
812 | &tx_buffer->tx_head.tx_rts.rts; | |
9e38a5c1 | 813 | |
92928f13 MP |
814 | pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2, |
815 | byPktType, cbFrameSize, wCurrentRate); | |
816 | pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1, | |
817 | byPktType, cbFrameSize, wCurrentRate); | |
818 | pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0, | |
cfabe4b4 | 819 | byPktType, cbFrameSize, wCurrentRate); |
b9cc2fc0 | 820 | |
92928f13 MP |
821 | pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, |
822 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); | |
823 | pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice, | |
824 | PK_TYPE_11B, cbFrameSize, | |
825 | pDevice->byTopCCKBasicRate, bNeedACK); | |
826 | ||
827 | if (need_mic) { | |
828 | *mic_hdr = &tx_buffer-> | |
829 | tx_head.tx_rts.tx.mic.hdr; | |
830 | head = &tx_buffer->tx_head.tx_rts.tx.mic.head; | |
831 | } else { | |
832 | head = &tx_buffer->tx_head.tx_rts.tx.head; | |
833 | } | |
f0e0d505 | 834 | |
92928f13 MP |
835 | /* Fill RTS */ |
836 | return s_vFillRTSHead(pDevice, byPktType, head, | |
837 | cbFrameSize, bNeedACK, psEthHeader, | |
838 | wCurrentRate, byFBOption); | |
f0e0d505 | 839 | |
92928f13 MP |
840 | } else { |
841 | struct vnt_rrv_time_cts *pBuf = &tx_buffer-> | |
842 | tx_head.tx_cts.cts; | |
843 | ||
844 | pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, | |
845 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); | |
846 | pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice, | |
847 | PK_TYPE_11B, cbFrameSize, | |
848 | pDevice->byTopCCKBasicRate, bNeedACK); | |
849 | ||
850 | pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3, | |
851 | byPktType, cbFrameSize, wCurrentRate); | |
852 | ||
853 | if (need_mic) { | |
854 | *mic_hdr = &tx_buffer-> | |
855 | tx_head.tx_cts.tx.mic.hdr; | |
856 | head = &tx_buffer->tx_head.tx_cts.tx.mic.head; | |
857 | } else { | |
858 | head = &tx_buffer->tx_head.tx_cts.tx.head; | |
859 | } | |
860 | ||
861 | /* Fill CTS */ | |
862 | return s_vFillCTSHead(pDevice, uDMAIdx, byPktType, | |
863 | head, cbFrameSize, bNeedACK, wCurrentRate, | |
864 | byFBOption); | |
865 | } | |
866 | } else if (byPktType == PK_TYPE_11A) { | |
b9cc2fc0 | 867 | if (need_mic) { |
92928f13 MP |
868 | *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr; |
869 | head = &tx_buffer->tx_head.tx_ab.tx.mic.head; | |
b9cc2fc0 | 870 | } else { |
92928f13 | 871 | head = &tx_buffer->tx_head.tx_ab.tx.head; |
b9cc2fc0 | 872 | } |
f0e0d505 | 873 | |
92928f13 MP |
874 | if (need_rts) { |
875 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> | |
876 | tx_head.tx_ab.ab; | |
9e38a5c1 | 877 | |
92928f13 | 878 | pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2, |
cfabe4b4 | 879 | byPktType, cbFrameSize, wCurrentRate); |
b9cc2fc0 | 880 | |
92928f13 MP |
881 | pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, |
882 | byPktType, cbFrameSize, wCurrentRate, bNeedACK); | |
9e38a5c1 | 883 | |
92928f13 MP |
884 | /* Fill RTS */ |
885 | return s_vFillRTSHead(pDevice, byPktType, head, | |
886 | cbFrameSize, bNeedACK, psEthHeader, | |
887 | wCurrentRate, byFBOption); | |
888 | } else { | |
889 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> | |
890 | tx_head.tx_ab.ab; | |
a90186e4 | 891 | |
92928f13 MP |
892 | pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, |
893 | PK_TYPE_11A, cbFrameSize, | |
894 | wCurrentRate, bNeedACK); | |
c12dca09 | 895 | |
92928f13 MP |
896 | return vnt_rxtx_datahead_a_fb(pDevice, byPktType, |
897 | wCurrentRate, &head->data_head_a_fb, | |
898 | cbFrameSize, bNeedACK); | |
899 | } | |
900 | } else if (byPktType == PK_TYPE_11B) { | |
901 | if (need_mic) { | |
902 | *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr; | |
903 | head = &tx_buffer->tx_head.tx_ab.tx.mic.head; | |
904 | } else { | |
905 | head = &tx_buffer->tx_head.tx_ab.tx.head; | |
906 | } | |
907 | ||
908 | if (need_rts) { | |
909 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> | |
910 | tx_head.tx_ab.ab; | |
9e38a5c1 | 911 | |
92928f13 | 912 | pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0, |
cfabe4b4 | 913 | byPktType, cbFrameSize, wCurrentRate); |
f0e0d505 | 914 | |
92928f13 MP |
915 | pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, |
916 | PK_TYPE_11B, cbFrameSize, wCurrentRate, | |
917 | bNeedACK); | |
918 | ||
919 | /* Fill RTS */ | |
920 | return s_vFillRTSHead(pDevice, byPktType, head, | |
921 | cbFrameSize, | |
351c7dc3 | 922 | bNeedACK, psEthHeader, wCurrentRate, byFBOption); |
92928f13 MP |
923 | } else { |
924 | struct vnt_rrv_time_ab *pBuf = &tx_buffer-> | |
925 | tx_head.tx_ab.ab; | |
9e38a5c1 | 926 | |
92928f13 MP |
927 | pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, |
928 | PK_TYPE_11B, cbFrameSize, | |
929 | wCurrentRate, bNeedACK); | |
c12dca09 | 930 | |
92928f13 MP |
931 | return vnt_rxtx_datahead_ab(pDevice, byPktType, |
932 | wCurrentRate, &head->data_head_ab, | |
933 | cbFrameSize, bNeedACK); | |
934 | } | |
935 | } | |
0a0f4b69 MP |
936 | |
937 | return 0; | |
92b96797 FB |
938 | } |
939 | /* | |
b902fbfe | 940 | u8 * pbyBuffer,//point to pTxBufHead |
3eaca0d2 | 941 | u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last |
cc856e61 | 942 | unsigned int cbFragmentSize,//Hdr+payoad+FCS |
92b96797 FB |
943 | */ |
944 | ||
d56131de | 945 | static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType, |
d66caada | 946 | struct vnt_tx_buffer *tx_buffer, int bNeedEncryption, |
d0a2b8fa MP |
947 | u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader, |
948 | u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate, | |
949 | u32 *pcbHeaderLen, u32 *pcbTotalLen) | |
92b96797 | 950 | { |
d66caada | 951 | struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head; |
d56131de MP |
952 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
953 | u32 cbFrameSize, cbFrameBodySize; | |
d56131de MP |
954 | u32 cb802_1_H_len; |
955 | u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0; | |
956 | u32 cbFCSlen = 4, cbMICHDR = 0; | |
f46142b0 MP |
957 | int bNeedACK; |
958 | bool bRTS = false; | |
d56131de MP |
959 | u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr; |
960 | u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; | |
961 | u8 abySNAP_Bridgetunnel[ETH_ALEN] | |
962 | = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}; | |
963 | u32 uDuration; | |
964 | u32 cbHeaderLength = 0, uPadding = 0; | |
5a5d6a80 | 965 | struct vnt_mic_hdr *pMICHDR; |
d56131de MP |
966 | u8 byFBOption = AUTO_FB_NONE, byFragType; |
967 | u16 wTxBufSize; | |
4235f72f | 968 | u32 dwMICKey0, dwMICKey1, dwMIC_Priority; |
d56131de | 969 | u32 *pdwMIC_L, *pdwMIC_R; |
e269fc2d | 970 | int bSoftWEP = false; |
9e38a5c1 | 971 | |
c545e6a6 | 972 | pMICHDR = NULL; |
92b96797 | 973 | |
e2efba76 | 974 | if (bNeedEncryption && pTransmitKey->pvKeyTable) { |
4e9b5e2b AM |
975 | if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true) |
976 | bSoftWEP = true; /* WEP 256 */ | |
e2efba76 | 977 | } |
92b96797 | 978 | |
c47b0a34 MP |
979 | /* Get pkt type */ |
980 | if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) | |
981 | cb802_1_H_len = 8; | |
982 | else | |
983 | cb802_1_H_len = 0; | |
92b96797 | 984 | |
21ec51f3 | 985 | cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len; |
92b96797 FB |
986 | |
987 | //Set packet type | |
3eaca0d2 | 988 | pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8); |
92b96797 | 989 | |
22040bbf | 990 | if ((pDevice->eOPMode == OP_MODE_ADHOC) || |
c47b0a34 | 991 | (pDevice->eOPMode == OP_MODE_AP)) { |
ceb8c5da | 992 | if (is_multicast_ether_addr(psEthHeader->h_dest)) { |
e269fc2d | 993 | bNeedACK = false; |
22040bbf AM |
994 | pTxBufHead->wFIFOCtl = |
995 | pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK); | |
996 | } else { | |
4e9b5e2b | 997 | bNeedACK = true; |
22040bbf AM |
998 | pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; |
999 | } | |
c47b0a34 MP |
1000 | } else { |
1001 | /* MSDUs in Infra mode always need ACK */ | |
1002 | bNeedACK = true; | |
1003 | pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; | |
1004 | } | |
92b96797 FB |
1005 | |
1006 | pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us; | |
1007 | ||
92b96797 | 1008 | //Set FRAGCTL_MACHDCNT |
078d0cfd MP |
1009 | cbMACHdLen = WLAN_HDR_ADDR3_LEN; |
1010 | ||
3eaca0d2 | 1011 | pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10); |
92b96797 FB |
1012 | |
1013 | //Set FIFOCTL_GrpAckPolicy | |
4e9b5e2b | 1014 | if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000 |
92b96797 FB |
1015 | pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; |
1016 | } | |
1017 | ||
f84cdf65 MP |
1018 | /* Set Auto Fallback Ctl */ |
1019 | if (wCurrentRate >= RATE_18M) { | |
1020 | if (pDevice->byAutoFBCtrl == AUTO_FB_0) { | |
1021 | pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0; | |
1022 | ||
1023 | pDevice->tx_rate_fb0 = | |
1024 | wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M]; | |
1025 | pDevice->tx_rate_fb1 = | |
1026 | wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M]; | |
1027 | ||
1028 | byFBOption = AUTO_FB_0; | |
1029 | } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) { | |
1030 | pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1; | |
1031 | pDevice->tx_rate_fb0 = | |
1032 | wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M]; | |
1033 | pDevice->tx_rate_fb1 = | |
1034 | wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M]; | |
1035 | ||
1036 | byFBOption = AUTO_FB_1; | |
1037 | } | |
1038 | } | |
92b96797 | 1039 | |
4e9b5e2b | 1040 | if (bSoftWEP != true) { |
92b96797 FB |
1041 | if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled |
1042 | if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104 | |
1043 | pTxBufHead->wFragCtl |= FRAGCTL_LEGACY; | |
1044 | } | |
1045 | if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) { | |
1046 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n"); | |
1047 | pTxBufHead->wFragCtl |= FRAGCTL_TKIP; | |
1048 | } | |
1049 | else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP | |
1050 | pTxBufHead->wFragCtl |= FRAGCTL_AES; | |
1051 | } | |
1052 | } | |
1053 | } | |
1054 | ||
92b96797 FB |
1055 | if ((bNeedEncryption) && (pTransmitKey != NULL)) { |
1056 | if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { | |
1057 | cbIVlen = 4; | |
1058 | cbICVlen = 4; | |
1059 | } | |
1060 | else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) { | |
1061 | cbIVlen = 8;//IV+ExtIV | |
1062 | cbMIClen = 8; | |
1063 | cbICVlen = 4; | |
1064 | } | |
1065 | if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { | |
1066 | cbIVlen = 8;//RSN Header | |
1067 | cbICVlen = 8;//MIC | |
5a5d6a80 | 1068 | cbMICHDR = sizeof(struct vnt_mic_hdr); |
92b96797 | 1069 | } |
e269fc2d | 1070 | if (bSoftWEP == false) { |
92b96797 FB |
1071 | //MAC Header should be padding 0 to DW alignment. |
1072 | uPadding = 4 - (cbMACHdLen%4); | |
1073 | uPadding %= 4; | |
1074 | } | |
1075 | } | |
1076 | ||
1077 | cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen; | |
1078 | ||
e269fc2d AM |
1079 | if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) { |
1080 | bRTS = false; | |
92b96797 | 1081 | } else { |
4e9b5e2b | 1082 | bRTS = true; |
92b96797 FB |
1083 | pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY); |
1084 | } | |
1085 | ||
b902fbfe | 1086 | pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]); |
d66caada MP |
1087 | wTxBufSize = sizeof(struct vnt_tx_fifo_head); |
1088 | ||
92b96797 FB |
1089 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet |
1090 | if (byFBOption == AUTO_FB_NONE) { | |
4e9b5e2b | 1091 | if (bRTS == true) {//RTS_need |
6398a59b | 1092 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) + |
78363fd1 | 1093 | cbMICHDR + sizeof(struct vnt_rts_g); |
92b96797 FB |
1094 | } |
1095 | else { //RTS_needless | |
4f990057 | 1096 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + |
78363fd1 | 1097 | cbMICHDR + sizeof(struct vnt_cts); |
92b96797 FB |
1098 | } |
1099 | } else { | |
1100 | // Auto Fall Back | |
4e9b5e2b | 1101 | if (bRTS == true) {//RTS_need |
6398a59b | 1102 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) + |
5b852f53 | 1103 | cbMICHDR + sizeof(struct vnt_rts_g_fb); |
92b96797 | 1104 | } |
e269fc2d | 1105 | else if (bRTS == false) { //RTS_needless |
4f990057 | 1106 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + |
5b852f53 | 1107 | cbMICHDR + sizeof(struct vnt_cts_fb); |
92b96797 FB |
1108 | } |
1109 | } // Auto Fall Back | |
1110 | } | |
1111 | else {//802.11a/b packet | |
1112 | if (byFBOption == AUTO_FB_NONE) { | |
4e9b5e2b | 1113 | if (bRTS == true) {//RTS_need |
976467d3 | 1114 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + |
5634a5ab | 1115 | cbMICHDR + sizeof(struct vnt_rts_ab); |
92b96797 | 1116 | } |
e269fc2d | 1117 | else if (bRTS == false) { //RTS_needless, no MICHDR |
976467d3 | 1118 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + |
558becf1 | 1119 | cbMICHDR + sizeof(struct vnt_tx_datahead_ab); |
92b96797 FB |
1120 | } |
1121 | } else { | |
1122 | // Auto Fall Back | |
4e9b5e2b | 1123 | if (bRTS == true) {//RTS_need |
976467d3 | 1124 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + |
bd3f51f1 | 1125 | cbMICHDR + sizeof(struct vnt_rts_a_fb); |
92b96797 | 1126 | } |
e269fc2d | 1127 | else if (bRTS == false) { //RTS_needless |
976467d3 | 1128 | cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + |
1da4ee20 | 1129 | cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb); |
92b96797 FB |
1130 | } |
1131 | } // Auto Fall Back | |
1132 | } | |
1133 | ||
b902fbfe AM |
1134 | pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength); |
1135 | pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding); | |
1136 | pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen); | |
92b96797 | 1137 | |
92b96797 FB |
1138 | //========================= |
1139 | // No Fragmentation | |
1140 | //========================= | |
1141 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n"); | |
1142 | byFragType = FRAGCTL_NONFRAG; | |
1143 | //uDMAIdx = TYPE_AC0DMA; | |
1144 | //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]); | |
1145 | ||
78363fd1 MP |
1146 | /* Fill FIFO, RrvTime, RTS and CTS */ |
1147 | uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, | |
1148 | tx_buffer, &pMICHDR, cbMICHDR, | |
1149 | cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS); | |
c12dca09 | 1150 | |
92b96797 | 1151 | // Generate TX MAC Header |
3eaca0d2 | 1152 | s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption, |
92b96797 FB |
1153 | byFragType, uDMAIdx, 0); |
1154 | ||
4e9b5e2b | 1155 | if (bNeedEncryption == true) { |
92b96797 | 1156 | //Fill TXKEY |
3ba0938c | 1157 | s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey, |
ec37d8b6 | 1158 | pbyMacHdr, (u16)cbFrameBodySize, pMICHDR); |
92b96797 FB |
1159 | |
1160 | if (pDevice->bEnableHostWEP) { | |
1161 | pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16; | |
1162 | pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0; | |
1163 | } | |
1164 | } | |
1165 | ||
c47b0a34 MP |
1166 | /* 802.1H */ |
1167 | if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) { | |
ceb8c5da | 1168 | if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) || |
c47b0a34 | 1169 | (psEthHeader->h_proto == cpu_to_le16(0xF380))) |
b902fbfe | 1170 | memcpy((u8 *) (pbyPayloadHead), |
c47b0a34 MP |
1171 | abySNAP_Bridgetunnel, 6); |
1172 | else | |
1173 | memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6); | |
92b96797 | 1174 | |
c47b0a34 | 1175 | pbyType = (u8 *) (pbyPayloadHead + 6); |
92b96797 | 1176 | |
c47b0a34 MP |
1177 | memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16)); |
1178 | } | |
92b96797 | 1179 | |
92b96797 FB |
1180 | if (pPacket != NULL) { |
1181 | // Copy the Packet into a tx Buffer | |
3e362598 | 1182 | memcpy((pbyPayloadHead + cb802_1_H_len), |
21ec51f3 CC |
1183 | (pPacket + ETH_HLEN), |
1184 | uSkbPacketLen - ETH_HLEN | |
92b96797 FB |
1185 | ); |
1186 | ||
1187 | } else { | |
1188 | // while bRelayPacketSend psEthHeader is point to header+payload | |
b902fbfe | 1189 | memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN); |
92b96797 FB |
1190 | } |
1191 | ||
4e9b5e2b | 1192 | if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) { |
92b96797 FB |
1193 | |
1194 | /////////////////////////////////////////////////////////////////// | |
1195 | ||
14c5ef57 MP |
1196 | if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) { |
1197 | dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]); | |
1198 | dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]); | |
1199 | } | |
92b96797 | 1200 | else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) { |
52a7e64b AM |
1201 | dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]); |
1202 | dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]); | |
92b96797 FB |
1203 | } |
1204 | else { | |
52a7e64b AM |
1205 | dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]); |
1206 | dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]); | |
92b96797 FB |
1207 | } |
1208 | // DO Software Michael | |
1209 | MIC_vInit(dwMICKey0, dwMICKey1); | |
ceb8c5da | 1210 | MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12); |
92b96797 | 1211 | dwMIC_Priority = 0; |
b902fbfe | 1212 | MIC_vAppend((u8 *)&dwMIC_Priority, 4); |
b4dc03af MP |
1213 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n", |
1214 | dwMICKey0, dwMICKey1); | |
92b96797 FB |
1215 | |
1216 | /////////////////////////////////////////////////////////////////// | |
1217 | ||
1218 | //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength)); | |
1219 | //for (ii = 0; ii < cbFrameBodySize; ii++) { | |
b902fbfe | 1220 | // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii)))); |
92b96797 FB |
1221 | //} |
1222 | //DBG_PRN_GRP12(("\n\n\n")); | |
1223 | ||
1224 | MIC_vAppend(pbyPayloadHead, cbFrameBodySize); | |
1225 | ||
52a7e64b AM |
1226 | pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize); |
1227 | pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4); | |
92b96797 FB |
1228 | |
1229 | MIC_vGetMIC(pdwMIC_L, pdwMIC_R); | |
1230 | MIC_vUnInit(); | |
1231 | ||
4e9b5e2b | 1232 | if (pDevice->bTxMICFail == true) { |
92b96797 FB |
1233 | *pdwMIC_L = 0; |
1234 | *pdwMIC_R = 0; | |
e269fc2d | 1235 | pDevice->bTxMICFail = false; |
92b96797 FB |
1236 | } |
1237 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize); | |
1238 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen); | |
1239 | //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R); | |
1240 | } | |
1241 | ||
4e9b5e2b | 1242 | if (bSoftWEP == true) { |
92b96797 | 1243 | |
3eaca0d2 | 1244 | s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen)); |
92b96797 | 1245 | |
4e9b5e2b AM |
1246 | } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) || |
1247 | ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) || | |
1248 | ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) { | |
92b96797 FB |
1249 | cbFrameSize -= cbICVlen; |
1250 | } | |
1251 | ||
92b96797 | 1252 | cbFrameSize -= cbFCSlen; |
92b96797 FB |
1253 | |
1254 | *pcbHeaderLen = cbHeaderLength; | |
1255 | *pcbTotalLen = cbHeaderLength + cbFrameSize ; | |
1256 | ||
92b96797 | 1257 | //Set FragCtl in TxBufferHead |
3eaca0d2 | 1258 | pTxBufHead->wFragCtl |= (u16)byFragType; |
92b96797 | 1259 | |
4e9b5e2b | 1260 | return true; |
92b96797 FB |
1261 | |
1262 | } | |
1263 | ||
92b96797 FB |
1264 | /*+ |
1265 | * | |
1266 | * Description: | |
1267 | * Translate 802.3 to 802.11 header | |
1268 | * | |
1269 | * Parameters: | |
1270 | * In: | |
a0a1f61a | 1271 | * pDevice - Pointer to adapter |
92b96797 FB |
1272 | * dwTxBufferAddr - Transmit Buffer |
1273 | * pPacket - Packet from upper layer | |
1274 | * cbPacketSize - Transmit Data Length | |
1275 | * Out: | |
1276 | * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header | |
1277 | * pcbAppendPayload - size of append payload for 802.1H translation | |
1278 | * | |
1279 | * Return Value: none | |
1280 | * | |
1281 | -*/ | |
1282 | ||
d56131de | 1283 | static void s_vGenerateMACHeader(struct vnt_private *pDevice, |
ceb8c5da | 1284 | u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader, |
d56131de | 1285 | int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx) |
92b96797 | 1286 | { |
1cac4a4b | 1287 | struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr; |
92b96797 | 1288 | |
c921cc8c | 1289 | pMACHeader->frame_control = TYPE_802_11_DATA; |
92b96797 FB |
1290 | |
1291 | if (pDevice->eOPMode == OP_MODE_AP) { | |
1cac4a4b | 1292 | memcpy(&(pMACHeader->addr1[0]), |
ceb8c5da | 1293 | &(psEthHeader->h_dest[0]), |
9a0e756c | 1294 | ETH_ALEN); |
1cac4a4b AM |
1295 | memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN); |
1296 | memcpy(&(pMACHeader->addr3[0]), | |
ceb8c5da | 1297 | &(psEthHeader->h_source[0]), |
9a0e756c | 1298 | ETH_ALEN); |
1cac4a4b | 1299 | pMACHeader->frame_control |= FC_FROMDS; |
9a0e756c AM |
1300 | } else { |
1301 | if (pDevice->eOPMode == OP_MODE_ADHOC) { | |
1cac4a4b | 1302 | memcpy(&(pMACHeader->addr1[0]), |
ceb8c5da | 1303 | &(psEthHeader->h_dest[0]), |
9a0e756c | 1304 | ETH_ALEN); |
1cac4a4b | 1305 | memcpy(&(pMACHeader->addr2[0]), |
ceb8c5da | 1306 | &(psEthHeader->h_source[0]), |
9a0e756c | 1307 | ETH_ALEN); |
1cac4a4b | 1308 | memcpy(&(pMACHeader->addr3[0]), |
9a0e756c AM |
1309 | &(pDevice->abyBSSID[0]), |
1310 | ETH_ALEN); | |
1311 | } else { | |
1cac4a4b | 1312 | memcpy(&(pMACHeader->addr3[0]), |
ceb8c5da | 1313 | &(psEthHeader->h_dest[0]), |
9a0e756c | 1314 | ETH_ALEN); |
1cac4a4b | 1315 | memcpy(&(pMACHeader->addr2[0]), |
ceb8c5da | 1316 | &(psEthHeader->h_source[0]), |
9a0e756c | 1317 | ETH_ALEN); |
1cac4a4b | 1318 | memcpy(&(pMACHeader->addr1[0]), |
9a0e756c AM |
1319 | &(pDevice->abyBSSID[0]), |
1320 | ETH_ALEN); | |
1cac4a4b | 1321 | pMACHeader->frame_control |= FC_TODS; |
92b96797 FB |
1322 | } |
1323 | } | |
1324 | ||
1325 | if (bNeedEncrypt) | |
1cac4a4b | 1326 | pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1)); |
92b96797 | 1327 | |
1cac4a4b | 1328 | pMACHeader->duration_id = cpu_to_le16(wDuration); |
92b96797 | 1329 | |
1cac4a4b | 1330 | pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4); |
92b96797 FB |
1331 | |
1332 | //Set FragNumber in Sequence Control | |
1cac4a4b | 1333 | pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx); |
92b96797 FB |
1334 | |
1335 | if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) { | |
1336 | pDevice->wSeqCounter++; | |
1337 | if (pDevice->wSeqCounter > 0x0fff) | |
1338 | pDevice->wSeqCounter = 0; | |
1339 | } | |
1340 | ||
1341 | if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag | |
1cac4a4b | 1342 | pMACHeader->frame_control |= FC_MOREFRAG; |
92b96797 FB |
1343 | } |
1344 | } | |
1345 | ||
92b96797 FB |
1346 | /*+ |
1347 | * | |
1348 | * Description: | |
1349 | * Request instructs a MAC to transmit a 802.11 management packet through | |
1350 | * the adapter onto the medium. | |
1351 | * | |
1352 | * Parameters: | |
1353 | * In: | |
1354 | * hDeviceContext - Pointer to the adapter | |
1355 | * pPacket - A pointer to a descriptor for the packet to transmit | |
1356 | * Out: | |
1357 | * none | |
1358 | * | |
e269fc2d | 1359 | * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false |
92b96797 FB |
1360 | * |
1361 | -*/ | |
1362 | ||
d56131de MP |
1363 | CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, |
1364 | struct vnt_tx_mgmt *pPacket) | |
92b96797 | 1365 | { |
d56131de | 1366 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
f39c0d8e | 1367 | struct vnt_tx_buffer *pTX_Buffer; |
dcdf1d03 | 1368 | struct vnt_usb_send_context *pContext; |
d66caada | 1369 | struct vnt_tx_fifo_head *pTxBufHead; |
1cac4a4b | 1370 | struct ieee80211_hdr *pMACHeader; |
ceb8c5da | 1371 | struct ethhdr sEthHeader; |
d56131de | 1372 | u8 byPktType, *pbyTxBufferAddr; |
f0e0d505 | 1373 | struct vnt_mic_hdr *pMICHDR = NULL; |
d56131de | 1374 | u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize; |
e269fc2d | 1375 | int bNeedACK, bIsPSPOLL = false; |
d56131de MP |
1376 | u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4; |
1377 | u32 uPadding = 0; | |
1378 | u16 wTxBufSize; | |
1379 | u32 cbMacHdLen; | |
1380 | u16 wCurrentRate = RATE_1M; | |
92b96797 | 1381 | |
aceaf018 | 1382 | pContext = s_vGetFreeContext(pDevice); |
92b96797 FB |
1383 | |
1384 | if (NULL == pContext) { | |
1385 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n"); | |
1386 | return CMD_STATUS_RESOURCES; | |
1387 | } | |
1388 | ||
f39c0d8e | 1389 | pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0]; |
92b96797 | 1390 | cbFrameBodySize = pPacket->cbPayloadLen; |
d66caada MP |
1391 | pTxBufHead = &pTX_Buffer->fifo_head; |
1392 | pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0]; | |
1393 | wTxBufSize = sizeof(struct vnt_tx_fifo_head); | |
92b96797 FB |
1394 | |
1395 | if (pDevice->byBBType == BB_TYPE_11A) { | |
1396 | wCurrentRate = RATE_6M; | |
1397 | byPktType = PK_TYPE_11A; | |
1398 | } else { | |
1399 | wCurrentRate = RATE_1M; | |
1400 | byPktType = PK_TYPE_11B; | |
1401 | } | |
1402 | ||
1403 | // SetPower will cause error power TX state for OFDM Date packet in TX buffer. | |
1404 | // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability. | |
1405 | // And cmd timer will wait data pkt TX finish before scanning so it's OK | |
1406 | // to set power here. | |
1407 | if (pMgmt->eScanState != WMAC_NO_SCANNING) { | |
1408 | RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh); | |
1409 | } else { | |
1410 | RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel); | |
1411 | } | |
1412 | pDevice->wCurrentRate = wCurrentRate; | |
1413 | ||
92b96797 FB |
1414 | //Set packet type |
1415 | if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000 | |
1416 | pTxBufHead->wFIFOCtl = 0; | |
1417 | } | |
1418 | else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000 | |
1419 | pTxBufHead->wFIFOCtl |= FIFOCTL_11B; | |
1420 | } | |
1421 | else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000 | |
1422 | pTxBufHead->wFIFOCtl |= FIFOCTL_11GB; | |
1423 | } | |
1424 | else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000 | |
1425 | pTxBufHead->wFIFOCtl |= FIFOCTL_11GA; | |
1426 | } | |
1427 | ||
1428 | pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN; | |
1429 | pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); | |
1430 | ||
22040bbf | 1431 | if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) { |
e269fc2d | 1432 | bNeedACK = false; |
92b96797 FB |
1433 | } |
1434 | else { | |
4e9b5e2b | 1435 | bNeedACK = true; |
92b96797 FB |
1436 | pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; |
1437 | }; | |
1438 | ||
1439 | if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || | |
1440 | (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) { | |
1441 | ||
1442 | pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY; | |
1443 | //Set Preamble type always long | |
1444 | //pDevice->byPreambleType = PREAMBLE_LONG; | |
1445 | // probe-response don't retry | |
1446 | //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) { | |
e269fc2d | 1447 | // bNeedACK = false; |
92b96797 FB |
1448 | // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK); |
1449 | //} | |
1450 | } | |
1451 | ||
1452 | pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0); | |
1453 | ||
1454 | if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) { | |
4e9b5e2b | 1455 | bIsPSPOLL = true; |
92b96797 FB |
1456 | cbMacHdLen = WLAN_HDR_ADDR2_LEN; |
1457 | } else { | |
1458 | cbMacHdLen = WLAN_HDR_ADDR3_LEN; | |
1459 | } | |
1460 | ||
1461 | //Set FRAGCTL_MACHDCNT | |
3eaca0d2 | 1462 | pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10)); |
92b96797 FB |
1463 | |
1464 | // Notes: | |
1465 | // Although spec says MMPDU can be fragmented; In most case, | |
1466 | // no one will send a MMPDU under fragmentation. With RTS may occur. | |
92b96797 FB |
1467 | |
1468 | if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) { | |
1469 | if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) { | |
1470 | cbIVlen = 4; | |
1471 | cbICVlen = 4; | |
1472 | pTxBufHead->wFragCtl |= FRAGCTL_LEGACY; | |
1473 | } | |
1474 | else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) { | |
1475 | cbIVlen = 8;//IV+ExtIV | |
1476 | cbMIClen = 8; | |
1477 | cbICVlen = 4; | |
1478 | pTxBufHead->wFragCtl |= FRAGCTL_TKIP; | |
1479 | //We need to get seed here for filling TxKey entry. | |
1480 | //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr, | |
1481 | // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG); | |
1482 | } | |
1483 | else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) { | |
1484 | cbIVlen = 8;//RSN Header | |
1485 | cbICVlen = 8;//MIC | |
1486 | pTxBufHead->wFragCtl |= FRAGCTL_AES; | |
92b96797 FB |
1487 | } |
1488 | //MAC Header should be padding 0 to DW alignment. | |
1489 | uPadding = 4 - (cbMacHdLen%4); | |
1490 | uPadding %= 4; | |
1491 | } | |
1492 | ||
1493 | cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen; | |
1494 | ||
1495 | //Set FIFOCTL_GrpAckPolicy | |
4e9b5e2b | 1496 | if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000 |
92b96797 FB |
1497 | pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; |
1498 | } | |
1499 | //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter() | |
1500 | ||
1501 | //Set RrvTime/RTS/CTS Buffer | |
1502 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet | |
4f990057 | 1503 | cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + |
78363fd1 | 1504 | sizeof(struct vnt_cts); |
92b96797 FB |
1505 | } |
1506 | else { // 802.11a/b packet | |
976467d3 | 1507 | cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + |
558becf1 | 1508 | sizeof(struct vnt_tx_datahead_ab); |
92b96797 FB |
1509 | } |
1510 | ||
ceb8c5da | 1511 | memcpy(&(sEthHeader.h_dest[0]), |
9a0e756c AM |
1512 | &(pPacket->p80211Header->sA3.abyAddr1[0]), |
1513 | ETH_ALEN); | |
ceb8c5da | 1514 | memcpy(&(sEthHeader.h_source[0]), |
9a0e756c AM |
1515 | &(pPacket->p80211Header->sA3.abyAddr2[0]), |
1516 | ETH_ALEN); | |
92b96797 FB |
1517 | //========================= |
1518 | // No Fragmentation | |
1519 | //========================= | |
3eaca0d2 | 1520 | pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG; |
92b96797 | 1521 | |
351c7dc3 | 1522 | /* Fill FIFO,RrvTime,RTS,and CTS */ |
78363fd1 | 1523 | uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, |
fa57560c | 1524 | pTX_Buffer, &pMICHDR, 0, |
f46142b0 | 1525 | cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false); |
92b96797 | 1526 | |
1cac4a4b | 1527 | pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize); |
92b96797 FB |
1528 | |
1529 | cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize; | |
1530 | ||
1531 | if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) { | |
b902fbfe AM |
1532 | u8 * pbyIVHead; |
1533 | u8 * pbyPayloadHead; | |
1534 | u8 * pbyBSSID; | |
92b96797 FB |
1535 | PSKeyItem pTransmitKey = NULL; |
1536 | ||
b902fbfe AM |
1537 | pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding); |
1538 | pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen); | |
92b96797 FB |
1539 | do { |
1540 | if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) && | |
4e9b5e2b | 1541 | (pDevice->bLinkPass == true)) { |
92b96797 FB |
1542 | pbyBSSID = pDevice->abyBSSID; |
1543 | // get pairwise key | |
e269fc2d | 1544 | if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { |
92b96797 | 1545 | // get group key |
4e9b5e2b | 1546 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) { |
92b96797 FB |
1547 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); |
1548 | break; | |
1549 | } | |
1550 | } else { | |
1551 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n"); | |
1552 | break; | |
1553 | } | |
1554 | } | |
1555 | // get group key | |
1556 | pbyBSSID = pDevice->abyBroadcastAddr; | |
e269fc2d | 1557 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { |
92b96797 FB |
1558 | pTransmitKey = NULL; |
1559 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode); | |
1560 | } else { | |
1561 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); | |
1562 | } | |
e269fc2d | 1563 | } while(false); |
92b96797 | 1564 | //Fill TXKEY |
3ba0938c | 1565 | s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey, |
3eaca0d2 | 1566 | (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL); |
92b96797 | 1567 | |
3e362598 | 1568 | memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen); |
b902fbfe | 1569 | memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen), |
92b96797 FB |
1570 | cbFrameBodySize); |
1571 | } | |
1572 | else { | |
1573 | // Copy the Packet into a tx Buffer | |
3e362598 | 1574 | memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen); |
92b96797 FB |
1575 | } |
1576 | ||
1cac4a4b | 1577 | pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4); |
92b96797 FB |
1578 | pDevice->wSeqCounter++ ; |
1579 | if (pDevice->wSeqCounter > 0x0fff) | |
1580 | pDevice->wSeqCounter = 0; | |
1581 | ||
1582 | if (bIsPSPOLL) { | |
1583 | // The MAC will automatically replace the Duration-field of MAC header by Duration-field | |
a0a1f61a | 1584 | // of FIFO control header. |
92b96797 FB |
1585 | // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is |
1586 | // in the same place of other packet's Duration-field). | |
1587 | // And it will cause Cisco-AP to issue Disassociation-packet | |
7e60a3de | 1588 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) { |
78363fd1 MP |
1589 | struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head. |
1590 | tx_cts.tx.head.cts_g.data_head; | |
1591 | data_head->wDuration_a = | |
7e60a3de | 1592 | cpu_to_le16(pPacket->p80211Header->sA2.wDurationID); |
78363fd1 | 1593 | data_head->wDuration_b = |
7e60a3de MP |
1594 | cpu_to_le16(pPacket->p80211Header->sA2.wDurationID); |
1595 | } else { | |
c12dca09 MP |
1596 | struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head. |
1597 | tx_ab.tx.head.data_head_ab; | |
1598 | data_head->wDuration = | |
558becf1 MP |
1599 | cpu_to_le16(pPacket->p80211Header->sA2.wDurationID); |
1600 | } | |
92b96797 FB |
1601 | } |
1602 | ||
3eaca0d2 | 1603 | pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount)); |
b902fbfe | 1604 | pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
92b96797 FB |
1605 | pTX_Buffer->byType = 0x00; |
1606 | ||
1607 | pContext->pPacket = NULL; | |
1608 | pContext->Type = CONTEXT_MGMT_PACKET; | |
3eaca0d2 | 1609 | pContext->uBufLen = (u16)cbReqCount + 4; //USB header |
92b96797 | 1610 | |
1cac4a4b | 1611 | if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) { |
d66caada MP |
1612 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
1613 | &pMACHeader->addr1[0], (u16)cbFrameSize, | |
1614 | pTxBufHead->wFIFOCtl); | |
92b96797 FB |
1615 | } |
1616 | else { | |
d66caada MP |
1617 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
1618 | &pMACHeader->addr3[0], (u16)cbFrameSize, | |
1619 | pTxBufHead->wFIFOCtl); | |
92b96797 FB |
1620 | } |
1621 | ||
1622 | PIPEnsSendBulkOut(pDevice,pContext); | |
1623 | return CMD_STATUS_PENDING; | |
1624 | } | |
1625 | ||
d56131de MP |
1626 | CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice, |
1627 | struct vnt_tx_mgmt *pPacket) | |
92b96797 | 1628 | { |
01f865ba | 1629 | struct vnt_beacon_buffer *pTX_Buffer; |
c7c57b24 | 1630 | struct vnt_tx_short_buf_head *short_head; |
d56131de MP |
1631 | u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN; |
1632 | u32 cbHeaderSize = 0; | |
1cac4a4b | 1633 | struct ieee80211_hdr *pMACHeader; |
d56131de MP |
1634 | u16 wCurrentRate; |
1635 | u32 cbFrameBodySize; | |
1636 | u32 cbReqCount; | |
dcdf1d03 | 1637 | struct vnt_usb_send_context *pContext; |
d56131de | 1638 | CMD_STATUS status; |
92b96797 | 1639 | |
aceaf018 | 1640 | pContext = s_vGetFreeContext(pDevice); |
92b96797 FB |
1641 | if (NULL == pContext) { |
1642 | status = CMD_STATUS_RESOURCES; | |
1643 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n"); | |
1644 | return status ; | |
1645 | } | |
01f865ba MP |
1646 | |
1647 | pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0]; | |
c7c57b24 | 1648 | short_head = &pTX_Buffer->short_head; |
92b96797 FB |
1649 | |
1650 | cbFrameBodySize = pPacket->cbPayloadLen; | |
1651 | ||
c7c57b24 | 1652 | cbHeaderSize = sizeof(struct vnt_tx_short_buf_head); |
92b96797 | 1653 | |
c7c57b24 MP |
1654 | if (pDevice->byBBType == BB_TYPE_11A) { |
1655 | wCurrentRate = RATE_6M; | |
1656 | ||
1657 | /* Get SignalField,ServiceField,Length */ | |
1658 | BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, | |
1659 | PK_TYPE_11A, &short_head->ab); | |
1660 | ||
1661 | /* Get Duration and TimeStampOff */ | |
1662 | short_head->duration = s_uGetDataDuration(pDevice, | |
1663 | PK_TYPE_11A, false); | |
1664 | short_head->time_stamp_off = | |
1665 | vnt_time_stamp_off(pDevice, wCurrentRate); | |
1666 | } else { | |
1667 | wCurrentRate = RATE_1M; | |
1668 | short_head->fifo_ctl |= FIFOCTL_11B; | |
1669 | ||
1670 | /* Get SignalField,ServiceField,Length */ | |
1671 | BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, | |
1672 | PK_TYPE_11B, &short_head->ab); | |
1673 | ||
1674 | /* Get Duration and TimeStampOff */ | |
1675 | short_head->duration = s_uGetDataDuration(pDevice, | |
6b5ad9d2 | 1676 | PK_TYPE_11B, false); |
c7c57b24 MP |
1677 | short_head->time_stamp_off = |
1678 | vnt_time_stamp_off(pDevice, wCurrentRate); | |
1679 | } | |
1680 | ||
92b96797 | 1681 | |
0b71fe36 MP |
1682 | /* Generate Beacon Header */ |
1683 | pMACHeader = &pTX_Buffer->hdr; | |
92b96797 | 1684 | |
0b71fe36 MP |
1685 | memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen); |
1686 | ||
1687 | pMACHeader->duration_id = 0; | |
1688 | pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4); | |
1689 | pDevice->wSeqCounter++; | |
1690 | if (pDevice->wSeqCounter > 0x0fff) | |
1691 | pDevice->wSeqCounter = 0; | |
92b96797 FB |
1692 | |
1693 | cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize; | |
1694 | ||
3eaca0d2 | 1695 | pTX_Buffer->wTxByteCount = (u16)cbReqCount; |
b902fbfe | 1696 | pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
92b96797 FB |
1697 | pTX_Buffer->byType = 0x01; |
1698 | ||
1699 | pContext->pPacket = NULL; | |
1700 | pContext->Type = CONTEXT_MGMT_PACKET; | |
3eaca0d2 | 1701 | pContext->uBufLen = (u16)cbReqCount + 4; //USB header |
92b96797 FB |
1702 | |
1703 | PIPEnsSendBulkOut(pDevice,pContext); | |
1704 | return CMD_STATUS_PENDING; | |
1705 | ||
1706 | } | |
1707 | ||
d56131de MP |
1708 | void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb) |
1709 | { | |
1710 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; | |
f39c0d8e | 1711 | struct vnt_tx_buffer *pTX_Buffer; |
d66caada | 1712 | struct vnt_tx_fifo_head *pTxBufHead; |
d56131de MP |
1713 | u8 byPktType; |
1714 | u8 *pbyTxBufferAddr; | |
d56131de | 1715 | u32 uDuration, cbReqCount; |
1cac4a4b | 1716 | struct ieee80211_hdr *pMACHeader; |
d56131de | 1717 | u32 cbHeaderSize, cbFrameBodySize; |
e269fc2d | 1718 | int bNeedACK, bIsPSPOLL = false; |
d56131de MP |
1719 | u32 cbFrameSize; |
1720 | u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4; | |
1721 | u32 uPadding = 0; | |
1722 | u32 cbMICHDR = 0, uLength = 0; | |
1723 | u32 dwMICKey0, dwMICKey1; | |
1724 | u32 dwMIC_Priority; | |
1725 | u32 *pdwMIC_L, *pdwMIC_R; | |
1726 | u16 wTxBufSize; | |
1727 | u32 cbMacHdLen; | |
ceb8c5da | 1728 | struct ethhdr sEthHeader; |
f0e0d505 | 1729 | struct vnt_mic_hdr *pMICHDR; |
d56131de MP |
1730 | u32 wCurrentRate = RATE_1M; |
1731 | PUWLAN_80211HDR p80211Header; | |
1732 | u32 uNodeIndex = 0; | |
e269fc2d | 1733 | int bNodeExist = false; |
d56131de MP |
1734 | SKeyItem STempKey; |
1735 | PSKeyItem pTransmitKey = NULL; | |
1736 | u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr; | |
1737 | u32 cbExtSuppRate = 0; | |
dcdf1d03 | 1738 | struct vnt_usb_send_context *pContext; |
92b96797 | 1739 | |
c545e6a6 | 1740 | pMICHDR = NULL; |
92b96797 FB |
1741 | |
1742 | if(skb->len <= WLAN_HDR_ADDR3_LEN) { | |
1743 | cbFrameBodySize = 0; | |
1744 | } | |
1745 | else { | |
1746 | cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN; | |
1747 | } | |
1748 | p80211Header = (PUWLAN_80211HDR)skb->data; | |
1749 | ||
aceaf018 | 1750 | pContext = s_vGetFreeContext(pDevice); |
92b96797 FB |
1751 | |
1752 | if (NULL == pContext) { | |
1753 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n"); | |
1754 | dev_kfree_skb_irq(skb); | |
1755 | return ; | |
1756 | } | |
1757 | ||
f39c0d8e | 1758 | pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0]; |
d66caada MP |
1759 | pTxBufHead = &pTX_Buffer->fifo_head; |
1760 | pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0]; | |
1761 | wTxBufSize = sizeof(struct vnt_tx_fifo_head); | |
92b96797 FB |
1762 | |
1763 | if (pDevice->byBBType == BB_TYPE_11A) { | |
1764 | wCurrentRate = RATE_6M; | |
1765 | byPktType = PK_TYPE_11A; | |
1766 | } else { | |
1767 | wCurrentRate = RATE_1M; | |
1768 | byPktType = PK_TYPE_11B; | |
1769 | } | |
1770 | ||
1771 | // SetPower will cause error power TX state for OFDM Date packet in TX buffer. | |
1772 | // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability. | |
1773 | // And cmd timer will wait data pkt TX finish before scanning so it's OK | |
1774 | // to set power here. | |
1775 | if (pMgmt->eScanState != WMAC_NO_SCANNING) { | |
1776 | RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh); | |
1777 | } else { | |
1778 | RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel); | |
1779 | } | |
1780 | ||
1781 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl); | |
1782 | ||
1783 | //Set packet type | |
1784 | if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000 | |
1785 | pTxBufHead->wFIFOCtl = 0; | |
1786 | } | |
1787 | else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000 | |
1788 | pTxBufHead->wFIFOCtl |= FIFOCTL_11B; | |
1789 | } | |
1790 | else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000 | |
1791 | pTxBufHead->wFIFOCtl |= FIFOCTL_11GB; | |
1792 | } | |
1793 | else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000 | |
1794 | pTxBufHead->wFIFOCtl |= FIFOCTL_11GA; | |
1795 | } | |
1796 | ||
1797 | pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN; | |
1798 | pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); | |
1799 | ||
22040bbf | 1800 | if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) { |
e269fc2d | 1801 | bNeedACK = false; |
92b96797 FB |
1802 | if (pDevice->bEnableHostWEP) { |
1803 | uNodeIndex = 0; | |
4e9b5e2b | 1804 | bNodeExist = true; |
9fc86028 | 1805 | } |
92b96797 FB |
1806 | } |
1807 | else { | |
1808 | if (pDevice->bEnableHostWEP) { | |
b902fbfe | 1809 | if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex)) |
4e9b5e2b | 1810 | bNodeExist = true; |
9fc86028 | 1811 | } |
4e9b5e2b | 1812 | bNeedACK = true; |
92b96797 FB |
1813 | pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; |
1814 | }; | |
1815 | ||
1816 | if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || | |
1817 | (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) { | |
1818 | ||
1819 | pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY; | |
1820 | //Set Preamble type always long | |
1821 | //pDevice->byPreambleType = PREAMBLE_LONG; | |
1822 | ||
1823 | // probe-response don't retry | |
1824 | //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) { | |
e269fc2d | 1825 | // bNeedACK = false; |
92b96797 FB |
1826 | // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK); |
1827 | //} | |
1828 | } | |
1829 | ||
1830 | pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0); | |
1831 | ||
1832 | if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) { | |
4e9b5e2b | 1833 | bIsPSPOLL = true; |
92b96797 FB |
1834 | cbMacHdLen = WLAN_HDR_ADDR2_LEN; |
1835 | } else { | |
1836 | cbMacHdLen = WLAN_HDR_ADDR3_LEN; | |
1837 | } | |
1838 | ||
a0a1f61a | 1839 | // hostapd daemon ext support rate patch |
92b96797 FB |
1840 | if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) { |
1841 | ||
1842 | if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) { | |
1843 | cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN; | |
1844 | } | |
1845 | ||
1846 | if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) { | |
1847 | cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN; | |
1848 | } | |
1849 | ||
1850 | if (cbExtSuppRate >0) { | |
1851 | cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES; | |
1852 | } | |
1853 | } | |
1854 | ||
92b96797 | 1855 | //Set FRAGCTL_MACHDCNT |
3eaca0d2 | 1856 | pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10); |
92b96797 FB |
1857 | |
1858 | // Notes: | |
1859 | // Although spec says MMPDU can be fragmented; In most case, | |
1860 | // no one will send a MMPDU under fragmentation. With RTS may occur. | |
92b96797 | 1861 | |
92b96797 FB |
1862 | if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) { |
1863 | if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) { | |
1864 | cbIVlen = 4; | |
1865 | cbICVlen = 4; | |
1866 | pTxBufHead->wFragCtl |= FRAGCTL_LEGACY; | |
1867 | } | |
1868 | else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) { | |
1869 | cbIVlen = 8;//IV+ExtIV | |
1870 | cbMIClen = 8; | |
1871 | cbICVlen = 4; | |
1872 | pTxBufHead->wFragCtl |= FRAGCTL_TKIP; | |
1873 | //We need to get seed here for filling TxKey entry. | |
1874 | //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr, | |
1875 | // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG); | |
1876 | } | |
1877 | else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) { | |
1878 | cbIVlen = 8;//RSN Header | |
1879 | cbICVlen = 8;//MIC | |
5a5d6a80 | 1880 | cbMICHDR = sizeof(struct vnt_mic_hdr); |
92b96797 | 1881 | pTxBufHead->wFragCtl |= FRAGCTL_AES; |
92b96797 FB |
1882 | } |
1883 | //MAC Header should be padding 0 to DW alignment. | |
1884 | uPadding = 4 - (cbMacHdLen%4); | |
1885 | uPadding %= 4; | |
1886 | } | |
1887 | ||
1888 | cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate; | |
1889 | ||
1890 | //Set FIFOCTL_GrpAckPolicy | |
4e9b5e2b | 1891 | if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000 |
92b96797 FB |
1892 | pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; |
1893 | } | |
1894 | //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter() | |
1895 | ||
92b96797 | 1896 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet |
4f990057 | 1897 | cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR + |
78363fd1 | 1898 | sizeof(struct vnt_cts); |
92b96797 FB |
1899 | |
1900 | } | |
1901 | else {//802.11a/b packet | |
976467d3 | 1902 | cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR + |
558becf1 | 1903 | sizeof(struct vnt_tx_datahead_ab); |
92b96797 | 1904 | } |
ceb8c5da | 1905 | memcpy(&(sEthHeader.h_dest[0]), |
9a0e756c AM |
1906 | &(p80211Header->sA3.abyAddr1[0]), |
1907 | ETH_ALEN); | |
ceb8c5da | 1908 | memcpy(&(sEthHeader.h_source[0]), |
9a0e756c AM |
1909 | &(p80211Header->sA3.abyAddr2[0]), |
1910 | ETH_ALEN); | |
92b96797 FB |
1911 | //========================= |
1912 | // No Fragmentation | |
1913 | //========================= | |
3eaca0d2 | 1914 | pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG; |
92b96797 | 1915 | |
351c7dc3 | 1916 | /* Fill FIFO,RrvTime,RTS,and CTS */ |
78363fd1 | 1917 | uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, |
fa57560c | 1918 | pTX_Buffer, &pMICHDR, cbMICHDR, |
f46142b0 | 1919 | cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false); |
92b96797 | 1920 | |
c545e6a6 | 1921 | pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize); |
92b96797 FB |
1922 | |
1923 | cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate; | |
1924 | ||
b902fbfe AM |
1925 | pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize); |
1926 | pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen); | |
1927 | pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding); | |
92b96797 FB |
1928 | |
1929 | // Copy the Packet into a tx Buffer | |
1930 | memcpy(pbyMacHdr, skb->data, cbMacHdLen); | |
1931 | ||
1932 | // version set to 0, patch for hostapd deamon | |
1cac4a4b | 1933 | pMACHeader->frame_control &= cpu_to_le16(0xfffc); |
92b96797 FB |
1934 | memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize); |
1935 | ||
a0a1f61a | 1936 | // replace support rate, patch for hostapd daemon( only support 11M) |
92b96797 FB |
1937 | if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) { |
1938 | if (cbExtSuppRate != 0) { | |
1939 | if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) | |
1940 | memcpy((pbyPayloadHead + cbFrameBodySize), | |
1941 | pMgmt->abyCurrSuppRates, | |
1942 | ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN | |
1943 | ); | |
1944 | if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) | |
1945 | memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN, | |
1946 | pMgmt->abyCurrExtSuppRates, | |
1947 | ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN | |
1948 | ); | |
1949 | } | |
1950 | } | |
1951 | ||
1952 | // Set wep | |
1953 | if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) { | |
1954 | ||
1955 | if (pDevice->bEnableHostWEP) { | |
1956 | pTransmitKey = &STempKey; | |
1957 | pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite; | |
1958 | pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex; | |
1959 | pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength; | |
1960 | pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16; | |
1961 | pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0; | |
1962 | memcpy(pTransmitKey->abyKey, | |
1963 | &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0], | |
1964 | pTransmitKey->uKeyLength | |
1965 | ); | |
1966 | } | |
1967 | ||
1968 | if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) { | |
1969 | ||
52a7e64b AM |
1970 | dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]); |
1971 | dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]); | |
92b96797 FB |
1972 | |
1973 | // DO Software Michael | |
1974 | MIC_vInit(dwMICKey0, dwMICKey1); | |
ceb8c5da | 1975 | MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12); |
92b96797 | 1976 | dwMIC_Priority = 0; |
b902fbfe | 1977 | MIC_vAppend((u8 *)&dwMIC_Priority, 4); |
b4dc03af MP |
1978 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\ |
1979 | " %X, %X\n", dwMICKey0, dwMICKey1); | |
92b96797 FB |
1980 | |
1981 | uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen; | |
1982 | ||
1983 | MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize); | |
1984 | ||
52a7e64b AM |
1985 | pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize); |
1986 | pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4); | |
92b96797 FB |
1987 | |
1988 | MIC_vGetMIC(pdwMIC_L, pdwMIC_R); | |
1989 | MIC_vUnInit(); | |
1990 | ||
4e9b5e2b | 1991 | if (pDevice->bTxMICFail == true) { |
92b96797 FB |
1992 | *pdwMIC_L = 0; |
1993 | *pdwMIC_R = 0; | |
e269fc2d | 1994 | pDevice->bTxMICFail = false; |
92b96797 FB |
1995 | } |
1996 | ||
1997 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize); | |
1998 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen); | |
b4dc03af MP |
1999 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n", |
2000 | *pdwMIC_L, *pdwMIC_R); | |
92b96797 FB |
2001 | |
2002 | } | |
2003 | ||
3ba0938c | 2004 | s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey, |
ec37d8b6 | 2005 | pbyMacHdr, (u16)cbFrameBodySize, pMICHDR); |
92b96797 FB |
2006 | |
2007 | if (pDevice->bEnableHostWEP) { | |
2008 | pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16; | |
2009 | pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0; | |
2010 | } | |
2011 | ||
2012 | if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) { | |
3eaca0d2 | 2013 | s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen)); |
92b96797 FB |
2014 | } |
2015 | } | |
2016 | ||
1cac4a4b | 2017 | pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4); |
92b96797 FB |
2018 | pDevice->wSeqCounter++ ; |
2019 | if (pDevice->wSeqCounter > 0x0fff) | |
2020 | pDevice->wSeqCounter = 0; | |
2021 | ||
92b96797 FB |
2022 | if (bIsPSPOLL) { |
2023 | // The MAC will automatically replace the Duration-field of MAC header by Duration-field | |
2024 | // of FIFO control header. | |
2025 | // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is | |
2026 | // in the same place of other packet's Duration-field). | |
2027 | // And it will cause Cisco-AP to issue Disassociation-packet | |
7e60a3de | 2028 | if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) { |
78363fd1 MP |
2029 | struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head. |
2030 | tx_cts.tx.head.cts_g.data_head; | |
2031 | data_head->wDuration_a = | |
7e60a3de | 2032 | cpu_to_le16(p80211Header->sA2.wDurationID); |
78363fd1 | 2033 | data_head->wDuration_b = |
7e60a3de MP |
2034 | cpu_to_le16(p80211Header->sA2.wDurationID); |
2035 | } else { | |
c12dca09 MP |
2036 | struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head. |
2037 | tx_ab.tx.head.data_head_ab; | |
2038 | data_head->wDuration = | |
558becf1 MP |
2039 | cpu_to_le16(p80211Header->sA2.wDurationID); |
2040 | } | |
92b96797 FB |
2041 | } |
2042 | ||
3eaca0d2 | 2043 | pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount)); |
b902fbfe | 2044 | pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
92b96797 FB |
2045 | pTX_Buffer->byType = 0x00; |
2046 | ||
2047 | pContext->pPacket = skb; | |
2048 | pContext->Type = CONTEXT_MGMT_PACKET; | |
3eaca0d2 | 2049 | pContext->uBufLen = (u16)cbReqCount + 4; //USB header |
92b96797 | 2050 | |
1cac4a4b | 2051 | if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) { |
d66caada MP |
2052 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
2053 | &pMACHeader->addr1[0], (u16)cbFrameSize, | |
2054 | pTxBufHead->wFIFOCtl); | |
92b96797 FB |
2055 | } |
2056 | else { | |
d66caada MP |
2057 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
2058 | &pMACHeader->addr3[0], (u16)cbFrameSize, | |
2059 | pTxBufHead->wFIFOCtl); | |
92b96797 FB |
2060 | } |
2061 | PIPEnsSendBulkOut(pDevice,pContext); | |
2062 | return ; | |
2063 | ||
2064 | } | |
2065 | ||
92b96797 FB |
2066 | //TYPE_AC0DMA data tx |
2067 | /* | |
2068 | * Description: | |
2069 | * Tx packet via AC0DMA(DMA1) | |
2070 | * | |
2071 | * Parameters: | |
2072 | * In: | |
2073 | * pDevice - Pointer to the adapter | |
2074 | * skb - Pointer to tx skb packet | |
2075 | * Out: | |
2076 | * void | |
2077 | * | |
2078 | * Return Value: NULL | |
2079 | */ | |
2080 | ||
d56131de MP |
2081 | int nsDMA_tx_packet(struct vnt_private *pDevice, |
2082 | u32 uDMAIdx, struct sk_buff *skb) | |
92b96797 | 2083 | { |
d56131de MP |
2084 | struct net_device_stats *pStats = &pDevice->stats; |
2085 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; | |
f39c0d8e | 2086 | struct vnt_tx_buffer *pTX_Buffer; |
d56131de MP |
2087 | u32 BytesToWrite = 0, uHeaderLen = 0; |
2088 | u32 uNodeIndex = 0; | |
2089 | u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; | |
2090 | u16 wAID; | |
2091 | u8 byPktType; | |
e269fc2d | 2092 | int bNeedEncryption = false; |
d56131de MP |
2093 | PSKeyItem pTransmitKey = NULL; |
2094 | SKeyItem STempKey; | |
2095 | int ii; | |
e269fc2d AM |
2096 | int bTKIP_UseGTK = false; |
2097 | int bNeedDeAuth = false; | |
d56131de | 2098 | u8 *pbyBSSID; |
e269fc2d | 2099 | int bNodeExist = false; |
dcdf1d03 | 2100 | struct vnt_usb_send_context *pContext; |
dfdcc425 | 2101 | bool fConvertedPacket; |
d56131de MP |
2102 | u32 status; |
2103 | u16 wKeepRate = pDevice->wCurrentRate; | |
e269fc2d | 2104 | int bTxeapol_key = false; |
92b96797 | 2105 | |
92b96797 FB |
2106 | if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { |
2107 | ||
2108 | if (pDevice->uAssocCount == 0) { | |
2109 | dev_kfree_skb_irq(skb); | |
2110 | return 0; | |
2111 | } | |
2112 | ||
b902fbfe | 2113 | if (is_multicast_ether_addr((u8 *)(skb->data))) { |
92b96797 | 2114 | uNodeIndex = 0; |
4e9b5e2b | 2115 | bNodeExist = true; |
92b96797 FB |
2116 | if (pMgmt->sNodeDBTable[0].bPSEnable) { |
2117 | ||
2118 | skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb); | |
2119 | pMgmt->sNodeDBTable[0].wEnQueueCnt++; | |
2120 | // set tx map | |
2121 | pMgmt->abyPSTxMap[0] |= byMask[0]; | |
2122 | return 0; | |
2123 | } | |
93184690 | 2124 | // multicast/broadcast data rate |
92b96797 FB |
2125 | |
2126 | if (pDevice->byBBType != BB_TYPE_11A) | |
2127 | pDevice->wCurrentRate = RATE_2M; | |
2128 | else | |
2129 | pDevice->wCurrentRate = RATE_24M; | |
2130 | // long preamble type | |
2131 | pDevice->byPreambleType = PREAMBLE_SHORT; | |
2132 | ||
2133 | }else { | |
2134 | ||
b902fbfe | 2135 | if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) { |
92b96797 FB |
2136 | |
2137 | if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) { | |
2138 | ||
2139 | skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb); | |
2140 | ||
2141 | pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++; | |
2142 | // set tx map | |
2143 | wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID; | |
2144 | pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7]; | |
2145 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n", | |
2146 | (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]); | |
2147 | ||
2148 | return 0; | |
2149 | } | |
2150 | // AP rate decided from node | |
2151 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate; | |
2152 | // tx preamble decided from node | |
2153 | ||
2154 | if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) { | |
2155 | pDevice->byPreambleType = pDevice->byShortPreamble; | |
2156 | ||
2157 | }else { | |
2158 | pDevice->byPreambleType = PREAMBLE_LONG; | |
2159 | } | |
4e9b5e2b | 2160 | bNodeExist = true; |
92b96797 FB |
2161 | } |
2162 | } | |
2163 | ||
e269fc2d | 2164 | if (bNodeExist == false) { |
92b96797 FB |
2165 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n"); |
2166 | dev_kfree_skb_irq(skb); | |
2167 | return 0; | |
2168 | } | |
2169 | } | |
2170 | ||
aceaf018 | 2171 | pContext = s_vGetFreeContext(pDevice); |
92b96797 FB |
2172 | |
2173 | if (pContext == NULL) { | |
2174 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n"); | |
2175 | dev_kfree_skb_irq(skb); | |
2176 | return STATUS_RESOURCES; | |
2177 | } | |
2178 | ||
ceb8c5da | 2179 | memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN); |
92b96797 FB |
2180 | |
2181 | //mike add:station mode check eapol-key challenge---> | |
2182 | { | |
b902fbfe AM |
2183 | u8 Protocol_Version; //802.1x Authentication |
2184 | u8 Packet_Type; //802.1x Authentication | |
2185 | u8 Descriptor_type; | |
3eaca0d2 | 2186 | u16 Key_info; |
92b96797 | 2187 | |
21ec51f3 CC |
2188 | Protocol_Version = skb->data[ETH_HLEN]; |
2189 | Packet_Type = skb->data[ETH_HLEN+1]; | |
2190 | Descriptor_type = skb->data[ETH_HLEN+1+1+2]; | |
2191 | Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]); | |
ceb8c5da | 2192 | if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) { |
aa209eef MP |
2193 | /* 802.1x OR eapol-key challenge frame transfer */ |
2194 | if (((Protocol_Version == 1) || (Protocol_Version == 2)) && | |
2195 | (Packet_Type == 3)) { | |
4e9b5e2b | 2196 | bTxeapol_key = true; |
92b96797 FB |
2197 | if(!(Key_info & BIT3) && //WPA or RSN group-key challenge |
2198 | (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key | |
2199 | if(Descriptor_type==254) { | |
4e9b5e2b | 2200 | pDevice->fWPA_Authened = true; |
92b96797 FB |
2201 | PRINT_K("WPA "); |
2202 | } | |
2203 | else { | |
4e9b5e2b | 2204 | pDevice->fWPA_Authened = true; |
92b96797 FB |
2205 | PRINT_K("WPA2(re-keying) "); |
2206 | } | |
2207 | PRINT_K("Authentication completed!!\n"); | |
2208 | } | |
a0a1f61a | 2209 | else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge |
92b96797 | 2210 | (Key_info & BIT8) && (Key_info & BIT9)) { |
4e9b5e2b | 2211 | pDevice->fWPA_Authened = true; |
92b96797 FB |
2212 | PRINT_K("WPA2 Authentication completed!!\n"); |
2213 | } | |
2214 | } | |
2215 | } | |
2216 | } | |
2217 | //mike add:station mode check eapol-key challenge<--- | |
2218 | ||
4e9b5e2b AM |
2219 | if (pDevice->bEncryptionEnable == true) { |
2220 | bNeedEncryption = true; | |
92b96797 FB |
2221 | // get Transmit key |
2222 | do { | |
2223 | if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && | |
2224 | (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { | |
2225 | pbyBSSID = pDevice->abyBSSID; | |
2226 | // get pairwise key | |
e269fc2d | 2227 | if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { |
92b96797 | 2228 | // get group key |
4e9b5e2b AM |
2229 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) { |
2230 | bTKIP_UseGTK = true; | |
92b96797 FB |
2231 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); |
2232 | break; | |
2233 | } | |
2234 | } else { | |
2235 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n"); | |
2236 | break; | |
2237 | } | |
2238 | }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { | |
ceb8c5da AM |
2239 | /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */ |
2240 | pbyBSSID = pDevice->sTxEthHeader.h_dest; | |
92b96797 FB |
2241 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n"); |
2242 | for (ii = 0; ii< 6; ii++) | |
2243 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii)); | |
2244 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n"); | |
2245 | ||
2246 | // get pairwise key | |
4e9b5e2b | 2247 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) |
92b96797 FB |
2248 | break; |
2249 | } | |
2250 | // get group key | |
2251 | pbyBSSID = pDevice->abyBroadcastAddr; | |
e269fc2d | 2252 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { |
92b96797 FB |
2253 | pTransmitKey = NULL; |
2254 | if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { | |
2255 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode); | |
2256 | } | |
2257 | else | |
2258 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode); | |
2259 | } else { | |
4e9b5e2b | 2260 | bTKIP_UseGTK = true; |
92b96797 FB |
2261 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); |
2262 | } | |
e269fc2d | 2263 | } while(false); |
92b96797 FB |
2264 | } |
2265 | ||
2266 | if (pDevice->bEnableHostWEP) { | |
2267 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex); | |
4e9b5e2b | 2268 | if (pDevice->bEncryptionEnable == true) { |
92b96797 FB |
2269 | pTransmitKey = &STempKey; |
2270 | pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite; | |
2271 | pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex; | |
2272 | pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength; | |
2273 | pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16; | |
2274 | pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0; | |
2275 | memcpy(pTransmitKey->abyKey, | |
2276 | &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0], | |
2277 | pTransmitKey->uKeyLength | |
2278 | ); | |
2279 | } | |
2280 | } | |
2281 | ||
b902fbfe | 2282 | byPktType = (u8)pDevice->byPacketType; |
92b96797 FB |
2283 | |
2284 | if (pDevice->bFixRate) { | |
2285 | if (pDevice->byBBType == BB_TYPE_11B) { | |
2286 | if (pDevice->uConnectionRate >= RATE_11M) { | |
2287 | pDevice->wCurrentRate = RATE_11M; | |
2288 | } else { | |
3eaca0d2 | 2289 | pDevice->wCurrentRate = (u16)pDevice->uConnectionRate; |
92b96797 FB |
2290 | } |
2291 | } else { | |
2292 | if ((pDevice->byBBType == BB_TYPE_11A) && | |
2293 | (pDevice->uConnectionRate <= RATE_6M)) { | |
2294 | pDevice->wCurrentRate = RATE_6M; | |
2295 | } else { | |
2296 | if (pDevice->uConnectionRate >= RATE_54M) | |
2297 | pDevice->wCurrentRate = RATE_54M; | |
2298 | else | |
3eaca0d2 | 2299 | pDevice->wCurrentRate = (u16)pDevice->uConnectionRate; |
92b96797 FB |
2300 | } |
2301 | } | |
2302 | } | |
2303 | else { | |
2304 | if (pDevice->eOPMode == OP_MODE_ADHOC) { | |
2305 | // Adhoc Tx rate decided from node DB | |
ceb8c5da | 2306 | if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) { |
92b96797 FB |
2307 | // Multicast use highest data rate |
2308 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate; | |
2309 | // preamble type | |
2310 | pDevice->byPreambleType = pDevice->byShortPreamble; | |
2311 | } | |
2312 | else { | |
ceb8c5da | 2313 | if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) { |
92b96797 FB |
2314 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate; |
2315 | if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) { | |
2316 | pDevice->byPreambleType = pDevice->byShortPreamble; | |
2317 | ||
2318 | } | |
2319 | else { | |
2320 | pDevice->byPreambleType = PREAMBLE_LONG; | |
2321 | } | |
2322 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate); | |
2323 | } | |
2324 | else { | |
2325 | if (pDevice->byBBType != BB_TYPE_11A) | |
2326 | pDevice->wCurrentRate = RATE_2M; | |
2327 | else | |
2328 | pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s | |
2329 | // abyCurrExtSuppRates[] | |
2330 | pDevice->byPreambleType = PREAMBLE_SHORT; | |
2331 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n"); | |
2332 | } | |
2333 | } | |
2334 | } | |
2335 | if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) { | |
2336 | // Infra STA rate decided from AP Node, index = 0 | |
2337 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate; | |
2338 | } | |
2339 | } | |
2340 | ||
ceb8c5da | 2341 | if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) { |
aa209eef MP |
2342 | if (pDevice->byBBType != BB_TYPE_11A) { |
2343 | pDevice->wCurrentRate = RATE_1M; | |
2344 | pDevice->byACKRate = RATE_1M; | |
2345 | pDevice->byTopCCKBasicRate = RATE_1M; | |
2346 | pDevice->byTopOFDMBasicRate = RATE_6M; | |
2347 | } else { | |
2348 | pDevice->wCurrentRate = RATE_6M; | |
2349 | pDevice->byACKRate = RATE_6M; | |
2350 | pDevice->byTopCCKBasicRate = RATE_1M; | |
2351 | pDevice->byTopOFDMBasicRate = RATE_6M; | |
2352 | } | |
2353 | } | |
92b96797 | 2354 | |
0cbd8d98 AM |
2355 | DBG_PRT(MSG_LEVEL_DEBUG, |
2356 | KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n", | |
2357 | pDevice->wCurrentRate); | |
92b96797 FB |
2358 | |
2359 | if (wKeepRate != pDevice->wCurrentRate) { | |
0cbd8d98 | 2360 | bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL); |
92b96797 FB |
2361 | } |
2362 | ||
2363 | if (pDevice->wCurrentRate <= RATE_11M) { | |
2364 | byPktType = PK_TYPE_11B; | |
2365 | } | |
2366 | ||
4e9b5e2b | 2367 | if (bNeedEncryption == true) { |
ceb8c5da AM |
2368 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto)); |
2369 | if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) { | |
e269fc2d | 2370 | bNeedEncryption = false; |
ceb8c5da | 2371 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto)); |
92b96797 FB |
2372 | if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { |
2373 | if (pTransmitKey == NULL) { | |
2374 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n"); | |
2375 | } | |
2376 | else { | |
4e9b5e2b | 2377 | if (bTKIP_UseGTK == true) { |
92b96797 FB |
2378 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n"); |
2379 | } | |
2380 | else { | |
b4dc03af MP |
2381 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n", |
2382 | pTransmitKey->dwKeyIndex); | |
4e9b5e2b | 2383 | bNeedEncryption = true; |
92b96797 FB |
2384 | } |
2385 | } | |
2386 | } | |
2387 | ||
92b96797 FB |
2388 | if (pDevice->bEnableHostWEP) { |
2389 | if ((uNodeIndex != 0) && | |
2390 | (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) { | |
b4dc03af MP |
2391 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n", |
2392 | pTransmitKey->dwKeyIndex); | |
4e9b5e2b | 2393 | bNeedEncryption = true; |
92b96797 FB |
2394 | } |
2395 | } | |
2396 | } | |
2397 | else { | |
2398 | ||
92b96797 FB |
2399 | if (pTransmitKey == NULL) { |
2400 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n"); | |
e269fc2d | 2401 | pContext->bBoolInUse = false; |
92b96797 FB |
2402 | dev_kfree_skb_irq(skb); |
2403 | pStats->tx_dropped++; | |
2404 | return STATUS_FAILURE; | |
2405 | } | |
92b96797 FB |
2406 | } |
2407 | } | |
2408 | ||
d0a2b8fa MP |
2409 | pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0]; |
2410 | ||
92b96797 | 2411 | fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType, |
d0a2b8fa | 2412 | pTX_Buffer, bNeedEncryption, |
92b96797 | 2413 | skb->len, uDMAIdx, &pDevice->sTxEthHeader, |
b902fbfe | 2414 | (u8 *)skb->data, pTransmitKey, uNodeIndex, |
92b96797 FB |
2415 | pDevice->wCurrentRate, |
2416 | &uHeaderLen, &BytesToWrite | |
2417 | ); | |
2418 | ||
e269fc2d AM |
2419 | if (fConvertedPacket == false) { |
2420 | pContext->bBoolInUse = false; | |
92b96797 FB |
2421 | dev_kfree_skb_irq(skb); |
2422 | return STATUS_FAILURE; | |
2423 | } | |
2424 | ||
4e9b5e2b | 2425 | if ( pDevice->bEnablePSMode == true ) { |
92b96797 | 2426 | if ( !pDevice->bPSModeTxBurst ) { |
0cbd8d98 AM |
2427 | bScheduleCommand((void *) pDevice, |
2428 | WLAN_CMD_MAC_DISPOWERSAVING, | |
2429 | NULL); | |
4e9b5e2b | 2430 | pDevice->bPSModeTxBurst = true; |
92b96797 FB |
2431 | } |
2432 | } | |
2433 | ||
b902fbfe | 2434 | pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
3eaca0d2 | 2435 | pTX_Buffer->wTxByteCount = (u16)BytesToWrite; |
92b96797 FB |
2436 | |
2437 | pContext->pPacket = skb; | |
2438 | pContext->Type = CONTEXT_DATA_PACKET; | |
3eaca0d2 | 2439 | pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header |
92b96797 | 2440 | |
d66caada MP |
2441 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
2442 | &pContext->sEthHeader.h_dest[0], | |
2443 | (u16)(BytesToWrite-uHeaderLen), | |
2444 | pTX_Buffer->fifo_head.wFIFOCtl); | |
92b96797 FB |
2445 | |
2446 | status = PIPEnsSendBulkOut(pDevice,pContext); | |
2447 | ||
4e9b5e2b | 2448 | if (bNeedDeAuth == true) { |
3eaca0d2 | 2449 | u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE; |
92b96797 | 2450 | |
b902fbfe | 2451 | bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason); |
92b96797 FB |
2452 | } |
2453 | ||
2454 | if(status!=STATUS_PENDING) { | |
e269fc2d | 2455 | pContext->bBoolInUse = false; |
92b96797 FB |
2456 | dev_kfree_skb_irq(skb); |
2457 | return STATUS_FAILURE; | |
2458 | } | |
2459 | else | |
2460 | return 0; | |
2461 | ||
2462 | } | |
2463 | ||
92b96797 FB |
2464 | /* |
2465 | * Description: | |
2466 | * Relay packet send (AC1DMA) from rx dpc. | |
2467 | * | |
2468 | * Parameters: | |
2469 | * In: | |
2470 | * pDevice - Pointer to the adapter | |
2471 | * pPacket - Pointer to rx packet | |
2472 | * cbPacketSize - rx ethernet frame size | |
2473 | * Out: | |
e269fc2d | 2474 | * TURE, false |
92b96797 | 2475 | * |
4e9b5e2b | 2476 | * Return Value: Return true if packet is copy to dma1; otherwise false |
92b96797 FB |
2477 | */ |
2478 | ||
d56131de MP |
2479 | int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen, |
2480 | u32 uNodeIndex) | |
92b96797 | 2481 | { |
d56131de | 2482 | struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; |
f39c0d8e | 2483 | struct vnt_tx_buffer *pTX_Buffer; |
d56131de MP |
2484 | u32 BytesToWrite = 0, uHeaderLen = 0; |
2485 | u8 byPktType = PK_TYPE_11B; | |
e269fc2d | 2486 | int bNeedEncryption = false; |
d56131de MP |
2487 | SKeyItem STempKey; |
2488 | PSKeyItem pTransmitKey = NULL; | |
2489 | u8 *pbyBSSID; | |
dcdf1d03 | 2490 | struct vnt_usb_send_context *pContext; |
d56131de MP |
2491 | u8 byPktTyp; |
2492 | int fConvertedPacket; | |
d56131de MP |
2493 | u32 status; |
2494 | u16 wKeepRate = pDevice->wCurrentRate; | |
92b96797 | 2495 | |
aceaf018 | 2496 | pContext = s_vGetFreeContext(pDevice); |
92b96797 FB |
2497 | |
2498 | if (NULL == pContext) { | |
e269fc2d | 2499 | return false; |
92b96797 FB |
2500 | } |
2501 | ||
ceb8c5da | 2502 | memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN); |
92b96797 | 2503 | |
4e9b5e2b AM |
2504 | if (pDevice->bEncryptionEnable == true) { |
2505 | bNeedEncryption = true; | |
92b96797 FB |
2506 | // get group key |
2507 | pbyBSSID = pDevice->abyBroadcastAddr; | |
e269fc2d | 2508 | if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { |
92b96797 FB |
2509 | pTransmitKey = NULL; |
2510 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode); | |
2511 | } else { | |
2512 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); | |
2513 | } | |
2514 | } | |
2515 | ||
2516 | if (pDevice->bEnableHostWEP) { | |
ee93e197 | 2517 | if (uNodeIndex < MAX_NODE_NUM + 1) { |
92b96797 FB |
2518 | pTransmitKey = &STempKey; |
2519 | pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite; | |
2520 | pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex; | |
2521 | pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength; | |
2522 | pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16; | |
2523 | pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0; | |
2524 | memcpy(pTransmitKey->abyKey, | |
2525 | &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0], | |
2526 | pTransmitKey->uKeyLength | |
2527 | ); | |
2528 | } | |
2529 | } | |
2530 | ||
2531 | if ( bNeedEncryption && (pTransmitKey == NULL) ) { | |
e269fc2d AM |
2532 | pContext->bBoolInUse = false; |
2533 | return false; | |
92b96797 FB |
2534 | } |
2535 | ||
b902fbfe | 2536 | byPktTyp = (u8)pDevice->byPacketType; |
92b96797 FB |
2537 | |
2538 | if (pDevice->bFixRate) { | |
2539 | if (pDevice->byBBType == BB_TYPE_11B) { | |
2540 | if (pDevice->uConnectionRate >= RATE_11M) { | |
2541 | pDevice->wCurrentRate = RATE_11M; | |
2542 | } else { | |
3eaca0d2 | 2543 | pDevice->wCurrentRate = (u16)pDevice->uConnectionRate; |
92b96797 FB |
2544 | } |
2545 | } else { | |
2546 | if ((pDevice->byBBType == BB_TYPE_11A) && | |
2547 | (pDevice->uConnectionRate <= RATE_6M)) { | |
2548 | pDevice->wCurrentRate = RATE_6M; | |
2549 | } else { | |
2550 | if (pDevice->uConnectionRate >= RATE_54M) | |
2551 | pDevice->wCurrentRate = RATE_54M; | |
2552 | else | |
3eaca0d2 | 2553 | pDevice->wCurrentRate = (u16)pDevice->uConnectionRate; |
92b96797 FB |
2554 | } |
2555 | } | |
2556 | } | |
2557 | else { | |
2558 | pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate; | |
2559 | } | |
2560 | ||
92b96797 | 2561 | if (wKeepRate != pDevice->wCurrentRate) { |
0cbd8d98 | 2562 | bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL); |
92b96797 FB |
2563 | } |
2564 | ||
2565 | if (pDevice->wCurrentRate <= RATE_11M) | |
2566 | byPktType = PK_TYPE_11B; | |
2567 | ||
abad19d0 AM |
2568 | BytesToWrite = uDataLen + ETH_FCS_LEN; |
2569 | ||
92b96797 FB |
2570 | // Convert the packet to an usb frame and copy into our buffer |
2571 | // and send the irp. | |
2572 | ||
d0a2b8fa MP |
2573 | pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0]; |
2574 | ||
92b96797 | 2575 | fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType, |
d0a2b8fa | 2576 | pTX_Buffer, bNeedEncryption, |
92b96797 FB |
2577 | uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader, |
2578 | pbySkbData, pTransmitKey, uNodeIndex, | |
2579 | pDevice->wCurrentRate, | |
2580 | &uHeaderLen, &BytesToWrite | |
2581 | ); | |
2582 | ||
e269fc2d AM |
2583 | if (fConvertedPacket == false) { |
2584 | pContext->bBoolInUse = false; | |
2585 | return false; | |
92b96797 FB |
2586 | } |
2587 | ||
b902fbfe | 2588 | pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F)); |
3eaca0d2 | 2589 | pTX_Buffer->wTxByteCount = (u16)BytesToWrite; |
92b96797 FB |
2590 | |
2591 | pContext->pPacket = NULL; | |
2592 | pContext->Type = CONTEXT_DATA_PACKET; | |
3eaca0d2 | 2593 | pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header |
92b96797 | 2594 | |
d66caada MP |
2595 | s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F), |
2596 | &pContext->sEthHeader.h_dest[0], | |
2597 | (u16)(BytesToWrite - uHeaderLen), | |
2598 | pTX_Buffer->fifo_head.wFIFOCtl); | |
92b96797 FB |
2599 | |
2600 | status = PIPEnsSendBulkOut(pDevice,pContext); | |
2601 | ||
4e9b5e2b | 2602 | return true; |
92b96797 FB |
2603 | } |
2604 |