userlibandfileserver/fileserver/shostmassstorage/server/protocol/tscsiprimarycmds.cpp
author Slion
Tue, 08 Dec 2009 08:11:42 +0100
branchanywhere
changeset 19 f6d3d9676ee4
parent 0 a41df078684a
child 33 0173bcd7697c
permissions -rw-r--r--
Trying to figure out how to implement my WINC like compatibility layer. Going the emulation way is probably not so smart. We should not use the kernel but rather hook native functions in the Exec calls.

// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of the License "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
// scsiprimarycmds.cpp
// 
//

/**
 @file
 @internalTechnology
*/

#include <e32base.h>
#include <e32base_private.h>

#include "msctypes.h"
#include "debug.h"
#include "msdebug.h"

#include "mtransport.h"
#include "mprotocol.h"

#include "tscsiclientreq.h"
#include "tscsiprimarycmds.h"


// **** TEST UNIT READY ****
TInt TScsiClientTestUnitReadyReq::EncodeRequestL(TDes8& aBuffer) const
    {
	__MSFNSLOG
    __SCSIPRINT(_L("<-- SCSI TEST UNIT READY"));
    TInt length = TScsiClientReq::EncodeRequestL(aBuffer);
    return length;
    }


// **** REQUEST SENSE ****
void TScsiClientRequestSenseResp::DecodeSenseInfo(const TDesC8& aPtr)
    {
	__MSFNSLOG
    iResponseCode = static_cast<TResponseCode>(aPtr[0]);
    iSenseInfo.iSenseCode = aPtr[02];
    iSenseInfo.iAdditional = aPtr[12];
    iSenseInfo.iQualifier = aPtr[13];
    }


void TScsiClientRequestSenseResp::DecodeL(const TDesC8& aPtr)
	{
	__MSFNSLOG
    __SCSIPRINT(_L("--> SCSI REQUEST SENSE"));
    if (aPtr.Length() < KResponseLength)
        {
        // Handle short data.
        // The data not transferred is assumed to be zero.

        // Create full size buffer
        TBuf8<KResponseLength> buffer;

        // Copy data into buffer
        buffer = aPtr;
        // Fill remainder with 0's
        buffer.AppendFill(0, KResponseLength - aPtr.Length());

        DecodeSenseInfo(buffer);
        }
    else
        {
        DecodeSenseInfo(aPtr);
        }
	}


// **** INQUIRY ****
void TScsiClientInquiryResp::DecodeInquiry(const TDesC8& aPtr)
    {
	__MSFNSLOG
    __SCSIPRINT(_L("--> SCSI INQUIRY"));
    iPeripheralInfo.iRemovable = (aPtr[1] & 0x80) ? ETrue : EFalse;

    iPeripheralInfo.iPeripheralQualifier = aPtr[0] >> 5;
    iPeripheralInfo.iPeripheralDeviceType = aPtr[0] & 0x1F;
    iPeripheralInfo.iVersion = aPtr[2];
    iPeripheralInfo.iResponseDataFormat = aPtr[3] & 0x0F;

    TPtrC8 vendorId(&aPtr[8], 8);
    iPeripheralInfo.iIdentification.iVendorId.Copy(vendorId);

    TPtrC8 productId(&aPtr[16], 16);
    iPeripheralInfo.iIdentification.iProductId.Copy(productId);

    TPtrC8 productRev(&aPtr[32], 4);
    iPeripheralInfo.iIdentification.iProductRev.Copy(productRev);
    }


void TScsiClientInquiryResp::DecodeL(const TDesC8& aPtr)
	{
    __MSFNSLOG
    __SCSIPRINT(_L("--> SCSI INQUIRY"));
    if (aPtr.Length() < KResponseLength)
        {
        // Handle short data.
        // The data not transferred is assumed to be zero.

        // Create zeroed buffer
        TBuf8<KResponseLength> buffer;
        buffer.FillZ(KResponseLength);

        // Copy data into buffer
        buffer = aPtr;
        buffer.SetLength(KResponseLength);

        DecodeInquiry(buffer);
        }
    else
        {
        DecodeInquiry(aPtr);
        }
	}


// ****	PREVENT MEDIA REMOVAL ****
TInt TScsiClientPreventMediaRemovalReq::EncodeRequestL(TDes8& aBuffer) const
    {
    __MSFNSLOG
    __SCSIPRINT(_L("<-- SCSI PREVENT MEDIA REMOVAL"));
    TInt length = TScsiClientReq::EncodeRequestL(aBuffer);
	if (iPrevent)
        aBuffer[4] |= 0x01;
    return length;
    }