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