mtptransports/mtpusbtransport/usbsic_imp/inc/cmtpusbconnection.h
changeset 0 d0791faffa3f
child 1 f8e15b44d440
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #ifndef CMTPUSBCONNECTION_H
       
    22 #define CMTPUSBCONNECTION_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <d32usbc.h>
       
    26 #include <mtp/mtpdataproviderapitypes.h>
       
    27 #include <mtp/tmtptyperequest.h>
       
    28 #include <mtp/tmtptypeevent.h>
       
    29 #include <mtp/tmtptypenull.h>
       
    30 
       
    31 #include "mtpusbtransportconstants.h"
       
    32 #include "mmtptransportconnection.h"
       
    33 #include "mtpdebug.h"
       
    34 #include "tmtpusbcontrolrequestsetup.h"
       
    35 #include "tmtpusbcontrolrequestcanceldata.h"
       
    36 #include "tmtpusbcontrolrequestdevicestatus.h"
       
    37 #include "tmtpusbcontrolrequestmodfunction.h"
       
    38 #include "tmtpusbcontrolrequestmodheader.h"
       
    39 #include "tmtpusbparameterpayloadblock.h"
       
    40 
       
    41 class CMTPUsbContainer;
       
    42 class CMTPUsbEpBase;
       
    43 class MMTPConnectionProtocol;
       
    44 class MMTPConnectionMgr;
       
    45 class MMTPType;
       
    46 
       
    47 /** 
       
    48 Implements the MTP USB device class connection protocol and transport layer 
       
    49 interface.
       
    50 @internalComponent
       
    51  
       
    52 */
       
    53 class CMTPUsbConnection : 
       
    54     public CActive, 
       
    55     public MMTPTransportConnection 
       
    56     {
       
    57 public:
       
    58     
       
    59     static CMTPUsbConnection* NewL(MMTPConnectionMgr& aConnectionMgr);
       
    60     ~CMTPUsbConnection();
       
    61     
       
    62 public: // From MMTPTransportConnection
       
    63 
       
    64     void BindL(MMTPConnectionProtocol& aProtocol);
       
    65     MMTPConnectionProtocol& BoundProtocolLayer();
       
    66     void CloseConnection();
       
    67     void ReceiveDataL(MMTPType& aData, const TMTPTypeRequest& aRequest);
       
    68     void ReceiveDataCancelL(const TMTPTypeRequest& aRequest);   
       
    69     void SendDataL(const MMTPType& aData, const TMTPTypeRequest& aRequest);
       
    70     void SendDataCancelL(const TMTPTypeRequest& aRequest);    
       
    71     void SendEventL(const TMTPTypeEvent& aEvent);  
       
    72     void SendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest);  
       
    73     void TransactionCompleteL(const TMTPTypeRequest& aRequest); 
       
    74     void Unbind(MMTPConnectionProtocol& aProtocol);
       
    75     TAny* GetExtendedInterface(TUid aInterfaceUid); 
       
    76     TUint GetImplementationUid();
       
    77      
       
    78 public:
       
    79   
       
    80     void ReceiveBulkDataCompleteL(TInt aError, MMTPType& aData);
       
    81     void ReceiveControlRequestDataCompleteL(TInt aError, MMTPType& aData);
       
    82     void ReceiveControlRequestSetupCompleteL(TInt aError, MMTPType& aData);
       
    83     void SendBulkDataCompleteL(TInt aError, const MMTPType& aData);
       
    84     void SendControlRequestDataCompleteL(TInt aError, const MMTPType& aData);
       
    85     void SendInterruptDataCompleteL(TInt aError, const MMTPType& aData);
       
    86     
       
    87     TUint EndpointBitPosition(TUint aId) const;
       
    88     const TUsbcEndpointCaps& EndpointCapsL(TUint aId);
       
    89     TUint EndpointDirection(TUint aId) const;
       
    90     TUint EndpointDirectionAndType(TUint aId) const;
       
    91     TEndpointNumber EndpointNumber(TUint aId) const;
       
    92     TUint EndpointType(TUint aId) const;
       
    93         
       
    94     RDevUsbcClient& Ldd();
       
    95     CMTPUsbContainer& BulkContainer();
       
    96     
       
    97     TMTPTypeRequest& GetCurrentRequest()
       
    98         {
       
    99         return iMTPRequest;
       
   100         }
       
   101 
       
   102 private: // From CActive
       
   103 
       
   104     void DoCancel();
       
   105     TInt RunError(TInt aError);
       
   106     void RunL();
       
   107 
       
   108 private:
       
   109  
       
   110     CMTPUsbConnection(MMTPConnectionMgr& aConnectionMgr);
       
   111     void ConstructL();
       
   112     
       
   113     void IssueAlternateDeviceStatusNotifyRequest();
       
   114     
       
   115     void BufferEventDataL(const TMTPTypeEvent& aEvent);
       
   116     void SendEventDataL();
       
   117     void SendUnreportedStatusEventL();
       
   118     
       
   119     void InitiateBulkRequestSequenceL();
       
   120     void InitiateControlRequestSequenceL();
       
   121     
       
   122     void ProcessBulkCommandL(TInt aError);
       
   123     void ProcessBulkDataInL(const TMTPTypeRequest& aRequest, const MMTPType& aData);
       
   124     void ProcessBulkDataOutL(TInt aError);
       
   125     void ProcessControlRequestCancelL(const TMTPUsbControlRequestSetup& aRequest);
       
   126     void ProcessControlRequestDeviceResetL(const TMTPUsbControlRequestSetup& aRequest);
       
   127     void ProcessControlRequestDeviceStatusL(const TMTPUsbControlRequestSetup& aRequest);
       
   128   
       
   129     TBool BulkRequestErrorHandled(TInt aError);
       
   130     TBool BulkRequestTransactionStateValid(TMTPTransactionPhase aExpectedTransactionState);
       
   131     TBool ControlRequestErrorHandled(TInt aError);
       
   132     
       
   133     void ConfigurationDescriptorSetL();
       
   134     void ConfigurationDescriptorClear();
       
   135     
       
   136     TBool ConnectionClosed() const;
       
   137     TBool ConnectionOpen() const;
       
   138     
       
   139     void ControlEndpointStartL();
       
   140     void ControlEndpointStop();
       
   141     
       
   142     void BulkEndpointsStallL();
       
   143     void BulkEndpointsStallClearL();
       
   144 
       
   145     void DataEndpointsStartL();
       
   146     void DataEndpointsStop();
       
   147     
       
   148     void EndpointStallL(TMTPUsbEndpointId aId);
       
   149     void EndpointStallClearL(TMTPUsbEndpointId aId);
       
   150     
       
   151     void ResumeConnectionL();
       
   152     void StartConnectionL();
       
   153     void StopConnection();
       
   154     void SuspendConnectionL();
       
   155     
       
   156     void StartUsbL();
       
   157     void StopUsb();
       
   158     
       
   159     TInt32 ConnectionState() const;
       
   160     TInt32 SuspendState() const;
       
   161     
       
   162     void SetBulkTransactionState(TMTPTransactionPhase aState);
       
   163     void SetConnectionState(TInt32 aState);
       
   164     void SetDeviceStatus(TUint16 aCode);
       
   165     void SetInterfaceDescriptorL();
       
   166     void SetSuspendState(TInt32 aState);
       
   167     void SetTransportPacketSizeL();
       
   168 
       
   169     TBool IsEpStalled(const TUint& aEpNumber);
       
   170     
       
   171 private: // Owned.
       
   172 
       
   173     /**
       
   174     The MTP USB device class connection state bit flags.
       
   175     */
       
   176     enum TConnectionState
       
   177         {
       
   178         /**
       
   179         The Connection is closed.
       
   180         */
       
   181         EIdle                   = 0x00000000,
       
   182         
       
   183         /**
       
   184         The Connection is open and in an error state pending a device reset control
       
   185         request from the host.
       
   186         */
       
   187         EStalled                = 0x00000001,
       
   188         
       
   189         /**
       
   190         The Connection is open and inactive.
       
   191         */
       
   192         EOpen                   = 0x00000002,
       
   193         
       
   194         /**
       
   195         The Connection is open and actively processing a bulk data transfer.
       
   196         */
       
   197         EBusy                   = 0x00000004,
       
   198         
       
   199         /**
       
   200         The connection state bit flags mask.
       
   201         */
       
   202         EConnectionStateMask    = 0x0000000F,
       
   203         };
       
   204 
       
   205     /**
       
   206     The MTP USB suspend state bit flags.
       
   207     */
       
   208     enum TSuspendState
       
   209         {
       
   210         /**
       
   211         The USB device is not suspended.
       
   212         */
       
   213         ENotSuspended           = 0x00000000,
       
   214         
       
   215         /**
       
   216         The USB device is suspended.
       
   217         */
       
   218         ESuspended              = 0x80000000,
       
   219         
       
   220         /**
       
   221         The USB device is suspended and asynchronous MTP event data is awaiting
       
   222         transmission to the host.
       
   223         */
       
   224         ESuspendedEventsPending = 0xC0000000,
       
   225         
       
   226         /**
       
   227         The suspend state bit flags mask.
       
   228         */
       
   229         ESuspendStateMask       = 0xF0000000,
       
   230         };
       
   231       
       
   232     /**
       
   233     Defines the MTP USB device class endpoint meta data.
       
   234     */
       
   235     struct TEpInfo
       
   236         {        
       
   237         /**
       
   238         The logical endpoint bit position.
       
   239         */
       
   240         TUint           iBitPosition;   
       
   241         
       
   242         /**
       
   243         The endpoint direction flag bits.
       
   244         */
       
   245         TUint           iDirection; 
       
   246         
       
   247         /**
       
   248         The endpoint polling interval.
       
   249         */
       
   250         TUint           iInterval;
       
   251         
       
   252         /**
       
   253         The high speed NAK rate
       
   254         */
       
   255         TUint			iInterval_Hs;    
       
   256         
       
   257         /**
       
   258         The logical endpoint number.
       
   259         */
       
   260         TEndpointNumber iNumber; 
       
   261         
       
   262         /**
       
   263         The endpoint type flag bits.
       
   264         */
       
   265         TUint           iType;         
       
   266         };
       
   267     
       
   268     /**
       
   269     The bulk transfer transaction state.
       
   270     */
       
   271     TMTPTransactionPhase                                iBulkTransactionState;
       
   272     
       
   273     /** 
       
   274     The current USB controller/interface alternate setting state.
       
   275     */
       
   276     TUint                                               iControllerStateCurrent;
       
   277     
       
   278     /** 
       
   279     The previous USB controller/interface alternate setting state.
       
   280     */
       
   281     TUint                                               iControllerStatePrevious;
       
   282     
       
   283     /**
       
   284     The USB device capabilities buffer.
       
   285     */
       
   286     TUsbDeviceCaps                                      iDeviceCaps;
       
   287     
       
   288     /**
       
   289     The current device status.
       
   290     */
       
   291     TUint16                                             iDeviceStatusCode;
       
   292     
       
   293     /**
       
   294     The endpoint capabilities buffer.
       
   295     */
       
   296     TUsbcEndpointCaps                                   iEndpointCaps;
       
   297     
       
   298     /**
       
   299     The USB device endpoints capability sets.
       
   300     */
       
   301     TUsbcEndpointData                                   iEndpointCapSets[KUsbcMaxEndpoints];
       
   302     
       
   303     /** 
       
   304     The USB MTP device class endpoints.
       
   305     */
       
   306     RPointerArray<CMTPUsbEpBase>                        iEndpoints;
       
   307     
       
   308     /** 
       
   309     The USB device.
       
   310     */
       
   311     RDevUsbcClient                                      iLdd;
       
   312     
       
   313     /**
       
   314     The MTP event dataset buffer.
       
   315     */
       
   316     TMTPTypeEvent                                       iMTPEvent;
       
   317     
       
   318     /**
       
   319     Event pending flag.
       
   320     */
       
   321     TBool												iEventPending;
       
   322     
       
   323     /**
       
   324     The active MTP operation request dataset buffer.
       
   325     */
       
   326     TMTPTypeRequest                                     iMTPRequest;
       
   327     
       
   328     /** 
       
   329     The active MTP SessionID.
       
   330     */
       
   331     TUint32                                             iMTPSessionId;
       
   332     
       
   333     /**
       
   334     The remote wakeup enabled flag.
       
   335     */
       
   336     TBool                                               iRemoteWakeup;
       
   337     
       
   338     /**
       
   339     The MTP USB device class state variable.
       
   340     */
       
   341     TInt32                                              iState;
       
   342     
       
   343     /** 
       
   344     The USB MTP device class generic bulk pipe container buffer.
       
   345     */
       
   346     CMTPUsbContainer*                                   iUsbBulkContainer;
       
   347     
       
   348     /**
       
   349     The USB MTP device class variable length Command/Response Block payload 
       
   350     dataset. 
       
   351     */
       
   352     TMTPUsbParameterPayloadBlock                        iUsbBulkParameterBlock;
       
   353     
       
   354     /** 
       
   355     The USB MTP device class event dataset buffer.
       
   356     */
       
   357     CMTPUsbContainer*                                   iUsbEventContainer;
       
   358     
       
   359     /**
       
   360     The USB MTP device class variable length Event Block payload dataset. 
       
   361     */
       
   362     TMTPUsbParameterPayloadBlock                        iUsbEventParameterBlock;
       
   363     
       
   364     /** 
       
   365     MTP USB device class cancel control request dataset buffer.
       
   366     */
       
   367     TMTPUsbControlRequestCancelData                     iUsbControlRequestCancelData;
       
   368     
       
   369     
       
   370     /** 
       
   371     MTP USB device class device status control request dataset buffer.
       
   372     */
       
   373     TMTPUsbControlRequestDeviceStatus                   iUsbControlRequestDeviceStatus;
       
   374     
       
   375     /** 
       
   376     The MTP USB device class control request setup dataset buffer.
       
   377     */
       
   378     TMTPUsbControlRequestSetup                          iUsbControlRequestSetup;
       
   379     
       
   380     /** 
       
   381     The MTP USB device class Microsoft OS Feature Descriptor (MOD) header 
       
   382     section dataset buffer.
       
   383     */
       
   384     TMTPUsbControlRequestMODHeader                      iUsbMODHeader;
       
   385     
       
   386     /** 
       
   387     The MTP USB device class Microsoft OS Feature Descriptor (MOD) function 
       
   388     section dataset buffer.
       
   389     */
       
   390     TMTPUsbControlRequestMODFunction                    iUsbMODFunction;
       
   391     
       
   392     /**
       
   393     The MTP USB device class endpoint meta data table.
       
   394     */
       
   395     static const TEpInfo                                KEndpointMetaData[];
       
   396     const TFixedArray<TEpInfo, EMTPUsbEpNumEndpoints>   iEndpointInfo;
       
   397 
       
   398 	/**
       
   399 	Cached error code in case of a ItoR transaction error.
       
   400 	*/
       
   401 	TInt												iXferError;
       
   402 
       
   403 	/**
       
   404 	Data sink for consuming data during error recovery from
       
   405 	a failed ItoR transaction.
       
   406 	*/
       
   407 	TMTPTypeNull										iNull;
       
   408 
       
   409 	/**
       
   410 	Buffer for reading discarded data into.
       
   411 	*/
       
   412 	RBuf8												iNullBuffer;
       
   413 	
       
   414 	/**
       
   415 	A flag to reflect if a Host initiated cancel transaction
       
   416 	is triggered.
       
   417 	*/
       
   418 	TBool 												iIsCancelReceived;
       
   419 	
       
   420     /**
       
   421     FLOGGER debug trace member variable.
       
   422     */
       
   423     __FLOG_DECLARATION_MEMBER_MUTABLE;
       
   424 
       
   425 private: // Not owned.
       
   426     
       
   427     /** 
       
   428     The MTP connection manager.
       
   429     */
       
   430     MMTPConnectionMgr*                                  iConnectionMgr;
       
   431 
       
   432     /** 
       
   433     The MTP connection protocol layer binding.
       
   434     */
       
   435     MMTPConnectionProtocol*                             iProtocolLayer;
       
   436  
       
   437     /**
       
   438      * indicate if a transaction_cannled needs to be return to PC
       
   439      */
       
   440     TBool                                               isResponseTransactionCancelledNeeded;
       
   441 	/**
       
   442 	 * indicate if a transaction has been ignored
       
   443 	 */
       
   444 	TBool												isCommandIgnored;
       
   445 
       
   446     };
       
   447     
       
   448 #endif // CMTPUSBCONNECTION_H