|
1 /* |
|
2 * Copyright (c) 2010 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 <e32base.h> |
|
19 #include <e32cons.h> |
|
20 |
|
21 #ifndef __OVER_DUMMYUSBSCLDD__ |
|
22 #include <d32usbc.h>//EEndPoint2 |
|
23 #else |
|
24 #include <dummyusbsclddapi.h> |
|
25 #endif |
|
26 #include "ncmdatainterface.h" |
|
27 #include "ncmdatareceiver.h" |
|
28 #include "ncmdatasender.h" |
|
29 #include "OstTraceDefinitions.h" |
|
30 #ifdef OST_TRACE_COMPILER_IN_USE |
|
31 #include "ncmdatainterfaceTraces.h" |
|
32 #endif |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 const TInt KAltSetting1 = 1; |
|
38 const TInt KAltSetting0 = 0; |
|
39 |
|
40 |
|
41 CNcmDataInterface* CNcmDataInterface::NewL(MNcmDataObserver& aEngine, |
|
42 RDevUsbcScClient& aLdd) |
|
43 { |
|
44 CNcmDataInterface *self = new (ELeave) CNcmDataInterface(aEngine, aLdd); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CNcmDataInterface::CNcmDataInterface(MNcmDataObserver& aEngine, |
|
52 RDevUsbcScClient& aLdd) : |
|
53 CActive(CActive::EPriorityStandard), iEngine(aEngine), iLdd(aLdd) |
|
54 { |
|
55 CActiveScheduler::Add(this); |
|
56 } |
|
57 |
|
58 void CNcmDataInterface::ConstructL() |
|
59 { |
|
60 OstTraceFunctionEntry0(CNCMDATAINTERFACE_CONSTRUCTL); |
|
61 |
|
62 iReceiver = CNcmDataReceiver::NewL(iLdd, *this); |
|
63 iSender = CNcmDataSender::NewL(iLdd, *this); |
|
64 OstTraceFunctionExit0(CNCMDATAINTERFACE_CONSTRUCTL_DUP01); |
|
65 } |
|
66 |
|
67 CNcmDataInterface::~CNcmDataInterface() |
|
68 { |
|
69 OstTraceFunctionEntry0(CNCMDATAINTERFACE_CNCMDATAINTERFACE_DUP01); |
|
70 Cancel(); |
|
71 |
|
72 delete iReceiver; |
|
73 delete iSender; |
|
74 OstTraceFunctionExit0(CNCMDATAINTERFACE_CNCMDATAINTERFACE_DUP02); |
|
75 } |
|
76 |
|
77 /** |
|
78 Start the NCM data channel |
|
79 */ |
|
80 void CNcmDataInterface::Start() |
|
81 { |
|
82 OstTraceFunctionEntry0(CNCMDATAINTERFACE_START); |
|
83 if (!iStarted) |
|
84 { |
|
85 iReceiver->Start(); |
|
86 iSender->Start(); |
|
87 iStarted = ETrue; |
|
88 } |
|
89 OstTraceFunctionExit0(CNCMDATAINTERFACE_START_DUP01); |
|
90 } |
|
91 |
|
92 /** |
|
93 Stop the NCM data channel |
|
94 */ |
|
95 void CNcmDataInterface::Stop() |
|
96 { |
|
97 OstTraceFunctionEntry0(CNCMDATAINTERFACE_STOP); |
|
98 if (iStarted) |
|
99 { |
|
100 iReceiver->Stop(); |
|
101 iSender->Stop(); |
|
102 iStarted = EFalse; |
|
103 |
|
104 //after stop(). |
|
105 if (KAltSetting1 == iAltSetting) |
|
106 { |
|
107 |
|
108 iAltSetting = KAltSetting0; |
|
109 } |
|
110 } |
|
111 OstTraceFunctionExit0(CNCMDATAINTERFACE_STOP_DUP01); |
|
112 } |
|
113 |
|
114 /** |
|
115 Send packet data from upper link to NCM host |
|
116 */ |
|
117 TInt CNcmDataInterface::Send(RMBufChain &aPacket) |
|
118 { |
|
119 const TInt KContinue = 1; |
|
120 const TInt KStop = 0; |
|
121 |
|
122 TInt ret = iSender->Send(aPacket); |
|
123 if (ret == KErrNone) |
|
124 { |
|
125 return KContinue; |
|
126 } |
|
127 else if (ret == KErrNotReady || ret == KErrCongestion) |
|
128 { |
|
129 return KStop; |
|
130 } |
|
131 else |
|
132 { |
|
133 iEngine.DataError(ret); |
|
134 return KStop; |
|
135 } |
|
136 } |
|
137 |
|
138 /** |
|
139 * Acitve this AO to monitor the LDD's alt-setting changes. |
|
140 */ |
|
141 void CNcmDataInterface::ActivateLdd() |
|
142 { |
|
143 TInt alt = 0; |
|
144 TInt ret = KErrNone; |
|
145 |
|
146 ret = iLdd.GetAlternateSetting(alt); |
|
147 OstTraceExt2(TRACE_NORMAL, CNCMDATAINTERFACE_ACTIVATELDD, "ActivateLDD:alt=%d, ret=%d", alt, ret); |
|
148 |
|
149 if (KErrNone == ret) |
|
150 { |
|
151 if (iAltSetting == alt) |
|
152 { |
|
153 iLdd.AlternateDeviceStatusNotify(iStatus, iIfState); |
|
154 SetActive(); |
|
155 } |
|
156 else |
|
157 { |
|
158 TRequestStatus* status = &iStatus; |
|
159 iStatus = KRequestPending; |
|
160 iIfState = KUsbAlternateSetting | alt; |
|
161 SetActive(); |
|
162 |
|
163 User::RequestComplete(status, KErrNone); |
|
164 } |
|
165 } |
|
166 else |
|
167 { |
|
168 //It's possible when Usb Device Status is not configed. |
|
169 iLdd.AlternateDeviceStatusNotify(iStatus, iIfState); |
|
170 SetActive(); |
|
171 } |
|
172 } |
|
173 |
|
174 void CNcmDataInterface::RunL() |
|
175 { |
|
176 OstTraceExt2(TRACE_NORMAL, CNCMDATAINTERFACE_RUNL, "State=%x, status=%d", iIfState, iStatus.Int()); |
|
177 |
|
178 if (KErrNone == iStatus.Int()) |
|
179 { |
|
180 iLdd.AlternateDeviceStatusNotify(iStatus, iIfState); |
|
181 SetActive(); |
|
182 |
|
183 if (iIfState & KUsbAlternateSetting) |
|
184 { |
|
185 TInt ret = KErrNone; |
|
186 iAltSetting = iIfState & ~KUsbAlternateSetting; |
|
187 |
|
188 if (KAltSetting1 == iAltSetting) |
|
189 { |
|
190 ret = iLdd.StartNextOutAlternateSetting(ETrue); |
|
191 if (KAltSetting1 == ret) |
|
192 { |
|
193 iEngine.HandleAltSetting(iAltSetting); |
|
194 } |
|
195 else |
|
196 { |
|
197 iEngine.DataError(ret); |
|
198 } |
|
199 } |
|
200 else |
|
201 { |
|
202 iEngine.HandleAltSetting(iAltSetting); |
|
203 ret = iLdd.StartNextOutAlternateSetting(ETrue); |
|
204 if (KAltSetting0 != ret) |
|
205 { |
|
206 iEngine.DataError(ret); |
|
207 } |
|
208 } |
|
209 } |
|
210 } |
|
211 else |
|
212 { |
|
213 iEngine.DataError(iStatus.Int()); |
|
214 } |
|
215 } |
|
216 |
|
217 /** |
|
218 * AO cancel. |
|
219 */ |
|
220 void CNcmDataInterface::DoCancel() |
|
221 { |
|
222 iLdd.AlternateDeviceStatusNotifyCancel(); |
|
223 } |
|
224 |
|
225 |
|
226 /** |
|
227 * Get Connection Speed. (NB. Upstream's is the same as downstream's). |
|
228 */ |
|
229 TInt CNcmDataInterface::GetSpeed(TInt& aSpeed) |
|
230 { |
|
231 const TInt KHighSpeed = 480 * 1024 * 1024; |
|
232 const TInt KFullSpeed = 12 * 1024 * 1024; |
|
233 |
|
234 if (iLdd.CurrentlyUsingHighSpeed()) |
|
235 { |
|
236 aSpeed = KHighSpeed; |
|
237 } |
|
238 else |
|
239 { |
|
240 aSpeed = KFullSpeed; |
|
241 } |
|
242 |
|
243 return KErrNone; |
|
244 |
|
245 } |
|
246 /** |
|
247 * Get Ntb Input Size. |
|
248 */ |
|
249 TInt CNcmDataInterface::GetNtbInputSize(TDes8& aSize) |
|
250 { |
|
251 const TUint KNtbIntputSizeLength = 4; |
|
252 aSize.SetLength(KNtbIntputSizeLength); |
|
253 LittleEndian::Put32(&aSize[0], iSender->NtbInMaxSize()); |
|
254 return KErrNone; |
|
255 } |
|
256 |
|
257 /** |
|
258 * Set Ntb Input Size. |
|
259 */ |
|
260 TInt CNcmDataInterface::SetNtbInputSize(TDesC8& aSize) |
|
261 { |
|
262 TInt size = LittleEndian::Get32(aSize.Ptr()); |
|
263 return iSender->SetNtbInMaxSize(size, KAltSetting0==iAltSetting); |
|
264 } |
|
265 |
|
266 /** |
|
267 * Get Ntb Parameter. |
|
268 */ |
|
269 TInt CNcmDataInterface::GetNtbParam(TDes8& aParamBuf) |
|
270 { |
|
271 TNcmNtbInParam param; |
|
272 |
|
273 iSender->GetNtbParam(param); |
|
274 |
|
275 const TUint32 KNtbParamLength = 0x001C; |
|
276 const TUint32 KNtbFormat = 0x0001; |
|
277 const TUint KNtbParamLengthOffset = 0; //0 |
|
278 const TUint KNtbFormatOffset = KNtbParamLengthOffset + 2; //2 |
|
279 const TUint KNtbInMaxSizeOffset = KNtbFormatOffset + 2; //4 |
|
280 const TUint KNtbInDivisorOffset = KNtbInMaxSizeOffset + 4; //8 |
|
281 const TUint KNtbInPayloadRemainderOffset = KNtbInDivisorOffset + 2; //10 |
|
282 const TUint KNtbInAlignmentOffset = KNtbInPayloadRemainderOffset + 2;//12 |
|
283 const TUint KNtbOutMaxSizeOffset = KNtbInAlignmentOffset + 4; //16 |
|
284 const TUint KNtbOutDivisorOffset = KNtbOutMaxSizeOffset + 4; //20 |
|
285 const TUint KNtbOutPayloadRemainderOffset = KNtbOutDivisorOffset + 2;//22 |
|
286 const TUint KNtbOutAlignmentOffset = KNtbOutPayloadRemainderOffset + 2;//24 |
|
287 |
|
288 aParamBuf.FillZ(KNtbParamLength); |
|
289 LittleEndian::Put16(&aParamBuf[KNtbParamLengthOffset], KNtbParamLength); |
|
290 LittleEndian::Put16(&aParamBuf[KNtbFormatOffset], KNtbFormat); |
|
291 LittleEndian::Put32(&aParamBuf[KNtbInMaxSizeOffset], param.iNtbInMaxSize); |
|
292 LittleEndian::Put16(&aParamBuf[KNtbInDivisorOffset], param.iNdpInDivisor); |
|
293 LittleEndian::Put16(&aParamBuf[KNtbInPayloadRemainderOffset], param.iNdpInPayloadRemainder); |
|
294 LittleEndian::Put16(&aParamBuf[KNtbInAlignmentOffset], param.iNdpInAlignment); |
|
295 |
|
296 //Tricky way: copy the Sender's parameter as the Receiver's. |
|
297 LittleEndian::Put32(&aParamBuf[KNtbOutMaxSizeOffset], iReceiver->NtbOutMaxSize()); |
|
298 LittleEndian::Put16(&aParamBuf[KNtbOutDivisorOffset], param.iNdpInDivisor); |
|
299 LittleEndian::Put16(&aParamBuf[KNtbOutPayloadRemainderOffset], param.iNdpInPayloadRemainder); |
|
300 LittleEndian::Put16(&aParamBuf[KNtbOutAlignmentOffset], param.iNdpInAlignment); |
|
301 |
|
302 return KErrNone; |
|
303 } |
|
304 |
|
305 TInt CNcmDataInterface::SetInEpBufferSize(TUint aSize) |
|
306 { |
|
307 return iSender->SetInEpBufferSize(aSize); |
|
308 } |
|
309 |