laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/28626 )
Change subject: Add very simplistic DF_PHONEBOOK support
......................................................................
Add very simplistic DF_PHONEBOOK support
This at least gives us the names for the DF and those EFs inside.
Change-Id: I12f70ae78e219e765ecb44cacff421d64c7b3f19
---
A pySim/df_phonebook.py
M pySim/ts_31_102.py
M pySim/ts_51_011.py
3 files changed, 71 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/26/28626/1
diff --git a/pySim/df_phonebook.py b/pySim/df_phonebook.py
new file mode 100644
index 0000000..0cccb6f
--- /dev/null
+++ b/pySim/df_phonebook.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+
+# without this, pylint will fail when inner classes are used
+# within the 'nested' kwarg of our TlvMeta metaclass on python 3.7 :(
+# pylint: disable=undefined-variable
+
+"""
+DF_PHONEBOOK as specified in 3GPP TS 31.102 V16.6.0
+Needs to be a separate python module to avoid cyclic imports
+"""
+
+#
+# Copyright (C) 2022 Harald Welte <laforge(a)osmocom.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+from pySim.tlv import *
+from pySim.filesystem import *
+from pySim.construct import *
+from construct import Optional as COptional
+from construct import *
+
+class EF_PBR(LinFixedEF):
+ def __init__(self, fid='4F30', name='EF.PBR', desc='Phone Book Reference', **kwargs):
+ super().__init__(fid, name=name, desc=desc, **kwargs)
+ #self._tlv = FIXME
+
+class EF_PSC(TransparentEF):
+ _construct = Struct('synce_counter'/Int32ub)
+ def __init__(self, fid='4F22', name='EF.PSC', desc='Phone Book Synchronization Counter', **kwargs):
+ super().__init__(fid, name=name, desc=desc, **kwargs)
+ #self._tlv = FIXME
+
+class EF_CC(TransparentEF):
+ _construct = Struct('change_counter'/Int16ub)
+ def __init__(self, fid='4F23', name='EF.CC', desc='Change Counter', **kwargs):
+ super().__init__(fid, name=name, desc=desc, **kwargs)
+
+class EF_PUID(TransparentEF):
+ _construct = Struct('previous_uid'/Int16ub)
+ def __init__(self, fid='4F24', name='EF.PUID', desc='Previous Unique Identifer', **kwargs):
+ super().__init__(fid, name=name, desc=desc, **kwargs)
+
+class DF_PHONEBOOK(CardDF):
+ def __init__(self, fid='5F3A', name='DF.PHONEBOOK', desc='Phonebook', **kwargs):
+ super().__init__(fid=fid, name=name, desc=desc, **kwargs)
+ files = [
+ EF_PBR(),
+ EF_PSC(),
+ EF_CC(),
+ EF_PUID(),
+ # FIXME: Those 4Fxx entries with unspecified FID...
+ ]
+ self.add_files(files)
diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py
index fa3af75..2147f5e 100644
--- a/pySim/ts_31_102.py
+++ b/pySim/ts_31_102.py
@@ -36,6 +36,7 @@
from pySim.ts_102_221 import EF_ARR
from pySim.tlv import *
from pySim.filesystem import *
+from pySim.df_phonebook import DF_PHONEBOOK
from pySim.construct import *
from construct import Optional as COptional
from construct import *
@@ -1282,7 +1283,7 @@
# FIXME: from EF_ePDGSelection onwards
EF_FromPreferred(service=114),
# FIXME: DF_SoLSA service=23
- # FIXME: DF_PHONEBOOK
+ DF_PHONEBOOK(),
# FIXME: DF_GSM_ACCESS service=27
DF_WLAN(service=[59, 60, 61, 62, 63, 66, 81, 82, 83, 84, 88]),
DF_HNB(service=[86, 90]),
diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index 209a273..854d9ad 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -32,6 +32,7 @@
from pySim.profile import match_sim
from pySim.profile import CardProfile
from pySim.filesystem import *
+from pySim.df_phonebook import DF_PHONEBOOK
import enum
from pySim.construct import *
from construct import Optional as COptional
@@ -497,6 +498,8 @@
EF_EXT('6f4e', None, 'EF.EXT4', 'Extension4 (BDN/SSC)'),
EF_SMSR(),
EF_CMI(),
+ # not really part of 51.011 but something that TS 31.102 specifies may exist here.
+ DF_PHONEBOOK(),
]
self.add_files(files)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28626
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I12f70ae78e219e765ecb44cacff421d64c7b3f19
Gerrit-Change-Number: 28626
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/28627 )
Change subject: fileystem: Use human-readable ADF name if available.
......................................................................
fileystem: Use human-readable ADF name if available.
When using __str__ for a CardDF we would get "DF(DF.TELECOM)"
but when using it on CardADF we would get ADF(a0000000871002)"
instead of "ADF(ADF.USIM)". Let's fix that.
Change-Id: I5801a08bcc28cb222734af6d9ee835227f4fee69
---
M pySim/filesystem.py
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/27/28627/1
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 813bebb..a3e83d6 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -488,7 +488,7 @@
mf.add_application_df(self)
def __str__(self):
- return "ADF(%s)" % (self.aid)
+ return "ADF(%s)" % (self.name if self.name else self.aid)
def _path_element(self, prefer_name: bool):
if self.name and prefer_name:
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28627
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I5801a08bcc28cb222734af6d9ee835227f4fee69
Gerrit-Change-Number: 28627
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/28623 )
Change subject: filesystem: raise exception only when applicable
......................................................................
filesystem: raise exception only when applicable
We should first see if any of the files in the tree actually
require a service mapping before raising
ValueError('TODO: implement recursive service -> file mapping')
Change-Id: I9c339f0cac020e7eec7f4f840748040e5f77923d
---
M pySim/filesystem.py
1 file changed, 12 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/23/28623/1
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 37c668d..c40eaf8 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -301,6 +301,14 @@
else:
raise ValueError
+ def _has_service(self):
+ if self.service:
+ return True
+ for c in self.children.values():
+ if isinstance(c, CardDF):
+ if c._has_service():
+ return True
+
def add_file(self, child: CardFile, ignore_existing: bool = False):
"""Add a child (DF/EF) to this DF.
Args:
@@ -336,7 +344,10 @@
for c in child.children.values():
self._add_file_services(c)
if isinstance(c, CardDF):
- raise ValueError('TODO: implement recursive service -> file mapping')
+ for gc in c.children.values():
+ if isinstance(gc, CardDF):
+ if gc._has_service():
+ raise ValueError('TODO: implement recursive service -> file mapping')
def add_files(self, children: Iterable[CardFile], ignore_existing: bool = False):
"""Add a list of child (DF/EF) to this DF
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28623
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I9c339f0cac020e7eec7f4f840748040e5f77923d
Gerrit-Change-Number: 28623
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange