1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
/*===========================================================================
FILE:
GobiQMICoreImg2k.cpp
DESCRIPTION:
QUALCOMM Gobi QMI Based API Core (Image Management, G2k API)
PUBLIC CLASSES AND FUNCTIONS:
cGobiQMICore
Copyright (c) 2011, Code Aurora Forum. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Code Aurora Forum nor
the names of its contributors may be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
==========================================================================*/
//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include "StdAfx.h"
#include "GobiMBNMgmt.h"
#include "GobiQMICore.h"
#include "QMIBuffers.h"
//---------------------------------------------------------------------------
// Definitions
//---------------------------------------------------------------------------
/*=========================================================================*/
// Free Methods
/*=========================================================================*/
/*===========================================================================
METHOD:
GetGenericImage (Free Method)
DESCRIPTION:
Return a compatible AMSS generic image
PARAMETERS:
uqcnInfo [ I ] - UQCN image needing a compatible AMSS generic image
RETURN VALUE:
sImageInfo - Generic image information
===========================================================================*/
sImageInfo GetGenericImage( const sImageInfo & uqcnInfo )
{
// Validate arguments
sImageInfo amssInfo;
// Obtain the technology/carrier of the UQCN
ULONG uqcnTech;
ULONG uqcnCarrier;
ULONG dummy;
eGobiError rc = ::MapVersionInfo( uqcnInfo.mVersionID,
(BYTE)uqcnInfo.mImageType,
uqcnInfo.mVersion.c_str(),
&uqcnTech,
&uqcnCarrier,
&dummy,
&dummy );
if (rc != eGOBI_ERR_NONE)
{
return amssInfo;
}
// Recursively enumerate all folders of the image store
std::vector <std::string> folders;
std::string imageStore = ::GetImageStore();
EnumerateFolders( imageStore, folders );
// Did we find any folders?
ULONG foldersSz = (ULONG)folders.size();
if (foldersSz == 0)
{
return amssInfo;
}
// Go through each folder searching for a compatible generic AMSS image
for (ULONG f = 0; f < foldersSz; f++)
{
// Search all MBN files in the specified folder
std::string folderSearch = folders[f];
int folderLen = folderSearch.size();
if (folderSearch[folderLen - 1] != '/')
{
folderSearch += '/';
}
std::vector <std::string> files;
DepthSearch( folderSearch,
0,
".mbn",
files );
int fileNum = files.size();
for (int i = 0; i < fileNum; i++)
{
std::string mbnName = files[i];
BYTE imageType = UCHAR_MAX;
BYTE imageID[16] = { 0 };
ULONG versionID = ULONG_MAX;
USHORT versionSz = MAX_PATH * 2 + 1;
CHAR versionStr[MAX_PATH * 2 + 1] = { 0 };
rc = ::GetImageInfo( mbnName.c_str(),
&imageType,
&imageID[0],
&versionID,
versionSz,
&versionStr[0] );
if (rc == eGOBI_ERR_NONE)
{
if ((eGobiMBNType)imageType == eGOBI_MBN_TYPE_MODEM)
{
ULONG amssTech;
ULONG amssCarrier;
rc = ::MapVersionInfo( versionID,
imageType,
(LPCSTR)&versionStr[0],
&amssTech,
&amssCarrier,
&dummy,
&dummy );
if (rc == eGOBI_ERR_NONE)
{
if ( (amssTech == uqcnTech)
&& (amssCarrier == (ULONG)eGOBI_IMG_CAR_GENERIC) )
{
amssInfo.mImageType = (eGobiMBNType)imageType;
amssInfo.mVersionID = versionID;
amssInfo.mVersion = (LPCSTR)&versionStr[0];
memcpy( (LPVOID)&amssInfo.mImageID[0],
(LPCVOID)&imageID[0],
MBN_UNIQUE_ID_LEN );
break;
}
}
}
}
}
}
// Success
return amssInfo;
}
/*=========================================================================*/
// cGobiQMICore Methods
/*=========================================================================*/
/*===========================================================================
METHOD:
GetFirmwareInfo (Public Method)
DESCRIPTION:
Returns image information obtained from the current device firmware
PARAMETERS:
pFirmwareID [ O ] - Firmware ID obtained from the firmware image
pTechnology [ O ] - Technology (0xFFFFFFFF if unknown)
pCarrier [ O ] - Carrier (0xFFFFFFFF if unknown)
pRegion [ O ] - Region (0xFFFFFFFF if unknown)
pGPSCapability [ O ] - GPS capability (0xFFFFFFFF if unknown)
RETURN VALUE:
eGobiError - Return code
===========================================================================*/
eGobiError cGobiQMICore::GetFirmwareInfo(
ULONG * pFirmwareID,
ULONG * pTechnology,
ULONG * pCarrier,
ULONG * pRegion,
ULONG * pGPSCapability )
{
// Validate arguments
if ( (pFirmwareID == 0)
|| (pTechnology == 0)
|| (pCarrier == 0)
|| (pRegion == 0)
|| (pGPSCapability == 0) )
{
return eGOBI_ERR_INVALID_ARG;
}
// Do we have a device node?
if (mDeviceNode.empty() == true)
{
return eGOBI_ERR_NO_CONNECTION;
}
// Generate and send the QMI request
WORD msgID = (WORD)eQMI_DMS_GET_REV_ID;
sProtocolBuffer rsp = SendSimple( eQMI_SVC_DMS, msgID );
if (rsp.IsValid() == false)
{
return GetCorrectedLastError();
}
// Did we receive a valid QMI response?
sQMIServiceBuffer qmiRsp( rsp.GetSharedBuffer() );
if (qmiRsp.IsValid() == false)
{
return eGOBI_ERR_MALFORMED_RSP;
}
// Check the mandatory QMI result TLV for success
ULONG rc = 0;
ULONG ec = 0;
bool bResult = qmiRsp.GetResult( rc, ec );
if (bResult == false)
{
return eGOBI_ERR_MALFORMED_RSP;
}
else if (rc != 0)
{
return GetCorrectedQMIError( ec );
}
// Prepare TLVs for parsing
std::vector <sDB2NavInput> tlvs = DB2ReduceQMIBuffer( qmiRsp );
const cCoreDatabase & db = GetDatabase();
// Parse the TLV we want (by DB key)
sProtocolEntityKey tlvKey( eDB2_ET_QMI_DMS_RSP, msgID, 17 );
cDataParser::tParsedFields pf = ParseTLV( db, rsp, tlvs, tlvKey );
if (pf.size() < 1)
{
return eGOBI_ERR_INVALID_RSP;
}
std::string uqcnIDString = pf[0].mValueString;
LONG strLen = uqcnIDString.size();
if (strLen != 8)
{
return eGOBI_ERR_INVALID_RSP;
}
std::string idString1 = uqcnIDString.substr( 0, 2 );
std::string idString2 = uqcnIDString.substr( 2, 2 );
std::string idString3 = uqcnIDString.substr( 4, 2 );
std::string idString4 = uqcnIDString.substr( 6, 2 );
ULONG id1 = 0;
ULONG id2 = 0;
ULONG id3 = 0;
ULONG id4 = 0;
bool bID1 = StringToULONG( idString1.c_str(), 16, id1 );
bool bID2 = StringToULONG( idString2.c_str(), 16, id2 );
bool bID3 = StringToULONG( idString3.c_str(), 16, id3 );
bool bID4 = StringToULONG( idString4.c_str(), 16, id4 );
if (bID1 == false || bID2 == false || bID3 == false || bID4 == false)
{
return eGOBI_ERR_INVALID_RSP;
}
ULONG uqcnID = (id1 << 24) | (id2 << 16) | (id3 << 8) | id4;
// Parse the TLV we want (AMSS revision)
tlvKey = sProtocolEntityKey( eDB2_ET_QMI_DMS_RSP, msgID, 1 );
pf = ParseTLV( db, rsp, tlvs, tlvKey );
if (pf.size() < 1 || pf[0].mValueString.size() <= 0)
{
return eGOBI_ERR_INVALID_RSP;
}
*pFirmwareID = uqcnID;
eGobiError err = ::MapVersionInfo( uqcnID,
(BYTE)eGOBI_MBN_TYPE_PRI,
pf[0].mValueString.c_str(),
pTechnology,
pCarrier,
pRegion,
pGPSCapability );
return err;
}
/*===========================================================================
METHOD:
UpgradeFirmware (Public Method)
DESCRIPTION:
This function performs the following set of steps:
a) Verifies arguments
b) Updates firmware ID on device
c) Resets the device
NOTE: Upon successful completion the above steps will have been completed,
however the actual upgrade of the firmware will necessarily then
follow.
PARAMETERS:
pDestinationPath [ I ] - The fully qualified path to the destination folder
that the firmware download service will use
RETURN VALUE:
eGobiError - Return code
===========================================================================*/
eGobiError cGobiQMICore::UpgradeFirmware( CHAR * pDestinationPath )
{
// Validate arguments
if (pDestinationPath == 0 || pDestinationPath[0] == 0)
{
return eGOBI_ERR_INVALID_ARG;
}
// Do we have a device ID?
if (mDeviceNode.empty() == true)
{
return eGOBI_ERR_NO_CONNECTION;
}
// Use that to validate the image store for this device
std::string tmpPath( pDestinationPath );
int tmpPathlen = tmpPath.size();
if (tmpPath[tmpPathlen - 1] != '/')
{
tmpPath += '/';
}
std::string imageStore = ::GetImageStore();
if (tmpPath.find( imageStore ) == std::string::npos)
{
return eGOBI_ERR_INVALID_FILE;
}
sImageInfo amssInfo;
sImageInfo uqcnInfo;
std::vector <sImageInfo> images;
images = ::GetImagesInfo( tmpPath );
ULONG imageCount = (ULONG)images.size();
for (ULONG i = 0; i < imageCount; i++)
{
const sImageInfo & ii = images[i];
if (ii.mImageType == eGOBI_MBN_TYPE_MODEM)
{
amssInfo = ii;
}
else if (ii.mImageType == eGOBI_MBN_TYPE_PRI)
{
uqcnInfo = ii;
}
}
if (uqcnInfo.IsValid() == false)
{
return eGOBI_ERR_INVALID_FILE;
}
if (amssInfo.IsValid() == false)
{
amssInfo = GetGenericImage( uqcnInfo );
// Still bad?
if (amssInfo.IsValid() == false)
{
return eGOBI_ERR_INVALID_FILE;
}
}
WORD msgID = (WORD)eQMI_DMS_SET_FIRMWARE_PREF;
std::vector <sDB2PackingInput> piv;
std::ostringstream amssIDStr;
std::ostringstream uqcnIDStr;
for (ULONG v = 0; v < 16; v++)
{
amssIDStr << " " << (ULONG)amssInfo.mImageID[v];
uqcnIDStr << " " << (ULONG)uqcnInfo.mImageID[v];
}
// "2 0%s %d \"%s\" 1%s %d \"%s\""
std::ostringstream tmp;
tmp << "2 0" << amssIDStr.str() << " " << amssInfo.mVersion.size()
<< " \"" << amssInfo.mVersion << "\" 1" << uqcnIDStr.str()
<< " " << uqcnInfo.mVersion.size() << " \""
<< uqcnInfo.mVersion << "\"";
sProtocolEntityKey pek( eDB2_ET_QMI_DMS_REQ, msgID, 1 );
sDB2PackingInput pi( pek, tmp.str().c_str() );
piv.push_back( pi );
// Pack up the QMI request
const cCoreDatabase & db = GetDatabase();
sSharedBuffer * pRequest = DB2PackQMIBuffer( db, piv );
// Send the QMI request, check result, and return
eGobiError rc = SendAndCheckReturn( eQMI_SVC_DMS, pRequest );
if (rc != eGOBI_ERR_NONE)
{
return rc;
}
// Ask device to power down
rc = SetPower( 5 );
if (rc != eGOBI_ERR_NONE)
{
return eGOBI_ERR_RESET;
}
return rc;
}
/*===========================================================================
METHOD:
GetImageInfo (Public Method)
DESCRIPTION:
Returns image information obtained from the firmware image located at the
provided path
PARAMETERS:
pPath [ I ] - Location of the firmware image
pFirmwareID [ O ] - Firmware ID obtained from the firmware image
pTechnology [ O ] - Technology (0xFFFFFFFF if unknown)
pCarrier [ O ] - Carrier (0xFFFFFFFF if unknown)
pRegion [ O ] - Region (0xFFFFFFFF if unknown)
pGPSCapability [ O ] - GPS capability (0xFFFFFFFF if unknown)
RETURN VALUE:
eGobiError - Return code
===========================================================================*/
eGobiError cGobiQMICore::GetImageInfo(
CHAR * pPath,
ULONG * pFirmwareID,
ULONG * pTechnology,
ULONG * pCarrier,
ULONG * pRegion,
ULONG * pGPSCapability )
{
// Validate arguments
if ( (pPath == 0)
|| (pPath[0] == 0)
|| (pFirmwareID == 0)
|| (pTechnology == 0)
|| (pCarrier == 0)
|| (pRegion == 0)
|| (pGPSCapability == 0) )
{
return eGOBI_ERR_INVALID_ARG;
}
// Do we have a device ID?
if (mDeviceNode.empty() == true)
{
return eGOBI_ERR_NO_CONNECTION;
}
// Use that to validate the image store for this device
std::string tmpPath( pPath );
int tmpPathlen = tmpPath.size();
if (tmpPath[tmpPathlen - 1] != '/')
{
tmpPath += '/';
}
std::string imageStore = ::GetImageStore();
if (tmpPath.find( imageStore ) < 0)
{
return eGOBI_ERR_INVALID_FILE;
}
std::vector <sImageInfo> images;
images = ::GetImagesInfo( tmpPath );
ULONG imageCount = (ULONG)images.size();
for (ULONG i = 0; i < imageCount; i++)
{
const sImageInfo & ii = images[i];
if (ii.mImageType == eGOBI_MBN_TYPE_PRI)
{
*pFirmwareID = ii.mVersionID;
return ::MapVersionInfo( ii.mVersionID,
(BYTE)ii.mImageType,
ii.mVersion.c_str(),
pTechnology,
pCarrier,
pRegion,
pGPSCapability );
}
}
return eGOBI_ERR_INVALID_FILE;
}
/*===========================================================================
METHOD:
GetImageStore (Public Method)
DESCRIPTION:
Returns the image store folder, i.e. the folder co-located with the
QDL Service executable which (by default) contains one or more carrier
specific image subfolders
PARAMETERS:
pathSize [ I ] - Maximum number of characters (including NULL
terminator) that can be copied to the image
store path array
pImageStorePath [ O ] - The path to the image store
RETURN VALUE:
eGobiError - Return code
===========================================================================*/
eGobiError cGobiQMICore::GetImageStore(
WORD pathSize,
CHAR * pImageStorePath )
{
// Do we have a device ID?
if (mDeviceNode.size() == true)
{
return eGOBI_ERR_NO_CONNECTION;
}
std::string imageStore = ::GetImageStore();
// Copy over image store
LONG strLen = imageStore.size();
if (pathSize < (ULONG)strLen + 1)
{
pImageStorePath[0] = 0;
return eGOBI_ERR_BUFFER_SZ;
}
memcpy( (LPVOID)pImageStorePath,
(LPCVOID)imageStore.c_str(),
(SIZE_T)strLen );
pImageStorePath[strLen] = 0;
return eGOBI_ERR_NONE;
}
|