| 1 |
/*=========================================================================== |
| 2 |
FILE: |
| 3 |
Gobi3000TranslationUIM.cpp |
| 4 |
|
| 5 |
DESCRIPTION: |
| 6 |
QUALCOMM Translation for Gobi 3000 (DMS_UIM 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 |
ParseUIMUnblockControlKey |
| 43 |
|
| 44 |
DESCRIPTION: |
| 45 |
This function unblocks the specified facility control key |
| 46 |
|
| 47 |
PARAMETERS: |
| 48 |
inLen [ I ] - Length of input buffer |
| 49 |
pIn [ I ] - Input buffer |
| 50 |
pUnblockRetriesLeft [ O ] - The number of unblock retries left, after |
| 51 |
which the control key will be permanently |
| 52 |
blocked |
| 53 |
(0xFFFFFFFF = unknown) |
| 54 |
RETURN VALUE: |
| 55 |
ULONG - Return code |
| 56 |
===========================================================================*/ |
| 57 |
ULONG ParseUIMUnblockControlKey( |
| 58 |
ULONG inLen, |
| 59 |
const BYTE * pIn, |
| 60 |
ULONG * pUnblockRetriesLeft ) |
| 61 |
{ |
| 62 |
// Validate arguments |
| 63 |
if (pIn == 0 || pUnblockRetriesLeft == 0) |
| 64 |
{ |
| 65 |
return eGOBI_ERR_INVALID_ARG; |
| 66 |
} |
| 67 |
|
| 68 |
// Find the TLV |
| 69 |
const sDMSUIMUnblockControlKeyResponse_Status * pTLVx10; |
| 70 |
ULONG outLenx10; |
| 71 |
ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 ); |
| 72 |
if (rc != eGOBI_ERR_NONE) |
| 73 |
{ |
| 74 |
return rc; |
| 75 |
} |
| 76 |
|
| 77 |
// Is the TLV large enough? |
| 78 |
if (outLenx10 < sizeof( sDMSUIMUnblockControlKeyResponse_Status )) |
| 79 |
{ |
| 80 |
return eGOBI_ERR_MALFORMED_RSP; |
| 81 |
} |
| 82 |
|
| 83 |
*pUnblockRetriesLeft = pTLVx10->mRemainingUnblockRetries; |
| 84 |
|
| 85 |
return eGOBI_ERR_NONE; |
| 86 |
} |
| 87 |
|
| 88 |
/*=========================================================================== |
| 89 |
METHOD: |
| 90 |
PackUIMUnblockControlKey |
| 91 |
|
| 92 |
DESCRIPTION: |
| 93 |
This function unblocks the specified facility control key |
| 94 |
|
| 95 |
PARAMETERS: |
| 96 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 97 |
contain, upon output the number of BYTEs copied |
| 98 |
to pOut |
| 99 |
pOut [ O ] - Output buffer |
| 100 |
id [ I ] - Facility ID |
| 101 |
pValue [ I ] - Control key de-personalization string |
| 102 |
|
| 103 |
RETURN VALUE: |
| 104 |
ULONG - Return code |
| 105 |
===========================================================================*/ |
| 106 |
ULONG PackUIMUnblockControlKey( |
| 107 |
ULONG * pOutLen, |
| 108 |
BYTE * pOut, |
| 109 |
ULONG id, |
| 110 |
CHAR * pValue ) |
| 111 |
{ |
| 112 |
// Validate arguments |
| 113 |
if (pOut == 0 |
| 114 |
|| pValue == 0 |
| 115 |
|| pValue[0] == 0) |
| 116 |
{ |
| 117 |
return eGOBI_ERR_INVALID_ARG; |
| 118 |
} |
| 119 |
|
| 120 |
// Add arguments |
| 121 |
std::string val( pValue ); |
| 122 |
UINT8 valSz = (UINT8)val.size(); |
| 123 |
|
| 124 |
// Check size |
| 125 |
WORD tlvx01Sz = sizeof( sDMSUIMUnblockControlKeyRequest_Facility ) + valSz; |
| 126 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 127 |
{ |
| 128 |
return eGOBI_ERR_BUFFER_SZ; |
| 129 |
} |
| 130 |
|
| 131 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut; |
| 132 |
pHeader->mTypeID = 0x01; |
| 133 |
pHeader->mLength = tlvx01Sz; |
| 134 |
|
| 135 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 136 |
|
| 137 |
sDMSUIMUnblockControlKeyRequest_Facility * pTLVx01; |
| 138 |
pTLVx01 = (sDMSUIMUnblockControlKeyRequest_Facility*)(pOut + offset); |
| 139 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 140 |
|
| 141 |
// Set the values |
| 142 |
pTLVx01->mFacility = (eQMIDMSUIMFacility)id; |
| 143 |
pTLVx01->mControlKeyLength = valSz; |
| 144 |
|
| 145 |
offset += sizeof( sDMSUIMUnblockControlKeyRequest_Facility ); |
| 146 |
|
| 147 |
memcpy( (pOut + offset), (LPCSTR)val.c_str(), valSz ); |
| 148 |
offset += valSz; |
| 149 |
|
| 150 |
*pOutLen = offset; |
| 151 |
return eGOBI_ERR_NONE; |
| 152 |
} |
| 153 |
|
| 154 |
/*=========================================================================== |
| 155 |
METHOD: |
| 156 |
ParseUIMSetControlKeyProtection |
| 157 |
|
| 158 |
DESCRIPTION: |
| 159 |
This function changes the specified facility control key |
| 160 |
|
| 161 |
PARAMETERS: |
| 162 |
inLen [ I ] - Length of input buffer |
| 163 |
pIn [ I ] - Input buffer |
| 164 |
pVerifyRetriesLeft [ O ] - Upon operational failure this will indicate |
| 165 |
the number of retries left, after which the |
| 166 |
control key will be blocked |
| 167 |
(0xFFFFFFFF = unknown) |
| 168 |
RETURN VALUE: |
| 169 |
ULONG - Return code |
| 170 |
===========================================================================*/ |
| 171 |
ULONG ParseUIMSetControlKeyProtection( |
| 172 |
ULONG inLen, |
| 173 |
const BYTE * pIn, |
| 174 |
ULONG * pVerifyRetriesLeft ) |
| 175 |
{ |
| 176 |
// Validate arguments |
| 177 |
if (pIn == 0 || pVerifyRetriesLeft == 0) |
| 178 |
{ |
| 179 |
return eGOBI_ERR_INVALID_ARG; |
| 180 |
} |
| 181 |
|
| 182 |
// Find the TLV |
| 183 |
const sDMSUIMSetControlKeyProtectionResponse_Status * pTLVx10; |
| 184 |
ULONG outLenx10; |
| 185 |
ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 ); |
| 186 |
if (rc != eGOBI_ERR_NONE) |
| 187 |
{ |
| 188 |
return rc; |
| 189 |
} |
| 190 |
|
| 191 |
// Is the TLV large enough? |
| 192 |
if (outLenx10 < sizeof( sDMSUIMSetControlKeyProtectionResponse_Status )) |
| 193 |
{ |
| 194 |
return eGOBI_ERR_MALFORMED_RSP; |
| 195 |
} |
| 196 |
|
| 197 |
*pVerifyRetriesLeft = pTLVx10->mRemainingVerifyRetries; |
| 198 |
|
| 199 |
return eGOBI_ERR_NONE; |
| 200 |
} |
| 201 |
|
| 202 |
/*=========================================================================== |
| 203 |
METHOD: |
| 204 |
PackUIMSetControlKeyProtection |
| 205 |
|
| 206 |
DESCRIPTION: |
| 207 |
This function changes the specified facility control key |
| 208 |
|
| 209 |
PARAMETERS: |
| 210 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 211 |
contain, upon output the number of BYTEs copied |
| 212 |
to pOut |
| 213 |
pOut [ O ] - Output buffer |
| 214 |
id [ I ] - Facility ID |
| 215 |
status [ I ] - Control key status |
| 216 |
pValue [ I ] - Control key de-personalization string |
| 217 |
|
| 218 |
RETURN VALUE: |
| 219 |
ULONG - Return code |
| 220 |
===========================================================================*/ |
| 221 |
ULONG PackUIMSetControlKeyProtection( |
| 222 |
ULONG * pOutLen, |
| 223 |
BYTE * pOut, |
| 224 |
ULONG id, |
| 225 |
ULONG status, |
| 226 |
CHAR * pValue ) |
| 227 |
{ |
| 228 |
// Validate arguments |
| 229 |
if (pOut == 0 |
| 230 |
|| pValue == 0 |
| 231 |
|| pValue[0] == 0) |
| 232 |
{ |
| 233 |
return eGOBI_ERR_INVALID_ARG; |
| 234 |
} |
| 235 |
|
| 236 |
// Add arguments |
| 237 |
std::string val( pValue ); |
| 238 |
UINT8 valSz = (UINT8)val.size(); |
| 239 |
|
| 240 |
// Check size |
| 241 |
WORD tlvx01Sz = sizeof( sDMSUIMSetControlKeyProtectionRequest_Facility ) + valSz; |
| 242 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 243 |
{ |
| 244 |
return eGOBI_ERR_BUFFER_SZ; |
| 245 |
} |
| 246 |
|
| 247 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut; |
| 248 |
pHeader->mTypeID = 0x01; |
| 249 |
pHeader->mLength = tlvx01Sz; |
| 250 |
|
| 251 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 252 |
|
| 253 |
sDMSUIMSetControlKeyProtectionRequest_Facility * pTLVx01; |
| 254 |
pTLVx01 = (sDMSUIMSetControlKeyProtectionRequest_Facility*)(pOut + offset); |
| 255 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 256 |
|
| 257 |
// Set the values |
| 258 |
pTLVx01->mFacility = (eQMIDMSUIMFacility)id; |
| 259 |
pTLVx01->mFacilityState = (eQMIDMSUIMFacilityStates)status; |
| 260 |
pTLVx01->mControlKeyLength = (UINT8)valSz; |
| 261 |
|
| 262 |
offset += sizeof( sDMSUIMSetControlKeyProtectionRequest_Facility ); |
| 263 |
|
| 264 |
memcpy( (pOut + offset), val.c_str(), valSz ); |
| 265 |
offset += valSz; |
| 266 |
|
| 267 |
*pOutLen = offset; |
| 268 |
return eGOBI_ERR_NONE; |
| 269 |
} |
| 270 |
|
| 271 |
/*=========================================================================== |
| 272 |
METHOD: |
| 273 |
ParseUIMGetControlKeyBlockingStatus |
| 274 |
|
| 275 |
DESCRIPTION: |
| 276 |
This function returns the status of the specified facility control key |
| 277 |
|
| 278 |
PARAMETERS: |
| 279 |
inLen [ I ] - Length of input buffer |
| 280 |
pIn [ I ] - Input buffer |
| 281 |
pStatus [ O ] - Control key status |
| 282 |
pVerifyRetriesLeft [ O ] - The number of retries left, after which the |
| 283 |
control key will be blocked |
| 284 |
pUnblockRetriesLeft [ O ] - The number of unblock retries left, after |
| 285 |
which the control key will be permanently |
| 286 |
blocked |
| 287 |
pbBlocking [ O ] - (Optional) Is the facility blocking? |
| 288 |
|
| 289 |
RETURN VALUE: |
| 290 |
ULONG - Return code |
| 291 |
===========================================================================*/ |
| 292 |
ULONG ParseUIMGetControlKeyBlockingStatus( |
| 293 |
ULONG inLen, |
| 294 |
const BYTE * pIn, |
| 295 |
ULONG * pStatus, |
| 296 |
ULONG * pVerifyRetriesLeft, |
| 297 |
ULONG * pUnblockRetriesLeft, |
| 298 |
ULONG * pbBlocking ) |
| 299 |
{ |
| 300 |
// Validate arguments |
| 301 |
if (pIn == 0 |
| 302 |
|| pStatus == 0 |
| 303 |
|| pVerifyRetriesLeft == 0 |
| 304 |
|| pUnblockRetriesLeft == 0) |
| 305 |
{ |
| 306 |
return eGOBI_ERR_INVALID_ARG; |
| 307 |
} |
| 308 |
|
| 309 |
// Find the first arguments |
| 310 |
const sDMSUIMGetControlKeyStatusResponse_Status * pTLVx01; |
| 311 |
ULONG outLenx01; |
| 312 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 313 |
if (rc != eGOBI_ERR_NONE) |
| 314 |
{ |
| 315 |
return rc; |
| 316 |
} |
| 317 |
|
| 318 |
// Is the TLV large enough? |
| 319 |
if (outLenx01 < sizeof( sDMSUIMGetControlKeyStatusResponse_Status )) |
| 320 |
{ |
| 321 |
return eGOBI_ERR_MALFORMED_RSP; |
| 322 |
} |
| 323 |
|
| 324 |
*pVerifyRetriesLeft = pTLVx01->mRemainingVerifyRetries; |
| 325 |
*pUnblockRetriesLeft = pTLVx01->mRemainingUnblockRetries; |
| 326 |
*pStatus = pTLVx01->mFacilityState; |
| 327 |
|
| 328 |
// Find the last (optional) argument |
| 329 |
if (pbBlocking != 0) |
| 330 |
{ |
| 331 |
const sDMSUIMGetControlKeyStatusResponse_Blocking * pTLVx10; |
| 332 |
ULONG tlvLenx10; |
| 333 |
rc = GetTLV( inLen, pIn, 0x10, &tlvLenx10, (const BYTE **)&pTLVx10 ); |
| 334 |
if (rc != eGOBI_ERR_NONE) |
| 335 |
{ |
| 336 |
return rc; |
| 337 |
} |
| 338 |
|
| 339 |
// Is the TLV large enough? |
| 340 |
if (tlvLenx10 < sizeof( sDMSUIMGetControlKeyStatusResponse_Blocking )) |
| 341 |
{ |
| 342 |
return eGOBI_ERR_MALFORMED_RSP; |
| 343 |
} |
| 344 |
|
| 345 |
*pbBlocking = pTLVx10->mOperationBlocking; |
| 346 |
} |
| 347 |
|
| 348 |
return eGOBI_ERR_NONE; |
| 349 |
} |
| 350 |
|
| 351 |
/*=========================================================================== |
| 352 |
METHOD: |
| 353 |
PackUIMGetControlKeyBlockingStatus |
| 354 |
|
| 355 |
DESCRIPTION: |
| 356 |
This function returns the status of the specified facility control key |
| 357 |
|
| 358 |
PARAMETERS: |
| 359 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 360 |
contain, upon output the number of BYTEs copied |
| 361 |
to pOut |
| 362 |
pOut [ O ] - Output buffer |
| 363 |
id [ I ] - Facility ID |
| 364 |
|
| 365 |
RETURN VALUE: |
| 366 |
ULONG - Return code |
| 367 |
===========================================================================*/ |
| 368 |
ULONG PackUIMGetControlKeyBlockingStatus( |
| 369 |
ULONG * pOutLen, |
| 370 |
BYTE * pOut, |
| 371 |
ULONG id ) |
| 372 |
{ |
| 373 |
// Validate arguments |
| 374 |
if (pOut == 0) |
| 375 |
{ |
| 376 |
return eGOBI_ERR_INVALID_ARG; |
| 377 |
} |
| 378 |
|
| 379 |
// Add id |
| 380 |
|
| 381 |
// Check size |
| 382 |
WORD tlvx01Sz = sizeof( sDMSUIMGetControlKeyStatusRequest_Facility ); |
| 383 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 384 |
{ |
| 385 |
return eGOBI_ERR_BUFFER_SZ; |
| 386 |
} |
| 387 |
|
| 388 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut; |
| 389 |
pHeader->mTypeID = 0x01; |
| 390 |
pHeader->mLength = tlvx01Sz; |
| 391 |
|
| 392 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 393 |
|
| 394 |
sDMSUIMGetControlKeyStatusRequest_Facility * pTLVx01; |
| 395 |
pTLVx01 = (sDMSUIMGetControlKeyStatusRequest_Facility*)(pOut + offset); |
| 396 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 397 |
|
| 398 |
// Set the values |
| 399 |
pTLVx01->mFacility = (eQMIDMSUIMFacility)id; |
| 400 |
|
| 401 |
offset += tlvx01Sz; |
| 402 |
|
| 403 |
*pOutLen = offset; |
| 404 |
|
| 405 |
return eGOBI_ERR_NONE; |
| 406 |
} |
| 407 |
|
| 408 |
/*=========================================================================== |
| 409 |
METHOD: |
| 410 |
ParseUIMGetControlKeyStatus |
| 411 |
|
| 412 |
DESCRIPTION: |
| 413 |
This function returns the status of the specified facility control key |
| 414 |
|
| 415 |
PARAMETERS: |
| 416 |
inLen [ I ] - Length of input buffer |
| 417 |
pIn [ I ] - Input buffer |
| 418 |
pStatus [ O ] - Control key status |
| 419 |
pVerifyRetriesLeft [ O ] - The number of retries left, after which the |
| 420 |
control key will be blocked |
| 421 |
pUnblockRetriesLeft [ O ] - The number of unblock retries left, after |
| 422 |
which the control key will be permanently |
| 423 |
blocked |
| 424 |
|
| 425 |
RETURN VALUE: |
| 426 |
ULONG - Return code |
| 427 |
===========================================================================*/ |
| 428 |
ULONG ParseUIMGetControlKeyStatus( |
| 429 |
ULONG inLen, |
| 430 |
const BYTE * pIn, |
| 431 |
ULONG * pStatus, |
| 432 |
ULONG * pVerifyRetriesLeft, |
| 433 |
ULONG * pUnblockRetriesLeft ) |
| 434 |
{ |
| 435 |
// Validate arguments |
| 436 |
if (pIn == 0 |
| 437 |
|| pStatus == 0 |
| 438 |
|| pVerifyRetriesLeft == 0 |
| 439 |
|| pUnblockRetriesLeft == 0) |
| 440 |
{ |
| 441 |
return eGOBI_ERR_INVALID_ARG; |
| 442 |
} |
| 443 |
|
| 444 |
// Find the arguments |
| 445 |
const sDMSUIMGetControlKeyStatusResponse_Status * pTLVx01; |
| 446 |
ULONG outLenx01; |
| 447 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 448 |
if (rc != eGOBI_ERR_NONE) |
| 449 |
{ |
| 450 |
return rc; |
| 451 |
} |
| 452 |
|
| 453 |
// Is the TLV large enough? |
| 454 |
if (outLenx01 < sizeof( sDMSUIMGetControlKeyStatusResponse_Status )) |
| 455 |
{ |
| 456 |
return eGOBI_ERR_MALFORMED_RSP; |
| 457 |
} |
| 458 |
|
| 459 |
*pVerifyRetriesLeft = pTLVx01->mRemainingVerifyRetries; |
| 460 |
*pUnblockRetriesLeft = pTLVx01->mRemainingUnblockRetries; |
| 461 |
*pStatus = pTLVx01->mFacilityState; |
| 462 |
|
| 463 |
return eGOBI_ERR_NONE; |
| 464 |
} |
| 465 |
|
| 466 |
/*=========================================================================== |
| 467 |
METHOD: |
| 468 |
PackUIMGetControlKeyStatus |
| 469 |
|
| 470 |
DESCRIPTION: |
| 471 |
This function requests the status of the specified facility control key |
| 472 |
|
| 473 |
PARAMETERS: |
| 474 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 475 |
contain, upon output the number of BYTEs copied |
| 476 |
to pOut |
| 477 |
pOut [ O ] - Output buffer |
| 478 |
id [ I ] - Facility ID |
| 479 |
|
| 480 |
RETURN VALUE: |
| 481 |
ULONG - Return code |
| 482 |
===========================================================================*/ |
| 483 |
ULONG PackUIMGetControlKeyStatus( |
| 484 |
ULONG * pOutLen, |
| 485 |
BYTE * pOut, |
| 486 |
ULONG id ) |
| 487 |
{ |
| 488 |
// Request is the same as PackUIMGetControlKeyBlockingStatus |
| 489 |
return PackUIMGetControlKeyBlockingStatus( pOutLen, |
| 490 |
pOut, |
| 491 |
id ); |
| 492 |
} |
| 493 |
|
| 494 |
/*=========================================================================== |
| 495 |
METHOD: |
| 496 |
ParseUIMGetICCID |
| 497 |
|
| 498 |
DESCRIPTION: |
| 499 |
This function returns the UIM ICCID |
| 500 |
|
| 501 |
PARAMETERS: |
| 502 |
inLen [ I ] - Length of input buffer |
| 503 |
pIn [ I ] - Input buffer |
| 504 |
stringSize [ I ] - The maximum number of characters (including NULL |
| 505 |
terminator) that the string array can contain |
| 506 |
pString [ O ] - NULL terminated string |
| 507 |
|
| 508 |
RETURN VALUE: |
| 509 |
ULONG - Return code |
| 510 |
===========================================================================*/ |
| 511 |
ULONG ParseUIMGetICCID( |
| 512 |
ULONG inLen, |
| 513 |
const BYTE * pIn, |
| 514 |
BYTE stringSize, |
| 515 |
CHAR * pString ) |
| 516 |
{ |
| 517 |
// Validate arguments |
| 518 |
if (pIn == 0 || stringSize == 0 || pString == 0) |
| 519 |
{ |
| 520 |
return eGOBI_ERR_INVALID_ARG; |
| 521 |
} |
| 522 |
|
| 523 |
// Find the TLV |
| 524 |
const sDMSUIMGetICCIDResponse_ICCID * pTLVx01; |
| 525 |
ULONG outLenx01; |
| 526 |
ULONG rc = GetTLV( inLen, pIn, 0x01, &outLenx01, (const BYTE **)&pTLVx01 ); |
| 527 |
if (rc != eGOBI_ERR_NONE) |
| 528 |
{ |
| 529 |
return rc; |
| 530 |
} |
| 531 |
|
| 532 |
// Is the TLV large enough? |
| 533 |
if (outLenx01 < sizeof( sDMSUIMGetICCIDResponse_ICCID )) |
| 534 |
{ |
| 535 |
return eGOBI_ERR_MALFORMED_RSP; |
| 536 |
} |
| 537 |
|
| 538 |
// The TLV only contains the string |
| 539 |
|
| 540 |
// Space to perform the copy? |
| 541 |
if (stringSize < outLenx01 + 1) |
| 542 |
{ |
| 543 |
return eGOBI_ERR_BUFFER_SZ; |
| 544 |
} |
| 545 |
|
| 546 |
memcpy( pString, (const CHAR*)pTLVx01, outLenx01 ); |
| 547 |
pString[outLenx01] = 0; |
| 548 |
|
| 549 |
return eGOBI_ERR_NONE; |
| 550 |
} |
| 551 |
|
| 552 |
/*=========================================================================== |
| 553 |
METHOD: |
| 554 |
ParseUIMGetPINStatus |
| 555 |
|
| 556 |
DESCRIPTION: |
| 557 |
This function returns the status of the pin |
| 558 |
|
| 559 |
PARAMETERS: |
| 560 |
inLen [ I ] - Length of input buffer |
| 561 |
pIn [ I ] - Input buffer |
| 562 |
id [ I ] - PIN ID (1/2) |
| 563 |
pStatus [ O ] - PIN status (0xFFFFFFFF = unknown) |
| 564 |
pVerifyRetriesLeft [ O ] - The number of retries left, after which the |
| 565 |
PIN will be blocked (0xFFFFFFFF = unknown) |
| 566 |
pUnblockRetriesLeft [ O ] - The number of unblock retries left, after |
| 567 |
which the PIN will be permanently blocked, |
| 568 |
i.e. UIM is unusable (0xFFFFFFFF = unknown) |
| 569 |
|
| 570 |
RETURN VALUE: |
| 571 |
ULONG - Return code |
| 572 |
===========================================================================*/ |
| 573 |
ULONG ParseUIMGetPINStatus( |
| 574 |
ULONG inLen, |
| 575 |
const BYTE * pIn, |
| 576 |
ULONG id, |
| 577 |
ULONG * pStatus, |
| 578 |
ULONG * pVerifyRetriesLeft, |
| 579 |
ULONG * pUnblockRetriesLeft ) |
| 580 |
{ |
| 581 |
// Validate arguments |
| 582 |
if (pIn == 0 |
| 583 |
|| id < 1 |
| 584 |
|| id > 2 |
| 585 |
|| pStatus == 0 |
| 586 |
|| pVerifyRetriesLeft == 0 |
| 587 |
|| pUnblockRetriesLeft == 0) |
| 588 |
{ |
| 589 |
return eGOBI_ERR_INVALID_ARG; |
| 590 |
} |
| 591 |
|
| 592 |
ULONG tlvLen; |
| 593 |
|
| 594 |
// The typeID is either 0x11 or 0x12 |
| 595 |
if (id == 1) |
| 596 |
{ |
| 597 |
const sDMSUIMGetPINStatusResponse_PIN1Status * pTLV11; |
| 598 |
ULONG rc = GetTLV( inLen, pIn, 0x11, &tlvLen, (const BYTE **)&pTLV11 ); |
| 599 |
|
| 600 |
if (rc != eGOBI_ERR_NONE) |
| 601 |
{ |
| 602 |
return rc; |
| 603 |
} |
| 604 |
|
| 605 |
// Is the TLV large enough? |
| 606 |
if (tlvLen < sizeof( sDMSUIMGetPINStatusResponse_PIN1Status )) |
| 607 |
{ |
| 608 |
return eGOBI_ERR_MALFORMED_RSP; |
| 609 |
} |
| 610 |
|
| 611 |
*pVerifyRetriesLeft = pTLV11->mRemainingVerifyRetries; |
| 612 |
*pUnblockRetriesLeft = pTLV11->mRemainingUnblockRetries; |
| 613 |
*pStatus = pTLV11->mPINStatus; |
| 614 |
} |
| 615 |
else if (id == 2) |
| 616 |
{ |
| 617 |
const sDMSUIMGetPINStatusResponse_PIN2Status * pTLV12; |
| 618 |
ULONG rc = GetTLV( inLen, pIn, 0x12, &tlvLen, (const BYTE **)&pTLV12 ); |
| 619 |
|
| 620 |
if (rc != eGOBI_ERR_NONE) |
| 621 |
{ |
| 622 |
return rc; |
| 623 |
} |
| 624 |
|
| 625 |
// Is the TLV large enough? |
| 626 |
if (tlvLen < sizeof( sDMSUIMGetPINStatusResponse_PIN2Status )) |
| 627 |
{ |
| 628 |
return eGOBI_ERR_MALFORMED_RSP; |
| 629 |
} |
| 630 |
|
| 631 |
*pVerifyRetriesLeft = pTLV12->mRemainingVerifyRetries; |
| 632 |
*pUnblockRetriesLeft = pTLV12->mRemainingUnblockRetries; |
| 633 |
*pStatus = pTLV12->mPINStatus; |
| 634 |
} |
| 635 |
else |
| 636 |
{ |
| 637 |
return eGOBI_ERR_INVALID_ARG; |
| 638 |
} |
| 639 |
|
| 640 |
return eGOBI_ERR_NONE; |
| 641 |
} |
| 642 |
|
| 643 |
/*=========================================================================== |
| 644 |
METHOD: |
| 645 |
ParseUIMChangePIN |
| 646 |
|
| 647 |
DESCRIPTION: |
| 648 |
This function changes the PIN value |
| 649 |
|
| 650 |
PARAMETERS: |
| 651 |
inLen [ I ] - Length of input buffer |
| 652 |
pIn [ I ] - Input buffer |
| 653 |
pVerifyRetriesLeft [ O ] - Upon operational failure this will indicate |
| 654 |
the number of retries left, after which the |
| 655 |
PIN will be blocked (0xFFFFFFFF = unknown) |
| 656 |
pUnblockRetriesLeft [ O ] - Upon operational failure this will indicate |
| 657 |
the number of unblock retries left, after |
| 658 |
which the PIN will be permanently blocked, |
| 659 |
i.e. UIM is unusable (0xFFFFFFFF = unknown) |
| 660 |
|
| 661 |
RETURN VALUE: |
| 662 |
ULONG - Return code |
| 663 |
===========================================================================*/ |
| 664 |
ULONG ParseUIMChangePIN( |
| 665 |
ULONG inLen, |
| 666 |
const BYTE * pIn, |
| 667 |
ULONG * pVerifyRetriesLeft, |
| 668 |
ULONG * pUnblockRetriesLeft ) |
| 669 |
{ |
| 670 |
// Validate arguments |
| 671 |
if (pIn == 0 || pVerifyRetriesLeft == 0 || pUnblockRetriesLeft == 0) |
| 672 |
{ |
| 673 |
return eGOBI_ERR_INVALID_ARG; |
| 674 |
} |
| 675 |
|
| 676 |
// Find the TLV |
| 677 |
const sDMSUIMChangePINResponse_RetryInfo * pTLVx10; |
| 678 |
ULONG outLenx10; |
| 679 |
ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 ); |
| 680 |
if (rc != eGOBI_ERR_NONE) |
| 681 |
{ |
| 682 |
return rc; |
| 683 |
} |
| 684 |
|
| 685 |
// Is the TLV large enough? |
| 686 |
if (outLenx10 < sizeof( sDMSUIMChangePINResponse_RetryInfo )) |
| 687 |
{ |
| 688 |
return eGOBI_ERR_MALFORMED_RSP; |
| 689 |
} |
| 690 |
|
| 691 |
*pVerifyRetriesLeft = pTLVx10->mRemainingVerifyRetries; |
| 692 |
*pUnblockRetriesLeft = pTLVx10->mRemainingUnblockRetries; |
| 693 |
|
| 694 |
return eGOBI_ERR_NONE; |
| 695 |
} |
| 696 |
|
| 697 |
/*=========================================================================== |
| 698 |
METHOD: |
| 699 |
PackUIMChangePIN |
| 700 |
|
| 701 |
DESCRIPTION: |
| 702 |
This function changes the PIN value |
| 703 |
|
| 704 |
PARAMETERS: |
| 705 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 706 |
contain, upon output the number of BYTEs copied |
| 707 |
to pOut |
| 708 |
pOut [ O ] - Output buffer |
| 709 |
id [ I ] - PIN ID (1/2) |
| 710 |
pOldValue [ I ] - Old PIN value of the PIN to change |
| 711 |
pNewValue [ I ] - New PIN value of the PIN to change |
| 712 |
|
| 713 |
RETURN VALUE: |
| 714 |
ULONG - Return code |
| 715 |
===========================================================================*/ |
| 716 |
ULONG PackUIMChangePIN( |
| 717 |
ULONG * pOutLen, |
| 718 |
BYTE * pOut, |
| 719 |
ULONG id, |
| 720 |
CHAR * pOldValue, |
| 721 |
CHAR * pNewValue ) |
| 722 |
{ |
| 723 |
// Validate arguments |
| 724 |
if (pOut == 0 |
| 725 |
|| id < 1 |
| 726 |
|| id > 2 |
| 727 |
|| pOldValue == 0 |
| 728 |
|| pOldValue[0] == 0 |
| 729 |
|| pNewValue == 0 |
| 730 |
|| pNewValue[0] == 0 ) |
| 731 |
{ |
| 732 |
return eGOBI_ERR_INVALID_ARG; |
| 733 |
} |
| 734 |
|
| 735 |
// Add arguments |
| 736 |
std::string oldVal( pOldValue ); |
| 737 |
ULONG oldValSz = (ULONG)oldVal.size(); |
| 738 |
std::string newVal( pNewValue ); |
| 739 |
ULONG newValSz = (ULONG)newVal.size(); |
| 740 |
|
| 741 |
// Check size |
| 742 |
WORD tlvx01Sz = sizeof( sDMSUIMChangePINRequest_Info ) |
| 743 |
+ (WORD)oldValSz + (WORD)newValSz; |
| 744 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 745 |
{ |
| 746 |
return eGOBI_ERR_BUFFER_SZ; |
| 747 |
} |
| 748 |
|
| 749 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut; |
| 750 |
pHeader->mTypeID = 0x01; |
| 751 |
pHeader->mLength = tlvx01Sz; |
| 752 |
|
| 753 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 754 |
|
| 755 |
// First part of the TLV |
| 756 |
sDMSUIMChangePINRequest_Info1 * pTLVx01_1; |
| 757 |
pTLVx01_1 = (sDMSUIMChangePINRequest_Info1*)(pOut + offset); |
| 758 |
memset( pTLVx01_1, 0, tlvx01Sz ); |
| 759 |
|
| 760 |
pTLVx01_1->mPINID = (UINT8)id; |
| 761 |
pTLVx01_1->mOldPINLength = (UINT8)oldValSz; |
| 762 |
offset += sizeof( sDMSUIMChangePINRequest_Info1 ); |
| 763 |
|
| 764 |
// mOldPINValue string |
| 765 |
memcpy( (pOut + offset), oldVal.c_str(), oldValSz ); |
| 766 |
offset += oldValSz; |
| 767 |
|
| 768 |
// Second part of the TLV |
| 769 |
sDMSUIMChangePINRequest_Info2 * pTLVx01_2; |
| 770 |
pTLVx01_2 = (sDMSUIMChangePINRequest_Info2*)(pOut + offset); |
| 771 |
|
| 772 |
pTLVx01_2->mNewPINLength = (UINT8)newValSz; |
| 773 |
offset += sizeof( sDMSUIMChangePINRequest_Info2 ); |
| 774 |
|
| 775 |
// mNewPINValue string |
| 776 |
memcpy( (pOut + offset), newVal.c_str(), newValSz ); |
| 777 |
offset += newValSz; |
| 778 |
|
| 779 |
*pOutLen = offset; |
| 780 |
|
| 781 |
return eGOBI_ERR_NONE; |
| 782 |
} |
| 783 |
|
| 784 |
/*=========================================================================== |
| 785 |
METHOD: |
| 786 |
ParseUIMUnblockPIN |
| 787 |
|
| 788 |
DESCRIPTION: |
| 789 |
This function unblocks a blocked PIN |
| 790 |
|
| 791 |
PARAMETERS: |
| 792 |
inLen [ I ] - Length of input buffer |
| 793 |
pIn [ I ] - Input buffer |
| 794 |
pVerifyRetriesLeft [ O ] - Upon operational failure this will indicate |
| 795 |
the number of retries left, after which the |
| 796 |
PIN will be blocked (0xFFFFFFFF = unknown) |
| 797 |
pUnblockRetriesLeft [ O ] - Upon operational failure this will indicate |
| 798 |
the number of unblock retries left, after |
| 799 |
which the PIN will be permanently blocked, |
| 800 |
i.e. UIM is unusable (0xFFFFFFFF = unknown) |
| 801 |
|
| 802 |
RETURN VALUE: |
| 803 |
ULONG - Return code |
| 804 |
===========================================================================*/ |
| 805 |
ULONG ParseUIMUnblockPIN( |
| 806 |
ULONG inLen, |
| 807 |
const BYTE * pIn, |
| 808 |
ULONG * pVerifyRetriesLeft, |
| 809 |
ULONG * pUnblockRetriesLeft ) |
| 810 |
{ |
| 811 |
// Validate arguments |
| 812 |
if (pIn == 0 || pVerifyRetriesLeft == 0 || pUnblockRetriesLeft == 0) |
| 813 |
{ |
| 814 |
return eGOBI_ERR_INVALID_ARG; |
| 815 |
} |
| 816 |
|
| 817 |
// Find the TLV |
| 818 |
const sDMSUIMUnblockPINResponse_RetryInfo * pTLVx10; |
| 819 |
ULONG outLenx10; |
| 820 |
ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 ); |
| 821 |
if (rc != eGOBI_ERR_NONE) |
| 822 |
{ |
| 823 |
return rc; |
| 824 |
} |
| 825 |
|
| 826 |
// Is the TLV large enough? |
| 827 |
if (outLenx10 < sizeof( sDMSUIMUnblockPINResponse_RetryInfo )) |
| 828 |
{ |
| 829 |
return eGOBI_ERR_MALFORMED_RSP; |
| 830 |
} |
| 831 |
|
| 832 |
*pVerifyRetriesLeft = pTLVx10->mRemainingVerifyRetries; |
| 833 |
*pUnblockRetriesLeft = pTLVx10->mRemainingUnblockRetries; |
| 834 |
|
| 835 |
return eGOBI_ERR_NONE; |
| 836 |
} |
| 837 |
|
| 838 |
/*=========================================================================== |
| 839 |
METHOD: |
| 840 |
PackUIMUnblockPIN |
| 841 |
|
| 842 |
DESCRIPTION: |
| 843 |
This function unblocks a blocked PIN |
| 844 |
|
| 845 |
PARAMETERS: |
| 846 |
id [ I ] - PIN ID (1/2) |
| 847 |
pPUKValue [ I ] - PUK value of the PIN to unblock |
| 848 |
pNewValue [ I ] - New PIN value of the PIN to unblock |
| 849 |
|
| 850 |
RETURN VALUE: |
| 851 |
ULONG - Return code |
| 852 |
===========================================================================*/ |
| 853 |
ULONG PackUIMUnblockPIN( |
| 854 |
ULONG * pOutLen, |
| 855 |
BYTE * pOut, |
| 856 |
ULONG id, |
| 857 |
CHAR * pPUKValue, |
| 858 |
CHAR * pNewValue ) |
| 859 |
{ |
| 860 |
// Validate arguments |
| 861 |
if (pOut == 0 |
| 862 |
|| id < 1 |
| 863 |
|| id > 2 |
| 864 |
|| pPUKValue == 0 |
| 865 |
|| pPUKValue[0] == 0 |
| 866 |
|| pNewValue == 0 |
| 867 |
|| pNewValue[0] == 0 ) |
| 868 |
{ |
| 869 |
return eGOBI_ERR_INVALID_ARG; |
| 870 |
} |
| 871 |
|
| 872 |
// Add arguments |
| 873 |
std::string oldVal( pPUKValue ); |
| 874 |
ULONG oldValSz = (ULONG)oldVal.size(); |
| 875 |
std::string newVal( pNewValue ); |
| 876 |
ULONG newValSz = (ULONG)newVal.size(); |
| 877 |
|
| 878 |
// Check size |
| 879 |
WORD tlvx01Sz = sizeof( sDMSUIMUnblockPINRequest_Info ) |
| 880 |
+ (WORD)oldValSz + (WORD)newValSz; |
| 881 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 882 |
{ |
| 883 |
return eGOBI_ERR_BUFFER_SZ; |
| 884 |
} |
| 885 |
|
| 886 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut; |
| 887 |
pHeader->mTypeID = 0x01; |
| 888 |
pHeader->mLength = tlvx01Sz; |
| 889 |
|
| 890 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 891 |
|
| 892 |
// First part of the TLV |
| 893 |
sDMSUIMUnblockPINRequest_Info1 * pTLVx01_1; |
| 894 |
pTLVx01_1 = (sDMSUIMUnblockPINRequest_Info1*)(pOut + offset); |
| 895 |
memset( pTLVx01_1, 0, tlvx01Sz ); |
| 896 |
|
| 897 |
pTLVx01_1->mPINID = (UINT8)id; |
| 898 |
pTLVx01_1->mPUKLength = (UINT8)oldValSz; |
| 899 |
offset += sizeof( sDMSUIMUnblockPINRequest_Info1 ); |
| 900 |
|
| 901 |
// mPUKValue string |
| 902 |
memcpy( (pOut + offset), oldVal.c_str(), oldValSz ); |
| 903 |
offset += oldValSz; |
| 904 |
|
| 905 |
// Second part of the TLV |
| 906 |
sDMSUIMUnblockPINRequest_Info2 * pTLVx01_2; |
| 907 |
pTLVx01_2 = (sDMSUIMUnblockPINRequest_Info2*)(pOut + offset); |
| 908 |
|
| 909 |
pTLVx01_2->mNewPINLength = (UINT8)newValSz; |
| 910 |
offset += sizeof( sDMSUIMUnblockPINRequest_Info2 ); |
| 911 |
|
| 912 |
// mNewPINValue string |
| 913 |
memcpy( (pOut + offset), newVal.c_str(), newValSz ); |
| 914 |
offset += newValSz; |
| 915 |
|
| 916 |
*pOutLen = offset; |
| 917 |
|
| 918 |
return eGOBI_ERR_NONE; |
| 919 |
} |
| 920 |
|
| 921 |
/*=========================================================================== |
| 922 |
METHOD: |
| 923 |
ParseUIMVerifyPIN |
| 924 |
|
| 925 |
DESCRIPTION: |
| 926 |
This function verifies the PIN before accessing the UIM contents |
| 927 |
|
| 928 |
PARAMETERS: |
| 929 |
inLen [ I ] - Length of input buffer |
| 930 |
pIn [ I ] - Input buffer |
| 931 |
pVerifyRetriesLeft [ O ] - Upon operational failure this will indicate |
| 932 |
the number of retries left, after which the |
| 933 |
PIN will be blocked (0xFFFFFFFF = unknown) |
| 934 |
pUnblockRetriesLeft [ O ] - Upon operational failure this will indicate |
| 935 |
the number of unblock retries left, after |
| 936 |
which the PIN will be permanently blocked, |
| 937 |
i.e. UIM is unusable (0xFFFFFFFF = unknown) |
| 938 |
|
| 939 |
RETURN VALUE: |
| 940 |
ULONG - Return code |
| 941 |
===========================================================================*/ |
| 942 |
ULONG ParseUIMVerifyPIN( |
| 943 |
ULONG inLen, |
| 944 |
const BYTE * pIn, |
| 945 |
ULONG * pVerifyRetriesLeft, |
| 946 |
ULONG * pUnblockRetriesLeft ) |
| 947 |
{ |
| 948 |
// Validate arguments |
| 949 |
if (pIn == 0 || pVerifyRetriesLeft == 0 || pUnblockRetriesLeft == 0) |
| 950 |
{ |
| 951 |
return eGOBI_ERR_INVALID_ARG; |
| 952 |
} |
| 953 |
|
| 954 |
// Find the TLV |
| 955 |
const sDMSUIMVerifyPINResponse_RetryInfo * pTLVx10; |
| 956 |
ULONG outLenx10; |
| 957 |
ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 ); |
| 958 |
if (rc != eGOBI_ERR_NONE) |
| 959 |
{ |
| 960 |
return rc; |
| 961 |
} |
| 962 |
|
| 963 |
// Is the TLV large enough? |
| 964 |
if (outLenx10 < sizeof( sDMSUIMVerifyPINResponse_RetryInfo )) |
| 965 |
{ |
| 966 |
return eGOBI_ERR_MALFORMED_RSP; |
| 967 |
} |
| 968 |
|
| 969 |
*pVerifyRetriesLeft = pTLVx10->mRemainingVerifyRetries; |
| 970 |
*pUnblockRetriesLeft = pTLVx10->mRemainingUnblockRetries; |
| 971 |
|
| 972 |
return eGOBI_ERR_NONE; |
| 973 |
} |
| 974 |
|
| 975 |
/*=========================================================================== |
| 976 |
METHOD: |
| 977 |
PackUIMVerifyPIN |
| 978 |
|
| 979 |
DESCRIPTION: |
| 980 |
This function verifies the PIN before accessing the UIM contents |
| 981 |
|
| 982 |
PARAMETERS: |
| 983 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 984 |
contain, upon output the number of BYTEs copied |
| 985 |
to pOut |
| 986 |
pOut [ O ] - Output buffer |
| 987 |
id [ I ] - PIN ID (1/2) |
| 988 |
pValue [ I ] - PIN value of the PIN to verify |
| 989 |
|
| 990 |
RETURN VALUE: |
| 991 |
ULONG - Return code |
| 992 |
===========================================================================*/ |
| 993 |
ULONG PackUIMVerifyPIN( |
| 994 |
ULONG * pOutLen, |
| 995 |
BYTE * pOut, |
| 996 |
ULONG id, |
| 997 |
CHAR * pValue ) |
| 998 |
{ |
| 999 |
// Validate arguments |
| 1000 |
if (pOut == 0 |
| 1001 |
|| id < 1 |
| 1002 |
|| id > 2 |
| 1003 |
|| pValue == 0 |
| 1004 |
|| pValue[0] == 0) |
| 1005 |
{ |
| 1006 |
return eGOBI_ERR_INVALID_ARG; |
| 1007 |
} |
| 1008 |
|
| 1009 |
// Add arguments |
| 1010 |
std::string val( pValue ); |
| 1011 |
UINT8 valSz = (UINT8)val.size(); |
| 1012 |
|
| 1013 |
// Check size |
| 1014 |
WORD tlvx01Sz = sizeof( sDMSUIMVerifyPINRequest_Info ) + valSz; |
| 1015 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 1016 |
{ |
| 1017 |
return eGOBI_ERR_BUFFER_SZ; |
| 1018 |
} |
| 1019 |
|
| 1020 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut; |
| 1021 |
pHeader->mTypeID = 0x01; |
| 1022 |
pHeader->mLength = tlvx01Sz; |
| 1023 |
|
| 1024 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 1025 |
|
| 1026 |
sDMSUIMVerifyPINRequest_Info * pTLVx01; |
| 1027 |
pTLVx01 = (sDMSUIMVerifyPINRequest_Info*)(pOut + offset); |
| 1028 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 1029 |
|
| 1030 |
// Set the values |
| 1031 |
pTLVx01->mPINID = (UINT8)id; |
| 1032 |
pTLVx01->mPINLength = valSz; |
| 1033 |
offset += sizeof( sDMSUIMVerifyPINRequest_Info ); |
| 1034 |
|
| 1035 |
// Add mPINValue |
| 1036 |
memcpy( (pOut + offset), val.c_str(), valSz ); |
| 1037 |
offset += valSz; |
| 1038 |
|
| 1039 |
*pOutLen = offset; |
| 1040 |
return eGOBI_ERR_NONE; |
| 1041 |
} |
| 1042 |
|
| 1043 |
/*=========================================================================== |
| 1044 |
METHOD: |
| 1045 |
ParseUIMSetPINProtection |
| 1046 |
|
| 1047 |
DESCRIPTION: |
| 1048 |
This function enables or disables protection of UIM contents by a |
| 1049 |
given PIN |
| 1050 |
|
| 1051 |
PARAMETERS: |
| 1052 |
inLen [ I ] - Length of input buffer |
| 1053 |
pIn [ I ] - Input buffer |
| 1054 |
pVerifyRetriesLeft [ O ] - Upon operational failure this will indicate |
| 1055 |
the number of retries left, after which the |
| 1056 |
PIN will be blocked (0xFFFFFFFF = unknown) |
| 1057 |
pUnblockRetriesLeft [ O ] - Upon operational failure this will indicate |
| 1058 |
the number of unblock retries left, after |
| 1059 |
which the PIN will be permanently blocked, |
| 1060 |
i.e. UIM is unusable (0xFFFFFFFF = unknown) |
| 1061 |
|
| 1062 |
RETURN VALUE: |
| 1063 |
ULONG - Return code |
| 1064 |
===========================================================================*/ |
| 1065 |
ULONG ParseUIMSetPINProtection( |
| 1066 |
ULONG inLen, |
| 1067 |
const BYTE * pIn, |
| 1068 |
ULONG * pVerifyRetriesLeft, |
| 1069 |
ULONG * pUnblockRetriesLeft ) |
| 1070 |
{ |
| 1071 |
// Validate arguments |
| 1072 |
if (pIn == 0 || pVerifyRetriesLeft == 0 || pUnblockRetriesLeft == 0) |
| 1073 |
{ |
| 1074 |
return eGOBI_ERR_INVALID_ARG; |
| 1075 |
} |
| 1076 |
|
| 1077 |
// Find the TLV |
| 1078 |
const sDMSUIMSetPINProtectionResponse_RetryInfo * pTLVx10; |
| 1079 |
ULONG outLenx10; |
| 1080 |
ULONG rc = GetTLV( inLen, pIn, 0x10, &outLenx10, (const BYTE **)&pTLVx10 ); |
| 1081 |
if (rc != eGOBI_ERR_NONE) |
| 1082 |
{ |
| 1083 |
return rc; |
| 1084 |
} |
| 1085 |
|
| 1086 |
// Is the TLV large enough? |
| 1087 |
if (outLenx10 < sizeof( sDMSUIMSetPINProtectionResponse_RetryInfo )) |
| 1088 |
{ |
| 1089 |
return eGOBI_ERR_MALFORMED_RSP; |
| 1090 |
} |
| 1091 |
|
| 1092 |
*pVerifyRetriesLeft = pTLVx10->mRemainingVerifyRetries; |
| 1093 |
*pUnblockRetriesLeft = pTLVx10->mRemainingUnblockRetries; |
| 1094 |
|
| 1095 |
return eGOBI_ERR_NONE; |
| 1096 |
} |
| 1097 |
|
| 1098 |
/*=========================================================================== |
| 1099 |
METHOD: |
| 1100 |
PackUIMSetPINProtection |
| 1101 |
|
| 1102 |
DESCRIPTION: |
| 1103 |
This function enables or disables protection of UIM contents by a |
| 1104 |
given PIN |
| 1105 |
|
| 1106 |
PARAMETERS: |
| 1107 |
pOutLen [I/O] - Upon input the maximum number of BYTEs pOut can |
| 1108 |
contain, upon output the number of BYTEs copied |
| 1109 |
to pOut |
| 1110 |
pOut [ O ] - Output buffer |
| 1111 |
id [ I ] - PIN ID (1/2) |
| 1112 |
bEnable [ I ] - Enable/disable PIN protection (0 = disable)? |
| 1113 |
pValue [ I ] - PIN value of the PIN to be enabled/disabled |
| 1114 |
|
| 1115 |
RETURN VALUE: |
| 1116 |
ULONG - Return code |
| 1117 |
===========================================================================*/ |
| 1118 |
ULONG PackUIMSetPINProtection( |
| 1119 |
ULONG * pOutLen, |
| 1120 |
BYTE * pOut, |
| 1121 |
ULONG id, |
| 1122 |
ULONG bEnable, |
| 1123 |
CHAR * pValue ) |
| 1124 |
{ |
| 1125 |
// Validate arguments |
| 1126 |
if (pOut == 0 |
| 1127 |
|| id < 1 |
| 1128 |
|| id > 2 |
| 1129 |
|| pValue == 0 |
| 1130 |
|| pValue[0] == 0) |
| 1131 |
{ |
| 1132 |
return eGOBI_ERR_INVALID_ARG; |
| 1133 |
} |
| 1134 |
|
| 1135 |
// Add arguments |
| 1136 |
std::string val( pValue ); |
| 1137 |
ULONG valSz = (ULONG)val.size(); |
| 1138 |
|
| 1139 |
// Check size |
| 1140 |
WORD tlvx01Sz = sizeof( sDMSUIMSetPINProtectionRequest_Info ) + (WORD)valSz; |
| 1141 |
if (*pOutLen < sizeof( sQMIRawContentHeader ) + tlvx01Sz) |
| 1142 |
{ |
| 1143 |
return eGOBI_ERR_BUFFER_SZ; |
| 1144 |
} |
| 1145 |
|
| 1146 |
sQMIRawContentHeader * pHeader = (sQMIRawContentHeader*)pOut; |
| 1147 |
pHeader->mTypeID = 0x01; |
| 1148 |
pHeader->mLength = tlvx01Sz; |
| 1149 |
|
| 1150 |
ULONG offset = sizeof( sQMIRawContentHeader ); |
| 1151 |
|
| 1152 |
sDMSUIMSetPINProtectionRequest_Info * pTLVx01; |
| 1153 |
pTLVx01 = (sDMSUIMSetPINProtectionRequest_Info*)(pOut + offset); |
| 1154 |
memset( pTLVx01, 0, tlvx01Sz ); |
| 1155 |
|
| 1156 |
// Set the values |
| 1157 |
pTLVx01->mPINID = (UINT8)id; |
| 1158 |
pTLVx01->mPINEnabled = (bEnable == 0 ? 0 : 1); |
| 1159 |
pTLVx01->mPINLength = (UINT8)valSz; |
| 1160 |
|
| 1161 |
offset += sizeof( sDMSUIMSetPINProtectionRequest_Info ); |
| 1162 |
|
| 1163 |
// Add mPINValue |
| 1164 |
memcpy( (pOut + offset), val.c_str(), valSz ); |
| 1165 |
offset += valSz; |
| 1166 |
|
| 1167 |
*pOutLen = offset; |
| 1168 |
return eGOBI_ERR_NONE; |
| 1169 |
} |