os/kernelhwsrv/kerneltest/f32test/smassstorage/scsiprot/t_ms_scsi.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// SCSCI Protocol unit test cases classes
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology
sl@0
    21
*/
sl@0
    22
sl@0
    23
#ifndef __T_MS_SCSI_H__
sl@0
    24
#define __T_MS_SCSI_H__
sl@0
    25
sl@0
    26
#include <e32def.h>
sl@0
    27
#include <f32fsys.h> // for Proxy drive
sl@0
    28
sl@0
    29
#include "scsiprot.h"
sl@0
    30
#include "drivemanager.h"
sl@0
    31
sl@0
    32
sl@0
    33
/**
sl@0
    34
	test scsi transport
sl@0
    35
*/
sl@0
    36
class TTestScsiTransport : public MTransportBase
sl@0
    37
	{
sl@0
    38
public:
sl@0
    39
	TTestScsiTransport();
sl@0
    40
sl@0
    41
	// MTransportBase methods
sl@0
    42
public:
sl@0
    43
	inline virtual void SetupReadData(TPtr8& aData);
sl@0
    44
	inline virtual void SetupReadData(TUint aLength);
sl@0
    45
	inline virtual void SetupWriteData(TPtrC8& aData);
sl@0
    46
	inline virtual TInt Start();
sl@0
    47
	inline virtual TInt Stop();
sl@0
    48
	inline virtual void RegisterProtocol(MProtocolBase& aProtocol);
sl@0
    49
	inline virtual TInt BytesAvailable();
sl@0
    50
sl@0
    51
	// test specific methods / members
sl@0
    52
public:
sl@0
    53
	void InitialiseReadBuf();
sl@0
    54
	
sl@0
    55
public:
sl@0
    56
	//new
sl@0
    57
	inline  virtual TInt InitialiseTransportL(TInt aTransportLddFlag); 
sl@0
    58
	inline	virtual void GetCommandBufPtr(TPtr8& aDes, TUint aLength); 
sl@0
    59
	inline	virtual void GetReadDataBufPtr(TPtr8& aDes);
sl@0
    60
	inline	virtual void GetWriteDataBufPtr(TPtrC8& aDes); 
sl@0
    61
	inline  virtual void ProcessReadData(TAny* aAddress);
sl@0
    62
sl@0
    63
public:
sl@0
    64
	/** pointer to the protocol */
sl@0
    65
	MProtocolBase* iProtocol;
sl@0
    66
	
sl@0
    67
	/** reference to Write Data protocol buffer */
sl@0
    68
	TPtrC8 iBufWrite;
sl@0
    69
sl@0
    70
	/** reference to Read Data protocol buffer */
sl@0
    71
	TBuf8<KMaxBufSize*2> iBufRead;
sl@0
    72
	
sl@0
    73
	/**reference to Command protocol buffer */
sl@0
    74
	TBuf8<36> iBufCmd;
sl@0
    75
sl@0
    76
	/** Number of bytes available in the protocol buffer */
sl@0
    77
	TUint iReadLength;
sl@0
    78
	};
sl@0
    79
sl@0
    80
sl@0
    81
/**
sl@0
    82
	test scsi proxy drive
sl@0
    83
*/
sl@0
    84
class CTestProxyDrive : public CProxyDrive
sl@0
    85
	{
sl@0
    86
public:
sl@0
    87
	CTestProxyDrive();
sl@0
    88
	virtual ~CTestProxyDrive();
sl@0
    89
	
sl@0
    90
sl@0
    91
	virtual TInt Read(TInt64 aPos,TInt aLength,TDes8& aTrg);
sl@0
    92
	
sl@0
    93
	virtual TInt Write(TInt64 aPos,const TDesC8& aSrc);
sl@0
    94
	
sl@0
    95
	virtual TInt Caps(TDes8& anInfo);
sl@0
    96
	
sl@0
    97
	virtual TInt Initialise();
sl@0
    98
	
sl@0
    99
	
sl@0
   100
	// not implemented methods
sl@0
   101
	virtual TInt Dismounted()
sl@0
   102
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   103
	virtual TInt Enlarge(TInt)
sl@0
   104
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   105
	virtual TInt ReduceSize(TInt, TInt)
sl@0
   106
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   107
	virtual TInt Read(TInt64, TInt, const TAny*, TInt, TInt)
sl@0
   108
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   109
	virtual TInt Write(TInt64,TInt,const TAny*,TInt,TInt)
sl@0
   110
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   111
	virtual TInt Format(TFormatInfo&)
sl@0
   112
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   113
	virtual TInt Format(TInt64,TInt)
sl@0
   114
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   115
	virtual TInt SetMountInfo(const TDesC8*, TInt)
sl@0
   116
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   117
	virtual TInt ForceRemount(TUint)
sl@0
   118
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   119
	virtual TInt Unlock(TMediaPassword&, TBool)
sl@0
   120
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   121
	virtual TInt Lock(TMediaPassword&, TMediaPassword&, TBool)
sl@0
   122
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   123
	virtual TInt Clear(TMediaPassword&)
sl@0
   124
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   125
	virtual TInt ControlIO(const RMessagePtr2&,TInt,TAny*,TAny*)
sl@0
   126
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   127
	virtual TInt DeleteNotify(TInt64, TInt)
sl@0
   128
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   129
	virtual TInt ErasePassword()
sl@0
   130
		{ ASSERT(EFalse); return KErrNone; }
sl@0
   131
sl@0
   132
	// test specific members / methods
sl@0
   133
public:
sl@0
   134
	/** Proxy drive Caps */
sl@0
   135
	TLocalDriveCapsV4 iCaps;
sl@0
   136
	
sl@0
   137
	/** Buffer with data for reading or writing*/
sl@0
   138
	TBuf8<KMaxBufSize*2> iMediaBuf;
sl@0
   139
sl@0
   140
	};
sl@0
   141
sl@0
   142
/**
sl@0
   143
	base class to encapsulate a single SCSI protocol test
sl@0
   144
*/
sl@0
   145
class CScsiTest : public CBase
sl@0
   146
	{
sl@0
   147
	// static memebers
sl@0
   148
public:
sl@0
   149
	/** 
sl@0
   150
	Defines Lun used for testing
sl@0
   151
	*/
sl@0
   152
	static TInt TestLun;
sl@0
   153
sl@0
   154
public:
sl@0
   155
	virtual ~CScsiTest();
sl@0
   156
	static CScsiTest* NewLC();
sl@0
   157
sl@0
   158
public:
sl@0
   159
	TPtrC8& GetSenseCodePtr();
sl@0
   160
	void MountTestDrive ();
sl@0
   161
	void DismountTestDrive ();
sl@0
   162
	CMassStorageDrive* TestDrive();
sl@0
   163
sl@0
   164
	// decode command
sl@0
   165
	inline TBool DecodePacket(TPtrC8& aCmd);
sl@0
   166
sl@0
   167
private:
sl@0
   168
	CScsiTest();
sl@0
   169
	void  ConstructL();
sl@0
   170
sl@0
   171
public:
sl@0
   172
	/** 
sl@0
   173
	Drive Manager
sl@0
   174
	*/
sl@0
   175
	CDriveManager* iDriveManager;
sl@0
   176
	/** 
sl@0
   177
	SCSI protocol
sl@0
   178
	*/
sl@0
   179
	CScsiProtocol* iScsiProt;
sl@0
   180
	/** 
sl@0
   181
	Transport object
sl@0
   182
	*/
sl@0
   183
	TTestScsiTransport iTransport;
sl@0
   184
	
sl@0
   185
	/**
sl@0
   186
	Test proxy drive
sl@0
   187
	*/
sl@0
   188
	CTestProxyDrive iProxyDrive;
sl@0
   189
sl@0
   190
	/** 
sl@0
   191
	drive map 
sl@0
   192
	*/
sl@0
   193
	RArray<TInt> iDriveMap;
sl@0
   194
sl@0
   195
	};
sl@0
   196
sl@0
   197
sl@0
   198
sl@0
   199
//
sl@0
   200
//	wrapper classes
sl@0
   201
//
sl@0
   202
/** RequestSense wrapper class */
sl@0
   203
class TRequestSenseData
sl@0
   204
	{
sl@0
   205
public:
sl@0
   206
	inline TRequestSenseData(TPtrC8 aData);
sl@0
   207
	
sl@0
   208
	inline TInt8 Key();
sl@0
   209
	inline TInt8 AdditionalCode();
sl@0
   210
	inline TInt8 AdditionalCodeQualifier();
sl@0
   211
		
sl@0
   212
public:
sl@0
   213
	/** pointer to internal data */
sl@0
   214
	TPtrC8 iData;
sl@0
   215
	};
sl@0
   216
sl@0
   217
	
sl@0
   218
/** Inquiry wrapper class */
sl@0
   219
class TInquiryData
sl@0
   220
	{
sl@0
   221
public:
sl@0
   222
	inline TInquiryData(TPtrC8 aData);
sl@0
   223
	
sl@0
   224
	inline TInt8 DeviceType(); 			// 5 lower bits in 1st byte
sl@0
   225
	inline TBool RMB(); 				// high bit in 2nd byte
sl@0
   226
	inline TInt8 Version();				// 3rd byte
sl@0
   227
	inline TInt8 RespDataFrmt();		// 4th byte 
sl@0
   228
    // TBuf<8>
sl@0
   229
	inline TPtr8 VendorId();
sl@0
   230
	// TBuf<16>
sl@0
   231
	inline TPtr8 ProductId();
sl@0
   232
	// TBuf<4>
sl@0
   233
	inline TPtr8 RevisionLevel();
sl@0
   234
	inline TInt8 PeripheralQualifier();	// 3 highest bits in 1st byte
sl@0
   235
	inline TInt8 Length(); 				// length of Inquiry data
sl@0
   236
	
sl@0
   237
public:
sl@0
   238
	/** pointer to internal data */
sl@0
   239
	TPtrC8 iData;
sl@0
   240
	};
sl@0
   241
sl@0
   242
sl@0
   243
// 
sl@0
   244
// Command wrappers
sl@0
   245
// Notes: Every command wrapper has internal buffer
sl@0
   246
//		  11 or 7 bytes long. This buffer is used for 
sl@0
   247
//		  10 or 6 bytes long commands. An extra byte is 
sl@0
   248
//		  used for the size of an command (see implementation
sl@0
   249
//		  of scsi protocol).
sl@0
   250
sl@0
   251
/** Wrapper class for READ(10) WRITE(10) VERIFY(10) command */
sl@0
   252
class TReadWrite10Cmd
sl@0
   253
	{
sl@0
   254
public:
sl@0
   255
	TReadWrite10Cmd();
sl@0
   256
	
sl@0
   257
	void SetBlockAddress(TUint32 aAddress);
sl@0
   258
	inline void SetTransferLength(TUint16 aLength);
sl@0
   259
	inline void SetProtect(TUint8 aProtect);
sl@0
   260
	
sl@0
   261
	inline void SetRead();
sl@0
   262
	inline void SetWrite();
sl@0
   263
	inline void SetVerify();
sl@0
   264
	inline void SetBytChk (TBool aSet);
sl@0
   265
	
sl@0
   266
public:
sl@0
   267
	/** buffer with command data */
sl@0
   268
	TBuf8<11> iCmd;
sl@0
   269
	};
sl@0
   270
sl@0
   271
/** Wrapper class for MODE SENSE(6) command */
sl@0
   272
class TModeSenseCmd
sl@0
   273
	{
sl@0
   274
public:
sl@0
   275
	TModeSenseCmd();
sl@0
   276
	inline void SetPC (TUint8 aPc);
sl@0
   277
	inline void SetPageCode (TUint8 aPc);
sl@0
   278
	
sl@0
   279
public:
sl@0
   280
	/** buffer with command data */
sl@0
   281
	TBuf8<7> iCmd;
sl@0
   282
	};
sl@0
   283
sl@0
   284
/** Wrapper class for INQUIRY command */
sl@0
   285
class TInquiryCmd
sl@0
   286
	{
sl@0
   287
public:
sl@0
   288
	TInquiryCmd();
sl@0
   289
	
sl@0
   290
public:
sl@0
   291
	/** buffer with command data */
sl@0
   292
	TBuf8<7> iCmd;
sl@0
   293
	};
sl@0
   294
sl@0
   295
/** Wrapper class for TEST UNIT READY command */
sl@0
   296
class TTestUnitReadyCmd
sl@0
   297
	{
sl@0
   298
public:
sl@0
   299
	TTestUnitReadyCmd();
sl@0
   300
	
sl@0
   301
public:
sl@0
   302
	/** buffer with command data */
sl@0
   303
	TBuf8<7> iCmd;
sl@0
   304
	};
sl@0
   305
sl@0
   306
/** Wrapper class for PREVENT ALLOW MEDIA REMOVAL command */
sl@0
   307
class TMediaRemovalCmd
sl@0
   308
	{
sl@0
   309
public:
sl@0
   310
	TMediaRemovalCmd();
sl@0
   311
	
sl@0
   312
public:
sl@0
   313
	/** buffer with command data */
sl@0
   314
	TBuf8<7> iCmd;
sl@0
   315
	};
sl@0
   316
sl@0
   317
/** Wrapper class for READ CAPACITY command */
sl@0
   318
class TReadCapacityCmd
sl@0
   319
	{
sl@0
   320
public:
sl@0
   321
	TReadCapacityCmd();
sl@0
   322
	
sl@0
   323
public:
sl@0
   324
	/** buffer with command data */
sl@0
   325
	TBuf8<11> iCmd;
sl@0
   326
	};
sl@0
   327
sl@0
   328
/** Wrapper class for READ CAPACITY response */
sl@0
   329
class TReadCapacityResponse : public TPtrC8
sl@0
   330
	{
sl@0
   331
public:
sl@0
   332
	TReadCapacityResponse(const TDesC8 &aDes);
sl@0
   333
	
sl@0
   334
	inline TUint32 LBAddress();
sl@0
   335
	inline TUint32 BlockLength();
sl@0
   336
	};
sl@0
   337
	
sl@0
   338
#include "t_ms_scsi.inl"
sl@0
   339
	
sl@0
   340
#endif //__T_MS_SCSI_H__