4 Mds_reset_descriptor(PADAPTER Adapter)
6 PMDS pMds = &Adapter->Mds;
9 pMds->TxThreadCount = 0;
10 pMds->TxFillIndex = 0;
12 pMds->ScanTxPause = 0;
13 memset(pMds->TxOwner, 0, ((MAX_USB_TX_BUFFER_NUMBER + 3) & ~0x03));
17 Mds_initial(PADAPTER Adapter)
19 PMDS pMds = &Adapter->Mds;
21 pMds->TxPause = FALSE;
22 pMds->TxRTSThreshold = DEFAULT_RTSThreshold;
23 pMds->TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
25 vRxTimerInit(Adapter);//for WPA countermeasure
27 return hal_get_tx_buffer( &Adapter->sHwData, &pMds->pTxBuffer );
31 Mds_Destroy(PADAPTER Adapter)
33 vRxTimerStop(Adapter);
37 Mds_Tx(PADAPTER Adapter)
39 phw_data_t pHwData = &Adapter->sHwData;
40 PMDS pMds = &Adapter->Mds;
42 PDESCRIPTOR pTxDes = &TxDes;
44 u16 XmitBufSize, PacketSize, stmp, CurrentSize, FragmentThreshold;
45 u8 FillIndex, TxDesIndex, FragmentCount, FillCount;
46 unsigned char BufferFilled = FALSE, MICAdd = 0;
51 if (!hal_driver_init_OK(pHwData))
54 //Only one thread can be run here
55 if (!OS_ATOMIC_INC( Adapter, &pMds->TxThreadCount) == 1)
58 // Start to fill the data
60 FillIndex = pMds->TxFillIndex;
61 if (pMds->TxOwner[FillIndex]) { // Is owned by software 0:Yes 1:No
63 WBDEBUG(("[Mds_Tx] Tx Owner is H/W.\n"));
68 XmitBufAddress = pMds->pTxBuffer + (MAX_USB_TX_BUFFER * FillIndex); //Get buffer
72 PacketSize = Adapter->sMlmeFrame.len;
76 //For Check the buffer resource
77 FragmentThreshold = CURRENT_FRAGMENT_THRESHOLD;
79 FragmentCount = PacketSize/FragmentThreshold + 1;
80 stmp = PacketSize + FragmentCount*32 + 8;//931130.5.c 8:MIC
81 if ((XmitBufSize + stmp) >= MAX_USB_TX_BUFFER) {
82 printk("[Mds_Tx] Excess max tx buffer.\n");
83 break; // buffer is not enough
92 /* Leaves first u8 intact */
93 memset((u8 *)pTxDes + 1, 0, sizeof(DESCRIPTOR) - 1);
95 TxDesIndex = pMds->TxDesIndex;//Get the current ID
96 pTxDes->Descriptor_ID = TxDesIndex;
97 pMds->TxDesFrom[ TxDesIndex ] = 2;//Storing the information of source comming from
99 pMds->TxDesIndex %= MAX_USB_TX_DESCRIPTOR;
101 MLME_GetNextPacket( Adapter, pTxDes );
103 // Copy header. 8byte USB + 24byte 802.11Hdr. Set TxRate, Preamble type
104 Mds_HeaderCopy( Adapter, pTxDes, XmitBufAddress );
106 // For speed up Key setting
107 if (pTxDes->EapFix) {
109 WBDEBUG(("35: EPA 4th frame detected. Size = %d\n", PacketSize));
111 pHwData->IsKeyPreSet = 1;
114 // Copy (fragment) frame body, and set USB, 802.11 hdr flag
115 CurrentSize = Mds_BodyCopy(Adapter, pTxDes, XmitBufAddress);
117 // Set RTS/CTS and Normal duration field into buffer
118 Mds_DurationSet(Adapter, pTxDes, XmitBufAddress);
121 // Calculation MIC from buffer which maybe fragment, then fill into temporary address 8 byte
124 Mds_MicFill( Adapter, pTxDes, XmitBufAddress );
126 //Shift to the next address
127 XmitBufSize += CurrentSize;
128 XmitBufAddress += CurrentSize;
130 #ifdef _IBSS_BEACON_SEQ_STICK_
131 if ((XmitBufAddress[ DOT_11_DA_OFFSET+8 ] & 0xfc) != MAC_SUBTYPE_MNGMNT_PROBE_REQUEST) // +8 for USB hdr
133 pMds->TxToggle = TRUE;
135 // Get packet to transmit completed, 1:TESTSTA 2:MLME 3: Ndis data
136 MLME_SendComplete(Adapter, 0, TRUE);
138 // Software TSC count 20060214
140 if (pMds->TxTsc == 0)
143 FillCount++; // 20060928
144 } while (HAL_USB_MODE_BURST(pHwData)); // End of multiple MSDU copy loop. FALSE = single TRUE = multiple sending
146 // Move to the next one, if necessary
149 pMds->TxBufferSize[ FillIndex ] = XmitBufSize;
151 // 20060928 set Tx count
152 pMds->TxCountInBuffer[FillIndex] = FillCount;
155 pMds->TxOwner[FillIndex] = 1;
158 pMds->TxFillIndex %= MAX_USB_TX_BUFFER_NUMBER;
159 BufferFilled = FALSE;
163 if (!PacketSize) // No more pk for transmitting
169 // Start to send by lower module
171 if (!pHwData->IsKeyPreSet)
172 Wb35Tx_start(pHwData);
175 OS_ATOMIC_DEC( Adapter, &pMds->TxThreadCount );
179 Mds_SendComplete(PADAPTER Adapter, PT02_DESCRIPTOR pT02)
181 PMDS pMds = &Adapter->Mds;
182 phw_data_t pHwData = &Adapter->sHwData;
183 u8 PacketId = (u8)pT02->T02_Tx_PktID;
184 unsigned char SendOK = TRUE;
185 u8 RetryCount, TxRate;
187 if (pT02->T02_IgnoreResult) // Don't care the result
189 if (pT02->T02_IsLastMpdu) {
190 //TODO: DTO -- get the retry count and fragment count
192 TxRate = pMds->TxRate[ PacketId ][ 0 ];
193 RetryCount = (u8)pT02->T02_MPDU_Cnt;
194 if (pT02->value & FLAG_ERROR_TX_MASK) {
197 if (pT02->T02_transmit_abort || pT02->T02_out_of_MaxTxMSDULiftTime) {
199 pHwData->dto_tx_retry_count += (RetryCount+1);
202 pHwData->tx_retry_count[RetryCount] += RetryCount;
204 pHwData->tx_retry_count[7] += RetryCount;
205 #ifdef _PE_STATE_DUMP_
206 WBDEBUG(("dto_tx_retry_count =%d\n", pHwData->dto_tx_retry_count));
208 MTO_SetTxCount(Adapter, TxRate, RetryCount);
210 pHwData->dto_tx_frag_count += (RetryCount+1);
213 if (pT02->T02_transmit_abort_due_to_TBTT)
214 pHwData->tx_TBTT_start_count++;
215 if (pT02->T02_transmit_without_encryption_due_to_wep_on_false)
216 pHwData->tx_WepOn_false_count++;
217 if (pT02->T02_discard_due_to_null_wep_key)
218 pHwData->tx_Null_key_count++;
220 if (pT02->T02_effective_transmission_rate)
221 pHwData->tx_ETR_count++;
222 MTO_SetTxCount(Adapter, TxRate, RetryCount);
225 // Clear send result buffer
226 pMds->TxResult[ PacketId ] = 0;
228 pMds->TxResult[ PacketId ] |= ((u16)(pT02->value & 0x0ffff));
232 Mds_HeaderCopy(PADAPTER Adapter, PDESCRIPTOR pDes, u8 *TargetBuffer)
234 PMDS pMds = &Adapter->Mds;
235 u8 *src_buffer = pDes->buffer_address[0];//931130.5.g
236 PT00_DESCRIPTOR pT00;
237 PT01_DESCRIPTOR pT01;
239 u8 i, ctmp1, ctmp2, ctmpf;
240 u16 FragmentThreshold = CURRENT_FRAGMENT_THRESHOLD;
243 stmp = pDes->buffer_total_size;
245 // Set USB header 8 byte
247 pT00 = (PT00_DESCRIPTOR)TargetBuffer;
249 pT01 = (PT01_DESCRIPTOR)TargetBuffer;
252 pT00->value = 0;// Clear
253 pT01->value = 0;// Clear
255 pT00->T00_tx_packet_id = pDes->Descriptor_ID;// Set packet ID
256 pT00->T00_header_length = 24;// Set header length
257 pT01->T01_retry_abort_ebable = 1;//921013 931130.5.h
260 pT01->T01_wep_id = 0;
262 FragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD; //Do not fragment
263 // Copy full data, the 1'st buffer contain all the data 931130.5.j
264 memcpy( TargetBuffer, src_buffer, DOT_11_MAC_HEADER_SIZE );// Copy header
265 pDes->buffer_address[0] = src_buffer + DOT_11_MAC_HEADER_SIZE;
266 pDes->buffer_total_size -= DOT_11_MAC_HEADER_SIZE;
267 pDes->buffer_size[0] = pDes->buffer_total_size;
269 // Set fragment threshold
270 FragmentThreshold -= (DOT_11_MAC_HEADER_SIZE + 4);
271 pDes->FragmentThreshold = FragmentThreshold;
274 TargetBuffer[1] |= 0x04;// Set more frag bit
279 stmp = *(u16 *)(TargetBuffer+30); // 2n alignment address
282 ctmp1 = ctmpf = CURRENT_TX_RATE_FOR_MNG;
284 pDes->TxRate = ctmp1;
286 WBDEBUG(("Tx rate =%x\n", ctmp1));
289 pT01->T01_modulation_type = (ctmp1%3) ? 0 : 1;
291 for( i=0; i<2; i++ ) {
295 pMds->TxRate[pDes->Descriptor_ID][i] = ctmp1; // backup the ta rate and fall back rate
297 if( ctmp1 == 108) ctmp2 = 7;
298 else if( ctmp1 == 96 ) ctmp2 = 6; // Rate convert for USB
299 else if( ctmp1 == 72 ) ctmp2 = 5;
300 else if( ctmp1 == 48 ) ctmp2 = 4;
301 else if( ctmp1 == 36 ) ctmp2 = 3;
302 else if( ctmp1 == 24 ) ctmp2 = 2;
303 else if( ctmp1 == 18 ) ctmp2 = 1;
304 else if( ctmp1 == 12 ) ctmp2 = 0;
305 else if( ctmp1 == 22 ) ctmp2 = 3;
306 else if( ctmp1 == 11 ) ctmp2 = 2;
307 else if( ctmp1 == 4 ) ctmp2 = 1;
308 else ctmp2 = 0; // if( ctmp1 == 2 ) or default
311 pT01->T01_transmit_rate = ctmp2;
313 pT01->T01_fall_back_rate = ctmp2;
319 if ((pT01->T01_modulation_type == 0) && (pT01->T01_transmit_rate == 0)) // RATE_1M
320 pDes->PreambleMode = WLAN_PREAMBLE_TYPE_LONG;
322 pDes->PreambleMode = CURRENT_PREAMBLE_MODE;
323 pT01->T01_plcp_header_length = pDes->PreambleMode; // Set preamble
327 // The function return the 4n size of usb pk
329 Mds_BodyCopy(PADAPTER Adapter, PDESCRIPTOR pDes, u8 *TargetBuffer)
331 PT00_DESCRIPTOR pT00;
332 PMDS pMds = &Adapter->Mds;
337 u16 SizeLeft, CopySize, CopyLeft, stmp;
338 u8 buf_index, FragmentCount = 0;
341 // Copy fragment body
342 buffer = TargetBuffer; // shift 8B usb + 24B 802.11
343 SizeLeft = pDes->buffer_total_size;
344 buf_index = pDes->buffer_start_index;
346 pT00 = (PT00_DESCRIPTOR)buffer;
348 pT00 = (PT00_DESCRIPTOR)buffer;
350 if (SizeLeft > pDes->FragmentThreshold) {
351 CopySize = pDes->FragmentThreshold;
352 pT00->T00_frame_length = 24 + CopySize;//Set USB length
354 pT00->T00_frame_length = 24 + SizeLeft;//Set USB length
356 SizeLeft -= CopySize;
359 pctmp = (u8 *)( buffer + 8 + DOT_11_SEQUENCE_OFFSET );
361 *pctmp |= FragmentCount;//931130.5.m
363 pT00->T00_first_mpdu = 1;
365 buffer += 32; // 8B usb + 24B 802.11 header
370 stmp &= ~0x03;//4n Alignment
371 Size += stmp;// Current 4n offset of mpdu
375 src_buffer = pDes->buffer_address[buf_index];
377 if (CopySize >= pDes->buffer_size[buf_index]) {
378 CopyLeft = pDes->buffer_size[buf_index];
380 // Get the next buffer of descriptor
382 buf_index %= MAX_DESCRIPTOR_BUFFER_INDEX;
384 u8 *pctmp = pDes->buffer_address[buf_index];
386 pDes->buffer_address[buf_index] = pctmp;
387 pDes->buffer_size[buf_index] -= CopySize;
390 memcpy(buffer, src_buffer, CopyLeft);
392 CopySize -= CopyLeft;
398 pMds->MicWriteAddress[ pMds->MicWriteIndex ] = buffer - pMds->MicAdd;
399 pMds->MicWriteSize[ pMds->MicWriteIndex ] = pMds->MicAdd;
402 else if( SizeLeft < 8 ) //931130.5.p
404 pMds->MicAdd = SizeLeft;
405 pMds->MicWriteAddress[ pMds->MicWriteIndex ] = buffer - ( 8 - SizeLeft );
406 pMds->MicWriteSize[ pMds->MicWriteIndex ] = 8 - SizeLeft;
407 pMds->MicWriteIndex++;
411 // Does it need to generate the new header for next mpdu?
413 buffer = TargetBuffer + Size; // Get the next 4n start address
414 memcpy( buffer, TargetBuffer, 32 );//Copy 8B USB +24B 802.11
415 pT00 = (PT00_DESCRIPTOR)buffer;
416 pT00->T00_first_mpdu = 0;
422 pT00->T00_last_mpdu = 1;
423 pT00->T00_IsLastMpdu = 1;
424 buffer = (u8 *)pT00 + 8; // +8 for USB hdr
425 buffer[1] &= ~0x04; // Clear more frag bit of 802.11 frame control
426 pDes->FragmentCount = FragmentCount; // Update the correct fragment number
432 Mds_DurationSet( PADAPTER Adapter, PDESCRIPTOR pDes, u8 *buffer )
434 PT00_DESCRIPTOR pT00;
435 PT01_DESCRIPTOR pT01;
436 u16 Duration, NextBodyLen, OffsetSize;
438 unsigned char CTS_on = FALSE, RTS_on = FALSE;
439 PT00_DESCRIPTOR pNextT00;
441 unsigned char boGroupAddr = FALSE;
444 OffsetSize = pDes->FragmentThreshold + 32 + 3;
446 Rate = pDes->TxRate >> 1;
450 pT00 = (PT00_DESCRIPTOR)buffer;
451 pT01 = (PT01_DESCRIPTOR)(buffer+4);
452 pNextT00 = (PT00_DESCRIPTOR)(buffer+OffsetSize);
454 if( buffer[ DOT_11_DA_OFFSET+8 ] & 0x1 ) // +8 for USB hdr
457 //========================================
458 // Set RTS/CTS mechanism
459 //========================================
462 //NOTE : If the protection mode is enabled and the MSDU will be fragmented,
463 // the tx rates of MPDUs will all be DSSS rates. So it will not use
464 // CTS-to-self in this case. CTS-To-self will only be used when without
465 // fragmentation. -- 20050112
466 BodyLen = (u16)pT00->T00_frame_length; //include 802.11 header
469 if( BodyLen >= CURRENT_RTS_THRESHOLD )
470 RTS_on = TRUE; // Using RTS
473 if( pT01->T01_modulation_type ) // Is using OFDM
475 if( CURRENT_PROTECT_MECHANISM ) // Is using protect
476 CTS_on = TRUE; // Using CTS
481 if( RTS_on || CTS_on )
483 if( pT01->T01_modulation_type) // Is using OFDM
486 // 2 SIFS + DATA transmit time + 1 ACK
487 // ACK Rate : 24 Mega bps
488 // ACK frame length = 14 bytes
489 Duration = 2*DEFAULT_SIFSTIME +
490 2*PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION +
491 ((BodyLen*8 + 22 + Rate*4 - 1)/(Rate*4))*Tsym +
492 ((112 + 22 + 95)/96)*Tsym;
497 // 2 SIFS + DATA transmit time + 1 ACK
498 // Rate : ?? Mega bps
499 // ACK frame length = 14 bytes
500 if( pT01->T01_plcp_header_length ) //long preamble
501 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME*2;
503 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME*2;
505 Duration += ( ((BodyLen + 14)*8 + Rate-1) / Rate +
506 DEFAULT_SIFSTIME*2 );
511 if( pT01->T01_modulation_type ) // Is using OFDM
513 //CTS + 1 SIFS + CTS duration
514 //CTS Rate : 24 Mega bps
515 //CTS frame length = 14 bytes
516 Duration += (DEFAULT_SIFSTIME +
517 PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION +
518 ((112 + 22 + 95)/96)*Tsym);
522 //CTS + 1 SIFS + CTS duration
523 //CTS Rate : ?? Mega bps
524 //CTS frame length = 14 bytes
525 if( pT01->T01_plcp_header_length ) //long preamble
526 Duration += LONG_PREAMBLE_PLUS_PLCPHEADER_TIME;
528 Duration += SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;
530 Duration += ( ((112 + Rate-1) / Rate) + DEFAULT_SIFSTIME );
534 // Set the value into USB descriptor
535 pT01->T01_add_rts = RTS_on ? 1 : 0;
536 pT01->T01_add_cts = CTS_on ? 1 : 0;
537 pT01->T01_rts_cts_duration = Duration;
540 //=====================================
541 // Fill the more fragment descriptor
542 //=====================================
547 for( i=pDes->FragmentCount-1; i>0; i-- )
549 NextBodyLen = (u16)pNextT00->T00_frame_length;
550 NextBodyLen += 4; //CRC
552 if( pT01->T01_modulation_type )
555 // data transmit time + 3 SIFS + 2 ACK
557 // ACK frame length = 14 bytes, tx rate = 24M
558 Duration = PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION * 3;
559 Duration += (((NextBodyLen*8 + 22 + Rate*4 - 1)/(Rate*4)) * Tsym +
560 (((2*14)*8 + 22 + 95)/96)*Tsym +
566 // data transmit time + 2 ACK + 3 SIFS
568 // ACK frame length = 14 bytes
570 if( pT01->T01_plcp_header_length ) //long preamble
571 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME*3;
573 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME*3;
575 Duration += ( ((NextBodyLen + (2*14))*8 + Rate-1) / Rate +
576 DEFAULT_SIFSTIME*3 );
579 ((u16 *)buffer)[5] = cpu_to_le16(Duration);// 4 USHOR for skip 8B USB, 2USHORT=FC + Duration
581 //----20061009 add by anson's endian
582 pNextT00->value = cpu_to_le32(pNextT00->value);
583 pT01->value = cpu_to_le32( pT01->value );
584 //----end 20061009 add by anson's endian
586 buffer += OffsetSize;
587 pT01 = (PT01_DESCRIPTOR)(buffer+4);
588 if (i != 1) //The last fragment will not have the next fragment
589 pNextT00 = (PT00_DESCRIPTOR)(buffer+OffsetSize);
592 //=====================================
593 // Fill the last fragment descriptor
594 //=====================================
595 if( pT01->T01_modulation_type )
599 // Rate : 24 Mega bps
600 // ACK frame length = 14 bytes
601 Duration = PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION;
602 //The Tx rate of ACK use 24M
603 Duration += (((112 + 22 + 95)/96)*Tsym + DEFAULT_SIFSTIME );
609 // Rate : ?? Mega bps
610 // ACK frame length = 14 bytes(112 bits)
611 if( pT01->T01_plcp_header_length ) //long preamble
612 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME;
614 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;
616 Duration += ( (112 + Rate-1)/Rate + DEFAULT_SIFSTIME );
620 ((u16 *)buffer)[5] = cpu_to_le16(Duration);// 4 USHOR for skip 8B USB, 2USHORT=FC + Duration
621 pT00->value = cpu_to_le32(pT00->value);
622 pT01->value = cpu_to_le32(pT01->value);
627 void MDS_EthernetPacketReceive( PADAPTER Adapter, PRXLAYER1 pRxLayer1 )
629 OS_RECEIVE_PACKET_INDICATE( Adapter, pRxLayer1 );