aboutsummaryrefslogtreecommitdiffstats
path: root/pySim/commands.py
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2023-09-07 12:43:12 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2023-09-07 14:19:26 +0200
commit37e57e0c45320fe3b855e3ec57ab52145c8b2987 (patch)
treea7de494c1a9830fb4e32f51fd99642fc7aca8ee7 /pySim/commands.py
parent0ac4d3c7dcaa4f1fdfa632c93e6af2bafbd7501d (diff)
filesystem: add attribute "leftpad" to class LinFixedEF
In some cases, the specs do not specify an absolute record length. Instead there may be only a minimum record length specified. The card vendor may then chose to use larger record length at will. This usually is no problem since the data is usually written from the left and the remaining bytes are padded at the end (right side) of the data. However in some rare cases (EF.MSISDN, see also 3GPP TS 51.011, section 10.5.5) the data must be written right-aligned towards the physical record length. This means that the data is padded from the left in this case. To fix this: Let's add a "leftpad" flag to LinFixedEF, which we set to true in those corner cases. The code that updates the record in commands.py must then check this flag and padd the data accordingly. Change-Id: I241d9fd656f9064a3ebb4e8e01a52b6b030f9923 Related: OS#5714
Diffstat (limited to 'pySim/commands.py')
-rw-r--r--pySim/commands.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/pySim/commands.py b/pySim/commands.py
index 477cb2b..e072069 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -26,7 +26,7 @@ import typing # construct also has a Union, so we do typing.Union below
from construct import *
from pySim.construct import LV
-from pySim.utils import rpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i, str_sanitize, expand_hex
+from pySim.utils import rpad, lpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i, str_sanitize, expand_hex
from pySim.utils import Hexstr, SwHexstr, ResTuple
from pySim.exceptions import SwMatchError
from pySim.transport import LinkBase
@@ -269,7 +269,7 @@ class SimCardCommands:
data.lower(), res[0].lower()))
def update_record(self, ef: Path, rec_no: int, data: Hexstr, force_len: bool = False,
- verify: bool = False, conserve: bool = False) -> ResTuple:
+ verify: bool = False, conserve: bool = False, leftpad: bool = False) -> ResTuple:
"""Execute UPDATE RECORD.
Args:
@@ -279,6 +279,7 @@ class SimCardCommands:
force_len : enforce record length by using the actual data length
verify : verify data by re-reading the record
conserve : read record and compare it with data, skip write on match
+ leftpad : apply 0xff padding from the left instead from the right side.
"""
res = self.select_path(ef)
@@ -295,7 +296,10 @@ class SimCardCommands:
raise ValueError('Data length exceeds record length (expected max %d, got %d)' % (
rec_length, len(data) // 2))
elif (len(data) // 2 < rec_length):
- data = rpad(data, rec_length * 2)
+ if leftpad:
+ data = lpad(data, rec_length * 2)
+ else:
+ data = rpad(data, rec_length * 2)
# Save write cycles by reading+comparing before write
if conserve: