From 8afcfc725ee9c3ac6052510867f5077adb5d2439 Mon Sep 17 00:00:00 2001 From: p1-bmu Date: Wed, 11 May 2022 15:56:26 +0200 Subject: [PATCH] corenet: fix PLMN encoding in RAN protos for 6-digits PLMN --- pycrate_corenet/utils_fmt.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pycrate_corenet/utils_fmt.py b/pycrate_corenet/utils_fmt.py index 087cd8c..4dd1e85 100644 --- a/pycrate_corenet/utils_fmt.py +++ b/pycrate_corenet/utils_fmt.py @@ -45,14 +45,26 @@ def pythonize_name(name): return name.replace('-', '_') -__PLMN = TS24008_IE.PLMN() def plmn_buf_to_str(buf): - __PLMN.from_bytes(buf) - return __PLMN.decode() + d = [] + [d.extend([0x30 + (b&0xf), 0x30+(b>>4)]) for b in buf] + if d[3] == 0x3f: + # filler, 5 digits MCC MNC + del d[3] + return bytes(d).decode() def plmn_str_to_buf(s): - __PLMN.encode(s) - return __PLMN.to_bytes() + s = s.encode() + if len(s) == 5: + return bytes([ + ((s[1]-0x30)<<4) + (s[0]-0x30), + 0xf0 + (s[2]-0x30), + ((s[4]-0x30)<<4) + (s[3]-0x30)]) + else: + return bytes([ + ((s[1]-0x30)<<4) + (s[0]-0x30), + ((s[3]-0x30)<<4) + (s[2]-0x30), + ((s[5]-0x30)<<4) + (s[4]-0x30)]) __IMSI = TS24008_IE.ID()