os/kernelhwsrv/kerneltest/e32utils/testusbcldd/inc/dtestusblogdev.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-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 the License "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 // f32test\testusbcldd\inc\dtestusblogdev.h
    15 // Test USB logical channel classes.
    16 // 
    17 //
    18 
    19 /**
    20  @file
    21  @internalTechnology
    22 */
    23 
    24 #ifndef __DTESTUSBCLOGDEVICE_H_
    25 #define __DTESTUSBCLOGDEVICE_H_
    26 
    27 #include "kerndefs.h"
    28 #include "usbcdesc.h"
    29 
    30 const TInt KTestUsbcMajorVersion = 0;
    31 const TInt KTestUsbcMinorVersion = 1;
    32 const TInt KTestUsbcBuildVersion = 1;
    33 const TInt KTestUsbcMaxRequests = 10;
    34 
    35 /** The USB version we are compliant with (BCD) */
    36 const TUint16 KUsbcUsbVersion = 0x0110;
    37 
    38 /** The Ep0 tx buffer area */
    39 const TInt KUsbcBufSz_Ep0Tx = 1024;
    40 
    41 /** Size of buffer for transferring data from client and host */
    42 const TInt KTransferBufSize = 1024;
    43 
    44 /** Must correspond to the max enum of TRequest + 1;
    45 	currently this is ERequestEndpointStatusNotify = 9 */
    46 const TInt KUsbcMaxRequests = 10;
    47 
    48 /** Maximum number of endpoints an Interface may have */
    49 const TInt KUsbcMaxEpNumber = 5;
    50 
    51 /** Size of endpoint buffers */
    52 const TInt KEndpointBufferSize = 16 * 1024;
    53 
    54 class DTestUsbcEndpoint;
    55 class DTestUsbcLogDevice : public DLogicalDevice
    56 	{
    57 public:
    58 	DTestUsbcLogDevice();
    59 	~DTestUsbcLogDevice();
    60 	TInt Install();
    61 	void GetCaps(TDes8& aDes) const;
    62 	TInt Create(DLogicalChannelBase*& aChannel);
    63 	DLogicalChannel* CreateL();
    64 	
    65 private:
    66 	RPointerArray<DTestUsbcEndpoint> iEndpoints;
    67 	};
    68 
    69 class TUsbcInterfaceSet;
    70 class TUsbcLogicalEndpoint;
    71 
    72 /** This is one 'Alternate Setting' of an interface. */
    73 class TUsbcInterface
    74 	{
    75 public:
    76 	TUsbcInterface(TUsbcInterfaceSet* aIfcSet, TUint8 aSetting);
    77 	~TUsbcInterface();
    78 public:
    79 	/** Array of endpoints making up (belonging to) this setting. */
    80 	RPointerArray<TUsbcLogicalEndpoint> iEndpoints;
    81 	/** 'Back' pointer. */
    82 	TUsbcInterfaceSet* const iInterfaceSet;
    83 	/** bAlternateSetting (zero-based). */
    84 	const TUint8 iSettingCode;
    85 	};
    86 
    87 /** This is an 'Interface' (owning 1 or more alternate settings TUsbcInterface). */
    88 class TUsbcInterfaceSet
    89 	{
    90 public:
    91 	TUsbcInterfaceSet(const DBase* aClientId, TUint8 aIfcNum);
    92 	~TUsbcInterfaceSet();
    93 	const TUsbcInterface* CurrentInterface() const;
    94 	TUsbcInterface* CurrentInterface();
    95 public:
    96 	/** Array of alternate settings provided by (belonging to) this interface. */
    97 	RPointerArray<TUsbcInterface> iInterfaces;
    98 	/** Pointer to the LDD which created and owns this interface. */
    99 	const DBase* const iClientId;
   100 	/** bInterfaceNumber (zero-based). */
   101 	TUint8 iInterfaceNumber;
   102 	/** bAlternateSetting (zero-based). */
   103 	TUint8 iCurrentInterface;
   104 	};
   105 	
   106 /** This is a logical 'Endpoint', as used by our device configuration model. */
   107 class TUsbcLogicalEndpoint
   108 	{
   109 public:
   110 	TUsbcLogicalEndpoint(TUint aEndpointNum, const TUsbcEndpointInfo& aInfo,
   111 						 TUsbcInterface* aInterface);
   112 	~TUsbcLogicalEndpoint();
   113 	public:
   114 	/** The virtual (logical) endpoint number. */
   115 	const TInt iLEndpointNum;
   116 	/** This endpoint's info structure. */
   117 	TUsbcEndpointInfo iInfo;
   118 	/** 'Back' pointer. */
   119 	const TUsbcInterface* iInterface;
   120 	};
   121 	
   122 class DLddTestUsbcChannel : public DLogicalChannel
   123 	{
   124 public:
   125 	DLddTestUsbcChannel(RPointerArray<DTestUsbcEndpoint>& aEndpoints);	
   126 	void HandleMsg(TMessageBase* aMsg);
   127 	TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
   128 	~DLddTestUsbcChannel();
   129 
   130 private:
   131 	TInt DoCancel(TInt aReqNo);
   132 	void DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2);
   133 	TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
   134 	TBool ValidateEndpoint(TUsbcEndpointInfo* aEndpointInfo);
   135 	TInt SetInterface(TInt aInterfaceNumber, TUsbcInterfaceInfoBuf *aUserInterfaceInfoBuf, TPtr8* aInterfaceString);
   136 	TInt SetInterface(TInt aInterfaceNumber, TUsbcClassInfo& aClass, TDesC8* aString,
   137 					  TInt aTotalEndpointsUsed, const TUsbcEndpointInfo aEndpointData[]);
   138 	TUsbcInterface* CreateInterface(TInt aIfc);
   139 	void DeleteInterface(TInt aIfc);
   140 	void DeleteInterfaceSet();
   141 	TInt CreateEndpoints(TUsbcInterface* aIfc, TInt aEndpointsUsed, const TUsbcEndpointInfo aEndpointData[]);
   142 	TInt SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass,
   143 							TDesC8* aString, const TUsbcEndpointInfo aEndpointData[]);
   144 	TInt ReleaseInterface(TInt aInterfaceNumber);
   145 	TInt HostEndpointStatusNotify(TInt aEndpointNumber, TRequestStatus* aStatus);
   146 	TInt EndpointStatusNotify(TUint* aEndpointMask, TRequestStatus* aStatus);
   147 	void EndpointStatusNotifyCallback();
   148 	TInt ClearEndpoint(TInt aEndpointNumber);
   149 	TInt DoTransferAsyncReq(TInt aEndpointNumber, TAny* a1, TAny* a2, TRequestStatus& aStatus);
   150 	TBool ValidEndpoint(TInt aEndpointNumber);
   151 	TInt FindRealEndpoint(TInt aEndpointNumber);
   152 	TInt HaltClearEndpoint(TBool aHalt, TInt aEndpointNumber);
   153 	void AlternateDeviceStatusNotify();
   154 	TInt SetAlternateDeviceStatusNotify(TRequestStatus* aStatus, TUint* aValue);
   155 	void CancelAlternateDeviceStatusNotify();
   156 	TInt ReEnumerate(TRequestStatus* aStatus);
   157 	void SetDeviceState(TUsbcDeviceState aState);
   158 private:
   159 	DThread* iClient;
   160 	TUsbcDescriptorPool iDescriptors;
   161 	TUsbcInterfaceSet iIfcSet;
   162 	RPointerArray<DTestUsbcEndpoint>& iEndpoints;
   163 	TUint* iEndpointStatusMask;
   164 	TRequestStatus* iEndpointStatusNotifyRequest;
   165 	TRequestStatus* iAlternateDeviceStatusNotifyRequest;
   166 	TUint* iAlternateDeviceStatusNotifyValue;
   167 	TUsbcDeviceState iDeviceState;
   168 	
   169 public:
   170 	static const TUsbcEndpointData iEndpointData[];
   171 		
   172 	friend class DTestUsbcEndpoint;
   173 	};
   174 			
   175 class DTestUsbcEndpoint : public DBase
   176 	{
   177 public:
   178 	DTestUsbcEndpoint();
   179 	~DTestUsbcEndpoint();
   180 	TInt Create(const TUsbcEndpointCaps& aCaps);
   181 	TInt TryToComplete();
   182 	TInt CopyData(TInt aSrcOffset, DThread* aDestClient, TDesC8* aDest,
   183 				  TInt aDestOffset, TInt aLen);
   184 	TBool SupportsDir(TUint aDir);
   185 	TBool EndpointSuitable(const TUsbcEndpointInfo& aInfo);
   186 	void DoCancel();
   187 	TInt Halt();
   188 	TInt Clear();
   189 	TBool IsHalted();
   190 	void SetClearCallback(DLddTestUsbcChannel* aCallback);
   191 	TInt HostStatusNotify(DThread* aHost, TRequestStatus* aStatus);
   192 	TInt NewRequest(DThread* aClient, TRequestStatus* aStatus, TEndpointTransferInfo& aInfo, TTransferType aType);
   193 	TInt NewHostRequest(DThread* aHost, TRequestStatus* aStatus, TEndpointTransferInfo& aInfo, TTransferType aType);
   194 private:
   195 	TRequestStatus* iClientStatus;
   196 	TRequestStatus* iHostStatus;
   197 	TRequestStatus* iHostNotifyStatus;
   198 	DThread* iClient;
   199 	DThread* iHost;
   200 	DThread* iNotifyHost;
   201 	TUsbcEndpointCaps iCaps;
   202 	TBool iRequestPending;
   203 	TBool iHostRequestPending;
   204 	TEndpointTransferInfo iClientTransferInfo;
   205 	TEndpointTransferInfo iHostTransferInfo;
   206 	TInt iDataTransferred;
   207 	TInt iHostDataTransferred;
   208 	TTransferType iRequestType;
   209 	TTransferType iHostRequestType;
   210 	HBuf8Plat* iBuffer;
   211 	TBool iHalted;
   212 	DLddTestUsbcChannel* iClearCallback;
   213 	
   214 public:
   215 	TBool iReserve;
   216 	};
   217 
   218 #endif // __DTESTUSBCLOGDEVICE_H_