annotate uptools/libcoding/hexdecode.c @ 1012:11391cb6bdc0

patch from fixeria: doc change from SE K2x0 to K2xx Since their discovery in late 2022, Sony Ericsson K200 and K220 phones were collectively referred to as SE K2x0 in FreeCalypso documentation. However, now that SE K205 has been discovered as yet another member of the same family (same PCBA in different case), it makes more sense to refer to the whole family as SE K2xx.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 23 Sep 2024 12:23:20 +0000
parents 18c692984549
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
329
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This library module implements decoding of long hex strings,
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * such as SMS PDUs.
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 decode_hex_line(inbuf, outbuf, outmax)
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 char *inbuf;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 u_char *outbuf;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 unsigned outmax;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char *inp = inbuf;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 u_char *outp = outbuf;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 unsigned outcnt = 0;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int c, d[2], i;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 while (*inp) {
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (!isxdigit(inp[0]) || !isxdigit(inp[1]))
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return(-1);
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (outcnt >= outmax)
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 break;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 for (i = 0; i < 2; i++) {
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 c = *inp++;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (isdigit(c))
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 d[i] = c - '0';
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 else if (isupper(c))
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 d[i] = c - 'A' + 10;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 else
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 d[i] = c - 'a' + 10;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 *outp++ = (d[0] << 4) | d[1];
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 outcnt++;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 }
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return outcnt;
18c692984549 uptools/libcoding: hex line decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }