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