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