28
|
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 |
/**
|
|
19 |
* @file
|
|
20 |
* @internalComponent
|
|
21 |
*/
|
|
22 |
|
|
23 |
#include "ncmclientmanager.h"
|
|
24 |
|
|
25 |
|
|
26 |
#ifdef OVERDUMMY_NCMCC
|
|
27 |
#include <usb/testncmcc/dummy_ncminternalsrv.h>
|
|
28 |
#else
|
|
29 |
#include "ncminternalsrv.h"
|
|
30 |
#endif // OVERDUMMY_NCMCC
|
|
31 |
|
|
32 |
#include "ncmclassdescriptor.h"
|
|
33 |
// For OST tracing
|
|
34 |
#include "OstTraceDefinitions.h"
|
|
35 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
36 |
#include "ncmclientmanagerTraces.h"
|
|
37 |
#endif
|
|
38 |
|
|
39 |
|
|
40 |
// NCM Interface MTU size
|
|
41 |
extern const TUint KEthernetFrameSize;
|
|
42 |
|
|
43 |
// NCM MAC Address String descriptor buffer length
|
|
44 |
const TUint KMacAddrStringDescSize = 32;
|
|
45 |
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Construtor
|
|
49 |
* @param aMacAddress the NCM ethernet interface MAC address
|
|
50 |
*/
|
|
51 |
CNcmClientManager::CNcmClientManager(const TNcmMacAddress& aHostMacAddress):
|
|
52 |
iHostMacAddress(aHostMacAddress)
|
|
53 |
{
|
|
54 |
OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_ENTRY, this );
|
|
55 |
|
|
56 |
// No implementation required
|
|
57 |
OstTraceFunctionExit1( CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_EXIT, this );
|
|
58 |
}
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Destructor
|
|
62 |
*/
|
|
63 |
CNcmClientManager::~CNcmClientManager()
|
|
64 |
{
|
|
65 |
OstTraceFunctionEntry0( CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_ENTRY_DESTRUCTOR );
|
|
66 |
|
|
67 |
TInt err = KErrNone;
|
|
68 |
if (iCommLddInitiated)
|
|
69 |
{
|
|
70 |
RChunk* commChunk = NULL;
|
|
71 |
OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_PRE_CLOSE_COMM_INTERFACE, "About to get chunk handle for communication interface!");
|
|
72 |
err = iCommLdd.GetDataTransferChunk(commChunk);
|
|
73 |
if (KErrNone == err)
|
|
74 |
{
|
|
75 |
OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_COMM_CHUNK, "About to close chunk handle for communication interface!");
|
|
76 |
commChunk->Close();
|
|
77 |
}
|
|
78 |
else
|
|
79 |
{
|
|
80 |
OstTrace1(TRACE_ERROR, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_COMM_CHUNK_FAIL, "Can not get chunk handle for communication interface: err = %d", err);
|
|
81 |
}
|
|
82 |
|
|
83 |
OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_COMM_INTERFACE, "About to close device handle for communication interface!");
|
|
84 |
iCommLdd.Close();
|
|
85 |
}
|
|
86 |
|
|
87 |
if (iDataLddInitiated)
|
|
88 |
{
|
|
89 |
RChunk* dataChunk = NULL;
|
|
90 |
OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_PRE_CLOSE_DATA_INTERFACE, "About to get chunk handle for data interface!");
|
|
91 |
err = iDataLdd.GetDataTransferChunk(dataChunk);
|
|
92 |
if (KErrNone == err)
|
|
93 |
{
|
|
94 |
OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_DATA_CHUNK, "About to close chunk handle for communication interface!");
|
|
95 |
dataChunk->Close();
|
|
96 |
}
|
|
97 |
else
|
|
98 |
{
|
|
99 |
OstTrace1(TRACE_ERROR, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_DATA_CHUNK_FAIL, "Can not get chunk handle for data interface: err = %d", err);
|
|
100 |
}
|
|
101 |
|
|
102 |
OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_DATA_INTERFACE, "About to close device handle for data interface!");
|
|
103 |
iDataLdd.Close();
|
|
104 |
}
|
|
105 |
OstTraceFunctionExit0( CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_ENTRY_DESTRUCTOR_EXIT );
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
/**
|
|
110 |
* Setup NCM interfaces
|
|
111 |
* @param[out] aDataEpBufferSize, NCM data interface EP buffer size
|
|
112 |
*/
|
|
113 |
void CNcmClientManager::SetNcmInterfacesL(TUint& aDataEpBufferSize)
|
|
114 |
{
|
|
115 |
OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_SETNCMINTERFACESL_ENTRY, this );
|
|
116 |
|
|
117 |
// Setup NCM communication interface
|
|
118 |
SetCommunicationInterfaceL();
|
|
119 |
|
|
120 |
// Setup NCM data interface
|
|
121 |
SetDataInterfaceL(aDataEpBufferSize);
|
|
122 |
|
49
|
123 |
// Retrieve Control interface number(alter 0)
|
|
124 |
TUint8 controlInterfaceNumber = 0;
|
|
125 |
User::LeaveIfError(InterfaceNumber(iCommLdd,0,controlInterfaceNumber));
|
|
126 |
|
|
127 |
// Retrieve data interface number(alter 0)
|
|
128 |
TUint8 dataInterfaceNumber = 0;
|
|
129 |
User::LeaveIfError(InterfaceNumber(iDataLdd,0,dataInterfaceNumber));
|
28
|
130 |
|
|
131 |
// Setup NCM class descriptor with correct interface number
|
49
|
132 |
User::LeaveIfError(SetupClassSpecificDescriptor(controlInterfaceNumber,dataInterfaceNumber));
|
28
|
133 |
OstTraceFunctionExit1( CNCMCLIENTMANAGER_SETNCMINTERFACESL_EXIT, this );
|
|
134 |
}
|
|
135 |
|
|
136 |
/**
|
|
137 |
* Transfer NCM interface handlers from NCM class controller to NCM
|
|
138 |
* packet driver through NCM internal server.
|
|
139 |
* @param aServer a reference to RNcmInternalSrv
|
|
140 |
*/
|
|
141 |
void CNcmClientManager::TransferInterfacesL(RNcmInternalSrv& aServer)
|
|
142 |
{
|
|
143 |
OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_TRANSFERINTERFACESL_ENTRY, this );
|
|
144 |
|
|
145 |
RChunk* commChunk = NULL;
|
|
146 |
RChunk* dataChunk = NULL;
|
|
147 |
|
|
148 |
OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_TRANSFERINTERFACESL_PRE_TRANSFER_INTERFACES, "About to Transfer handles to NCM internal server!");
|
|
149 |
User::LeaveIfError(iCommLdd.GetDataTransferChunk(commChunk));
|
|
150 |
User::LeaveIfError(iDataLdd.GetDataTransferChunk(dataChunk));
|
|
151 |
User::LeaveIfError(aServer.TransferHandle(iCommLdd, *commChunk,
|
|
152 |
iDataLdd, *dataChunk));
|
|
153 |
OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_TRANSFERINTERFACESL_INTERFACES_TRANSFERED, "Transfer handles to NCM internal server Done!");
|
|
154 |
OstTraceFunctionExit1( CNCMCLIENTMANAGER_TRANSFERINTERFACESL_EXIT, this );
|
|
155 |
}
|
|
156 |
|
|
157 |
/**
|
|
158 |
* Setup NCM communication inteface
|
|
159 |
*/
|
|
160 |
void CNcmClientManager::SetCommunicationInterfaceL()
|
|
161 |
{
|
|
162 |
OstTraceFunctionEntry1( CNCMCLIENTMANAGER_SETCOMMUNICATIONINTERFACEL_ENTRY, this );
|
|
163 |
|
|
164 |
User::LeaveIfError(iCommLdd.Open(0));
|
|
165 |
iCommLddInitiated = ETrue;
|
|
166 |
|
|
167 |
TInt err = KErrNone;
|
|
168 |
|
|
169 |
TUsbcScInterfaceInfoBuf ifc0;
|
|
170 |
TUsbcDeviceState deviceStatus;
|
|
171 |
|
|
172 |
User::LeaveIfError(iCommLdd.DeviceStatus(deviceStatus));
|
|
173 |
|
|
174 |
if (deviceStatus == EUsbcDeviceStateConfigured)
|
|
175 |
{
|
|
176 |
User::Leave( KErrInUse);
|
|
177 |
}
|
|
178 |
|
|
179 |
TUsbDeviceCaps dCaps;
|
|
180 |
User::LeaveIfError(iCommLdd.DeviceCaps(dCaps));
|
|
181 |
|
|
182 |
TInt epNum = dCaps().iTotalEndpoints;
|
|
183 |
|
|
184 |
TUsbcEndpointData data[KUsbcMaxEndpoints];
|
|
185 |
TPtr8 dataptr(reinterpret_cast<TUint8*> (data), sizeof(data),
|
|
186 |
sizeof(data));
|
|
187 |
|
|
188 |
User::LeaveIfError(iCommLdd.EndpointCaps(dataptr));
|
|
189 |
|
|
190 |
TBool foundIntIN = EFalse;
|
39
|
191 |
const TUint KEndPointType = KUsbEpTypeInterrupt | KUsbEpDirIn;
|
28
|
192 |
for (TInt i = 0; i < epNum; i++)
|
|
193 |
{
|
39
|
194 |
const TUsbcEndpointData* epData = &data[i];
|
|
195 |
if ((!epData->iInUse) && // Not in use
|
|
196 |
((epData->iCaps.iTypesAndDir & KEndPointType) == KEndPointType))
|
28
|
197 |
{
|
|
198 |
// EEndpoint1 is going to be our INTERRUPT (IN, write) endpoint
|
|
199 |
ifc0().iEndpointData[0].iType = KUsbEpTypeInterrupt;
|
|
200 |
ifc0().iEndpointData[0].iDir = KUsbEpDirIn;
|
39
|
201 |
ifc0().iEndpointData[0].iSize = epData->iCaps.MinPacketSize();
|
28
|
202 |
ifc0().iEndpointData[0].iInterval = 0x01;
|
|
203 |
ifc0().iEndpointData[0].iInterval_Hs = 0x01;
|
|
204 |
|
|
205 |
foundIntIN = ETrue;
|
|
206 |
break;
|
|
207 |
}
|
|
208 |
}
|
|
209 |
if (EFalse == foundIntIN)
|
|
210 |
{
|
|
211 |
OstTrace0( TRACE_ERROR, CNCMCLIENTMANAGER_SETCOMMUNICATIONINTERFACEL, "Can not find proper endpint for NCM communication interface" );
|
|
212 |
User::Leave( KErrNotFound);
|
|
213 |
}
|
|
214 |
|
|
215 |
/*********************************************************************************************/
|
|
216 |
//Communication Class Interface (0x00)
|
|
217 |
/*********************************************************************************************/
|
|
218 |
_LIT16(KIfClassName0, "USB Networking (NCM)");
|
|
219 |
HBufC16* string0 = KIfClassName0().AllocLC();
|
|
220 |
|
|
221 |
ifc0().iString = string0;
|
|
222 |
ifc0().iTotalEndpointsUsed = 1;
|
|
223 |
ifc0().iClass.iClassNum = 0x02;
|
|
224 |
ifc0().iClass.iSubClassNum = 0x0D;
|
|
225 |
ifc0().iClass.iProtocolNum = 0x00;
|
|
226 |
|
|
227 |
User::LeaveIfError(iCommLdd.SetInterface(0, ifc0));
|
|
228 |
|
|
229 |
err = iCommLdd.FinalizeInterface();
|
|
230 |
if (KErrNone != err)
|
|
231 |
{
|
|
232 |
OstTrace1(TRACE_ERROR, CNCMCLIENTMANAGER_SETCOMMUNICATIONINTERFACEL_FAIL_TO_INIT, "Failed to FinalizeInterface, err %d", err);
|
|
233 |
User::Leave(err);
|
|
234 |
}
|
|
235 |
CleanupStack::PopAndDestroy(string0);
|
|
236 |
OstTraceFunctionExit1( CNCMCLIENTMANAGER_SETCOMMUNICATIONINTERFACEL_EXIT, this );
|
|
237 |
}
|
|
238 |
|
|
239 |
/**
|
|
240 |
* Setup NCM data interface
|
|
241 |
* @param aDataEpBufferSize, the determined data interface
|
|
242 |
* endpoint buffer size.
|
|
243 |
*/
|
|
244 |
void CNcmClientManager::SetDataInterfaceL(TUint& aDataEpBufferSize)
|
|
245 |
{
|
|
246 |
OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_SETDATAINTERFACEL_ENTRY, this );
|
|
247 |
|
|
248 |
const TUint KMaxScBufferSize = 1048576; // Up limit of end point buffer
|
|
249 |
const TUint KMinScBufferSize = 262144; // Lower limit of end point buffer
|
|
250 |
const TUint KMaxScReadSize = 65536;
|
|
251 |
|
|
252 |
User::LeaveIfError(iDataLdd.Open(0));
|
|
253 |
iDataLddInitiated = ETrue;
|
|
254 |
|
|
255 |
TUsbcScInterfaceInfoBuf ifc0, ifc1;
|
|
256 |
TUsbDeviceCaps dCaps;
|
|
257 |
User::LeaveIfError(iDataLdd.DeviceCaps(dCaps));
|
|
258 |
|
|
259 |
TBool isResourceAllocationV2 = ((dCaps().iFeatureWord1
|
|
260 |
& KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) != 0);
|
|
261 |
|
|
262 |
TUsbcDeviceState deviceStatus;
|
|
263 |
|
|
264 |
User::LeaveIfError(iDataLdd.DeviceStatus(deviceStatus));
|
|
265 |
if (deviceStatus == EUsbcDeviceStateConfigured)
|
|
266 |
{
|
|
267 |
User::Leave(KErrInUse);
|
|
268 |
}
|
|
269 |
|
|
270 |
TInt epNum = dCaps().iTotalEndpoints;
|
|
271 |
TUsbcEndpointData data[KUsbcMaxEndpoints];
|
|
272 |
TPtr8 dataptr(reinterpret_cast<TUint8*> (data), sizeof(data),
|
|
273 |
sizeof(data));
|
|
274 |
|
|
275 |
User::LeaveIfError(iDataLdd.EndpointCaps(dataptr));
|
|
276 |
|
|
277 |
const TUint KNcmDataInterfaceEpNumber = 2;
|
|
278 |
TBool foundBulkIN = EFalse;
|
|
279 |
TBool foundBulkOUT = EFalse;
|
|
280 |
TInt maxPacketSize = 0;
|
39
|
281 |
const TUint KEndPointBulkInType = KUsbEpTypeBulk | KUsbEpDirIn;
|
|
282 |
const TUint KEndPointBulkOutType = KUsbEpTypeBulk | KUsbEpDirOut;
|
28
|
283 |
for (TInt i = 0; i < epNum; i++)
|
|
284 |
{
|
39
|
285 |
const TUsbcEndpointData* epData = &data[i];
|
|
286 |
|
|
287 |
// Check if this endpoint is in use
|
|
288 |
if (epData->iInUse)
|
|
289 |
{
|
|
290 |
continue;
|
|
291 |
}
|
|
292 |
|
|
293 |
maxPacketSize = epData->iCaps.MaxPacketSize();
|
|
294 |
if (!foundBulkIN &&
|
|
295 |
((epData->iCaps.iTypesAndDir & KEndPointBulkInType) == KEndPointBulkInType))
|
28
|
296 |
{
|
|
297 |
// EEndpoint1 is going to be our TX (IN, write) endpoint
|
|
298 |
ifc1().iEndpointData[0].iType = KUsbEpTypeBulk;
|
|
299 |
ifc1().iEndpointData[0].iDir = KUsbEpDirIn;
|
|
300 |
ifc1().iEndpointData[0].iSize = maxPacketSize;
|
39
|
301 |
ifc1().iEndpointData[0].iInterval_Hs = 0x0;
|
28
|
302 |
ifc1().iEndpointData[0].iBufferSize = KMaxScBufferSize;
|
|
303 |
|
|
304 |
if (isResourceAllocationV2)
|
|
305 |
{
|
|
306 |
ifc1().iEndpointData[0].iFeatureWord1 |=
|
|
307 |
(KUsbcEndpointInfoFeatureWord1_DMA | KUsbcEndpointInfoFeatureWord1_DoubleBuffering);
|
|
308 |
}
|
|
309 |
|
|
310 |
foundBulkIN = ETrue;
|
|
311 |
if (foundBulkIN && foundBulkOUT)
|
|
312 |
{
|
|
313 |
break;
|
|
314 |
}
|
|
315 |
continue;
|
|
316 |
}
|
|
317 |
|
39
|
318 |
if (!foundBulkOUT &&
|
|
319 |
((epData->iCaps.iTypesAndDir & KEndPointBulkOutType) == KEndPointBulkOutType))
|
28
|
320 |
{
|
|
321 |
// EEndpoint2 is going to be our RX (OUT, read) endpoint
|
|
322 |
ifc1().iEndpointData[1].iType = KUsbEpTypeBulk;
|
|
323 |
ifc1().iEndpointData[1].iDir = KUsbEpDirOut;
|
|
324 |
ifc1().iEndpointData[1].iSize = maxPacketSize;
|
39
|
325 |
ifc1().iEndpointData[1].iInterval_Hs = 0x1;
|
28
|
326 |
ifc1().iEndpointData[1].iBufferSize = KMaxScBufferSize;
|
|
327 |
ifc1().iEndpointData[1].iReadSize = KMaxScReadSize;
|
|
328 |
|
|
329 |
if (isResourceAllocationV2)
|
|
330 |
{
|
|
331 |
ifc1().iEndpointData[1].iFeatureWord1 |=
|
|
332 |
(KUsbcEndpointInfoFeatureWord1_DMA | KUsbcEndpointInfoFeatureWord1_DoubleBuffering);
|
|
333 |
}
|
|
334 |
|
|
335 |
foundBulkOUT = ETrue;
|
|
336 |
if (foundBulkIN && foundBulkOUT)
|
|
337 |
{
|
|
338 |
break;
|
|
339 |
}
|
|
340 |
continue;
|
|
341 |
}
|
|
342 |
}
|
|
343 |
|
|
344 |
// Leave if no properly endpoint is found
|
|
345 |
if (EFalse == foundBulkIN || EFalse == foundBulkOUT)
|
|
346 |
{
|
|
347 |
User::Leave(KErrNotFound);
|
|
348 |
}
|
|
349 |
|
|
350 |
_LIT16(KIfClassName0, "NCM Data Interface 0");
|
|
351 |
|
|
352 |
HBufC16* string0 = KIfClassName0().AllocL();
|
|
353 |
CleanupStack::PushL(string0);
|
|
354 |
ifc0().iString = string0;
|
|
355 |
ifc0().iTotalEndpointsUsed = 0;
|
|
356 |
ifc0().iClass.iClassNum = 0x0A;
|
|
357 |
ifc0().iClass.iSubClassNum = 0x00;
|
|
358 |
ifc0().iClass.iProtocolNum = 0x01;
|
|
359 |
User::LeaveIfError(iDataLdd.SetInterface(0, ifc0));
|
|
360 |
|
|
361 |
_LIT16(KIfClassName1, "NCM Data Interface 1");
|
|
362 |
HBufC16* string1 = KIfClassName1().AllocL();
|
|
363 |
CleanupStack::PushL(string1);
|
|
364 |
ifc1().iString = string1;
|
|
365 |
ifc1().iTotalEndpointsUsed = KNcmDataInterfaceEpNumber;
|
|
366 |
ifc1().iClass.iClassNum = 0x0A;
|
|
367 |
ifc1().iClass.iSubClassNum = 0x00;
|
|
368 |
ifc1().iClass.iProtocolNum = 0x01;
|
|
369 |
|
|
370 |
// Try to allocate expected memory for data interface endpoints
|
|
371 |
aDataEpBufferSize = KMaxScBufferSize;
|
|
372 |
|
|
373 |
TInt err = KErrNone;
|
|
374 |
FOREVER
|
|
375 |
{
|
|
376 |
OstTrace1(TRACE_NORMAL, CNCMCLIENTMANAGER_SETDATAINTERFACEL_TRY_NEW_BUF_SIZE, "Try buffer size: %d", aDataEpBufferSize);
|
|
377 |
err = iDataLdd.SetInterface(1, ifc1);
|
|
378 |
if (KErrNoMemory == err)
|
|
379 |
{
|
|
380 |
// Reduce buffer size and retry
|
|
381 |
aDataEpBufferSize = aDataEpBufferSize / 2;
|
|
382 |
if (aDataEpBufferSize < KMinScBufferSize)
|
|
383 |
{
|
|
384 |
User::Leave(KErrNoMemory);
|
|
385 |
}
|
|
386 |
ifc1().iEndpointData[0].iBufferSize = aDataEpBufferSize;
|
|
387 |
ifc1().iEndpointData[1].iBufferSize = aDataEpBufferSize;
|
|
388 |
continue;
|
|
389 |
}
|
|
390 |
else
|
|
391 |
{
|
|
392 |
OstTrace1(TRACE_ERROR, CNCMCLIENTMANAGER_SETDATAINTERFACEL_SET_INTERFACE_FAIL, "Set data interface and the returned err code is %d", err);
|
|
393 |
// Leave with error code
|
|
394 |
User::LeaveIfError(err);
|
|
395 |
break;
|
|
396 |
}
|
|
397 |
}
|
|
398 |
|
|
399 |
CleanupStack::PopAndDestroy(2, string0);
|
|
400 |
|
|
401 |
User::LeaveIfError(iDataLdd.FinalizeInterface());
|
|
402 |
OstTraceFunctionExit1( CNCMCLIENTMANAGER_SETDATAINTERFACEL_EXIT, this );
|
|
403 |
}
|
|
404 |
|
|
405 |
/**
|
|
406 |
* Setup the Class Descriptors
|
|
407 |
* @param aDataInterfaceNumber The interface number of the data class
|
|
408 |
* @return Error.
|
|
409 |
*/
|
49
|
410 |
TInt CNcmClientManager::SetupClassSpecificDescriptor(TUint8 aControlInterfaceNumber,TUint8 aDataInterfaceNumber)
|
28
|
411 |
{
|
|
412 |
OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_SETUPCLASSSPECIFICDESCRIPTOR_ENTRY, this );
|
|
413 |
|
|
414 |
TInt res;
|
|
415 |
|
|
416 |
TNcmClassDescriptor descriptor;
|
|
417 |
|
|
418 |
// Header Functional Descriptor- CDC spec table 15
|
|
419 |
descriptor.iHdrSize = 0x05;
|
|
420 |
descriptor.iHdrType = 0x24;
|
|
421 |
descriptor.iHdrSubType = 0x00;
|
|
422 |
descriptor.iHdrBcdCDC = 0x0120;
|
|
423 |
|
|
424 |
// Ethernet Networking Functional Descriptor- ECM spec table 3
|
|
425 |
descriptor.iEthFunLength = 0x0D;
|
|
426 |
descriptor.iEthFunType = 0x24;
|
|
427 |
descriptor.iEthFunSubtype = 0x0F;
|
|
428 |
|
|
429 |
// Generate the MAC address new NCM interface
|
|
430 |
res = SetMacAddressString(descriptor.iMACAddress);
|
|
431 |
|
|
432 |
if (res != KErrNone)
|
|
433 |
{
|
|
434 |
OstTraceFunctionExitExt( CNCMCLIENTMANAGER_SETUPCLASSSPECIFICDESCRIPTOR_EXIT, this, res );
|
|
435 |
return res;
|
|
436 |
}
|
|
437 |
|
|
438 |
descriptor.iEthernetStatistics = 0;
|
|
439 |
descriptor.iMaxSegmentSize = KEthernetFrameSize;
|
|
440 |
descriptor.iNumberMCFilters = 0;
|
|
441 |
descriptor.iNumberPowerFilters = 0;
|
|
442 |
|
|
443 |
// NCM Functional Descriptor- NCM spec table 5-2
|
|
444 |
descriptor.iNcmFunLength = 0x06;
|
|
445 |
descriptor.iNcmFunType = 0x24;
|
|
446 |
descriptor.iNcmFunSubtype = 0x1A;
|
|
447 |
descriptor.iNcmVersion = 0x0100;
|
|
448 |
descriptor.iNetworkCapabilities = 0;
|
|
449 |
|
|
450 |
// Union functional descriptor- CDC spec table 16
|
|
451 |
descriptor.iUnSize = 0x05;
|
|
452 |
descriptor.iUnType = 0x24;
|
|
453 |
descriptor.iUnSubType = 0x06;
|
49
|
454 |
descriptor.iUnMasterInterface = aControlInterfaceNumber;
|
28
|
455 |
descriptor.iUnSlaveInterface = aDataInterfaceNumber;
|
|
456 |
|
|
457 |
OstTrace0( TRACE_NORMAL, CNCMCLIENTMANAGER_SETUPCLASSSPECIFICDESCRIPTOR_PRE_SET_BLOCK, "About to call SetCSInterfaceDescriptorBlock" );
|
|
458 |
res = iCommLdd.SetCSInterfaceDescriptorBlock(0, descriptor.Des());
|
|
459 |
if (res != KErrNone)
|
|
460 |
{
|
|
461 |
OstTraceFunctionExitExt( CNCMCLIENTMANAGER_SETUPCLASSSPECIFICDESCRIPTOR_EXIT_DUP1, this, res );
|
|
462 |
return res;
|
|
463 |
}
|
|
464 |
|
|
465 |
OstTraceFunctionExitExt( CNCMCLIENTMANAGER_SETUPCLASSSPECIFICDESCRIPTOR_EXIT_DUP2, this, KErrNone );
|
|
466 |
return KErrNone;
|
|
467 |
}
|
|
468 |
|
|
469 |
/**
|
|
470 |
* Set the MAC address string in descriptor
|
|
471 |
* @param aStrIndex the MAC address string index
|
|
472 |
*/
|
|
473 |
TInt CNcmClientManager::SetMacAddressString(TUint8& aStrIndex)
|
|
474 |
{
|
|
475 |
OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_SETMACADDRESSSTRING_ENTRY, this );
|
|
476 |
|
|
477 |
TBuf16<KMacAddrStringDescSize> str;
|
|
478 |
|
|
479 |
// Search for MAC address string from index 0x10
|
|
480 |
aStrIndex = 0x10;
|
|
481 |
|
|
482 |
TInt ret = KErrNone;
|
|
483 |
#ifndef OVERDUMMY_NCMCC
|
|
484 |
while (aStrIndex++ < 0xFF && ret != KErrNotFound)
|
|
485 |
{
|
|
486 |
ret = iDataLdd.GetStringDescriptor(aStrIndex, str);
|
|
487 |
}
|
|
488 |
#endif // OVERDUMMY_NCMCC
|
|
489 |
|
|
490 |
if (aStrIndex < 0xFF)
|
|
491 |
{
|
|
492 |
TBuf8<KEthernetAddressLength*2> macAddrStr;
|
|
493 |
_LIT8(KMacAddressFormat, "%02X%02X%02X%02X%02X%02X");
|
|
494 |
OstTraceExt1(TRACE_NORMAL, CNCMCLIENTMANAGER_SETMACADDRESSSTRING, "The MAC address is %s", iHostMacAddress);
|
|
495 |
macAddrStr.AppendFormat(KMacAddressFormat, iHostMacAddress[0],
|
|
496 |
iHostMacAddress[1], iHostMacAddress[2], iHostMacAddress[3],
|
|
497 |
iHostMacAddress[4], iHostMacAddress[5]);
|
|
498 |
str.Copy(macAddrStr);
|
|
499 |
ret = iDataLdd.SetStringDescriptor(aStrIndex, str);
|
|
500 |
}
|
|
501 |
|
|
502 |
OstTraceFunctionExitExt( CNCMCLIENTMANAGER_SETMACADDRESSSTRING_EXIT, this, ret );
|
|
503 |
return ret;
|
|
504 |
}
|
|
505 |
|
|
506 |
/**
|
49
|
507 |
* Get interface number
|
|
508 |
* @param aLdd The logic device driver which can be used to query for.
|
|
509 |
* @param aSettingsNumber The alter settings for the interface
|
|
510 |
* @param [out] aInterfaceNumber Carry out the interface bumber back to caller.
|
|
511 |
* @return KErrNone If interface number is return via aInterfaceNumber.
|
|
512 |
* Other system wide error code if anything went wrong.
|
28
|
513 |
*/
|
49
|
514 |
TInt CNcmClientManager::InterfaceNumber(RDevUsbcScClient& aLdd,TInt aSettingsNumber,TUint8& aInterfaceNumber)
|
28
|
515 |
{
|
49
|
516 |
OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_INTERFACENUMBER_ENTRY, this );
|
28
|
517 |
|
49
|
518 |
// Get descriptor size first
|
28
|
519 |
TInt interfaceSize = 0;
|
49
|
520 |
TInt res = aLdd.GetInterfaceDescriptorSize(aSettingsNumber, interfaceSize);
|
28
|
521 |
if ( KErrNone == res )
|
|
522 |
{
|
49
|
523 |
OstTraceFunctionExitExt( CNCMCLIENTMANAGER_INTERFACENUMBER_EXIT, this, res );
|
28
|
524 |
return res;
|
|
525 |
}
|
|
526 |
|
49
|
527 |
// Allocate enough buffer
|
28
|
528 |
HBufC8* interfaceBuf = HBufC8::New(interfaceSize);
|
|
529 |
if ( !interfaceBuf )
|
|
530 |
{
|
49
|
531 |
OstTraceFunctionExitExt( CNCMCLIENTMANAGER_INTERFACENUMBER_EXIT_DUP1, this, KErrNoMemory);
|
28
|
532 |
return KErrNoMemory;
|
|
533 |
}
|
|
534 |
|
49
|
535 |
// Get the buffer back
|
28
|
536 |
TPtr8 interfacePtr = interfaceBuf->Des();
|
|
537 |
interfacePtr.SetLength(0);
|
49
|
538 |
res = aLdd.GetInterfaceDescriptor(aSettingsNumber, interfacePtr);
|
28
|
539 |
if ( KErrNone == res )
|
|
540 |
{
|
|
541 |
delete interfaceBuf;
|
49
|
542 |
OstTraceFunctionExitExt( CNCMCLIENTMANAGER_INTERFACENUMBER_EXIT_DUP2, this, res );
|
28
|
543 |
return res;
|
|
544 |
}
|
|
545 |
|
49
|
546 |
OstTrace1(TRACE_NORMAL, CNCMCLIENTMANAGER_INTERFACENUMBER_INTERFACE_INFO, "***Interface length =% d", interfacePtr.Length());
|
|
547 |
|
|
548 |
#ifdef OST_TRACE_COMPILER_IN_USE // to depress a build warning incase no ost trace is used
|
28
|
549 |
for ( TInt i = 0 ; i < interfacePtr.Length() ; i++ )
|
|
550 |
{
|
49
|
551 |
OstTrace1(TRACE_NORMAL, CNCMCLIENTMANAGER_INTERFACENUMBER_INTERFACE_INFO2, "***** %x", interfacePtr[i]);
|
28
|
552 |
}
|
49
|
553 |
#endif
|
|
554 |
|
28
|
555 |
const TUint8* buffer = reinterpret_cast<const TUint8*>(interfacePtr.Ptr());
|
49
|
556 |
|
28
|
557 |
// 2 is where the interface number is, according to the LDD API
|
|
558 |
aInterfaceNumber = buffer[2];
|
49
|
559 |
|
|
560 |
OstTraceExt1(TRACE_NORMAL, CNCMCLIENTMANAGER_INTERFACENUMBER, "Interface number = %hhu", aInterfaceNumber);
|
|
561 |
|
|
562 |
// Now it is safe to delete the buffer we allocated.
|
28
|
563 |
delete interfaceBuf;
|
|
564 |
|
49
|
565 |
OstTraceFunctionExitExt( CNCMCLIENTMANAGER_INTERFACENUMBER_EXIT_DUP3, this, KErrNone );
|
28
|
566 |
return KErrNone;
|
|
567 |
}
|