userlibandfileserver/fileserver/shostmassstorage/server/protocol/tsbcclientinterface.cpp
changeset 297 b2826f67641f
parent 33 0173bcd7697c
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".
    18  @internalTechnology
    18  @internalTechnology
    19 */
    19 */
    20 
    20 
    21 #include <e32base.h>
    21 #include <e32base.h>
    22 
    22 
    23 #include "msdebug.h"
    23 #include "OstTraceDefinitions.h"
    24 #include "debug.h"
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "tsbcclientinterfaceTraces.h"
       
    26 #endif
       
    27 
    25 #include "msctypes.h"
    28 #include "msctypes.h"
    26 
    29 
    27 #include "mtransport.h"
    30 #include "mtransport.h"
    28 #include "mprotocol.h"
    31 #include "mprotocol.h"
    29 #include "tscsiclientreq.h"
    32 #include "tscsiclientreq.h"
    32 #include "mscutils.h"
    35 #include "mscutils.h"
    33 #include "usbmshostpanic.h"
    36 #include "usbmshostpanic.h"
    34 #include "tscsiblockcmds.h"
    37 #include "tscsiblockcmds.h"
    35 #include "tsbcclientinterface.h"
    38 #include "tsbcclientinterface.h"
    36 
    39 
       
    40 
    37 /**
    41 /**
    38 Constructor.
    42 Constructor.
    39 
    43 
    40 @param aTransport The Transport interface to be used
    44 @param aTransport The Transport interface to be used
    41 */
    45 */
    42 TSbcClientInterface::TSbcClientInterface(MTransport& aTransport)
    46 TSbcClientInterface::TSbcClientInterface(MTransport& aTransport)
    43 :   iTransport(aTransport)
    47 :   iTransport(aTransport)
    44     {
    48     {
    45     __MSFNLOG
       
    46     }
    49     }
    47 
    50 
    48 
    51 
    49 TSbcClientInterface::~TSbcClientInterface()
    52 TSbcClientInterface::~TSbcClientInterface()
    50     {
    53     {
    51     __MSFNLOG
       
    52     }
    54     }
    53 
    55 
    54 
    56 
    55 /**
    57 /**
    56 Constructor to create and send SCSI MODE SENSE (6) request to obtain the
    58 Constructor to create and send SCSI MODE SENSE (6) request to obtain the
    63 @return TInt KErrNone if successful, KErrCommandFailed to indicate a
    65 @return TInt KErrNone if successful, KErrCommandFailed to indicate a
    64 device status error, KErrCommandStalled to indicate device stall
    66 device status error, KErrCommandStalled to indicate device stall
    65 */
    67 */
    66 TInt TSbcClientInterface::ModeSense6L(TUint aPageCode, TBool& aWriteProtected)
    68 TInt TSbcClientInterface::ModeSense6L(TUint aPageCode, TBool& aWriteProtected)
    67     {
    69     {
    68     __MSFNLOG
       
    69     TScsiClientModeSense6Req modeSense6Req(TScsiClientModeSense6Req::ECurrentValues,
    70     TScsiClientModeSense6Req modeSense6Req(TScsiClientModeSense6Req::ECurrentValues,
    70                                            aPageCode);
    71                                            aPageCode);
    71     TScsiClientModeSense6Resp modeSense6Resp;
    72     TScsiClientModeSense6Resp modeSense6Resp;
    72     TInt err = iTransport.SendControlCmdL(&modeSense6Req, &modeSense6Resp);
    73     TInt err = iTransport.SendControlCmdL(&modeSense6Req, &modeSense6Resp);
    73     if (!err)
    74     if (!err)
    74         {
    75         {
    75         __SCSIPRINT1(_L("SCSI MODE SENSE (6) INFO WrProtect=%d"),
    76         OstTrace1(TRACE_SHOSTMASSSTORAGE_SCSI, TSBCCLIENTINTERFACE_10,
    76                      modeSense6Resp.iWriteProtected);
    77                   "SCSI MODE SENSE (6) INFO WrProtect=%d", modeSense6Resp.iWriteProtected);
    77         aWriteProtected = modeSense6Resp.iWriteProtected;
    78         aWriteProtected = modeSense6Resp.iWriteProtected;
    78         }
    79         }
    79     else
    80     else
    80         {
    81         {
    81         aWriteProtected = EFalse;
    82         aWriteProtected = EFalse;
    82         }
    83         }
    83 	return err;
    84     return err;
    84     }
    85     }
    85 
    86 
    86 
    87 
    87 /**
    88 /**
    88 Create and send SCSI MODE SENSE (10) request to obtain the mediums Write Protect
    89 Create and send SCSI MODE SENSE (10) request to obtain the mediums Write Protect
    95 @return TInt KErrNone if successful, KErrCommandFailed to indicate a
    96 @return TInt KErrNone if successful, KErrCommandFailed to indicate a
    96 device status error, KErrCommandStalled to indicate a device stall
    97 device status error, KErrCommandStalled to indicate a device stall
    97 */
    98 */
    98 TInt TSbcClientInterface::ModeSense10L(TUint aPageCode, TBool& aWriteProtected)
    99 TInt TSbcClientInterface::ModeSense10L(TUint aPageCode, TBool& aWriteProtected)
    99     {
   100     {
   100     __MSFNLOG
       
   101     TScsiClientModeSense10Req modeSense10Req(TScsiClientModeSense10Req::ECurrentValues,
   101     TScsiClientModeSense10Req modeSense10Req(TScsiClientModeSense10Req::ECurrentValues,
   102                                              aPageCode);
   102                                              aPageCode);
   103     TScsiClientModeSense10Resp modeSense10Resp;
   103     TScsiClientModeSense10Resp modeSense10Resp;
   104     TInt err = iTransport.SendControlCmdL(&modeSense10Req, &modeSense10Resp);
   104     TInt err = iTransport.SendControlCmdL(&modeSense10Req, &modeSense10Resp);
   105 
   105 
   106     if (!err)
   106     if (!err)
   107         {
   107         {
   108         __SCSIPRINT1(_L("SCSI MODE SENSE (10) INFO WrProtect=%d"),
   108         OstTrace1(TRACE_SHOSTMASSSTORAGE_SCSI, TSBCCLIENTINTERFACE_11,
   109                      modeSense10Resp.iWriteProtected);
   109                   "SCSI MODE SENSE (10) INFO WrProtect=%d", modeSense10Resp.iWriteProtected);
   110         aWriteProtected = modeSense10Resp.iWriteProtected;
   110         aWriteProtected = modeSense10Resp.iWriteProtected;
   111         }
   111         }
   112     else
   112     else
   113         {
   113         {
   114         aWriteProtected = EFalse;
   114         aWriteProtected = EFalse;
   115         }
   115         }
   116 	return err;
   116     return err;
   117     }
   117     }
   118 
   118 
   119 
   119 
   120 /**
   120 /**
   121 Constructor to create SCSI MODE SENSE (10) request.
   121 Constructor to create SCSI MODE SENSE (10) request.
   132     iPageControl(aPageControl),
   132     iPageControl(aPageControl),
   133     iPageCode(aPageCode),
   133     iPageCode(aPageCode),
   134     iSubPageCode(aSubPageCode),
   134     iSubPageCode(aSubPageCode),
   135     iAllocationLength(KResponseLength)
   135     iAllocationLength(KResponseLength)
   136     {
   136     {
   137     __MSFNLOG
       
   138     }
   137     }
   139 
   138 
   140 
   139 
   141 TInt TScsiClientModeSense10Req::EncodeRequestL(TDes8& aBuffer) const
   140 TInt TScsiClientModeSense10Req::EncodeRequestL(TDes8& aBuffer) const
   142     {
   141     {
   143     __MSFNSLOG
   142     OstTrace0(TRACE_SHOSTMASSSTORAGE_SCSI, TSBCCLIENTINTERFACE_12,
   144     __SCSIPRINT(_L("<-- SCSI MODE SENSE (10)"));
   143               "<-- SCSI MODE SENSE (10)");
   145     TInt length = TScsiClientReq::EncodeRequestL(aBuffer);
   144     TInt length = TScsiClientReq::EncodeRequestL(aBuffer);
   146 
   145 
   147     // PC
   146     // PC
   148     aBuffer[2] = iPageCode;
   147     aBuffer[2] = iPageCode;
   149     aBuffer[2] |= iPageControl << 6;
   148     aBuffer[2] |= iPageControl << 6;
   169 device status error or KErrArgument to indicate that aLen is too large for the
   168 device status error or KErrArgument to indicate that aLen is too large for the
   170 protocol.
   169 protocol.
   171 */
   170 */
   172 TInt TSbcClientInterface::Read10L(TLba aLba, TDes8& aBuffer, TInt& aLen)
   171 TInt TSbcClientInterface::Read10L(TLba aLba, TDes8& aBuffer, TInt& aLen)
   173     {
   172     {
   174     __MSFNLOG
   173     __ASSERT_DEBUG(iBlockTransfer.BlockLength(), User::Panic(KUsbMsHostPanicCat, EBlockLengthNotSet));
   175 	__ASSERT_DEBUG(iBlockTransfer.BlockLength(), User::Panic(KUsbMsHostPanicCat, EBlockLengthNotSet));
       
   176     __ASSERT_DEBUG(aLen % iBlockTransfer.BlockLength() == 0, User::Panic(KUsbMsHostPanicCat, EBlockDevice));
   174     __ASSERT_DEBUG(aLen % iBlockTransfer.BlockLength() == 0, User::Panic(KUsbMsHostPanicCat, EBlockDevice));
   177 
   175 
   178     TScsiClientRead10Req read10Req;
   176     TScsiClientRead10Req read10Req;
   179 
   177 
   180     read10Req.iLogicalBlockAddress = aLba;
   178     read10Req.iLogicalBlockAddress = aLba;
   184         {
   182         {
   185         User::Leave(KErrArgument);
   183         User::Leave(KErrArgument);
   186         }
   184         }
   187     read10Req.iBlockTransferLength = static_cast<TUint16>(blockTransferLength);
   185     read10Req.iBlockTransferLength = static_cast<TUint16>(blockTransferLength);
   188     TInt err = iTransport.SendDataRxCmdL(&read10Req, aBuffer, aLen);
   186     TInt err = iTransport.SendDataRxCmdL(&read10Req, aBuffer, aLen);
   189 	return err;
   187     return err;
   190     }
   188     }
   191 
   189 
   192 /**
   190 /**
   193 Create READ CAPACITY (10) request and send to the transport layer. The request
   191 Create READ CAPACITY (10) request and send to the transport layer. The request
   194 returns the device servers capacity information. The device server's response
   192 returns the device servers capacity information. The device server's response
   201 @return TInt KErrNone if successful, KErrCommandFailed to indicate a
   199 @return TInt KErrNone if successful, KErrCommandFailed to indicate a
   202 device status error, KErrCommandStalled to indicate a device stall
   200 device status error, KErrCommandStalled to indicate a device stall
   203 */
   201 */
   204 TInt TSbcClientInterface::ReadCapacity10L(TLba& aLba, TUint32& aBlockSize)
   202 TInt TSbcClientInterface::ReadCapacity10L(TLba& aLba, TUint32& aBlockSize)
   205     {
   203     {
   206     __MSFNLOG
       
   207     TScsiClientReadCapacity10Req capacity10Req;
   204     TScsiClientReadCapacity10Req capacity10Req;
   208     TScsiClientReadCapacity10Resp capacity10Resp;
   205     TScsiClientReadCapacity10Resp capacity10Resp;
   209 
   206 
   210     TInt err = iTransport.SendControlCmdL(&capacity10Req, &capacity10Resp);
   207     TInt err = iTransport.SendControlCmdL(&capacity10Req, &capacity10Resp);
   211     if (!err)
   208     if (!err)
   212         {
   209         {
   213         aLba = capacity10Resp.iLba;
   210         aLba = capacity10Resp.iLba;
   214         aBlockSize = capacity10Resp.iBlockSize;
   211         aBlockSize = capacity10Resp.iBlockSize;
   215 
   212 
   216         __SCSIPRINT2(_L("Capacity LBA=0x%08x SIZE=0x%08x"),
   213         OstTraceExt2(TRACE_SHOSTMASSSTORAGE_SCSI, TSBCCLIENTINTERFACE__,
   217                      aLba, aBlockSize);
   214                      "Capacity LBA=0x%08x SIZE=0x%08x", aLba, aBlockSize);
   218 
   215 
   219         iBlockTransfer.SetCapacityL(aBlockSize, aLba);
   216         iBlockTransfer.SetCapacityL(aBlockSize, aLba);
   220         }
   217         }
   221 	return err;
   218     return err;
   222     }
   219     }
   223 
   220 
   224 
   221 
   225 /**
   222 /**
   226 Create START STOP UNIT request. The function leaves if the device response is
   223 Create START STOP UNIT request. The function leaves if the device response is
   231 @return TInt KErrNone if successful otherwise KErrCommandFailed to indicate a
   228 @return TInt KErrNone if successful otherwise KErrCommandFailed to indicate a
   232 device status error
   229 device status error
   233 */
   230 */
   234 TInt TSbcClientInterface::StartStopUnitL(TBool aStart)
   231 TInt TSbcClientInterface::StartStopUnitL(TBool aStart)
   235     {
   232     {
   236     __MSFNLOG
       
   237     TScsiClientStartStopUnitReq startStopUnitReq;
   233     TScsiClientStartStopUnitReq startStopUnitReq;
   238 
   234 
   239     startStopUnitReq.iImmed = ETrue;
   235     startStopUnitReq.iImmed = ETrue;
   240     startStopUnitReq.iLoej = EFalse;
   236     startStopUnitReq.iLoej = EFalse;
   241     startStopUnitReq.iStart = aStart;
   237     startStopUnitReq.iStart = aStart;
   242 
   238 
   243     TInt err = iTransport.SendControlCmdL(&startStopUnitReq);
   239     TInt err = iTransport.SendControlCmdL(&startStopUnitReq);
   244 
   240 
   245 	return err;
   241     return err;
   246     }
   242     }
   247 
   243 
   248 
   244 
   249 /**
   245 /**
   250 Create WRITE (10) request and send to the transport layer. This performs a
   246 Create WRITE (10) request and send to the transport layer. This performs a
   262 device status error or KErrArgument to indicate that aLen is too large for the
   258 device status error or KErrArgument to indicate that aLen is too large for the
   263 protocol.
   259 protocol.
   264 */
   260 */
   265 TInt TSbcClientInterface::Write10L(TLba aLba, TDesC8& aBuffer, TUint aPos, TInt& aLen)
   261 TInt TSbcClientInterface::Write10L(TLba aLba, TDesC8& aBuffer, TUint aPos, TInt& aLen)
   266     {
   262     {
   267     __MSFNLOG
   263     __ASSERT_DEBUG(iBlockTransfer.BlockLength(), User::Panic(KUsbMsHostPanicCat, EBlockLengthNotSet));
   268 	__ASSERT_DEBUG(iBlockTransfer.BlockLength(), User::Panic(KUsbMsHostPanicCat, EBlockLengthNotSet));
       
   269     __ASSERT_DEBUG(aLen % iBlockTransfer.BlockLength() == 0, User::Panic(KUsbMsHostPanicCat, EBlockDevice));
   264     __ASSERT_DEBUG(aLen % iBlockTransfer.BlockLength() == 0, User::Panic(KUsbMsHostPanicCat, EBlockDevice));
   270 
   265 
   271     // check that buffer size is large enough
   266     // check that buffer size is large enough
   272 	if (aBuffer.Length() < (aPos + aLen))
   267     if (aBuffer.Length() < (aPos + aLen))
   273 		{
   268         {
   274         User::Leave(KErrArgument);
   269         User::Leave(KErrArgument);
   275 		}
   270         }
   276 
   271 
   277     TScsiClientWrite10Req write10Req;
   272     TScsiClientWrite10Req write10Req;
   278     write10Req.iLogicalBlockAddress = aLba;
   273     write10Req.iLogicalBlockAddress = aLba;
   279 
   274 
   280     TInt blockTransferLength = aLen / iBlockTransfer.BlockLength();
   275     TInt blockTransferLength = aLen / iBlockTransfer.BlockLength();
   283         User::Leave(KErrArgument);
   278         User::Leave(KErrArgument);
   284         }
   279         }
   285     write10Req.iBlockTransferLength = static_cast<TUint16>(blockTransferLength);
   280     write10Req.iBlockTransferLength = static_cast<TUint16>(blockTransferLength);
   286 
   281 
   287     TInt err = iTransport.SendDataTxCmdL(&write10Req, aBuffer, aPos, aLen);
   282     TInt err = iTransport.SendDataTxCmdL(&write10Req, aBuffer, aPos, aLen);
   288 	return err;
   283     return err;
   289     }
   284     }
   290 
   285