1 /* |
1 /* |
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
19 /** |
19 /** |
20 @file |
20 @file |
21 */ |
21 */ |
22 |
22 |
23 #include <e32svr.h> |
23 #include <e32svr.h> |
|
24 #include <usb/usblogger.h> |
24 #include "UsbSettings.h" |
25 #include "UsbSettings.h" |
25 #include "CUsbServer.h" |
26 #include "CUsbServer.h" |
26 #include "CUsbSession.h" |
27 #include "CUsbSession.h" |
27 #include "CUsbDevice.h" |
28 #include "CUsbDevice.h" |
28 |
29 |
29 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
30 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
31 #include <e32property.h> //Publish & Subscribe header |
30 #include "CUsbOtg.h" |
32 #include "CUsbOtg.h" |
31 #include "cusbhost.h" |
33 #include "cusbhost.h" |
32 #include <e32property.h> //Publish & Subscribe header |
|
33 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
34 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
34 |
35 |
35 #include <usb/usblogger.h> |
|
36 #include "UsbmanServerSecurityPolicy.h" |
36 #include "UsbmanServerSecurityPolicy.h" |
37 #include <usb/usblogger.h> |
37 #include "OstTraceDefinitions.h" |
38 |
38 #ifdef OST_TRACE_COMPILER_IN_USE |
39 #ifdef __FLOG_ACTIVE |
39 #include "CUsbServerTraces.h" |
40 _LIT8(KLogComponent, "USBSVR"); |
40 #endif |
41 #endif |
41 |
|
42 |
42 |
43 |
43 /** |
44 /** |
44 * The CUsbServer::NewL method |
45 * The CUsbServer::NewL method |
45 * |
46 * |
46 * Constructs a Usb Server |
47 * Constructs a Usb Server |
49 * |
50 * |
50 * @return A new Usb Server object |
51 * @return A new Usb Server object |
51 */ |
52 */ |
52 CUsbServer* CUsbServer::NewLC() |
53 CUsbServer* CUsbServer::NewLC() |
53 { |
54 { |
54 LOG_STATIC_FUNC_ENTRY |
55 OstTraceFunctionEntry0( CUSBSERVER_NEWLC_ENTRY ); |
55 |
56 |
56 CUsbServer* self = new(ELeave) CUsbServer; |
57 CUsbServer* self = new(ELeave) CUsbServer; |
57 CleanupStack::PushL(self); |
58 CleanupStack::PushL(self); |
58 self->StartL(KUsbServerName); |
59 self->StartL(KUsbServerName); |
59 self->ConstructL(); |
60 self->ConstructL(); |
|
61 OstTraceFunctionExit0( CUSBSERVER_NEWLC_EXIT ); |
60 return self; |
62 return self; |
61 } |
63 } |
62 |
64 |
63 |
65 |
64 /** |
66 /** |
68 * |
70 * |
69 * @internalComponent |
71 * @internalComponent |
70 */ |
72 */ |
71 CUsbServer::~CUsbServer() |
73 CUsbServer::~CUsbServer() |
72 { |
74 { |
73 LOG_FUNC |
75 OstTraceFunctionEntry0( CUSBSERVER_CUSBSERVER_DES_ENTRY ); |
74 |
76 |
75 delete iShutdownTimer; |
77 delete iShutdownTimer; |
76 delete iUsbDevice; |
78 delete iUsbDevice; |
77 |
79 |
78 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
80 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
79 delete iUsbHost; |
81 delete iUsbHost; |
80 |
82 |
81 #ifndef __OVER_DUMMYUSBDI__ |
83 #ifndef __OVER_DUMMYUSBDI__ |
82 // Check that this is A-Device |
84 // Check that this is A-Device |
83 LOGTEXT(_L8("Checking Id-Pin state...")); |
85 OstTrace0( TRACE_NORMAL, CUSBSERVER_CUSBSERVER, "CUsbServer::~CUsbServer; Checking Id-Pin state..." ); |
84 TInt value = 0; |
86 TInt value = 0; |
85 TInt err = RProperty::Get(KUidUsbManCategory, KUsbOtgIdPinPresentProperty,value); |
87 TInt err = RProperty::Get(KUidUsbManCategory, KUsbOtgIdPinPresentProperty,value); |
86 if (err == 0 && value == 1) |
88 if (err == 0 && value == 1) |
87 { |
89 { |
88 // Ensure VBus is dropped when Usb server exits |
90 // Ensure VBus is dropped when Usb server exits |
89 LOGTEXT(_L8("Checking VBus state...")); |
91 OstTrace0( TRACE_NORMAL, CUSBSERVER_CUSBSERVER_DUP1, "CUsbServer::~CUsbServer; Checking VBus state..." ); |
90 err = RProperty::Get(KUidUsbManCategory, KUsbOtgVBusPoweredProperty,value); |
92 err = RProperty::Get(KUidUsbManCategory, KUsbOtgVBusPoweredProperty,value); |
91 if ( err == KErrNone && value != 0 ) |
93 if ( err == KErrNone && value != 0 ) |
92 { |
94 { |
93 if ( iUsbOtg ) |
95 if ( iUsbOtg ) |
94 { |
96 { |
95 err = iUsbOtg->BusDrop(); |
97 err = iUsbOtg->BusDrop(); |
96 LOGTEXT2(_L8("BusDrop() returned err = %d"),err); |
98 OstTrace1( TRACE_NORMAL, CUSBSERVER_CUSBSERVER_DUP2, "CUsbServer::~CUsbServer;BusDrop() returned err = %d", err ); |
97 LOGTEXT(_L8("USBMAN will wait until VBus is actually dropped")); |
99 OstTrace0( TRACE_NORMAL, CUSBSERVER_CUSBSERVER_DUP3, "CUsbServer::~CUsbServer; USBMAN will wait until VBus is actually dropped" ); |
98 // Wait 1 second for Hub driver to perform VBus drop |
100 // Wait 1 second for Hub driver to perform VBus drop |
99 RTimer timer; |
101 RTimer timer; |
100 err = timer.CreateLocal(); |
102 err = timer.CreateLocal(); |
101 if ( err == KErrNone ) |
103 if ( err == KErrNone ) |
102 { |
104 { |
105 User::WaitForRequest(tstatus); |
107 User::WaitForRequest(tstatus); |
106 timer.Close(); |
108 timer.Close(); |
107 } |
109 } |
108 else |
110 else |
109 { |
111 { |
110 LOGTEXT2(_L8("Failed to create local timer: err = %d"),err); |
112 OstTrace1( TRACE_NORMAL, CUSBSERVER_CUSBSERVER_DUP4, "CUsbServer::~CUsbServer;Failed to create local timer: err = %d", err ); |
111 } |
113 } |
112 } |
114 } |
113 else |
115 else |
114 { |
116 { |
115 LOGTEXT(_L8("Unexpected: OTG object is NULL")); |
117 OstTrace0( TRACE_NORMAL, CUSBSERVER_CUSBSERVER_DUP5, "CUsbServer::~CUsbServer; Unexpected: OTG object is NULL" ); |
116 } |
118 } |
117 } |
119 } |
118 else |
120 else |
119 { |
121 { |
120 LOGTEXT3(_L8("VBus is already dropped or an error occured: err = %d, value =%d"),err,value); |
122 OstTraceExt2( TRACE_NORMAL, CUSBSERVER_CUSBSERVER_DUP6, "CUsbServer::~CUsbServer;VBus is already dropped or an error occured: err = %d, value =%d", err, value ); |
121 } |
123 } |
122 } |
124 } |
123 else |
125 else |
124 { |
126 { |
125 LOGTEXT3(_L8("No Id-Pin is found or an error occured: err = %d, value = %d"), err, value); |
127 OstTraceExt2( TRACE_NORMAL, CUSBSERVER_CUSBSERVER_DUP7, "CUsbServer::~CUsbServer;No Id-Pin is found or an error occured: err = %d, value = %d", err, value ); |
126 } |
128 } |
127 |
129 |
128 delete iUsbOtg; |
130 delete iUsbOtg; |
129 #endif |
131 #endif |
130 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
132 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
131 |
133 |
132 #ifdef __FLOG_ACTIVE |
134 OstTraceFunctionExit0( CUSBSERVER_CUSBSERVER_DES_EXIT ); |
133 CUsbLog::Close(); |
|
134 #endif |
|
135 } |
135 } |
136 |
136 |
137 |
137 |
138 /** |
138 /** |
139 * The CUsbServer::CUsbServer method |
139 * The CUsbServer::CUsbServer method |
154 * |
154 * |
155 * @internalComponent |
155 * @internalComponent |
156 */ |
156 */ |
157 void CUsbServer::ConstructL() |
157 void CUsbServer::ConstructL() |
158 { |
158 { |
159 #ifdef __FLOG_ACTIVE |
159 |
160 // Set the logger up so that everything in this thread that logs using it |
|
161 // will do so 'connectedly' (i.e. quickly). If this fails, we don't care- |
|
162 // logging will still work, just 'statically' (i.e. slowly). |
|
163 static_cast<void>(CUsbLog::Connect()); |
|
164 #endif |
|
165 |
160 |
166 iShutdownTimer = new(ELeave) CShutdownTimer; |
161 iShutdownTimer = new(ELeave) CShutdownTimer; |
167 iShutdownTimer->ConstructL(); |
162 iShutdownTimer->ConstructL(); |
168 |
163 |
169 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
164 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
172 iUsbOtg->StartL(); |
167 iUsbOtg->StartL(); |
173 #endif |
168 #endif |
174 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
169 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
175 |
170 |
176 iUsbDevice = CUsbDevice::NewL(*this); |
171 iUsbDevice = CUsbDevice::NewL(*this); |
177 LOGTEXT(_L8("About to load USB classes")); |
172 OstTrace0( TRACE_NORMAL, CUSBSERVER_CONSTRUCTL, "CUsbServer::ConstructL; About to load USB classes" ); |
178 iUsbDevice->EnumerateClassControllersL(); |
173 iUsbDevice->EnumerateClassControllersL(); |
179 |
174 |
180 #ifndef USE_DUMMY_CLASS_CONTROLLER |
175 #ifndef USE_DUMMY_CLASS_CONTROLLER |
181 iUsbDevice->ReadPersonalitiesL(); |
176 iUsbDevice->ReadPersonalitiesL(); |
182 if (iUsbDevice->isPersonalityCfged()) |
177 if (iUsbDevice->isPersonalityCfged()) |
186 #endif |
181 #endif |
187 iUsbDevice->SetDefaultPersonalityL(); |
182 iUsbDevice->SetDefaultPersonalityL(); |
188 } |
183 } |
189 else |
184 else |
190 { |
185 { |
191 LOGTEXT(_L8("Personalities unconfigured, so using fallback CCs")); |
186 OstTrace0( TRACE_NORMAL, CUSBSERVER_CONSTRUCTL_DUP1, "CUsbServer::ConstructL;Personalities unconfigured, so using fallback CCs" ); |
192 iUsbDevice->LoadFallbackClassControllersL(); |
187 iUsbDevice->LoadFallbackClassControllersL(); |
193 } |
188 } |
194 #else // USE_DUMMY_CLASS_CONTROLLER |
189 #else // USE_DUMMY_CLASS_CONTROLLER |
195 LOGTEXT(_L8("Using Dummy Class Controller, so using fallback CCs")); |
190 OstTrace0( TRACE_NORMAL, CUSBSERVER_CONSTRUCTL_DUP2, "CUsbServer::ConstructL; Using Dummy Class Controller, so using fallback CCs" ); |
196 iUsbDevice->LoadFallbackClassControllersL(); |
191 iUsbDevice->LoadFallbackClassControllersL(); |
197 #endif // USE_DUMMY_CLASS_CONTROLLER |
192 #endif // USE_DUMMY_CLASS_CONTROLLER |
198 |
193 |
199 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
194 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
200 iUsbHost = CUsbHost::NewL(); |
195 iUsbHost = CUsbHost::NewL(); |
202 //But it will cause the loading of personality longer. |
197 //But it will cause the loading of personality longer. |
203 //So it is moved back here. |
198 //So it is moved back here. |
204 iUsbHost->StartL(); |
199 iUsbHost->StartL(); |
205 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
200 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
206 |
201 |
207 LOGTEXT(_L8("CUsbServer constructed")); |
202 OstTrace0( TRACE_NORMAL, CUSBSERVER_CONSTRUCTL_DUP3, "CUsbServer::ConstructL; CUsbServer constructed" ); |
208 } |
203 } |
209 |
204 |
210 |
205 |
211 /** |
206 /** |
212 * The CUsbServer::NewSessionL method |
207 * The CUsbServer::NewSessionL method |
219 * |
214 * |
220 * @return A new USB session to be used for the client |
215 * @return A new USB session to be used for the client |
221 */ |
216 */ |
222 CSession2* CUsbServer::NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const |
217 CSession2* CUsbServer::NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const |
223 { |
218 { |
224 LOG_LINE |
219 OstTraceFunctionEntry0( CUSBSERVER_NEWSESSIONL_ENTRY ); |
225 LOG_FUNC |
|
226 |
220 |
227 (void)aMessage;//Remove compiler warning |
221 (void)aMessage;//Remove compiler warning |
228 |
222 |
229 TVersion v(KUsbSrvMajorVersionNumber,KUsbSrvMinorVersionNumber,KUsbSrvBuildVersionNumber); |
223 TVersion v(KUsbSrvMajorVersionNumber,KUsbSrvMinorVersionNumber,KUsbSrvBuildVersionNumber); |
230 |
224 |
231 LOGTEXT(_L8("CUsbServer::NewSessionL - creating new session...")); |
225 OstTrace0( TRACE_NORMAL, CUSBSERVER_NEWSESSIONL, "CUsbServer::NewSessionL; CUsbServer::NewSessionL - creating new session..." ); |
232 if (!User::QueryVersionSupported(v, aVersion)) |
226 if (!User::QueryVersionSupported(v, aVersion)) |
233 { |
227 { |
234 LEAVEL(KErrNotSupported); |
228 OstTrace1( TRACE_NORMAL, CUSBSERVER_NEWSESSIONL_DUP1, "CUsbServer::NewSessionL;leave reason=%d", KErrNotSupported ); |
|
229 User::Leave(KErrNotSupported); |
235 } |
230 } |
236 |
231 |
237 CUsbServer* ncThis = const_cast<CUsbServer*>(this); |
232 CUsbServer* ncThis = const_cast<CUsbServer*>(this); |
238 |
233 |
239 CUsbSession* sess = CUsbSession::NewL(ncThis); |
234 CUsbSession* sess = CUsbSession::NewL(ncThis); |
240 |
235 |
|
236 OstTraceFunctionExit0( CUSBSERVER_NEWSESSIONL_EXIT ); |
241 return sess; |
237 return sess; |
242 } |
238 } |
243 |
239 |
244 |
240 |
245 /** |
241 /** |
260 * |
256 * |
261 * @post the number of open sessions is incremented by one |
257 * @post the number of open sessions is incremented by one |
262 */ |
258 */ |
263 void CUsbServer::IncrementSessionCount() |
259 void CUsbServer::IncrementSessionCount() |
264 { |
260 { |
265 LOGTEXT2(_L8(">CUsbServer::IncrementSessionCount %d"), iSessionCount); |
261 OstTraceFunctionEntry0( CUSBSERVER_INCREMENTSESSIONCOUNT_ENTRY ); |
266 __ASSERT_DEBUG(iSessionCount >= 0, _USB_PANIC(KUsbSvrPncCat, EICSInvalidCount)); |
262 OstTrace1( TRACE_NORMAL, CUSBSERVER_INCREMENTSESSIONCOUNT, "CUsbServer::IncrementSessionCount;iSessionCount=%d", iSessionCount ); |
|
263 if(iSessionCount < 0) |
|
264 { |
|
265 OstTrace1( TRACE_FATAL, CUSBSERVER_INCREMENTSESSIONCOUNT_DUP1, "CUsbServer::IncrementSessionCount;panic code=%d", EICSInvalidCount ); |
|
266 __ASSERT_DEBUG(EFalse, User::Panic(KUsbSvrPncCat, EICSInvalidCount)); |
|
267 } |
267 |
268 |
268 ++iSessionCount; |
269 ++iSessionCount; |
269 iShutdownTimer->Cancel(); |
270 iShutdownTimer->Cancel(); |
270 |
271 |
271 LOGTEXT(_L8("<CUsbServer::IncrementSessionCount")); |
272 OstTraceFunctionExit0( CUSBSERVER_INCREMENTSESSIONCOUNT_EXIT ); |
272 } |
273 } |
273 |
274 |
274 /** |
275 /** |
275 * Decrement the open session count (iSessionCount) by one. |
276 * Decrement the open session count (iSessionCount) by one. |
276 * |
277 * |
277 * @post the number of open sessions is decremented by one |
278 * @post the number of open sessions is decremented by one |
278 */ |
279 */ |
279 void CUsbServer::DecrementSessionCount() |
280 void CUsbServer::DecrementSessionCount() |
280 { |
281 { |
281 LOGTEXT3(_L8("CUsbServer::DecrementSessionCount %d, %d"), iSessionCount, Device().ServiceState()); |
282 OstTraceExt2( TRACE_NORMAL, CUSBSERVER_DECREMENTSESSIONCOUNT, "CUsbServer::DecrementSessionCount;iSessionCount=%d;Device().ServiceState()=%d", iSessionCount, Device().ServiceState() ); |
282 __ASSERT_DEBUG(iSessionCount > 0, _USB_PANIC(KUsbSvrPncCat, EDCSInvalidCount)); |
283 if(iSessionCount <= 0) |
|
284 { |
|
285 OstTrace1( TRACE_FATAL, CUSBSERVER_DECREMENTSESSIONCOUNT_DUP1, "CUsbServer::DecrementSessionCount;panic code=%d", EDCSInvalidCount ); |
|
286 __ASSERT_DEBUG(EFalse, User::Panic(KUsbSvrPncCat, EDCSInvalidCount)); |
|
287 } |
283 |
288 |
284 --iSessionCount; |
289 --iSessionCount; |
285 |
290 |
286 if (iSessionCount == 0 && Device().ServiceState() == EUsbServiceIdle) |
291 if (iSessionCount == 0 && Device().ServiceState() == EUsbServiceIdle) |
287 { |
292 { |
298 * @pre the services have been stopped. |
303 * @pre the services have been stopped. |
299 * @see CUsbDevice::SetServiceStateIdle |
304 * @see CUsbDevice::SetServiceStateIdle |
300 */ |
305 */ |
301 void CUsbServer::LaunchShutdownTimerIfNoSessions() |
306 void CUsbServer::LaunchShutdownTimerIfNoSessions() |
302 { |
307 { |
303 LOGTEXT(_L8("CUsbServer::LaunchShutdownTimerIfNoSessions")); |
308 OstTraceFunctionEntry0( CUSBSERVER_LAUNCHSHUTDOWNTIMERIFNOSESSIONS_ENTRY ); |
304 __ASSERT_DEBUG(Device().ServiceState() == EUsbServiceIdle, _USB_PANIC(KUsbSvrPncCat, ELSTNSNotIdle)); |
309 #ifdef _DEBUG |
305 |
310 if(Device().ServiceState() != EUsbServiceIdle) |
|
311 { |
|
312 OstTrace1( TRACE_FATAL, CUSBSERVER_LAUNCHSHUTDOWNTIMERIFNOSESSIONS, "CUsbServer::LaunchShutdownTimerIfNoSessions;panic code=%d", ELSTNSNotIdle ); |
|
313 User::Panic(KUsbSvrPncCat, ELSTNSNotIdle); |
|
314 } |
|
315 #endif |
306 if (iSessionCount == 0) |
316 if (iSessionCount == 0) |
307 iShutdownTimer->After(KShutdownDelay); |
317 iShutdownTimer->After(KShutdownDelay); |
|
318 OstTraceFunctionExit0( CUSBSERVER_LAUNCHSHUTDOWNTIMERIFNOSESSIONS_EXIT ); |
308 } |
319 } |
309 |
320 |
310 /** |
321 /** |
311 * Initialize this shutdown timer as a normal-priority |
322 * Initialize this shutdown timer as a normal-priority |
312 * (EPriorityStandard) active object. |
323 * (EPriorityStandard) active object. |