Debian Codegraph @

gobi-api/Gobi_2012-06-18-1054/Gobi3000Translation/Gobi3000TranslationUIM.cpp

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