mtptransports/mtpusbtransport/usbsic_imp/src/cmtpusbconnection.cpp
branchRCL_3
changeset 12 523717cdb0ad
parent 4 60a94a45d437
child 15 f85613f12947
equal deleted inserted replaced
11:f5809cfbf6d5 12:523717cdb0ad
   129     TRAPD(err, BulkEndpointsStallL());
   129     TRAPD(err, BulkEndpointsStallL());
   130     UNUSED_VAR(err);
   130     UNUSED_VAR(err);
   131     __FLOG(_L8("CloseConnection - Exit"));
   131     __FLOG(_L8("CloseConnection - Exit"));
   132     }
   132     }
   133     
   133     
   134 void CMTPUsbConnection::ReceiveDataL(MMTPType& aData, const TMTPTypeRequest& /*aRequest*/)
   134 void CMTPUsbConnection::ReceiveDataL(MMTPType& aData, const TMTPTypeRequest& aRequest)
   135     {
   135     {
   136     __FLOG(_L8("ReceiveDataL - Entry"));
   136     __FLOG(_L8("ReceiveDataL - Entry"));
   137     
   137     
   138     // Update the transaction state.
   138     // Update the transaction state.
   139     SetBulkTransactionState(EDataIToRPhase);
   139     SetBulkTransactionState(EDataIToRPhase);
   140     
   140     
   141     // Setup the bulk container and initiate the bulk data receive sequence.
   141     if (iIsCancelReceived) //cancel received
   142     iUsbBulkContainer->SetPayloadL(&aData);
   142         {
   143     
   143         __FLOG(_L8("Transaction has been cancelled, just flush trash data and complete"));
   144     //Expected containerType pre-setup here in case we don't receive IToR dataphase at all so 
   144         static_cast<CMTPUsbEpBulkOut*>(iEndpoints[EMTPUsbEpBulkOut])->FlushRxDataL();
   145     //Cancel operation can trigger right call inside ReceiveBulkDataCompleteL(). 
   145         BoundProtocolLayer().ReceiveDataCompleteL(KErrCancel, aData, iMTPRequest);
   146     iUsbBulkContainer->SetUint16L(CMTPUsbContainer::EContainerType, EMTPUsbContainerTypeDataBlock);
   146         }
   147     
   147     else
   148     static_cast<CMTPUsbEpBulkOut*>(iEndpoints[EMTPUsbEpBulkOut])->ReceiveBulkDataL(*iUsbBulkContainer);
   148         {  
       
   149         // Setup the bulk container and initiate the bulk data receive sequence.
       
   150         iUsbBulkContainer->SetPayloadL(&aData);
       
   151         
       
   152         //Expected containerType pre-setup here in case we don't receive IToR dataphase at all so 
       
   153         //Cancel operation can trigger right call inside ReceiveBulkDataCompleteL(). 
       
   154         iUsbBulkContainer->SetUint16L(CMTPUsbContainer::EContainerType, EMTPUsbContainerTypeDataBlock);
       
   155         
       
   156         static_cast<CMTPUsbEpBulkOut*>(iEndpoints[EMTPUsbEpBulkOut])->ReceiveBulkDataL(*iUsbBulkContainer);
       
   157         }
   149     
   158     
   150     __FLOG(_L8("ReceiveDataL - Exit"));       
   159     __FLOG(_L8("ReceiveDataL - Exit"));       
   151     }
   160     }
   152 
   161 
   153 void CMTPUsbConnection::ReceiveDataCancelL(const TMTPTypeRequest& /*aRequest*/)
   162 void CMTPUsbConnection::ReceiveDataCancelL(const TMTPTypeRequest& /*aRequest*/)
   470             RDebug::Print(_L("The Transaction ID want to canceled is %d -------------"), iUsbControlRequestCancelData.Uint32(TMTPUsbControlRequestCancelData::ETransactionID));
   479             RDebug::Print(_L("The Transaction ID want to canceled is %d -------------"), iUsbControlRequestCancelData.Uint32(TMTPUsbControlRequestCancelData::ETransactionID));
   471             RDebug::Print(_L("Current Transaction ID is %d ----------------"),iMTPRequest.Uint32(TMTPTypeRequest::ERequestTransactionID));
   480             RDebug::Print(_L("Current Transaction ID is %d ----------------"),iMTPRequest.Uint32(TMTPTypeRequest::ERequestTransactionID));
   472 			#endif
   481 			#endif
   473             
   482             
   474             isResponseTransactionCancelledNeeded = true;
   483             isResponseTransactionCancelledNeeded = true;
   475             if(  BoundProtocolLayer().TransactionPhaseL(iMTPSessionId) > EIdlePhase   ) 
   484             TMTPTransactionPhase transPhase = BoundProtocolLayer().TransactionPhaseL(iMTPSessionId);
       
   485             if( transPhase > EIdlePhase && transPhase < ECompletingPhase ) 
   476             	{
   486             	{
   477             	
       
   478                	  
       
   479 
       
   480 	            iMTPEvent.Reset();
   487 	            iMTPEvent.Reset();
   481 	            iMTPEvent.SetUint16(TMTPTypeEvent::EEventCode, iUsbControlRequestCancelData.Uint16(TMTPUsbControlRequestCancelData::ECancellationCode));
   488 	            iMTPEvent.SetUint16(TMTPTypeEvent::EEventCode, iUsbControlRequestCancelData.Uint16(TMTPUsbControlRequestCancelData::ECancellationCode));
   482 	            iMTPEvent.SetUint32(TMTPTypeEvent::EEventSessionID, iMTPSessionId);
   489 	            iMTPEvent.SetUint32(TMTPTypeEvent::EEventSessionID, iMTPSessionId);
   483 	            
   490 	            
   484 	            // replace the transaction id in the event with the current transaction id
   491 	            // replace the transaction id in the event with the current transaction id
   494 	            if (ConnectionOpen())
   501 	            if (ConnectionOpen())
   495 	                {
   502 	                {
   496 	                BoundProtocolLayer().ReceivedEventL(iMTPEvent);
   503 	                BoundProtocolLayer().ReceivedEventL(iMTPEvent);
   497 	                }
   504 	                }
   498             	}
   505             	}
       
   506             else if (transPhase == ECompletingPhase)
       
   507                 {
       
   508                 __FLOG(_L8("cancel event received at completing phase, flush rx data"));
       
   509 
       
   510                 //flush rx data.
       
   511                 static_cast<CMTPUsbEpBulkOut*>(iEndpoints[EMTPUsbEpBulkOut])->FlushRxDataL();
       
   512                 }
   499             else
   513             else
   500             	{
   514             	{
   501 
   515                 __FLOG(_L8("cancel event received at idle phase, stop data EPs, flush rx data, restart data eps"));
   502 				#ifdef _DEBUG 
   516                 
   503             	RDebug::Print(_L("cancel evnet received at idle state, stop data EPs, flush rx data, restart data eps,statusOK\n"));
       
   504 				#endif
       
   505 
       
   506             	// stop data endpoint
   517             	// stop data endpoint
   507             	DataEndpointsStop();
   518             	DataEndpointsStop();
   508       
   519       
   509             	//flush rx data
   520                 //flush rx data.
   510             	TInt  nbytes = 0;
   521                 static_cast<CMTPUsbEpBulkOut*>(iEndpoints[EMTPUsbEpBulkOut])->FlushRxDataL();
   511             	TInt err = iLdd.QueryReceiveBuffer(EndpointNumber(EMTPUsbEpBulkOut), nbytes);
   522                 
   512 				#ifdef _DEBUG
       
   513             	RDebug::Print(_L("QueryReceiveBuffer()-----err is %d , nbytes is %d"), err, nbytes);
       
   514 				#endif	  
       
   515 
       
   516             	// has data, read it
       
   517             	if( (err == KErrNone) && (nbytes > 0) )
       
   518             		{
       
   519             		// create the read buff
       
   520             		RBuf8 readBuf;
       
   521             		readBuf.CreateL(nbytes);
       
   522             		// synchronously read the data
       
   523             		TRequestStatus status;
       
   524             		iLdd.ReadOneOrMore(status, EndpointNumber(EMTPUsbEpBulkOut), readBuf);
       
   525             		User::WaitForRequest(status);
       
   526             		if (KErrNone == status.Int())
       
   527             			{
       
   528 	      		 		#ifdef _DEBUG
       
   529             			RDebug::Print(_L("%d bytes is flushed"), nbytes);
       
   530 	      		  		#endif
       
   531             			}
       
   532             		readBuf.Close(); 
       
   533             		}
       
   534             	// initiate bulk request sequence.
   523             	// initiate bulk request sequence.
   535             	InitiateBulkRequestSequenceL();
   524             	InitiateBulkRequestSequenceL();   
   536                        
   525             	
   537             	SetDeviceStatus(EMTPUsbDeviceStatusOK);                   
   526                 SetDeviceStatus(EMTPUsbDeviceStatusOK);
   538             	}
   527             	}
   539             }
   528             }
   540 
   529 
   541         // Initiate the next control request sequence.     
   530         // Initiate the next control request sequence.     
   542         InitiateControlRequestSequenceL();
   531         InitiateControlRequestSequenceL();
  1050     {
  1039     {
  1051     __FLOG(_L8("InitiateControlRequestSequenceL - Entry"));
  1040     __FLOG(_L8("InitiateControlRequestSequenceL - Entry"));
  1052     CMTPUsbEpControl& ctrl(*static_cast<CMTPUsbEpControl*>(iEndpoints[EMTPUsbEpControl]));
  1041     CMTPUsbEpControl& ctrl(*static_cast<CMTPUsbEpControl*>(iEndpoints[EMTPUsbEpControl]));
  1053     if (!ctrl.Stalled())
  1042     if (!ctrl.Stalled())
  1054         {
  1043         {
       
  1044 
  1055         ctrl.ReceiveControlRequestSetupL(iUsbControlRequestSetup);
  1045         ctrl.ReceiveControlRequestSetupL(iUsbControlRequestSetup);
  1056         }
  1046         }
  1057     __FLOG(_L8("InitiateControlRequestSequenceL - Exit"));        
  1047     __FLOG(_L8("InitiateControlRequestSequenceL - Exit"));        
  1058     }
  1048     }
  1059 
  1049 
  1398         case KErrUsbDeviceNotConfigured:    
  1388         case KErrUsbDeviceNotConfigured:    
  1399         case KErrUsbInterfaceChange:
  1389         case KErrUsbInterfaceChange:
  1400         case KErrUsbDeviceClosing:
  1390         case KErrUsbDeviceClosing:
  1401         case KErrUsbCableDetached:
  1391         case KErrUsbCableDetached:
  1402         case KErrUsbDeviceBusReset:
  1392         case KErrUsbDeviceBusReset:
       
  1393         case KErrUsbEpNotReady:
  1403             // Interface state is changing (@see RunL).
  1394             // Interface state is changing (@see RunL).
  1404             break;
  1395             break;
  1405 
  1396 
  1406         default:
  1397         default:
  1407             // Unknown error on the control endpoint, shutdown the connection.
  1398             // Unknown error on the control endpoint, shutdown the connection.