1 /* |
|
2 * Copyright (c) 2008-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: Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <usbuinotif.h> |
|
20 #include <usbpersonalityids.h> |
|
21 |
|
22 #include "cusbstatehostainitiatebase.h" |
|
23 #ifndef STIF |
|
24 #include "cusbnotifmanager.h" |
|
25 #include "cusbtimer.h" |
|
26 #else |
|
27 #include "mockcusbnotifmanager.h" |
|
28 #include "mockcusbtimer.h" |
|
29 #endif |
|
30 |
|
31 #include "definitions.h" |
|
32 #include "errors.h" |
|
33 |
|
34 #include "debug.h" |
|
35 #include "panic.h" |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CUsbStateHostAInitiateBase::CUsbStateHostAInitiateBase( |
|
42 CUsbOtgWatcher* aWatcher) : |
|
43 CUsbStateHostABase(aWatcher) |
|
44 { |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 void CUsbStateHostAInitiateBase::ConstructL() |
|
52 { |
|
53 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::ConstructL" ) ); |
|
54 |
|
55 CUsbStateHostABase::ConstructL(); |
|
56 |
|
57 iAttachmentTimer = CUsbTimer::NewL(this, EDeviceAttachmentTimer); |
|
58 |
|
59 //iUsbPersonalitySwitch = CUsbPersonalitySwitch::NewL(this); |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CUsbStateHostAInitiateBase::~CUsbStateHostAInitiateBase() |
|
67 { |
|
68 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::~CUsbStateHostAInitiateBase" ) ); |
|
69 |
|
70 delete iAttachmentTimer; |
|
71 //delete iUsbPersonalitySwitch; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 void CUsbStateHostAInitiateBase::JustBeforeLeavingThisStateL() |
|
79 { |
|
80 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::JustBeforeLeavingThisStateL" ) ); |
|
81 iAttachmentTimer->Cancel(); |
|
82 } |
|
83 |
|
84 // From TimerObserver |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CUsbStateHostAInitiateBase::TimerElapsedL(TUsbTimerId aTimerId) |
|
90 { |
|
91 switch (aTimerId) |
|
92 { |
|
93 case EDeviceAttachmentTimer: |
|
94 { |
|
95 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::TimerElapsedL - AttachmentTimer" ) ); |
|
96 HandleL(EUsbWatcherErrDandlingCable, EUsbStateHostHandle); |
|
97 break; |
|
98 } |
|
99 default: |
|
100 { |
|
101 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::TimerElapsedL - Unknown timer" ) ); |
|
102 Panic(EWrongTimerId); |
|
103 } |
|
104 } |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CUsbStateHostAInitiateBase::VBusUpL() |
|
112 { |
|
113 // start timer, waiting for device attachment |
|
114 iAttachmentTimer->After(KTimeToWaitForDeviceAttachment); |
|
115 } |
|
116 |
|
117 // From VBus observer |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CUsbStateHostAInitiateBase::VBusDownL() |
|
123 { |
|
124 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::VBusDownL" ) ); |
|
125 iAttachmentTimer->Cancel(); |
|
126 |
|
127 CUsbStateHostABase::VBusDownL(); |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 void CUsbStateHostAInitiateBase::AHostL() |
|
135 { |
|
136 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::AHostL" ) ); |
|
137 // do nothing |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CUsbStateHostAInitiateBase::APeripheralL() |
|
145 { |
|
146 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::AHostL" ) ); |
|
147 ChangeHostStateL(EUsbStateHostAPeripheral); |
|
148 } |
|
149 |
|
150 // From Host Event notification observer |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 void CUsbStateHostAInitiateBase::DeviceAttachedL(TDeviceEventInformation aTdi) |
|
156 { |
|
157 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL aTdi.iDeviceId = %d" ), aTdi.iDeviceId)); |
|
158 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL aTdi.iEventType = %d" ), aTdi.iEventType)); |
|
159 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL aTdi.iError = %d" ), aTdi.iError)); |
|
160 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL aTdi.iDriverLoadStatus = %d" ), aTdi.iDriverLoadStatus)); |
|
161 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL aTdi.iVid = %d" ), aTdi.iVid)); |
|
162 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL aTdi.iPid = %d" ), aTdi.iPid)); |
|
163 |
|
164 iAttachmentTimer->Cancel(); |
|
165 |
|
166 // check if an OTG device connected |
|
167 TOtgDescriptor otgDescriptor; |
|
168 |
|
169 // ignore all the errors, assume we connected to not otg |
|
170 TInt err = iWatcher->Usb().GetOtgDescriptor(aTdi.iDeviceId, otgDescriptor); |
|
171 |
|
172 TBool hnpSupported(otgDescriptor.iAttributes & EUsbOtgHNPSupported); |
|
173 TBool srpSupported(otgDescriptor.iAttributes & EUsbOtgSRPSupported); |
|
174 |
|
175 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL GetOtgDescriptor err = %d, HNP supported = %d, SRP supported = %d" ), err, hnpSupported, srpSupported)); |
|
176 |
|
177 // OTG device supports both hnp and srp |
|
178 if(hnpSupported && srpSupported) |
|
179 { |
|
180 |
|
181 HandleL(EUsbWatcherConnectedToOTG, EUsbStateHostHandle); |
|
182 return; |
|
183 } |
|
184 |
|
185 if (KErrNone != aTdi.iError) |
|
186 { |
|
187 switch (aTdi.iError) |
|
188 // error in attachement |
|
189 { |
|
190 case KErrBadPower: |
|
191 { |
|
192 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL TooMuchPower" ) ); |
|
193 HandleL(EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration, EUsbStateHostDelayHandle); |
|
194 break; |
|
195 } |
|
196 default: |
|
197 { |
|
198 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL AttachmentError" ) ); |
|
199 HandleL(EUsbWatcherErrUnsupportedDevice, EUsbStateHostHandle); |
|
200 break; |
|
201 } |
|
202 |
|
203 } |
|
204 |
|
205 return; |
|
206 } |
|
207 |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 void CUsbStateHostAInitiateBase::DriverLoadSuccessL(TDeviceEventInformation) |
|
215 { |
|
216 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DriverLoadSuccessL" ) ); |
|
217 ChangeHostStateL(EUsbStateHostAHost); |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 void CUsbStateHostAInitiateBase::DriverLoadPartialSuccessL( |
|
225 TDeviceEventInformation) |
|
226 { |
|
227 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DriverLoadPartialSuccessL" ) ); |
|
228 iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgWarning, |
|
229 EUsbOtgPartiallySupportedDevice, NULL); |
|
230 ChangeHostStateL(EUsbStateHostAHost); |
|
231 |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 void CUsbStateHostAInitiateBase::DriverLoadFailureL( |
|
239 TDeviceEventInformation aDei) |
|
240 { |
|
241 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DriverLoadFailureL" ) ); |
|
242 |
|
243 // try initiate to switch to mass storage |
|
244 /* if (KErrNone != iUsbPersonalitySwitch->SwitchPersonalityL(aDei.iDeviceId, |
|
245 KUsbPersonalityIdMS )) |
|
246 {*/ |
|
247 HandleL(EUsbWatcherErrDriversNotFound, EUsbStateHostDelayHandle); |
|
248 // } |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 void CUsbStateHostAInitiateBase::SrpReceivedL() |
|
256 { |
|
257 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::SrpReceivedL" ) ); |
|
258 if (CUsbVBusObserver::EVBusUp != iWatcher->VBusObserver()->VBus()) |
|
259 { |
|
260 TInt err = iWatcher->Usb().BusRespondSrp(); |
|
261 if (KErrNone != err) |
|
262 { |
|
263 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::SrpReceivedL BusRespondSrp error" ) ); |
|
264 iWatcher->HandleHostProblemL(EUsbWatcherErrorInConnection, EUsbStateHostHandle); |
|
265 } |
|
266 } |
|
267 } |
|
268 |
|
269 void CUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL( |
|
270 MUsbPersonalitySwitchObserver::TState aState, TInt aData) |
|
271 { |
|
272 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL aState = %d aData = %d" ), TInt(aState), aData)); |
|
273 |
|
274 switch (aState) |
|
275 { |
|
276 case ERequestingAllPersonalities: |
|
277 { |
|
278 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL ERequestingAllPersonalities" ) ); |
|
279 break; |
|
280 } |
|
281 case ERequestingSetPersonality: |
|
282 { |
|
283 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL ERequestingSetPersonality" ) ); |
|
284 break; |
|
285 } |
|
286 case EGetAllPersonalitiesCompleted: |
|
287 { |
|
288 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL EGetAllPersonalitiesCompleted" ) ); |
|
289 if (KErrNotFound == aData) |
|
290 { |
|
291 // no supported or needed personality/ies in the peripheral |
|
292 HandleL(EUsbWatcherErrDriversNotFound, EUsbStateHostDelayHandle); |
|
293 } |
|
294 break; |
|
295 } |
|
296 case ESetPersonalityCompleted: |
|
297 { |
|
298 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL ESetPersonalityCompleted" ) ); |
|
299 |
|
300 break; |
|
301 } |
|
302 case ERequestCancelled: |
|
303 { |
|
304 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL ERequestCancelled" ) ); |
|
305 break; |
|
306 } |
|
307 case ERequestFailed: |
|
308 { |
|
309 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL ERequestFailed" ) ); |
|
310 HandleL(EUsbWatcherErrDriversNotFound, EUsbStateHostDelayHandle); |
|
311 break; |
|
312 } |
|
313 default: |
|
314 { |
|
315 Panic(EUnexpectedUsbSwitchPersonalityState); |
|
316 } |
|
317 } |
|
318 } |
|