sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #include sl@0: #include "debug.h" sl@0: #include "msdebug.h" sl@0: #include "msctypes.h" sl@0: #include "mscutils.h" sl@0: sl@0: #include "mtransport.h" sl@0: #include "mprotocol.h" sl@0: #include "tscsiclientreq.h" sl@0: #include "tscsiblockcmds.h" sl@0: sl@0: sl@0: // **** MODE SENSE (6) **** sl@0: void TScsiClientModeSense6Resp::DecodeL(const TDesC8& aPtr) sl@0: { sl@0: __MSFNSLOG sl@0: __SCSIPRINT(_L("--> SCSI MODE SENSE (6)")); sl@0: __SCSIPRINT1(_L("len=%d"), aPtr.Length()); sl@0: // Mode Parameter List sl@0: // SPC-3 7.4.2 sl@0: // - Mode Parameter Header sl@0: // - Block Descriptor(s) sl@0: // - Mode Page(s) sl@0: sl@0: // Mode Parameter Header sl@0: // SPC-3 7.4.3 sl@0: // [0] Mode Data Length sl@0: // [1] Medium Type sl@0: // [2] Device-Specific Paramater sl@0: // [3] Block Descriptor Length sl@0: sl@0: sl@0: // validate length sl@0: if (aPtr.Length() < KResponseLength) sl@0: { sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: TInt modeDataLength = aPtr[0]; sl@0: if (aPtr.Length() - 1 < modeDataLength) sl@0: { sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: TInt mediumType = aPtr[1]; sl@0: TUint8 deviceSpecificParameter = aPtr[2]; sl@0: // TInt blockDescriptorLength = aPtr[3]; sl@0: sl@0: __SCSIPRINT2(_L("Medium Type=%d DSP=0x%x"), mediumType, deviceSpecificParameter); sl@0: // [1] Medium Type sl@0: // 0x00 for SBC sl@0: if (mediumType == 0) sl@0: { sl@0: // [2] Device specific parameter sl@0: // SBC-3 6.3.1 sl@0: // get the WP bit from the Device Specific parameters sl@0: iWriteProtected = (deviceSpecificParameter & 0x80) ? ETrue : EFalse; sl@0: } sl@0: else sl@0: { sl@0: // unsupported medium type sl@0: iWriteProtected = EFalse; sl@0: } sl@0: sl@0: // [3] Block Descriptor Length sl@0: // 0x00 for no descriptors sl@0: sl@0: // No Block Descriptors sl@0: sl@0: // No Mode Pages sl@0: sl@0: } sl@0: sl@0: sl@0: // **** MODE SENSE (10) **** sl@0: void TScsiClientModeSense10Resp::DecodeL(const TDesC8& aPtr) sl@0: { sl@0: __MSFNSLOG sl@0: __SCSIPRINT(_L("--> SCSI MODE SENSE (10)")); sl@0: __SCSIPRINT1(_L("len=%d"), aPtr.Length()); sl@0: // Mode Parameter List sl@0: // SPC-3 7.4.2 sl@0: // - Mode Parameter Header sl@0: // - Block Descriptor(s) sl@0: // - Mode Page(s) sl@0: sl@0: // Mode Parameter Header sl@0: // SPC-3 7.4.3 sl@0: // [0] Mode Data Length sl@0: // [1] Mode Data Length sl@0: // [2] Medium Type sl@0: // [3] Device-Specific Paramater sl@0: // [4] Reserved sl@0: // [5] Reserved sl@0: // [6] Block Descriptor Length sl@0: // [7] Block Descriptor Length sl@0: sl@0: // validate length sl@0: if (aPtr.Length() < KResponseLength) sl@0: { sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: TInt modeDataLength = BigEndian::Get32(&aPtr[0]); sl@0: if (aPtr.Length() - 2 < modeDataLength) sl@0: { sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: TInt mediumType = aPtr[2]; sl@0: TUint8 deviceSpecificParameter = aPtr[3]; sl@0: // TInt blockDescriptorLength = BigEndian::Get32(&aPtr[6]);; sl@0: sl@0: __SCSIPRINT2(_L("Medium Type=%d DSP=0x%x"), mediumType, deviceSpecificParameter); sl@0: // [1] Medium Type sl@0: // 0x00 for SBC sl@0: if (mediumType == 0) sl@0: { sl@0: // [2] Device specific parameter sl@0: // SBC-3 6.3.1 sl@0: // get the WP bit from the Device Specific parameters sl@0: iWriteProtected = (deviceSpecificParameter & 0x80) ? ETrue : EFalse; sl@0: } sl@0: else sl@0: { sl@0: // unsupported medium type sl@0: iWriteProtected = EFalse; sl@0: } sl@0: sl@0: // [3] Block Descriptor Length sl@0: // 0x00 for no descriptors sl@0: sl@0: // No Block Descriptors sl@0: sl@0: // No Mode Pages sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: // **** READ CAPACITY (10) *** sl@0: TInt TScsiClientReadCapacity10Req::EncodeRequestL(TDes8& aBuffer) const sl@0: { sl@0: __MSFNSLOG sl@0: __SCSIPRINT(_L("<-- READ CAPACITY 10")); sl@0: TInt length = TScsiClientReq::EncodeRequestL(aBuffer); sl@0: sl@0: if (iLba) sl@0: { sl@0: // PMI bit sl@0: aBuffer[8] = 0x01; sl@0: // LBA sl@0: BigEndian::Put32(&aBuffer[2], iLba); sl@0: } sl@0: return length; sl@0: } sl@0: sl@0: sl@0: void TScsiClientReadCapacity10Resp::DecodeL(const TDesC8& aPtr) sl@0: { sl@0: __MSFNSLOG sl@0: __SCSIPRINT(_L("--> SCSI READ CAPACITY (10)")); sl@0: iLba = BigEndian::Get32(&aPtr[0]); sl@0: iBlockSize = BigEndian::Get32(&aPtr[4]); sl@0: } sl@0: sl@0: sl@0: // **** RdWr10 **** sl@0: TInt TScsiClientRdWr10Req::EncodeRequestL(TDes8& aBuffer) const sl@0: { sl@0: __MSFNSLOG sl@0: TInt length = TScsiClientReq::EncodeRequestL(aBuffer); sl@0: sl@0: // PROTECT sl@0: if (iProtect) sl@0: aBuffer[1] = iProtect << 5; sl@0: sl@0: __SCSIPRINT2(_L("LBA=%08x LEN=%08x"), iLogicalBlockAddress, iBlockTransferLength); sl@0: // LOGICAL BLOCK ADDRESS sl@0: BigEndian::Put32(&aBuffer[2], iLogicalBlockAddress); sl@0: // TRANSFER LENGTH sl@0: BigEndian::Put16(&aBuffer[7], iBlockTransferLength); sl@0: return length; sl@0: } sl@0: sl@0: // **** READ (10) **** sl@0: TInt TScsiClientRead10Req::EncodeRequestL(TDes8& aBuffer) const sl@0: { sl@0: __MSFNSLOG sl@0: __SCSIPRINT(_L("<-- SCSI READ (10)")); sl@0: TInt length = TScsiClientRdWr10Req::EncodeRequestL(aBuffer); sl@0: return length; sl@0: } sl@0: sl@0: sl@0: // **** START STOP UNIT **** sl@0: TInt TScsiClientStartStopUnitReq::EncodeRequestL(TDes8& aBuffer) const sl@0: { sl@0: __MSFNSLOG sl@0: __SCSIPRINT(_L("--> SCSI START STOP UNIT")); sl@0: TInt length = TScsiClientReq::EncodeRequestL(aBuffer); sl@0: sl@0: // byte 1 mask sl@0: const TUint8 KImmedMask = 0x01; sl@0: sl@0: // byte 4 mask sl@0: const TUint8 KStartMask = 0x01; sl@0: const TUint8 KLoejMask = 0x02; sl@0: sl@0: if (iImmed) sl@0: aBuffer[1] |= KImmedMask; sl@0: if (iStart) sl@0: aBuffer[4] |= KStartMask; sl@0: if (iLoej) sl@0: aBuffer[4] |= KLoejMask; sl@0: return length; sl@0: } sl@0: sl@0: sl@0: // **** WRITE (10) **** sl@0: TInt TScsiClientWrite10Req::EncodeRequestL(TDes8& aBuffer) const sl@0: { sl@0: __MSFNSLOG sl@0: __SCSIPRINT(_L("<-- SCSI WRITE 10")); sl@0: sl@0: TInt length = TScsiClientRdWr10Req::EncodeRequestL(aBuffer); sl@0: return length; sl@0: } sl@0: