Update contrib.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include <e32std_private.h>
20 #include "t_gml_tur_protocol.h"
21 #include "t_gml_tur_controller.h"
22 #include "cbulkonlytransport.h"
24 LOCAL_D RTest test(_L("t_gml_tur"));
26 _LIT(KDriverFileName,"TESTUSBC.LDD");
27 _LIT(KLddName,"usbc");
28 _LIT(KTransportThreadName,"TransportThread");
29 _LIT(KTransportSemName,"TransportThreadSem");
31 LOCAL_D const TInt KFiveDrives = 5;
32 LOCAL_D const TEndpointNumber KOutEp = EEndpoint1;
34 GLDEF_D CUsbMassStorageController* gController = NULL;
36 LOCAL_C void SetCBWHeader(TDes8& cbwData, TInt32 aDataTransferLength, TBool aDataIn, TUint8 aLun, TUint8 aCBLength)
48 //dCBWDataTransferLength
49 cbwData[8] = TUint8((aDataTransferLength & 0x000000FF));
50 cbwData[9] = TUint8((aDataTransferLength & 0x0000FF00) >> 8);
51 cbwData[10] = TUint8((aDataTransferLength & 0x00FF0000) >> 16);
52 cbwData[11] = TUint8((aDataTransferLength & 0xFF000000) >> 24);
65 cbwData[14] = aCBLength;
68 LOCAL_C TInt TransportThreadEntry(TAny* aPtr)
71 TInt numDrives = KFiveDrives;
73 //Create and install cleanup trap and active scheduler
74 CTrapCleanup* cleanup = CTrapCleanup::New();
80 CActiveScheduler* sched = new CActiveScheduler;
85 CActiveScheduler::Install(sched);
88 CScsiProtocol* protocol = NULL;
89 TRAP(err, protocol = CScsiProtocol::NewL());
95 CUsbMassStorageController* controller = (CUsbMassStorageController*)aPtr;
96 gController = controller;
97 controller->CreateL(0);
99 CBulkOnlyTransport* transport = NULL;
100 TRAP(err, transport = CBulkOnlyTransport::NewL(numDrives, *controller));
106 controller->SetTransport(transport);
107 TRAP(err, transport->InitialiseTransportL(1));
109 transport->RegisterProtocol(*protocol);
112 //Synchronize with test thread
113 RSemaphore gSemThreadReady;
114 gSemThreadReady.OpenGlobal(KTransportSemName);
115 gSemThreadReady.Signal();
116 gSemThreadReady.Close();
118 CActiveScheduler::Start();
129 GLDEF_C TInt E32Main()
135 test.Start(_L("Loading ldd"));
136 err = User::LoadLogicalDevice(KDriverFileName);
137 test(err == KErrNone || err == KErrAlreadyExists);
139 RDevTestUsbcClient ldd;
141 test(err == KErrNone);
143 //ldd.ResetEndpoints();
145 RSemaphore gSemThreadReady;
146 err = gSemThreadReady.CreateGlobal(KTransportSemName, 0);
148 CUsbMassStorageController* controller = new CUsbMassStorageController();
149 test(controller != NULL);
151 //Start transport thread.
152 RThread transportThread;
153 test.Next(_L("Creating transport thread, Max Lun = 4"));
154 err = transportThread.Create(KTransportThreadName, TransportThreadEntry, KDefaultStackSize, NULL, (void*)controller);
155 test(err == KErrNone);
156 transportThread.Resume();
158 //Synchronize with transport thread.
159 gSemThreadReady.Wait();
160 gSemThreadReady.Close();
161 test(gController != NULL);
163 TRequestStatus status;
165 test.Next(_L("Writing GetMaxLun request to endpoint 0"));
166 //Write GetMaxLun request to endpoint 0
167 TBuf8<KRequestHdrSize> controlData;
168 controlData.SetLength(KRequestHdrSize);
170 controlData[0] = 0xA1;
171 controlData[1] = 0xFE;
172 controlData[6] = 0x01;
173 ldd.HostWrite(status, EEndpoint0, controlData, KRequestHdrSize);
175 User::WaitForRequest(status);
176 test.Printf(_L("status = %d"), status.Int());
177 test(status.Int() == KErrNone);
179 //Read request response
180 controlData.SetLength(1);
181 ldd.HostRead(status, EEndpoint0, controlData, 1);
183 User::WaitForRequest(status);
184 test(status.Int() == KErrNone);
186 test.Printf(_L("Max LUN: %d\n"), controlData[0]);
187 test(controlData[0] == KFiveDrives - 1);
189 //Send TEST UNIT READY command
190 TBuf8<KCbwLength> cbwData;
191 cbwData.SetLength(KCbwLength);
193 SetCBWHeader(cbwData, 6, ETrue, 0, 6);
194 ldd.HostWrite(status, KOutEp, cbwData, KCbwLength);
195 User::WaitForRequest(status);
196 test(status.Int() == KErrNone);
198 test.Next(_L("Writing Reset request to endpoint 0"));
199 //Write Reset request to endpoint 0
200 controlData.SetLength(KRequestHdrSize);
202 controlData[0] = 0x21;
203 controlData[1] = 0xFF;
204 ldd.HostWrite(status, EEndpoint0, controlData, KRequestHdrSize);
206 User::WaitForRequest(status);
207 test(status.Int() == KErrNone);
209 User::After(3000000); //3 seconds
210 test(gController->IsReset());
211 test.Printf(_L("Controller got reset request\n"));
213 TRequestStatus logonStatus;
214 transportThread.Logon(logonStatus);
215 TRequestStatus* statusPtr = &(controller->iStatus);
216 transportThread.RequestComplete(statusPtr, KErrNone);
217 //Wait for thread to die
218 test.Printf(_L("Waiting for controller thread to die\n"));
219 User::WaitForRequest(logonStatus);
220 transportThread.Close();
221 test.Printf(_L("The thread is dead, long live the thread\n"));
225 test.Printf(_L("Unloading ldd"));
226 err = User::FreeLogicalDevice(KLddName);
227 test(err == KErrNone);