1 /* |
|
2 * Copyright (c) 2008 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 #include <e32base.h> |
|
19 #include <usbhosterrors.h> |
|
20 #include <d32otgdi_errors.h> |
|
21 #include <d32usbdi_errors.h> |
|
22 |
|
23 #include "cusbotgwatcher.h" |
|
24 #include "cusbstatehostabase.h" |
|
25 #include "cusbstatehosthandledropping.h" |
|
26 |
|
27 #include "errors.h" |
|
28 |
|
29 #include "debug.h" |
|
30 #include "panic.h" |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CUsbStateHostABase::CUsbStateHostABase(CUsbOtgWatcher& aWatcher) : |
|
37 CUsbState(aWatcher) |
|
38 { |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 void CUsbStateHostABase::ConstructL() |
|
46 { |
|
47 LOG_FUNC |
|
48 CUsbState::ConstructL(); |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CUsbStateHostABase::~CUsbStateHostABase() |
|
56 { |
|
57 LOG_FUNC |
|
58 } |
|
59 |
|
60 // From VBus observer |
|
61 // --------------------------------------------------------------------------- |
|
62 // VBus can be dropped by lower leyer in case of a critical problem |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 void CUsbStateHostABase::VBusDownL() |
|
66 { |
|
67 LOG_FUNC |
|
68 HandleL(EUsbWatcherErrorInConnection, EUsbStateHostHandleDropping); |
|
69 } |
|
70 |
|
71 // From OTG state observer |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void CUsbStateHostABase::AIdleL() |
|
77 { |
|
78 LOG_FUNC |
|
79 // do nothing |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CUsbStateHostABase::AHostL() |
|
87 { |
|
88 LOG_FUNC |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 void CUsbStateHostABase::APeripheralL() |
|
96 { |
|
97 LOG_FUNC |
|
98 ChangeHostStateL( EUsbStateHostAPeripheral); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CUsbStateHostABase::AVBusErrorL() |
|
106 { |
|
107 LOG_FUNC |
|
108 // No need to handle BusClearError error code, due to Bus will be dropped anyway |
|
109 iWatcher.Usb().BusClearError(); |
|
110 HandleL(EUsbWatcherErrDeviceRequiresTooMuchPower, |
|
111 EUsbStateHostHandleDropping); |
|
112 } |
|
113 |
|
114 // From bus activity observer |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CUsbStateHostABase::BusIdleL() |
|
120 { |
|
121 LOG_FUNC |
|
122 //do nothing |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CUsbStateHostABase::BusActiveL() |
|
130 { |
|
131 LOG_FUNC |
|
132 // do nothing |
|
133 } |
|
134 |
|
135 // From message notification observer |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 void CUsbStateHostABase::MessageNotificationReceivedL(TInt aMessage) |
|
141 { |
|
142 LOG_FUNC |
|
143 LOG1( "aMessage = %d" , aMessage); |
|
144 |
|
145 switch (aMessage) |
|
146 { |
|
147 |
|
148 // OTGDI |
|
149 case KErrUsbOtgStackNotStarted:// = -6680; |
|
150 case KErrUsbOtgHnpNotResponding:// = -6683; |
|
151 case KErrUsbOtgBusControlProblem:// = -6685; |
|
152 case KErrUsbOtgVbusPowerUpError:// = -6686; |
|
153 case KErrUsbOtgHnpEnableProblem:// = -6687; |
|
154 case KErrUsbOtgVbusError:// = -6690; |
|
155 |
|
156 // hosterrors.h |
|
157 case KErrUsbConfigurationHasNoInterfaces: |
|
158 case KErrUsbInterfaceCountMismatch: |
|
159 case KErrUsbDuplicateInterfaceNumbers: |
|
160 case KErrUsbBadDescriptor: |
|
161 case KErrUsbDeviceDetachedDuringDriverLoading: |
|
162 case KErrUsbAttachmentFailureGeneralError: |
|
163 { |
|
164 LOG( "ErrorInConnection" ); |
|
165 HandleL(EUsbWatcherErrorInConnection, EUsbStateHostHandleDropping); |
|
166 break; |
|
167 } |
|
168 |
|
169 // OTGDI |
|
170 case KErrUsbOtgPeriphNotSupported: // = -6688, for OPT only |
|
171 |
|
172 // USBDI |
|
173 case KErrUsbRequestsPending: |
|
174 case KErrUsbBadAddress: |
|
175 case KErrUsbNoAddress: |
|
176 case KErrUsbSetAddrFailed: |
|
177 case KErrUsbNoPower: |
|
178 case KErrUsbTooDeep: |
|
179 case KErrUsbIOError: |
|
180 case KErrUsbNotConfigured: |
|
181 case KErrUsbTimeout: |
|
182 case KErrUsbStalled: |
|
183 case KErrUsbTestFailure: |
|
184 case KErrUsbBadState: |
|
185 case KErrUsbDeviceSuspended: |
|
186 case KErrUsbBadDescriptorTopology: |
|
187 case KErrUsbDeviceRejected: |
|
188 case KErrUsbDeviceFailed: |
|
189 case KErrUsbBadDevice: // = -6656 |
|
190 case KErrUsbBadHub: |
|
191 case KErrUsbEventOverflow: |
|
192 case KErrUsbBadDeviceAttached: |
|
193 |
|
194 // hosterrors.h |
|
195 case KErrUsbUnsupportedDevice: |
|
196 { |
|
197 LOG( "UnsupportedDevice" ); |
|
198 HandleL(EUsbWatcherErrUnsupportedDevice, |
|
199 EUsbStateHostHandleDropping); |
|
200 break; |
|
201 } |
|
202 default: |
|
203 { |
|
204 LOG1( "Unhandled message = %d" , aMessage); |
|
205 break; |
|
206 } |
|
207 |
|
208 } |
|
209 |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 void CUsbStateHostABase::BadHubPositionL() |
|
217 { |
|
218 LOG_FUNC |
|
219 HandleL(EUsbWatcherHubsNotSupported, EUsbStateHostHandleDropping); |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 void CUsbStateHostABase::VBusErrorL() |
|
227 { |
|
228 LOG_FUNC |
|
229 // No error code handling after BusClearError call, due to bus will be dropped anyway |
|
230 iWatcher.Usb().BusClearError(); |
|
231 HandleL(EUsbWatcherErrDeviceRequiresTooMuchPower, |
|
232 EUsbStateHostHandleDropping); |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 void CUsbStateHostABase::SrpReceivedL() |
|
240 { |
|
241 LOG_FUNC |
|
242 |
|
243 if (iWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) |
|
244 { |
|
245 LOG( "Session is ongoing (VBus high); ignore SRP request." ); |
|
246 return; |
|
247 } |
|
248 |
|
249 TInt err = iWatcher.Usb().BusRespondSrp(); |
|
250 LOG1( "BusRespondSrp() error = %d" , err ); |
|
251 |
|
252 if (KErrNone != err && KErrUsbOtgVbusAlreadyRaised != err) |
|
253 { |
|
254 iWatcher.HandleHostProblemL(EUsbWatcherErrorInConnection, |
|
255 EUsbStateHostHandleDropping); |
|
256 } |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 void CUsbStateHostABase::SessionRequestedL() |
|
264 { |
|
265 LOG_FUNC |
|
266 |
|
267 if (iWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) |
|
268 { |
|
269 // session already ongoing; BusRequest() in this case returns KErrUsbOtgBadState... |
|
270 LOG( "Session is ongoing (VBus high); ignore Session Request." ); |
|
271 return; |
|
272 } |
|
273 |
|
274 TInt err = iWatcher.Usb().BusRequest(); |
|
275 LOG1( "BusRequest() err = %d" , err); |
|
276 |
|
277 if (KErrNone != err && KErrUsbOtgVbusAlreadyRaised != err) |
|
278 { |
|
279 iWatcher.HandleHostProblemL(EUsbWatcherErrorInConnection, |
|
280 EUsbStateHostHandleDropping); |
|
281 } |
|
282 } |
|