FreeCalypso > hg > fc-pcsc-tools
view libcommon/plmncodes.c @ 102:9ce95d9c5c34
plmnsel-erase-all command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 17 Feb 2021 23:25:47 +0000 |
parents | d2e800abd257 |
children |
line wrap: on
line source
/* * This module implements some functions for working with MCC-MNC PLMN codes. */ #include <sys/types.h> #include <ctype.h> #include <stdio.h> decode_plmn_3bytes(bin, asc, space_pad) u_char *bin; char *asc; { asc[0] = encode_hex_digit(bin[0] & 0xF); asc[1] = encode_hex_digit(bin[0] >> 4); asc[2] = encode_hex_digit(bin[1] & 0xF); asc[3] = '-'; asc[4] = encode_hex_digit(bin[2] & 0xF); asc[5] = encode_hex_digit(bin[2] >> 4); asc[6] = encode_hex_digit(bin[1] >> 4); asc[7] = '\0'; if (asc[6] == 'F') { if (space_pad) asc[6] = ' '; else asc[6] = '\0'; } } encode_plmn_3bytes(asc, bin) char *asc; u_char *bin; { u_char mcc[3], mnc[3]; if (!isxdigit(asc[0]) || !isxdigit(asc[1]) || !isxdigit(asc[2])) { inv: fprintf(stderr, "error: invalid MCC-MNC argument\n"); return(-1); } mcc[0] = decode_hex_digit(asc[0]); mcc[1] = decode_hex_digit(asc[1]); mcc[2] = decode_hex_digit(asc[2]); asc += 3; if (*asc == '-') asc++; if (!isxdigit(asc[0]) || !isxdigit(asc[1])) goto inv; mnc[0] = decode_hex_digit(asc[0]); mnc[1] = decode_hex_digit(asc[1]); asc += 2; if (*asc == '\0') mnc[2] = 0xF; else if (isxdigit(asc[0]) && asc[1] == '\0') mnc[2] = decode_hex_digit(*asc); else goto inv; bin[0] = (mcc[1] << 4) | mcc[0]; bin[1] = (mnc[2] << 4) | mcc[2]; bin[2] = (mnc[1] << 4) | mnc[0]; return(0); }