]>
Commit | Line | Data |
---|---|---|
91980990 GKH |
1 | /* |
2 | ************************************************************************* | |
3 | * Ralink Tech Inc. | |
4 | * 5F., No.36, Taiyuan St., Jhubei City, | |
5 | * Hsinchu County 302, | |
6 | * Taiwan, R.O.C. | |
7 | * | |
8 | * (c) Copyright 2002-2007, Ralink Technology, Inc. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify * | |
11 | * it under the terms of the GNU General Public License as published by * | |
12 | * the Free Software Foundation; either version 2 of the License, or * | |
13 | * (at your option) any later version. * | |
14 | * * | |
15 | * This program is distributed in the hope that it will be useful, * | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
18 | * GNU General Public License for more details. * | |
19 | * * | |
20 | * You should have received a copy of the GNU General Public License * | |
21 | * along with this program; if not, write to the * | |
22 | * Free Software Foundation, Inc., * | |
23 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
24 | * * | |
25 | ************************************************************************* | |
26 | ||
27 | Module Name: | |
28 | rtmp_data.c | |
29 | ||
30 | Abstract: | |
31 | Data path subroutines | |
32 | ||
33 | Revision History: | |
34 | Who When What | |
35 | -------- ---------- ---------------------------------------------- | |
91980990 GKH |
36 | */ |
37 | #include "../rt_config.h" | |
38 | ||
39 | ||
40 | ||
41 | VOID STARxEAPOLFrameIndicate( | |
42 | IN PRTMP_ADAPTER pAd, | |
43 | IN MAC_TABLE_ENTRY *pEntry, | |
44 | IN RX_BLK *pRxBlk, | |
45 | IN UCHAR FromWhichBSSID) | |
46 | { | |
47 | PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD); | |
48 | PRXWI_STRUC pRxWI = pRxBlk->pRxWI; | |
49 | UCHAR *pTmpBuf; | |
50 | ||
91980990 GKH |
51 | if (pAd->StaCfg.WpaSupplicantUP) |
52 | { | |
53 | // All EAPoL frames have to pass to upper layer (ex. WPA_SUPPLICANT daemon) | |
54 | // TBD : process fragmented EAPol frames | |
55 | { | |
56 | // In 802.1x mode, if the received frame is EAP-SUCCESS packet, turn on the PortSecured variable | |
57 | if ( pAd->StaCfg.IEEE8021X == TRUE && | |
58 | (EAP_CODE_SUCCESS == WpaCheckEapCode(pAd, pRxBlk->pData, pRxBlk->DataSize, LENGTH_802_1_H))) | |
59 | { | |
60 | PUCHAR Key; | |
61 | UCHAR CipherAlg; | |
62 | int idx = 0; | |
63 | ||
64 | DBGPRINT_RAW(RT_DEBUG_TRACE, ("Receive EAP-SUCCESS Packet\n")); | |
ca97b838 | 65 | //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; |
91980990 GKH |
66 | STA_PORT_SECURED(pAd); |
67 | ||
68 | if (pAd->StaCfg.IEEE8021x_required_keys == FALSE) | |
69 | { | |
70 | idx = pAd->StaCfg.DesireSharedKeyId; | |
71 | CipherAlg = pAd->StaCfg.DesireSharedKey[idx].CipherAlg; | |
72 | Key = pAd->StaCfg.DesireSharedKey[idx].Key; | |
73 | ||
74 | if (pAd->StaCfg.DesireSharedKey[idx].KeyLen > 0) | |
75 | { | |
ca97b838 | 76 | #ifdef RTMP_MAC_PCI |
91980990 GKH |
77 | MAC_TABLE_ENTRY *pEntry = &pAd->MacTab.Content[BSSID_WCID]; |
78 | ||
79 | // Set key material and cipherAlg to Asic | |
80 | AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL); | |
81 | ||
82 | // Assign group key info | |
83 | RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL); | |
84 | ||
85 | // Assign pairwise key info | |
86 | RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, pEntry); | |
87 | ||
88 | pAd->IndicateMediaState = NdisMediaStateConnected; | |
89 | pAd->ExtraInfo = GENERAL_LINK_UP; | |
ca97b838 BZ |
90 | #endif // RTMP_MAC_PCI // |
91 | #ifdef RTMP_MAC_USB | |
5f5d2df8 BZ |
92 | union |
93 | { | |
94 | char buf[sizeof(NDIS_802_11_WEP)+MAX_LEN_OF_KEY- 1]; | |
95 | NDIS_802_11_WEP keyinfo; | |
96 | } WepKey; | |
97 | int len; | |
98 | ||
99 | ||
100 | NdisZeroMemory(&WepKey, sizeof(WepKey)); | |
101 | len =pAd->StaCfg.DesireSharedKey[idx].KeyLen; | |
102 | ||
103 | NdisMoveMemory(WepKey.keyinfo.KeyMaterial, | |
104 | pAd->StaCfg.DesireSharedKey[idx].Key, | |
105 | pAd->StaCfg.DesireSharedKey[idx].KeyLen); | |
106 | ||
107 | WepKey.keyinfo.KeyIndex = 0x80000000 + idx; | |
108 | WepKey.keyinfo.KeyLength = len; | |
109 | pAd->SharedKey[BSS0][idx].KeyLen =(UCHAR) (len <= 5 ? 5 : 13); | |
110 | ||
111 | pAd->IndicateMediaState = NdisMediaStateConnected; | |
112 | pAd->ExtraInfo = GENERAL_LINK_UP; | |
113 | // need to enqueue cmd to thread | |
114 | RTUSBEnqueueCmdFromNdis(pAd, OID_802_11_ADD_WEP, TRUE, &WepKey, sizeof(WepKey.keyinfo) + len - 1); | |
ca97b838 | 115 | #endif // RTMP_MAC_USB // |
91980990 GKH |
116 | // For Preventing ShardKey Table is cleared by remove key procedure. |
117 | pAd->SharedKey[BSS0][idx].CipherAlg = CipherAlg; | |
118 | pAd->SharedKey[BSS0][idx].KeyLen = pAd->StaCfg.DesireSharedKey[idx].KeyLen; | |
119 | NdisMoveMemory(pAd->SharedKey[BSS0][idx].Key, | |
120 | pAd->StaCfg.DesireSharedKey[idx].Key, | |
121 | pAd->StaCfg.DesireSharedKey[idx].KeyLen); | |
122 | } | |
123 | } | |
124 | } | |
125 | ||
126 | Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID); | |
127 | return; | |
128 | } | |
129 | } | |
130 | else | |
91980990 GKH |
131 | { |
132 | // Special DATA frame that has to pass to MLME | |
133 | // 1. Cisco Aironet frames for CCX2. We need pass it to MLME for special process | |
134 | // 2. EAPOL handshaking frames when driver supplicant enabled, pass to MLME for special process | |
135 | { | |
136 | pTmpBuf = pRxBlk->pData - LENGTH_802_11; | |
137 | NdisMoveMemory(pTmpBuf, pRxBlk->pHeader, LENGTH_802_11); | |
138 | REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pTmpBuf, pRxBlk->DataSize + LENGTH_802_11, pRxWI->RSSI0, pRxWI->RSSI1, pRxWI->RSSI2, pRxD->PlcpSignal); | |
139 | DBGPRINT_RAW(RT_DEBUG_TRACE, ("!!! report EAPOL/AIRONET DATA to MLME (len=%d) !!!\n", pRxBlk->DataSize)); | |
140 | } | |
141 | } | |
142 | ||
143 | RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); | |
144 | return; | |
145 | ||
146 | } | |
147 | ||
148 | VOID STARxDataFrameAnnounce( | |
149 | IN PRTMP_ADAPTER pAd, | |
150 | IN MAC_TABLE_ENTRY *pEntry, | |
151 | IN RX_BLK *pRxBlk, | |
152 | IN UCHAR FromWhichBSSID) | |
153 | { | |
154 | ||
155 | // non-EAP frame | |
156 | if (!RTMPCheckWPAframe(pAd, pEntry, pRxBlk->pData, pRxBlk->DataSize, FromWhichBSSID)) | |
157 | { | |
ca97b838 | 158 | |
91980990 GKH |
159 | { |
160 | // drop all non-EAP DATA frame before | |
161 | // this client's Port-Access-Control is secured | |
162 | if (pRxBlk->pHeader->FC.Wep) | |
163 | { | |
164 | // unsupported cipher suite | |
165 | if (pAd->StaCfg.WepStatus == Ndis802_11EncryptionDisabled) | |
166 | { | |
167 | // release packet | |
168 | RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); | |
169 | return; | |
170 | } | |
171 | } | |
172 | else | |
173 | { | |
174 | // encryption in-use but receive a non-EAPOL clear text frame, drop it | |
175 | if ((pAd->StaCfg.WepStatus != Ndis802_11EncryptionDisabled) && | |
176 | (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)) | |
177 | { | |
178 | // release packet | |
179 | RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); | |
180 | return; | |
181 | } | |
182 | } | |
183 | } | |
184 | RX_BLK_CLEAR_FLAG(pRxBlk, fRX_EAP); | |
185 | if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_ARALINK)) | |
186 | { | |
187 | // Normal legacy, AMPDU or AMSDU | |
188 | CmmRxnonRalinkFrameIndicate(pAd, pRxBlk, FromWhichBSSID); | |
189 | ||
190 | } | |
191 | else | |
192 | { | |
193 | // ARALINK | |
194 | CmmRxRalinkFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID); | |
195 | } | |
91980990 GKH |
196 | } |
197 | else | |
198 | { | |
199 | RX_BLK_SET_FLAG(pRxBlk, fRX_EAP); | |
1623267a | 200 | |
91980990 GKH |
201 | if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU) && (pAd->CommonCfg.bDisableReordering == 0)) |
202 | { | |
203 | Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID); | |
204 | } | |
205 | else | |
91980990 GKH |
206 | { |
207 | // Determin the destination of the EAP frame | |
208 | // to WPA state machine or upper layer | |
209 | STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID); | |
210 | } | |
211 | } | |
212 | } | |
213 | ||
214 | ||
215 | // For TKIP frame, calculate the MIC value | |
216 | BOOLEAN STACheckTkipMICValue( | |
217 | IN PRTMP_ADAPTER pAd, | |
218 | IN MAC_TABLE_ENTRY *pEntry, | |
219 | IN RX_BLK *pRxBlk) | |
220 | { | |
221 | PHEADER_802_11 pHeader = pRxBlk->pHeader; | |
222 | UCHAR *pData = pRxBlk->pData; | |
223 | USHORT DataSize = pRxBlk->DataSize; | |
224 | UCHAR UserPriority = pRxBlk->UserPriority; | |
225 | PCIPHER_KEY pWpaKey; | |
226 | UCHAR *pDA, *pSA; | |
227 | ||
228 | pWpaKey = &pAd->SharedKey[BSS0][pRxBlk->pRxWI->KeyIndex]; | |
229 | ||
230 | pDA = pHeader->Addr1; | |
231 | if (RX_BLK_TEST_FLAG(pRxBlk, fRX_INFRA)) | |
232 | { | |
233 | pSA = pHeader->Addr3; | |
234 | } | |
235 | else | |
236 | { | |
237 | pSA = pHeader->Addr2; | |
238 | } | |
239 | ||
240 | if (RTMPTkipCompareMICValue(pAd, | |
241 | pData, | |
242 | pDA, | |
243 | pSA, | |
244 | pWpaKey->RxMic, | |
245 | UserPriority, | |
246 | DataSize) == FALSE) | |
247 | { | |
248 | DBGPRINT_RAW(RT_DEBUG_ERROR,("Rx MIC Value error 2\n")); | |
249 | ||
91980990 GKH |
250 | if (pAd->StaCfg.WpaSupplicantUP) |
251 | { | |
252 | WpaSendMicFailureToWpaSupplicant(pAd, (pWpaKey->Type == PAIRWISEKEY) ? TRUE : FALSE); | |
253 | } | |
254 | else | |
91980990 GKH |
255 | { |
256 | RTMPReportMicError(pAd, pWpaKey); | |
257 | } | |
258 | ||
259 | // release packet | |
260 | RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); | |
261 | return FALSE; | |
262 | } | |
263 | ||
264 | return TRUE; | |
265 | } | |
266 | ||
267 | ||
268 | // | |
269 | // All Rx routines use RX_BLK structure to hande rx events | |
270 | // It is very important to build pRxBlk attributes | |
271 | // 1. pHeader pointer to 802.11 Header | |
272 | // 2. pData pointer to payload including LLC (just skip Header) | |
273 | // 3. set payload size including LLC to DataSize | |
274 | // 4. set some flags with RX_BLK_SET_FLAG() | |
275 | // | |
276 | VOID STAHandleRxDataFrame( | |
277 | IN PRTMP_ADAPTER pAd, | |
278 | IN RX_BLK *pRxBlk) | |
279 | { | |
280 | PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD); | |
281 | PRXWI_STRUC pRxWI = pRxBlk->pRxWI; | |
282 | PHEADER_802_11 pHeader = pRxBlk->pHeader; | |
283 | PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket; | |
284 | BOOLEAN bFragment = FALSE; | |
285 | MAC_TABLE_ENTRY *pEntry = NULL; | |
286 | UCHAR FromWhichBSSID = BSS0; | |
287 | UCHAR UserPriority = 0; | |
288 | ||
289 | { | |
290 | // before LINK UP, all DATA frames are rejected | |
291 | if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) | |
292 | { | |
293 | // release packet | |
294 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
295 | return; | |
296 | } | |
297 | ||
91980990 GKH |
298 | // Drop not my BSS frames |
299 | if (pRxD->MyBss == 0) | |
300 | { | |
301 | { | |
302 | // release packet | |
303 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
304 | return; | |
305 | } | |
306 | } | |
307 | ||
308 | pAd->RalinkCounters.RxCountSinceLastNULL++; | |
309 | if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable && (pHeader->FC.SubType & 0x08)) | |
310 | { | |
311 | UCHAR *pData; | |
ca97b838 | 312 | DBGPRINT(RT_DEBUG_INFO,("bAPSDCapable\n")); |
91980990 GKH |
313 | |
314 | // Qos bit 4 | |
315 | pData = (PUCHAR)pHeader + LENGTH_802_11; | |
316 | if ((*pData >> 4) & 0x01) | |
317 | { | |
ca97b838 | 318 | DBGPRINT(RT_DEBUG_INFO,("RxDone- Rcv EOSP frame, driver may fall into sleep\n")); |
91980990 GKH |
319 | pAd->CommonCfg.bInServicePeriod = FALSE; |
320 | ||
321 | // Force driver to fall into sleep mode when rcv EOSP frame | |
322 | if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) | |
323 | { | |
324 | USHORT TbttNumToNextWakeUp; | |
325 | USHORT NextDtim = pAd->StaCfg.DtimPeriod; | |
326 | ULONG Now; | |
327 | ||
328 | NdisGetSystemUpTime(&Now); | |
329 | NextDtim -= (USHORT)(Now - pAd->StaCfg.LastBeaconRxTime)/pAd->CommonCfg.BeaconPeriod; | |
330 | ||
331 | TbttNumToNextWakeUp = pAd->StaCfg.DefaultListenCount; | |
332 | if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM) && (TbttNumToNextWakeUp > NextDtim)) | |
333 | TbttNumToNextWakeUp = NextDtim; | |
334 | ||
ca97b838 | 335 | RTMP_SET_PSM_BIT(pAd, PWR_SAVE); |
91980990 GKH |
336 | // if WMM-APSD is failed, try to disable following line |
337 | AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp); | |
338 | } | |
339 | } | |
340 | ||
341 | if ((pHeader->FC.MoreData) && (pAd->CommonCfg.bInServicePeriod)) | |
342 | { | |
343 | DBGPRINT(RT_DEBUG_TRACE,("Sending another trigger frame when More Data bit is set to 1\n")); | |
344 | } | |
345 | } | |
346 | ||
347 | // Drop NULL, CF-ACK(no data), CF-POLL(no data), and CF-ACK+CF-POLL(no data) data frame | |
348 | if ((pHeader->FC.SubType & 0x04)) // bit 2 : no DATA | |
349 | { | |
350 | // release packet | |
351 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
352 | return; | |
353 | } | |
354 | ||
355 | // Drop not my BSS frame (we can not only check the MyBss bit in RxD) | |
0aa7c8dd | 356 | |
91980990 GKH |
357 | if (INFRA_ON(pAd)) |
358 | { | |
359 | // Infrastructure mode, check address 2 for BSSID | |
360 | if (!RTMPEqualMemory(&pHeader->Addr2, &pAd->CommonCfg.Bssid, 6)) | |
361 | { | |
362 | // Receive frame not my BSSID | |
363 | // release packet | |
364 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
365 | return; | |
366 | } | |
367 | } | |
368 | else // Ad-Hoc mode or Not associated | |
369 | { | |
370 | // Ad-Hoc mode, check address 3 for BSSID | |
371 | if (!RTMPEqualMemory(&pHeader->Addr3, &pAd->CommonCfg.Bssid, 6)) | |
372 | { | |
373 | // Receive frame not my BSSID | |
374 | // release packet | |
375 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
376 | return; | |
377 | } | |
378 | } | |
91980990 GKH |
379 | |
380 | // | |
381 | // find pEntry | |
382 | // | |
383 | if (pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE) | |
384 | { | |
385 | pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID]; | |
386 | } | |
387 | else | |
388 | { | |
389 | // 1. release packet if infra mode | |
390 | // 2. new a pEntry if ad-hoc mode | |
391 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
392 | return; | |
393 | } | |
394 | ||
395 | // infra or ad-hoc | |
396 | if (INFRA_ON(pAd)) | |
397 | { | |
398 | RX_BLK_SET_FLAG(pRxBlk, fRX_INFRA); | |
91980990 GKH |
399 | ASSERT(pRxWI->WirelessCliID == BSSID_WCID); |
400 | } | |
401 | ||
402 | // check Atheros Client | |
403 | if ((pEntry->bIAmBadAtheros == FALSE) && (pRxD->AMPDU == 1) && (pHeader->FC.Retry )) | |
404 | { | |
405 | pEntry->bIAmBadAtheros = TRUE; | |
406 | pAd->CommonCfg.IOTestParm.bCurrentAtheros = TRUE; | |
407 | pAd->CommonCfg.IOTestParm.bLastAtheros = TRUE; | |
408 | if (!STA_AES_ON(pAd)) | |
409 | { | |
410 | AsicUpdateProtect(pAd, 8, ALLN_SETPROTECT, TRUE, FALSE); | |
411 | } | |
412 | } | |
413 | } | |
414 | ||
415 | pRxBlk->pData = (UCHAR *)pHeader; | |
416 | ||
417 | // | |
418 | // update RxBlk->pData, DataSize | |
419 | // 802.11 Header, QOS, HTC, Hw Padding | |
420 | // | |
421 | ||
422 | // 1. skip 802.11 HEADER | |
423 | { | |
424 | pRxBlk->pData += LENGTH_802_11; | |
425 | pRxBlk->DataSize -= LENGTH_802_11; | |
426 | } | |
427 | ||
428 | // 2. QOS | |
429 | if (pHeader->FC.SubType & 0x08) | |
430 | { | |
431 | RX_BLK_SET_FLAG(pRxBlk, fRX_QOS); | |
432 | UserPriority = *(pRxBlk->pData) & 0x0f; | |
433 | // bit 7 in QoS Control field signals the HT A-MSDU format | |
434 | if ((*pRxBlk->pData) & 0x80) | |
435 | { | |
436 | RX_BLK_SET_FLAG(pRxBlk, fRX_AMSDU); | |
437 | } | |
438 | ||
439 | // skip QOS contorl field | |
440 | pRxBlk->pData += 2; | |
441 | pRxBlk->DataSize -=2; | |
442 | } | |
443 | pRxBlk->UserPriority = UserPriority; | |
444 | ||
ca97b838 BZ |
445 | /* check if need to resend PS Poll when received packet with MoreData = 1 */ |
446 | if ((pAd->StaCfg.Psm == PWR_SAVE) && (pHeader->FC.MoreData == 1)) | |
447 | { | |
448 | if ((((UserPriority == 0) || (UserPriority == 3)) && | |
449 | pAd->CommonCfg.bAPSDAC_BE == 0) || | |
450 | (((UserPriority == 1) || (UserPriority == 2)) && | |
451 | pAd->CommonCfg.bAPSDAC_BK == 0) || | |
452 | (((UserPriority == 4) || (UserPriority == 5)) && | |
453 | pAd->CommonCfg.bAPSDAC_VI == 0) || | |
454 | (((UserPriority == 6) || (UserPriority == 7)) && | |
455 | pAd->CommonCfg.bAPSDAC_VO == 0)) | |
456 | { | |
457 | /* non-UAPSD delivery-enabled AC */ | |
458 | RTMP_PS_POLL_ENQUEUE(pAd); | |
459 | } | |
460 | } | |
461 | ||
91980990 GKH |
462 | // 3. Order bit: A-Ralink or HTC+ |
463 | if (pHeader->FC.Order) | |
464 | { | |
465 | #ifdef AGGREGATION_SUPPORT | |
466 | if ((pRxWI->PHYMODE <= MODE_OFDM) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED))) | |
467 | { | |
468 | RX_BLK_SET_FLAG(pRxBlk, fRX_ARALINK); | |
469 | } | |
470 | else | |
ca97b838 | 471 | #endif // AGGREGATION_SUPPORT // |
91980990 | 472 | { |
91980990 GKH |
473 | RX_BLK_SET_FLAG(pRxBlk, fRX_HTC); |
474 | // skip HTC contorl field | |
475 | pRxBlk->pData += 4; | |
476 | pRxBlk->DataSize -= 4; | |
91980990 GKH |
477 | } |
478 | } | |
479 | ||
480 | // 4. skip HW padding | |
481 | if (pRxD->L2PAD) | |
482 | { | |
483 | // just move pData pointer | |
484 | // because DataSize excluding HW padding | |
485 | RX_BLK_SET_FLAG(pRxBlk, fRX_PAD); | |
486 | pRxBlk->pData += 2; | |
487 | } | |
488 | ||
91980990 GKH |
489 | if (pRxD->BA) |
490 | { | |
491 | RX_BLK_SET_FLAG(pRxBlk, fRX_AMPDU); | |
492 | } | |
91980990 GKH |
493 | |
494 | // | |
495 | // Case I Process Broadcast & Multicast data frame | |
496 | // | |
497 | if (pRxD->Bcast || pRxD->Mcast) | |
498 | { | |
499 | INC_COUNTER64(pAd->WlanCounters.MulticastReceivedFrameCount); | |
500 | ||
501 | // Drop Mcast/Bcast frame with fragment bit on | |
502 | if (pHeader->FC.MoreFrag) | |
503 | { | |
504 | // release packet | |
505 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
506 | return; | |
507 | } | |
508 | ||
509 | // Filter out Bcast frame which AP relayed for us | |
510 | if (pHeader->FC.FrDs && MAC_ADDR_EQUAL(pHeader->Addr3, pAd->CurrentAddress)) | |
511 | { | |
512 | // release packet | |
513 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
514 | return; | |
515 | } | |
516 | ||
517 | Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID); | |
518 | return; | |
519 | } | |
520 | else if (pRxD->U2M) | |
521 | { | |
522 | pAd->LastRxRate = (USHORT)((pRxWI->MCS) + (pRxWI->BW <<7) + (pRxWI->ShortGI <<8)+ (pRxWI->PHYMODE <<14)) ; | |
523 | ||
91980990 GKH |
524 | if (ADHOC_ON(pAd)) |
525 | { | |
526 | pEntry = MacTableLookup(pAd, pHeader->Addr2); | |
527 | if (pEntry) | |
528 | Update_Rssi_Sample(pAd, &pEntry->RssiSample, pRxWI); | |
529 | } | |
530 | ||
531 | ||
532 | Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI); | |
533 | ||
534 | pAd->StaCfg.LastSNR0 = (UCHAR)(pRxWI->SNR0); | |
535 | pAd->StaCfg.LastSNR1 = (UCHAR)(pRxWI->SNR1); | |
536 | ||
537 | pAd->RalinkCounters.OneSecRxOkDataCnt++; | |
538 | ||
539 | ||
540 | if (!((pHeader->Frag == 0) && (pHeader->FC.MoreFrag == 0))) | |
541 | { | |
542 | // re-assemble the fragmented packets | |
543 | // return complete frame (pRxPacket) or NULL | |
544 | bFragment = TRUE; | |
545 | pRxPacket = RTMPDeFragmentDataFrame(pAd, pRxBlk); | |
546 | } | |
547 | ||
548 | if (pRxPacket) | |
549 | { | |
550 | pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID]; | |
551 | ||
552 | // process complete frame | |
553 | if (bFragment && (pRxD->Decrypted) && (pEntry->WepStatus == Ndis802_11Encryption2Enabled)) | |
554 | { | |
555 | // Minus MIC length | |
556 | pRxBlk->DataSize -= 8; | |
557 | ||
558 | // For TKIP frame, calculate the MIC value | |
559 | if (STACheckTkipMICValue(pAd, pEntry, pRxBlk) == FALSE) | |
560 | { | |
561 | return; | |
562 | } | |
563 | } | |
564 | ||
565 | STARxDataFrameAnnounce(pAd, pEntry, pRxBlk, FromWhichBSSID); | |
566 | return; | |
567 | } | |
568 | else | |
569 | { | |
570 | // just return | |
571 | // because RTMPDeFragmentDataFrame() will release rx packet, | |
572 | // if packet is fragmented | |
573 | return; | |
574 | } | |
575 | } | |
576 | ||
577 | ASSERT(0); | |
578 | // release packet | |
579 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
580 | } | |
581 | ||
582 | VOID STAHandleRxMgmtFrame( | |
583 | IN PRTMP_ADAPTER pAd, | |
584 | IN RX_BLK *pRxBlk) | |
585 | { | |
586 | PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD); | |
587 | PRXWI_STRUC pRxWI = pRxBlk->pRxWI; | |
588 | PHEADER_802_11 pHeader = pRxBlk->pHeader; | |
589 | PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket; | |
590 | ||
591 | do | |
592 | { | |
593 | ||
ca97b838 BZ |
594 | |
595 | /* check if need to resend PS Poll when received packet with MoreData = 1 */ | |
596 | if ((pAd->StaCfg.Psm == PWR_SAVE) && (pHeader->FC.MoreData == 1)) | |
597 | { | |
598 | /* for UAPSD, all management frames will be VO priority */ | |
599 | if (pAd->CommonCfg.bAPSDAC_VO == 0) | |
600 | { | |
601 | /* non-UAPSD delivery-enabled AC */ | |
602 | RTMP_PS_POLL_ENQUEUE(pAd); | |
603 | } | |
604 | } | |
605 | ||
606 | /* TODO: if MoreData == 0, station can go to sleep */ | |
607 | ||
608 | ||
91980990 | 609 | // We should collect RSSI not only U2M data but also my beacon |
ca97b838 BZ |
610 | if ((pHeader->FC.SubType == SUBTYPE_BEACON) && (MAC_ADDR_EQUAL(&pAd->CommonCfg.Bssid, &pHeader->Addr2)) |
611 | && (pAd->RxAnt.EvaluatePeriod == 0)) | |
612 | { | |
91980990 GKH |
613 | Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI); |
614 | ||
615 | pAd->StaCfg.LastSNR0 = (UCHAR)(pRxWI->SNR0); | |
616 | pAd->StaCfg.LastSNR1 = (UCHAR)(pRxWI->SNR1); | |
617 | } | |
618 | ||
5f5d2df8 | 619 | |
91980990 GKH |
620 | // First check the size, it MUST not exceed the mlme queue size |
621 | if (pRxWI->MPDUtotalByteCount > MGMT_DMA_BUFFER_SIZE) | |
622 | { | |
623 | DBGPRINT_ERR(("STAHandleRxMgmtFrame: frame too large, size = %d \n", pRxWI->MPDUtotalByteCount)); | |
624 | break; | |
625 | } | |
626 | ||
627 | REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pHeader, pRxWI->MPDUtotalByteCount, | |
628 | pRxWI->RSSI0, pRxWI->RSSI1, pRxWI->RSSI2, pRxD->PlcpSignal); | |
629 | } while (FALSE); | |
630 | ||
631 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_SUCCESS); | |
632 | } | |
633 | ||
634 | VOID STAHandleRxControlFrame( | |
635 | IN PRTMP_ADAPTER pAd, | |
636 | IN RX_BLK *pRxBlk) | |
637 | { | |
91980990 | 638 | PRXWI_STRUC pRxWI = pRxBlk->pRxWI; |
91980990 GKH |
639 | PHEADER_802_11 pHeader = pRxBlk->pHeader; |
640 | PNDIS_PACKET pRxPacket = pRxBlk->pRxPacket; | |
641 | ||
642 | switch (pHeader->FC.SubType) | |
643 | { | |
644 | case SUBTYPE_BLOCK_ACK_REQ: | |
91980990 GKH |
645 | { |
646 | CntlEnqueueForRecv(pAd, pRxWI->WirelessCliID, (pRxWI->MPDUtotalByteCount), (PFRAME_BA_REQ)pHeader); | |
647 | } | |
648 | break; | |
91980990 GKH |
649 | case SUBTYPE_BLOCK_ACK: |
650 | case SUBTYPE_ACK: | |
651 | default: | |
652 | break; | |
653 | } | |
654 | ||
655 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
656 | } | |
657 | ||
658 | ||
659 | /* | |
660 | ======================================================================== | |
661 | ||
662 | Routine Description: | |
663 | Process RxDone interrupt, running in DPC level | |
664 | ||
665 | Arguments: | |
666 | pAd Pointer to our adapter | |
667 | ||
668 | Return Value: | |
669 | None | |
670 | ||
671 | IRQL = DISPATCH_LEVEL | |
672 | ||
673 | Note: | |
674 | This routine has to maintain Rx ring read pointer. | |
675 | Need to consider QOS DATA format when converting to 802.3 | |
676 | ======================================================================== | |
677 | */ | |
678 | BOOLEAN STARxDoneInterruptHandle( | |
679 | IN PRTMP_ADAPTER pAd, | |
680 | IN BOOLEAN argc) | |
681 | { | |
682 | NDIS_STATUS Status; | |
683 | UINT32 RxProcessed, RxPending; | |
684 | BOOLEAN bReschedule = FALSE; | |
685 | RT28XX_RXD_STRUC *pRxD; | |
686 | UCHAR *pData; | |
687 | PRXWI_STRUC pRxWI; | |
688 | PNDIS_PACKET pRxPacket; | |
689 | PHEADER_802_11 pHeader; | |
690 | RX_BLK RxCell; | |
691 | ||
692 | RxProcessed = RxPending = 0; | |
693 | ||
694 | // process whole rx ring | |
695 | while (1) | |
696 | { | |
697 | ||
698 | if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF | | |
699 | fRTMP_ADAPTER_RESET_IN_PROGRESS | | |
700 | fRTMP_ADAPTER_HALT_IN_PROGRESS | | |
701 | fRTMP_ADAPTER_NIC_NOT_EXIST) || | |
702 | !RTMP_TEST_FLAG(pAd,fRTMP_ADAPTER_START_UP)) | |
703 | { | |
704 | break; | |
705 | } | |
706 | ||
ca97b838 | 707 | #ifdef RTMP_MAC_PCI |
91980990 GKH |
708 | if (RxProcessed++ > MAX_RX_PROCESS_CNT) |
709 | { | |
710 | // need to reschedule rx handle | |
711 | bReschedule = TRUE; | |
712 | break; | |
713 | } | |
ca97b838 | 714 | #endif // RTMP_MAC_PCI // |
91980990 GKH |
715 | |
716 | RxProcessed ++; // test | |
717 | ||
718 | // 1. allocate a new data packet into rx ring to replace received packet | |
719 | // then processing the received packet | |
720 | // 2. the callee must take charge of release of packet | |
721 | // 3. As far as driver is concerned , | |
722 | // the rx packet must | |
723 | // a. be indicated to upper layer or | |
724 | // b. be released if it is discarded | |
725 | pRxPacket = GetPacketFromRxRing(pAd, &(RxCell.RxD), &bReschedule, &RxPending); | |
726 | if (pRxPacket == NULL) | |
727 | { | |
728 | // no more packet to process | |
729 | break; | |
730 | } | |
731 | ||
732 | // get rx ring descriptor | |
733 | pRxD = &(RxCell.RxD); | |
734 | // get rx data buffer | |
735 | pData = GET_OS_PKT_DATAPTR(pRxPacket); | |
736 | pRxWI = (PRXWI_STRUC) pData; | |
737 | pHeader = (PHEADER_802_11) (pData+RXWI_SIZE) ; | |
738 | ||
91980990 GKH |
739 | // build RxCell |
740 | RxCell.pRxWI = pRxWI; | |
741 | RxCell.pHeader = pHeader; | |
742 | RxCell.pRxPacket = pRxPacket; | |
743 | RxCell.pData = (UCHAR *) pHeader; | |
744 | RxCell.DataSize = pRxWI->MPDUtotalByteCount; | |
745 | RxCell.Flags = 0; | |
746 | ||
747 | // Increase Total receive byte counter after real data received no mater any error or not | |
748 | pAd->RalinkCounters.ReceivedByteCount += pRxWI->MPDUtotalByteCount; | |
ca97b838 | 749 | pAd->RalinkCounters.OneSecReceivedByteCount += pRxWI->MPDUtotalByteCount; |
91980990 GKH |
750 | pAd->RalinkCounters.RxCount ++; |
751 | ||
752 | INC_COUNTER64(pAd->WlanCounters.ReceivedFragmentCount); | |
753 | ||
754 | if (pRxWI->MPDUtotalByteCount < 14) | |
755 | Status = NDIS_STATUS_FAILURE; | |
756 | ||
757 | if (MONITOR_ON(pAd)) | |
758 | { | |
759 | send_monitor_packets(pAd, &RxCell); | |
760 | break; | |
761 | } | |
ca97b838 BZ |
762 | |
763 | /* STARxDoneInterruptHandle() is called in rtusb_bulk.c */ | |
91980990 GKH |
764 | |
765 | // Check for all RxD errors | |
766 | Status = RTMPCheckRxError(pAd, pHeader, pRxWI, pRxD); | |
767 | ||
768 | // Handle the received frame | |
769 | if (Status == NDIS_STATUS_SUCCESS) | |
770 | { | |
771 | switch (pHeader->FC.Type) | |
772 | { | |
773 | // CASE I, receive a DATA frame | |
774 | case BTYPE_DATA: | |
775 | { | |
776 | // process DATA frame | |
777 | STAHandleRxDataFrame(pAd, &RxCell); | |
778 | } | |
779 | break; | |
780 | // CASE II, receive a MGMT frame | |
781 | case BTYPE_MGMT: | |
782 | { | |
783 | STAHandleRxMgmtFrame(pAd, &RxCell); | |
784 | } | |
785 | break; | |
786 | // CASE III. receive a CNTL frame | |
787 | case BTYPE_CNTL: | |
788 | { | |
789 | STAHandleRxControlFrame(pAd, &RxCell); | |
790 | } | |
791 | break; | |
792 | // discard other type | |
793 | default: | |
794 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
795 | break; | |
796 | } | |
797 | } | |
798 | else | |
799 | { | |
800 | pAd->Counters8023.RxErrors++; | |
801 | // discard this frame | |
802 | RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); | |
803 | } | |
804 | } | |
805 | ||
806 | return bReschedule; | |
807 | } | |
808 | ||
809 | /* | |
810 | ======================================================================== | |
811 | ||
812 | Routine Description: | |
813 | Arguments: | |
814 | pAd Pointer to our adapter | |
815 | ||
816 | IRQL = DISPATCH_LEVEL | |
817 | ||
818 | ======================================================================== | |
819 | */ | |
820 | VOID RTMPHandleTwakeupInterrupt( | |
821 | IN PRTMP_ADAPTER pAd) | |
822 | { | |
5f5d2df8 | 823 | AsicForceWakeup(pAd, FALSE); |
91980990 GKH |
824 | } |
825 | ||
826 | /* | |
827 | ======================================================================== | |
828 | Routine Description: | |
829 | Early checking and OS-depened parsing for Tx packet send to our STA driver. | |
830 | ||
831 | Arguments: | |
832 | NDIS_HANDLE MiniportAdapterContext Pointer refer to the device handle, i.e., the pAd. | |
833 | PPNDIS_PACKET ppPacketArray The packet array need to do transmission. | |
834 | UINT NumberOfPackets Number of packet in packet array. | |
835 | ||
836 | Return Value: | |
837 | NONE | |
838 | ||
839 | Note: | |
840 | This function do early checking and classification for send-out packet. | |
841 | You only can put OS-depened & STA related code in here. | |
842 | ======================================================================== | |
843 | */ | |
844 | VOID STASendPackets( | |
845 | IN NDIS_HANDLE MiniportAdapterContext, | |
846 | IN PPNDIS_PACKET ppPacketArray, | |
847 | IN UINT NumberOfPackets) | |
848 | { | |
849 | UINT Index; | |
850 | PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) MiniportAdapterContext; | |
851 | PNDIS_PACKET pPacket; | |
852 | BOOLEAN allowToSend = FALSE; | |
853 | ||
854 | ||
855 | for (Index = 0; Index < NumberOfPackets; Index++) | |
856 | { | |
857 | pPacket = ppPacketArray[Index]; | |
858 | ||
859 | do | |
860 | { | |
861 | if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) || | |
862 | RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) || | |
863 | RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) | |
864 | { | |
865 | // Drop send request since hardware is in reset state | |
866 | break; | |
867 | } | |
868 | else if (!INFRA_ON(pAd) && !ADHOC_ON(pAd)) | |
869 | { | |
870 | // Drop send request since there are no physical connection yet | |
871 | break; | |
872 | } | |
873 | else | |
874 | { | |
875 | // Record that orignal packet source is from NDIS layer,so that | |
876 | // later on driver knows how to release this NDIS PACKET | |
91980990 GKH |
877 | RTMP_SET_PACKET_WCID(pPacket, 0); // this field is useless when in STA mode |
878 | RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS); | |
879 | NDIS_SET_PACKET_STATUS(pPacket, NDIS_STATUS_PENDING); | |
880 | pAd->RalinkCounters.PendingNdisPacketCount++; | |
881 | ||
882 | allowToSend = TRUE; | |
883 | } | |
884 | } while(FALSE); | |
885 | ||
886 | if (allowToSend == TRUE) | |
887 | STASendPacket(pAd, pPacket); | |
888 | else | |
889 | RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); | |
890 | } | |
891 | ||
892 | // Dequeue outgoing frames from TxSwQueue[] and process it | |
893 | RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); | |
894 | ||
895 | } | |
896 | ||
897 | ||
898 | /* | |
899 | ======================================================================== | |
900 | Routine Description: | |
901 | This routine is used to do packet parsing and classification for Tx packet | |
902 | to STA device, and it will en-queue packets to our TxSwQueue depends on AC | |
903 | class. | |
904 | ||
905 | Arguments: | |
906 | pAd Pointer to our adapter | |
907 | pPacket Pointer to send packet | |
908 | ||
909 | Return Value: | |
910 | NDIS_STATUS_SUCCESS If succes to queue the packet into TxSwQueue. | |
911 | NDIS_STATUS_FAILURE If failed to do en-queue. | |
912 | ||
913 | Note: | |
914 | You only can put OS-indepened & STA related code in here. | |
915 | ======================================================================== | |
916 | */ | |
917 | NDIS_STATUS STASendPacket( | |
918 | IN PRTMP_ADAPTER pAd, | |
919 | IN PNDIS_PACKET pPacket) | |
920 | { | |
921 | PACKET_INFO PacketInfo; | |
922 | PUCHAR pSrcBufVA; | |
923 | UINT SrcBufLen; | |
924 | UINT AllowFragSize; | |
925 | UCHAR NumberOfFrag; | |
ca97b838 | 926 | UCHAR RTSRequired; |
91980990 GKH |
927 | UCHAR QueIdx, UserPriority; |
928 | MAC_TABLE_ENTRY *pEntry = NULL; | |
929 | unsigned int IrqFlags; | |
930 | UCHAR FlgIsIP = 0; | |
931 | UCHAR Rate; | |
932 | ||
933 | // Prepare packet information structure for buffer descriptor | |
934 | // chained within a single NDIS packet. | |
935 | RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen); | |
936 | ||
937 | if (pSrcBufVA == NULL) | |
938 | { | |
939 | DBGPRINT(RT_DEBUG_ERROR,("STASendPacket --> pSrcBufVA == NULL !!!SrcBufLen=%x\n",SrcBufLen)); | |
940 | // Resourece is low, system did not allocate virtual address | |
941 | // return NDIS_STATUS_FAILURE directly to upper layer | |
942 | RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); | |
943 | return NDIS_STATUS_FAILURE; | |
944 | } | |
945 | ||
946 | ||
947 | if (SrcBufLen < 14) | |
948 | { | |
949 | DBGPRINT(RT_DEBUG_ERROR,("STASendPacket --> Ndis Packet buffer error !!!\n")); | |
950 | RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); | |
951 | return (NDIS_STATUS_FAILURE); | |
952 | } | |
953 | ||
954 | // In HT rate adhoc mode, A-MPDU is often used. So need to lookup BA Table and MAC Entry. | |
955 | // Note multicast packets in adhoc also use BSSID_WCID index. | |
956 | { | |
957 | if(INFRA_ON(pAd)) | |
958 | { | |
91980990 GKH |
959 | { |
960 | pEntry = &pAd->MacTab.Content[BSSID_WCID]; | |
961 | RTMP_SET_PACKET_WCID(pPacket, BSSID_WCID); | |
962 | Rate = pAd->CommonCfg.TxRate; | |
963 | } | |
964 | } | |
965 | else if (ADHOC_ON(pAd)) | |
966 | { | |
967 | if (*pSrcBufVA & 0x01) | |
968 | { | |
969 | RTMP_SET_PACKET_WCID(pPacket, MCAST_WCID); | |
970 | pEntry = &pAd->MacTab.Content[MCAST_WCID]; | |
971 | } | |
972 | else | |
973 | { | |
974 | pEntry = MacTableLookup(pAd, pSrcBufVA); | |
975 | } | |
976 | Rate = pAd->CommonCfg.TxRate; | |
977 | } | |
978 | } | |
979 | ||
980 | if (!pEntry) | |
981 | { | |
982 | DBGPRINT(RT_DEBUG_ERROR,("STASendPacket->Cannot find pEntry(%2x:%2x:%2x:%2x:%2x:%2x) in MacTab!\n", PRINT_MAC(pSrcBufVA))); | |
983 | // Resourece is low, system did not allocate virtual address | |
984 | // return NDIS_STATUS_FAILURE directly to upper layer | |
985 | RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); | |
986 | return NDIS_STATUS_FAILURE; | |
987 | } | |
988 | ||
989 | if (ADHOC_ON(pAd) | |
990 | ) | |
991 | { | |
992 | RTMP_SET_PACKET_WCID(pPacket, (UCHAR)pEntry->Aid); | |
993 | } | |
994 | ||
995 | // | |
996 | // Check the Ethernet Frame type of this packet, and set the RTMP_SET_PACKET_SPECIFIC flags. | |
997 | // Here we set the PACKET_SPECIFIC flags(LLC, VLAN, DHCP/ARP, EAPOL). | |
998 | RTMPCheckEtherType(pAd, pPacket); | |
999 | ||
1000 | ||
1001 | ||
1002 | // | |
1003 | // WPA 802.1x secured port control - drop all non-802.1x frame before port secured | |
1004 | // | |
1005 | if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || | |
1006 | (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) || | |
1007 | (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || | |
1008 | (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) | |
91980990 | 1009 | || (pAd->StaCfg.IEEE8021X == TRUE) |
91980990 GKH |
1010 | ) |
1011 | && ((pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED) || (pAd->StaCfg.MicErrCnt >= 2)) | |
1012 | && (RTMP_GET_PACKET_EAPOL(pPacket)== FALSE) | |
1013 | ) | |
1014 | { | |
1015 | DBGPRINT(RT_DEBUG_TRACE,("STASendPacket --> Drop packet before port secured !!!\n")); | |
1016 | RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); | |
1017 | ||
1018 | return (NDIS_STATUS_FAILURE); | |
1019 | } | |
1020 | ||
1021 | ||
1022 | // STEP 1. Decide number of fragments required to deliver this MSDU. | |
1023 | // The estimation here is not very accurate because difficult to | |
1024 | // take encryption overhead into consideration here. The result | |
1025 | // "NumberOfFrag" is then just used to pre-check if enough free | |
1026 | // TXD are available to hold this MSDU. | |
1027 | ||
1028 | ||
1029 | if (*pSrcBufVA & 0x01) // fragmentation not allowed on multicast & broadcast | |
1030 | NumberOfFrag = 1; | |
1031 | else if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)) | |
1032 | NumberOfFrag = 1; // Aggregation overwhelms fragmentation | |
1033 | else if (CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_AMSDU_INUSED)) | |
1034 | NumberOfFrag = 1; // Aggregation overwhelms fragmentation | |
91980990 GKH |
1035 | else if ((pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTMIX) || (pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTGREENFIELD)) |
1036 | NumberOfFrag = 1; // MIMO RATE overwhelms fragmentation | |
91980990 GKH |
1037 | else |
1038 | { | |
1039 | // The calculated "NumberOfFrag" is a rough estimation because of various | |
1040 | // encryption/encapsulation overhead not taken into consideration. This number is just | |
1041 | // used to make sure enough free TXD are available before fragmentation takes place. | |
1042 | // In case the actual required number of fragments of an NDIS packet | |
1043 | // excceeds "NumberOfFrag"caculated here and not enough free TXD available, the | |
1044 | // last fragment (i.e. last MPDU) will be dropped in RTMPHardTransmit() due to out of | |
1045 | // resource, and the NDIS packet will be indicated NDIS_STATUS_FAILURE. This should | |
1046 | // rarely happen and the penalty is just like a TX RETRY fail. Affordable. | |
1047 | ||
1048 | AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC; | |
1049 | NumberOfFrag = ((PacketInfo.TotalPacketLength - LENGTH_802_3 + LENGTH_802_1_H) / AllowFragSize) + 1; | |
1050 | // To get accurate number of fragmentation, Minus 1 if the size just match to allowable fragment size | |
1051 | if (((PacketInfo.TotalPacketLength - LENGTH_802_3 + LENGTH_802_1_H) % AllowFragSize) == 0) | |
1052 | { | |
1053 | NumberOfFrag--; | |
1054 | } | |
1055 | } | |
1056 | ||
1057 | // Save fragment number to Ndis packet reserved field | |
1058 | RTMP_SET_PACKET_FRAGMENTS(pPacket, NumberOfFrag); | |
1059 | ||
1060 | ||
1061 | // STEP 2. Check the requirement of RTS: | |
1062 | // If multiple fragment required, RTS is required only for the first fragment | |
1063 | // if the fragment size large than RTS threshold | |
1064 | // For RT28xx, Let ASIC send RTS/CTS | |
ca97b838 BZ |
1065 | // RTMP_SET_PACKET_RTS(pPacket, 0); |
1066 | if (NumberOfFrag > 1) | |
1067 | RTSRequired = (pAd->CommonCfg.FragmentThreshold > pAd->CommonCfg.RtsThreshold) ? 1 : 0; | |
1068 | else | |
1069 | RTSRequired = (PacketInfo.TotalPacketLength > pAd->CommonCfg.RtsThreshold) ? 1 : 0; | |
1070 | ||
1071 | // Save RTS requirement to Ndis packet reserved field | |
1072 | RTMP_SET_PACKET_RTS(pPacket, RTSRequired); | |
91980990 GKH |
1073 | RTMP_SET_PACKET_TXRATE(pPacket, pAd->CommonCfg.TxRate); |
1074 | ||
1075 | // | |
1076 | // STEP 3. Traffic classification. outcome = <UserPriority, QueIdx> | |
1077 | // | |
1078 | UserPriority = 0; | |
1079 | QueIdx = QID_AC_BE; | |
5f5d2df8 BZ |
1080 | if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && |
1081 | CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE)) | |
91980990 GKH |
1082 | { |
1083 | USHORT Protocol; | |
1084 | UCHAR LlcSnapLen = 0, Byte0, Byte1; | |
1085 | do | |
1086 | { | |
1087 | // get Ethernet protocol field | |
1088 | Protocol = (USHORT)((pSrcBufVA[12] << 8) + pSrcBufVA[13]); | |
1089 | if (Protocol <= 1500) | |
1090 | { | |
1091 | // get Ethernet protocol field from LLC/SNAP | |
1092 | if (Sniff2BytesFromNdisBuffer(PacketInfo.pFirstBuffer, LENGTH_802_3 + 6, &Byte0, &Byte1) != NDIS_STATUS_SUCCESS) | |
1093 | break; | |
1094 | ||
1095 | Protocol = (USHORT)((Byte0 << 8) + Byte1); | |
1096 | LlcSnapLen = 8; | |
1097 | } | |
1098 | ||
1099 | // always AC_BE for non-IP packet | |
1100 | if (Protocol != 0x0800) | |
1101 | break; | |
1102 | ||
1103 | // get IP header | |
1104 | if (Sniff2BytesFromNdisBuffer(PacketInfo.pFirstBuffer, LENGTH_802_3 + LlcSnapLen, &Byte0, &Byte1) != NDIS_STATUS_SUCCESS) | |
1105 | break; | |
1106 | ||
1107 | // return AC_BE if packet is not IPv4 | |
1108 | if ((Byte0 & 0xf0) != 0x40) | |
1109 | break; | |
1110 | ||
1111 | FlgIsIP = 1; | |
1112 | UserPriority = (Byte1 & 0xe0) >> 5; | |
1113 | QueIdx = MapUserPriorityToAccessCategory[UserPriority]; | |
1114 | ||
1115 | // TODO: have to check ACM bit. apply TSPEC if ACM is ON | |
1116 | // TODO: downgrade UP & QueIdx before passing ACM | |
ca97b838 BZ |
1117 | /* |
1118 | Under WMM ACM control, we dont need to check the bit; | |
1119 | Or when a TSPEC is built for VO but we will change to issue | |
1120 | BA session for BE here, so we will not use BA to send VO packets. | |
1121 | */ | |
91980990 GKH |
1122 | if (pAd->CommonCfg.APEdcaParm.bACM[QueIdx]) |
1123 | { | |
1124 | UserPriority = 0; | |
1125 | QueIdx = QID_AC_BE; | |
1126 | } | |
1127 | } while (FALSE); | |
1128 | } | |
1129 | ||
1130 | RTMP_SET_PACKET_UP(pPacket, UserPriority); | |
1131 | ||
1132 | ||
1133 | ||
1134 | // Make sure SendTxWait queue resource won't be used by other threads | |
1135 | RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); | |
1136 | if (pAd->TxSwQueue[QueIdx].Number >= MAX_PACKETS_IN_QUEUE) | |
1137 | { | |
1138 | RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); | |
91980990 GKH |
1139 | RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); |
1140 | ||
1141 | return NDIS_STATUS_FAILURE; | |
1142 | } | |
1143 | else | |
1144 | { | |
ca97b838 | 1145 | InsertTailQueueAc(pAd, pEntry, &pAd->TxSwQueue[QueIdx], PACKET_TO_QUEUE_ENTRY(pPacket)); |
91980990 GKH |
1146 | } |
1147 | RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); | |
1148 | ||
91980990 | 1149 | if ((pAd->CommonCfg.BACapability.field.AutoBA == TRUE)&& |
5f5d2df8 | 1150 | IS_HT_STA(pEntry)) |
91980990 | 1151 | { |
ca97b838 | 1152 | //PMAC_TABLE_ENTRY pMacEntry = &pAd->MacTab.Content[BSSID_WCID]; |
91980990 GKH |
1153 | if (((pEntry->TXBAbitmap & (1<<UserPriority)) == 0) && |
1154 | ((pEntry->BADeclineBitmap & (1<<UserPriority)) == 0) && | |
1155 | (pEntry->PortSecured == WPA_802_1X_PORT_SECURED) | |
1156 | // For IOT compatibility, if | |
1157 | // 1. It is Ralink chip or | |
1158 | // 2. It is OPEN or AES mode, | |
1159 | // then BA session can be bulit. | |
1160 | && ((pEntry->ValidAsCLI && pAd->MlmeAux.APRalinkIe != 0x0) || | |
ca97b838 | 1161 | (pEntry->WepStatus != Ndis802_11WEPEnabled && pEntry->WepStatus != Ndis802_11Encryption2Enabled)) |
91980990 GKH |
1162 | ) |
1163 | { | |
ca97b838 | 1164 | BAOriSessionSetUp(pAd, pEntry, UserPriority, 0, 10, FALSE); |
91980990 GKH |
1165 | } |
1166 | } | |
91980990 GKH |
1167 | |
1168 | pAd->RalinkCounters.OneSecOsTxCount[QueIdx]++; // TODO: for debug only. to be removed | |
1169 | return NDIS_STATUS_SUCCESS; | |
1170 | } | |
1171 | ||
1172 | ||
1173 | /* | |
1174 | ======================================================================== | |
1175 | ||
1176 | Routine Description: | |
1177 | This subroutine will scan through releative ring descriptor to find | |
1178 | out avaliable free ring descriptor and compare with request size. | |
1179 | ||
1180 | Arguments: | |
1181 | pAd Pointer to our adapter | |
1182 | QueIdx Selected TX Ring | |
1183 | ||
1184 | Return Value: | |
1185 | NDIS_STATUS_FAILURE Not enough free descriptor | |
1186 | NDIS_STATUS_SUCCESS Enough free descriptor | |
1187 | ||
1188 | IRQL = PASSIVE_LEVEL | |
1189 | IRQL = DISPATCH_LEVEL | |
1190 | ||
1191 | Note: | |
1192 | ||
1193 | ======================================================================== | |
1194 | */ | |
ca97b838 | 1195 | #ifdef RTMP_MAC_PCI |
91980990 GKH |
1196 | NDIS_STATUS RTMPFreeTXDRequest( |
1197 | IN PRTMP_ADAPTER pAd, | |
1198 | IN UCHAR QueIdx, | |
1199 | IN UCHAR NumberRequired, | |
1200 | IN PUCHAR FreeNumberIs) | |
1201 | { | |
1202 | ULONG FreeNumber = 0; | |
1203 | NDIS_STATUS Status = NDIS_STATUS_FAILURE; | |
1204 | ||
1205 | switch (QueIdx) | |
1206 | { | |
1207 | case QID_AC_BK: | |
1208 | case QID_AC_BE: | |
1209 | case QID_AC_VI: | |
1210 | case QID_AC_VO: | |
91980990 GKH |
1211 | if (pAd->TxRing[QueIdx].TxSwFreeIdx > pAd->TxRing[QueIdx].TxCpuIdx) |
1212 | FreeNumber = pAd->TxRing[QueIdx].TxSwFreeIdx - pAd->TxRing[QueIdx].TxCpuIdx - 1; | |
1213 | else | |
1214 | FreeNumber = pAd->TxRing[QueIdx].TxSwFreeIdx + TX_RING_SIZE - pAd->TxRing[QueIdx].TxCpuIdx - 1; | |
1215 | ||
1216 | if (FreeNumber >= NumberRequired) | |
1217 | Status = NDIS_STATUS_SUCCESS; | |
ca97b838 BZ |
1218 | break; |
1219 | ||
1220 | case QID_MGMT: | |
1221 | if (pAd->MgmtRing.TxSwFreeIdx > pAd->MgmtRing.TxCpuIdx) | |
1222 | FreeNumber = pAd->MgmtRing.TxSwFreeIdx - pAd->MgmtRing.TxCpuIdx - 1; | |
1223 | else | |
1224 | FreeNumber = pAd->MgmtRing.TxSwFreeIdx + MGMT_RING_SIZE - pAd->MgmtRing.TxCpuIdx - 1; | |
1225 | ||
1226 | if (FreeNumber >= NumberRequired) | |
1227 | Status = NDIS_STATUS_SUCCESS; | |
1228 | break; | |
1229 | ||
1230 | default: | |
1231 | DBGPRINT(RT_DEBUG_ERROR,("RTMPFreeTXDRequest::Invalid QueIdx(=%d)\n", QueIdx)); | |
1232 | break; | |
1233 | } | |
1234 | *FreeNumberIs = (UCHAR)FreeNumber; | |
1235 | ||
1236 | return (Status); | |
1237 | } | |
1238 | #endif // RTMP_MAC_PCI // | |
1239 | #ifdef RTMP_MAC_USB | |
1240 | /* | |
1241 | Actually, this function used to check if the TxHardware Queue still has frame need to send. | |
1242 | If no frame need to send, go to sleep, else, still wake up. | |
1243 | */ | |
1244 | NDIS_STATUS RTMPFreeTXDRequest( | |
1245 | IN PRTMP_ADAPTER pAd, | |
1246 | IN UCHAR QueIdx, | |
1247 | IN UCHAR NumberRequired, | |
1248 | IN PUCHAR FreeNumberIs) | |
1249 | { | |
1250 | //ULONG FreeNumber = 0; | |
1251 | NDIS_STATUS Status = NDIS_STATUS_FAILURE; | |
1252 | unsigned long IrqFlags; | |
1253 | HT_TX_CONTEXT *pHTTXContext; | |
1254 | ||
1255 | switch (QueIdx) | |
1256 | { | |
1257 | case QID_AC_BK: | |
1258 | case QID_AC_BE: | |
1259 | case QID_AC_VI: | |
1260 | case QID_AC_VO: | |
5f5d2df8 BZ |
1261 | { |
1262 | pHTTXContext = &pAd->TxContext[QueIdx]; | |
1263 | RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); | |
1264 | if ((pHTTXContext->CurWritePosition != pHTTXContext->ENextBulkOutPosition) || | |
1265 | (pHTTXContext->IRPPending == TRUE)) | |
1266 | { | |
1267 | Status = NDIS_STATUS_FAILURE; | |
1268 | } | |
1269 | else | |
1270 | { | |
1271 | Status = NDIS_STATUS_SUCCESS; | |
1272 | } | |
1273 | RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); | |
1274 | } | |
91980990 | 1275 | break; |
91980990 | 1276 | case QID_MGMT: |
5f5d2df8 BZ |
1277 | if (pAd->MgmtRing.TxSwFreeIdx != MGMT_RING_SIZE) |
1278 | Status = NDIS_STATUS_FAILURE; | |
1279 | else | |
1280 | Status = NDIS_STATUS_SUCCESS; | |
91980990 | 1281 | break; |
91980990 GKH |
1282 | default: |
1283 | DBGPRINT(RT_DEBUG_ERROR,("RTMPFreeTXDRequest::Invalid QueIdx(=%d)\n", QueIdx)); | |
1284 | break; | |
1285 | } | |
91980990 GKH |
1286 | |
1287 | return (Status); | |
1288 | } | |
ca97b838 | 1289 | #endif // RTMP_MAC_USB // |
91980990 GKH |
1290 | |
1291 | VOID RTMPSendDisassociationFrame( | |
1292 | IN PRTMP_ADAPTER pAd) | |
1293 | { | |
1294 | } | |
1295 | ||
1296 | VOID RTMPSendNullFrame( | |
1297 | IN PRTMP_ADAPTER pAd, | |
1298 | IN UCHAR TxRate, | |
1299 | IN BOOLEAN bQosNull) | |
1300 | { | |
1301 | UCHAR NullFrame[48]; | |
1302 | ULONG Length; | |
1303 | PHEADER_802_11 pHeader_802_11; | |
1304 | ||
91980990 GKH |
1305 | // WPA 802.1x secured port control |
1306 | if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || | |
1307 | (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) || | |
1308 | (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || | |
1309 | (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) | |
91980990 | 1310 | || (pAd->StaCfg.IEEE8021X == TRUE) |
91980990 GKH |
1311 | ) && |
1312 | (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)) | |
1313 | { | |
1314 | return; | |
1315 | } | |
1316 | ||
1317 | NdisZeroMemory(NullFrame, 48); | |
1318 | Length = sizeof(HEADER_802_11); | |
1319 | ||
1320 | pHeader_802_11 = (PHEADER_802_11) NullFrame; | |
1321 | ||
1322 | pHeader_802_11->FC.Type = BTYPE_DATA; | |
1323 | pHeader_802_11->FC.SubType = SUBTYPE_NULL_FUNC; | |
1324 | pHeader_802_11->FC.ToDs = 1; | |
1325 | COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid); | |
1326 | COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress); | |
1327 | COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid); | |
1328 | ||
1329 | if (pAd->CommonCfg.bAPSDForcePowerSave) | |
1330 | { | |
1331 | pHeader_802_11->FC.PwrMgmt = PWR_SAVE; | |
1332 | } | |
1333 | else | |
1334 | { | |
1335 | pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE) ? 1: 0; | |
1336 | } | |
1337 | pHeader_802_11->Duration = pAd->CommonCfg.Dsifs + RTMPCalcDuration(pAd, TxRate, 14); | |
1338 | ||
1339 | pAd->Sequence++; | |
1340 | pHeader_802_11->Sequence = pAd->Sequence; | |
1341 | ||
1342 | // Prepare QosNull function frame | |
1343 | if (bQosNull) | |
1344 | { | |
1345 | pHeader_802_11->FC.SubType = SUBTYPE_QOS_NULL; | |
1346 | ||
1347 | // copy QOS control bytes | |
1348 | NullFrame[Length] = 0; | |
1349 | NullFrame[Length+1] = 0; | |
1350 | Length += 2;// if pad with 2 bytes for alignment, APSD will fail | |
1351 | } | |
1352 | ||
1353 | HAL_KickOutNullFrameTx(pAd, 0, NullFrame, Length); | |
1354 | ||
1355 | } | |
1356 | ||
1357 | // IRQL = DISPATCH_LEVEL | |
1358 | VOID RTMPSendRTSFrame( | |
1359 | IN PRTMP_ADAPTER pAd, | |
1360 | IN PUCHAR pDA, | |
1361 | IN unsigned int NextMpduSize, | |
1362 | IN UCHAR TxRate, | |
1363 | IN UCHAR RTSRate, | |
1364 | IN USHORT AckDuration, | |
1365 | IN UCHAR QueIdx, | |
1366 | IN UCHAR FrameGap) | |
1367 | { | |
1368 | } | |
1369 | ||
1370 | ||
1371 | ||
1372 | // -------------------------------------------------------- | |
1373 | // FIND ENCRYPT KEY AND DECIDE CIPHER ALGORITHM | |
1374 | // Find the WPA key, either Group or Pairwise Key | |
1375 | // LEAP + TKIP also use WPA key. | |
1376 | // -------------------------------------------------------- | |
1377 | // Decide WEP bit and cipher suite to be used. Same cipher suite should be used for whole fragment burst | |
1378 | // In Cisco CCX 2.0 Leap Authentication | |
1379 | // WepStatus is Ndis802_11Encryption1Enabled but the key will use PairwiseKey | |
1380 | // Instead of the SharedKey, SharedKey Length may be Zero. | |
1381 | VOID STAFindCipherAlgorithm( | |
1382 | IN PRTMP_ADAPTER pAd, | |
1383 | IN TX_BLK *pTxBlk) | |
1384 | { | |
1385 | NDIS_802_11_ENCRYPTION_STATUS Cipher; // To indicate cipher used for this packet | |
1386 | UCHAR CipherAlg = CIPHER_NONE; // cipher alogrithm | |
1387 | UCHAR KeyIdx = 0xff; | |
1388 | PUCHAR pSrcBufVA; | |
1389 | PCIPHER_KEY pKey = NULL; | |
1390 | ||
1391 | pSrcBufVA = GET_OS_PKT_DATAPTR(pTxBlk->pPacket); | |
1392 | ||
1393 | { | |
1394 | // Select Cipher | |
1395 | if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))) | |
1396 | Cipher = pAd->StaCfg.GroupCipher; // Cipher for Multicast or Broadcast | |
1397 | else | |
1398 | Cipher = pAd->StaCfg.PairCipher; // Cipher for Unicast | |
1399 | ||
1400 | if (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket)) | |
1401 | { | |
1402 | ASSERT(pAd->SharedKey[BSS0][0].CipherAlg <= CIPHER_CKIP128); | |
1403 | ||
1404 | // 4-way handshaking frame must be clear | |
1405 | if (!(TX_BLK_TEST_FLAG(pTxBlk, fTX_bClearEAPFrame)) && (pAd->SharedKey[BSS0][0].CipherAlg) && | |
1406 | (pAd->SharedKey[BSS0][0].KeyLen)) | |
1407 | { | |
1408 | CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg; | |
1409 | KeyIdx = 0; | |
1410 | } | |
1411 | } | |
1412 | else if (Cipher == Ndis802_11Encryption1Enabled) | |
1413 | { | |
91980990 GKH |
1414 | KeyIdx = pAd->StaCfg.DefaultKeyId; |
1415 | } | |
1416 | else if ((Cipher == Ndis802_11Encryption2Enabled) || | |
1417 | (Cipher == Ndis802_11Encryption3Enabled)) | |
1418 | { | |
1419 | if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))) // multicast | |
1420 | KeyIdx = pAd->StaCfg.DefaultKeyId; | |
1421 | else if (pAd->SharedKey[BSS0][0].KeyLen) | |
1422 | KeyIdx = 0; | |
1423 | else | |
1424 | KeyIdx = pAd->StaCfg.DefaultKeyId; | |
1425 | } | |
1426 | ||
1427 | if (KeyIdx == 0xff) | |
1428 | CipherAlg = CIPHER_NONE; | |
1429 | else if ((Cipher == Ndis802_11EncryptionDisabled) || (pAd->SharedKey[BSS0][KeyIdx].KeyLen == 0)) | |
1430 | CipherAlg = CIPHER_NONE; | |
91980990 GKH |
1431 | else if ( pAd->StaCfg.WpaSupplicantUP && |
1432 | (Cipher == Ndis802_11Encryption1Enabled) && | |
1433 | (pAd->StaCfg.IEEE8021X == TRUE) && | |
1434 | (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)) | |
1435 | CipherAlg = CIPHER_NONE; | |
91980990 GKH |
1436 | else |
1437 | { | |
1438 | //Header_802_11.FC.Wep = 1; | |
1439 | CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg; | |
1440 | pKey = &pAd->SharedKey[BSS0][KeyIdx]; | |
1441 | } | |
1442 | } | |
1443 | ||
1444 | pTxBlk->CipherAlg = CipherAlg; | |
1445 | pTxBlk->pKey = pKey; | |
1446 | } | |
1447 | ||
1448 | ||
1449 | VOID STABuildCommon802_11Header( | |
1450 | IN PRTMP_ADAPTER pAd, | |
1451 | IN TX_BLK *pTxBlk) | |
1452 | { | |
91980990 | 1453 | HEADER_802_11 *pHeader_802_11; |
91980990 GKH |
1454 | |
1455 | // | |
1456 | // MAKE A COMMON 802.11 HEADER | |
1457 | // | |
1458 | ||
1459 | // normal wlan header size : 24 octets | |
1460 | pTxBlk->MpduHeaderLen = sizeof(HEADER_802_11); | |
1461 | ||
1462 | pHeader_802_11 = (HEADER_802_11 *) &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; | |
1463 | ||
1464 | NdisZeroMemory(pHeader_802_11, sizeof(HEADER_802_11)); | |
1465 | ||
1466 | pHeader_802_11->FC.FrDs = 0; | |
1467 | pHeader_802_11->FC.Type = BTYPE_DATA; | |
1468 | pHeader_802_11->FC.SubType = ((TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) ? SUBTYPE_QDATA : SUBTYPE_DATA); | |
1469 | ||
91980990 GKH |
1470 | if (pTxBlk->pMacEntry) |
1471 | { | |
1472 | if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bForceNonQoS)) | |
1473 | { | |
1474 | pHeader_802_11->Sequence = pTxBlk->pMacEntry->NonQosDataSeq; | |
1475 | pTxBlk->pMacEntry->NonQosDataSeq = (pTxBlk->pMacEntry->NonQosDataSeq+1) & MAXSEQ; | |
1476 | } | |
1477 | else | |
1478 | { | |
91980990 GKH |
1479 | { |
1480 | pHeader_802_11->Sequence = pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority]; | |
1481 | pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority] = (pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority]+1) & MAXSEQ; | |
1482 | } | |
1483 | } | |
1484 | } | |
1485 | else | |
1486 | { | |
1487 | pHeader_802_11->Sequence = pAd->Sequence; | |
1488 | pAd->Sequence = (pAd->Sequence+1) & MAXSEQ; // next sequence | |
1489 | } | |
1490 | ||
1491 | pHeader_802_11->Frag = 0; | |
1492 | ||
1493 | pHeader_802_11->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData); | |
1494 | ||
1495 | { | |
1496 | if (INFRA_ON(pAd)) | |
1497 | { | |
91980990 GKH |
1498 | { |
1499 | COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid); | |
1500 | COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress); | |
1501 | COPY_MAC_ADDR(pHeader_802_11->Addr3, pTxBlk->pSrcBufHeader); | |
1502 | pHeader_802_11->FC.ToDs = 1; | |
1503 | } | |
1504 | } | |
1505 | else if (ADHOC_ON(pAd)) | |
1506 | { | |
1507 | COPY_MAC_ADDR(pHeader_802_11->Addr1, pTxBlk->pSrcBufHeader); | |
1508 | COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress); | |
1509 | COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid); | |
1510 | pHeader_802_11->FC.ToDs = 0; | |
1511 | } | |
1512 | } | |
1513 | ||
1514 | if (pTxBlk->CipherAlg != CIPHER_NONE) | |
1515 | pHeader_802_11->FC.Wep = 1; | |
1516 | ||
1517 | // ----------------------------------------------------------------- | |
1518 | // STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later. | |
1519 | // ----------------------------------------------------------------- | |
1520 | if (pAd->CommonCfg.bAPSDForcePowerSave) | |
1521 | pHeader_802_11->FC.PwrMgmt = PWR_SAVE; | |
1522 | else | |
1523 | pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE); | |
1524 | } | |
1525 | ||
91980990 GKH |
1526 | VOID STABuildCache802_11Header( |
1527 | IN RTMP_ADAPTER *pAd, | |
1528 | IN TX_BLK *pTxBlk, | |
1529 | IN UCHAR *pHeader) | |
1530 | { | |
1531 | MAC_TABLE_ENTRY *pMacEntry; | |
1532 | PHEADER_802_11 pHeader80211; | |
1533 | ||
1534 | pHeader80211 = (PHEADER_802_11)pHeader; | |
1535 | pMacEntry = pTxBlk->pMacEntry; | |
1536 | ||
1537 | // | |
1538 | // Update the cached 802.11 HEADER | |
1539 | // | |
1540 | ||
1541 | // normal wlan header size : 24 octets | |
1542 | pTxBlk->MpduHeaderLen = sizeof(HEADER_802_11); | |
1543 | ||
1544 | // More Bit | |
1545 | pHeader80211->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData); | |
1546 | ||
1547 | // Sequence | |
1548 | pHeader80211->Sequence = pMacEntry->TxSeq[pTxBlk->UserPriority]; | |
1549 | pMacEntry->TxSeq[pTxBlk->UserPriority] = (pMacEntry->TxSeq[pTxBlk->UserPriority]+1) & MAXSEQ; | |
1550 | ||
1551 | { | |
ca97b838 BZ |
1552 | // Check if the frame can be sent through DLS direct link interface |
1553 | // If packet can be sent through DLS, then force aggregation disable. (Hard to determine peer STA's capability) | |
1554 | ||
91980990 | 1555 | // The addr3 of normal packet send from DS is Dest Mac address. |
91980990 GKH |
1556 | if (ADHOC_ON(pAd)) |
1557 | COPY_MAC_ADDR(pHeader80211->Addr3, pAd->CommonCfg.Bssid); | |
1558 | else | |
1559 | COPY_MAC_ADDR(pHeader80211->Addr3, pTxBlk->pSrcBufHeader); | |
1560 | } | |
1561 | ||
1562 | // ----------------------------------------------------------------- | |
1563 | // STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later. | |
1564 | // ----------------------------------------------------------------- | |
1565 | if (pAd->CommonCfg.bAPSDForcePowerSave) | |
1566 | pHeader80211->FC.PwrMgmt = PWR_SAVE; | |
1567 | else | |
1568 | pHeader80211->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE); | |
1569 | } | |
91980990 GKH |
1570 | |
1571 | static inline PUCHAR STA_Build_ARalink_Frame_Header( | |
1572 | IN RTMP_ADAPTER *pAd, | |
1573 | IN TX_BLK *pTxBlk) | |
1574 | { | |
1575 | PUCHAR pHeaderBufPtr; | |
1576 | HEADER_802_11 *pHeader_802_11; | |
1577 | PNDIS_PACKET pNextPacket; | |
1578 | UINT32 nextBufLen; | |
1579 | PQUEUE_ENTRY pQEntry; | |
1580 | ||
1581 | STAFindCipherAlgorithm(pAd, pTxBlk); | |
1582 | STABuildCommon802_11Header(pAd, pTxBlk); | |
1583 | ||
1584 | ||
1585 | pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; | |
1586 | pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr; | |
1587 | ||
1588 | // steal "order" bit to mark "aggregation" | |
1589 | pHeader_802_11->FC.Order = 1; | |
1590 | ||
1591 | // skip common header | |
1592 | pHeaderBufPtr += pTxBlk->MpduHeaderLen; | |
1593 | ||
1594 | if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) | |
1595 | { | |
1596 | // | |
1597 | // build QOS Control bytes | |
1598 | // | |
1599 | *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F); | |
1600 | ||
1601 | *(pHeaderBufPtr+1) = 0; | |
1602 | pHeaderBufPtr +=2; | |
1603 | pTxBlk->MpduHeaderLen += 2; | |
1604 | } | |
1605 | ||
1606 | // padding at front of LLC header. LLC header should at 4-bytes aligment. | |
1607 | pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr; | |
ca97b838 | 1608 | pHeaderBufPtr = (PUCHAR)ROUND_UP(pHeaderBufPtr, 4); |
91980990 GKH |
1609 | pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen); |
1610 | ||
1611 | // For RA Aggregation, | |
1612 | // put the 2nd MSDU length(extra 2-byte field) after QOS_CONTROL in little endian format | |
1613 | pQEntry = pTxBlk->TxPacketList.Head; | |
ca97b838 | 1614 | pNextPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); |
91980990 GKH |
1615 | nextBufLen = GET_OS_PKT_LEN(pNextPacket); |
1616 | if (RTMP_GET_PACKET_VLAN(pNextPacket)) | |
1617 | nextBufLen -= LENGTH_802_1Q; | |
1618 | ||
1619 | *pHeaderBufPtr = (UCHAR)nextBufLen & 0xff; | |
1620 | *(pHeaderBufPtr+1) = (UCHAR)(nextBufLen >> 8); | |
1621 | ||
1622 | pHeaderBufPtr += 2; | |
1623 | pTxBlk->MpduHeaderLen += 2; | |
1624 | ||
1625 | return pHeaderBufPtr; | |
1626 | ||
1627 | } | |
1628 | ||
91980990 GKH |
1629 | static inline PUCHAR STA_Build_AMSDU_Frame_Header( |
1630 | IN RTMP_ADAPTER *pAd, | |
1631 | IN TX_BLK *pTxBlk) | |
1632 | { | |
1633 | PUCHAR pHeaderBufPtr;//, pSaveBufPtr; | |
1634 | HEADER_802_11 *pHeader_802_11; | |
1635 | ||
1636 | ||
1637 | STAFindCipherAlgorithm(pAd, pTxBlk); | |
1638 | STABuildCommon802_11Header(pAd, pTxBlk); | |
1639 | ||
1640 | pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; | |
1641 | pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr; | |
1642 | ||
1643 | // skip common header | |
1644 | pHeaderBufPtr += pTxBlk->MpduHeaderLen; | |
1645 | ||
1646 | // | |
1647 | // build QOS Control bytes | |
1648 | // | |
1649 | *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F); | |
1650 | ||
1651 | // | |
1652 | // A-MSDU packet | |
1653 | // | |
1654 | *pHeaderBufPtr |= 0x80; | |
1655 | ||
1656 | *(pHeaderBufPtr+1) = 0; | |
1657 | pHeaderBufPtr +=2; | |
1658 | pTxBlk->MpduHeaderLen += 2; | |
1659 | ||
1660 | //pSaveBufPtr = pHeaderBufPtr; | |
1661 | ||
1662 | // | |
1663 | // padding at front of LLC header | |
1664 | // LLC header should locate at 4-octets aligment | |
1665 | // | |
1666 | // @@@ MpduHeaderLen excluding padding @@@ | |
1667 | // | |
1668 | pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr; | |
ca97b838 | 1669 | pHeaderBufPtr = (PUCHAR) ROUND_UP(pHeaderBufPtr, 4); |
91980990 GKH |
1670 | pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen); |
1671 | ||
1672 | return pHeaderBufPtr; | |
1673 | ||
1674 | } | |
1675 | ||
1676 | ||
1677 | VOID STA_AMPDU_Frame_Tx( | |
1678 | IN PRTMP_ADAPTER pAd, | |
1679 | IN TX_BLK *pTxBlk) | |
1680 | { | |
1681 | HEADER_802_11 *pHeader_802_11; | |
1682 | PUCHAR pHeaderBufPtr; | |
1683 | USHORT FreeNumber; | |
1684 | MAC_TABLE_ENTRY *pMacEntry; | |
1685 | BOOLEAN bVLANPkt; | |
1686 | PQUEUE_ENTRY pQEntry; | |
1687 | ||
1688 | ASSERT(pTxBlk); | |
1689 | ||
1690 | while(pTxBlk->TxPacketList.Head) | |
1691 | { | |
1692 | pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); | |
1693 | pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); | |
1694 | if ( RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) | |
1695 | { | |
1696 | RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE); | |
1697 | continue; | |
1698 | } | |
1699 | ||
1700 | bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE); | |
1701 | ||
1702 | pMacEntry = pTxBlk->pMacEntry; | |
1703 | if (pMacEntry->isCached) | |
1704 | { | |
1705 | // NOTE: Please make sure the size of pMacEntry->CachedBuf[] is smaller than pTxBlk->HeaderBuf[]!!!! | |
1706 | NdisMoveMemory((PUCHAR)&pTxBlk->HeaderBuf[TXINFO_SIZE], (PUCHAR)&pMacEntry->CachedBuf[0], TXWI_SIZE + sizeof(HEADER_802_11)); | |
1707 | pHeaderBufPtr = (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]); | |
1708 | STABuildCache802_11Header(pAd, pTxBlk, pHeaderBufPtr); | |
1709 | } | |
1710 | else | |
1711 | { | |
1712 | STAFindCipherAlgorithm(pAd, pTxBlk); | |
1713 | STABuildCommon802_11Header(pAd, pTxBlk); | |
1714 | ||
1715 | pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; | |
1716 | } | |
1717 | ||
1718 | ||
1719 | pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr; | |
1720 | ||
1721 | // skip common header | |
1722 | pHeaderBufPtr += pTxBlk->MpduHeaderLen; | |
1723 | ||
1724 | // | |
1725 | // build QOS Control bytes | |
1726 | // | |
1727 | *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F); | |
1728 | *(pHeaderBufPtr+1) = 0; | |
1729 | pHeaderBufPtr +=2; | |
1730 | pTxBlk->MpduHeaderLen += 2; | |
1731 | ||
1732 | // | |
1733 | // build HTC+ | |
1734 | // HTC control filed following QoS field | |
1735 | // | |
1736 | if ((pAd->CommonCfg.bRdg == TRUE) && CLIENT_STATUS_TEST_FLAG(pTxBlk->pMacEntry, fCLIENT_STATUS_RDG_CAPABLE)) | |
1737 | { | |
1738 | if (pMacEntry->isCached == FALSE) | |
1739 | { | |
1740 | // mark HTC bit | |
1741 | pHeader_802_11->FC.Order = 1; | |
1742 | ||
1743 | NdisZeroMemory(pHeaderBufPtr, 4); | |
1744 | *(pHeaderBufPtr+3) |= 0x80; | |
1745 | } | |
1746 | pHeaderBufPtr += 4; | |
1747 | pTxBlk->MpduHeaderLen += 4; | |
1748 | } | |
1749 | ||
1750 | //pTxBlk->MpduHeaderLen = pHeaderBufPtr - pTxBlk->HeaderBuf - TXWI_SIZE - TXINFO_SIZE; | |
1751 | ASSERT(pTxBlk->MpduHeaderLen >= 24); | |
1752 | ||
1753 | // skip 802.3 header | |
1754 | pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3; | |
1755 | pTxBlk->SrcBufLen -= LENGTH_802_3; | |
1756 | ||
1757 | // skip vlan tag | |
1758 | if (bVLANPkt) | |
1759 | { | |
1760 | pTxBlk->pSrcBufData += LENGTH_802_1Q; | |
1761 | pTxBlk->SrcBufLen -= LENGTH_802_1Q; | |
1762 | } | |
1763 | ||
1764 | // | |
1765 | // padding at front of LLC header | |
1766 | // LLC header should locate at 4-octets aligment | |
1767 | // | |
1768 | // @@@ MpduHeaderLen excluding padding @@@ | |
1769 | // | |
1770 | pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr; | |
ca97b838 | 1771 | pHeaderBufPtr = (PUCHAR) ROUND_UP(pHeaderBufPtr, 4); |
91980990 GKH |
1772 | pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen); |
1773 | ||
1774 | { | |
1775 | ||
1776 | // | |
1777 | // Insert LLC-SNAP encapsulation - 8 octets | |
1778 | // | |
1779 | EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap); | |
1780 | if (pTxBlk->pExtraLlcSnapEncap) | |
1781 | { | |
1782 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6); | |
1783 | pHeaderBufPtr += 6; | |
1784 | // get 2 octets (TypeofLen) | |
1785 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2); | |
1786 | pHeaderBufPtr += 2; | |
1787 | pTxBlk->MpduHeaderLen += LENGTH_802_1_H; | |
1788 | } | |
1789 | ||
1790 | } | |
1791 | ||
1792 | if (pMacEntry->isCached) | |
1793 | { | |
1794 | RTMPWriteTxWI_Cache(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk); | |
1795 | } | |
1796 | else | |
1797 | { | |
1798 | RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk); | |
1799 | ||
1800 | NdisZeroMemory((PUCHAR)(&pMacEntry->CachedBuf[0]), sizeof(pMacEntry->CachedBuf)); | |
1801 | NdisMoveMemory((PUCHAR)(&pMacEntry->CachedBuf[0]), (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), (pHeaderBufPtr - (PUCHAR)(&pTxBlk->HeaderBuf[TXINFO_SIZE]))); | |
1802 | pMacEntry->isCached = TRUE; | |
1803 | } | |
1804 | ||
1805 | // calculate Transmitted AMPDU count and ByteCount | |
1806 | { | |
1807 | pAd->RalinkCounters.TransmittedMPDUsInAMPDUCount.u.LowPart ++; | |
1808 | pAd->RalinkCounters.TransmittedOctetsInAMPDUCount.QuadPart += pTxBlk->SrcBufLen; | |
1809 | } | |
1810 | ||
1811 | //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx); | |
1812 | ||
1813 | HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber); | |
1814 | ||
1815 | // | |
1816 | // Kick out Tx | |
1817 | // | |
ed291e80 AM |
1818 | if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX)) |
1819 | HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx); | |
91980990 GKH |
1820 | |
1821 | pAd->RalinkCounters.KickTxCount++; | |
1822 | pAd->RalinkCounters.OneSecTxDoneCount++; | |
1823 | } | |
1824 | ||
1825 | } | |
1826 | ||
1827 | ||
1828 | VOID STA_AMSDU_Frame_Tx( | |
1829 | IN PRTMP_ADAPTER pAd, | |
1830 | IN TX_BLK *pTxBlk) | |
1831 | { | |
1832 | PUCHAR pHeaderBufPtr; | |
1833 | USHORT FreeNumber; | |
1834 | USHORT subFramePayloadLen = 0; // AMSDU Subframe length without AMSDU-Header / Padding. | |
1835 | USHORT totalMPDUSize=0; | |
1836 | UCHAR *subFrameHeader; | |
1837 | UCHAR padding = 0; | |
1838 | USHORT FirstTx = 0, LastTxIdx = 0; | |
1839 | BOOLEAN bVLANPkt; | |
1840 | int frameNum = 0; | |
1841 | PQUEUE_ENTRY pQEntry; | |
1842 | ||
1843 | ||
1844 | ASSERT(pTxBlk); | |
1845 | ||
1846 | ASSERT((pTxBlk->TxPacketList.Number > 1)); | |
1847 | ||
1848 | while(pTxBlk->TxPacketList.Head) | |
1849 | { | |
1850 | pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); | |
1851 | pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); | |
1852 | if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) | |
1853 | { | |
1854 | RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE); | |
1855 | continue; | |
1856 | } | |
1857 | ||
1858 | bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE); | |
1859 | ||
1860 | // skip 802.3 header | |
1861 | pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3; | |
1862 | pTxBlk->SrcBufLen -= LENGTH_802_3; | |
1863 | ||
1864 | // skip vlan tag | |
1865 | if (bVLANPkt) | |
1866 | { | |
1867 | pTxBlk->pSrcBufData += LENGTH_802_1Q; | |
1868 | pTxBlk->SrcBufLen -= LENGTH_802_1Q; | |
1869 | } | |
1870 | ||
1871 | if (frameNum == 0) | |
1872 | { | |
1873 | pHeaderBufPtr = STA_Build_AMSDU_Frame_Header(pAd, pTxBlk); | |
1874 | ||
1875 | // NOTE: TxWI->MPDUtotalByteCount will be updated after final frame was handled. | |
1876 | RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk); | |
1877 | } | |
1878 | else | |
1879 | { | |
1880 | pHeaderBufPtr = &pTxBlk->HeaderBuf[0]; | |
1881 | padding = ROUND_UP(LENGTH_AMSDU_SUBFRAMEHEAD + subFramePayloadLen, 4) - (LENGTH_AMSDU_SUBFRAMEHEAD + subFramePayloadLen); | |
1882 | NdisZeroMemory(pHeaderBufPtr, padding + LENGTH_AMSDU_SUBFRAMEHEAD); | |
1883 | pHeaderBufPtr += padding; | |
1884 | pTxBlk->MpduHeaderLen = padding; | |
1885 | } | |
1886 | ||
1887 | // | |
1888 | // A-MSDU subframe | |
1889 | // DA(6)+SA(6)+Length(2) + LLC/SNAP Encap | |
1890 | // | |
1891 | subFrameHeader = pHeaderBufPtr; | |
1892 | subFramePayloadLen = pTxBlk->SrcBufLen; | |
1893 | ||
1894 | NdisMoveMemory(subFrameHeader, pTxBlk->pSrcBufHeader, 12); | |
1895 | ||
1896 | ||
1897 | pHeaderBufPtr += LENGTH_AMSDU_SUBFRAMEHEAD; | |
1898 | pTxBlk->MpduHeaderLen += LENGTH_AMSDU_SUBFRAMEHEAD; | |
1899 | ||
1900 | ||
1901 | // | |
1902 | // Insert LLC-SNAP encapsulation - 8 octets | |
1903 | // | |
1904 | EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap); | |
1905 | ||
1906 | subFramePayloadLen = pTxBlk->SrcBufLen; | |
1907 | ||
1908 | if (pTxBlk->pExtraLlcSnapEncap) | |
1909 | { | |
1910 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6); | |
1911 | pHeaderBufPtr += 6; | |
1912 | // get 2 octets (TypeofLen) | |
1913 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2); | |
1914 | pHeaderBufPtr += 2; | |
1915 | pTxBlk->MpduHeaderLen += LENGTH_802_1_H; | |
1916 | subFramePayloadLen += LENGTH_802_1_H; | |
1917 | } | |
1918 | ||
1919 | // update subFrame Length field | |
1920 | subFrameHeader[12] = (subFramePayloadLen & 0xFF00) >> 8; | |
1921 | subFrameHeader[13] = subFramePayloadLen & 0xFF; | |
1922 | ||
1923 | totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen; | |
1924 | ||
1925 | if (frameNum ==0) | |
1926 | FirstTx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber); | |
1927 | else | |
1928 | LastTxIdx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber); | |
1929 | ||
1930 | frameNum++; | |
1931 | ||
1932 | pAd->RalinkCounters.KickTxCount++; | |
1933 | pAd->RalinkCounters.OneSecTxDoneCount++; | |
1934 | ||
1935 | // calculate Transmitted AMSDU Count and ByteCount | |
1936 | { | |
1937 | pAd->RalinkCounters.TransmittedAMSDUCount.u.LowPart ++; | |
1938 | pAd->RalinkCounters.TransmittedOctetsInAMSDU.QuadPart += totalMPDUSize; | |
1939 | } | |
1940 | ||
1941 | } | |
1942 | ||
1943 | HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx); | |
1944 | HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx); | |
1945 | ||
1946 | // | |
1947 | // Kick out Tx | |
1948 | // | |
ed291e80 AM |
1949 | if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX)) |
1950 | HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx); | |
91980990 | 1951 | } |
91980990 GKH |
1952 | |
1953 | VOID STA_Legacy_Frame_Tx( | |
1954 | IN PRTMP_ADAPTER pAd, | |
1955 | IN TX_BLK *pTxBlk) | |
1956 | { | |
1957 | HEADER_802_11 *pHeader_802_11; | |
1958 | PUCHAR pHeaderBufPtr; | |
1959 | USHORT FreeNumber; | |
1960 | BOOLEAN bVLANPkt; | |
1961 | PQUEUE_ENTRY pQEntry; | |
1962 | ||
1963 | ASSERT(pTxBlk); | |
1964 | ||
1965 | ||
1966 | pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); | |
1967 | pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); | |
1968 | if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) | |
1969 | { | |
1970 | RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE); | |
1971 | return; | |
1972 | } | |
1973 | ||
1974 | if (pTxBlk->TxFrameType == TX_MCAST_FRAME) | |
1975 | { | |
1976 | INC_COUNTER64(pAd->WlanCounters.MulticastTransmittedFrameCount); | |
1977 | } | |
1978 | ||
1979 | if (RTMP_GET_PACKET_RTS(pTxBlk->pPacket)) | |
1980 | TX_BLK_SET_FLAG(pTxBlk, fTX_bRtsRequired); | |
1981 | else | |
1982 | TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bRtsRequired); | |
1983 | ||
1984 | bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE); | |
1985 | ||
1986 | if (pTxBlk->TxRate < pAd->CommonCfg.MinTxRate) | |
1987 | pTxBlk->TxRate = pAd->CommonCfg.MinTxRate; | |
1988 | ||
1989 | STAFindCipherAlgorithm(pAd, pTxBlk); | |
1990 | STABuildCommon802_11Header(pAd, pTxBlk); | |
1991 | ||
1992 | ||
1993 | // skip 802.3 header | |
1994 | pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3; | |
1995 | pTxBlk->SrcBufLen -= LENGTH_802_3; | |
1996 | ||
1997 | // skip vlan tag | |
1998 | if (bVLANPkt) | |
1999 | { | |
2000 | pTxBlk->pSrcBufData += LENGTH_802_1Q; | |
2001 | pTxBlk->SrcBufLen -= LENGTH_802_1Q; | |
2002 | } | |
2003 | ||
2004 | pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; | |
2005 | pHeader_802_11 = (HEADER_802_11 *) pHeaderBufPtr; | |
2006 | ||
2007 | // skip common header | |
2008 | pHeaderBufPtr += pTxBlk->MpduHeaderLen; | |
2009 | ||
2010 | if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) | |
2011 | { | |
2012 | // | |
2013 | // build QOS Control bytes | |
2014 | // | |
ca97b838 | 2015 | *(pHeaderBufPtr) = ((pTxBlk->UserPriority & 0x0F) | (pAd->CommonCfg.AckPolicy[pTxBlk->QueIdx]<<5)); |
91980990 GKH |
2016 | *(pHeaderBufPtr+1) = 0; |
2017 | pHeaderBufPtr +=2; | |
2018 | pTxBlk->MpduHeaderLen += 2; | |
2019 | } | |
2020 | ||
2021 | // The remaining content of MPDU header should locate at 4-octets aligment | |
2022 | pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr; | |
ca97b838 | 2023 | pHeaderBufPtr = (PUCHAR) ROUND_UP(pHeaderBufPtr, 4); |
91980990 GKH |
2024 | pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen); |
2025 | ||
2026 | { | |
2027 | ||
2028 | // | |
2029 | // Insert LLC-SNAP encapsulation - 8 octets | |
2030 | // | |
2031 | // | |
2032 | // if original Ethernet frame contains no LLC/SNAP, | |
2033 | // then an extra LLC/SNAP encap is required | |
2034 | // | |
2035 | EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, pTxBlk->pExtraLlcSnapEncap); | |
2036 | if (pTxBlk->pExtraLlcSnapEncap) | |
2037 | { | |
2038 | UCHAR vlan_size; | |
2039 | ||
2040 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6); | |
2041 | pHeaderBufPtr += 6; | |
2042 | // skip vlan tag | |
2043 | vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0; | |
2044 | // get 2 octets (TypeofLen) | |
2045 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader+12+vlan_size, 2); | |
2046 | pHeaderBufPtr += 2; | |
2047 | pTxBlk->MpduHeaderLen += LENGTH_802_1_H; | |
2048 | } | |
2049 | ||
2050 | } | |
2051 | ||
2052 | // | |
2053 | // prepare for TXWI | |
2054 | // use Wcid as Key Index | |
2055 | // | |
2056 | ||
2057 | RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk); | |
2058 | ||
2059 | //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx); | |
2060 | ||
2061 | HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber); | |
2062 | ||
2063 | pAd->RalinkCounters.KickTxCount++; | |
2064 | pAd->RalinkCounters.OneSecTxDoneCount++; | |
2065 | ||
2066 | // | |
2067 | // Kick out Tx | |
2068 | // | |
ed291e80 AM |
2069 | if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX)) |
2070 | HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx); | |
91980990 GKH |
2071 | } |
2072 | ||
2073 | ||
2074 | VOID STA_ARalink_Frame_Tx( | |
2075 | IN PRTMP_ADAPTER pAd, | |
2076 | IN TX_BLK *pTxBlk) | |
2077 | { | |
2078 | PUCHAR pHeaderBufPtr; | |
2079 | USHORT FreeNumber; | |
2080 | USHORT totalMPDUSize=0; | |
2081 | USHORT FirstTx, LastTxIdx; | |
2082 | int frameNum = 0; | |
2083 | BOOLEAN bVLANPkt; | |
2084 | PQUEUE_ENTRY pQEntry; | |
2085 | ||
2086 | ||
2087 | ASSERT(pTxBlk); | |
2088 | ||
2089 | ASSERT((pTxBlk->TxPacketList.Number== 2)); | |
2090 | ||
2091 | ||
2092 | FirstTx = LastTxIdx = 0; // Is it ok init they as 0? | |
2093 | while(pTxBlk->TxPacketList.Head) | |
2094 | { | |
2095 | pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); | |
2096 | pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); | |
2097 | ||
2098 | if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) | |
2099 | { | |
2100 | RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE); | |
2101 | continue; | |
2102 | } | |
2103 | ||
2104 | bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE); | |
2105 | ||
2106 | // skip 802.3 header | |
2107 | pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3; | |
2108 | pTxBlk->SrcBufLen -= LENGTH_802_3; | |
2109 | ||
2110 | // skip vlan tag | |
2111 | if (bVLANPkt) | |
2112 | { | |
2113 | pTxBlk->pSrcBufData += LENGTH_802_1Q; | |
2114 | pTxBlk->SrcBufLen -= LENGTH_802_1Q; | |
2115 | } | |
2116 | ||
2117 | if (frameNum == 0) | |
2118 | { // For first frame, we need to create the 802.11 header + padding(optional) + RA-AGG-LEN + SNAP Header | |
2119 | ||
2120 | pHeaderBufPtr = STA_Build_ARalink_Frame_Header(pAd, pTxBlk); | |
2121 | ||
2122 | // It's ok write the TxWI here, because the TxWI->MPDUtotalByteCount | |
2123 | // will be updated after final frame was handled. | |
2124 | RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk); | |
2125 | ||
2126 | ||
2127 | // | |
2128 | // Insert LLC-SNAP encapsulation - 8 octets | |
2129 | // | |
2130 | EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData-2, pTxBlk->pExtraLlcSnapEncap); | |
2131 | ||
2132 | if (pTxBlk->pExtraLlcSnapEncap) | |
2133 | { | |
2134 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6); | |
2135 | pHeaderBufPtr += 6; | |
2136 | // get 2 octets (TypeofLen) | |
2137 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2); | |
2138 | pHeaderBufPtr += 2; | |
2139 | pTxBlk->MpduHeaderLen += LENGTH_802_1_H; | |
2140 | } | |
2141 | } | |
2142 | else | |
2143 | { // For second aggregated frame, we need create the 802.3 header to headerBuf, because PCI will copy it to SDPtr0. | |
2144 | ||
2145 | pHeaderBufPtr = &pTxBlk->HeaderBuf[0]; | |
2146 | pTxBlk->MpduHeaderLen = 0; | |
2147 | ||
2148 | // A-Ralink sub-sequent frame header is the same as 802.3 header. | |
2149 | // DA(6)+SA(6)+FrameType(2) | |
2150 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader, 12); | |
2151 | pHeaderBufPtr += 12; | |
2152 | // get 2 octets (TypeofLen) | |
2153 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData-2, 2); | |
2154 | pHeaderBufPtr += 2; | |
2155 | pTxBlk->MpduHeaderLen = LENGTH_ARALINK_SUBFRAMEHEAD; | |
2156 | } | |
2157 | ||
2158 | totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen; | |
2159 | ||
2160 | //FreeNumber = GET_TXRING_FREENO(pAd, QueIdx); | |
2161 | if (frameNum ==0) | |
2162 | FirstTx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber); | |
2163 | else | |
2164 | LastTxIdx = HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, &FreeNumber); | |
2165 | ||
2166 | frameNum++; | |
2167 | ||
2168 | pAd->RalinkCounters.OneSecTxAggregationCount++; | |
2169 | pAd->RalinkCounters.KickTxCount++; | |
2170 | pAd->RalinkCounters.OneSecTxDoneCount++; | |
2171 | ||
2172 | } | |
2173 | ||
2174 | HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx); | |
2175 | HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx); | |
2176 | ||
2177 | // | |
2178 | // Kick out Tx | |
2179 | // | |
ed291e80 AM |
2180 | if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX)) |
2181 | HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx); | |
91980990 GKH |
2182 | |
2183 | } | |
2184 | ||
2185 | ||
2186 | VOID STA_Fragment_Frame_Tx( | |
2187 | IN RTMP_ADAPTER *pAd, | |
2188 | IN TX_BLK *pTxBlk) | |
2189 | { | |
2190 | HEADER_802_11 *pHeader_802_11; | |
2191 | PUCHAR pHeaderBufPtr; | |
2192 | USHORT FreeNumber; | |
2193 | UCHAR fragNum = 0; | |
2194 | PACKET_INFO PacketInfo; | |
2195 | USHORT EncryptionOverhead = 0; | |
2196 | UINT32 FreeMpduSize, SrcRemainingBytes; | |
2197 | USHORT AckDuration; | |
2198 | UINT NextMpduSize; | |
2199 | BOOLEAN bVLANPkt; | |
2200 | PQUEUE_ENTRY pQEntry; | |
ca97b838 | 2201 | HTTRANSMIT_SETTING *pTransmit; |
91980990 GKH |
2202 | |
2203 | ||
2204 | ASSERT(pTxBlk); | |
2205 | ||
2206 | pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); | |
2207 | pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); | |
2208 | if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) | |
2209 | { | |
2210 | RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE); | |
2211 | return; | |
2212 | } | |
2213 | ||
2214 | ASSERT(TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag)); | |
2215 | bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE); | |
2216 | ||
2217 | STAFindCipherAlgorithm(pAd, pTxBlk); | |
2218 | STABuildCommon802_11Header(pAd, pTxBlk); | |
2219 | ||
2220 | if (pTxBlk->CipherAlg == CIPHER_TKIP) | |
2221 | { | |
2222 | pTxBlk->pPacket = duplicate_pkt_with_TKIP_MIC(pAd, pTxBlk->pPacket); | |
2223 | if (pTxBlk->pPacket == NULL) | |
2224 | return; | |
2225 | RTMP_QueryPacketInfo(pTxBlk->pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader, &pTxBlk->SrcBufLen); | |
2226 | } | |
2227 | ||
2228 | // skip 802.3 header | |
2229 | pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3; | |
2230 | pTxBlk->SrcBufLen -= LENGTH_802_3; | |
2231 | ||
2232 | ||
2233 | // skip vlan tag | |
2234 | if (bVLANPkt) | |
2235 | { | |
2236 | pTxBlk->pSrcBufData += LENGTH_802_1Q; | |
2237 | pTxBlk->SrcBufLen -= LENGTH_802_1Q; | |
2238 | } | |
2239 | ||
2240 | pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; | |
2241 | pHeader_802_11 = (HEADER_802_11 *)pHeaderBufPtr; | |
2242 | ||
2243 | ||
2244 | // skip common header | |
2245 | pHeaderBufPtr += pTxBlk->MpduHeaderLen; | |
2246 | ||
2247 | if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) | |
2248 | { | |
2249 | // | |
2250 | // build QOS Control bytes | |
2251 | // | |
2252 | *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F); | |
2253 | ||
2254 | *(pHeaderBufPtr+1) = 0; | |
2255 | pHeaderBufPtr +=2; | |
2256 | pTxBlk->MpduHeaderLen += 2; | |
2257 | } | |
2258 | ||
2259 | // | |
2260 | // padding at front of LLC header | |
2261 | // LLC header should locate at 4-octets aligment | |
2262 | // | |
2263 | pTxBlk->HdrPadLen = (ULONG)pHeaderBufPtr; | |
ca97b838 | 2264 | pHeaderBufPtr = (PUCHAR) ROUND_UP(pHeaderBufPtr, 4); |
91980990 GKH |
2265 | pTxBlk->HdrPadLen = (ULONG)(pHeaderBufPtr - pTxBlk->HdrPadLen); |
2266 | ||
2267 | ||
2268 | ||
2269 | // | |
2270 | // Insert LLC-SNAP encapsulation - 8 octets | |
2271 | // | |
2272 | // | |
2273 | // if original Ethernet frame contains no LLC/SNAP, | |
2274 | // then an extra LLC/SNAP encap is required | |
2275 | // | |
2276 | EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, pTxBlk->pExtraLlcSnapEncap); | |
2277 | if (pTxBlk->pExtraLlcSnapEncap) | |
2278 | { | |
2279 | UCHAR vlan_size; | |
2280 | ||
2281 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6); | |
2282 | pHeaderBufPtr += 6; | |
2283 | // skip vlan tag | |
2284 | vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0; | |
2285 | // get 2 octets (TypeofLen) | |
2286 | NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader+12+vlan_size, 2); | |
2287 | pHeaderBufPtr += 2; | |
2288 | pTxBlk->MpduHeaderLen += LENGTH_802_1_H; | |
2289 | } | |
2290 | ||
2291 | ||
2292 | // If TKIP is used and fragmentation is required. Driver has to | |
2293 | // append TKIP MIC at tail of the scatter buffer | |
2294 | // MAC ASIC will only perform IV/EIV/ICV insertion but no TKIP MIC | |
2295 | if (pTxBlk->CipherAlg == CIPHER_TKIP) | |
2296 | { | |
ca97b838 | 2297 | RTMPCalculateMICValue(pAd, pTxBlk->pPacket, pTxBlk->pExtraLlcSnapEncap, pTxBlk->pKey, 0); |
91980990 GKH |
2298 | |
2299 | // NOTE: DON'T refer the skb->len directly after following copy. Becasue the length is not adjust | |
2300 | // to correct lenght, refer to pTxBlk->SrcBufLen for the packet length in following progress. | |
2301 | NdisMoveMemory(pTxBlk->pSrcBufData + pTxBlk->SrcBufLen, &pAd->PrivateInfo.Tx.MIC[0], 8); | |
2302 | //skb_put((RTPKT_TO_OSPKT(pTxBlk->pPacket))->tail, 8); | |
2303 | pTxBlk->SrcBufLen += 8; | |
2304 | pTxBlk->TotalFrameLen += 8; | |
2305 | pTxBlk->CipherAlg = CIPHER_TKIP_NO_MIC; | |
2306 | } | |
2307 | ||
2308 | // | |
2309 | // calcuate the overhead bytes that encryption algorithm may add. This | |
2310 | // affects the calculate of "duration" field | |
2311 | // | |
2312 | if ((pTxBlk->CipherAlg == CIPHER_WEP64) || (pTxBlk->CipherAlg == CIPHER_WEP128)) | |
2313 | EncryptionOverhead = 8; //WEP: IV[4] + ICV[4]; | |
2314 | else if (pTxBlk->CipherAlg == CIPHER_TKIP_NO_MIC) | |
2315 | EncryptionOverhead = 12;//TKIP: IV[4] + EIV[4] + ICV[4], MIC will be added to TotalPacketLength | |
2316 | else if (pTxBlk->CipherAlg == CIPHER_TKIP) | |
2317 | EncryptionOverhead = 20;//TKIP: IV[4] + EIV[4] + ICV[4] + MIC[8] | |
2318 | else if (pTxBlk->CipherAlg == CIPHER_AES) | |
2319 | EncryptionOverhead = 16; // AES: IV[4] + EIV[4] + MIC[8] | |
2320 | else | |
2321 | EncryptionOverhead = 0; | |
2322 | ||
ca97b838 BZ |
2323 | pTransmit = pTxBlk->pTransmit; |
2324 | // Decide the TX rate | |
2325 | if (pTransmit->field.MODE == MODE_CCK) | |
2326 | pTxBlk->TxRate = pTransmit->field.MCS; | |
2327 | else if (pTransmit->field.MODE == MODE_OFDM) | |
2328 | pTxBlk->TxRate = pTransmit->field.MCS + RATE_FIRST_OFDM_RATE; | |
2329 | else | |
2330 | pTxBlk->TxRate = RATE_6_5; | |
2331 | ||
91980990 | 2332 | // decide how much time an ACK/CTS frame will consume in the air |
ca97b838 | 2333 | if (pTxBlk->TxRate <= RATE_LAST_OFDM_RATE) |
91980990 | 2334 | AckDuration = RTMPCalcDuration(pAd, pAd->CommonCfg.ExpectedACKRate[pTxBlk->TxRate], 14); |
ca97b838 BZ |
2335 | else |
2336 | AckDuration = RTMPCalcDuration(pAd, RATE_6_5, 14); | |
91980990 GKH |
2337 | |
2338 | // Init the total payload length of this frame. | |
2339 | SrcRemainingBytes = pTxBlk->SrcBufLen; | |
2340 | ||
2341 | pTxBlk->TotalFragNum = 0xff; | |
2342 | ||
2343 | do { | |
2344 | ||
2345 | FreeMpduSize = pAd->CommonCfg.FragmentThreshold - LENGTH_CRC; | |
2346 | ||
2347 | FreeMpduSize -= pTxBlk->MpduHeaderLen; | |
2348 | ||
2349 | if (SrcRemainingBytes <= FreeMpduSize) | |
2350 | { // this is the last or only fragment | |
2351 | ||
2352 | pTxBlk->SrcBufLen = SrcRemainingBytes; | |
2353 | ||
2354 | pHeader_802_11->FC.MoreFrag = 0; | |
2355 | pHeader_802_11->Duration = pAd->CommonCfg.Dsifs + AckDuration; | |
2356 | ||
2357 | // Indicate the lower layer that this's the last fragment. | |
2358 | pTxBlk->TotalFragNum = fragNum; | |
2359 | } | |
2360 | else | |
2361 | { // more fragment is required | |
2362 | ||
2363 | pTxBlk->SrcBufLen = FreeMpduSize; | |
2364 | ||
2365 | NextMpduSize = min(((UINT)SrcRemainingBytes - pTxBlk->SrcBufLen), ((UINT)pAd->CommonCfg.FragmentThreshold)); | |
2366 | pHeader_802_11->FC.MoreFrag = 1; | |
2367 | pHeader_802_11->Duration = (3 * pAd->CommonCfg.Dsifs) + (2 * AckDuration) + RTMPCalcDuration(pAd, pTxBlk->TxRate, NextMpduSize + EncryptionOverhead); | |
2368 | } | |
2369 | ||
2370 | if (fragNum == 0) | |
2371 | pTxBlk->FrameGap = IFS_HTTXOP; | |
2372 | else | |
2373 | pTxBlk->FrameGap = IFS_SIFS; | |
2374 | ||
2375 | RTMPWriteTxWI_Data(pAd, (PTXWI_STRUC)(&pTxBlk->HeaderBuf[TXINFO_SIZE]), pTxBlk); | |
2376 | ||
2377 | HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, &FreeNumber); | |
2378 | ||
2379 | pAd->RalinkCounters.KickTxCount++; | |
2380 | pAd->RalinkCounters.OneSecTxDoneCount++; | |
2381 | ||
2382 | // Update the frame number, remaining size of the NDIS packet payload. | |
2383 | ||
2384 | // space for 802.11 header. | |
2385 | if (fragNum == 0 && pTxBlk->pExtraLlcSnapEncap) | |
2386 | pTxBlk->MpduHeaderLen -= LENGTH_802_1_H; | |
2387 | ||
2388 | fragNum++; | |
2389 | SrcRemainingBytes -= pTxBlk->SrcBufLen; | |
2390 | pTxBlk->pSrcBufData += pTxBlk->SrcBufLen; | |
2391 | ||
2392 | pHeader_802_11->Frag++; // increase Frag # | |
2393 | ||
2394 | }while(SrcRemainingBytes > 0); | |
2395 | ||
2396 | // | |
2397 | // Kick out Tx | |
2398 | // | |
ca97b838 | 2399 | if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX)) |
91980990 GKH |
2400 | HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx); |
2401 | } | |
2402 | ||
2403 | ||
2404 | #define RELEASE_FRAMES_OF_TXBLK(_pAd, _pTxBlk, _pQEntry, _Status) \ | |
2405 | while(_pTxBlk->TxPacketList.Head) \ | |
2406 | { \ | |
2407 | _pQEntry = RemoveHeadQueue(&_pTxBlk->TxPacketList); \ | |
2408 | RELEASE_NDIS_PACKET(_pAd, QUEUE_ENTRY_TO_PACKET(_pQEntry), _Status); \ | |
2409 | } | |
2410 | ||
2411 | ||
2412 | /* | |
2413 | ======================================================================== | |
2414 | ||
2415 | Routine Description: | |
2416 | Copy frame from waiting queue into relative ring buffer and set | |
2417 | appropriate ASIC register to kick hardware encryption before really | |
2418 | sent out to air. | |
2419 | ||
2420 | Arguments: | |
2421 | pAd Pointer to our adapter | |
2422 | PNDIS_PACKET Pointer to outgoing Ndis frame | |
2423 | NumberOfFrag Number of fragment required | |
2424 | ||
2425 | Return Value: | |
2426 | None | |
2427 | ||
2428 | IRQL = DISPATCH_LEVEL | |
2429 | ||
2430 | Note: | |
2431 | ||
2432 | ======================================================================== | |
2433 | */ | |
2434 | NDIS_STATUS STAHardTransmit( | |
2435 | IN PRTMP_ADAPTER pAd, | |
2436 | IN TX_BLK *pTxBlk, | |
2437 | IN UCHAR QueIdx) | |
2438 | { | |
2439 | NDIS_PACKET *pPacket; | |
2440 | PQUEUE_ENTRY pQEntry; | |
2441 | ||
2442 | // --------------------------------------------- | |
2443 | // STEP 0. DO SANITY CHECK AND SOME EARLY PREPARATION. | |
2444 | // --------------------------------------------- | |
2445 | // | |
2446 | ASSERT(pTxBlk->TxPacketList.Number); | |
2447 | if (pTxBlk->TxPacketList.Head == NULL) | |
2448 | { | |
2449 | DBGPRINT(RT_DEBUG_ERROR, ("pTxBlk->TotalFrameNum == %ld!\n", pTxBlk->TxPacketList.Number)); | |
2450 | return NDIS_STATUS_FAILURE; | |
2451 | } | |
2452 | ||
2453 | pPacket = QUEUE_ENTRY_TO_PACKET(pTxBlk->TxPacketList.Head); | |
2454 | ||
91980990 GKH |
2455 | // ------------------------------------------------------------------ |
2456 | // STEP 1. WAKE UP PHY | |
2457 | // outgoing frame always wakeup PHY to prevent frame lost and | |
2458 | // turn off PSM bit to improve performance | |
2459 | // ------------------------------------------------------------------ | |
2460 | // not to change PSM bit, just send this frame out? | |
2461 | if ((pAd->StaCfg.Psm == PWR_SAVE) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) | |
2462 | { | |
ca97b838 BZ |
2463 | DBGPRINT_RAW(RT_DEBUG_INFO, ("AsicForceWakeup At HardTx\n")); |
2464 | #ifdef RTMP_MAC_PCI | |
5f5d2df8 | 2465 | AsicForceWakeup(pAd, TRUE); |
ca97b838 BZ |
2466 | #endif // RTMP_MAC_PCI // |
2467 | #ifdef RTMP_MAC_USB | |
2468 | RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_FORCE_WAKE_UP, NULL, 0); | |
2469 | #endif // RTMP_MAC_USB // | |
91980990 GKH |
2470 | } |
2471 | ||
2472 | // It should not change PSM bit, when APSD turn on. | |
2473 | if ((!(pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable) && (pAd->CommonCfg.bAPSDForcePowerSave == FALSE)) | |
2474 | || (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket)) | |
2475 | || (RTMP_GET_PACKET_WAI(pTxBlk->pPacket))) | |
2476 | { | |
2477 | if ((pAd->StaCfg.Psm == PWR_SAVE) && | |
2478 | (pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP)) | |
ca97b838 | 2479 | RTMP_SET_PSM_BIT(pAd, PWR_ACTIVE); |
91980990 GKH |
2480 | } |
2481 | ||
2482 | switch (pTxBlk->TxFrameType) | |
2483 | { | |
91980990 GKH |
2484 | case TX_AMPDU_FRAME: |
2485 | STA_AMPDU_Frame_Tx(pAd, pTxBlk); | |
2486 | break; | |
2487 | case TX_AMSDU_FRAME: | |
2488 | STA_AMSDU_Frame_Tx(pAd, pTxBlk); | |
2489 | break; | |
91980990 GKH |
2490 | case TX_LEGACY_FRAME: |
2491 | STA_Legacy_Frame_Tx(pAd, pTxBlk); | |
2492 | break; | |
2493 | case TX_MCAST_FRAME: | |
2494 | STA_Legacy_Frame_Tx(pAd, pTxBlk); | |
2495 | break; | |
2496 | case TX_RALINK_FRAME: | |
2497 | STA_ARalink_Frame_Tx(pAd, pTxBlk); | |
2498 | break; | |
2499 | case TX_FRAG_FRAME: | |
2500 | STA_Fragment_Frame_Tx(pAd, pTxBlk); | |
2501 | break; | |
2502 | default: | |
2503 | { | |
2504 | // It should not happened! | |
2505 | DBGPRINT(RT_DEBUG_ERROR, ("Send a pacekt was not classified!! It should not happen!\n")); | |
2506 | while(pTxBlk->TxPacketList.Number) | |
2507 | { | |
2508 | pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); | |
2509 | pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); | |
2510 | if (pPacket) | |
2511 | RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); | |
2512 | } | |
2513 | } | |
2514 | break; | |
2515 | } | |
2516 | ||
2517 | return (NDIS_STATUS_SUCCESS); | |
2518 | ||
2519 | } | |
2520 | ||
2521 | ULONG HashBytesPolynomial(UCHAR *value, unsigned int len) | |
2522 | { | |
2523 | unsigned char *word = value; | |
2524 | unsigned int ret = 0; | |
2525 | unsigned int i; | |
2526 | ||
2527 | for(i=0; i < len; i++) | |
2528 | { | |
2529 | int mod = i % 32; | |
2530 | ret ^=(unsigned int) (word[i]) << mod; | |
2531 | ret ^=(unsigned int) (word[i]) >> (32 - mod); | |
2532 | } | |
2533 | return ret; | |
2534 | } | |
2535 | ||
2536 | VOID Sta_Announce_or_Forward_802_3_Packet( | |
2537 | IN PRTMP_ADAPTER pAd, | |
2538 | IN PNDIS_PACKET pPacket, | |
2539 | IN UCHAR FromWhichBSSID) | |
2540 | { | |
2541 | if (TRUE | |
2542 | ) | |
2543 | { | |
2544 | announce_802_3_packet(pAd, pPacket); | |
2545 | } | |
2546 | else | |
2547 | { | |
2548 | // release packet | |
2549 | RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); | |
2550 | } | |
2551 | } | |
2552 |