userlibandfileserver/fileserver/shostmassstorage/server/controller/cusbhostmslogicalunit.cpp
changeset 297 b2826f67641f
parent 0 a41df078684a
equal deleted inserted replaced
296:94f2adf59133 297:b2826f67641f
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-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".
    29 #include "tspcclientinterface.h"
    29 #include "tspcclientinterface.h"
    30 #include "cscsiprotocol.h"
    30 #include "cscsiprotocol.h"
    31 
    31 
    32 #include "cusbhostmslogicalunit.h"
    32 #include "cusbhostmslogicalunit.h"
    33 #include "usbmshostpanic.h"
    33 #include "usbmshostpanic.h"
    34 #include "msdebug.h"
    34 
    35 #include "debug.h"
    35 #include "OstTraceDefinitions.h"
    36 
    36 #ifdef OST_TRACE_COMPILER_IN_USE
       
    37 #include "cusbhostmslogicalunitTraces.h"
       
    38 #endif
    37 
    39 
    38 CUsbHostMsLogicalUnit* CUsbHostMsLogicalUnit::NewL(TLun aLun)
    40 CUsbHostMsLogicalUnit* CUsbHostMsLogicalUnit::NewL(TLun aLun)
    39     {
    41     {
    40     __MSFNSLOG
    42     CUsbHostMsLogicalUnit* r = new (ELeave) CUsbHostMsLogicalUnit(aLun);
    41 	CUsbHostMsLogicalUnit* r = new (ELeave) CUsbHostMsLogicalUnit(aLun);
    43     CleanupStack::PushL(r);
    42 	CleanupStack::PushL(r);
    44     r->ConstructL();
    43 	r->ConstructL();
    45     CleanupStack::Pop();
    44 	CleanupStack::Pop();
    46     return r;
    45 	return r;
    47     }
    46 	}
       
    47 
    48 
    48 
    49 
    49 void CUsbHostMsLogicalUnit::ConstructL()
    50 void CUsbHostMsLogicalUnit::ConstructL()
    50     {
    51     {
    51     __MSFNLOG
       
    52     const TInt KInitialDataBufSize = 0x200;
    52     const TInt KInitialDataBufSize = 0x200;
    53 	iDataBuf.CreateL(KInitialDataBufSize);
    53     iDataBuf.CreateL(KInitialDataBufSize);
    54     }
    54     }
    55 
    55 
    56 
    56 
    57 CUsbHostMsLogicalUnit::CUsbHostMsLogicalUnit(TLun aLun)
    57 CUsbHostMsLogicalUnit::CUsbHostMsLogicalUnit(TLun aLun)
    58 :   iProtocol(NULL),
    58 :   iProtocol(NULL),
    59     iLun(aLun),
    59     iLun(aLun),
    60 	iSuspendRequest(EFalse)
    60     iSuspendRequest(EFalse)
    61     {
    61     {
    62     __MSFNLOG
    62     }
    63 	}
       
    64 
    63 
    65 CUsbHostMsLogicalUnit::~CUsbHostMsLogicalUnit()
    64 CUsbHostMsLogicalUnit::~CUsbHostMsLogicalUnit()
    66     {
    65     {
    67     __MSFNLOG
       
    68     iDataBuf.Close();
    66     iDataBuf.Close();
    69 	delete iProtocol;
    67     delete iProtocol;
    70 	}
    68     }
    71 
    69 
    72 
    70 
    73 void CUsbHostMsLogicalUnit::InitL()
    71 void CUsbHostMsLogicalUnit::InitL()
    74     {
    72     {
    75     __MSFNLOG
    73     iProtocol->InitialiseUnitL();
    76 	iProtocol->InitialiseUnitL();
       
    77     }
    74     }
    78 
    75 
    79 void CUsbHostMsLogicalUnit::UnInitL()
    76 void CUsbHostMsLogicalUnit::UnInitL()
    80     {
    77     {
    81     __MSFNLOG
    78     iProtocol->UninitialiseUnitL();
    82 	iProtocol->UninitialiseUnitL();
       
    83     }
    79     }
    84 
    80 
    85 void CUsbHostMsLogicalUnit::ReadL(const RMessage2& aMessage)
    81 void CUsbHostMsLogicalUnit::ReadL(const RMessage2& aMessage)
    86     {
    82     {
    87     __MSFNLOG
    83     TReadWrite p;
    88 	TReadWrite p;
    84     TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
    89 	TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
    85     aMessage.ReadL(0, pReadWrite);
    90 	aMessage.ReadL(0, pReadWrite);
    86     OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, CUSBHOSTMSLOGICALUNIT_10,
    91     __HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
    87                  "pos = 0x%x %x len = %08x", I64HIGH(p.iPos), I64LOW(p.iPos), p.iLen);
    92 
       
    93     User::LeaveIfError(CheckPosition(p));
       
    94 
       
    95 	// check if buffer can hold requested data and resize if not
       
    96 	if (iDataBuf.MaxLength() < p.iLen)
       
    97         iDataBuf.ReAllocL(p.iLen);
       
    98 
       
    99     iProtocol->ReadL(p.iPos, iDataBuf, p.iLen);
       
   100     aMessage.WriteL(1, iDataBuf);
       
   101     }
       
   102 
       
   103 
       
   104 void CUsbHostMsLogicalUnit::WriteL(const RMessage2& aMessage)
       
   105     {
       
   106     __MSFNLOG
       
   107 	TReadWrite p;
       
   108 	TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
       
   109 	aMessage.ReadL(1, pReadWrite);
       
   110     __HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
       
   111 
    88 
   112     User::LeaveIfError(CheckPosition(p));
    89     User::LeaveIfError(CheckPosition(p));
   113 
    90 
   114     // check if buffer can hold requested data and resize if not
    91     // check if buffer can hold requested data and resize if not
   115     if (iDataBuf.MaxLength() < p.iLen)
    92     if (iDataBuf.MaxLength() < p.iLen)
   116         iDataBuf.ReAllocL(p.iLen);
    93         iDataBuf.ReAllocL(p.iLen);
   117 
    94 
   118 	aMessage.ReadL(0, iDataBuf);
    95     iProtocol->ReadL(p.iPos, iDataBuf, p.iLen);
   119 	iProtocol->WriteL(p.iPos, iDataBuf, p.iLen);
    96     aMessage.WriteL(1, iDataBuf);
   120     }
    97     }
   121 
    98 
   122 
    99 
   123 void CUsbHostMsLogicalUnit::EraseL(const RMessage2& aMessage)
   100 void CUsbHostMsLogicalUnit::WriteL(const RMessage2& aMessage)
   124     {
   101     {
   125     __MSFNLOG
   102     TReadWrite p;
   126 	TReadWrite p;
   103     TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
   127 	TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
   104     aMessage.ReadL(1, pReadWrite);
   128 	aMessage.ReadL(0, pReadWrite);
   105     OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, CUSBHOSTMSLOGICALUNIT_11,
   129     __HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
   106                  "pos = 0x%x %x len = %08x", I64HIGH(p.iPos), I64LOW(p.iPos), p.iLen);
   130 
   107 
   131     User::LeaveIfError(CheckPosition(p));
   108     User::LeaveIfError(CheckPosition(p));
   132 
   109 
   133     // check if buffer can hold requested data and resize if not
   110     // check if buffer can hold requested data and resize if not
   134     if (iDataBuf.MaxLength() < p.iLen)
   111     if (iDataBuf.MaxLength() < p.iLen)
   135         iDataBuf.ReAllocL(p.iLen);
   112         iDataBuf.ReAllocL(p.iLen);
   136 
   113 
       
   114     aMessage.ReadL(0, iDataBuf);
       
   115     iProtocol->WriteL(p.iPos, iDataBuf, p.iLen);
       
   116     }
       
   117 
       
   118 
       
   119 void CUsbHostMsLogicalUnit::EraseL(const RMessage2& aMessage)
       
   120     {
       
   121     TReadWrite p;
       
   122     TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
       
   123     aMessage.ReadL(0, pReadWrite);
       
   124     OstTraceExt3(TRACE_SHOSTMASSSTORAGE_HOST, CUSBHOSTMSLOGICALUNIT_12,
       
   125                  "pos = 0x%x %x len = %08x", I64HIGH(p.iPos), I64LOW(p.iPos), p.iLen);
       
   126 
       
   127     User::LeaveIfError(CheckPosition(p));
       
   128 
       
   129     // check if buffer can hold requested data and resize if not
       
   130     if (iDataBuf.MaxLength() < p.iLen)
       
   131         iDataBuf.ReAllocL(p.iLen);
       
   132 
   137     iDataBuf.FillZ(p.iLen);
   133     iDataBuf.FillZ(p.iLen);
   138 	iProtocol->WriteL(p.iPos, iDataBuf, p.iLen);
   134     iProtocol->WriteL(p.iPos, iDataBuf, p.iLen);
   139     }
   135     }
   140 
   136 
   141 
   137 
   142 void CUsbHostMsLogicalUnit::CapsL(const RMessage2& aMessage)
   138 void CUsbHostMsLogicalUnit::CapsL(const RMessage2& aMessage)
   143     {
   139     {
   144     __MSFNLOG
       
   145 
       
   146     TCapsInfo capsInfo;
   140     TCapsInfo capsInfo;
   147     TPckg<TCapsInfo> pckg(capsInfo);
   141     TPckg<TCapsInfo> pckg(capsInfo);
   148 	iProtocol->GetCapacityL(capsInfo);
   142     iProtocol->GetCapacityL(capsInfo);
   149     iSize = static_cast<TInt64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength;
   143     iSize = static_cast<TInt64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength;
   150 	aMessage.WriteL(0, pckg);
   144     aMessage.WriteL(0, pckg);
   151     }
   145     }
   152 
   146 
   153 void CUsbHostMsLogicalUnit::NotifyChange(const RMessage2& aMessage)
   147 void CUsbHostMsLogicalUnit::NotifyChange(const RMessage2& aMessage)
   154     {
   148     {
   155     __MSFNLOG
   149     iProtocol->NotifyChange(aMessage);
   156 	iProtocol->NotifyChange(aMessage);
       
   157     }
   150     }
   158 
   151 
   159 
   152 
   160 void CUsbHostMsLogicalUnit::ForceCompleteNotifyChangeL()
   153 void CUsbHostMsLogicalUnit::ForceCompleteNotifyChangeL()
   161     {
   154     {
   162     __MSFNLOG
   155     iProtocol->ForceCompleteNotifyChangeL();
   163 	iProtocol->ForceCompleteNotifyChangeL();
       
   164     }
   156     }
   165 
   157 
   166 void CUsbHostMsLogicalUnit::CancelChangeNotifierL()
   158 void CUsbHostMsLogicalUnit::CancelChangeNotifierL()
   167     {
   159     {
   168     __MSFNLOG
   160     iProtocol->CancelChangeNotifierL();
   169 	iProtocol->CancelChangeNotifierL();
       
   170     }
   161     }
   171 
   162 
   172 TBool CUsbHostMsLogicalUnit::IsConnected()
   163 TBool CUsbHostMsLogicalUnit::IsConnected()
   173 	{
   164     {
   174 	return iProtocol->IsConnected() ? ETrue : EFalse;
   165     return iProtocol->IsConnected() ? ETrue : EFalse;
   175 	}
   166     }
   176 
   167 
   177 TBool CUsbHostMsLogicalUnit::IsReadyToSuspend()
   168 TBool CUsbHostMsLogicalUnit::IsReadyToSuspend()
   178     {
   169     {
   179     __MSFNLOG
   170     return iSuspendRequest ? ETrue : EFalse;
   180 	return iSuspendRequest ? ETrue : EFalse;
   171     }
   181 	}
       
   182 
   172 
   183 void CUsbHostMsLogicalUnit::ReadyToSuspend()
   173 void CUsbHostMsLogicalUnit::ReadyToSuspend()
   184     {
   174     {
   185     __MSFNLOG
   175     iSuspendRequest = ETrue;
   186 	iSuspendRequest = ETrue;
       
   187     }
   176     }
   188 
   177 
   189 void CUsbHostMsLogicalUnit::CancelReadyToSuspend()
   178 void CUsbHostMsLogicalUnit::CancelReadyToSuspend()
   190     {
   179     {
   191     __MSFNLOG
   180     iSuspendRequest = EFalse;
   192 	iSuspendRequest = EFalse;
       
   193     }
   181     }
   194 
   182 
   195 void CUsbHostMsLogicalUnit::SuspendL()
   183 void CUsbHostMsLogicalUnit::SuspendL()
   196     {
   184     {
   197     __MSFNLOG
   185     iProtocol->SuspendL();
   198 	iProtocol->SuspendL();
       
   199     }
   186     }
   200 
   187 
   201 void CUsbHostMsLogicalUnit::ResumeL()
   188 void CUsbHostMsLogicalUnit::ResumeL()
   202 	{
   189     {
   203     __MSFNLOG
   190     // We do not cancel iSuspendRequest here
   204 	// We do not cancel iSuspendRequest here
   191     iProtocol->ResumeL();
   205 	iProtocol->ResumeL();
   192     }
   206 	}
       
   207 
   193 
   208 void CUsbHostMsLogicalUnit::DoLunReadyCheckL()
   194 void CUsbHostMsLogicalUnit::DoLunReadyCheckL()
   209     {
   195     {
   210     __MSFNLOG
   196     iProtocol->DoScsiReadyCheckEventL();
   211 	iProtocol->DoScsiReadyCheckEventL();
       
   212     }
   197     }
   213 
   198 
   214 TInt CUsbHostMsLogicalUnit::InitialiseProtocolL(TLun aLun,
   199 TInt CUsbHostMsLogicalUnit::InitialiseProtocolL(TLun aLun,
   215                                                 THostMassStorageConfig& aConfig,
   200                                                 THostMassStorageConfig& aConfig,
   216                                                 MTransport& aTransport)
   201                                                 MTransport& aTransport)
   217     {
   202     {
   218     __MSFNLOG
       
   219     __ASSERT_DEBUG(iProtocol == NULL, User::Panic(KUsbMsHostPanicCat, EProtocolNotFree));
   203     __ASSERT_DEBUG(iProtocol == NULL, User::Panic(KUsbMsHostPanicCat, EProtocolNotFree));
   220 	switch(aConfig.iProtocolId)
   204     switch(aConfig.iProtocolId)
   221         {
   205         {
   222 	case ScsiProtocol:
   206     case ScsiProtocol:
   223 		iProtocol = CScsiProtocol::NewL(aLun, aTransport);
   207         iProtocol = CScsiProtocol::NewL(aLun, aTransport);
   224 		break;
   208         break;
   225 	default:
   209     default:
   226 		__HOSTPRINT(_L("Unsupported Transport class requested"));
   210         OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, CUSBHOSTMSLOGICALUNIT_13,
   227 		iProtocol = NULL;
   211                   "Unsupported Transport class requested");
   228 		return KErrNotSupported;
   212         iProtocol = NULL;
       
   213         return KErrNotSupported;
   229         }
   214         }
   230 	return KErrNone;
   215     return KErrNone;
   231     }
   216     }
   232 
   217 
   233 TInt CUsbHostMsLogicalUnit::CheckPosition(const TReadWrite& aReadWrite)
   218 TInt CUsbHostMsLogicalUnit::CheckPosition(const TReadWrite& aReadWrite)
   234     {
   219     {
   235     if (aReadWrite.iLen == 0)
   220     if (aReadWrite.iLen == 0)
   238             return KErrEof;
   223             return KErrEof;
   239         else
   224         else
   240             return KErrArgument;
   225             return KErrArgument;
   241         }
   226         }
   242 
   227 
   243 	// detect drive not present
   228     // detect drive not present
   244 	if (iSize == 0)
   229     if (iSize == 0)
   245 		return KErrNotReady;
   230         return KErrNotReady;
   246 
   231 
   247     if (aReadWrite.iPos >= iSize)
   232     if (aReadWrite.iPos >= iSize)
   248         return KErrArgument;
   233         return KErrArgument;
   249     return KErrNone;
   234     return KErrNone;
   250     }
   235     }