annotate libutil/plmncodes.c @ 179:efe944a5c4e3

doc/Brute-force-search: update for data directory rename
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 02 Mar 2021 05:20:19 +0000
parents f064dbcc5f41
children 3ddbc3fea5f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
35 if (!isxdigit(asc[0]) || !isxdigit(asc[1]) || !isxdigit(asc[2])) {
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
36 inv: fprintf(stderr, "error: invalid MCC-MNC argument\n");
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
37 return(-1);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
38 }
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
39 mcc[0] = decode_hex_digit(asc[0]);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
40 mcc[1] = decode_hex_digit(asc[1]);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
41 mcc[2] = decode_hex_digit(asc[2]);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
42 asc += 3;
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
43 if (*asc == '-')
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
44 asc++;
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
45 if (!isxdigit(asc[0]) || !isxdigit(asc[1]))
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
46 goto inv;
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
47 mnc[0] = decode_hex_digit(asc[0]);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
48 mnc[1] = decode_hex_digit(asc[1]);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
49 asc += 2;
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
50 if (*asc == '\0')
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
51 mnc[2] = 0xF;
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
52 else if (isxdigit(asc[0]) && asc[1] == '\0')
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
53 mnc[2] = decode_hex_digit(*asc);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
54 else
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
55 goto inv;
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
56 bin[0] = (mcc[1] << 4) | mcc[0];
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
57 bin[1] = (mnc[2] << 4) | mcc[2];
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
58 bin[2] = (mnc[1] << 4) | mnc[0];
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
59 return(0);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
60 }