FreeCalypso > hg > fc-pcsc-tools
comparison libcommon/plmncodes.c @ 99:d2e800abd257
fc-simtool plmnsel-write command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 17 Feb 2021 22:43:18 +0000 |
parents | 4eb447be01c0 |
children |
comparison
equal
deleted
inserted
replaced
98:6ba14a9247d2 | 99:d2e800abd257 |
---|---|
1 /* | 1 /* |
2 * This module implements some functions for working with MCC-MNC PLMN codes. | 2 * This module implements some functions for working with MCC-MNC PLMN codes. |
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <ctype.h> | |
7 #include <stdio.h> | |
6 | 8 |
7 decode_plmn_3bytes(bin, asc, space_pad) | 9 decode_plmn_3bytes(bin, asc, space_pad) |
8 u_char *bin; | 10 u_char *bin; |
9 char *asc; | 11 char *asc; |
10 { | 12 { |
21 asc[6] = ' '; | 23 asc[6] = ' '; |
22 else | 24 else |
23 asc[6] = '\0'; | 25 asc[6] = '\0'; |
24 } | 26 } |
25 } | 27 } |
28 | |
29 encode_plmn_3bytes(asc, bin) | |
30 char *asc; | |
31 u_char *bin; | |
32 { | |
33 u_char mcc[3], mnc[3]; | |
34 | |
35 if (!isxdigit(asc[0]) || !isxdigit(asc[1]) || !isxdigit(asc[2])) { | |
36 inv: fprintf(stderr, "error: invalid MCC-MNC argument\n"); | |
37 return(-1); | |
38 } | |
39 mcc[0] = decode_hex_digit(asc[0]); | |
40 mcc[1] = decode_hex_digit(asc[1]); | |
41 mcc[2] = decode_hex_digit(asc[2]); | |
42 asc += 3; | |
43 if (*asc == '-') | |
44 asc++; | |
45 if (!isxdigit(asc[0]) || !isxdigit(asc[1])) | |
46 goto inv; | |
47 mnc[0] = decode_hex_digit(asc[0]); | |
48 mnc[1] = decode_hex_digit(asc[1]); | |
49 asc += 2; | |
50 if (*asc == '\0') | |
51 mnc[2] = 0xF; | |
52 else if (isxdigit(asc[0]) && asc[1] == '\0') | |
53 mnc[2] = decode_hex_digit(*asc); | |
54 else | |
55 goto inv; | |
56 bin[0] = (mcc[1] << 4) | mcc[0]; | |
57 bin[1] = (mnc[2] << 4) | mcc[2]; | |
58 bin[2] = (mnc[1] << 4) | mnc[0]; | |
59 return(0); | |
60 } |