[MERGED] pysim[master]: utils: Functions to encode/decode EF SPN.

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Alexander Chemeris gerrit-no-reply at lists.osmocom.org
Sat Jan 13 11:49:34 UTC 2018


Alexander Chemeris has submitted this change and it was merged.

Change subject: utils: Functions to encode/decode EF SPN.
......................................................................


utils: Functions to encode/decode EF SPN.

According to TS 51 011.

Change-Id: Ida184bc5c81cc8c228b8981b703f77d017e53334
---
M pySim/utils.py
1 file changed, 19 insertions(+), 0 deletions(-)

Approvals:
  Alexander Chemeris: Verified
  Harald Welte: Looks good to me, approved



diff --git a/pySim/utils.py b/pySim/utils.py
index 84b613f..8463581 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -34,6 +34,12 @@
 def i2h(s):
 	return ''.join(['%02x'%(x) for x in s])
 
+def h2s(s):
+	return ''.join([chr((int(x,16)<<4)+int(y,16)) for x,y in zip(s[0::2], s[1::2]) if not (x == 'f' and y == 'f') ])
+
+def s2h(s):
+	return b2h(s)
+
 def swap_nibbles(s):
 	return ''.join([x+y for x,y in zip(s[1::2], s[0::2])])
 
@@ -73,3 +79,16 @@
 def enc_plmn(mcc, mnc):
 	"""Converts integer MCC/MNC into 6 bytes for EF"""
 	return swap_nibbles(lpad('%d' % mcc, 3) + lpad('%d' % mnc, 3))
+
+def dec_spn(ef):
+	byte1 = int(ef[0:2])
+	hplmn_disp = (byte1&0x01 == 0x01)
+	oplmn_disp = (byte1&0x02 == 0x02)
+	name = h2s(ef[2:])
+	return (name, hplmn_disp, oplmn_disp)
+
+def enc_spn(name, hplmn_disp=False, oplmn_disp=False):
+	byte1 = 0x00
+	if hplmn_disp: byte1 = byte1|0x01
+	if oplmn_disp: byte1 = byte1|0x02
+	return i2h([byte1])+s2h(name)

-- 
To view, visit https://gerrit.osmocom.org/5715
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ida184bc5c81cc8c228b8981b703f77d017e53334
Gerrit-PatchSet: 1
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Owner: Alexander Chemeris <Alexander.Chemeris at gmail.com>
Gerrit-Reviewer: Alexander Chemeris <Alexander.Chemeris at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list