kerneltest/e32test/usb/t_usb_device/src/activecontrol.cpp
changeset 281 13fbfa31d2ba
parent 259 57b9594f5772
child 271 dc268b18d709
equal deleted inserted replaced
266:0008ccd16016 281:13fbfa31d2ba
    22 #include "usblib.h"											// Helpers
    22 #include "usblib.h"											// Helpers
    23 #include "config.h"
    23 #include "config.h"
    24 #include "activecontrol.h"
    24 #include "activecontrol.h"
    25 #include "apitests.h"
    25 #include "apitests.h"
    26 #include "activerw.h"
    26 #include "activerw.h"
       
    27 #include "d32otgdi.h"
    27 #ifdef USB_SC
    28 #ifdef USB_SC
    28 #include "tranhandleserver.h"
    29 #include "tranhandleserver.h"
    29 #endif
    30 #endif
    30 
    31 
    31 #include "OstTraceDefinitions.h"
    32 #include "OstTraceDefinitions.h"
    34 #endif
    35 #endif
    35 
    36 
    36 
    37 
    37 void StartMassStorage(RDEVCLIENT* aPort);
    38 void StartMassStorage(RDEVCLIENT* aPort);
    38 void StopMassStorage(RDEVCLIENT* aPort);
    39 void StopMassStorage(RDEVCLIENT* aPort);
       
    40 void OpenStackIfOtg();
       
    41 void CloseStackIfOtg();
       
    42 
       
    43 _LIT(KOtgdiLddFilename, "otgdi");
       
    44 static TBool gSupportsOtg;
       
    45 static RUsbOtgDriver gOtgPort;
    39 
    46 
    40 enum Ep0Requests
    47 enum Ep0Requests
    41 	{
    48 	{
    42 	EStop = 0x1,
    49 	EStop = 0x1,
    43 	EVersion = 0x10,
    50 	EVersion = 0x10,
   285 					#endif
   292 					#endif
   286 					}
   293 					}
   287 				}
   294 				}
   288 			}
   295 			}
   289 
   296 
       
   297 		// Check for OTG support
       
   298 		TBuf8<KUsbDescSize_Otg> otg_desc;
       
   299 		r = iPort[0].GetOtgDescriptor(otg_desc);
       
   300 		if (!(r == KErrNotSupported || r == KErrNone))
       
   301 			{
       
   302 			OstTrace1(TRACE_NORMAL, CACTIVECONTROL_CONSTRUCTL_DUP08, "Error %d while fetching OTG descriptor", r);
       
   303 			User::Leave(-1);
       
   304 			return;
       
   305 			}
       
   306 		gSupportsOtg = (r != KErrNotSupported) ? ETrue : EFalse;
       
   307 
       
   308 		OpenStackIfOtg();
       
   309 		
   290 		iTotalChannels += lddPtr->iNumChannels;
   310 		iTotalChannels += lddPtr->iNumChannels;
   291 		nextPort += lddPtr->iNumChannels;
   311 		nextPort += lddPtr->iNumChannels;
   292 		lddPtr = lddPtr->iPtrNext;
   312 		lddPtr = lddPtr->iPtrNext;
   293 		}
   313 		}
   294 
   314 
  1028 
  1048 
  1029 					if (value && firstBulkOutEndpoint > 0)
  1049 					if (value && firstBulkOutEndpoint > 0)
  1030 						{
  1050 						{
  1031 						PrintHostLog();
  1051 						PrintHostLog();
  1032 						}
  1052 						}
  1033 
  1053 						
       
  1054 					CloseStackIfOtg();
       
  1055 					
  1034 					for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
  1056 					for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
  1035 						{
  1057 						{
  1036 						// base class cancel -> calls our DoCancel
  1058 						// base class cancel -> calls our DoCancel
  1037 						delete iDeviceStateNotifier[portNumber];
  1059 						delete iDeviceStateNotifier[portNumber];
  1038 						delete iStallNotifier[portNumber];
  1060 						delete iStallNotifier[portNumber];
  1370 					// send this now as the port will be disconnected
  1392 					// send this now as the port will be disconnected
  1371 					sendStatus = EFalse;
  1393 					sendStatus = EFalse;
  1372 					r = iPort[0].SendEp0StatusPacket();
  1394 					r = iPort[0].SendEp0StatusPacket();
  1373 					test_KErrNone(r);
  1395 					test_KErrNone(r);
  1374 
  1396 
       
  1397 					CloseStackIfOtg();
       
  1398 					
  1375 					for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
  1399 					for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
  1376 						{
  1400 						{
  1377 						delete iDeviceStateNotifier[portNumber];
  1401 						delete iDeviceStateNotifier[portNumber];
  1378 						delete iStallNotifier[portNumber];
  1402 						delete iStallNotifier[portNumber];
  1379 						if (portNumber == 0)
  1403 						if (portNumber == 0)
  1413 					    }
  1437 					    }
  1414 
  1438 
  1415 					SetupDescriptors(iLddPtr, &iPort[0],value);
  1439 					SetupDescriptors(iLddPtr, &iPort[0],value);
  1416 					StartMassStorage(&iPort[0]);
  1440 					StartMassStorage(&iPort[0]);
  1417 
  1441 
       
  1442 					OpenStackIfOtg();
       
  1443 					
  1418 					test.Next (_L("Enumeration..."));
  1444 					test.Next (_L("Enumeration..."));
  1419 					r = ReEnumerate();
  1445 					r = ReEnumerate();
  1420 					test_KErrNone(r);
  1446 					test_KErrNone(r);
  1421 
  1447 
  1422 
  1448 
  1531 	return KErrNone;
  1557 	return KErrNone;
  1532 	}
  1558 	}
  1533 
  1559 
  1534 void CActiveControl::PrintHostLog()
  1560 void CActiveControl::PrintHostLog()
  1535 	{
  1561 	{
       
  1562 #ifdef OST_TRACE_COMPILER_IN_USE
  1536 	TRequestStatus status = 0;
  1563 	TRequestStatus status = 0;
  1537 	wchar_t lineBuf[128];
  1564 	wchar_t lineBuf[128];
  1538 	TUint j = 0;
  1565 	TUint j = 0;
  1539 
  1566 
  1540 	TUSB_VERBOSE_PRINT("Reading Host log file\n");
  1567 	TUSB_VERBOSE_PRINT("Reading Host log file\n");
  1549 	TAny * scReadData;
  1576 	TAny * scReadData;
  1550 	TUint8 * scCharPtr;
  1577 	TUint8 * scCharPtr;
  1551 	TUint readSize;
  1578 	TUint readSize;
  1552 	TBool readZlp = EFalse;
  1579 	TBool readZlp = EFalse;
  1553 
  1580 
  1554 	r = iPort->OpenEndpoint(scReadBuf,firstBulkOutEndpoint);
  1581     r = iPort->OpenEndpoint(scReadBuf,firstBulkOutEndpoint);
  1555 	test_KErrNone(r);
  1582     test_KErrNone(r);
  1556 	do
  1583     do
  1557 		{
  1584         {
  1558 		r = scReadBuf.GetBuffer (scReadData,readSize,readZlp,status);
  1585         r = scReadBuf.GetBuffer (scReadData,readSize,readZlp,status);
  1559 		// The following line can be reinstated once the shared chunk failure is fixed
  1586         // The following line can be reinstated once the shared chunk failure is fixed
  1560 		// that prevents the readZlp flag from being set
  1587         // that prevents the readZlp flag from being set
  1561 		// test_Value(r, (r == KErrNone) || (r == KErrCompletion) || (r == KErrEof));
  1588         // test_Value(r, (r == KErrNone) || (r == KErrCompletion) || (r == KErrEof));
  1562 		if (r == KErrCompletion)
  1589         if (r == KErrCompletion)
  1563 			{
  1590             {
  1564 			TUSB_VERBOSE_PRINT1("Host log file %d bytes read\n",readSize);
  1591             TUSB_VERBOSE_PRINT1("Host log file %d bytes read\n",readSize);
  1565 			if(gVerbose)
  1592             if(gVerbose)
  1566 			    {
  1593                 {
  1567 			    OstTrace1(TRACE_VERBOSE, CACTIVECONTROL_PRINTHOSTLOG_DUP01, "Host log file %d bytes read\n",readSize);
  1594                 OstTrace1(TRACE_VERBOSE, CACTIVECONTROL_PRINTHOSTLOG_DUP01, "Host log file %d bytes read\n",readSize);
  1568 			    }
  1595                 }
  1569 			scCharPtr = (TUint8 *)scReadData;
  1596             scCharPtr = (TUint8 *)scReadData;
  1570 			// Print the host log file
  1597             // Print the host log file
  1571 			for (TUint i = 0; i < readSize; i++)
  1598             for (TUint i = 0; i < readSize; i++)
  1572 				{
  1599                 {
  1573 				if (* scCharPtr == '\r')
  1600                 if (* scCharPtr == '\r')
  1574 					{
  1601                     {
  1575 					lineBuf[j++] = '\0';
  1602                     lineBuf[j++] = '\0';
  1576 					OstTraceExt1(TRACE_NORMAL, CACTIVECONTROL_PRINTHOSTLOG_DUP02, "%S",*lineBuf);
  1603                     OstTraceExt1(TRACE_NORMAL, CACTIVECONTROL_PRINTHOSTLOG_DUP02, "%S",*lineBuf);
  1577 					j = 0;
  1604                     j = 0;
  1578 					}
  1605                     }
  1579 				else
  1606                 else
  1580 					{
  1607                     {
  1581 					if (* scCharPtr != '\n')
  1608                     if (* scCharPtr != '\n')
  1582 						{
  1609                         {
  1583 						lineBuf[j++] = * scCharPtr;
  1610                         lineBuf[j++] = * scCharPtr;
  1584 						}
  1611                         }
  1585 					}
  1612                     }
  1586 				scCharPtr++;
  1613                 scCharPtr++;
  1587 				}
  1614                 }
  1588 			}
  1615             }
  1589 		if (r == KErrNone)
  1616         if (r == KErrNone)
  1590 			{
  1617             {
  1591 			User::WaitForRequest(status);
  1618             User::WaitForRequest(status);
  1592 			test_KErrNone(status.Int());
  1619             test_KErrNone(status.Int());
  1593 			}
  1620             }
  1594 		}
  1621         }
  1595 	while (r >= KErrNone && !readZlp);
  1622     while (r >= KErrNone && !readZlp);
  1596 	#else
  1623     #else
  1597 	TPtr8 readBuf((TUint8 *)User::Alloc(KHostLogFileSize),KHostLogFileSize,KHostLogFileSize);
  1624     TPtr8 readBuf((TUint8 *)User::Alloc(KHostLogFileSize),KHostLogFileSize,KHostLogFileSize);
  1598 	iPort[0].ReadUntilShort(status, (TEndpointNumber)firstBulkOutEndpoint, readBuf);
  1625     iPort[0].ReadUntilShort(status, (TEndpointNumber)firstBulkOutEndpoint, readBuf);
  1599 	User::WaitForRequest(status);
  1626     User::WaitForRequest(status);
  1600 	test_KErrNone(status.Int());
  1627     test_KErrNone(status.Int());
  1601 	TUSB_VERBOSE_PRINT1("Host log file %d bytes read\n",readBuf.Length());
  1628     TUSB_VERBOSE_PRINT1("Host log file %d bytes read\n",readBuf.Length());
  1602 	if(gVerbose)
  1629     if(gVerbose)
  1603 	    {
  1630         {
  1604 	    OstTrace1(TRACE_VERBOSE, CACTIVECONTROL_PRINTHOSTLOG_DUP03, "Host log file %d bytes read\n",readBuf.Length());
  1631         OstTrace1(TRACE_VERBOSE, CACTIVECONTROL_PRINTHOSTLOG_DUP03, "Host log file %d bytes read\n",readBuf.Length());
  1605 	    }
  1632         }
  1606 	for (TUint i = 0; i < readBuf.Length(); i++)
  1633     for (TUint i = 0; i < readBuf.Length(); i++)
  1607 		{
  1634         {
  1608 		if (readBuf[i] == '\r')
  1635         if (readBuf[i] == '\r')
  1609 			{
  1636             {
  1610 			lineBuf[j++] = '\0';
  1637             lineBuf[j++] = '\0';
  1611 			OstTraceExt1(TRACE_NORMAL, CACTIVECONTROL_PRINTHOSTLOG_DUP04, "%s",*lineBuf);
  1638             OstTraceExt1(TRACE_NORMAL, CACTIVECONTROL_PRINTHOSTLOG_DUP04, "%s",*lineBuf);
  1612 			j = 0;
  1639             j = 0;
  1613 			}
  1640             }
  1614 		else
  1641         else
  1615 			{
  1642             {
  1616 			if (readBuf[i] != '\n')
  1643             if (readBuf[i] != '\n')
  1617 				{
  1644                 {
  1618 				lineBuf[j++] = readBuf[i];
  1645                 lineBuf[j++] = readBuf[i];
  1619 				}
  1646                 }
  1620 			}
  1647             }
  1621 		}
  1648         }
  1622 	User::Free ((TAny *)readBuf.Ptr());
  1649     User::Free ((TAny *)readBuf.Ptr());
  1623 	#endif
  1650     #endif
       
  1651     
       
  1652 #endif // OST_TRACE_COMPILER_IN_USE
  1624 	}
  1653 	}
  1625 
  1654 
  1626 void CActiveControl::QueryUsbClientL(LDDConfigPtr aLddPtr, RDEVCLIENT* aPort)
  1655 void CActiveControl::QueryUsbClientL(LDDConfigPtr aLddPtr, RDEVCLIENT* aPort)
  1627 	{
  1656 	{
  1628 	// Get device/endpoint capabilities
  1657 	// Get device/endpoint capabilities
  2358 	test.End();
  2387 	test.End();
  2359 	RequestEp0ControlPacket();
  2388 	RequestEp0ControlPacket();
  2360 	}
  2389 	}
  2361 
  2390 
  2362 #endif
  2391 #endif
       
  2392 
       
  2393 void OpenStackIfOtg()
       
  2394 	{
       
  2395 	// On an OTG device we have to start the OTG driver, otherwise the Client
       
  2396 	// stack will remain disabled forever.
       
  2397 	if (gSupportsOtg)
       
  2398 		{
       
  2399 		test.Start(_L("Running on OTG device: loading OTG driver\n"));
       
  2400 		test.Next(_L("Load OTG LDD"));
       
  2401 		TInt r = User::LoadLogicalDevice(KOtgdiLddFilename);
       
  2402 		test((r == KErrNone) || (r == KErrAlreadyExists));
       
  2403 
       
  2404 		test.Next(_L("Open OTG channel"));
       
  2405 		r = gOtgPort.Open();
       
  2406 		test(r == KErrNone);
       
  2407 
       
  2408 		test.Next(_L("Start OTG stack"));
       
  2409 		r = gOtgPort.StartStacks();
       
  2410 		test(r == KErrNone);
       
  2411 		test.End();
       
  2412 		}
       
  2413 	}
       
  2414 
       
  2415 void CloseStackIfOtg()
       
  2416 	{
       
  2417 	if (gSupportsOtg)
       
  2418 		{
       
  2419 		test.Start(_L("Close OTG stack\n"));
       
  2420 		test.Next(_L("Stop OTG stack"));
       
  2421 		gOtgPort.StopStacks();
       
  2422 		test.Next(_L("Close OTG Channel"));
       
  2423 		gOtgPort.Close();
       
  2424 		test.Next(_L("Free OTG LDD"));
       
  2425 		TInt r = User::FreeLogicalDevice(RUsbOtgDriver::Name());
       
  2426 		test(r == KErrNone);
       
  2427 		test.End();
       
  2428 		}
       
  2429 	}
       
  2430 	
  2363 // -eof-
  2431 // -eof-