annotate uicc/pbupdate.c @ 159:a5e2b6e3bdf7

fc-uicc-tool: fix-sysmo-msisdn command ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Feb 2021 04:07:24 +0000
parents ce2a880ab704
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
146
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the pb-update command.
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <ctype.h>
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <string.h>
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <strings.h>
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static u_char gsm7_encode_table[256] = {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0x00 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 0xFF, 0xFF, '\n', 0xFF, 0xFF, '\r', 0xFF, 0xFF,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0x10 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 ' ', '!', '"', '#', 0x02, '%', '&', 0x27, /* 0x20 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 '(', ')', '*', '+', ',', '-', '.', '/',
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 '0', '1', '2', '3', '4', '5', '6', '7', /* 0x30 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 '8', '9', ':', ';', '<', '=', '>', '?',
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', /* 0x40 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', /* 0x50 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 'X', 'Y', 'Z', 0xBC, 0xAF, 0xBE, 0x94, 0x11,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 0xFF, 'a', 'b', 'c', 'd', 'e', 'f', 'g', /* 0x60 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', /* 0x70 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 'x', 'y', 'z', 0xA8, 0xC0, 0xA9, 0xBD, 0xFF,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0x80 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0x90 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 0xFF, 0x40, 0xFF, 0x01, 0x24, 0x03, 0xFF, 0x5F, /* 0xA0 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0xB0 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x60,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 0xFF, 0xFF, 0xFF, 0xFF, 0x5B, 0x0E, 0x1C, 0x09, /* 0xC0 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 0xFF, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 0xFF, 0x5D, 0xFF, 0xFF, 0xFF, 0xFF, 0x5C, 0xFF, /* 0xD0 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 0x0B, 0xFF, 0xFF, 0xFF, 0x5E, 0xFF, 0xFF, 0x1E,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 0x7F, 0xFF, 0xFF, 0xFF, 0x7B, 0x0F, 0x1D, 0xFF, /* 0xE0 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 0x04, 0x05, 0xFF, 0xFF, 0x07, 0xFF, 0xFF, 0xFF,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 0xFF, 0x7D, 0x08, 0xFF, 0xFF, 0xFF, 0x7C, 0xFF, /* 0xF0 */
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 0x0C, 0x06, 0xFF, 0xFF, 0x7E, 0xFF, 0xFF, 0xFF
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 };
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 static
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 digit_char_to_gsm(ch)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 switch (ch) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case '0':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 case '1':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 case '2':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 case '3':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 case '4':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 case '5':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 case '6':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 case '7':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 case '8':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 case '9':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return (ch - '0');
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 case '*':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return 0xA;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 case '#':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return 0xB;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 case 'a':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 case 'b':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 case 'c':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return (ch - 'a' + 0xC);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 case 'A':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 case 'B':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 case 'C':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return (ch - 'A' + 0xC);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 return (-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 static void
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 pack_digit_bytes(digits, dest, num_digit_bytes)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 u_char *digits, *dest;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 unsigned num_digit_bytes;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 u_char *sp, *dp;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 unsigned n;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 sp = digits;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 dp = dest;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 for (n = 0; n < num_digit_bytes; n++) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 *dp++ = sp[0] | (sp[1] << 4);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 sp += 2;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 static char *
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 decode_qstring_alpha(cp, record, maxlen, filename_for_errs, lineno_for_errs)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 char *cp, *filename_for_errs;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 u_char *record;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 unsigned maxlen;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 unsigned acclen, nadd;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 int c;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 for (acclen = 0; ; ) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 if (*cp == '\0') {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 unterm_qstring: fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 "%s line %d: unterminated quoted string\n",
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 filename_for_errs, lineno_for_errs);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 return(0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 if (*cp == '"')
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 c = *cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 if (c == '\\') {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 if (*cp == '\0')
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 goto unterm_qstring;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 c = *cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 switch (c) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 case 'n':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 c = '\n';
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 case 'r':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 c = '\r';
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 case '"':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 case '\\':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 default:
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 "%s line %d: non-understood backslash escape\n",
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 filename_for_errs, lineno_for_errs);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 return(0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 c = gsm7_encode_table[c];
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 if (c == 0xFF) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 "%s line %d: character in quoted string cannot be encoded in GSM7\n",
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 filename_for_errs, lineno_for_errs);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 return(0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 if (c & 0x80)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 nadd = 2;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 else
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 nadd = 1;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 if (acclen + nadd > maxlen) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 "%s line %d: alpha tag string is longer than SIM limit\n",
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 filename_for_errs, lineno_for_errs);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 return(0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 if (c & 0x80)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 record[acclen++] = 0x1B;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 record[acclen++] = c & 0x7F;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 return(cp + 1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 static char *
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 decode_hex_alpha(cp, record, maxlen, filename_for_errs, lineno_for_errs)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 char *cp, *filename_for_errs;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 u_char *record;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 unsigned maxlen;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 unsigned acclen;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 for (acclen = 0; ; ) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 if (!isxdigit(cp[0]) || !isxdigit(cp[1]))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 if (acclen >= maxlen) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 "%s line %d: alpha tag string is longer than SIM limit\n",
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 filename_for_errs, lineno_for_errs);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 return(0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 record[acclen++] = (decode_hex_digit(cp[0]) << 4) |
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 decode_hex_digit(cp[1]);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 cp += 2;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 return(cp);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 static
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 process_record(line, pb_record_len, pb_record_count, filename_for_errs,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 lineno_for_errs)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 char *line, *filename_for_errs;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 unsigned pb_record_len, pb_record_count;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 unsigned recno;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 u_char record[255], *fixp;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 u_char digits[20];
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 unsigned ndigits, num_digit_bytes;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 char *cp;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 int c;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 recno = strtoul(line+1, 0, 10);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 if (recno < 1 || recno > pb_record_count) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 fprintf(stderr, "%s line %d: record number is out of range\n",
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 filename_for_errs, lineno_for_errs);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 cp = line + 1;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 while (isdigit(*cp))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 if (*cp++ != ':') {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 inv_syntax: fprintf(stderr, "%s line %d: invalid syntax\n",
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 filename_for_errs, lineno_for_errs);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 while (isspace(*cp))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 memset(record, 0xFF, pb_record_len);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 fixp = record + pb_record_len - 14;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 if (digit_char_to_gsm(*cp) < 0)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 goto inv_syntax;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 for (ndigits = 0; ; ndigits++) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 c = digit_char_to_gsm(*cp);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 if (c < 0)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 if (ndigits >= 20) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 fprintf(stderr, "%s line %d: too many number digits\n",
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 filename_for_errs, lineno_for_errs);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 digits[ndigits] = c;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 if (ndigits & 1)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 digits[ndigits++] = 0xF;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 num_digit_bytes = ndigits >> 1;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 fixp[0] = num_digit_bytes + 1;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 pack_digit_bytes(digits, fixp + 2, num_digit_bytes);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 if (*cp++ != ',')
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 goto inv_syntax;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 if (cp[0] != '0' || cp[1] != 'x' && cp[1] != 'X' || !isxdigit(cp[2]) ||
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 !isxdigit(cp[3]) || !isspace(cp[4]))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 goto inv_syntax;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 fixp[1] = strtoul(cp, 0, 16);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 cp += 5;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 while (isspace(*cp))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 if (!strncasecmp(cp, "CCP=", 4)) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 cp += 4;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 fixp[12] = strtoul(cp, 0, 0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 while (*cp && !isspace(*cp))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 while (isspace(*cp))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 if (!strncasecmp(cp, "EXT=", 4)) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 cp += 4;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 fixp[13] = strtoul(cp, 0, 0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 while (*cp && !isspace(*cp))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 while (isspace(*cp))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 if (*cp == '"') {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 cp = decode_qstring_alpha(cp, record, pb_record_len - 14,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 filename_for_errs, lineno_for_errs);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 if (!cp)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 } else if (!strncasecmp(cp, "HEX", 3)) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 cp += 3;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 while (isspace(*cp))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 cp = decode_hex_alpha(cp, record, pb_record_len - 14,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 filename_for_errs, lineno_for_errs);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 if (!cp)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 } else
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 goto inv_syntax;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 while (isspace(*cp))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 if (*cp)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 goto inv_syntax;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 return update_rec_op(recno, 0x04, record, pb_record_len);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 cmd_pb_update(argc, argv)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 char **argv;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 int rc;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 FILE *inf;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 int lineno;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 char linebuf[1024];
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 unsigned pb_record_len, pb_record_count;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 rc = phonebook_op_common(argv[1], &pb_record_len, &pb_record_count);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 if (rc < 0)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 return(rc);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 inf = fopen(argv[2], "r");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 if (!inf) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 perror(argv[2]);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 if (!index(linebuf, '\n')) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 "%s line %d: too long or missing newline\n",
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 argv[2], lineno);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 fclose(inf);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 if (linebuf[0] != '#' || !isdigit(linebuf[1]))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 continue;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 rc = process_record(linebuf, pb_record_len, pb_record_count,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 argv[2], lineno);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 if (rc < 0) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 fclose(inf);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 return(rc);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 fclose(inf);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 return(0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 static
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 decode_number_arg(arg, fixp)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 char *arg;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321 u_char *fixp;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 u_char digits[20];
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324 unsigned ndigits, num_digit_bytes;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 char *cp, *endp;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 int c;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 cp = arg;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 if (*cp == '+') {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 fixp[1] = 0x91;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 } else
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 fixp[1] = 0x81;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 if (digit_char_to_gsm(*cp) < 0) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 inv_arg: fprintf(stderr, "error: invalid phone number argument\n");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 for (ndigits = 0; ; ndigits++) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 c = digit_char_to_gsm(*cp);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 if (c < 0)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 if (ndigits >= 20) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 fprintf(stderr, "error: too many number digits\n");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 digits[ndigits] = c;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349 if (ndigits & 1)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350 digits[ndigits++] = 0xF;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351 num_digit_bytes = ndigits >> 1;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352 fixp[0] = num_digit_bytes + 1;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 pack_digit_bytes(digits, fixp + 2, num_digit_bytes);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 if (*cp == ',') {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 if (!isdigit(*cp))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 goto inv_arg;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358 fixp[1] = strtoul(cp, &endp, 0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 if (*endp)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 goto inv_arg;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361 } else if (*cp)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 goto inv_arg;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 return(0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366 static
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 decode_alphatag_arg(arg, record, maxlen)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368 char *arg;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 u_char *record;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370 unsigned maxlen;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372 unsigned acclen, nadd;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373 char *cp;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374 int c;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 cp = arg;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 for (acclen = 0; *cp; ) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 c = *cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
379 if (c == '\\') {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380 if (*cp == '\0') {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
381 fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
382 "error: dangling backslash escape\n");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
383 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
384 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
385 c = *cp++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
386 switch (c) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
387 case 'n':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
388 c = '\n';
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
389 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
390 case 'r':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
391 c = '\r';
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
392 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
393 case '"':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
394 case '\\':
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
395 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
396 default:
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
397 fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
398 "error: non-understood backslash escape\n");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
399 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
400 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
401 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
402 c = gsm7_encode_table[c];
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
403 if (c == 0xFF) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
404 fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
405 "error: character in alpha tag string cannot be encoded in GSM7\n");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
406 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
407 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
408 if (c & 0x80)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
409 nadd = 2;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
410 else
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
411 nadd = 1;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
412 if (acclen + nadd > maxlen) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
413 fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
414 "error: alpha tag string is longer than SIM limit\n");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
415 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
416 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
417 if (c & 0x80)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
418 record[acclen++] = 0x1B;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
419 record[acclen++] = c & 0x7F;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
420 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
421 return(0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
422 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
423
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
424 cmd_pb_update_imm(argc, argv)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
425 char **argv;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
426 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
427 int rc;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
428 unsigned recno;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
429 u_char record[255], *fixp;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
430 unsigned pb_record_len, pb_record_count;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
431
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
432 rc = phonebook_op_common(argv[1], &pb_record_len, &pb_record_count);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
433 if (rc < 0)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
434 return(rc);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
435 recno = strtoul(argv[2], 0, 0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
436 if (recno < 1 || recno > pb_record_count) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
437 fprintf(stderr, "error: specified record number is invalid\n");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
438 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
439 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
440 memset(record, 0xFF, pb_record_len);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
441 fixp = record + pb_record_len - 14;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
442 rc = decode_number_arg(argv[3], fixp);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
443 if (rc < 0)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
444 return(rc);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
445 if (argv[4]) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
446 rc = decode_alphatag_arg(argv[4], record, pb_record_len - 14);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
447 if (rc < 0)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
448 return(rc);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
449 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
450 return update_rec_op(recno, 0x04, record, pb_record_len);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
451 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
452
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
453 static
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
454 decode_alphatag_arg_hex(arg, record, maxlen)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
455 char *arg;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
456 u_char *record;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
457 unsigned maxlen;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
458 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
459 unsigned acclen;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
460
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
461 for (acclen = 0; ; acclen++) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
462 while (isspace(*arg))
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
463 arg++;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
464 if (!*arg)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
465 break;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
466 if (!isxdigit(arg[0]) || !isxdigit(arg[1])) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
467 fprintf(stderr, "error: invalid hex string input\n");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
468 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
469 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
470 if (acclen >= maxlen) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
471 fprintf(stderr,
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
472 "error: alpha tag string is longer than SIM limit\n");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
473 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
474 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
475 record[acclen] = (decode_hex_digit(arg[0]) << 4) |
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
476 decode_hex_digit(arg[1]);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
477 arg += 2;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
478 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
479 return(0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
480 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
481
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
482 cmd_pb_update_imm_hex(argc, argv)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
483 char **argv;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
484 {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
485 int rc;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
486 unsigned recno;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
487 u_char record[255], *fixp;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
488 unsigned pb_record_len, pb_record_count;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
489
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
490 rc = phonebook_op_common(argv[1], &pb_record_len, &pb_record_count);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
491 if (rc < 0)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
492 return(rc);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
493 recno = strtoul(argv[2], 0, 0);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
494 if (recno < 1 || recno > pb_record_count) {
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
495 fprintf(stderr, "error: specified record number is invalid\n");
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
496 return(-1);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
497 }
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
498 memset(record, 0xFF, pb_record_len);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
499 fixp = record + pb_record_len - 14;
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
500 rc = decode_number_arg(argv[3], fixp);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
501 if (rc < 0)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
502 return(rc);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
503 rc = decode_alphatag_arg_hex(argv[4], record, pb_record_len - 14);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
504 if (rc < 0)
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
505 return(rc);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
506 return update_rec_op(recno, 0x04, record, pb_record_len);
ce2a880ab704 fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
507 }