[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. runtime: refactor file selection methods select and select_file The implementation of the methods select and select_file of class RuntimeLchan is a bit complex. We access the card directly in several places which makes it difficult to track the state changes. We should clean this up so that we call self.rs.card.select_adf_by_aid/ self.scc.select_file from a single place only. This means that the method select uses the method select_file. This results in a much cleaner implementation. We also should take care that the important states that we track (selected_file, selected_adf, etc.) are updated by a single private method. Since the update always must happen after a select _select_post is a good place to do this. Related: OS#5418 Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 --- M pySim/runtime.py 1 file changed, 72 insertions(+), 40 deletions(-) Approvals: fixeria: Looks good to me, but someone else must approve Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim/runtime.py b/pySim/runtime.py index 1155433..f836ec8 100644 --- a/pySim/runtime.py +++ b/pySim/runtime.py @@ -255,6 +255,8 @@ raise ValueError( "Cannot select unknown file by name %s, only hexadecimal 4 digit FID is allowed" % fid) +self._select_pre(cmd_app) + try: # We access the card through the select_file method of the scc object. # If we succeed, we know that the file exists on the card and we may @@ -264,6 +266,7 @@ # so we do not have to update any state in that case. (data, sw) = self.scc.select_file(fid) except SwMatchError as swm: +self._select_post(cmd_app) k = self.interpret_sw(swm.sw_actual) if not k: raise(swm) @@ -282,8 +285,8 @@ desc="elementary file, manually added at runtime") self.selected_file.add_files([f]) -self.selected_file = f -return select_resp, data + +self._select_post(cmd_app, f, data) def _select_pre(self, cmd_app): # unregister commands of old file @@ -291,7 +294,17 @@ for c in self.selected_file.shell_commands: cmd_app.unregister_command_set(c) -def _select_post(self, cmd_app): +def _select_post(self, cmd_app, file:Optional[CardFile] = None, select_resp_data = None): +# we store some reference data (see above) about the currently selected file. +# This data must be updated after every select. +if file: +self.selected_file = file +if isinstance(file, CardADF): +self.selected_adf = file +if select_resp_data: +self.selected_file_fcp_hex = select_resp_data +self.selected_file_fcp = self.selected_file.decode_select_response(select_resp_data) + # register commands of new file if cmd_app and self.selected_file.shell_commands: for c in self.selected_file.shell_commands: @@ -308,22 +321,31 @@ inter_path = self.selected_file.build_select_path_to(file) if not inter_path: raise RuntimeError('Cannot determine path from %s to %s' % (self.selected_file, file)) - self._select_pre(cmd_app) -for p in inter_path: +# be sure the variables that we pass to _select_post contain valid values. +selected_file = self.selected_file +data = self.selected_file_fcp_hex + +for f in inter_path: try: -if isinstance(p, CardADF): -(data, sw) = self.rs.card.select_adf_by_aid(p.aid, scc=self.scc) -self.selected_adf = p +# We now directly accessing the card to perform the selection. This +# will change the state of the card, so we must take care to update +# the local state (lchan) as well. This is done in the method +# _select_post. It should be noted that the caller must always use +# the methods select_file or select. The caller must not access the +# card directly since this would lead into an incoherence of the +# card state and the state of the lchan. +if isinstance(f, CardADF): +(data, sw) = self.rs.card.select_adf_by_aid(f.aid, scc=self.scc) else: -(data, sw) = self.scc.select_file(p.fid) -self.selected_file = p +(data, sw) = self.scc.select_file(f.fid) +selected_file = f except SwMatchError as swm: -
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: dexter, fixeria. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 5: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 5 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: fixeria Gerrit-Attention: dexter Gerrit-Comment-Date: Sat, 16 Dec 2023 19:45:11 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: fixeria, laforge. dexter has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 4: This change is ready for review. -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 4 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: laforge Gerrit-Attention: fixeria Gerrit-Comment-Date: Wed, 13 Dec 2023 11:48:22 + Gerrit-HasComments: No Gerrit-Has-Labels: No Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: dexter, laforge. fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 4: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 4 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: laforge Gerrit-Attention: dexter Gerrit-Comment-Date: Wed, 13 Dec 2023 09:28:59 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: fixeria, laforge. Hello Jenkins Builder, fixeria, laforge, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email to look at the new patch set (#4). The following approvals got outdated and were removed: Code-Review+1 by laforge, Verified+1 by Jenkins Builder Change subject: runtime: refactor file selection methods select and select_file .. runtime: refactor file selection methods select and select_file The implementation of the methods select and select_file of class RuntimeLchan is a bit complex. We access the card directly in several places which makes it difficult to track the state changes. We should clean this up so that we call self.rs.card.select_adf_by_aid/ self.scc.select_file from a single place only. This means that the method select uses the method select_file. This results in a much cleaner implementation. We also should take care that the important states that we track (selected_file, selected_adf, etc.) are updated by a single private method. Since the update always must happen after a select _select_post is a good place to do this. Related: OS#5418 Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 --- M pySim/runtime.py 1 file changed, 72 insertions(+), 40 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/32/34932/4 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 4 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: laforge Gerrit-Attention: fixeria Gerrit-MessageType: newpatchset
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: fixeria, laforge. dexter has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 4: (2 comments) File pySim/runtime.py: https://gerrit.osmocom.org/c/pysim/+/34932/comment/0ca99f6a_1263e04f PS3, Line 357: failes > fails (without 'e') Done https://gerrit.osmocom.org/c/pysim/+/34932/comment/68ed37cd_7fea7177 PS3, Line 383: f = sels[name] > unused? you're doing `sels[name]` below... Done -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 4 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: laforge Gerrit-Attention: fixeria Gerrit-Comment-Date: Wed, 13 Dec 2023 09:08:48 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: dexter. fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 3: (2 comments) File pySim/runtime.py: https://gerrit.osmocom.org/c/pysim/+/34932/comment/780e95ff_025b0e03 PS3, Line 357: failes fails (without 'e') https://gerrit.osmocom.org/c/pysim/+/34932/comment/9d063036_1f488791 PS3, Line 383: f = sels[name] unused? you're doing `sels[name]` below... -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 3 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: dexter Gerrit-Comment-Date: Thu, 07 Dec 2023 17:32:34 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: dexter, fixeria. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 3: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 3 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: fixeria Gerrit-Attention: dexter Gerrit-Comment-Date: Thu, 07 Dec 2023 13:19:04 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: dexter, fixeria, laforge. Hello Jenkins Builder, fixeria, laforge, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email to look at the new patch set (#3). The following approvals got outdated and were removed: Code-Review+1 by fixeria, Code-Review+1 by laforge, Verified+1 by Jenkins Builder Change subject: runtime: refactor file selection methods select and select_file .. runtime: refactor file selection methods select and select_file The implementation of the methods select and select_file of class RuntimeLchan is a bit complex. We access the card directly in several places which makes it difficult to track the state changes. We should clean this up so that we call self.rs.card.select_adf_by_aid/ self.scc.select_file from a single place only. This means that the method select uses the method select_file. This results in a much cleaner implementation. We also should take care that the important states that we track (selected_file, selected_adf, etc.) are updated by a single private method. Since the update always must happen after a select _select_post is a good place to do this. Related: OS#5418 Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 --- M pySim/runtime.py 1 file changed, 73 insertions(+), 40 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/32/34932/3 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 3 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: laforge Gerrit-Attention: fixeria Gerrit-Attention: dexter Gerrit-MessageType: newpatchset
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: dexter. fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 2: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 2 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: dexter Gerrit-Comment-Date: Wed, 01 Nov 2023 16:41:30 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: dexter, fixeria. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 2: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 2 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: fixeria Gerrit-Attention: dexter Gerrit-Comment-Date: Wed, 01 Nov 2023 15:58:28 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: fixeria, laforge. Hello Jenkins Builder, fixeria, laforge, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email to look at the new patch set (#2). The following approvals got outdated and were removed: Verified+1 by Jenkins Builder Change subject: runtime: refactor file selection methods select and select_file .. runtime: refactor file selection methods select and select_file The implementation of the methods select and select_file of class RuntimeLchan is a bit complex. We access the card directly in several places which makes it difficult to track the state changes. We should clean this up so that we call self.rs.card.select_adf_by_aid/ self.scc.select_file from a single place only. This means that the method select uses the method select_file. This results in a much cleaner implementation. We also should take care that the important states that we track (selected_file, selected_adf, etc.) are updated by a single private method. Since the update always must happen after a select _select_post is a good place to do this. Related: OS#6210 Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 --- M pySim/runtime.py 1 file changed, 89 insertions(+), 41 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/32/34932/2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 2 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: laforge Gerrit-Attention: fixeria Gerrit-MessageType: newpatchset
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: fixeria, laforge. dexter has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 2: (4 comments) File pySim/runtime.py: https://gerrit.osmocom.org/c/pysim/+/34932/comment/965df6aa_a206d527 PS1, Line 174: > yeah, we've seen this already several times. […] Done https://gerrit.osmocom.org/c/pysim/+/34932/comment/b4df4396_b30556bf PS1, Line 296: CardFile > `Optional[CardFile]` Done https://gerrit.osmocom.org/c/pysim/+/34932/comment/be65dd6f_2e57cdef PS1, Line 298: > tabs vs spaces Done https://gerrit.osmocom.org/c/pysim/+/34932/comment/41d1b7bd_4c2be2cf PS1, Line 375: > tabs vs spaces Done -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 2 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: laforge Gerrit-Attention: fixeria Gerrit-Comment-Date: Wed, 01 Nov 2023 14:53:32 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: laforge Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: dexter, fixeria. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 1: (1 comment) File pySim/runtime.py: https://gerrit.osmocom.org/c/pysim/+/34932/comment/4549be3a_2151ad5c PS1, Line 174: > Tabs should not be mixed with spaces. Please configure your editor to use > spaces for *.py. yeah, we've seen this already several times. This should be done automatically by editor config so we don't need to waste review cycles on it. -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 1 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: fixeria Gerrit-Attention: dexter Gerrit-Comment-Date: Wed, 01 Nov 2023 13:39:47 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
Attention is currently required from: dexter, laforge. fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. Patch Set 1: (4 comments) File pySim/runtime.py: https://gerrit.osmocom.org/c/pysim/+/34932/comment/67d5d0a2_2a4e2b04 PS1, Line 174: Tabs should not be mixed with spaces. Please configure your editor to use spaces for *.py. https://gerrit.osmocom.org/c/pysim/+/34932/comment/b7c3a251_b80da082 PS1, Line 296: CardFile `Optional[CardFile]` https://gerrit.osmocom.org/c/pysim/+/34932/comment/b2f4ed6d_e27573d6 PS1, Line 298: tabs vs spaces https://gerrit.osmocom.org/c/pysim/+/34932/comment/db0bba04_ab29f17c PS1, Line 375: tabs vs spaces -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34932?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 Gerrit-Change-Number: 34932 Gerrit-PatchSet: 1 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Attention: laforge Gerrit-Attention: dexter Gerrit-Comment-Date: Wed, 01 Nov 2023 09:37:23 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
[M] Change in pysim[master]: runtime: refactor file selection methods select and select_file
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/34932?usp=email ) Change subject: runtime: refactor file selection methods select and select_file .. runtime: refactor file selection methods select and select_file The implementation of the methods select and select_file of class RuntimeLchan is a bit complex. We access the card directly in several places which makes it difficult to track the state changes. We should clean this up so that we call self.rs.card.select_adf_by_aid/ self.scc.select_file from a single place only. This means that the method select uses the method select_file. This results in a much cleaner implementation. We also should take care that the important states that we track (selected_file, selected_adf, etc.) are updated by a single private method. Since the update always must happen after a select _select_post is a good place to do this. Related: OS#6210 Change-Id: I9ae213f3b078983f3e6d4c11db38fdbe504c84f2 --- M pySim/runtime.py 1 file changed, 89 insertions(+), 41 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/32/34932/1 diff --git a/pySim/runtime.py b/pySim/runtime.py index 8660724..feaa355 100644 --- a/pySim/runtime.py +++ b/pySim/runtime.py @@ -64,7 +64,7 @@ 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') +self.lchan[0].select('3F00') # add application ADFs + MF-files from profile apps = self._match_applications() @@ -110,6 +110,12 @@ # probe for those applications for f in sorted(set(apps_profile) - set(apps_taken), key=str): try: +# we can not use the lchan provided methods select, or select_file +# since those method work on an already finished file model. At +# this point we are still in the initialization process, so it is +# no problem when we access the card directly without caring about +# updating other states. For normal selects at runtime, the caller +# must use the lchan provided methods select or select_file! data, sw = self.card.select_adf_by_aid(f.aid) if sw == "9000": print(" %s: %s" % (f.name, f.aid)) @@ -163,11 +169,14 @@ def __init__(self, lchan_nr: int, rs: RuntimeState): self.lchan_nr = lchan_nr self.rs = rs +self.scc = self.rs.card._scc.fork_lchan(lchan_nr) + + # File reference data self.selected_file = self.rs.mf self.selected_adf = None self.selected_file_fcp = None self.selected_file_fcp_hex = None -self.scc = self.rs.card._scc.fork_lchan(lchan_nr) + def add_lchan(self, lchan_nr: int) -> 'RuntimeLchan': """Add a new logical channel from the current logical channel. Just affects @@ -246,9 +255,17 @@ raise ValueError( "Cannot select unknown file by name %s, only hexadecimal 4 digit FID is allowed" % fid) +self._select_pre(cmd_app) + try: +# We access the card through the select_file method of the scc object. +# If we succeed, we know that the file exists and we may proceed with +# creating a new file at run time. In case the file does not exist, we +# just abort. The state on the card (selected file/application) wont't +# be changed, so we do not have to update any state in that case. (data, sw) = self.scc.select_file(fid) except SwMatchError as swm: +self._select_post(cmd_app) k = self.interpret_sw(swm.sw_actual) if not k: raise(swm) @@ -267,8 +284,8 @@ desc="elementary file, manually added at runtime") self.selected_file.add_files([f]) -self.selected_file = f -return select_resp, data + +self._select_post(cmd_app, f, data) def _select_pre(self, cmd_app): # unregister commands of old file @@ -276,7 +293,17 @@ for c in self.selected_file.shell_commands: cmd_app.unregister_command_set(c) -def _select_post(self, cmd_app): +def _select_post(self, cmd_app, file:CardFile = None, select_resp_data = None): +# we store some reference data (see above) about the currently selected file. + # This data must be updated after every select. +if file: +self.selected_file = file +if isinstance(file, CardADF): +self.selected_adf = file +if select_resp_data: +self.selected_file_fcp_hex = select_resp_data +self.selected_file_fcp = self.selected_file.decode_select_response(select_resp_data) + #