os/kernelhwsrv/kerneltest/f32test/smassstorage/scsiprot/t_ms_scsi.inl
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
// TTestScsiTransport
sl@0
    15
// setup read data 
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
inline void TTestScsiTransport::SetupReadData (TPtr8& aData)
sl@0
    20
	{
sl@0
    21
	__FNLOG ("TTestScsiTransport::SetupReadData");
sl@0
    22
sl@0
    23
	// copy data from the begining of a buffer, always
sl@0
    24
	iReadLength = aData.Length();
sl@0
    25
	aData.Copy (&iBufRead[0], aData.Length());
sl@0
    26
	}
sl@0
    27
sl@0
    28
/** setup write data */
sl@0
    29
inline void TTestScsiTransport::SetupWriteData (TPtrC8& aData)
sl@0
    30
	{
sl@0
    31
	__FNLOG ("TTestScsiTransport::SetupWriteData");
sl@0
    32
	iBufWrite.Set(aData);
sl@0
    33
	}
sl@0
    34
sl@0
    35
/** start a transport */
sl@0
    36
inline TInt TTestScsiTransport::Start() 
sl@0
    37
	{
sl@0
    38
	__FNLOG ("TTestScsiTransport::Start");
sl@0
    39
	// not implemented
sl@0
    40
	ASSERT(EFalse);
sl@0
    41
	return 0;
sl@0
    42
	}
sl@0
    43
sl@0
    44
/** stop a transport */
sl@0
    45
inline TInt TTestScsiTransport::Stop()
sl@0
    46
	{
sl@0
    47
	__FNLOG ("TTestScsiTransport::Stop");
sl@0
    48
	// not implemented
sl@0
    49
	ASSERT(EFalse);
sl@0
    50
	
sl@0
    51
	return 0;
sl@0
    52
	}
sl@0
    53
sl@0
    54
inline void TTestScsiTransport::RegisterProtocol(MProtocolBase& aProtocol)
sl@0
    55
	{
sl@0
    56
	__FNLOG ("TTestScsiTransport::RegisterProtocol\n");
sl@0
    57
	iProtocol = &aProtocol;
sl@0
    58
	}
sl@0
    59
sl@0
    60
inline TInt TTestScsiTransport::BytesAvailable()
sl@0
    61
	{
sl@0
    62
	__FNLOG ("TTestScsiTransport::BytesAvailable\n");
sl@0
    63
	TUint retVal = iReadLength;
sl@0
    64
	iReadLength = 0;
sl@0
    65
	return(retVal);
sl@0
    66
	}
sl@0
    67
sl@0
    68
inline TInt TTestScsiTransport::InitialiseTransportL(TInt /*aTransportLddFlag*/)
sl@0
    69
	{
sl@0
    70
	return KErrNone;
sl@0
    71
	}
sl@0
    72
sl@0
    73
inline void TTestScsiTransport::GetCommandBufPtr(TPtr8& aDes, TUint aLength)
sl@0
    74
	{
sl@0
    75
	__FNLOG ("TTestScsiTransport::GetCommandBufPtr");
sl@0
    76
	aDes.Set((TUint8*)(iBufCmd.Ptr()), aLength, aLength);
sl@0
    77
	}
sl@0
    78
sl@0
    79
inline void TTestScsiTransport::GetReadDataBufPtr(TPtr8& aDes)
sl@0
    80
	{
sl@0
    81
	__FNLOG ("TTestScsiTransport::GetReadDataBufPtr");
sl@0
    82
	aDes.Set((TUint8*)(iBufRead.Ptr()),KMaxBufSize, KMaxBufSize);
sl@0
    83
	}
sl@0
    84
	
sl@0
    85
inline void TTestScsiTransport::GetWriteDataBufPtr(TPtrC8& aDes)
sl@0
    86
	{
sl@0
    87
	__FNLOG ("TTestScsiTransport::GetWriteDataBufPtr");
sl@0
    88
	aDes.Set((TUint8*)(iBufRead.Ptr()),iReadLength);
sl@0
    89
	}
sl@0
    90
sl@0
    91
inline void TTestScsiTransport::SetupReadData(TUint aLength)
sl@0
    92
	{
sl@0
    93
	__FNLOG ("TTestScsiTransport::SetupReadData");
sl@0
    94
	iReadLength = aLength;
sl@0
    95
	}
sl@0
    96
sl@0
    97
inline void TTestScsiTransport::ProcessReadData(TAny* /*aAddress*/)
sl@0
    98
	{
sl@0
    99
	return;
sl@0
   100
	}
sl@0
   101
//
sl@0
   102
// CTestProxyDrive
sl@0
   103
//
sl@0
   104
inline TInt CTestProxyDrive::Caps(TDes8& anInfo)
sl@0
   105
	{ 
sl@0
   106
	anInfo.Copy(TLocalDriveCapsV4Buf(iCaps)); 
sl@0
   107
	return KErrNone; 
sl@0
   108
	}
sl@0
   109
sl@0
   110
sl@0
   111
/**
sl@0
   112
A private structure that, when Connected, holds a pair of references to 
sl@0
   113
the CProxyDrive and the corresponding TBusLocalDrive's Media Changed flag.
sl@0
   114
*/
sl@0
   115
struct CMassStorageDrive::CLocalDriveRef : public CBase
sl@0
   116
	{
sl@0
   117
	CLocalDriveRef(CProxyDrive& aProxyDrive, TBool& aMediaChanged)
sl@0
   118
	    : iProxyDrive(aProxyDrive), iMediaChanged(aMediaChanged)
sl@0
   119
		{
sl@0
   120
		}
sl@0
   121
	CProxyDrive& iProxyDrive;
sl@0
   122
	TBool& iMediaChanged;
sl@0
   123
	TDriveState iDriveState;	
sl@0
   124
};
sl@0
   125
sl@0
   126
sl@0
   127
//
sl@0
   128
// CScsiTest
sl@0
   129
//
sl@0
   130
inline TBool CScsiTest::DecodePacket(TPtrC8& aCmd)
sl@0
   131
	{ 
sl@0
   132
	return iScsiProt->DecodePacket(aCmd, TestLun); 
sl@0
   133
	}
sl@0
   134
sl@0
   135
sl@0
   136
sl@0
   137
sl@0
   138
//
sl@0
   139
// command wrappers
sl@0
   140
//
sl@0
   141
TRequestSenseData::TRequestSenseData(TPtrC8 aData)
sl@0
   142
: iData(aData)
sl@0
   143
// SCSI-2 spec. p.136
sl@0
   144
	{ 
sl@0
   145
	ASSERT((iData.Length() >= 17) && (iData[7] + 8 == iData.Length())); 
sl@0
   146
	}
sl@0
   147
	
sl@0
   148
inline TInt8 TRequestSenseData::Key()
sl@0
   149
	{ 
sl@0
   150
	return static_cast<TInt8>(iData[2] & 0x0F); 
sl@0
   151
	}
sl@0
   152
		
sl@0
   153
inline TInt8 TRequestSenseData::AdditionalCode()
sl@0
   154
	{ 
sl@0
   155
	return iData[12]; 
sl@0
   156
	}
sl@0
   157
		
sl@0
   158
inline TInt8 TRequestSenseData::AdditionalCodeQualifier()
sl@0
   159
	{ 
sl@0
   160
	return iData[13]; 
sl@0
   161
	}
sl@0
   162
sl@0
   163
sl@0
   164
//
sl@0
   165
// class TInquiryData
sl@0
   166
//
sl@0
   167
TInquiryData::TInquiryData(TPtrC8 aData)
sl@0
   168
	{ 
sl@0
   169
	iData.Set(aData);
sl@0
   170
	}
sl@0
   171
	
sl@0
   172
inline TInt8 TInquiryData::DeviceType() 	// 5 lower bits in 1st byte
sl@0
   173
	{ 
sl@0
   174
	return static_cast<TInt8>(iData[0] & 0x1F); 
sl@0
   175
	}
sl@0
   176
		
sl@0
   177
inline TBool TInquiryData::RMB() 			// high bit in 2nd byte
sl@0
   178
	{ 
sl@0
   179
	return ((iData[1] & 0x80) == 0x80); 
sl@0
   180
	}
sl@0
   181
		
sl@0
   182
inline TInt8 TInquiryData::Version()		// 3rd byte
sl@0
   183
	{ 
sl@0
   184
	return iData[2]; 
sl@0
   185
	}
sl@0
   186
	
sl@0
   187
inline TInt8 TInquiryData::RespDataFrmt()	// 4th byte 
sl@0
   188
	{ 
sl@0
   189
	return (iData[3]); 
sl@0
   190
	}
sl@0
   191
	
sl@0
   192
inline TPtr8 TInquiryData::VendorId()
sl@0
   193
	{ 
sl@0
   194
	return TPtr8(const_cast<TUint8*>(&iData[8]), 8, 8); 
sl@0
   195
	}
sl@0
   196
	
sl@0
   197
inline TPtr8 TInquiryData::ProductId()
sl@0
   198
	{ 
sl@0
   199
	return TPtr8(const_cast<TUint8*>(&iData[16]), 16, 16); 
sl@0
   200
	}
sl@0
   201
sl@0
   202
inline TPtr8 TInquiryData::RevisionLevel()
sl@0
   203
	{ 
sl@0
   204
	return TPtr8(const_cast<TUint8*>(&iData[32]), 4, 4); 
sl@0
   205
	}
sl@0
   206
		
sl@0
   207
inline TInt8 TInquiryData::PeripheralQualifier()	// 3 highest bits in 1st byte
sl@0
   208
	{ 
sl@0
   209
	return static_cast<TInt8>((iData[0] & 0xE0) >> 5); 
sl@0
   210
	}
sl@0
   211
sl@0
   212
inline TInt8 TInquiryData::Length()			// length of Inquiry data
sl@0
   213
	{ 
sl@0
   214
	return static_cast<TInt8>(iData[4] + 4); 
sl@0
   215
	}
sl@0
   216
sl@0
   217
//
sl@0
   218
// class TReadWrite10Cmd
sl@0
   219
//
sl@0
   220
/** set transfer length */
sl@0
   221
inline void TReadWrite10Cmd::SetTransferLength(TUint16 aLength)
sl@0
   222
	{
sl@0
   223
	iCmd[8] = static_cast<TInt8>((aLength & 0xFF00) >> 8);
sl@0
   224
	iCmd[9] = static_cast<TInt8>(aLength & 0x00FF);
sl@0
   225
	}
sl@0
   226
sl@0
   227
/** set protect flag */
sl@0
   228
inline void TReadWrite10Cmd::SetProtect(TUint8 aProtect)
sl@0
   229
	{
sl@0
   230
	// Note: used only 3 lower bits
sl@0
   231
	//			clear flag    and set a new one
sl@0
   232
	iCmd[2] = static_cast<TInt8>((iCmd[2] & 0x1F) | (aProtect << 5));
sl@0
   233
	}
sl@0
   234
sl@0
   235
/** setup read command */
sl@0
   236
inline void TReadWrite10Cmd::SetRead()
sl@0
   237
	{
sl@0
   238
	iCmd[1] = 0x28; // READ(10) cmd
sl@0
   239
	}
sl@0
   240
sl@0
   241
/** setup write command */
sl@0
   242
inline void TReadWrite10Cmd::SetWrite()
sl@0
   243
	{
sl@0
   244
	iCmd[1] = 0x2A; // WRITE(10) cmd
sl@0
   245
	}
sl@0
   246
sl@0
   247
/** setup verify command */
sl@0
   248
inline void TReadWrite10Cmd::SetVerify()
sl@0
   249
	{
sl@0
   250
	iCmd[1] = 0x2F; // VERIFY(10) cmd
sl@0
   251
	}
sl@0
   252
sl@0
   253
/** set BYTCHK fiels. Valid for VERIFY10 cmd only */
sl@0
   254
inline void TReadWrite10Cmd::SetBytChk (TBool aSet)
sl@0
   255
	{
sl@0
   256
	if (0x2F == iCmd[1])	// if VERIFY(10)
sl@0
   257
		{
sl@0
   258
		iCmd[2] = static_cast<TInt8>((iCmd[2] & 0xFD) | (aSet << 1));
sl@0
   259
		}
sl@0
   260
	}
sl@0
   261
sl@0
   262
/** c'or */
sl@0
   263
inline TModeSenseCmd::TModeSenseCmd()
sl@0
   264
	{
sl@0
   265
	iCmd.FillZ (iCmd.MaxLength());
sl@0
   266
	
sl@0
   267
	iCmd[0] = static_cast<TInt8>(iCmd.MaxLength()-1);	// size of the Cmd
sl@0
   268
	iCmd[1] = 0x1A;
sl@0
   269
	}
sl@0
   270
sl@0
   271
/** set PC, 2 bits field */
sl@0
   272
inline void TModeSenseCmd::SetPC (TUint8 aPc)
sl@0
   273
	{
sl@0
   274
	iCmd[3] = static_cast<TInt8>((iCmd[3] & 0x3F) | (aPc << 6));
sl@0
   275
	}
sl@0
   276
	
sl@0
   277
/** set page code, 6 bits field */
sl@0
   278
inline void TModeSenseCmd::SetPageCode (TUint8 aPageCode)
sl@0
   279
	{
sl@0
   280
	iCmd[3] = static_cast<TInt8>((iCmd[3] & 0xC0) | aPageCode);
sl@0
   281
	}
sl@0
   282
sl@0
   283
sl@0
   284
inline TInquiryCmd::TInquiryCmd()
sl@0
   285
	{
sl@0
   286
	iCmd.FillZ (iCmd.MaxLength());
sl@0
   287
	iCmd[0] = static_cast<TInt8>(iCmd.MaxLength()-1);	// size of a command itself
sl@0
   288
	iCmd[1] = 0x12; 				// inquiry operation code
sl@0
   289
	iCmd[5] = 36;					// min required allocation length
sl@0
   290
	}
sl@0
   291
sl@0
   292
inline TTestUnitReadyCmd::TTestUnitReadyCmd()
sl@0
   293
	{
sl@0
   294
	iCmd.FillZ (iCmd.MaxLength());
sl@0
   295
	iCmd[0] = static_cast<TInt8>(iCmd.MaxLength()-1);	// size of a command itself
sl@0
   296
	iCmd[1] = 0x00; 				// TEST UNIT READY command
sl@0
   297
	}
sl@0
   298
	
sl@0
   299
inline TMediaRemovalCmd::TMediaRemovalCmd()
sl@0
   300
	{
sl@0
   301
	iCmd.FillZ (iCmd.MaxLength());
sl@0
   302
	iCmd[0] = static_cast<TInt8>(iCmd.MaxLength()-1);	// size of a command itself
sl@0
   303
	iCmd[1] = 0x1E; 				// PREVENT ALLOW MEDIUM REMOVAL command
sl@0
   304
	}
sl@0
   305
	
sl@0
   306
inline TReadCapacityCmd::TReadCapacityCmd()
sl@0
   307
	{
sl@0
   308
	iCmd.FillZ (iCmd.MaxLength());
sl@0
   309
	iCmd[0] = static_cast<TInt8>(iCmd.MaxLength()-1);	// size of a command itself
sl@0
   310
	iCmd[1] = 0x25; 				// READ CAPACITY command
sl@0
   311
	}
sl@0
   312
sl@0
   313
inline TReadCapacityResponse::TReadCapacityResponse(const TDesC8 &aDes)
sl@0
   314
	: TPtrC8(aDes)
sl@0
   315
	{
sl@0
   316
	}
sl@0
   317
	
sl@0
   318
/** accessor */
sl@0
   319
inline TUint32 TReadCapacityResponse::LBAddress()
sl@0
   320
	{
sl@0
   321
	return TUint32(AtC(0)<<24) | (AtC(1)<<16) | AtC(2)<<8 | AtC(3);
sl@0
   322
	}
sl@0
   323
	
sl@0
   324
/** accessor */
sl@0
   325
inline TUint32 TReadCapacityResponse::BlockLength()
sl@0
   326
	{
sl@0
   327
	return TUint32(AtC(4)<<24) | (AtC(5)<<16) | AtC(6)<<8 | AtC(7);
sl@0
   328
	}
sl@0
   329