diff options
author | Harald Welte <laforge@gnumonks.org> | 2012-07-13 22:57:31 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2012-07-13 22:57:31 +0200 |
commit | a9250b9ebcdab7134e5d062e8ca37f9532eca5e8 (patch) | |
tree | 89a3ce7321b8eebe9d483a48dbe61aabe41a1dd0 | |
parent | e866473f2a96ed146dcbeeadf24a45289c81ef02 (diff) |
gsm48_decode_lai(): return real integers for mcc/mnc, not hex!
This is to make it orthogonal with gsm48_encode_lai()
-rw-r--r-- | src/gsm/gsm48.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c index 61e5d2cb..fe62dee7 100644 --- a/src/gsm/gsm48.c +++ b/src/gsm/gsm48.c @@ -285,15 +285,22 @@ void gsm48_generate_lai(struct gsm48_loc_area_id *lai48, uint16_t mcc, lai48->lac = htons(lac); } +/* Attention: this function retunrs true integers, not hex! */ int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc, uint16_t *mnc, uint16_t *lac) { - *mcc = ((lai->digits[0] & 0x0f) << 8) - | (lai->digits[0] & 0xf0) - | (lai->digits[1] & 0x0f); - *mnc = ((lai->digits[2] & 0x0f) << 8) - | (lai->digits[2] & 0xf0) - | ((lai->digits[1] & 0xf0) >> 4); + *mcc = (lai->digits[0] & 0x0f) * 100 + + (lai->digits[0] >> 4) * 10 + + (lai->digits[1] & 0x0f); + + if ((lai->digits[1] & 0xf0) == 0xf0) { + *mnc = (lai->digits[2] & 0x0f) * 10 + + (lai->digits[2] >> 4); + } else { + *mnc = (lai->digits[2] & 0x0f) * 100 + + (lai->digits[2] >> 4) * 10 + + (lai->digits[1] >> 4); + } *lac = ntohs(lai->lac); return 0; |