equip/init: read the selected EF directly, bound the startup drain

pySim's scc.read_binary/read_record call select_path(ef) first, so the
ICCID, network-state, EF.ARR and EF.PBR readers - which had already made a
parent-scoped selection and hold its FCP - sent a second SELECT per file
and per record.  _read_selected_ef() issues READ BINARY (chunked at
max_cmd_len from the FCP file size) / READ RECORD (b2<rec>04<len> at the
FCP record length) directly; the pySim helpers stay as the fallback when
the FCP lacks the value.

The startup TERMINAL PROFILE drain now breaks on the chain's idle SW
instead of polling STATUS once more.

Measured on the last startup: ~3.4 s traced init (netstate/ARR/PBR 271
APDUs / 1.26 s incl. 169 SELECTs; the card's own TP processing 1.58 s);
the change removes ~0.7-0.8 s of the read phase without touching any data
or the TP.

v3.38.1; tests: tests/test_read_selected.py (direct reads, chunking, the
fallback and the drain source pin) and the ARR/PBR/ICCID/netstate fakes.
1067 Python + 1075 frontend.  sw cache simple-v482.
This commit is contained in:
catarrh committed 2026-10-24 18:54:31 +03:00
1 parent 80cbd8e935
commit 0231df905c
11 files changed
+252 -20

No files matched your search

+27
View File
@@ -13,6 +13,28 @@ from types import SimpleNamespace
from pysim_simple_server import server
class FakeScc:
"""Serves the selected fake file for direct READ BINARY/RECORD APDUs."""
cla_byte = '00'
max_cmd_len = 255
def __init__(self, lchan):
self.lchan = lchan
self.sent = []
def send_apdu_checksw(self, pdu):
self.sent.append(pdu)
kind, val = self.lchan.files[self.lchan.selected]
if pdu[2:4] == 'b0':
off = int(pdu[4:8], 16)
ln = int(pdu[8:10], 16)
return val[off * 2:(off + ln) * 2], '9000'
if pdu[2:4] == 'b2':
return val[int(pdu[4:6], 16) - 1], '9000'
raise AssertionError('unexpected APDU %s' % pdu)
class FakeLchan:
def __init__(self, files):
self.files = files # path -> ('transparent', hex) | ('record', [hex])
@@ -23,6 +45,9 @@ class FakeLchan:
self.selected_file_type = lambda: 'ef'
self.selected_file_structure = lambda: self.files[self.selected][0]
self.selected_file_num_of_rec = lambda: len(self.files[self.selected][1])
self.selected_file_record_len = lambda: 2
self.selected_file_size = lambda: len(self.files[self.selected][1]) // 2
self.scc = FakeScc(self)
self.read_binary = lambda: (self.files[self.selected][1], '9000')
self.read_record = lambda i: (self.files[self.selected][1][i - 1], '9000')
@@ -68,6 +93,8 @@ class NetStateServerTests(unittest.TestCase):
('select', 'DF.GSM/6F07'),
('select', 'ADF.USIM/6FCD'),
('select', 'ADF.USIM/6FE4')])
# v3.38.1: the reads use the selected file directly - no second SELECT
self.assertEqual(lchan.scc.sent, ['00b0000003', '00b2010402', '00b2020402'])
def test_install_builds_the_state_and_network(self):
files = {'imsi': {'name': 'EF.IMSI', 'fid': '6F07', 'present': True,