|
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); |
|
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 HandleL(EUsbWatcherConnectedToOTG); |
|
181 return; |
|
182 } |
|
183 |
|
184 if (KErrNone != aTdi.iError) |
|
185 { |
|
186 switch (aTdi.iError) |
|
187 // error in attachement |
|
188 { |
|
189 case KErrBadPower: |
|
190 { |
|
191 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL TooMuchPower" ) ); |
|
192 HandleL(EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration); |
|
193 break; |
|
194 } |
|
195 default: |
|
196 { |
|
197 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DeviceAttachedL AttachmentError" ) ); |
|
198 HandleL(EUsbWatcherErrUnsupportedDevice); |
|
199 break; |
|
200 } |
|
201 |
|
202 } |
|
203 |
|
204 return; |
|
205 } |
|
206 |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CUsbStateHostAInitiateBase::DriverLoadSuccessL(TDeviceEventInformation) |
|
214 { |
|
215 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DriverLoadSuccessL" ) ); |
|
216 ChangeHostStateL(EUsbStateHostAHost); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 void CUsbStateHostAInitiateBase::DriverLoadPartialSuccessL( |
|
224 TDeviceEventInformation) |
|
225 { |
|
226 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DriverLoadPartialSuccessL" ) ); |
|
227 iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgWarning, |
|
228 EUsbOtgPartiallySupportedDevice, NULL); |
|
229 ChangeHostStateL(EUsbStateHostAHost); |
|
230 |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 void CUsbStateHostAInitiateBase::DriverLoadFailureL( |
|
238 TDeviceEventInformation aDei) |
|
239 { |
|
240 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::DriverLoadFailureL" ) ); |
|
241 |
|
242 // try initiate to switch to mass storage |
|
243 /* if (KErrNone != iUsbPersonalitySwitch->SwitchPersonalityL(aDei.iDeviceId, |
|
244 KUsbPersonalityIdMS )) |
|
245 {*/ |
|
246 HandleL(EUsbWatcherErrDriversNotFound); |
|
247 // } |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 void CUsbStateHostAInitiateBase::SrpReceivedL() |
|
255 { |
|
256 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::SrpReceivedL" ) ); |
|
257 if (CUsbVBusObserver::EVBusUp != iWatcher->VBusObserver()->VBus()) |
|
258 { |
|
259 TInt err = iWatcher->Usb().BusRespondSrp(); |
|
260 if (KErrNone != err) |
|
261 { |
|
262 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::SrpReceivedL BusRespondSrp error" ) ); |
|
263 iWatcher->HandleHostProblemL(EUsbWatcherErrorInConnection); |
|
264 } |
|
265 } |
|
266 } |
|
267 |
|
268 void CUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL( |
|
269 MUsbPersonalitySwitchObserver::TState aState, TInt aData) |
|
270 { |
|
271 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL aState = %d aData = %d" ), TInt(aState), aData)); |
|
272 |
|
273 switch (aState) |
|
274 { |
|
275 case ERequestingAllPersonalities: |
|
276 { |
|
277 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL ERequestingAllPersonalities" ) ); |
|
278 break; |
|
279 } |
|
280 case ERequestingSetPersonality: |
|
281 { |
|
282 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL ERequestingSetPersonality" ) ); |
|
283 break; |
|
284 } |
|
285 case EGetAllPersonalitiesCompleted: |
|
286 { |
|
287 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL EGetAllPersonalitiesCompleted" ) ); |
|
288 if (KErrNotFound == aData) |
|
289 { |
|
290 // no supported or needed personality/ies in the peripheral |
|
291 HandleL(EUsbWatcherErrDriversNotFound); |
|
292 } |
|
293 break; |
|
294 } |
|
295 case ESetPersonalityCompleted: |
|
296 { |
|
297 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL ESetPersonalityCompleted" ) ); |
|
298 |
|
299 break; |
|
300 } |
|
301 case ERequestCancelled: |
|
302 { |
|
303 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL ERequestCancelled" ) ); |
|
304 break; |
|
305 } |
|
306 case ERequestFailed: |
|
307 { |
|
308 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiateBase::UsbPersonalitySwitchStateChangedL ERequestFailed" ) ); |
|
309 HandleL(EUsbWatcherErrDriversNotFound); |
|
310 break; |
|
311 } |
|
312 default: |
|
313 { |
|
314 Panic(EUnexpectedUsbSwitchPersonalityState); |
|
315 } |
|
316 } |
|
317 } |