laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/33698 )
Change subject: cards: card_detect for pure UICC/SIM differentiation
......................................................................
cards: card_detect for pure UICC/SIM differentiation
Change-Id: I01009955fe1bef811a30d21ef347fb1bbccc7619
---
M pySim-shell.py
M pySim/cards.py
2 files changed, 34 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/98/33698/1
diff --git a/pySim-shell.py b/pySim-shell.py
index 061ac36..4d4f2e2 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -95,7 +95,7 @@
return None, None
generic_card = False
- card = card_detect("auto", scc)
+ card = card_detect(scc)
if card is None:
print("Warning: Could not detect card type - assuming a generic card type...")
card = SimCardBase(scc)
diff --git a/pySim/cards.py b/pySim/cards.py
index 4598217..c6aee69 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -24,6 +24,7 @@
from typing import Optional, Dict, Tuple
from pySim.ts_102_221 import EF_DIR, EF_ICCID
+from pySim.ts_51_011 import DF_GSM
from pySim.transport import LinkBase
import abc
@@ -75,13 +76,17 @@
class SimCardBase(CardBase):
"""Here we only add methods for commands specified in TS 51.011, without
any higher-layer processing."""
+ name = 'SIM'
def __init__(self, scc: LinkBase):
super(SimCardBase, self).__init__(scc)
self._scc.cla_byte = "A0"
self._scc.sel_ctrl = "0000"
- name = 'SIM'
+ def probe(self):
+ # EF.DIR is a mandatory EF on all ICCIDs; however it *may* also exist on a TS 51.011 SIM
+ df_gsm = DF_GSM()
+ return self.file_exists(df_gsm.fid)
class UiccCardBase(SimCardBase):
@@ -94,6 +99,11 @@
# See also: ETSI TS 102 221, Table 9.3
self._adm_chv_num = 0xA0
+ def probe(self):
+ # EF.DIR is a mandatory EF on all ICCIDs; however it *may* also exist on a TS 51.011 SIM
+ ef_dir = EF_DIR()
+ return self.file_exists(ef_dir.fid)
+
def read_aids(self) -> List[Hexstr]:
"""Fetch all the AIDs present on UICC"""
self._aids = []
@@ -155,3 +165,16 @@
# If we cannot get the full AID, try with short AID
return self._scc.select_adf(aid)
return (None, None)
+
+def card_detect(scc: LinkBase) -> Optional[CardBase]:
+ # UICC always has higher preference, as a UICC might also contain a SIM application
+ uicc = UiccCardBase(scc)
+ if uicc.probe():
+ return uicc
+
+ # this is for detecting a real, classic TS 11.11 SIM card without any UICC support
+ sim = SimCardBase(scc)
+ if sim.probe():
+ return sim
+
+ return None
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/33698
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I01009955fe1bef811a30d21ef347fb1bbccc7619
Gerrit-Change-Number: 33698
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/+/33699 )
Change subject: Introduce concept of CardProfileAddon
......................................................................
Introduce concept of CardProfileAddon
We have a strict "one CardProfile per card" rule. For a modern UICC
without legacy SIM support, that works great, as all applications
have AID and ADF and can hence be enumerated/detected that way.
However, in reality there are mostly UICC that have legacy SIM, GSM-R
or even CDMA support, all of which are not proper UICC applications
for historical reasons.
So instead of having hard-coded hacks in various places, let's introduce
the new concept of a CardProfileAddon. Every profile can have any
number of those. When building up the RuntimeState, we iterate over the
CardProfile addons, and probe which of those are actually on the card.
For those discovered, we add their files to the filesystem hierarchy.
Change-Id: I5866590b6d48f85eb889c9b1b8ab27936d2378b9
---
M pySim-shell.py
M pySim/cdma_ruim.py
M pySim/filesystem.py
M pySim/gsm_r.py
M pySim/profile.py
M pySim/ts_102_221.py
M pySim/ts_51_011.py
7 files changed, 123 insertions(+), 12 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/99/33699/1
diff --git a/pySim-shell.py b/pySim-shell.py
index 4d4f2e2..b48abc7 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -137,11 +137,6 @@
# Create runtime state with card profile
rs = RuntimeState(card, profile)
- # FIXME: This is an GSM-R related file, it needs to be added throughout,
- # the profile. At the moment we add it for all cards, this won't hurt,
- # but regular SIM and UICC will not have it and fail to select it.
- rs.mf.add_file(DF_EIRENE())
-
CardModel.apply_matching_models(scc, rs)
# inform the transport that we can do context-specific SW interpretation
diff --git a/pySim/cdma_ruim.py b/pySim/cdma_ruim.py
index 3fab558..62dbb22 100644
--- a/pySim/cdma_ruim.py
+++ b/pySim/cdma_ruim.py
@@ -22,7 +22,7 @@
from pySim.utils import *
from pySim.filesystem import *
from pySim.profile import match_ruim
-from pySim.profile import CardProfile
+from pySim.profile import CardProfile, CardProfileAddon
from pySim.ts_51_011 import CardProfileSIM
from pySim.ts_51_011 import DF_TELECOM, DF_GSM
from pySim.ts_51_011 import EF_ServiceTable
@@ -191,3 +191,14 @@
@staticmethod
def match_with_card(scc: SimCardCommands) -> bool:
return match_ruim(scc)
+
+class AddonRUIM(CardProfileAddon):
+ """An Addon that can be found on either classic GSM SIM or on UICC to support GSM-R."""
+ def __init__(self):
+ files = [
+ DF_CDMA()
+ ]
+ super().__init__('RUIM', desc='CDMA RUIM', files_in_mf=files)
+
+ def probe(self, card: 'CardBase') -> bool:
+ return card.file_exists(self.files_in_mf[0].fid)
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 22ff60d..cb3b403 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -1307,6 +1307,16 @@
self.card.set_apdu_parameter(
cla=self.profile.cla, sel_ctrl=self.profile.sel_ctrl)
+ for addon_cls in self.profile.addons:
+ addon = addon_cls()
+ if addon.probe(self.card):
+ print("Detected %s Add-on \"%s\"" % (self.profile, addon))
+ for f in addon.files_in_mf:
+ self.mf.add_file(f)
+
+ # go back to MF before the next steps (addon probing might have changed DF)
+ self.card._scc.select_file('3F00')
+
# add application ADFs + MF-files from profile
apps = self._match_applications()
for a in apps:
diff --git a/pySim/gsm_r.py b/pySim/gsm_r.py
index 389a8cb..cd111d6 100644
--- a/pySim/gsm_r.py
+++ b/pySim/gsm_r.py
@@ -35,8 +35,8 @@
from pySim.construct import *
import enum
+from pySim.profile import CardProfileAddon
from pySim.filesystem import *
-import pySim.ts_102_221
import pySim.ts_51_011
######################################################################
@@ -362,3 +362,15 @@
desc='Free Number Call Type 0 and 8'),
]
self.add_files(files)
+
+
+class AddonGSMR(CardProfileAddon):
+ """An Addon that can be found on either classic GSM SIM or on UICC to support GSM-R."""
+ def __init__(self):
+ files = [
+ DF_EIRENE()
+ ]
+ super().__init__('GSM-R', desc='Railway GSM', files_in_mf=files)
+
+ def probe(self, card: 'CardBase') -> bool:
+ return card.file_exists(self.files_in_mf[0].fid)
diff --git a/pySim/profile.py b/pySim/profile.py
index e464e1f..e89eeb3 100644
--- a/pySim/profile.py
+++ b/pySim/profile.py
@@ -88,6 +88,7 @@
shell_cmdsets : List of cmd2 shell command sets of profile-specific commands
cla : class byte that should be used with cards of this profile
sel_ctrl : selection control bytes class byte that should be used with cards of this profile
+ addons: List of optional CardAddons that a card of this profile might have
"""
self.name = name
self.desc = kw.get("desc", None)
@@ -97,6 +98,8 @@
self.shell_cmdsets = kw.get("shell_cmdsets", [])
self.cla = kw.get("cla", "00")
self.sel_ctrl = kw.get("sel_ctrl", "0004")
+ # list of optional addons that a card of this profile might have
+ self.addons = kw.get("addons", [])
def __str__(self):
return self.name
@@ -161,3 +164,33 @@
return p()
return None
+
+ def add_addon(self, addon: 'CardProfileAddon'):
+ assert(addon not in self.addons)
+ # we don't install any additional files, as that is happening in the RuntimeState.
+ self.addons.append(addon)
+
+class CardProfileAddon:
+ """A Card Profile Add-on is something that is not a card application or a full stand-alone
+ card profile, but an add-on to an existing profile. Think of GSM-R specific files existing
+ on what is otherwise a SIM or USIM+SIM card."""
+
+ def __init__(self, name: str, **kw):
+ """
+ Args:
+ desc (str) : Description
+ files_in_mf : List of CardEF instances present in MF
+ shell_cmdsets : List of cmd2 shell command sets of profile-specific commands
+ """
+ self.name = name
+ self.desc = kw.get("desc", None)
+ self.files_in_mf = kw.get("files_in_mf", [])
+ self.shell_cmdsets = kw.get("shell_cmdsets", [])
+ pass
+
+ def __str__(self):
+ return self.name
+
+ def probe(self, card: 'CardBase') -> bool:
+ """Probe a given card to determine whether or not this add-on is present/supported."""
+ return False
diff --git a/pySim/ts_102_221.py b/pySim/ts_102_221.py
index b6c003b..df8b842 100644
--- a/pySim/ts_102_221.py
+++ b/pySim/ts_102_221.py
@@ -31,7 +31,9 @@
# A UICC will usually also support 2G functionality. If this is the case, we
# need to add DF_GSM and DF_TELECOM along with the UICC related files
-from pySim.ts_51_011 import DF_GSM, DF_TELECOM
+from pySim.ts_51_011 import DF_GSM, DF_TELECOM, AddonSIM
+from pySim.gsm_r import AddonGSMR
+from pySim.cdma_ruim import AddonRUIM
ts_102_22x_cmdset = CardCommandSet('TS 102 22x', [
# TS 102 221 Section 10.1.2 Table 10.5 "Coding of Instruction Byte"
@@ -768,6 +770,11 @@
# FIXME: DF.CD
EF_UMPC(),
]
+ addons = [
+ AddonSIM,
+ AddonGSMR,
+ AddonRUIM,
+ ]
sw = {
'Normal': {
'9000': 'Normal ending of the command',
@@ -839,7 +846,7 @@
super().__init__(name, desc='ETSI TS 102 221', cla="00",
sel_ctrl="0004", files_in_mf=files, sw=sw,
- shell_cmdsets = [self.AddlShellCommands()])
+ shell_cmdsets = [self.AddlShellCommands()], addons = addons)
@staticmethod
def decode_select_response(resp_hex: str) -> object:
@@ -895,4 +902,5 @@
@staticmethod
def match_with_card(scc: SimCardCommands) -> bool:
- return match_uicc(scc) and match_sim(scc)
+ # don't ever select this profile, we only use this from pySim-trace
+ return False
diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index 1f98e72..c81bfdf 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -30,9 +30,10 @@
#
from pySim.profile import match_sim
-from pySim.profile import CardProfile
+from pySim.profile import CardProfile, CardProfileAddon
from pySim.filesystem import *
from pySim.ts_31_102_telecom import DF_PHONEBOOK, DF_MULTIMEDIA, DF_MCS, DF_V2X
+from pySim.gsm_r import AddonGSMR
import enum
from pySim.construct import *
from construct import Optional as COptional
@@ -1047,8 +1048,12 @@
},
}
+ addons = [
+ AddonGSMR,
+ ]
+
super().__init__('SIM', desc='GSM SIM Card', cla="a0",
- sel_ctrl="0000", files_in_mf=[DF_TELECOM(), DF_GSM()], sw=sw)
+ sel_ctrl="0000", files_in_mf=[DF_TELECOM(), DF_GSM()], sw=sw, addons = addons)
@staticmethod
def decode_select_response(resp_hex: str) -> object:
@@ -1104,3 +1109,17 @@
@staticmethod
def match_with_card(scc: SimCardCommands) -> bool:
return match_sim(scc)
+
+
+class AddonSIM(CardProfileAddon):
+ """An add-on that can be found on a UICC in order to support classic GSM SIM."""
+ def __init__(self):
+ files = [
+ DF_GSM(),
+ DF_TELECOM(),
+ ]
+ super().__init__('SIM', desc='GSM SIM', files_in_mf=files)
+
+ def probe(self, card:'CardBase') -> bool:
+ # we assume the add-on to be present in case DF.GSM is found on the card
+ return card.file_exists(self.files_in_mf[0].fid)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/33699
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I5866590b6d48f85eb889c9b1b8ab27936d2378b9
Gerrit-Change-Number: 33699
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/+/33689 )
Change subject: filesystem: Support selecting MF from MF
......................................................................
filesystem: Support selecting MF from MF
This was currently not handled in build_select_path_to(), resulting in
weird exceptions like 'Cannot determine path from MF(3f00) to MF(3f00)'
Change-Id: I41b9f047ee5dc6b91b487f370f011af994aaca04
---
M pySim/filesystem.py
1 file changed, 15 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/89/33689/1
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 04e849b..22ff60d 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -149,6 +149,9 @@
def build_select_path_to(self, target: 'CardFile') -> Optional[List['CardFile']]:
"""Build the relative sequence of files we need to traverse to get from us to 'target'."""
+ # special-case handling for selecting MF while we MF is selected
+ if target == target.get_mf():
+ return [target]
cur_fqpath = self.fully_qualified_path_fobj()
target_fqpath = target.fully_qualified_path_fobj()
inter_path = []
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/33689
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I41b9f047ee5dc6b91b487f370f011af994aaca04
Gerrit-Change-Number: 33689
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange
Attention is currently required from: daniel.
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/33686 )
Change subject: osmo_io: Add function to change the maximum length of the tx_queue
......................................................................
Patch Set 2: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/33686
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If3d1de8bffe1123002515878655ea9e02b482888
Gerrit-Change-Number: 33686
Gerrit-PatchSet: 2
Gerrit-Owner: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: daniel <dwillmann(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 11 Jul 2023 15:39:22 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: daniel.
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/33685 )
Change subject: osmo_io: Document expectation that segmentation_cb() can modify msgb
......................................................................
Patch Set 1: Code-Review+1
(1 comment)
File src/core/osmo_io.c:
https://gerrit.osmocom.org/c/libosmocore/+/33685/comment/e410e6d3_e3654b59
PS1, Line 264: memcpy(msgb_data(msg_pending), data + expected_len, extra_len);
> No - msg_pending is a new msg allocation, data is from msg->data
Ack
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/33685
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Idd2115baae98a7818aabb26232d4423d2d48fb5c
Gerrit-Change-Number: 33685
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: daniel <dwillmann(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 11 Jul 2023 15:38:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: pespin <pespin(a)sysmocom.de>
Comment-In-Reply-To: daniel <dwillmann(a)sysmocom.de>
Gerrit-MessageType: comment
Attention is currently required from: pespin.
daniel has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/33686 )
Change subject: osmo_io: Add function to change the maximum length of the tx_queue
......................................................................
Patch Set 2:
(1 comment)
File src/core/osmo_io.c:
https://gerrit.osmocom.org/c/libosmocore/+/33686/comment/10f9a401_6f364f85
PS1, Line 549: void osmo_iofd_set_txqueue_size(struct osmo_io_fd *iofd, unsigned int size)
> osmo_iofd_set_txqueue_max_length()?
Ack
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/33686
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If3d1de8bffe1123002515878655ea9e02b482888
Gerrit-Change-Number: 33686
Gerrit-PatchSet: 2
Gerrit-Owner: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 11 Jul 2023 15:37:29 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: comment
Attention is currently required from: pespin.
Hello Jenkins Builder, pespin,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/libosmocore/+/33686
to look at the new patch set (#2).
Change subject: osmo_io: Add function to change the maximum length of the tx_queue
......................................................................
osmo_io: Add function to change the maximum length of the tx_queue
Change-Id: If3d1de8bffe1123002515878655ea9e02b482888
---
M include/osmocom/core/osmo_io.h
M src/core/libosmocore.map
M src/core/osmo_io.c
3 files changed, 20 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/86/33686/2
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/33686
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If3d1de8bffe1123002515878655ea9e02b482888
Gerrit-Change-Number: 33686
Gerrit-PatchSet: 2
Gerrit-Owner: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newpatchset
Attention is currently required from: pespin.
daniel has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/32536 )
Change subject: osmo_io: Add io_uring backend
......................................................................
Set Ready For Review
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/32536
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I5152129eb84b31ccc9e02bc2a5c5bdb046d331bc
Gerrit-Change-Number: 32536
Gerrit-PatchSet: 6
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: daniel <dwillmann(a)sysmocom.de>
Gerrit-CC: laforge <laforge(a)osmocom.org>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 11 Jul 2023 15:37:08 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment