dexter has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38196?usp=email )
Change subject: filesystem, cosmetic: remove excess whitespace
......................................................................
filesystem, cosmetic: remove excess whitespace
Change-Id: I902670590ae75a5d197616ae37d8268a60125121
---
M pySim/filesystem.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
pespin: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 43a72f2..c55bcbe 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -179,7 +179,7 @@
"""Return a dict of {'identifier': self} tuples.
Args:
- alias : Add an alias with given name to 'self'
+ alias : Add an alias with given name to 'self'
flags : Specify which selectables to return 'FIDS' and/or 'NAMES';
If not specified, all selectables will be returned.
Returns:
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38196?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I902670590ae75a5d197616ae37d8268a60125121
Gerrit-Change-Number: 38196
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38196?usp=email )
Change subject: filesystem, cosmetic: remove excess whitespace
......................................................................
filesystem, cosmetic: remove excess whitespace
Change-Id: I902670590ae75a5d197616ae37d8268a60125121
---
M pySim/filesystem.py
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/96/38196/1
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 43a72f2..c55bcbe 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -179,7 +179,7 @@
"""Return a dict of {'identifier': self} tuples.
Args:
- alias : Add an alias with given name to 'self'
+ alias : Add an alias with given name to 'self'
flags : Specify which selectables to return 'FIDS' and/or 'NAMES';
If not specified, all selectables will be returned.
Returns:
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38196?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I902670590ae75a5d197616ae37d8268a60125121
Gerrit-Change-Number: 38196
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Attention is currently required from: dexter.
laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/pysim/+/38195?usp=email )
Change subject: filesystem: pass total_len to construct of when encoding file contents
......................................................................
Patch Set 1: Code-Review-1
(4 comments)
File pySim/filesystem.py:
https://gerrit.osmocom.org/c/pysim/+/38195/comment/de34e383_98a0ce51?usp=em… :
PS1, Line 182: '
unrelated cosmetic change. Not critical, but in case you are doing another version of this patch anyway, this should be removed.
https://gerrit.osmocom.org/c/pysim/+/38195/comment/336e860e_8ae0f3e4?usp=em… :
PS1, Line 747: if total_len is not None:
this could deserve some documentation (doc-string or comment). For somebody not super familiar with every bit of the code (I guess everyone ecxcept me and now you) the functionality will not be obvious. You could also do it like this
```
if total_len is not None: # caller has provided the on-card size
...
elif self.size[1] is not None: # use the recommended size
...
elif self.size[0] is not None: # use the minimum size
```
btw: I'm not entirely sure if self.size could be None, at whcih point self.size[1] or [0] would cause an exception.
https://gerrit.osmocom.org/c/pysim/+/38195/comment/839cddea_3246df69?usp=em… :
PS1, Line 1043: __get_rec_len
why do we have double-underscores here but single-underscore for _get_size() above? Also: please add comments/documentation like for _get_size, as I requested above.
https://gerrit.osmocom.org/c/pysim/+/38195/comment/c4c2b572_564fe968?usp=em… :
PS1, Line 1266: return b2h(filter_dict(build_construct(self._construct, abstract_data, self._get_size(total_len))))
Did you test that? I think a _get_rec_len() would actually be required here. Calling _get_size() of the parent class (TransparentEF) will return the total file size, ad not the size of an individual record.
The TransRecEf.encode_record_{hex,bin} should only include a single record. The TransRecEF._encode_bin() below then iterates over all records.
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38195?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I1b7a51594fbc5d9fe01132c39354a2fa88d53f9b
Gerrit-Change-Number: 38195
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: dexter <pmaier(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 17 Sep 2024 18:25:04 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38193?usp=email )
Change subject: runtime: add new API functions to get the record len and file size
......................................................................
runtime: add new API functions to get the record len and file size
We have an API function to get the number of records, let's now also
add API functions to get the record length and the overall size of
the currently selected file.
Related: OS#5714
Change-Id: Ica7811c04161d8098b40c7219ed6b939df716cfd
---
M pySim/runtime.py
1 file changed, 6 insertions(+), 0 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim/runtime.py b/pySim/runtime.py
index b903ccb..898008e 100644
--- a/pySim/runtime.py
+++ b/pySim/runtime.py
@@ -211,6 +211,12 @@
def selected_file_num_of_rec(self) -> Optional[int]:
return self.selected_file_fcp['file_descriptor'].get('num_of_rec')
+ def selected_file_record_len(self) -> Optional[int]:
+ return self.selected_file_fcp['file_descriptor'].get('record_len')
+
+ def selected_file_size(self) -> Optional[int]:
+ return self.selected_file_fcp.get('file_size')
+
def get_cwd(self) -> CardDF:
"""Obtain the current working directory.
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38193?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ica7811c04161d8098b40c7219ed6b939df716cfd
Gerrit-Change-Number: 38193
Gerrit-PatchSet: 2
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Attention is currently required from: dexter.
laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/pysim/+/38194?usp=email )
Change subject: pySim-shell: improve command "desc"
......................................................................
Patch Set 1: Code-Review+1
(1 comment)
File pySim-shell.py:
https://gerrit.osmocom.org/c/pysim/+/38194/comment/6f7c0e21_a5ac505e?usp=em… :
PS1, Line 783: self._cmd.poutput(" actual_size: %s" % str(self._cmd.lchan.selected_file_size()))
one might also add the total/max file size of a BerTlvEF here. (can be a separate patch in the future).
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38194?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I98e139ba2bf35df5524245cdd96f5c52cf09b986
Gerrit-Change-Number: 38194
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: dexter <pmaier(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 17 Sep 2024 17:59:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: dexter.
laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/pysim/+/38193?usp=email )
Change subject: runtime: add new API functions to get the record len and file size
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38193?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ica7811c04161d8098b40c7219ed6b939df716cfd
Gerrit-Change-Number: 38193
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: dexter <pmaier(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 17 Sep 2024 17:55:23 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38193?usp=email )
Change subject: runtime: add new API functions to get the record len and file size
......................................................................
runtime: add new API functions to get the record len and file size
We have an API function to get the number of records, let's now also
add API functions to get the record length and the overall size of
the currently selected file.
Related: OS#5714
Change-Id: Ica7811c04161d8098b40c7219ed6b939df716cfd
---
M pySim/runtime.py
1 file changed, 6 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/93/38193/1
diff --git a/pySim/runtime.py b/pySim/runtime.py
index b903ccb..898008e 100644
--- a/pySim/runtime.py
+++ b/pySim/runtime.py
@@ -211,6 +211,12 @@
def selected_file_num_of_rec(self) -> Optional[int]:
return self.selected_file_fcp['file_descriptor'].get('num_of_rec')
+ def selected_file_record_len(self) -> Optional[int]:
+ return self.selected_file_fcp['file_descriptor'].get('record_len')
+
+ def selected_file_size(self) -> Optional[int]:
+ return self.selected_file_fcp.get('file_size')
+
def get_cwd(self) -> CardDF:
"""Obtain the current working directory.
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38193?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ica7811c04161d8098b40c7219ed6b939df716cfd
Gerrit-Change-Number: 38193
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38195?usp=email )
Change subject: filesystem: pass total_len to construct of when encoding file contents
......................................................................
filesystem: pass total_len to construct of when encoding file contents
In our construct models we frequently use a context parameter "total_len",
we also pass this parameter to construct when we decode files, but we
do not pass it when we generate files. This is a problem, because when
total_len is used in the construct model, this parameter must be known
also when decoding the file.
Let's make sure that the total_len is properly determined and and passed
to construct (via pyosmocom)
Related: OS#5714
Change-Id: I1b7a51594fbc5d9fe01132c39354a2fa88d53f9b
---
M pySim/filesystem.py
M pySim/runtime.py
M requirements.txt
3 files changed, 36 insertions(+), 16 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/95/38195/1
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 43a72f2..5258569 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -179,7 +179,7 @@
"""Return a dict of {'identifier': self} tuples.
Args:
- alias : Add an alias with given name to 'self'
+ alias : Add an alias with given name to 'self'
flags : Specify which selectables to return 'FIDS' and/or 'NAMES';
If not specified, all selectables will be returned.
Returns:
@@ -743,7 +743,17 @@
return t.to_dict()
return {'raw': raw_bin_data.hex()}
- def encode_bin(self, abstract_data: dict) -> bytearray:
+ def _get_size(self, total_len : int = None):
+ if total_len is not None:
+ return {"total_len" : total_len}
+ elif self.size[1] is not None:
+ return {"total_len" : self.size[1]}
+ elif self.size[0] is not None:
+ return {"total_len" : self.size[0]}
+ else:
+ return {"total_len" : None}
+
+ def encode_bin(self, abstract_data: dict, total_len : int = None) -> bytearray:
"""Encode abstract representation into raw (binary) data.
A derived class would typically provide an _encode_bin() or _encode_hex() method
@@ -762,7 +772,7 @@
if callable(method):
return h2b(method(abstract_data))
if self._construct:
- return build_construct(self._construct, abstract_data)
+ return build_construct(self._construct, abstract_data, self._get_size(total_len))
if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
@@ -770,7 +780,7 @@
raise NotImplementedError(
"%s encoder not yet implemented. Patches welcome." % self)
- def encode_hex(self, abstract_data: dict) -> str:
+ def encode_hex(self, abstract_data: dict, total_len : int = None) -> str:
"""Encode abstract representation into raw (hex string) data.
A derived class would typically provide an _encode_bin() or _encode_hex() method
@@ -790,7 +800,7 @@
raw_bin_data = method(abstract_data)
return b2h(raw_bin_data)
if self._construct:
- return b2h(build_construct(self._construct, abstract_data))
+ return b2h(build_construct(self._construct, abstract_data, self._get_size(total_len)))
if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
@@ -1030,7 +1040,17 @@
return t.to_dict()
return {'raw': raw_hex_data}
- def encode_record_hex(self, abstract_data: dict, record_nr: int) -> str:
+ def __get_rec_len(self, total_len : int = None):
+ if total_len is not None:
+ return {"total_len" : total_len}
+ elif self.rec_len[1] is not None:
+ return {"total_len" : self.rec_len[1]}
+ elif self.rec_len[0] is not None:
+ return {"total_len" : self.rec_len[0]}
+ else:
+ return {"total_len" : None}
+
+ def encode_record_hex(self, abstract_data: dict, record_nr: int, total_len: int = None) -> str:
"""Encode abstract representation into raw (hex string) data.
A derived class would typically provide an _encode_record_bin() or _encode_record_hex()
@@ -1051,7 +1071,7 @@
raw_bin_data = method(abstract_data, record_nr=record_nr)
return b2h(raw_bin_data)
if self._construct:
- return b2h(build_construct(self._construct, abstract_data))
+ return b2h(build_construct(self._construct, abstract_data, self.__get_rec_len(total_len)))
if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
@@ -1059,7 +1079,7 @@
raise NotImplementedError(
"%s encoder not yet implemented. Patches welcome." % self)
- def encode_record_bin(self, abstract_data: dict, record_nr : int) -> bytearray:
+ def encode_record_bin(self, abstract_data: dict, record_nr : int, total_len : int = None) -> bytearray:
"""Encode abstract representation into raw (binary) data.
A derived class would typically provide an _encode_record_bin() or _encode_record_hex()
@@ -1079,7 +1099,7 @@
if callable(method):
return h2b(method(abstract_data, record_nr=record_nr))
if self._construct:
- return build_construct(self._construct, abstract_data)
+ return build_construct(self._construct, abstract_data, self.__get_rec_len(total_len))
if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
@@ -1224,7 +1244,7 @@
return t.to_dict()
return {'raw': raw_hex_data}
- def encode_record_hex(self, abstract_data: dict) -> str:
+ def encode_record_hex(self, abstract_data: dict, total_len : int = None) -> str:
"""Encode abstract representation into raw (hex string) data.
A derived class would typically provide an _encode_record_bin() or _encode_record_hex()
@@ -1243,7 +1263,7 @@
if callable(method):
return b2h(method(abstract_data))
if self._construct:
- return b2h(filter_dict(build_construct(self._construct, abstract_data)))
+ return b2h(filter_dict(build_construct(self._construct, abstract_data, self._get_size(total_len))))
if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
@@ -1251,7 +1271,7 @@
raise NotImplementedError(
"%s encoder not yet implemented. Patches welcome." % self)
- def encode_record_bin(self, abstract_data: dict) -> bytearray:
+ def encode_record_bin(self, abstract_data: dict, total_len : int = None) -> bytearray:
"""Encode abstract representation into raw (binary) data.
A derived class would typically provide an _encode_record_bin() or _encode_record_hex()
@@ -1270,7 +1290,7 @@
if callable(method):
return h2b(method(abstract_data))
if self._construct:
- return filter_dict(build_construct(self._construct, abstract_data))
+ return filter_dict(build_construct(self._construct, abstract_data, self._get_size(total_len)))
if self._tlv:
t = self._tlv() if inspect.isclass(self._tlv) else self._tlv
t.from_dict(abstract_data)
diff --git a/pySim/runtime.py b/pySim/runtime.py
index 898008e..5281857 100644
--- a/pySim/runtime.py
+++ b/pySim/runtime.py
@@ -518,7 +518,7 @@
Args:
data : abstract data which is to be encoded and written
"""
- data_hex = self.selected_file.encode_hex(data)
+ data_hex = self.selected_file.encode_hex(data, self.selected_file_size())
return self.update_binary(data_hex)
def read_record(self, rec_nr: int = 0):
@@ -568,7 +568,7 @@
rec_nr : Record number to read
data_hex : Abstract data to be written
"""
- data_hex = self.selected_file.encode_record_hex(data, rec_nr)
+ data_hex = self.selected_file.encode_record_hex(data, rec_nr, self.selected_file_record_len())
return self.update_record(rec_nr, data_hex)
def retrieve_data(self, tag: int = 0):
diff --git a/requirements.txt b/requirements.txt
index 99fd5f9..25e3654 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,7 +5,7 @@
jsonpath-ng
construct>=2.9.51
bidict
-pyosmocom>=0.0.2
+pyosmocom>=0.0.3
pyyaml>=5.1
termcolor
colorlog
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38195?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I1b7a51594fbc5d9fe01132c39354a2fa88d53f9b
Gerrit-Change-Number: 38195
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>