kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/protocol/tscsiservercmds.cpp
changeset 297 b2826f67641f
parent 0 a41df078684a
equal deleted inserted replaced
296:94f2adf59133 297:b2826f67641f
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    25 #include "scsimsctypes.h"
    25 #include "scsimsctypes.h"
    26 
    26 
    27 #include "tscsiserverreq.h"
    27 #include "tscsiserverreq.h"
    28 #include "tscsiservercmds.h"
    28 #include "tscsiservercmds.h"
    29 #include "debug.h"
    29 #include "debug.h"
    30 #include "msdebug.h"
       
    31 
    30 
    32 /**
    31 /**
    33 Default constructor for TSenseInfo
    32 Default constructor for TSenseInfo
    34 */
    33 */
    35 TSrvSenseInfo::TSrvSenseInfo()
    34 TSrvSenseInfo::TSrvSenseInfo()
    36     {
    35     {
    37     __MSFNLOG
       
    38     iSenseCode = ENoSense;
    36     iSenseCode = ENoSense;
    39     iAdditional = 0;
    37     iAdditional = 0;
    40 	iQualifier = 0;
    38     iQualifier = 0;
    41     }
    39     }
    42 
    40 
    43 /**
    41 /**
    44 Set sense with no additional info.
    42 Set sense with no additional info.
    45 
    43 
    46 @param aSenseCode sense key
    44 @param aSenseCode sense key
    47 */
    45 */
    48 void TSrvSenseInfo::SetSense(TSenseCode aSenseCode)
    46 void TSrvSenseInfo::SetSense(TSenseCode aSenseCode)
    49 	{
    47     {
    50     __MSFNLOG
    48     iSenseCode  = static_cast<TUint8>(aSenseCode);
    51 	iSenseCode	= static_cast<TUint8>(aSenseCode);
    49     iAdditional = 0;
    52 	iAdditional = 0;
    50     iQualifier  = 0;
    53 	iQualifier  = 0;
    51     }
    54 	}
       
    55 
    52 
    56 
    53 
    57 /**
    54 /**
    58 Set sense with additional info.
    55 Set sense with additional info.
    59 
    56 
    61 @param aAdditional additional sense code (ASC)
    58 @param aAdditional additional sense code (ASC)
    62 */
    59 */
    63 void TSrvSenseInfo::SetSense(TSenseCode aSenseCode,
    60 void TSrvSenseInfo::SetSense(TSenseCode aSenseCode,
    64                           TAdditionalCode aAdditional)
    61                           TAdditionalCode aAdditional)
    65 
    62 
    66 	{
    63     {
    67     __MSFNLOG
    64     iSenseCode = static_cast<TUint8>(aSenseCode);
    68 	iSenseCode = static_cast<TUint8>(aSenseCode);
    65     iAdditional = static_cast<TUint8>(aAdditional);
    69 	iAdditional = static_cast<TUint8>(aAdditional);
    66     iQualifier = 0;
    70 	iQualifier = 0;
    67     }
    71 	}
       
    72 
    68 
    73 
    69 
    74 /**
    70 /**
    75 Set sense with additional info and qualifier.
    71 Set sense with additional info and qualifier.
    76 
    72 
    79 @param aQualifier additional sense code qualifier (ASCQ)
    75 @param aQualifier additional sense code qualifier (ASCQ)
    80 */
    76 */
    81 void TSrvSenseInfo::SetSense(TSenseCode aSenseCode,
    77 void TSrvSenseInfo::SetSense(TSenseCode aSenseCode,
    82                           TAdditionalCode aAdditional,
    78                           TAdditionalCode aAdditional,
    83                           TUint8 aQualifier)
    79                           TUint8 aQualifier)
    84 	{
    80     {
    85     __MSFNLOG
    81     iSenseCode = static_cast<TUint8>(aSenseCode);
    86 	iSenseCode = static_cast<TUint8>(aSenseCode);
    82     iAdditional = static_cast<TUint8>(aAdditional);
    87 	iAdditional = static_cast<TUint8>(aAdditional);
    83     iQualifier = aQualifier;
    88 	iQualifier = aQualifier;
    84     }
    89 	}
       
    90 
    85 
    91 
    86 
    92 // **** TEST UNIT READY ****
    87 // **** TEST UNIT READY ****
    93 // **** REQUEST SENSE ****
    88 // **** REQUEST SENSE ****
    94 void TScsiServerRequestSenseResp::Encode(TDes8& aBuffer) const
    89 void TScsiServerRequestSenseResp::Encode(TDes8& aBuffer) const
    95     {
    90     {
    96     __MSFNSLOG
       
    97     aBuffer.FillZ(KCommandLength);
    91     aBuffer.FillZ(KCommandLength);
    98     __PRINT(_L("->PROTOCOL(SCSI) REQUEST SENSE\n"));
    92     __PRINT(_L("->PROTOCOL(SCSI) REQUEST SENSE\n"));
    99     //additional sense length
    93     //additional sense length
   100 	aBuffer[07] = static_cast<TUint8>(KCommandLength - 8);
    94     aBuffer[07] = static_cast<TUint8>(KCommandLength - 8);
   101 
    95 
   102     aBuffer[0] = iResponseCode;
    96     aBuffer[0] = iResponseCode;
   103 	aBuffer[02] = static_cast<TUint8>(iSensePtr->iSenseCode);
    97     aBuffer[02] = static_cast<TUint8>(iSensePtr->iSenseCode);
   104 	aBuffer[12] = iSensePtr->iAdditional;
    98     aBuffer[12] = iSensePtr->iAdditional;
   105 	aBuffer[13] = iSensePtr->iQualifier;
    99     aBuffer[13] = iSensePtr->iQualifier;
   106 
   100 
   107     //truncate to Allocation Length of the Request
   101     //truncate to Allocation Length of the Request
   108     TUint length = iAllocationLength < KCommandLength ?
   102     TUint length = iAllocationLength < KCommandLength ?
   109                     iAllocationLength : KCommandLength;
   103                     iAllocationLength : KCommandLength;
   110     aBuffer.SetLength(length);
   104     aBuffer.SetLength(length);
   111     }
   105     }
   112 
   106 
   113 // **** INQUIRY ****
   107 // **** INQUIRY ****
   114 void TScsiServerInquiryReq::DecodeL(const TDesC8& aPtr)
   108 void TScsiServerInquiryReq::DecodeL(const TDesC8& aPtr)
   115     {
   109     {
   116     __MSFNLOG
   110     TScsiServerReq::DecodeL(aPtr);
   117 	TScsiServerReq::DecodeL(aPtr);
       
   118     iCmdDt = aPtr[1] & 0x2;
   111     iCmdDt = aPtr[1] & 0x2;
   119     iEvpd = aPtr[1] & 0x1;
   112     iEvpd = aPtr[1] & 0x1;
   120     iPage = aPtr[2];
   113     iPage = aPtr[2];
   121     iAllocationLength = aPtr[4];
   114     iAllocationLength = aPtr[4];
   122     __PRINT(_L("<-PROTOCOL(SCSI) INQUIRY\n"));
   115     __PRINT(_L("<-PROTOCOL(SCSI) INQUIRY\n"));
   123     }
   116     }
   124 
   117 
   125 
   118 
   126 void TScsiServerInquiryResp::Encode(TDes8& aBuffer) const
   119 void TScsiServerInquiryResp::Encode(TDes8& aBuffer) const
   127     {
   120     {
   128     __MSFNSLOG
       
   129     __PRINT(_L("->PROTOCOL(SCSI) INQUIRY\n"));
   121     __PRINT(_L("->PROTOCOL(SCSI) INQUIRY\n"));
   130 
   122 
   131 	aBuffer.FillZ(KResponseLength);
   123     aBuffer.FillZ(KResponseLength);
   132 
   124 
   133     // MSB: RMB : Removable
   125     // MSB: RMB : Removable
   134     if (iRemovable)
   126     if (iRemovable)
   135         {
   127         {
   136         aBuffer[1] |= 0x80;
   128         aBuffer[1] |= 0x80;
   138 
   130 
   139     // AERC, TrmTsk, NormACA, Response Data Format
   131     // AERC, TrmTsk, NormACA, Response Data Format
   140     aBuffer[3] |= (iResponseDataFormat & 0x0F);
   132     aBuffer[3] |= (iResponseDataFormat & 0x0F);
   141 
   133 
   142     // Additional Length
   134     // Additional Length
   143 	aBuffer[4] = 0x1F;
   135     aBuffer[4] = 0x1F;
   144 
   136 
   145     // Vendor ID (Vendor Specific/Logged by T10)
   137     // Vendor ID (Vendor Specific/Logged by T10)
   146 	TPtr8 vendorId(&aBuffer[8], 8, 8);
   138     TPtr8 vendorId(&aBuffer[8], 8, 8);
   147 	vendorId.Fill(' ', 8);
   139     vendorId.Fill(' ', 8);
   148 	vendorId.Copy(iConfig.iVendorId);
   140     vendorId.Copy(iConfig.iVendorId);
   149 
   141 
   150     // Product ID (Vendor Specific)
   142     // Product ID (Vendor Specific)
   151     TPtr8 productId(&aBuffer[16], 16, 16);
   143     TPtr8 productId(&aBuffer[16], 16, 16);
   152     productId.Fill(' ', 16);
   144     productId.Fill(' ', 16);
   153     productId.Copy(iConfig.iProductId);
   145     productId.Copy(iConfig.iProductId);
   162                     iAllocationLength : KResponseLength;
   154                     iAllocationLength : KResponseLength;
   163     aBuffer.SetLength(length);
   155     aBuffer.SetLength(length);
   164     }
   156     }
   165 
   157 
   166 
   158 
   167 // ****	MODE SENSE (6) ****
   159 // **** MODE SENSE (6) ****
   168 void TScsiServerModeSense6Req::DecodeL(const TDesC8& aPtr)
   160 void TScsiServerModeSense6Req::DecodeL(const TDesC8& aPtr)
   169     {
   161     {
   170     __MSFNLOG
   162     TScsiServerReq::DecodeL(aPtr);
   171 	TScsiServerReq::DecodeL(aPtr);
       
   172     iPageCode = aPtr[2] & 0x3F;
   163     iPageCode = aPtr[2] & 0x3F;
   173     iPageControl = static_cast<TPageControl>(aPtr[2] >> 6);
   164     iPageControl = static_cast<TPageControl>(aPtr[2] >> 6);
   174     iAllocationLength = aPtr[4];
   165     iAllocationLength = aPtr[4];
   175     __PRINT(_L("<-PROTOCOL(SCSI) MODE SENSE (6)\n"));
   166     __PRINT(_L("<-PROTOCOL(SCSI) MODE SENSE (6)\n"));
   176     }
   167     }
   177 
   168 
   178 
   169 
   179 void TScsiServerModeSense6Resp::Encode(TDes8& aBuffer) const
   170 void TScsiServerModeSense6Resp::Encode(TDes8& aBuffer) const
   180     {
   171     {
   181     __MSFNSLOG
       
   182     __PRINT(_L("->PROTOCOL(SCSI) MODE SENSE (6)\n"));
   172     __PRINT(_L("->PROTOCOL(SCSI) MODE SENSE (6)\n"));
   183     // reserve 4 bytes for Length, Media type, Device-specific parameter and
   173     // reserve 4 bytes for Length, Media type, Device-specific parameter and
   184     // Block descriptor length
   174     // Block descriptor length
   185     aBuffer.FillZ(KCommandLength);
   175     aBuffer.FillZ(KCommandLength);
   186 
   176 
   223     TUint length = iAllocationLength < KCommandLength ?
   213     TUint length = iAllocationLength < KCommandLength ?
   224                     iAllocationLength : KCommandLength;
   214                     iAllocationLength : KCommandLength;
   225     aBuffer.SetLength(length);
   215     aBuffer.SetLength(length);
   226     }
   216     }
   227 
   217 
   228 // ****	START STOP UNIT ****
   218 // **** START STOP UNIT ****
   229 void TScsiServerStartStopUnitReq::DecodeL(const TDesC8& aPtr)
   219 void TScsiServerStartStopUnitReq::DecodeL(const TDesC8& aPtr)
   230     {
   220     {
   231     __MSFNLOG
   221     TScsiServerReq::DecodeL(aPtr);
   232 	TScsiServerReq::DecodeL(aPtr);
       
   233 
   222 
   234     const TUint8 KStartMask = 0x01;
   223     const TUint8 KStartMask = 0x01;
   235     const TUint8 KImmedMask = 0x01;
   224     const TUint8 KImmedMask = 0x01;
   236     const TUint8 KLoejMask = 0x02;
   225     const TUint8 KLoejMask = 0x02;
   237 
   226 
   244     __PRINT1(_L("START = %d\n"), iStart);
   233     __PRINT1(_L("START = %d\n"), iStart);
   245     __PRINT1(_L("LOEJ = %d\n"), iLoej);
   234     __PRINT1(_L("LOEJ = %d\n"), iLoej);
   246     }
   235     }
   247 
   236 
   248 
   237 
   249 // ****	PREVENT MEDIA REMOVAL ****
   238 // **** PREVENT MEDIA REMOVAL ****
   250 void TScsiServerPreventMediaRemovalReq::DecodeL(const TDesC8& aPtr)
   239 void TScsiServerPreventMediaRemovalReq::DecodeL(const TDesC8& aPtr)
   251     {
   240     {
   252     __MSFNLOG
   241     TScsiServerReq::DecodeL(aPtr);
   253 	TScsiServerReq::DecodeL(aPtr);
   242     iPrevent = aPtr[4] & 0x01;
   254 	iPrevent = aPtr[4] & 0x01;
   243     __PRINT1(_L("<-PROTOCOL(SCSI) PREVENT MEDIA REMOVAL prevent = %d\n"), iPrevent);
   255 	__PRINT1(_L("<-PROTOCOL(SCSI) PREVENT MEDIA REMOVAL prevent = %d\n"), iPrevent);
   244     }
   256     }
   245 
   257 
   246 
   258 
   247 // **** READ FORMAT CAPACITIES ****
   259 // ****	READ FORMAT CAPACITIES ****
       
   260 void TScsiServerReadFormatCapacitiesReq::DecodeL(const TDesC8& aPtr)
   248 void TScsiServerReadFormatCapacitiesReq::DecodeL(const TDesC8& aPtr)
   261     {
   249     {
   262     __MSFNLOG
   250     TScsiServerReq::DecodeL(aPtr);
   263 	TScsiServerReq::DecodeL(aPtr);
       
   264     const TUint8* ptr = aPtr.Ptr();
   251     const TUint8* ptr = aPtr.Ptr();
   265     iAllocationLength = BigEndian::Get32(ptr+7);
   252     iAllocationLength = BigEndian::Get32(ptr+7);
   266 	__PRINT(_L("<-PROTOCOL(SCSI) READ FORMAT CAPACITIES\n"));
   253     __PRINT(_L("<-PROTOCOL(SCSI) READ FORMAT CAPACITIES\n"));
   267     }
   254     }
   268 
   255 
   269 
   256 
   270 void TScsiServerReadFormatCapacitiesResp::Encode(TDes8& aBuffer) const
   257 void TScsiServerReadFormatCapacitiesResp::Encode(TDes8& aBuffer) const
   271     {
   258     {
   272     __MSFNSLOG
   259     __PRINT(_L("->PROTOCOL(SCSI) READ FORMAT CAPACITIES\n"));
   273 	__PRINT(_L("->PROTOCOL(SCSI) READ FORMAT CAPACITIES\n"));
   260     aBuffer.FillZ(KResponseLength);
   274 	aBuffer.FillZ(KResponseLength);
   261     aBuffer[3] = 0x08;  // Capacity List Length
   275 	aBuffer[3] = 0x08;	// Capacity List Length
   262 
   276 
   263     aBuffer[4] = static_cast<TUint8>(iNumberBlocks >> 24);  // Number of blocks
   277 	aBuffer[4] = static_cast<TUint8>(iNumberBlocks >> 24);	// Number of blocks
   264     aBuffer[5] = static_cast<TUint8>(iNumberBlocks >> 16);  //
   278 	aBuffer[5] = static_cast<TUint8>(iNumberBlocks >> 16);	//
   265     aBuffer[6] = static_cast<TUint8>(iNumberBlocks >> 8);   //
   279 	aBuffer[6] = static_cast<TUint8>(iNumberBlocks >> 8);	//
   266     aBuffer[7] = static_cast<TUint8>(iNumberBlocks);        //
   280 	aBuffer[7] = static_cast<TUint8>(iNumberBlocks);		//
   267 
   281 
   268     aBuffer[8] = 0x02;  // Formatted size
   282 	aBuffer[8] = 0x02;	// Formatted size
   269 
   283 
   270     aBuffer[9]  = 0x00; // 512 Byte Blocks
   284 	aBuffer[9]  = 0x00;	// 512 Byte Blocks
   271     aBuffer[10] = 0x02; //
   285 	aBuffer[10] = 0x02;	//
   272     aBuffer[11] = 0x00; //
   286 	aBuffer[11] = 0x00;	//
       
   287 
   273 
   288     // Truncate to Allocation Length of the Request
   274     // Truncate to Allocation Length of the Request
   289     // Truncate to Allocation Length of the Request
   275     // Truncate to Allocation Length of the Request
   290     TUint length = iAllocationLength < KResponseLength ?
   276     TUint length = iAllocationLength < KResponseLength ?
   291                     iAllocationLength : KResponseLength;
   277                     iAllocationLength : KResponseLength;
   292     aBuffer.SetLength(length);
   278     aBuffer.SetLength(length);
   293     }
   279     }
   294 
   280 
   295 
   281 
   296 // ****	READ CAPACITY (10) ****
   282 // **** READ CAPACITY (10) ****
   297 void TScsiServerReadCapacity10Req::DecodeL(const TDesC8& aPtr)
   283 void TScsiServerReadCapacity10Req::DecodeL(const TDesC8& aPtr)
   298     {
   284     {
   299     __MSFNLOG
   285     TScsiServerReq::DecodeL(aPtr);
   300 	TScsiServerReq::DecodeL(aPtr);
       
   301     iPmi = aPtr[8] & 0x01;
   286     iPmi = aPtr[8] & 0x01;
   302     const TUint8* ptr = aPtr.Ptr();
   287     const TUint8* ptr = aPtr.Ptr();
   303 	iLogicalBlockAddress = BigEndian::Get32(ptr+2);
   288     iLogicalBlockAddress = BigEndian::Get32(ptr+2);
   304     __PRINT(_L("<-PROTOCOL(SCSI) READ CAPACITY (10)\n"));
   289     __PRINT(_L("<-PROTOCOL(SCSI) READ CAPACITY (10)\n"));
   305     }
   290     }
   306 
   291 
   307 
   292 
   308 void TScsiServerReadCapacity10Resp::Encode(TDes8& aBuffer) const
   293 void TScsiServerReadCapacity10Resp::Encode(TDes8& aBuffer) const
   309     {
   294     {
   310     __MSFNSLOG
       
   311     aBuffer.FillZ(KCommandLength);
   295     aBuffer.FillZ(KCommandLength);
   312 
   296 
   313     __PRINT3(_L("->PROTOCOL(SCSI) READ CAPACITY (10) Block size=0x%X, NumBlocks=0x%08X%08X\n"),
   297     __PRINT3(_L("->PROTOCOL(SCSI) READ CAPACITY (10) Block size=0x%X, NumBlocks=0x%08X%08X\n"),
   314              iBlockSize,
   298              iBlockSize,
   315              I64HIGH(iNumberBlocks),
   299              I64HIGH(iNumberBlocks),
   329         {
   313         {
   330         // indicate that size more then )0xFFFFFFFF
   314         // indicate that size more then )0xFFFFFFFF
   331         aBuffer[0] = aBuffer[1] = aBuffer[2] = aBuffer[3] = 0xFF;
   315         aBuffer[0] = aBuffer[1] = aBuffer[2] = aBuffer[3] = 0xFF;
   332         }
   316         }
   333 
   317 
   334 	// Block Size
   318     // Block Size
   335     aBuffer[4] = static_cast<TUint8>(iBlockSize >> 24);
   319     aBuffer[4] = static_cast<TUint8>(iBlockSize >> 24);
   336     aBuffer[5] = static_cast<TUint8>(iBlockSize >> 16);
   320     aBuffer[5] = static_cast<TUint8>(iBlockSize >> 16);
   337     aBuffer[6] = static_cast<TUint8>(iBlockSize >> 8);
   321     aBuffer[6] = static_cast<TUint8>(iBlockSize >> 8);
   338     aBuffer[7] = static_cast<TUint8>(iBlockSize);
   322     aBuffer[7] = static_cast<TUint8>(iBlockSize);
   339     }
   323     }
   340 
   324 
   341 
   325 
   342 // ****	RdWr10 ****
   326 // **** RdWr10 ****
   343 void TScsiServerRdWr10Req::DecodeL(const TDesC8& aDes)
   327 void TScsiServerRdWr10Req::DecodeL(const TDesC8& aDes)
   344 {
   328 {
   345     __MSFNLOG
   329     TScsiServerReq::DecodeL(aDes);
   346 	TScsiServerReq::DecodeL(aDes);
       
   347 
   330 
   348     // PROTECT
   331     // PROTECT
   349 	iProtect = aDes[1] >> 5;
   332     iProtect = aDes[1] >> 5;
   350 
   333 
   351     const TUint8* ptr = aDes.Ptr();
   334     const TUint8* ptr = aDes.Ptr();
   352     // LOGICAL BLOCK ADDRESS
   335     // LOGICAL BLOCK ADDRESS
   353 	iLogicalBlockAddress = BigEndian::Get32(ptr+2);
   336     iLogicalBlockAddress = BigEndian::Get32(ptr+2);
   354     // TRANSFER LENGTH
   337     // TRANSFER LENGTH
   355 	iTransferLength = BigEndian::Get16(ptr+7);
   338     iTransferLength = BigEndian::Get16(ptr+7);
   356 
   339 
   357 	__PRINT2(_L("<-PROTOCOL(SCSI) RD/WR (10) : LBA = %x, Length = %x  (blocks)\n"),
   340     __PRINT2(_L("<-PROTOCOL(SCSI) RD/WR (10) : LBA = %x, Length = %x  (blocks)\n"),
   358              iLogicalBlockAddress, iTransferLength);
   341              iLogicalBlockAddress, iTransferLength);
   359 }
   342 }
   360 
   343 
   361 
   344 
   362 // ****	READ (10) ****
   345 // **** READ (10) ****
   363 // ****	WRITE (10) ****
   346 // **** WRITE (10) ****
   364 // ****	VERIFY (10) ****
   347 // **** VERIFY (10) ****
   365 void TScsiServerVerify10Req::DecodeL(const TDesC8& aPtr)
   348 void TScsiServerVerify10Req::DecodeL(const TDesC8& aPtr)
   366     {
   349     {
   367     __MSFNLOG
   350     TScsiServerRdWr10Req::DecodeL(aPtr);
   368 	TScsiServerRdWr10Req::DecodeL(aPtr);
   351     iBytchk = aPtr[1] & 0x02 ? ETrue : EFalse;
   369 	iBytchk = aPtr[1] & 0x02 ? ETrue : EFalse;
   352     }
   370     }