userlibandfileserver/fileserver/shostmassstorage/server/protocol/cscsiprotocol.cpp
branchRCL_3
changeset 97 41f0cfe18c80
parent 87 2f92ad2dc5db
child 110 c734af59ce98
equal deleted inserted replaced
89:1df514389a47 97:41f0cfe18c80
   102 	// retry the connection for a number of seconds
   102 	// retry the connection for a number of seconds
   103     TInt retryCounter = 20;
   103     TInt retryCounter = 20;
   104     do
   104     do
   105         {
   105         {
   106         retryCounter--;
   106         retryCounter--;
   107         iFsm->ConnectLogicalUnitL();
   107         TInt err = iFsm->ConnectLogicalUnitL();
       
   108         if (err == KErrNotSupported)
       
   109             {
       
   110             break;
       
   111             }
   108         if (iFsm->IsConnected())
   112         if (iFsm->IsConnected())
   109             {
   113             {
   110             iState = EConnected;
   114             iState = EConnected;
   111             break;
   115             break;
   112             }
   116             }
   131 void CScsiProtocol::ReadL(TPos aPos,
   135 void CScsiProtocol::ReadL(TPos aPos,
   132                           TDes8& aBuf,
   136                           TDes8& aBuf,
   133                           TInt aLength)
   137                           TInt aLength)
   134     {
   138     {
   135 	__MSFNLOG
   139 	__MSFNLOG
       
   140 
       
   141     if (!iSbcInterface)
       
   142         User::Leave(KErrNotSupported);
       
   143 
   136     if(!IsConnected())
   144     if(!IsConnected())
   137 		User::Leave(KErrNotReady);
   145 		User::Leave(KErrNotReady);
   138     iSbcInterface->iBlockTransfer.ReadL(*this, aPos, aLength, aBuf);
   146     iSbcInterface->iBlockTransfer.ReadL(*this, aPos, aLength, aBuf);
   139     }
   147     }
   140 
   148 
   141 
   149 
   142 void CScsiProtocol::BlockReadL(TPos aPos, TDes8& aCopybuf, TInt aLen)
   150 void CScsiProtocol::BlockReadL(TPos aPos, TDes8& aCopybuf, TInt aLen)
   143     {
   151     {
   144 	__MSFNLOG
   152 	__MSFNLOG
       
   153     if (!iSbcInterface)
       
   154         User::Leave(KErrNotSupported);
       
   155 
   145 	__ASSERT_DEBUG(aPos % iSbcInterface->iBlockTransfer.BlockLength() == 0,
   156 	__ASSERT_DEBUG(aPos % iSbcInterface->iBlockTransfer.BlockLength() == 0,
   146                    User::Panic(KUsbMsHostPanicCat, EBlockDevice));
   157                    User::Panic(KUsbMsHostPanicCat, EBlockDevice));
   147 
   158 
   148     const TInt blockLen = iSbcInterface->iBlockTransfer.BlockLength();
   159     const TInt blockLen = iSbcInterface->iBlockTransfer.BlockLength();
   149     TInt len = aLen;
   160     TInt len = aLen;
   194 void CScsiProtocol::WriteL(TPos aPosition,
   205 void CScsiProtocol::WriteL(TPos aPosition,
   195                            TDesC8& aBuf,
   206                            TDesC8& aBuf,
   196                            TInt aLength)
   207                            TInt aLength)
   197     {
   208     {
   198 	__MSFNLOG
   209 	__MSFNLOG
       
   210     if (!iSbcInterface)
       
   211         User::Leave(KErrNotSupported);
       
   212 
   199     if(!IsConnected())
   213     if(!IsConnected())
   200 		User::Leave(KErrNotReady);
   214 		User::Leave(KErrNotReady);
   201     iSbcInterface->iBlockTransfer.WriteL(*this, aPosition, aLength, aBuf);
   215     iSbcInterface->iBlockTransfer.WriteL(*this, aPosition, aLength, aBuf);
   202     }
   216     }
   203 
   217 
   204 
   218 
   205 void CScsiProtocol::BlockWriteL(TPos aPos, TDesC8& aCopybuf, TUint aOffset, TInt aLen)
   219 void CScsiProtocol::BlockWriteL(TPos aPos, TDesC8& aCopybuf, TUint aOffset, TInt aLen)
   206     {
   220     {
   207 	__MSFNLOG
   221 	__MSFNLOG
       
   222     if (!iSbcInterface)
       
   223         User::Leave(KErrNotSupported);
       
   224 
   208 	__ASSERT_DEBUG(aPos % iSbcInterface->iBlockTransfer.BlockLength() == 0,
   225 	__ASSERT_DEBUG(aPos % iSbcInterface->iBlockTransfer.BlockLength() == 0,
   209                    User::Panic(KUsbMsHostPanicCat, EBlockDevice));
   226                    User::Panic(KUsbMsHostPanicCat, EBlockDevice));
   210     const TInt blockLen = iSbcInterface->iBlockTransfer.BlockLength();
   227     const TInt blockLen = iSbcInterface->iBlockTransfer.BlockLength();
   211     TInt len = aLen;
   228     TInt len = aLen;
   212 	TInt err = iSbcInterface->Write10L(aPos/blockLen, aCopybuf, aOffset, len);
   229 	TInt err = iSbcInterface->Write10L(aPos/blockLen, aCopybuf, aOffset, len);
   247 	__MSFNLOG
   264 	__MSFNLOG
   248     if (!IsConnected())
   265     if (!IsConnected())
   249         {
   266         {
   250         DoScsiReadyCheckEventL();
   267         DoScsiReadyCheckEventL();
   251         }
   268         }
       
   269 
       
   270     if (!iSbcInterface)
       
   271         {
       
   272         aCapsInfo.iMediaType = EMediaCdRom;
       
   273         aCapsInfo.iNumberOfBlocks = 0;
       
   274         aCapsInfo.iBlockLength = 0;
       
   275         aCapsInfo.iWriteProtect = ETrue;
       
   276         return;
       
   277         }
       
   278 
       
   279     aCapsInfo.iMediaType = EMediaHardDisk;
   252 
   280 
   253 	TLba lastLba;
   281 	TLba lastLba;
   254 	TUint32 blockLength;
   282 	TUint32 blockLength;
   255 
   283 
   256     // Retry ReadCapacity10L if stalled
   284     // Retry ReadCapacity10L if stalled
   349                  &info.iIdentification.iProductId,
   377                  &info.iIdentification.iProductId,
   350                  &info.iIdentification.iProductRev);
   378                  &info.iIdentification.iProductRev);
   351 
   379 
   352     if (info.iPeripheralQualifier != 0 && info.iPeripheralQualifier != 1)
   380     if (info.iPeripheralQualifier != 0 && info.iPeripheralQualifier != 1)
   353         {
   381         {
   354         __HOSTPRINT(_L("Peripheral Qualifier[Unknown device type]\n"))
   382         __HOSTPRINT(_L("Peripheral Qualifier[Unknown device type]"))
   355         return KErrUnknown;
   383         err = KErrUnknown;
   356         }
   384         }
   357 
   385     else if (info.iPeripheralDeviceType == 0)
   358     if (info.iPeripheralDeviceType != 0)
   386         {
   359         {
   387         // SCSI SBC Direct access device
   360         __HOSTPRINT(_L("Peripheral Device Type[Unsupported device type]\n"))
   388         iRemovableMedia = info.iRemovable;
   361         return KErrUnknown;
   389     
   362         }
   390         // SCSI Block device
   363 
   391         iSbcInterface = new (ELeave) TSbcClientInterface(iSpcInterface.Transport());
   364     iRemovableMedia = info.iRemovable;
   392         iSbcInterface->InitBuffers(&iHeadbuf, &iTailbuf);
   365 
   393         err = KErrNone;
   366     // SCSI Block device
   394         }
   367     iSbcInterface = new (ELeave) TSbcClientInterface(iSpcInterface.Transport());
   395     else if (info.iPeripheralDeviceType == 5)
   368     iSbcInterface->InitBuffers(&iHeadbuf, &iTailbuf);
   396         {
   369 
   397         // SCSI MMC-2 CD-ROM device
   370     return KErrNone;
   398         __HOSTPRINT(_L("Peripheral Device Type[CD-ROM]"))
       
   399         iRemovableMedia = info.iRemovable;
       
   400 
       
   401         // MMC-2 is not supported. A SCSI interface call will return 
       
   402         // KErrNotSupported. If SCSI support is extended in future then
       
   403         // TSbcInterface class should be replaced with a proper interface class.
       
   404         iSbcInterface = NULL;
       
   405         err = KErrNone;
       
   406         }
       
   407     else
       
   408         {
       
   409         __HOSTPRINT(_L("Peripheral Device Type[Unsupported device type]"))
       
   410         err = KErrUnknown;    
       
   411         }
       
   412 
       
   413     return err;
   371     }
   414     }
   372 
   415 
   373 
   416 
   374 /**
   417 /**
   375 Perform SCSI TEST UNIT READY command. The function leaves if the device response
   418 Perform SCSI TEST UNIT READY command. The function leaves if the device response
   398 device status error, KErrCommandStalled to indicate a device stall
   441 device status error, KErrCommandStalled to indicate a device stall
   399 */
   442 */
   400 TInt CScsiProtocol::MsReadCapacityL()
   443 TInt CScsiProtocol::MsReadCapacityL()
   401     {
   444     {
   402 	__MSFNLOG
   445 	__MSFNLOG
       
   446     if (!iSbcInterface)
       
   447         {
       
   448         User::Leave(KErrNotSupported);
       
   449         }
       
   450 
   403     // READ CAPACITY
   451     // READ CAPACITY
   404     TUint32 blockSize;
   452     TUint32 blockSize;
   405     TUint32 lastLba;
   453     TUint32 lastLba;
   406     TInt err = iSbcInterface->ReadCapacity10L(lastLba, blockSize);
   454     TInt err = iSbcInterface->ReadCapacity10L(lastLba, blockSize);
   407 
   455 
   418 device status error, KErrCommandStalled to indicate a device stall
   466 device status error, KErrCommandStalled to indicate a device stall
   419 */
   467 */
   420 TInt CScsiProtocol::MsModeSense10L()
   468 TInt CScsiProtocol::MsModeSense10L()
   421     {
   469     {
   422 	__MSFNLOG
   470 	__MSFNLOG
       
   471     if (!iSbcInterface)
       
   472         User::Leave(KErrNotSupported);
       
   473 
   423     TBool writeProtected;
   474     TBool writeProtected;
   424     TInt err = iSbcInterface->ModeSense10L(TSbcClientInterface::EReturnAllModePages, writeProtected);
   475     TInt err = iSbcInterface->ModeSense10L(TSbcClientInterface::EReturnAllModePages, writeProtected);
   425 
   476 
   426     if (!err)
   477     if (!err)
   427         {
   478         {
   439 device status error, KErrCommandStalled to indicate a device stall
   490 device status error, KErrCommandStalled to indicate a device stall
   440 */
   491 */
   441 TInt CScsiProtocol::MsModeSense6L()
   492 TInt CScsiProtocol::MsModeSense6L()
   442     {
   493     {
   443 	__MSFNLOG
   494 	__MSFNLOG
       
   495     if (!iSbcInterface)
       
   496         User::Leave(KErrNotSupported);
       
   497 
   444     TBool writeProtected;
   498     TBool writeProtected;
   445     TInt err = iSbcInterface->ModeSense6L(TSbcClientInterface::EReturnAllModePages, writeProtected);
   499     TInt err = iSbcInterface->ModeSense6L(TSbcClientInterface::EReturnAllModePages, writeProtected);
   446 
   500 
   447     if (!err)
   501     if (!err)
   448         {
   502         {
   460 device status error
   514 device status error
   461 */
   515 */
   462 TInt CScsiProtocol::MsStartStopUnitL(TBool aStart)
   516 TInt CScsiProtocol::MsStartStopUnitL(TBool aStart)
   463     {
   517     {
   464 	__MSFNLOG
   518 	__MSFNLOG
       
   519     if (!iSbcInterface)
       
   520         User::Leave(KErrNotSupported);
       
   521 
   465     return iSbcInterface->StartStopUnitL(aStart);
   522     return iSbcInterface->StartStopUnitL(aStart);
   466     }
   523     }
   467 
   524 
   468 
   525 
   469 /**
   526 /**
   490     // Check if init is needed
   547     // Check if init is needed
   491     if (iSenseInfo.iSenseCode == TSenseInfo::ENotReady &&
   548     if (iSenseInfo.iSenseCode == TSenseInfo::ENotReady &&
   492         iSenseInfo.iAdditional == TSenseInfo::EAscLogicalUnitNotReady &&
   549         iSenseInfo.iAdditional == TSenseInfo::EAscLogicalUnitNotReady &&
   493         iSenseInfo.iQualifier == TSenseInfo::EAscqInitializingCommandRequired)
   550         iSenseInfo.iQualifier == TSenseInfo::EAscqInitializingCommandRequired)
   494         {
   551         {
   495         // start unit
   552 		if (iSbcInterface)
   496         err = iSbcInterface->StartStopUnitL(ETrue);
   553 			{
   497         if (err)
   554 	        // start unit
   498             {
   555 			err = iSbcInterface->StartStopUnitL(ETrue);
   499             User::LeaveIfError(MsRequestSenseL());
   556 	        if (err)
   500             }
   557 		        {
       
   558 			    User::LeaveIfError(MsRequestSenseL());
       
   559 				}			
       
   560 			}
   501         }
   561         }
   502 
   562 
   503     err = GetSystemWideSenseError(iSenseInfo);
   563     err = GetSystemWideSenseError(iSenseInfo);
   504 
   564 
   505     TScsiState nextState = iState;
   565     TScsiState nextState = iState;
   743 void CScsiProtocol::DoScsiReadyCheckEventL()
   803 void CScsiProtocol::DoScsiReadyCheckEventL()
   744 	{
   804 	{
   745     __MSFNLOG
   805     __MSFNLOG
   746 	TInt err = KErrNone;
   806 	TInt err = KErrNone;
   747 
   807 
   748 	if(iFsm->IsRemovableMedia() || iState != EConnected)
   808 	if(iRemovableMedia || iState != EConnected)
   749         {
   809         {
   750 		iFsm->SetStatusCheck();
   810 		iFsm->SetStatusCheck();
   751 		TRAP(err, iFsm->ConnectLogicalUnitL());
   811 		TRAP(err, iFsm->ConnectLogicalUnitL());
   752 		iFsm->ClearStatusCheck();
   812 		iFsm->ClearStatusCheck();
   753 
   813