sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// CUsbMassStorageController implementation.
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file
|
sl@0
|
20 |
@internalTechnology
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "cusbmassstoragecontroller.h"
|
sl@0
|
24 |
#include "massstoragedebug.h"
|
sl@0
|
25 |
#include "scsiprot.h"
|
sl@0
|
26 |
#include "cbulkonlytransport.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
/**
|
sl@0
|
29 |
Destructor
|
sl@0
|
30 |
*/
|
sl@0
|
31 |
CUsbMassStorageController::~CUsbMassStorageController()
|
sl@0
|
32 |
{
|
sl@0
|
33 |
delete iServer;
|
sl@0
|
34 |
delete iProtocol;
|
sl@0
|
35 |
delete iTransport;
|
sl@0
|
36 |
delete iDriveManager;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
/**
|
sl@0
|
40 |
Creates the drive manager, transport, protocol and server
|
sl@0
|
41 |
|
sl@0
|
42 |
@param aMaxDrives Maximum number of Mass Storage drives supported.
|
sl@0
|
43 |
*/
|
sl@0
|
44 |
void CUsbMassStorageController::CreateL(RArray<TInt>& aDriveMapping)
|
sl@0
|
45 |
{
|
sl@0
|
46 |
__PRINT(_L("CUsbMassStorageController::CreateL In"));
|
sl@0
|
47 |
iTransportLddFlag = EUsbcsc; // Create transport object using SC Ldd By default
|
sl@0
|
48 |
//Save this value for use in the Reset method.
|
sl@0
|
49 |
iMaxDrives = aDriveMapping.Count();
|
sl@0
|
50 |
//Create and init drive manager
|
sl@0
|
51 |
iDriveManager = CDriveManager::NewL(aDriveMapping);
|
sl@0
|
52 |
|
sl@0
|
53 |
//Create transport and protocol and initialize them
|
sl@0
|
54 |
__PRINT(_L("CUsbMassStorageController::CreateL: Creating transport and protocol"));
|
sl@0
|
55 |
iTransport = CBulkOnlyTransport::NewL(iMaxDrives, *this, iTransportLddFlag);
|
sl@0
|
56 |
if (!iTransport)
|
sl@0
|
57 |
User::Leave(KErrNoMemory);
|
sl@0
|
58 |
|
sl@0
|
59 |
iProtocol = CScsiProtocol::NewL(*iDriveManager);
|
sl@0
|
60 |
|
sl@0
|
61 |
//Create and start server
|
sl@0
|
62 |
__PRINT(_L("CUsbMassStorageController::CreateL: Creating server"));
|
sl@0
|
63 |
iServer = CUsbMassStorageServer::NewLC(*this);
|
sl@0
|
64 |
CleanupStack::Pop(iServer);
|
sl@0
|
65 |
__PRINT(_L("CUsbMassStorageController::CreateL Out"));
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
/**
|
sl@0
|
69 |
Returns a reference to the drive manager
|
sl@0
|
70 |
|
sl@0
|
71 |
@return A reference to the drive manager
|
sl@0
|
72 |
*/
|
sl@0
|
73 |
CDriveManager& CUsbMassStorageController::DriveManager()
|
sl@0
|
74 |
{
|
sl@0
|
75 |
return *iDriveManager;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
void CUsbMassStorageController::GetTransport(MTransportBase* &aTransport)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
aTransport = iTransport;
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
/**
|
sl@0
|
85 |
Starts the transport and initializes the protocol.
|
sl@0
|
86 |
|
sl@0
|
87 |
@param aConfig Reference to Mass Storage configuration data
|
sl@0
|
88 |
*/
|
sl@0
|
89 |
TInt CUsbMassStorageController::Start(TMassStorageConfig& aConfig)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
__PRINT(_L("CUsbMassStorageController::Start In"));
|
sl@0
|
92 |
//Save this value for use in the Reset method.
|
sl@0
|
93 |
iConfig = aConfig;
|
sl@0
|
94 |
|
sl@0
|
95 |
__ASSERT_DEBUG(iTransport, User::Invariant());
|
sl@0
|
96 |
if ((iTransport->InitialiseTransportL((TInt) iTransportLddFlag)) != KErrNone)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
iTransportLddFlag = EUsbc; // If SC Ldd not present use the default USB Client Ldd
|
sl@0
|
99 |
delete iTransport;
|
sl@0
|
100 |
iTransport = CBulkOnlyTransport::NewL(iMaxDrives, *this, iTransportLddFlag);
|
sl@0
|
101 |
if (!iTransport)
|
sl@0
|
102 |
User::Leave(KErrNoMemory);
|
sl@0
|
103 |
if ((iTransport->InitialiseTransportL((TInt) iTransportLddFlag)) != KErrNone)
|
sl@0
|
104 |
return KErrNotFound;
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
TInt err = KErrNotReady;
|
sl@0
|
108 |
|
sl@0
|
109 |
if (iProtocol && iTransport)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
iTransport->RegisterProtocol(*iProtocol);
|
sl@0
|
112 |
iProtocol->RegisterTransport(iTransport);
|
sl@0
|
113 |
__PRINT(_L("CUsbMassStorageController::Start: Starting"));
|
sl@0
|
114 |
((CScsiProtocol*)iProtocol)->SetScsiParameters(aConfig);
|
sl@0
|
115 |
err = iTransport->Start();
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
__PRINT(_L("CUsbMassStorageController::Start Out"));
|
sl@0
|
119 |
|
sl@0
|
120 |
return err;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
/**
|
sl@0
|
124 |
Stops the transport.
|
sl@0
|
125 |
*/
|
sl@0
|
126 |
TInt CUsbMassStorageController::Stop()
|
sl@0
|
127 |
{
|
sl@0
|
128 |
|
sl@0
|
129 |
__PRINT(_L("CUsbMassStorageController::Stop In"));
|
sl@0
|
130 |
TInt err = KErrNotReady;
|
sl@0
|
131 |
if (iTransport)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
__PRINT(_L("CUsbMassStorageController::Stop: Stopping"));
|
sl@0
|
134 |
err = iTransport->Stop();
|
sl@0
|
135 |
}
|
sl@0
|
136 |
TInt i=0;
|
sl@0
|
137 |
for (i=0; i<=iMaxDrives; ++i)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
iDriveManager->SetCritical(i, EFalse); //unset critical
|
sl@0
|
140 |
}
|
sl@0
|
141 |
__PRINT(_L("CUsbMassStorageController::Stop Out"));
|
sl@0
|
142 |
|
sl@0
|
143 |
return err;
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
/**
|
sl@0
|
147 |
Delete the transport and protocol and start new ones.
|
sl@0
|
148 |
*/
|
sl@0
|
149 |
void CUsbMassStorageController::Reset()
|
sl@0
|
150 |
{
|
sl@0
|
151 |
|
sl@0
|
152 |
delete iProtocol;
|
sl@0
|
153 |
iProtocol = NULL;
|
sl@0
|
154 |
|
sl@0
|
155 |
//Create transport and protocol and initialize them
|
sl@0
|
156 |
__PRINT(_L("CUsbMassStorageController::Reset: Creating protocol"));
|
sl@0
|
157 |
|
sl@0
|
158 |
TRAPD(err,iProtocol = CScsiProtocol::NewL(*iDriveManager));
|
sl@0
|
159 |
err = err;
|
sl@0
|
160 |
__ASSERT_DEBUG(err==KErrNone, User::Invariant());
|
sl@0
|
161 |
iTransport->RegisterProtocol(*iProtocol);
|
sl@0
|
162 |
iProtocol->RegisterTransport(iTransport);
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|