FreeCalypso > hg > fc-pcsc-tools
annotate libutil/plmncodes.c @ 202:3f6f50103dd3
fc-simtool: update-rec-prev separate command eliminated,
absorbed into regular update-rec
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Mar 2021 04:06:39 +0000 |
parents | 3ddbc3fea5f0 |
children |
rev | line source |
---|---|
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements some functions for working with MCC-MNC PLMN codes. |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
99
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
6 #include <ctype.h> |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
7 #include <stdio.h> |
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 decode_plmn_3bytes(bin, asc, space_pad) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 u_char *bin; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 char *asc; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 asc[0] = encode_hex_digit(bin[0] & 0xF); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 asc[1] = encode_hex_digit(bin[0] >> 4); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 asc[2] = encode_hex_digit(bin[1] & 0xF); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 asc[3] = '-'; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 asc[4] = encode_hex_digit(bin[2] & 0xF); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 asc[5] = encode_hex_digit(bin[2] >> 4); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 asc[6] = encode_hex_digit(bin[1] >> 4); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 asc[7] = '\0'; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (asc[6] == 'F') { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (space_pad) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 asc[6] = ' '; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 else |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 asc[6] = '\0'; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
99
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
28 |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
29 encode_plmn_3bytes(asc, bin) |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
30 char *asc; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
31 u_char *bin; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
32 { |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
33 u_char mcc[3], mnc[3]; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
34 |
197
3ddbc3fea5f0
encode_plmn_3bytes() error handling change
Mychaela Falconia <falcon@freecalypso.org>
parents:
157
diff
changeset
|
35 if (!isxdigit(asc[0]) || !isxdigit(asc[1]) || !isxdigit(asc[2])) |
99
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
36 return(-1); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
37 mcc[0] = decode_hex_digit(asc[0]); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
38 mcc[1] = decode_hex_digit(asc[1]); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
39 mcc[2] = decode_hex_digit(asc[2]); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
40 asc += 3; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
41 if (*asc == '-') |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
42 asc++; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
43 if (!isxdigit(asc[0]) || !isxdigit(asc[1])) |
197
3ddbc3fea5f0
encode_plmn_3bytes() error handling change
Mychaela Falconia <falcon@freecalypso.org>
parents:
157
diff
changeset
|
44 return(-1); |
99
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
45 mnc[0] = decode_hex_digit(asc[0]); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
46 mnc[1] = decode_hex_digit(asc[1]); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
47 asc += 2; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
48 if (*asc == '\0') |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
49 mnc[2] = 0xF; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
50 else if (isxdigit(asc[0]) && asc[1] == '\0') |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
51 mnc[2] = decode_hex_digit(*asc); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
52 else |
197
3ddbc3fea5f0
encode_plmn_3bytes() error handling change
Mychaela Falconia <falcon@freecalypso.org>
parents:
157
diff
changeset
|
53 return(-1); |
99
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
54 bin[0] = (mcc[1] << 4) | mcc[0]; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
55 bin[1] = (mnc[2] << 4) | mcc[2]; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
56 bin[2] = (mnc[1] << 4) | mnc[0]; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
57 return(0); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
58 } |