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;
43 PUCHAR XmitBufAddress;
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((PUCHAR)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, PUCHAR TargetBuffer)
234 PMDS pMds = &Adapter->Mds;
235 PUCHAR 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 = *(PUSHORT)(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, PUCHAR TargetBuffer)
331 PT00_DESCRIPTOR pT00;
332 PMDS pMds = &Adapter->Mds;
333 PUCHAR buffer, src_buffer, pctmp;
335 u16 SizeLeft, CopySize, CopyLeft, stmp;
336 u8 buf_index, FragmentCount = 0;
339 // Copy fragment body
340 buffer = TargetBuffer; // shift 8B usb + 24B 802.11
341 SizeLeft = pDes->buffer_total_size;
342 buf_index = pDes->buffer_start_index;
344 pT00 = (PT00_DESCRIPTOR)buffer;
346 pT00 = (PT00_DESCRIPTOR)buffer;
348 if (SizeLeft > pDes->FragmentThreshold) {
349 CopySize = pDes->FragmentThreshold;
350 pT00->T00_frame_length = 24 + CopySize;//Set USB length
352 pT00->T00_frame_length = 24 + SizeLeft;//Set USB length
354 SizeLeft -= CopySize;
357 pctmp = (PUCHAR)( buffer + 8 + DOT_11_SEQUENCE_OFFSET );
359 *pctmp |= FragmentCount;//931130.5.m
361 pT00->T00_first_mpdu = 1;
363 buffer += 32; // 8B usb + 24B 802.11 header
368 stmp &= ~0x03;//4n Alignment
369 Size += stmp;// Current 4n offset of mpdu
373 src_buffer = pDes->buffer_address[buf_index];
375 if (CopySize >= pDes->buffer_size[buf_index]) {
376 CopyLeft = pDes->buffer_size[buf_index];
378 // Get the next buffer of descriptor
380 buf_index %= MAX_DESCRIPTOR_BUFFER_INDEX;
382 PUCHAR pctmp = pDes->buffer_address[buf_index];
384 pDes->buffer_address[buf_index] = pctmp;
385 pDes->buffer_size[buf_index] -= CopySize;
388 memcpy(buffer, src_buffer, CopyLeft);
390 CopySize -= CopyLeft;
396 pMds->MicWriteAddress[ pMds->MicWriteIndex ] = buffer - pMds->MicAdd;
397 pMds->MicWriteSize[ pMds->MicWriteIndex ] = pMds->MicAdd;
400 else if( SizeLeft < 8 ) //931130.5.p
402 pMds->MicAdd = SizeLeft;
403 pMds->MicWriteAddress[ pMds->MicWriteIndex ] = buffer - ( 8 - SizeLeft );
404 pMds->MicWriteSize[ pMds->MicWriteIndex ] = 8 - SizeLeft;
405 pMds->MicWriteIndex++;
409 // Does it need to generate the new header for next mpdu?
411 buffer = TargetBuffer + Size; // Get the next 4n start address
412 memcpy( buffer, TargetBuffer, 32 );//Copy 8B USB +24B 802.11
413 pT00 = (PT00_DESCRIPTOR)buffer;
414 pT00->T00_first_mpdu = 0;
420 pT00->T00_last_mpdu = 1;
421 pT00->T00_IsLastMpdu = 1;
422 buffer = (PUCHAR)pT00 + 8; // +8 for USB hdr
423 buffer[1] &= ~0x04; // Clear more frag bit of 802.11 frame control
424 pDes->FragmentCount = FragmentCount; // Update the correct fragment number
430 Mds_DurationSet( PADAPTER Adapter, PDESCRIPTOR pDes, PUCHAR buffer )
432 PT00_DESCRIPTOR pT00;
433 PT01_DESCRIPTOR pT01;
434 u16 Duration, NextBodyLen, OffsetSize;
436 unsigned char CTS_on = FALSE, RTS_on = FALSE;
437 PT00_DESCRIPTOR pNextT00;
439 unsigned char boGroupAddr = FALSE;
442 OffsetSize = pDes->FragmentThreshold + 32 + 3;
444 Rate = pDes->TxRate >> 1;
448 pT00 = (PT00_DESCRIPTOR)buffer;
449 pT01 = (PT01_DESCRIPTOR)(buffer+4);
450 pNextT00 = (PT00_DESCRIPTOR)(buffer+OffsetSize);
452 if( buffer[ DOT_11_DA_OFFSET+8 ] & 0x1 ) // +8 for USB hdr
455 //========================================
456 // Set RTS/CTS mechanism
457 //========================================
460 //NOTE : If the protection mode is enabled and the MSDU will be fragmented,
461 // the tx rates of MPDUs will all be DSSS rates. So it will not use
462 // CTS-to-self in this case. CTS-To-self will only be used when without
463 // fragmentation. -- 20050112
464 BodyLen = (u16)pT00->T00_frame_length; //include 802.11 header
467 if( BodyLen >= CURRENT_RTS_THRESHOLD )
468 RTS_on = TRUE; // Using RTS
471 if( pT01->T01_modulation_type ) // Is using OFDM
473 if( CURRENT_PROTECT_MECHANISM ) // Is using protect
474 CTS_on = TRUE; // Using CTS
479 if( RTS_on || CTS_on )
481 if( pT01->T01_modulation_type) // Is using OFDM
484 // 2 SIFS + DATA transmit time + 1 ACK
485 // ACK Rate : 24 Mega bps
486 // ACK frame length = 14 bytes
487 Duration = 2*DEFAULT_SIFSTIME +
488 2*PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION +
489 ((BodyLen*8 + 22 + Rate*4 - 1)/(Rate*4))*Tsym +
490 ((112 + 22 + 95)/96)*Tsym;
495 // 2 SIFS + DATA transmit time + 1 ACK
496 // Rate : ?? Mega bps
497 // ACK frame length = 14 bytes
498 if( pT01->T01_plcp_header_length ) //long preamble
499 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME*2;
501 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME*2;
503 Duration += ( ((BodyLen + 14)*8 + Rate-1) / Rate +
504 DEFAULT_SIFSTIME*2 );
509 if( pT01->T01_modulation_type ) // Is using OFDM
511 //CTS + 1 SIFS + CTS duration
512 //CTS Rate : 24 Mega bps
513 //CTS frame length = 14 bytes
514 Duration += (DEFAULT_SIFSTIME +
515 PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION +
516 ((112 + 22 + 95)/96)*Tsym);
520 //CTS + 1 SIFS + CTS duration
521 //CTS Rate : ?? Mega bps
522 //CTS frame length = 14 bytes
523 if( pT01->T01_plcp_header_length ) //long preamble
524 Duration += LONG_PREAMBLE_PLUS_PLCPHEADER_TIME;
526 Duration += SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;
528 Duration += ( ((112 + Rate-1) / Rate) + DEFAULT_SIFSTIME );
532 // Set the value into USB descriptor
533 pT01->T01_add_rts = RTS_on ? 1 : 0;
534 pT01->T01_add_cts = CTS_on ? 1 : 0;
535 pT01->T01_rts_cts_duration = Duration;
538 //=====================================
539 // Fill the more fragment descriptor
540 //=====================================
545 for( i=pDes->FragmentCount-1; i>0; i-- )
547 NextBodyLen = (u16)pNextT00->T00_frame_length;
548 NextBodyLen += 4; //CRC
550 if( pT01->T01_modulation_type )
553 // data transmit time + 3 SIFS + 2 ACK
555 // ACK frame length = 14 bytes, tx rate = 24M
556 Duration = PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION * 3;
557 Duration += (((NextBodyLen*8 + 22 + Rate*4 - 1)/(Rate*4)) * Tsym +
558 (((2*14)*8 + 22 + 95)/96)*Tsym +
564 // data transmit time + 2 ACK + 3 SIFS
566 // ACK frame length = 14 bytes
568 if( pT01->T01_plcp_header_length ) //long preamble
569 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME*3;
571 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME*3;
573 Duration += ( ((NextBodyLen + (2*14))*8 + Rate-1) / Rate +
574 DEFAULT_SIFSTIME*3 );
577 ((PUSHORT)buffer)[5] = cpu_to_le16(Duration);// 4 USHOR for skip 8B USB, 2USHORT=FC + Duration
579 //----20061009 add by anson's endian
580 pNextT00->value = cpu_to_le32(pNextT00->value);
581 pT01->value = cpu_to_le32( pT01->value );
582 //----end 20061009 add by anson's endian
584 buffer += OffsetSize;
585 pT01 = (PT01_DESCRIPTOR)(buffer+4);
586 if (i != 1) //The last fragment will not have the next fragment
587 pNextT00 = (PT00_DESCRIPTOR)(buffer+OffsetSize);
590 //=====================================
591 // Fill the last fragment descriptor
592 //=====================================
593 if( pT01->T01_modulation_type )
597 // Rate : 24 Mega bps
598 // ACK frame length = 14 bytes
599 Duration = PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION;
600 //The Tx rate of ACK use 24M
601 Duration += (((112 + 22 + 95)/96)*Tsym + DEFAULT_SIFSTIME );
607 // Rate : ?? Mega bps
608 // ACK frame length = 14 bytes(112 bits)
609 if( pT01->T01_plcp_header_length ) //long preamble
610 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME;
612 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;
614 Duration += ( (112 + Rate-1)/Rate + DEFAULT_SIFSTIME );
618 ((PUSHORT)buffer)[5] = cpu_to_le16(Duration);// 4 USHOR for skip 8B USB, 2USHORT=FC + Duration
619 pT00->value = cpu_to_le32(pT00->value);
620 pT01->value = cpu_to_le32(pT01->value);
625 void MDS_EthernetPacketReceive( PADAPTER Adapter, PRXLAYER1 pRxLayer1 )
627 OS_RECEIVE_PACKET_INDICATE( Adapter, pRxLayer1 );