comparison simtool/chv.c @ 3:e9e8ce12f5a5

encode_pin_entry() factored out into libcommon
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 11 Feb 2021 23:11:57 +0000
parents 2071b28cd0c7
children 32d6186668cf
comparison
equal deleted inserted replaced
2:5b69dfc789f2 3:e9e8ce12f5a5
2 * This module implements the standard set of CHV commands 2 * This module implements the standard set of CHV commands
3 * for GSM 11.11 SIMs. 3 * for GSM 11.11 SIMs.
4 */ 4 */
5 5
6 #include <sys/types.h> 6 #include <sys/types.h>
7 #include <ctype.h>
8 #include <stdio.h> 7 #include <stdio.h>
9 #include <stdlib.h>
10 #include "simresp.h" 8 #include "simresp.h"
11
12 encode_pin_entry(arg, dest)
13 char *arg;
14 u_char *dest;
15 {
16 unsigned n;
17
18 n = 0;
19 while (*arg) {
20 if (!isdigit(*arg)) {
21 fprintf(stderr,
22 "error: PIN argument contains a non-digit character\n");
23 return(-1);
24 }
25 if (n >= 8) {
26 fprintf(stderr, "error: PIN argument is too long\n");
27 return(-1);
28 }
29 *dest++ = *arg++;
30 n++;
31 }
32 for (; n < 8; n++)
33 *dest++ = 0xFF;
34 return(0);
35 }
36 9
37 cmd_verify_chv(argc, argv) 10 cmd_verify_chv(argc, argv)
38 char **argv; 11 char **argv;
39 { 12 {
40 u_char cmd[13]; 13 u_char cmd[13];