os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/inc/testdevicebase.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
#ifndef __TEST_DEVICE_BASE_H
sl@0
     2
#define __TEST_DEVICE_BASE_H
sl@0
     3
sl@0
     4
/*
sl@0
     5
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     6
* All rights reserved.
sl@0
     7
* This component and the accompanying materials are made available
sl@0
     8
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     9
* which accompanies this distribution, and is available
sl@0
    10
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
    11
*
sl@0
    12
* Initial Contributors:
sl@0
    13
* Nokia Corporation - initial contribution.
sl@0
    14
*
sl@0
    15
* Contributors:
sl@0
    16
*
sl@0
    17
* Description:
sl@0
    18
* @file TestDeviceBase.h
sl@0
    19
* @internalComponent
sl@0
    20
* 
sl@0
    21
*
sl@0
    22
*/
sl@0
    23
sl@0
    24
sl@0
    25
sl@0
    26
#include <e32base.h>
sl@0
    27
#include <d32usbc.h>
sl@0
    28
#include "UsbClientStateWatcher.h"
sl@0
    29
#include "ep0reader.h"
sl@0
    30
#include "BaseTestCase.h"
sl@0
    31
#include <d32otgdi.h>
sl@0
    32
sl@0
    33
namespace NUnitTesting_USBDI
sl@0
    34
	{
sl@0
    35
	
sl@0
    36
// Forward declarations
sl@0
    37
	
sl@0
    38
class CInterfaceBase;
sl@0
    39
class CSoftwareConnectTimer;
sl@0
    40
class CRemoteWakeupTimer;	
sl@0
    41
sl@0
    42
/**
sl@0
    43
This class represents a test USB device.  There is only one configuration supported
sl@0
    44
for this representation
sl@0
    45
*/
sl@0
    46
class RUsbTestDevice :	public MUsbClientStateObserver,
sl@0
    47
						public MRequestHandler
sl@0
    48
	{
sl@0
    49
public:
sl@0
    50
	/**
sl@0
    51
	Destructor
sl@0
    52
	*/
sl@0
    53
	
sl@0
    54
	virtual ~RUsbTestDevice();
sl@0
    55
sl@0
    56
	// ctor
sl@0
    57
	RUsbTestDevice(CBaseTestCase* aTestCase);
sl@0
    58
sl@0
    59
	void ResetState();
sl@0
    60
	
sl@0
    61
	/**
sl@0
    62
	Requests error/reports from this test device
sl@0
    63
	@param aObserverStatus the status of the entity that requests error reports
sl@0
    64
	*/
sl@0
    65
	
sl@0
    66
	void SubscribeToReports(TRequestStatus& aOberverStatus);
sl@0
    67
	
sl@0
    68
	/**
sl@0
    69
	Cancel request for any errors from operations from this device
sl@0
    70
	*/
sl@0
    71
	
sl@0
    72
	void CancelSubscriptionToReports();
sl@0
    73
	
sl@0
    74
	/**
sl@0
    75
	Open a basic device
sl@0
    76
	@leave KErrNoMemory
sl@0
    77
	*/
sl@0
    78
	
sl@0
    79
	void OpenL();
sl@0
    80
	
sl@0
    81
	/**
sl@0
    82
	Close this device, releaseing all resources
sl@0
    83
	*/
sl@0
    84
	
sl@0
    85
	void Close();
sl@0
    86
sl@0
    87
	/**
sl@0
    88
	Sets specific information for the device
sl@0
    89
	@param aClassCode the class code that is specified by the standard 
sl@0
    90
	   00h  Use class information in the Interface Descriptors 
sl@0
    91
	   02h  Communications and CDC Control (together with interface descriptor)
sl@0
    92
	   09h  Hub 
sl@0
    93
	   DCh  Diagnostic Device (together with interface descriptors)
sl@0
    94
	   EFh  Miscellaneous (together with interface descriptors)
sl@0
    95
	   FFh  Vendor Specific (together with interface descriptors)
sl@0
    96
	@param aSubClassCode the subclass code specified by the USB org 
sl@0
    97
	@param aDeviceProtocol
sl@0
    98
	*/
sl@0
    99
	
sl@0
   100
	TInt SetClassCode(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol);
sl@0
   101
sl@0
   102
	/**
sl@0
   103
	Set the USB specification that this device complies to
sl@0
   104
	@param aSpecification the specificatio nnumber
sl@0
   105
	*/
sl@0
   106
	
sl@0
   107
	TInt SetUsbSpecification(TUint16 aSpecification);
sl@0
   108
sl@0
   109
	/**
sl@0
   110
	Set the information for the vendor of this device
sl@0
   111
	@param aVendorId the identity number for the vendor
sl@0
   112
	*/
sl@0
   113
	
sl@0
   114
	TInt SetVendor(TUint16 aVendorId);
sl@0
   115
	
sl@0
   116
	/**
sl@0
   117
	Set the product information
sl@0
   118
	@param aProductId the identity of the product
sl@0
   119
	@param aProductString the string used to describe the product
sl@0
   120
	@param aManufacturerString the string used to describe the manufacturer
sl@0
   121
	@param aSerialNumberString the product serial number as string
sl@0
   122
	*/
sl@0
   123
	
sl@0
   124
	TInt SetProduct(TUint16 aProductId,const TDesC16& aProductString,const TDesC16& aManufacturerString,
sl@0
   125
				const TDesC16& aSerialNumberString);
sl@0
   126
sl@0
   127
	/**
sl@0
   128
	Establishes the configuration string for the device
sl@0
   129
	@param aConfigString the string for the configuration
sl@0
   130
	*/			
sl@0
   131
	
sl@0
   132
	TInt SetConfigurationString(const TDesC16& aConfigString);
sl@0
   133
				
sl@0
   134
	/**
sl@0
   135
	Adds an test interface to the test device
sl@0
   136
	@param aInterface a pointer to the interface
sl@0
   137
	*/
sl@0
   138
	
sl@0
   139
	void AddInterface(CInterfaceBase* aInterface);
sl@0
   140
	
sl@0
   141
	/**
sl@0
   142
	Access the interfacefor this device identified by the interface index number
sl@0
   143
	@param aIndex the index of the interface
sl@0
   144
	@return the interface
sl@0
   145
	*/
sl@0
   146
	
sl@0
   147
	CInterfaceBase& Interface(TInt aIndex);
sl@0
   148
	
sl@0
   149
	/**
sl@0
   150
	Software connect this test device to the host bus.
sl@0
   151
	The device must already by physically connected.
sl@0
   152
	*/
sl@0
   153
	
sl@0
   154
	void SoftwareConnect();
sl@0
   155
	
sl@0
   156
	/**
sl@0
   157
	Software dis-connect this test device from the host bus.
sl@0
   158
	The device can be left physically connected
sl@0
   159
	*/
sl@0
   160
	
sl@0
   161
	void SoftwareDisconnect();
sl@0
   162
	
sl@0
   163
	/**
sl@0
   164
	Perform a remote wake-up for the device
sl@0
   165
	*/
sl@0
   166
	
sl@0
   167
	void RemoteWakeup();
sl@0
   168
sl@0
   169
	/**
sl@0
   170
	Notifies the test case of any errors in operations for this test device
sl@0
   171
	@param aCompletionCode the error code to complete the test case with
sl@0
   172
	*/
sl@0
   173
	
sl@0
   174
	void ReportError(TInt aCompletionCode);	
sl@0
   175
sl@0
   176
	/**
sl@0
   177
	Sends a zero length data packet to acknowledge the request
sl@0
   178
	*/
sl@0
   179
	
sl@0
   180
	void AcknowledgeRequestReceived();
sl@0
   181
	
sl@0
   182
public: // From MUsbClientStateObserver
sl@0
   183
sl@0
   184
	/**
sl@0
   185
	Called when the device has changed state
sl@0
   186
	@param aNewState will hold the new state the device has been placed into by the host
sl@0
   187
	@param aChangeCompletionCode the operation comletion code
sl@0
   188
	*/
sl@0
   189
	void StateChangeL(TUsbcDeviceState aNewState,TInt aChangeCompletionCode);
sl@0
   190
	
sl@0
   191
public: // From MRequestHandler
sl@0
   192
	
sl@0
   193
	/**
sl@0
   194
	Process control requests from device endpoint 0
sl@0
   195
	@param aRequest the control request value
sl@0
   196
	@param aValue a parameter value for the request
sl@0
   197
	@param aIndex an index parameter for the request
sl@0
   198
	@param aDataReqLength the length of the data to be returned to the host
sl@0
   199
	@param aPayload the data payload sent to the device by the host in a data phase
sl@0
   200
	*/
sl@0
   201
	
sl@0
   202
	virtual TInt ProcessRequestL(TUint8 aRequest,TUint16 aValue,TUint16 aIndex,
sl@0
   203
		TUint16 aDataReqLength,const TDesC8& aPayload);
sl@0
   204
	
sl@0
   205
protected:
sl@0
   206
sl@0
   207
	/**
sl@0
   208
	Constructor, build a test device
sl@0
   209
	*/
sl@0
   210
	
sl@0
   211
	RUsbTestDevice();
sl@0
   212
sl@0
   213
	/**
sl@0
   214
	Start listening for control requests sent by the host
sl@0
   215
	*/
sl@0
   216
	
sl@0
   217
	void StartEp0Reading();
sl@0
   218
sl@0
   219
	/**
sl@0
   220
	Stop reading control requests from endpoint 0
sl@0
   221
	*/
sl@0
   222
	
sl@0
   223
	void StopEp0Reading();
sl@0
   224
	
sl@0
   225
	/**
sl@0
   226
	Derived devices will be notified through this function when the device has changed state
sl@0
   227
	and this base class has performed basic functionality
sl@0
   228
	@param aNewState the new state of the device
sl@0
   229
	*/
sl@0
   230
	
sl@0
   231
	virtual void OnStateChangeL(TUsbcDeviceState aNewState) = 0;
sl@0
   232
sl@0
   233
sl@0
   234
protected:
sl@0
   235
sl@0
   236
	RDevUsbcClient iClientDriver; // The USB client driver object
sl@0
   237
	
sl@0
   238
	/**
sl@0
   239
	The device can have many interfaces offering different functions (part functions)
sl@0
   240
	They are kept and owned by the device
sl@0
   241
	*/
sl@0
   242
	RPointerArray<CInterfaceBase> iInterfaces;
sl@0
   243
	
sl@0
   244
	/**
sl@0
   245
	The watcher of states for the USB client 
sl@0
   246
	*/
sl@0
   247
	CUsbClientStateWatcher* iStateWatcher;
sl@0
   248
	TUsbcDeviceState iCurrentState;
sl@0
   249
	
sl@0
   250
	/**
sl@0
   251
	The information about the capabilities of the device.
sl@0
   252
	This is mostly hardware specific information
sl@0
   253
	*/
sl@0
   254
	TUsbDeviceCaps iDeviceCaps;
sl@0
   255
	
sl@0
   256
	/**
sl@0
   257
	The control endpoint 0, reading device directed requests
sl@0
   258
	*/
sl@0
   259
	CDeviceEndpoint0* iDeviceEp0;
sl@0
   260
	
sl@0
   261
	/**
sl@0
   262
	The timer required perform any connect, disconnect or re-connections
sl@0
   263
	*/
sl@0
   264
	CSoftwareConnectTimer* iConnectTimer;
sl@0
   265
	
sl@0
   266
	/**
sl@0
   267
	The timer that performs any remote wakeups
sl@0
   268
	*/
sl@0
   269
	CRemoteWakeupTimer* iWakeupTimer;
sl@0
   270
sl@0
   271
	/**
sl@0
   272
	*/
sl@0
   273
	TRequestStatus* iObserverStatus;
sl@0
   274
	
sl@0
   275
	/**
sl@0
   276
	A Aux buffer
sl@0
   277
	*/
sl@0
   278
	HBufC8* iAuxBuffer;
sl@0
   279
sl@0
   280
	CBaseTestCase*	iTestCase;
sl@0
   281
	
sl@0
   282
	RProcess iOtgUsbMan;
sl@0
   283
	};
sl@0
   284
	
sl@0
   285
	
sl@0
   286
	}
sl@0
   287
sl@0
   288
sl@0
   289
#endif