mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
utils: Add functions to decode IMSI and ICCID from EF raw data.
This commit is contained in:
committed by
Sylvain Munaut
parent
21885249cf
commit
5e96c3d910
@@ -42,3 +42,20 @@ def rpad(s, l, c='f'):
|
||||
|
||||
def lpad(s, l, c='f'):
|
||||
return c * (l - len(s)) + s
|
||||
|
||||
def dec_imsi(ef):
|
||||
"""Converts an EF value to the imsi string representation"""
|
||||
if len(ef) < 4:
|
||||
return None
|
||||
l = int(ef[0:2]) * 2 # Length of the IMSI string
|
||||
swapped = swap_nibbles(ef[2:])
|
||||
oe = (int(swapped[0])>>3) & 1 # Odd (1) / Even (0)
|
||||
if oe:
|
||||
l = l-1
|
||||
if l+1 > len(swapped):
|
||||
return None
|
||||
imsi = swapped[1:l+2]
|
||||
return imsi
|
||||
|
||||
def dec_iccid(ef):
|
||||
return swap_nibbles(ef).strip('f')
|
||||
|
||||
Reference in New Issue
Block a user