| 1 |
/*=========================================================================== |
| 2 |
FILE: |
| 3 |
Gobi3000TranslationDMS.cpp |
| 4 |
|
| 5 |
DESCRIPTION: |
| 6 |
QUALCOMM Translation for Gobi 3000 (DMS Service) |
| 7 |
|
| 8 |
Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 9 |
|
| 10 |
Redistribution and use in source and binary forms, with or without |
| 11 |
modification, are permitted provided that the following conditions are met: |
| 12 |
* Redistributions of source code must retain the above copyright |
| 13 |
notice, this list of conditions and the following disclaimer. |
| 14 |
* Redistributions in binary form must reproduce the above copyright |
| 15 |
notice, this list of conditions and the following disclaimer in the |
| 16 |
documentation and/or other materials provided with the distribution. |
| 17 |
* Neither the name of Code Aurora Forum nor |
| 18 |
the names of its contributors may be used to endorse or promote |
| 19 |
products derived from this software without specific prior written |
| 20 |
permission. |
| 21 |
|
| 22 |
|
| 23 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 24 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 25 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 26 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 27 |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 28 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 29 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 30 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 31 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 32 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 33 |
POSSIBILITY OF SUCH DAMAGE. |
| 34 |
==========================================================================*/ |
| 35 |
|
| 36 |
//--------------------------------------------------------------------------- |
| 37 |
// Include Files |
| 38 |
//--------------------------------------------------------------------------- |
| 39 |
#include "Gobi3000Translation.h" |
| 40 |
|
| 41 |
/*=========================================================================== |
| 42 |
METHOD: |
| 43 |
ParseGetDeviceCapabilities |
| 44 |
|
| 45 |
DESCRIPTION: |
| 46 |
This function gets device capabilities |
| 47 |
|
| 48 |
PARAMETERS: |
| 49 |
inLen [ I ] - Length of input buffer |
| 50 |
pIn [ I ] - Input buffer |
| 51 |
pMaxTXChannelRate [ O ] - Maximum transmission rate (bps) |
| 52 |
pMaxRXChannelRate [ O ] - Maximum reception rate (bps) |
| 53 |
pDataServiceCapability [ O ] - CS/PS data service capability |
| 54 |
pSimCapability [ O ] - Device SIM support |
| 55 |
pRadioIfacesSize [I/O] - Upon input the maximum number of elements |
| 56 |
that the radio interfaces can contain. |
| 57 |
Upon successful output the actual number |
| 58 |
of elements in the radio interface array |
| 59 |
pRadioIfaces [ O ] - The radio interface array |
| 60 |
|
| 61 |
RETURN VALUE: |
| 62 |
ULONG - Return code |
| 63 |
===========================================================================*/ |
| 64 |
ULONG ParseGetDeviceCapabilities( |
| 65 |
ULONG inLen, |
| 66 |
const BYTE * pIn, |
| 67 |
ULONG * pMaxTXChannelRate, |
| 68 |
ULONG * pMaxRXChannelRate, |
| 69 |
ULONG * pDataServiceCapability, |
| 70 |
ULONG * pSimCapability, |
| 71 |
ULONG * pRadioIfacesSize, |
| 72 |
BYTE * pRadioIfaces ) |
| 73 |
{ |
| 74 |
// Validate arguments |
| 75 |
if (pIn == 0 |
| 76 |
|| pMaxTXChannelRate == 0 |
| 77 |
|| pMaxRXChannelRate == 0 |
| 78 |
|| pDataServiceCapability == 0 |
| 79 |
|| pSimCapability == 0 |
| 80 |
|| pRadioIfacesSize == 0 |
| 81 |
|| *pRadioIfacesSize == 0 |
| 82 |
|| pRadioIfaces == 0) |
| 83 |
{ |
| 84 |
return eGOBI_ERR_INVALID_ARG; |
| 85 |
} |
| 86 |
|
| 87 |
ULONG maxRadioIfaces = (ULONG)*pRadioIfacesSize; |
| 88 |
|
| 89 |
// Assume failure |
| 90 |
*pRadioIfacesSize = 0; |
| 91 |
|
| 92 |
const sDMSGetDeviceCapabilitiesResponse_Capabilities * pTLVx01; |
| 93 |
ULONG structSzx01 = sizeof( sDMSGetDeviceCapabilitiesResponse_Capabilities ); |
| 94 |
ULONG outLenx01; |
| 95 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 96 |
if (rc != eGOBI_ERR_NONE) |
| 97 |
{ |
| 98 |
return rc; |
| 99 |
} |
| 100 |
|
| 101 |
if (outLenx01 < structSzx01) |
| 102 |
{ |
| 103 |
return eGOBI_ERR_BUFFER_SZ; |
| 104 |
} |
| 105 |
|
| 106 |
// Populate the variables |
| 107 |
*pMaxTXChannelRate = pTLVx01->mMaxTXRatebps; |
| 108 |
*pMaxRXChannelRate = pTLVx01->mMaxRXRatebps; |
| 109 |
*pDataServiceCapability = pTLVx01->mDataServiceCapability; |
| 110 |
|
| 111 |
// SIM capability should be treated as a boolean, even though it's not |
| 112 |
*pSimCapability = (pTLVx01->mSIMSupported == 0 ? 0 : 1); |
| 113 |
|
| 114 |
ULONG activeRadioIfaces = pTLVx01->mRadioInterfaceCount; |
| 115 |
if (activeRadioIfaces > maxRadioIfaces) |
| 116 |
{ |
| 117 |
activeRadioIfaces = maxRadioIfaces; |
| 118 |
} |
| 119 |
|
| 120 |
const eQMIDMSRadioInterfaces * pInRadioInterfaces; |
| 121 |
|
| 122 |
// Verify there is room for the array in the TLV |
| 123 |
if (outLenx01 < structSzx01 |
| 124 |
+ sizeof( eQMIDMSRadioInterfaces ) * activeRadioIfaces) |
| 125 |
{ |
| 126 |
return eGOBI_ERR_MALFORMED_RSP; |
| 127 |
} |
| 128 |
|
| 129 |
// Align to the first array element |
| 130 |
pInRadioInterfaces = (const eQMIDMSRadioInterfaces *) |
| 131 |
((const BYTE *)pTLVx01 + structSzx01); |
| 132 |
|
| 133 |
ULONG * pOutRadioIfaces = (ULONG *)pRadioIfaces; |
| 134 |
for (ULONG r = 0; r < activeRadioIfaces; r++) |
| 135 |
{ |
| 136 |
*pOutRadioIfaces = *pInRadioInterfaces; |
| 137 |
pOutRadioIfaces++; |
| 138 |
pInRadioInterfaces++; |
| 139 |
} |
| 140 |
|
| 141 |
*pRadioIfacesSize = activeRadioIfaces; |
| 142 |
return eGOBI_ERR_NONE; |
| 143 |
} |
| 144 |
|
| 145 |
/*=========================================================================== |
| 146 |
METHOD: |
| 147 |
ParseGetManufacturer |
| 148 |
|
| 149 |
DESCRIPTION: |
| 150 |
This function returns the device manufacturer name |
| 151 |
|
| 152 |
PARAMETERS: |
| 153 |
inLen [ I ] - Length of input buffer |
| 154 |
pIn [ I ] - Input buffer |
| 155 |
stringSize [ I ] - The maximum number of characters (including NULL |
| 156 |
terminator) that the string array can contain |
| 157 |
pString [ O ] - NULL terminated string |
| 158 |
|
| 159 |
RETURN VALUE: |
| 160 |
ULONG - Return code |
| 161 |
===========================================================================*/ |
| 162 |
ULONG ParseGetManufacturer( |
| 163 |
ULONG inLen, |
| 164 |
const BYTE * pIn, |
| 165 |
BYTE stringSize, |
| 166 |
CHAR * pString ) |
| 167 |
{ |
| 168 |
// Validate arguments |
| 169 |
if (pIn == 0 || stringSize == 0 || pString == 0) |
| 170 |
{ |
| 171 |
return eGOBI_ERR_INVALID_ARG; |
| 172 |
} |
| 173 |
|
| 174 |
// Assume failure |
| 175 |
*pString = 0; |
| 176 |
|
| 177 |
// Find the manufacturer |
| 178 |
// sDMSGetDeviceManfacturerResponse_Manfacturer only contains this |
| 179 |
const CHAR * pTLVx01; |
| 180 |
ULONG outLenx01; |
| 181 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 182 |
if (rc != eGOBI_ERR_NONE) |
| 183 |
{ |
| 184 |
return rc; |
| 185 |
} |
| 186 |
|
| 187 |
// Space to perform the copy? |
| 188 |
if (stringSize < outLenx01 + 1) |
| 189 |
{ |
| 190 |
return eGOBI_ERR_BUFFER_SZ; |
| 191 |
} |
| 192 |
|
| 193 |
memcpy( pString, pTLVx01, outLenx01 ); |
| 194 |
pString[outLenx01] = 0; |
| 195 |
|
| 196 |
return eGOBI_ERR_NONE; |
| 197 |
} |
| 198 |
|
| 199 |
/*=========================================================================== |
| 200 |
METHOD: |
| 201 |
ParseGetModelID |
| 202 |
|
| 203 |
DESCRIPTION: |
| 204 |
This function returns the device model ID |
| 205 |
|
| 206 |
PARAMETERS: |
| 207 |
inLen [ I ] - Length of input buffer |
| 208 |
pIn [ I ] - Input buffer |
| 209 |
stringSize [ I ] - The maximum number of characters (including NULL |
| 210 |
terminator) that the string array can contain |
| 211 |
pString [ O ] - NULL terminated string |
| 212 |
|
| 213 |
RETURN VALUE: |
| 214 |
ULONG - Return code |
| 215 |
===========================================================================*/ |
| 216 |
ULONG ParseGetModelID( |
| 217 |
ULONG inLen, |
| 218 |
const BYTE * pIn, |
| 219 |
BYTE stringSize, |
| 220 |
CHAR * pString ) |
| 221 |
{ |
| 222 |
// Validate arguments |
| 223 |
if (pIn == 0 || stringSize == 0 || pString == 0) |
| 224 |
{ |
| 225 |
return eGOBI_ERR_INVALID_ARG; |
| 226 |
} |
| 227 |
|
| 228 |
// Assume failure |
| 229 |
*pString = 0; |
| 230 |
|
| 231 |
// Find the model |
| 232 |
// sDMSGetDeviceModelResponse_Model only contains the model |
| 233 |
const CHAR * pTLVx01; |
| 234 |
ULONG outLenx01; |
| 235 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 236 |
if (rc != eGOBI_ERR_NONE) |
| 237 |
{ |
| 238 |
return rc; |
| 239 |
} |
| 240 |
|
| 241 |
// Space to perform the copy? |
| 242 |
if (stringSize < outLenx01 + 1) |
| 243 |
{ |
| 244 |
return eGOBI_ERR_BUFFER_SZ; |
| 245 |
} |
| 246 |
|
| 247 |
memcpy( pString, pTLVx01, outLenx01 ); |
| 248 |
pString[outLenx01] = 0; |
| 249 |
|
| 250 |
return eGOBI_ERR_NONE; |
| 251 |
} |
| 252 |
|
| 253 |
/*=========================================================================== |
| 254 |
METHOD: |
| 255 |
ParseGetFirmwareRevision |
| 256 |
|
| 257 |
DESCRIPTION: |
| 258 |
This function returns the device firmware revision |
| 259 |
|
| 260 |
PARAMETERS: |
| 261 |
inLen [ I ] - Length of input buffer |
| 262 |
pIn [ I ] - Input buffer |
| 263 |
stringSize [ I ] - The maximum number of characters (including NULL |
| 264 |
terminator) that the string array can contain |
| 265 |
pString [ O ] - NULL terminated string |
| 266 |
|
| 267 |
RETURN VALUE: |
| 268 |
ULONG - Return code |
| 269 |
===========================================================================*/ |
| 270 |
ULONG ParseGetFirmwareRevision( |
| 271 |
ULONG inLen, |
| 272 |
const BYTE * pIn, |
| 273 |
BYTE stringSize, |
| 274 |
CHAR * pString ) |
| 275 |
{ |
| 276 |
// Validate arguments |
| 277 |
if (pIn == 0 || stringSize == 0 || pString == 0) |
| 278 |
{ |
| 279 |
return eGOBI_ERR_INVALID_ARG; |
| 280 |
} |
| 281 |
|
| 282 |
// Assume failure |
| 283 |
*pString = 0; |
| 284 |
|
| 285 |
// Find the PRI revision |
| 286 |
// sDMSGetDeviceRevisionResponse_UQCNRevision only contains this |
| 287 |
const CHAR * pTLVx11; |
| 288 |
ULONG outLenx11; |
| 289 |
ULONG rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 ); |
| 290 |
if (rc != eGOBI_ERR_NONE) |
| 291 |
{ |
| 292 |
return rc; |
| 293 |
} |
| 294 |
|
| 295 |
// Space to perform the copy? |
| 296 |
if (stringSize < outLenx11 + 1) |
| 297 |
{ |
| 298 |
return eGOBI_ERR_BUFFER_SZ; |
| 299 |
} |
| 300 |
|
| 301 |
memcpy( pString, pTLVx11, outLenx11 ); |
| 302 |
pString[outLenx11] = 0; |
| 303 |
|
| 304 |
return eGOBI_ERR_NONE; |
| 305 |
} |
| 306 |
|
| 307 |
/*=========================================================================== |
| 308 |
METHOD: |
| 309 |
ParseGetFirmwareRevisions |
| 310 |
|
| 311 |
DESCRIPTION: |
| 312 |
This function returns the device firmware (AMSS, boot, and PRI) |
| 313 |
revisions |
| 314 |
|
| 315 |
PARAMETERS: |
| 316 |
inLen [ I ] - Length of input buffer |
| 317 |
pIn [ I ] - Input buffer |
| 318 |
amssSize [ I ] - The maximum number of characters (including NULL |
| 319 |
terminator) that the AMSS string array can contain |
| 320 |
pAMSSString [ O ] - NULL terminated AMSS revision string |
| 321 |
bootSize [ I ] - The maximum number of characters (including NULL |
| 322 |
terminator) that the boot string array can contain |
| 323 |
pBootString [ O ] - NULL terminated boot code revision string |
| 324 |
priSize [ I ] - The maximum number of characters (including NULL |
| 325 |
terminator) that the PRI string array can contain |
| 326 |
pPRIString [ O ] - NULL terminated PRI revision string |
| 327 |
|
| 328 |
RETURN VALUE: |
| 329 |
ULONG - Return code |
| 330 |
===========================================================================*/ |
| 331 |
ULONG ParseGetFirmwareRevisions( |
| 332 |
ULONG inLen, |
| 333 |
const BYTE * pIn, |
| 334 |
BYTE amssSize, |
| 335 |
CHAR * pAMSSString, |
| 336 |
BYTE bootSize, |
| 337 |
CHAR * pBootString, |
| 338 |
BYTE priSize, |
| 339 |
CHAR * pPRIString ) |
| 340 |
{ |
| 341 |
// Validate arguments |
| 342 |
if (pIn == 0 |
| 343 |
|| amssSize == 0 || pAMSSString == 0 |
| 344 |
|| bootSize == 0 || pBootString == 0 |
| 345 |
|| priSize == 0 || pPRIString == 0) |
| 346 |
{ |
| 347 |
return eGOBI_ERR_INVALID_ARG; |
| 348 |
} |
| 349 |
|
| 350 |
// Assume failure |
| 351 |
*pAMSSString = 0; |
| 352 |
*pBootString = 0; |
| 353 |
*pPRIString = 0; |
| 354 |
|
| 355 |
// Find the AMSS version |
| 356 |
// sDMSGetDeviceRevisionResponse_Revision only contains this |
| 357 |
const CHAR * pTLVx01; |
| 358 |
ULONG outLenx01; |
| 359 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 360 |
if (rc != eGOBI_ERR_NONE) |
| 361 |
{ |
| 362 |
return rc; |
| 363 |
} |
| 364 |
|
| 365 |
// Space to perform the copy? |
| 366 |
if (amssSize < outLenx01 + 1) |
| 367 |
{ |
| 368 |
return eGOBI_ERR_BUFFER_SZ; |
| 369 |
} |
| 370 |
|
| 371 |
memcpy( pAMSSString, pTLVx01, outLenx01 ); |
| 372 |
pAMSSString[outLenx01] = 0; |
| 373 |
|
| 374 |
// Find the Boot version |
| 375 |
// sDMSGetDeviceRevisionResponse_BootCodeRevision only contains this |
| 376 |
const CHAR * pTLVx10; |
| 377 |
ULONG outLenx10; |
| 378 |
rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 ); |
| 379 |
if (rc != eGOBI_ERR_NONE) |
| 380 |
{ |
| 381 |
return rc; |
| 382 |
} |
| 383 |
|
| 384 |
// Space to perform the copy? |
| 385 |
if (bootSize < outLenx10 + 1) |
| 386 |
{ |
| 387 |
return eGOBI_ERR_BUFFER_SZ; |
| 388 |
} |
| 389 |
|
| 390 |
memcpy( pBootString, pTLVx10, outLenx10 ); |
| 391 |
pBootString[outLenx10] = 0; |
| 392 |
|
| 393 |
// The PRI version is returned by ParseGetFirmwareRevision() |
| 394 |
rc = ParseGetFirmwareRevision( inLen, pIn, priSize, pPRIString ); |
| 395 |
if (rc != eGOBI_ERR_NONE) |
| 396 |
{ |
| 397 |
return rc; |
| 398 |
} |
| 399 |
|
| 400 |
return eGOBI_ERR_NONE; |
| 401 |
} |
| 402 |
|
| 403 |
/*=========================================================================== |
| 404 |
METHOD: |
| 405 |
ParseGetVoiceNumber |
| 406 |
|
| 407 |
DESCRIPTION: |
| 408 |
This function returns the voice number in use by the device |
| 409 |
|
| 410 |
PARAMETERS: |
| 411 |
inLen [ I ] - Length of input buffer |
| 412 |
pIn [ I ] - Input buffer |
| 413 |
voiceNumberSize [ I ] - The maximum number of characters (including NULL |
| 414 |
terminator) that the voice number array can |
| 415 |
contain |
| 416 |
pVoiceNumber [ O ] - Voice number (MDN or ISDN) string |
| 417 |
minSize [ I ] - The maximum number of characters (including NULL |
| 418 |
terminator) that the MIN array can contain |
| 419 |
pMIN [ O ] - MIN string (empty string returned when MIN is |
| 420 |
not supported/programmed) |
| 421 |
|
| 422 |
RETURN VALUE: |
| 423 |
ULONG - Return code |
| 424 |
===========================================================================*/ |
| 425 |
ULONG ParseGetVoiceNumber( |
| 426 |
ULONG inLen, |
| 427 |
const BYTE * pIn, |
| 428 |
BYTE voiceNumberSize, |
| 429 |
CHAR * pVoiceNumber, |
| 430 |
BYTE minSize, |
| 431 |
CHAR * pMIN ) |
| 432 |
{ |
| 433 |
// Validate arguments |
| 434 |
if (pIn == 0 |
| 435 |
|| voiceNumberSize == 0 || pVoiceNumber == 0 |
| 436 |
|| minSize == 0 || pMIN == 0) |
| 437 |
{ |
| 438 |
return eGOBI_ERR_INVALID_ARG; |
| 439 |
} |
| 440 |
|
| 441 |
// Assume failure |
| 442 |
*pVoiceNumber = 0; |
| 443 |
*pMIN = 0; |
| 444 |
|
| 445 |
// Find the Voice number |
| 446 |
// sDMSGetDeviceVoiceNumberResponse_VoiceNumber only contains this |
| 447 |
const CHAR * pTLVx01; |
| 448 |
ULONG outLenx01; |
| 449 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 450 |
if (rc != eGOBI_ERR_NONE) |
| 451 |
{ |
| 452 |
return rc; |
| 453 |
} |
| 454 |
|
| 455 |
// Space to perform the copy? |
| 456 |
if (voiceNumberSize < outLenx01 + 1) |
| 457 |
{ |
| 458 |
return eGOBI_ERR_BUFFER_SZ; |
| 459 |
} |
| 460 |
|
| 461 |
memcpy( pVoiceNumber, pTLVx01, outLenx01 ); |
| 462 |
pVoiceNumber[outLenx01] = 0; |
| 463 |
|
| 464 |
// Find the Mobile ID (optional) |
| 465 |
// sDMSGetDeviceVoiceNumberResponse_MobileIDNumber only contains this |
| 466 |
const CHAR * pTLVx10; |
| 467 |
ULONG outLenx10; |
| 468 |
rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 ); |
| 469 |
if (rc == eGOBI_ERR_NONE) |
| 470 |
{ |
| 471 |
// Space to perform the copy? |
| 472 |
if (minSize < outLenx10 + 1) |
| 473 |
{ |
| 474 |
return eGOBI_ERR_BUFFER_SZ; |
| 475 |
} |
| 476 |
|
| 477 |
memcpy( pMIN, pTLVx10, outLenx10 ); |
| 478 |
pMIN[outLenx10] = 0; |
| 479 |
} |
| 480 |
|
| 481 |
return eGOBI_ERR_NONE; |
| 482 |
} |
| 483 |
|
| 484 |
/*=========================================================================== |
| 485 |
METHOD: |
| 486 |
ParseGetIMSI |
| 487 |
|
| 488 |
DESCRIPTION: |
| 489 |
This function returns the device IMSI |
| 490 |
|
| 491 |
PARAMETERS: |
| 492 |
inLen [ I ] - Length of input buffer |
| 493 |
pIn [ I ] - Input buffer |
| 494 |
stringSize [ I ] - The maximum number of characters (including NULL |
| 495 |
terminator) that the string array can contain |
| 496 |
pString [ O ] - NULL terminated string |
| 497 |
|
| 498 |
RETURN VALUE: |
| 499 |
ULONG - Return code |
| 500 |
===========================================================================*/ |
| 501 |
ULONG ParseGetIMSI( |
| 502 |
ULONG inLen, |
| 503 |
const BYTE * pIn, |
| 504 |
BYTE stringSize, |
| 505 |
CHAR * pString ) |
| 506 |
{ |
| 507 |
// Validate arguments |
| 508 |
if (pIn == 0 || stringSize == 0 || pString == 0) |
| 509 |
{ |
| 510 |
return eGOBI_ERR_INVALID_ARG; |
| 511 |
} |
| 512 |
|
| 513 |
// Assume failure |
| 514 |
*pString = 0; |
| 515 |
|
| 516 |
// Find the IMSI |
| 517 |
// sDMSGetDeviceVoiceNumberResponse_IMSI only contains this |
| 518 |
const CHAR * pTLVx01; |
| 519 |
ULONG outLenx01; |
| 520 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 521 |
if (rc != eGOBI_ERR_NONE) |
| 522 |
{ |
| 523 |
return rc; |
| 524 |
} |
| 525 |
|
| 526 |
// Space to perform the copy? |
| 527 |
if (stringSize < outLenx01 + 1) |
| 528 |
{ |
| 529 |
return eGOBI_ERR_BUFFER_SZ; |
| 530 |
} |
| 531 |
|
| 532 |
memcpy( pString, pTLVx01, outLenx01 ); |
| 533 |
pString[outLenx01] = 0; |
| 534 |
|
| 535 |
return eGOBI_ERR_NONE; |
| 536 |
} |
| 537 |
|
| 538 |
/*=========================================================================== |
| 539 |
METHOD: |
| 540 |
ParseGetSerialNumbers |
| 541 |
|
| 542 |
DESCRIPTION: |
| 543 |
This command returns all serial numbers assigned to the device |
| 544 |
|
| 545 |
PARAMETERS: |
| 546 |
inLen [ I ] - Length of input buffer |
| 547 |
pIn [ I ] - Input buffer |
| 548 |
esnSize [ I ] - The maximum number of characters (including NULL |
| 549 |
terminator) that the ESN array can contain |
| 550 |
pESNString [ O ] - ESN string (empty string returned when ESN is |
| 551 |
not supported/programmed) |
| 552 |
imeiSize [ I ] - The maximum number of characters (including NULL |
| 553 |
terminator) that the IMEI array can contain |
| 554 |
pIMEIString [ O ] - IMEI string (empty string returned when IMEI is |
| 555 |
not supported/programmed) |
| 556 |
meidSize [ I ] - The maximum number of characters (including NULL |
| 557 |
terminator) that the MEID array can contain |
| 558 |
pMEIDString [ O ] - MEID string (empty string returned when MEID is |
| 559 |
not supported/programmed) |
| 560 |
|
| 561 |
RETURN VALUE: |
| 562 |
ULONG - Return code |
| 563 |
===========================================================================*/ |
| 564 |
ULONG ParseGetSerialNumbers( |
| 565 |
ULONG inLen, |
| 566 |
const BYTE * pIn, |
| 567 |
BYTE esnSize, |
| 568 |
CHAR * pESNString, |
| 569 |
BYTE imeiSize, |
| 570 |
CHAR * pIMEIString, |
| 571 |
BYTE meidSize, |
| 572 |
CHAR * pMEIDString ) |
| 573 |
{ |
| 574 |
// Validate arguments |
| 575 |
if (pIn == 0 |
| 576 |
|| esnSize == 0 || pESNString == 0 |
| 577 |
|| imeiSize == 0 || pIMEIString == 0 |
| 578 |
|| meidSize == 0 || pMEIDString == 0) |
| 579 |
{ |
| 580 |
return eGOBI_ERR_INVALID_ARG; |
| 581 |
} |
| 582 |
|
| 583 |
// Assume failure |
| 584 |
*pESNString = 0; |
| 585 |
*pIMEIString = 0; |
| 586 |
*pMEIDString = 0; |
| 587 |
|
| 588 |
// Find the ESN |
| 589 |
// sDMSGetDeviceSerialNumbersResponse_ESN only contains this |
| 590 |
const CHAR * pTLVx10; |
| 591 |
ULONG outLenx10; |
| 592 |
ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 ); |
| 593 |
if (rc != eGOBI_ERR_NONE) |
| 594 |
{ |
| 595 |
return rc; |
| 596 |
} |
| 597 |
|
| 598 |
// Space to perform the copy? |
| 599 |
if (esnSize < outLenx10 + 1) |
| 600 |
{ |
| 601 |
return eGOBI_ERR_BUFFER_SZ; |
| 602 |
} |
| 603 |
|
| 604 |
memcpy( pESNString, pTLVx10, outLenx10 ); |
| 605 |
pESNString[outLenx10] = 0; |
| 606 |
|
| 607 |
// Find the IMEI |
| 608 |
// sDMSGetDeviceSerialNumbersResponse_IMEI only contains this |
| 609 |
const CHAR * pTLVx11; |
| 610 |
ULONG outLenx11; |
| 611 |
rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 ); |
| 612 |
if (rc != eGOBI_ERR_NONE) |
| 613 |
{ |
| 614 |
return rc; |
| 615 |
} |
| 616 |
|
| 617 |
// Space to perform the copy? |
| 618 |
if (imeiSize < outLenx11 + 1) |
| 619 |
{ |
| 620 |
return eGOBI_ERR_BUFFER_SZ; |
| 621 |
} |
| 622 |
|
| 623 |
memcpy( pIMEIString, pTLVx11, outLenx11 ); |
| 624 |
pIMEIString[outLenx11] = 0; |
| 625 |
|
| 626 |
// Find the MEID |
| 627 |
// sDMSGetDeviceSerialNumbersResponse_MEID only contains this |
| 628 |
const CHAR * pTLVx12; |
| 629 |
ULONG outLenx12; |
| 630 |
rc = GetTLV( inLen, pIn, 0x12, &outLenx12, (const BYTE **)&pTLVx12 ); |
| 631 |
if (rc != eGOBI_ERR_NONE) |
| 632 |
{ |
| 633 |
return rc; |
| 634 |
} |
| 635 |
|
| 636 |
// Space to perform the copy? |
| 637 |
if (meidSize < outLenx12 + 1) |
| 638 |
{ |
| 639 |
return eGOBI_ERR_BUFFER_SZ; |
| 640 |
} |
| 641 |
|
| 642 |
memcpy( pMEIDString, pTLVx12, outLenx12 ); |
| 643 |
pMEIDString[outLenx12] = 0; |
| 644 |
|
| 645 |
return eGOBI_ERR_NONE; |
| 646 |
} |
| 647 |
|
| 648 |
/*=========================================================================== |
| 649 |
METHOD: |
| 650 |
PackSetLock |
| 651 |
|
| 652 |
DESCRIPTION: |
| 653 |
This function sets the user lock state maintained by the device |
| 654 |
|
| 655 |
PARAMETERS: |
| 656 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 657 |
contain, upon output the number of BYTEs copied |
| 658 |
to pOut |
| 659 |
pOut [ O ] - Output buffer |
| 660 |
state [ I ] - Desired lock state |
| 661 |
pCurrentPIN [ I ] - Current four digit PIN string |
| 662 |
|
| 663 |
RETURN VALUE: |
| 664 |
ULONG - Return code |
| 665 |
===========================================================================*/ |
| 666 |
ULONG PackSetLock( |
| 667 |
ULONG * pOutLen, |
| 668 |
BYTE * pOut, |
| 669 |
ULONG state, |
| 670 |
CHAR * pCurrentPIN ) |
| 671 |
{ |
| 672 |
// Validate arguments |
| 673 |
if (pOut == 0 || pCurrentPIN == 0 || pCurrentPIN[0] == 0) |
| 674 |
{ |
| 675 |
return eGOBI_ERR_INVALID_ARG; |
| 676 |
} |
| 677 |
|
| 678 |
std::string thePIN( pCurrentPIN ); |
| 679 |
if (thePIN.size() > 4) |
| 680 |
{ |
| 681 |
return eGOBI_ERR_INVALID_ARG; |
| 682 |
} |
| 683 |
|
| 684 |
if (thePIN.find_first_not_of( "0123456789" ) != std::string::npos ) |
| 685 |
{ |
| 686 |
return eGOBI_ERR_INVALID_ARG; |
| 687 |
} |
| 688 |
|
| 689 |
// Check size |
| 690 |
WORD tlvx01Sz = sizeof( sDMSSetLockStateRequest_LockState ); |
| 691 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 692 |
{ |
| 693 |
return eGOBI_ERR_BUFFER_SZ; |
| 694 |
} |
| 695 |
|
| 696 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut); |
| 697 |
pHeader->mTypeID = 0x01; |
| 698 |
pHeader->mLength = tlvx01Sz; |
| 699 |
|
| 700 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 701 |
|
| 702 |
sDMSSetLockStateRequest_LockState * pTLVx01; |
| 703 |
pTLVx01 = (sDMSSetLockStateRequest_LockState*)(pOut + offset); |
| 704 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 705 |
|
| 706 |
// Set the values |
| 707 |
pTLVx01->mLockState = (eQMIDMSLockStates)state; |
| 708 |
memcpy( &pTLVx01->mLockCode[0], thePIN.c_str(), thePIN.size() ); |
| 709 |
|
| 710 |
offset += tlvx01Sz; |
| 711 |
|
| 712 |
*pOutLen = offset; |
| 713 |
return eGOBI_ERR_NONE; |
| 714 |
} |
| 715 |
|
| 716 |
/*=========================================================================== |
| 717 |
METHOD: |
| 718 |
ParseQueryLock |
| 719 |
|
| 720 |
DESCRIPTION: |
| 721 |
This function sets the user lock state maintained by the device |
| 722 |
|
| 723 |
PARAMETERS: |
| 724 |
inLen [ I ] - Length of input buffer |
| 725 |
pIn [ I ] - Input buffer |
| 726 |
pState [ O ] - Current lock state |
| 727 |
|
| 728 |
RETURN VALUE: |
| 729 |
ULONG - Return code |
| 730 |
===========================================================================*/ |
| 731 |
ULONG ParseQueryLock( |
| 732 |
ULONG inLen, |
| 733 |
const BYTE * pIn, |
| 734 |
ULONG * pState ) |
| 735 |
{ |
| 736 |
// Validate arguments |
| 737 |
if (pIn == 0 || pState == 0) |
| 738 |
{ |
| 739 |
return eGOBI_ERR_INVALID_ARG; |
| 740 |
} |
| 741 |
|
| 742 |
// Find the state |
| 743 |
const sDMSGetLockStateResponse_LockState * pTLVx01; |
| 744 |
ULONG outLenx01; |
| 745 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 746 |
if (rc != eGOBI_ERR_NONE) |
| 747 |
{ |
| 748 |
return rc; |
| 749 |
} |
| 750 |
|
| 751 |
if (outLenx01 < sizeof( sDMSGetLockStateResponse_LockState )) |
| 752 |
{ |
| 753 |
return eGOBI_ERR_MALFORMED_RSP; |
| 754 |
} |
| 755 |
|
| 756 |
*pState = pTLVx01->mLockState; |
| 757 |
|
| 758 |
return eGOBI_ERR_NONE; |
| 759 |
} |
| 760 |
|
| 761 |
/*=========================================================================== |
| 762 |
METHOD: |
| 763 |
PackChangeLockPIN |
| 764 |
|
| 765 |
DESCRIPTION: |
| 766 |
This command sets the user lock code maintained by the device |
| 767 |
|
| 768 |
PARAMETERS: |
| 769 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 770 |
contain, upon output the number of BYTEs copied |
| 771 |
to pOut |
| 772 |
pOut [ O ] - Output buffer |
| 773 |
pCurrentPIN [ I ] - Current four digit PIN string |
| 774 |
pDesiredPIN [ I ] - New four digit PIN string |
| 775 |
|
| 776 |
RETURN VALUE: |
| 777 |
ULONG - Return code |
| 778 |
===========================================================================*/ |
| 779 |
ULONG PackChangeLockPIN( |
| 780 |
ULONG * pOutLen, |
| 781 |
BYTE * pOut, |
| 782 |
CHAR * pCurrentPIN, |
| 783 |
CHAR * pDesiredPIN ) |
| 784 |
{ |
| 785 |
// Validate arguments |
| 786 |
if (pOut == 0 |
| 787 |
|| pCurrentPIN == 0 || pCurrentPIN[0] == 0 |
| 788 |
|| pDesiredPIN == 0 || pDesiredPIN[0] == 0) |
| 789 |
{ |
| 790 |
return eGOBI_ERR_INVALID_ARG; |
| 791 |
} |
| 792 |
|
| 793 |
std::string theCurPIN( pCurrentPIN ); |
| 794 |
if (theCurPIN.size() > 4) |
| 795 |
{ |
| 796 |
return eGOBI_ERR_INVALID_ARG; |
| 797 |
} |
| 798 |
|
| 799 |
if (theCurPIN.find_first_not_of( "0123456789" ) != std::string::npos ) |
| 800 |
{ |
| 801 |
return eGOBI_ERR_INVALID_ARG; |
| 802 |
} |
| 803 |
|
| 804 |
std::string theNewPIN( pDesiredPIN ); |
| 805 |
if (theNewPIN.size() > 4) |
| 806 |
{ |
| 807 |
return eGOBI_ERR_INVALID_ARG; |
| 808 |
} |
| 809 |
|
| 810 |
if (theNewPIN.find_first_not_of( "0123456789" ) != std::string::npos ) |
| 811 |
{ |
| 812 |
return eGOBI_ERR_INVALID_ARG; |
| 813 |
} |
| 814 |
|
| 815 |
// Check size |
| 816 |
WORD tlvx01Sz = sizeof( sDMSSetLockCodeRequest_LockCode ); |
| 817 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 818 |
{ |
| 819 |
return eGOBI_ERR_BUFFER_SZ; |
| 820 |
} |
| 821 |
|
| 822 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut); |
| 823 |
pHeader->mTypeID = 0x01; |
| 824 |
pHeader->mLength = tlvx01Sz; |
| 825 |
|
| 826 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 827 |
|
| 828 |
sDMSSetLockCodeRequest_LockCode * pTLVx01; |
| 829 |
pTLVx01 = (sDMSSetLockCodeRequest_LockCode*)(pOut + offset); |
| 830 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 831 |
|
| 832 |
// Set the values |
| 833 |
memcpy( &pTLVx01->mCurrentLockCode[0], |
| 834 |
theCurPIN.c_str(), |
| 835 |
theCurPIN.size() ); |
| 836 |
|
| 837 |
memcpy( &pTLVx01->mNewLockCode[0], |
| 838 |
theNewPIN.c_str(), |
| 839 |
theNewPIN.size() ); |
| 840 |
|
| 841 |
offset += tlvx01Sz; |
| 842 |
|
| 843 |
*pOutLen = offset; |
| 844 |
return eGOBI_ERR_NONE; |
| 845 |
} |
| 846 |
|
| 847 |
/*=========================================================================== |
| 848 |
METHOD: |
| 849 |
ParseGetHardwareRevision |
| 850 |
|
| 851 |
DESCRIPTION: |
| 852 |
This function returns the device hardware revision |
| 853 |
|
| 854 |
PARAMETERS: |
| 855 |
inLen [ I ] - Length of input buffer |
| 856 |
pIn [ I ] - Input buffer |
| 857 |
stringSize [ I ] - The maximum number of characters (including NULL |
| 858 |
terminator) that the string array can contain |
| 859 |
pString [ O ] - NULL terminated string |
| 860 |
|
| 861 |
RETURN VALUE: |
| 862 |
ULONG - Return code |
| 863 |
===========================================================================*/ |
| 864 |
ULONG ParseGetHardwareRevision( |
| 865 |
ULONG inLen, |
| 866 |
const BYTE * pIn, |
| 867 |
BYTE stringSize, |
| 868 |
CHAR * pString ) |
| 869 |
{ |
| 870 |
// Validate arguments |
| 871 |
if (pIn == 0 || pString == 0) |
| 872 |
{ |
| 873 |
return eGOBI_ERR_INVALID_ARG; |
| 874 |
} |
| 875 |
|
| 876 |
// Find the hardware revision |
| 877 |
// sDMSGetHardwareRevisionResponse_HardwareRevision only contains this |
| 878 |
const CHAR * pTLVx01; |
| 879 |
ULONG outLenx01; |
| 880 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 881 |
if (rc != eGOBI_ERR_NONE) |
| 882 |
{ |
| 883 |
return rc; |
| 884 |
} |
| 885 |
|
| 886 |
// Space to perform the copy? |
| 887 |
if (stringSize < outLenx01 + 1) |
| 888 |
{ |
| 889 |
return eGOBI_ERR_BUFFER_SZ; |
| 890 |
} |
| 891 |
|
| 892 |
memcpy( pString, pTLVx01, outLenx01 ); |
| 893 |
pString[outLenx01] = 0; |
| 894 |
|
| 895 |
return eGOBI_ERR_NONE; |
| 896 |
} |
| 897 |
|
| 898 |
/*=========================================================================== |
| 899 |
METHOD: |
| 900 |
ParseGetPRLVersion |
| 901 |
|
| 902 |
DESCRIPTION: |
| 903 |
This function returns the version of the active Preferred Roaming List |
| 904 |
(PRL) in use by the device |
| 905 |
|
| 906 |
PARAMETERS: |
| 907 |
inLen [ I ] - Length of input buffer |
| 908 |
pIn [ I ] - Input buffer |
| 909 |
pPRLVersion [ O ] - The PRL version number |
| 910 |
|
| 911 |
RETURN VALUE: |
| 912 |
ULONG - Return code |
| 913 |
===========================================================================*/ |
| 914 |
ULONG ParseGetPRLVersion( |
| 915 |
ULONG inLen, |
| 916 |
const BYTE * pIn, |
| 917 |
WORD * pPRLVersion ) |
| 918 |
{ |
| 919 |
// Validate arguments |
| 920 |
if (pIn == 0 || pPRLVersion == 0) |
| 921 |
{ |
| 922 |
return eGOBI_ERR_INVALID_ARG; |
| 923 |
} |
| 924 |
|
| 925 |
// Find the state |
| 926 |
const sDMSGetPRLVersionResponse_PRLVersion * pTLVx01; |
| 927 |
ULONG outLenx01; |
| 928 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 929 |
if (rc != eGOBI_ERR_NONE) |
| 930 |
{ |
| 931 |
return rc; |
| 932 |
} |
| 933 |
|
| 934 |
if (outLenx01 < sizeof( sDMSGetPRLVersionResponse_PRLVersion )) |
| 935 |
{ |
| 936 |
return eGOBI_ERR_MALFORMED_RSP; |
| 937 |
} |
| 938 |
|
| 939 |
*pPRLVersion = pTLVx01->mPRLVersion; |
| 940 |
|
| 941 |
return eGOBI_ERR_NONE; |
| 942 |
} |
| 943 |
|
| 944 |
/*=========================================================================== |
| 945 |
METHOD: |
| 946 |
ParseGetERIFile |
| 947 |
|
| 948 |
DESCRIPTION: |
| 949 |
This command returns the ERI file that is stored in EFS on the device |
| 950 |
|
| 951 |
PARAMETERS: |
| 952 |
inLen [ I ] - Length of input buffer |
| 953 |
pIn [ I ] - Input buffer |
| 954 |
pFileSize [I/O] - Upon input the maximum number of bytes that the file |
| 955 |
contents array can contain. Upon successful output |
| 956 |
the actual number of bytes written to the file contents |
| 957 |
array |
| 958 |
pFile [ O ] - The file contents |
| 959 |
|
| 960 |
RETURN VALUE: |
| 961 |
ULONG - Return code |
| 962 |
===========================================================================*/ |
| 963 |
ULONG ParseGetERIFile( |
| 964 |
ULONG inLen, |
| 965 |
const BYTE * pIn, |
| 966 |
ULONG * pFileSize, |
| 967 |
BYTE * pFile ) |
| 968 |
{ |
| 969 |
// Validate arguments |
| 970 |
if (pIn == 0 || pFileSize == 0 || *pFileSize == 0 || pFile == 0) |
| 971 |
{ |
| 972 |
return eGOBI_ERR_INVALID_ARG; |
| 973 |
} |
| 974 |
|
| 975 |
// Assume failure |
| 976 |
ULONG maxFileSize = *pFileSize; |
| 977 |
*pFileSize = 0; |
| 978 |
|
| 979 |
// Find the state |
| 980 |
const sDMSReadERIDataResponse_UserData * pTLVx01; |
| 981 |
ULONG outLenx01; |
| 982 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 983 |
if (rc != eGOBI_ERR_NONE) |
| 984 |
{ |
| 985 |
return rc; |
| 986 |
} |
| 987 |
|
| 988 |
if (outLenx01 < sizeof( sDMSReadERIDataResponse_UserData )) |
| 989 |
{ |
| 990 |
return eGOBI_ERR_MALFORMED_RSP; |
| 991 |
} |
| 992 |
|
| 993 |
ULONG fileSz = pTLVx01->mDataLength; |
| 994 |
const BYTE * pInFile; |
| 995 |
|
| 996 |
// Verify there is room for the array in the TLV |
| 997 |
if (outLenx01 < sizeof( sDMSReadERIDataResponse_UserData ) |
| 998 |
+ sizeof( BYTE ) * fileSz) |
| 999 |
{ |
| 1000 |
return eGOBI_ERR_MALFORMED_RSP; |
| 1001 |
} |
| 1002 |
|
| 1003 |
// Space to copy into? |
| 1004 |
if (fileSz > maxFileSize) |
| 1005 |
{ |
| 1006 |
return eGOBI_ERR_BUFFER_SZ; |
| 1007 |
} |
| 1008 |
|
| 1009 |
// Align to the first array element |
| 1010 |
pInFile = (const BYTE *)pTLVx01 |
| 1011 |
+ sizeof( sDMSReadERIDataResponse_UserData ); |
| 1012 |
|
| 1013 |
// Perform the copy |
| 1014 |
memcpy( pFile, pInFile, fileSz ); |
| 1015 |
*pFileSize = fileSz; |
| 1016 |
|
| 1017 |
return eGOBI_ERR_NONE; |
| 1018 |
} |
| 1019 |
|
| 1020 |
/*=========================================================================== |
| 1021 |
METHOD: |
| 1022 |
PackActivateAutomatic |
| 1023 |
|
| 1024 |
DESCRIPTION: |
| 1025 |
This function requests the device to perform automatic service activation |
| 1026 |
|
| 1027 |
PARAMETERS: |
| 1028 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 1029 |
contain, upon output the number of BYTEs copied |
| 1030 |
to pOut |
| 1031 |
pOut [ O ] - Output buffer |
| 1032 |
pActivationCode [ I ] - Activation code (maximum string length of 12) |
| 1033 |
|
| 1034 |
RETURN VALUE: |
| 1035 |
ULONG - Return code |
| 1036 |
===========================================================================*/ |
| 1037 |
ULONG PackActivateAutomatic( |
| 1038 |
ULONG * pOutLen, |
| 1039 |
BYTE * pOut, |
| 1040 |
CHAR * pActivationCode ) |
| 1041 |
{ |
| 1042 |
// Validate arguments |
| 1043 |
if (pOut == 0 || pActivationCode == 0 || pActivationCode[0] == 0) |
| 1044 |
{ |
| 1045 |
return eGOBI_ERR_INVALID_ARG; |
| 1046 |
} |
| 1047 |
|
| 1048 |
std::string ac( pActivationCode ); |
| 1049 |
if (ac.size() > 12) |
| 1050 |
{ |
| 1051 |
return eGOBI_ERR_INVALID_ARG; |
| 1052 |
} |
| 1053 |
|
| 1054 |
// Check size |
| 1055 |
WORD tlvx01Sz = sizeof( sDMSActivateAutomaticRequest_ActivationCode ) |
| 1056 |
+ (WORD)ac.size(); |
| 1057 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 1058 |
{ |
| 1059 |
return eGOBI_ERR_BUFFER_SZ; |
| 1060 |
} |
| 1061 |
|
| 1062 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut); |
| 1063 |
pHeader->mTypeID = 0x01; |
| 1064 |
pHeader->mLength = tlvx01Sz; |
| 1065 |
|
| 1066 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 1067 |
|
| 1068 |
sDMSActivateAutomaticRequest_ActivationCode * pTLVx01; |
| 1069 |
pTLVx01 = (sDMSActivateAutomaticRequest_ActivationCode*)(pOut + offset); |
| 1070 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 1071 |
|
| 1072 |
// Set the values |
| 1073 |
pTLVx01->mCodeLength = (UINT8)ac.size(); |
| 1074 |
|
| 1075 |
memcpy( (BYTE *)pTLVx01 |
| 1076 |
+ sizeof( sDMSActivateAutomaticRequest_ActivationCode ), |
| 1077 |
ac.c_str(), |
| 1078 |
ac.size() ); |
| 1079 |
|
| 1080 |
offset += tlvx01Sz; |
| 1081 |
|
| 1082 |
*pOutLen = offset; |
| 1083 |
return eGOBI_ERR_NONE; |
| 1084 |
} |
| 1085 |
|
| 1086 |
/*=========================================================================== |
| 1087 |
METHOD: |
| 1088 |
PackResetToFactoryDefaults |
| 1089 |
|
| 1090 |
DESCRIPTION: |
| 1091 |
This function requests the device reset configuration to factory defaults |
| 1092 |
|
| 1093 |
CHANGES: |
| 1094 |
* The client must manually reset the device after this request completes |
| 1095 |
using DMSSetOperatingMode() |
| 1096 |
|
| 1097 |
PARAMETERS: |
| 1098 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 1099 |
contain, upon output the number of BYTEs copied to pOut |
| 1100 |
pOut [ O ] - Output buffer |
| 1101 |
pSPC [ I ] - NULL terminated string representing the six digit |
| 1102 |
service programming code |
| 1103 |
|
| 1104 |
RETURN VALUE: |
| 1105 |
ULONG - Return code |
| 1106 |
===========================================================================*/ |
| 1107 |
ULONG PackResetToFactoryDefaults( |
| 1108 |
ULONG * pOutLen, |
| 1109 |
BYTE * pOut, |
| 1110 |
CHAR * pSPC ) |
| 1111 |
{ |
| 1112 |
// Validate arguments |
| 1113 |
if (pOut == 0 || pSPC == 0 || pSPC[0] == 0) |
| 1114 |
{ |
| 1115 |
return eGOBI_ERR_INVALID_ARG; |
| 1116 |
} |
| 1117 |
|
| 1118 |
std::string spc( pSPC ); |
| 1119 |
if (spc.size() > 6) |
| 1120 |
{ |
| 1121 |
return eGOBI_ERR_INVALID_ARG; |
| 1122 |
} |
| 1123 |
|
| 1124 |
if (spc.find_first_not_of( "0123456789" ) != std::string::npos ) |
| 1125 |
{ |
| 1126 |
return eGOBI_ERR_INVALID_ARG; |
| 1127 |
} |
| 1128 |
|
| 1129 |
// Check size |
| 1130 |
WORD tlvx01Sz = sizeof( sDMSResetFactoryDefaultsRequest_SPC ); |
| 1131 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 1132 |
{ |
| 1133 |
return eGOBI_ERR_BUFFER_SZ; |
| 1134 |
} |
| 1135 |
|
| 1136 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut); |
| 1137 |
pHeader->mTypeID = 0x01; |
| 1138 |
pHeader->mLength = tlvx01Sz; |
| 1139 |
|
| 1140 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 1141 |
|
| 1142 |
// The SPC |
| 1143 |
sDMSResetFactoryDefaultsRequest_SPC * pTLVx01; |
| 1144 |
pTLVx01 = (sDMSResetFactoryDefaultsRequest_SPC*)(pOut + offset); |
| 1145 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 1146 |
|
| 1147 |
// Set the values |
| 1148 |
memcpy( &pTLVx01->mSPC[0], spc.c_str(), spc.size() ); |
| 1149 |
|
| 1150 |
offset += tlvx01Sz; |
| 1151 |
*pOutLen = offset; |
| 1152 |
|
| 1153 |
return eGOBI_ERR_NONE; |
| 1154 |
} |
| 1155 |
|
| 1156 |
/*=========================================================================== |
| 1157 |
METHOD: |
| 1158 |
ParseGetActivationState |
| 1159 |
|
| 1160 |
DESCRIPTION: |
| 1161 |
This function returns the device activation state |
| 1162 |
|
| 1163 |
PARAMETERS: |
| 1164 |
inLen [ I ] - Length of input buffer |
| 1165 |
pIn [ I ] - Input buffer |
| 1166 |
pActivationState [ O ] - Service activation state |
| 1167 |
|
| 1168 |
RETURN VALUE: |
| 1169 |
ULONG - Return code |
| 1170 |
===========================================================================*/ |
| 1171 |
ULONG ParseGetActivationState( |
| 1172 |
ULONG inLen, |
| 1173 |
const BYTE * pIn, |
| 1174 |
ULONG * pActivationState ) |
| 1175 |
{ |
| 1176 |
// Validate arguments |
| 1177 |
if (pIn == 0 || pActivationState == 0) |
| 1178 |
{ |
| 1179 |
return eGOBI_ERR_INVALID_ARG; |
| 1180 |
} |
| 1181 |
|
| 1182 |
// Find the state |
| 1183 |
const sDMSGetActivationStateResponse_ActivationState * pTLVx01; |
| 1184 |
ULONG outLenx01; |
| 1185 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 1186 |
if (rc != eGOBI_ERR_NONE) |
| 1187 |
{ |
| 1188 |
return rc; |
| 1189 |
} |
| 1190 |
|
| 1191 |
if (outLenx01 < sizeof( sDMSGetActivationStateResponse_ActivationState )) |
| 1192 |
{ |
| 1193 |
return eGOBI_ERR_MALFORMED_RSP; |
| 1194 |
} |
| 1195 |
|
| 1196 |
*pActivationState = pTLVx01->mActivationState; |
| 1197 |
|
| 1198 |
return eGOBI_ERR_NONE; |
| 1199 |
} |
| 1200 |
|
| 1201 |
/*=========================================================================== |
| 1202 |
METHOD: |
| 1203 |
PackSetPower |
| 1204 |
|
| 1205 |
DESCRIPTION: |
| 1206 |
This function sets the operating mode of the device |
| 1207 |
|
| 1208 |
PARAMETERS: |
| 1209 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 1210 |
contain, upon output the number of BYTEs copied to pOut |
| 1211 |
pOut [ O ] - Output buffer |
| 1212 |
powerMode [ I ] - Selected operating mode |
| 1213 |
|
| 1214 |
RETURN VALUE: |
| 1215 |
ULONG - Return code |
| 1216 |
===========================================================================*/ |
| 1217 |
ULONG PackSetPower( |
| 1218 |
ULONG * pOutLen, |
| 1219 |
BYTE * pOut, |
| 1220 |
ULONG powerMode ) |
| 1221 |
{ |
| 1222 |
// Validate arguments |
| 1223 |
if (pOut == 0) |
| 1224 |
{ |
| 1225 |
return eGOBI_ERR_INVALID_ARG; |
| 1226 |
} |
| 1227 |
|
| 1228 |
// Check size |
| 1229 |
WORD tlvx01Sz = sizeof( sDMSSetOperatingModeRequest_OperatingMode ); |
| 1230 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 1231 |
{ |
| 1232 |
return eGOBI_ERR_BUFFER_SZ; |
| 1233 |
} |
| 1234 |
|
| 1235 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut); |
| 1236 |
pHeader->mTypeID = 0x01; |
| 1237 |
pHeader->mLength = tlvx01Sz; |
| 1238 |
|
| 1239 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 1240 |
|
| 1241 |
// Set the mode |
| 1242 |
sDMSSetOperatingModeRequest_OperatingMode * pTLVx01; |
| 1243 |
pTLVx01 = (sDMSSetOperatingModeRequest_OperatingMode*)(pOut + offset); |
| 1244 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 1245 |
|
| 1246 |
// Set the values |
| 1247 |
pTLVx01->mOperatingMode = (eQMIDMSOperatingModes)powerMode; |
| 1248 |
|
| 1249 |
offset += tlvx01Sz; |
| 1250 |
*pOutLen = offset; |
| 1251 |
|
| 1252 |
return eGOBI_ERR_NONE; |
| 1253 |
} |
| 1254 |
|
| 1255 |
/*=========================================================================== |
| 1256 |
METHOD: |
| 1257 |
ParseGetPower |
| 1258 |
|
| 1259 |
DESCRIPTION: |
| 1260 |
This function returns the operating mode of the device |
| 1261 |
|
| 1262 |
PARAMETERS: |
| 1263 |
inLen [ I ] - Length of input buffer |
| 1264 |
pIn [ I ] - Input buffer |
| 1265 |
pPowerMode [ O ] - Current operating mode |
| 1266 |
|
| 1267 |
RETURN VALUE: |
| 1268 |
ULONG - Return code |
| 1269 |
===========================================================================*/ |
| 1270 |
ULONG ParseGetPower( |
| 1271 |
ULONG inLen, |
| 1272 |
const BYTE * pIn, |
| 1273 |
ULONG * pPowerMode ) |
| 1274 |
{ |
| 1275 |
// Validate arguments |
| 1276 |
if (pIn == 0 || pPowerMode == 0) |
| 1277 |
{ |
| 1278 |
return eGOBI_ERR_INVALID_ARG; |
| 1279 |
} |
| 1280 |
|
| 1281 |
// Assume failure |
| 1282 |
*pPowerMode = 0xffffffff; |
| 1283 |
|
| 1284 |
// Find the mode |
| 1285 |
const sDMSGetOperatingModeResponse_OperatingMode * pTLVx01; |
| 1286 |
ULONG outLenx01; |
| 1287 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 1288 |
if (rc != eGOBI_ERR_NONE) |
| 1289 |
{ |
| 1290 |
return rc; |
| 1291 |
} |
| 1292 |
|
| 1293 |
if (outLenx01 < sizeof( sDMSGetOperatingModeResponse_OperatingMode )) |
| 1294 |
{ |
| 1295 |
return eGOBI_ERR_MALFORMED_RSP; |
| 1296 |
} |
| 1297 |
|
| 1298 |
*pPowerMode = pTLVx01->mOperatingMode; |
| 1299 |
|
| 1300 |
return eGOBI_ERR_NONE; |
| 1301 |
} |
| 1302 |
|
| 1303 |
/*=========================================================================== |
| 1304 |
METHOD: |
| 1305 |
ParseGetOfflineReason |
| 1306 |
|
| 1307 |
DESCRIPTION: |
| 1308 |
This function returns the reason why the operating mode of the device |
| 1309 |
is currently offline |
| 1310 |
|
| 1311 |
PARAMETERS: |
| 1312 |
inLen [ I ] - Length of input buffer |
| 1313 |
pIn [ I ] - Input buffer |
| 1314 |
pReasonMask [ O ] - Bitmask of offline reasons |
| 1315 |
pbPlatform [ O ] - Offline due to being platform retricted? |
| 1316 |
|
| 1317 |
RETURN VALUE: |
| 1318 |
ULONG - Return code |
| 1319 |
===========================================================================*/ |
| 1320 |
ULONG ParseGetOfflineReason( |
| 1321 |
ULONG inLen, |
| 1322 |
const BYTE * pIn, |
| 1323 |
ULONG * pReasonMask, |
| 1324 |
ULONG * pbPlatform ) |
| 1325 |
{ |
| 1326 |
// Validate arguments |
| 1327 |
if (pIn == 0 || pReasonMask == 0 || pbPlatform == 0) |
| 1328 |
{ |
| 1329 |
return eGOBI_ERR_INVALID_ARG; |
| 1330 |
} |
| 1331 |
|
| 1332 |
// Assume failure |
| 1333 |
*pReasonMask = 0; |
| 1334 |
*pbPlatform = 0; |
| 1335 |
|
| 1336 |
// Find the reason mask (optional) |
| 1337 |
const sDMSGetOperatingModeResponse_OfflineReason * pTLVx10; |
| 1338 |
ULONG outLenx10; |
| 1339 |
ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 ); |
| 1340 |
if (rc == eGOBI_ERR_NONE) |
| 1341 |
{ |
| 1342 |
if (outLenx10 < sizeof( sDMSGetOperatingModeResponse_OfflineReason )) |
| 1343 |
{ |
| 1344 |
return eGOBI_ERR_MALFORMED_RSP; |
| 1345 |
} |
| 1346 |
|
| 1347 |
// Copy the bitmask to pReasonMask |
| 1348 |
*pReasonMask = *(WORD*)pTLVx10; |
| 1349 |
} |
| 1350 |
|
| 1351 |
// Find the platform restriction (optional) |
| 1352 |
const sDMSGetOperatingModeResponse_PlatformRestricted * pTLVx11; |
| 1353 |
ULONG outLenx11; |
| 1354 |
rc = GetTLV( inLen, pIn, 0x11, &outLenx11, (const BYTE **)&pTLVx11 ); |
| 1355 |
if (rc == eGOBI_ERR_NONE) |
| 1356 |
{ |
| 1357 |
if (outLenx11 < sizeof( sDMSGetOperatingModeResponse_PlatformRestricted )) |
| 1358 |
{ |
| 1359 |
return eGOBI_ERR_MALFORMED_RSP; |
| 1360 |
} |
| 1361 |
|
| 1362 |
// Copy the value |
| 1363 |
*pbPlatform = pTLVx11->mPlatformRestricted; |
| 1364 |
} |
| 1365 |
|
| 1366 |
return eGOBI_ERR_NONE; |
| 1367 |
} |
| 1368 |
|
| 1369 |
/*=========================================================================== |
| 1370 |
METHOD: |
| 1371 |
ParseGetNetworkTime |
| 1372 |
|
| 1373 |
DESCRIPTION: |
| 1374 |
This function returns the current time of the device |
| 1375 |
|
| 1376 |
PARAMETERS: |
| 1377 |
inLen [ I ] - Length of input buffer |
| 1378 |
pIn [ I ] - Input buffer |
| 1379 |
pTimeCount [ O ] - Count of 1.25ms that have elapsed from the start |
| 1380 |
of GPS time (Jan 6, 1980) |
| 1381 |
pTimeSource [ O ] - Source of the timestamp |
| 1382 |
|
| 1383 |
RETURN VALUE: |
| 1384 |
ULONG - Return code |
| 1385 |
===========================================================================*/ |
| 1386 |
ULONG ParseGetNetworkTime( |
| 1387 |
ULONG inLen, |
| 1388 |
const BYTE * pIn, |
| 1389 |
ULONGLONG * pTimeCount, |
| 1390 |
ULONG * pTimeSource ) |
| 1391 |
{ |
| 1392 |
// Validate arguments |
| 1393 |
if (pIn == 0 || pTimeCount == 0 || pTimeSource == 0) |
| 1394 |
{ |
| 1395 |
return eGOBI_ERR_INVALID_ARG; |
| 1396 |
} |
| 1397 |
|
| 1398 |
// Find the reason mask |
| 1399 |
const sDMSGetTimestampResponse_Timestamp * pTLVx01; |
| 1400 |
ULONG outLenx01; |
| 1401 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 1402 |
if (rc != eGOBI_ERR_NONE) |
| 1403 |
{ |
| 1404 |
return rc; |
| 1405 |
} |
| 1406 |
|
| 1407 |
if (outLenx01 < sizeof( sDMSGetTimestampResponse_Timestamp )) |
| 1408 |
{ |
| 1409 |
return eGOBI_ERR_MALFORMED_RSP; |
| 1410 |
} |
| 1411 |
|
| 1412 |
// Get the values |
| 1413 |
*pTimeCount = pTLVx01->mTimestamp; |
| 1414 |
// mSource is of type eQMIDMSTimestampSources |
| 1415 |
*pTimeSource = pTLVx01->mSource; |
| 1416 |
|
| 1417 |
return eGOBI_ERR_NONE; |
| 1418 |
} |
| 1419 |
|
| 1420 |
/*=========================================================================== |
| 1421 |
METHOD: |
| 1422 |
PackValidateSPC |
| 1423 |
|
| 1424 |
DESCRIPTION: |
| 1425 |
This function validates the service programming code |
| 1426 |
|
| 1427 |
PARAMETERS: |
| 1428 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 1429 |
contain, upon output the number of BYTEs copied to pOut |
| 1430 |
pOut [ O ] - Output buffer |
| 1431 |
pSPC [ I ] - Six digit service programming code |
| 1432 |
|
| 1433 |
RETURN VALUE: |
| 1434 |
ULONG - Return code |
| 1435 |
===========================================================================*/ |
| 1436 |
ULONG PackValidateSPC( |
| 1437 |
ULONG * pOutLen, |
| 1438 |
BYTE * pOut, |
| 1439 |
CHAR * pSPC ) |
| 1440 |
{ |
| 1441 |
// Validate arguments |
| 1442 |
if (pOut == 0 || pSPC == 0 || pSPC[0] == 0) |
| 1443 |
{ |
| 1444 |
return eGOBI_ERR_INVALID_ARG; |
| 1445 |
} |
| 1446 |
|
| 1447 |
std::string spc( pSPC ); |
| 1448 |
if (spc.size() > 6) |
| 1449 |
{ |
| 1450 |
return eGOBI_ERR_INVALID_ARG; |
| 1451 |
} |
| 1452 |
|
| 1453 |
if (spc.find_first_not_of( "0123456789" ) != std::string::npos ) |
| 1454 |
{ |
| 1455 |
return eGOBI_ERR_INVALID_ARG; |
| 1456 |
} |
| 1457 |
|
| 1458 |
// Check size |
| 1459 |
WORD tlvx01Sz = sizeof( sDMSValidateSPCRequest_SPC ); |
| 1460 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 1461 |
{ |
| 1462 |
return eGOBI_ERR_BUFFER_SZ; |
| 1463 |
} |
| 1464 |
|
| 1465 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)(pOut); |
| 1466 |
pHeader->mTypeID = 0x01; |
| 1467 |
pHeader->mLength = tlvx01Sz; |
| 1468 |
|
| 1469 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 1470 |
|
| 1471 |
// The SPC |
| 1472 |
sDMSValidateSPCRequest_SPC * pTLVx01; |
| 1473 |
pTLVx01 = (sDMSValidateSPCRequest_SPC*)(pOut + offset); |
| 1474 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 1475 |
|
| 1476 |
// Set the values |
| 1477 |
memcpy( &pTLVx01->mSPC[0], spc.c_str(), spc.size() ); |
| 1478 |
|
| 1479 |
offset += tlvx01Sz; |
| 1480 |
*pOutLen = offset; |
| 1481 |
|
| 1482 |
return eGOBI_ERR_NONE; |
| 1483 |
} |