|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32std.h> |
|
19 #include "CdcInterfaceBase.h" |
|
20 #include <usb/usblogger.h> |
|
21 |
|
22 #ifdef __FLOG_ACTIVE |
|
23 _LIT8(KLogComponent, "ECACM"); |
|
24 #endif |
|
25 |
|
26 CCdcInterfaceBase::CCdcInterfaceBase(const TDesC16& aIfcName) |
|
27 /** |
|
28 * Constructor. |
|
29 * |
|
30 * @param aIfcName The name of the interface. |
|
31 */ |
|
32 { |
|
33 iIfcName.Set(aIfcName); |
|
34 } |
|
35 |
|
36 void CCdcInterfaceBase::BaseConstructL() |
|
37 /** |
|
38 * Construct the object |
|
39 * This call registers the object with the USB device driver |
|
40 */ |
|
41 { |
|
42 LOGTEXT(_L8("\tcalling RDevUsbcClient::Open")); |
|
43 // 0 is assumed to mean ep0 |
|
44 TInt ret = iLdd.Open(0); |
|
45 if ( ret ) |
|
46 { |
|
47 LOGTEXT2(_L8("\tRDevUsbcClient::Open = %d"), ret); |
|
48 LEAVEIFERRORL(ret); |
|
49 } |
|
50 |
|
51 ret = SetUpInterface(); |
|
52 if ( ret ) |
|
53 { |
|
54 LOGTEXT2(_L8("\tSetUpInterface = %d"), ret); |
|
55 LEAVEIFERRORL(ret); |
|
56 } |
|
57 } |
|
58 |
|
59 CCdcInterfaceBase::~CCdcInterfaceBase() |
|
60 /** |
|
61 * Destructor. |
|
62 */ |
|
63 { |
|
64 LOG_FUNC |
|
65 |
|
66 if ( iLdd.Handle() ) |
|
67 { |
|
68 LOGTEXT(_L8("\tLDD handle exists")); |
|
69 |
|
70 // Don't bother calling ReleaseInterface- the base driver spec says |
|
71 // that Close does it for us. |
|
72 |
|
73 LOGTEXT(_L8("\tclosing LDD session")); |
|
74 iLdd.Close(); |
|
75 } |
|
76 } |
|
77 |
|
78 TInt CCdcInterfaceBase::GetInterfaceNumber(TUint8& aIntNumber) |
|
79 /** |
|
80 * Get my interface number |
|
81 * |
|
82 * @param aIntNumber My interface number |
|
83 * @return Error. |
|
84 */ |
|
85 { |
|
86 LOG_FUNC |
|
87 |
|
88 TInt interfaceSize = 0; |
|
89 |
|
90 // 0 means the main interface in the LDD API |
|
91 TInt res = iLdd.GetInterfaceDescriptorSize(0, interfaceSize); |
|
92 |
|
93 if ( res ) |
|
94 { |
|
95 LOGTEXT2(_L8("\t***GetInterfaceDescriptorSize()=%d"), res); |
|
96 return res; |
|
97 } |
|
98 |
|
99 HBufC8* interfaceBuf = HBufC8::New(interfaceSize); |
|
100 if ( !interfaceBuf ) |
|
101 { |
|
102 LOGTEXT(_L8("\t***failed to create interfaceBuf- " |
|
103 "returning KErrNoMemory")); |
|
104 return KErrNoMemory; |
|
105 } |
|
106 |
|
107 TPtr8 interfacePtr = interfaceBuf->Des(); |
|
108 interfacePtr.SetLength(0); |
|
109 // 0 means the main interface in the LDD API |
|
110 res = iLdd.GetInterfaceDescriptor(0, interfacePtr); |
|
111 |
|
112 if ( res ) |
|
113 { |
|
114 delete interfaceBuf; |
|
115 LOGTEXT2(_L8("\t***GetInterfaceDescriptor()=%d"), res); |
|
116 return res; |
|
117 } |
|
118 |
|
119 #ifdef __FLOG_ACTIVE |
|
120 LOGTEXT2(_L8("\t***interface length = %d"), interfacePtr.Length()); |
|
121 for ( TInt i = 0 ; i < interfacePtr.Length() ; i++ ) |
|
122 { |
|
123 LOGTEXT2(_L8("\t***** %x"),interfacePtr[i]); |
|
124 } |
|
125 #endif |
|
126 |
|
127 const TUint8* buffer = reinterpret_cast<const TUint8*>(interfacePtr.Ptr()); |
|
128 // 2 is where the interface number is, according to the LDD API |
|
129 aIntNumber = buffer[2]; |
|
130 |
|
131 LOGTEXT2(_L8("\tinterface number = %d"), aIntNumber); |
|
132 |
|
133 delete interfaceBuf; |
|
134 |
|
135 return KErrNone; |
|
136 } |
|
137 |
|
138 // |
|
139 // End of file |