os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/server/controller/cusbhostmslogicalunit.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/server/controller/cusbhostmslogicalunit.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,250 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @internalTechnology
    1.22 +*/
    1.23 +
    1.24 +#include <e32base.h>
    1.25 +
    1.26 +#include "shared.h"
    1.27 +#include "msgservice.h"
    1.28 +#include "msctypes.h"
    1.29 +
    1.30 +#include "mprotocol.h"
    1.31 +#include "mblocktransferprotocol.h"
    1.32 +#include "tspcclientinterface.h"
    1.33 +#include "cscsiprotocol.h"
    1.34 +
    1.35 +#include "cusbhostmslogicalunit.h"
    1.36 +#include "usbmshostpanic.h"
    1.37 +#include "msdebug.h"
    1.38 +#include "debug.h"
    1.39 +
    1.40 +
    1.41 +CUsbHostMsLogicalUnit* CUsbHostMsLogicalUnit::NewL(TLun aLun)
    1.42 +    {
    1.43 +    __MSFNSLOG
    1.44 +	CUsbHostMsLogicalUnit* r = new (ELeave) CUsbHostMsLogicalUnit(aLun);
    1.45 +	CleanupStack::PushL(r);
    1.46 +	r->ConstructL();
    1.47 +	CleanupStack::Pop();
    1.48 +	return r;
    1.49 +	}
    1.50 +
    1.51 +
    1.52 +void CUsbHostMsLogicalUnit::ConstructL()
    1.53 +    {
    1.54 +    __MSFNLOG
    1.55 +    const TInt KInitialDataBufSize = 0x200;
    1.56 +	iDataBuf.CreateL(KInitialDataBufSize);
    1.57 +    }
    1.58 +
    1.59 +
    1.60 +CUsbHostMsLogicalUnit::CUsbHostMsLogicalUnit(TLun aLun)
    1.61 +:   iProtocol(NULL),
    1.62 +    iLun(aLun),
    1.63 +	iSuspendRequest(EFalse)
    1.64 +    {
    1.65 +    __MSFNLOG
    1.66 +	}
    1.67 +
    1.68 +CUsbHostMsLogicalUnit::~CUsbHostMsLogicalUnit()
    1.69 +    {
    1.70 +    __MSFNLOG
    1.71 +    iDataBuf.Close();
    1.72 +	delete iProtocol;
    1.73 +	}
    1.74 +
    1.75 +
    1.76 +void CUsbHostMsLogicalUnit::InitL()
    1.77 +    {
    1.78 +    __MSFNLOG
    1.79 +	iProtocol->InitialiseUnitL();
    1.80 +    }
    1.81 +
    1.82 +void CUsbHostMsLogicalUnit::UnInitL()
    1.83 +    {
    1.84 +    __MSFNLOG
    1.85 +	iProtocol->UninitialiseUnitL();
    1.86 +    }
    1.87 +
    1.88 +void CUsbHostMsLogicalUnit::ReadL(const RMessage2& aMessage)
    1.89 +    {
    1.90 +    __MSFNLOG
    1.91 +	TReadWrite p;
    1.92 +	TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
    1.93 +	aMessage.ReadL(0, pReadWrite);
    1.94 +    __HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
    1.95 +
    1.96 +    User::LeaveIfError(CheckPosition(p));
    1.97 +
    1.98 +	// check if buffer can hold requested data and resize if not
    1.99 +	if (iDataBuf.MaxLength() < p.iLen)
   1.100 +        iDataBuf.ReAllocL(p.iLen);
   1.101 +
   1.102 +    iProtocol->ReadL(p.iPos, iDataBuf, p.iLen);
   1.103 +    aMessage.WriteL(1, iDataBuf);
   1.104 +    }
   1.105 +
   1.106 +
   1.107 +void CUsbHostMsLogicalUnit::WriteL(const RMessage2& aMessage)
   1.108 +    {
   1.109 +    __MSFNLOG
   1.110 +	TReadWrite p;
   1.111 +	TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
   1.112 +	aMessage.ReadL(1, pReadWrite);
   1.113 +    __HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
   1.114 +
   1.115 +    User::LeaveIfError(CheckPosition(p));
   1.116 +
   1.117 +    // check if buffer can hold requested data and resize if not
   1.118 +    if (iDataBuf.MaxLength() < p.iLen)
   1.119 +        iDataBuf.ReAllocL(p.iLen);
   1.120 +
   1.121 +	aMessage.ReadL(0, iDataBuf);
   1.122 +	iProtocol->WriteL(p.iPos, iDataBuf, p.iLen);
   1.123 +    }
   1.124 +
   1.125 +
   1.126 +void CUsbHostMsLogicalUnit::EraseL(const RMessage2& aMessage)
   1.127 +    {
   1.128 +    __MSFNLOG
   1.129 +	TReadWrite p;
   1.130 +	TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
   1.131 +	aMessage.ReadL(0, pReadWrite);
   1.132 +    __HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
   1.133 +
   1.134 +    User::LeaveIfError(CheckPosition(p));
   1.135 +
   1.136 +    // check if buffer can hold requested data and resize if not
   1.137 +    if (iDataBuf.MaxLength() < p.iLen)
   1.138 +        iDataBuf.ReAllocL(p.iLen);
   1.139 +
   1.140 +    iDataBuf.FillZ(p.iLen);
   1.141 +	iProtocol->WriteL(p.iPos, iDataBuf, p.iLen);
   1.142 +    }
   1.143 +
   1.144 +
   1.145 +void CUsbHostMsLogicalUnit::CapsL(const RMessage2& aMessage)
   1.146 +    {
   1.147 +    __MSFNLOG
   1.148 +
   1.149 +    TCapsInfo capsInfo;
   1.150 +    TPckg<TCapsInfo> pckg(capsInfo);
   1.151 +	iProtocol->GetCapacityL(capsInfo);
   1.152 +    iSize = static_cast<TInt64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength;
   1.153 +	aMessage.WriteL(0, pckg);
   1.154 +    }
   1.155 +
   1.156 +void CUsbHostMsLogicalUnit::NotifyChange(const RMessage2& aMessage)
   1.157 +    {
   1.158 +    __MSFNLOG
   1.159 +	iProtocol->NotifyChange(aMessage);
   1.160 +    }
   1.161 +
   1.162 +
   1.163 +void CUsbHostMsLogicalUnit::ForceCompleteNotifyChangeL()
   1.164 +    {
   1.165 +    __MSFNLOG
   1.166 +	iProtocol->ForceCompleteNotifyChangeL();
   1.167 +    }
   1.168 +
   1.169 +void CUsbHostMsLogicalUnit::CancelChangeNotifierL()
   1.170 +    {
   1.171 +    __MSFNLOG
   1.172 +	iProtocol->CancelChangeNotifierL();
   1.173 +    }
   1.174 +
   1.175 +TBool CUsbHostMsLogicalUnit::IsConnected()
   1.176 +	{
   1.177 +	return iProtocol->IsConnected() ? ETrue : EFalse;
   1.178 +	}
   1.179 +
   1.180 +TBool CUsbHostMsLogicalUnit::IsReadyToSuspend()
   1.181 +    {
   1.182 +    __MSFNLOG
   1.183 +	return iSuspendRequest ? ETrue : EFalse;
   1.184 +	}
   1.185 +
   1.186 +void CUsbHostMsLogicalUnit::ReadyToSuspend()
   1.187 +    {
   1.188 +    __MSFNLOG
   1.189 +	iSuspendRequest = ETrue;
   1.190 +    }
   1.191 +
   1.192 +void CUsbHostMsLogicalUnit::CancelReadyToSuspend()
   1.193 +    {
   1.194 +    __MSFNLOG
   1.195 +	iSuspendRequest = EFalse;
   1.196 +    }
   1.197 +
   1.198 +void CUsbHostMsLogicalUnit::SuspendL()
   1.199 +    {
   1.200 +    __MSFNLOG
   1.201 +	iProtocol->SuspendL();
   1.202 +    }
   1.203 +
   1.204 +void CUsbHostMsLogicalUnit::ResumeL()
   1.205 +	{
   1.206 +    __MSFNLOG
   1.207 +	// We do not cancel iSuspendRequest here
   1.208 +	iProtocol->ResumeL();
   1.209 +	}
   1.210 +
   1.211 +void CUsbHostMsLogicalUnit::DoLunReadyCheckL()
   1.212 +    {
   1.213 +    __MSFNLOG
   1.214 +	iProtocol->DoScsiReadyCheckEventL();
   1.215 +    }
   1.216 +
   1.217 +TInt CUsbHostMsLogicalUnit::InitialiseProtocolL(TLun aLun,
   1.218 +                                                THostMassStorageConfig& aConfig,
   1.219 +                                                MTransport& aTransport)
   1.220 +    {
   1.221 +    __MSFNLOG
   1.222 +    __ASSERT_DEBUG(iProtocol == NULL, User::Panic(KUsbMsHostPanicCat, EProtocolNotFree));
   1.223 +	switch(aConfig.iProtocolId)
   1.224 +        {
   1.225 +	case ScsiProtocol:
   1.226 +		iProtocol = CScsiProtocol::NewL(aLun, aTransport);
   1.227 +		break;
   1.228 +	default:
   1.229 +		__HOSTPRINT(_L("Unsupported Transport class requested"));
   1.230 +		iProtocol = NULL;
   1.231 +		return KErrNotSupported;
   1.232 +        }
   1.233 +	return KErrNone;
   1.234 +    }
   1.235 +
   1.236 +TInt CUsbHostMsLogicalUnit::CheckPosition(const TReadWrite& aReadWrite)
   1.237 +    {
   1.238 +    if (aReadWrite.iLen == 0)
   1.239 +        {
   1.240 +        if (aReadWrite.iPos == iSize)
   1.241 +            return KErrEof;
   1.242 +        else
   1.243 +            return KErrArgument;
   1.244 +        }
   1.245 +
   1.246 +	// detect drive not present
   1.247 +	if (iSize == 0)
   1.248 +		return KErrNotReady;
   1.249 +
   1.250 +    if (aReadWrite.iPos >= iSize)
   1.251 +        return KErrArgument;
   1.252 +    return KErrNone;
   1.253 +    }