FreeCalypso > hg > fc-pcsc-tools
annotate libcommon/revnibbles.c @ 19:72a24b8538eb
meaty function of pb-dump moved back into simtool, out of libcommon
Upon further reflection, I am not going to keep any of the pb-*
commands in the new version of fc-uicc-tool: they are logically
incorrect for UICC/USIM anyway, as they access phonebook files
via old classic SIM paths, rather than their USIM paths. OTOH,
I am going to implement new SMSP commands in fc-simtool, and I
do not plan to replicate them in fc-uicc-tool either. Guts of
fc-simtool pb-dump belong in simtool/pbdump.c, not in libcommon,
just like the guts of the future smsp-dump command will belong
in its own respective implementation module.
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 12 Feb 2021 03:33:26 +0000 |
| parents | 4360a7906f34 |
| children |
| rev | line source |
|---|---|
|
7
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements some reversed-nibbles parsing functions. |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 encode_hex_digit(d) |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 unsigned d; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 { |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 if (d <= 9) |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 return(d + '0'); |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 else |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 return(d - 10 + 'A'); |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 } |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 decode_reversed_nibbles(bytes, nbytes, dest) |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 u_char *bytes; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 unsigned nbytes; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char *dest; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 u_char *sp; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 char *dp; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 unsigned n, c; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 sp = bytes; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 dp = dest; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 for (n = 0; n < nbytes; n++) { |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 c = *sp & 0xF; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 *dp++ = encode_hex_digit(c); |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 c = *sp >> 4; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 *dp++ = encode_hex_digit(c); |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 sp++; |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
|
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
