Change in pysim[master]: pySim-shell: add method to probe for UICC

2021-11-08 Thread dexter
dexter has abandoned this change. ( https://gerrit.osmocom.org/c/pysim/+/26043 )

Change subject: pySim-shell: add method to probe for UICC
..


Abandoned

I have now implemented it differently.
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/26043
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I535bef35847140e611d4fa95ed2859ee81cce605
Gerrit-Change-Number: 26043
Gerrit-PatchSet: 4
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel 
Gerrit-Reviewer: fixeria 
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: osmith 
Gerrit-Reviewer: pespin 
Gerrit-MessageType: abandon


Change in pysim[master]: pySim-shell: add method to probe for UICC

2021-11-05 Thread osmith
osmith has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/26043 )

Change subject: pySim-shell: add method to probe for UICC
..


Patch Set 4:

(1 comment)

(clicking on start review to add a comment)

https://gerrit.osmocom.org/c/pysim/+/26043/4/pySim-shell.py
File pySim-shell.py:

https://gerrit.osmocom.org/c/pysim/+/26043/4/pySim-shell.py@85
PS4, Line 85: ;
> Thanks! There is no way to have this in the linter? python does not complain 
> about it, so this goes  […]
you can install flake8 and put something like this in your pre-commit hook:

  flake8 --select E703 $(find -name '*.py')

it will test for this, e.g.:
  ./test.py:15:74: E703 statement ends with a semicolon


to add it to the linter that runs in gerrit, I've created: 
https://osmocom.org/issues/5292



--
To view, visit https://gerrit.osmocom.org/c/pysim/+/26043
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I535bef35847140e611d4fa95ed2859ee81cce605
Gerrit-Change-Number: 26043
Gerrit-PatchSet: 4
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel 
Gerrit-Reviewer: fixeria 
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: osmith 
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Fri, 05 Nov 2021 12:34:47 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: osmith 
Comment-In-Reply-To: dexter 
Gerrit-MessageType: comment


Change in pysim[master]: pySim-shell: add method to probe for UICC

2021-11-03 Thread dexter
dexter has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/26043 )

Change subject: pySim-shell: add method to probe for UICC
..


Patch Set 4:

(2 comments)

> Patch Set 4: Code-Review+1
>
> I'm happy to merge the patch as it is an improvement.  Howeve, I think a 
> proper solution is to move all of that detection logic into the various 
> CardProfile etc. classes.
>
> So the main application code of pySim-shell should really only call one 
> (classmethod?) to perform autodetection aof card profiles, which would then 
> iterate of all subclasses of CardProfile, call their autodetect method, which 
> would do whatever it needs to do, etc.

I think I get what you mean. I will move the detection into the profile classes 
- I put this into WIP until I am done with that.

https://gerrit.osmocom.org/c/pysim/+/26043/4/pySim-shell.py
File pySim-shell.py:

https://gerrit.osmocom.org/c/pysim/+/26043/4/pySim-shell.py@85
PS4, Line 85: ;
> lines don't end with ";" in python
Thanks! There is no way to have this in the linter? python does not complain 
about it, so this goes unnoticed from time to time.


https://gerrit.osmocom.org/c/pysim/+/26043/4/pySim-shell.py@109
PS4, Line 109: SIM
> word repeated
Done



--
To view, visit https://gerrit.osmocom.org/c/pysim/+/26043
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I535bef35847140e611d4fa95ed2859ee81cce605
Gerrit-Change-Number: 26043
Gerrit-PatchSet: 4
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel 
Gerrit-Reviewer: fixeria 
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: osmith 
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Wed, 03 Nov 2021 16:25:05 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: osmith 
Gerrit-MessageType: comment


Change in pysim[master]: pySim-shell: add method to probe for UICC

2021-11-03 Thread osmith
osmith has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/26043 )

Change subject: pySim-shell: add method to probe for UICC
..


Patch Set 4:

(2 comments)

two nitpicks, otherwise LGTM

https://gerrit.osmocom.org/c/pysim/+/26043/4/pySim-shell.py
File pySim-shell.py:

https://gerrit.osmocom.org/c/pysim/+/26043/4/pySim-shell.py@85
PS4, Line 85: ;
lines don't end with ";" in python


https://gerrit.osmocom.org/c/pysim/+/26043/4/pySim-shell.py@109
PS4, Line 109: SIM
word repeated



--
To view, visit https://gerrit.osmocom.org/c/pysim/+/26043
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I535bef35847140e611d4fa95ed2859ee81cce605
Gerrit-Change-Number: 26043
Gerrit-PatchSet: 4
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel 
Gerrit-Reviewer: fixeria 
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: osmith 
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Wed, 03 Nov 2021 14:38:10 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


Change in pysim[master]: pySim-shell: add method to probe for UICC

2021-11-03 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/26043 )

Change subject: pySim-shell: add method to probe for UICC
..


Patch Set 4: Code-Review+1

I'm happy to merge the patch as it is an improvement.  Howeve, I think a proper 
solution is to move all of that detection logic into the various CardProfile 
etc. classes.

So the main application code of pySim-shell should really only call one 
(classmethod?) to perform autodetection aof card profiles, which would then 
iterate of all subclasses of CardProfile, call their autodetect method, which 
would do whatever it needs to do, etc.


--
To view, visit https://gerrit.osmocom.org/c/pysim/+/26043
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I535bef35847140e611d4fa95ed2859ee81cce605
Gerrit-Change-Number: 26043
Gerrit-PatchSet: 4
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel 
Gerrit-Reviewer: fixeria 
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: osmith 
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Wed, 03 Nov 2021 12:02:39 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in pysim[master]: pySim-shell: add method to probe for UICC

2021-11-01 Thread dexter
dexter has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/26043 )

Change subject: pySim-shell: add method to probe for UICC
..


Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/c/pysim/+/26043/1/pySim-shell.py
File pySim-shell.py:

https://gerrit.osmocom.org/c/pysim/+/26043/1/pySim-shell.py@87
PS1, Line 87: card_is_uicc = probe_card(card, ['UICC'])
> why does the 'UICC' get passed in a list? […]
It gets passed in a list because in theory the function can do more than one 
test in one go. Its also possible to ask ['UICC', 'SIM'] = Is this a UICC card 
with SIM functionality? Unfortunately I noticed that I did not need the 
possibility to ask for both at once.

Regarding the card model I think we should try to drop it - we could keep the 
file as compatibility layer for pySim-prog and pySim-read, but in pySim-shell 
we should try to use the SimCardCommands class directly. Thats what we already 
do by using the private _scc object in the card object, which is not nice 
because _scc is ment to be a private property of the card.

I think the only special functions of the card object we use is the verify_adm 
method, which may be different for each card. This is not much and can 
separated, so that the pySim-shell and the old code can use it.



--
To view, visit https://gerrit.osmocom.org/c/pysim/+/26043
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I535bef35847140e611d4fa95ed2859ee81cce605
Gerrit-Change-Number: 26043
Gerrit-PatchSet: 1
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: laforge 
Gerrit-Comment-Date: Mon, 01 Nov 2021 13:38:50 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: laforge 
Gerrit-MessageType: comment


Change in pysim[master]: pySim-shell: add method to probe for UICC

2021-10-31 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/26043 )

Change subject: pySim-shell: add method to probe for UICC
..


Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/c/pysim/+/26043/1/pySim-shell.py
File pySim-shell.py:

https://gerrit.osmocom.org/c/pysim/+/26043/1/pySim-shell.py@87
PS1, Line 87: card_is_uicc = probe_card(card, ['UICC'])
why does the 'UICC' get passed in a list?

Also, why not simply have probe_card() return a list of card models/profiles?  
This way  we would have something like:

probe_result = probe_card(card)
if 'SIM' in probe_result:
...
if 'USIM' in probe_result:
...


Furthermore, I think the entire 'card' model needs a more fundamental reform.  
It made sense for pySim-prog supporting only a few very specific models of 
programmable cards.  But it makes no sense at all for pysim-shell.



--
To view, visit https://gerrit.osmocom.org/c/pysim/+/26043
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I535bef35847140e611d4fa95ed2859ee81cce605
Gerrit-Change-Number: 26043
Gerrit-PatchSet: 1
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: laforge 
Gerrit-Comment-Date: Sun, 31 Oct 2021 07:27:14 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


Change in pysim[master]: pySim-shell: add method to probe for UICC

2021-10-29 Thread dexter
dexter has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/26043 )


Change subject: pySim-shell: add method to probe for UICC
..

pySim-shell: add method to probe for UICC

UICC and old SIM cards can be difficult to tell apart without prior
knowledge of the card. The ATR won't tell if the card is UICC or not.
The only remaining option is to try out if the card is able to handle
UICC APDUs. The same is true for 2G SIM cards. It is not guranteed that
every UICC card will have 2G functionality.

Lets add functionality that probes the card type and then decide which
profile is suitable.

Change-Id: I535bef35847140e611d4fa95ed2859ee81cce605
Related: OS#5274
---
M pySim-shell.py
M pySim/filesystem.py
A pySim/probe.py
M pySim/ts_102_221.py
M pySim/ts_51_011.py
5 files changed, 119 insertions(+), 12 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/43/26043/1

diff --git a/pySim-shell.py b/pySim-shell.py
index 3fc5859..555ddac 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -58,6 +58,8 @@

 from pySim.card_key_provider import CardKeyProviderCsv, 
card_key_provider_register, card_key_provider_get_field

+from pySim.probe import probe_card
+
 def init_card(sl):
"""
Detect card in reader and setup card profile and runtime state. This
@@ -79,19 +81,36 @@

card = card_detect("auto", scc)
if card is None:
-   print("Could not detect card type!")
-   return None, None;
+   print("Warning: Could not detect card type - assuming a generic 
card type...")
+   card = SimCard(scc);
+
+   card_is_uicc = probe_card(card, ['UICC'])
+   card_is_sim = probe_card(card, ['SIM'])
+
+   if card_is_uicc:
+   if card_is_sim:
+   print("Info: Card is of type SIM and UICC")
+   else:
+   print("Info: Card is of type UICC")
+   profile = CardProfileUICC()
+   profile.add_application(CardApplicationUSIM())
+   profile.add_application(CardApplicationISIM())
+   elif card_is_sim:
+   print("Info: Card is of type SIM")
+   profile = CardProfileSIM()
+   else:
+   print("Unsupported card type!")
+   return None, None

# Create runtime state with card profile
-   profile = CardProfileUICC()
-   profile.add_application(CardApplicationUSIM())
-   profile.add_application(CardApplicationISIM())
rs = RuntimeState(card, profile)

-   # FIXME: do this dynamically
-   rs.mf.add_file(DF_TELECOM())
-   rs.mf.add_file(DF_GSM())
-   rs.mf.add_file(DF_EIRENE())
+   # The card is an UICC, but can also be used a 2G SIM, so we must add 
the SIM
+   # SIM related bits manaully because they are not part of the UICC 
profile
+   if card_is_uicc and card_is_sim:
+   rs.mf.add_file(DF_TELECOM())
+   rs.mf.add_file(DF_GSM())
+   rs.mf.add_file(DF_EIRENE())

CardModel.apply_matching_models(scc, rs)

diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index dcc2608..bf4025c 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -1033,6 +1033,11 @@
 self.card = card
 self.selected_file = self.mf # type: CardDF
 self.profile = profile
+
+# make sure the class and selection control bytes, which are specified
+# by the card profile are used
+self.card.set_apdu_parameter(cla=self.profile.cla, 
sel_ctrl=self.profile.sel_ctrl)
+
 # add application ADFs + MF-files from profile
 apps = self._match_applications()
 for a in apps:
@@ -1042,11 +1047,22 @@
 self.mf.add_file(f)
 self.conserve_write = True

+# make sure that when the runtime state is created, the card is also
+# in a defined state.
+self.reset()
+
 def _match_applications(self):
 """match the applications from the profile with applications on the 
card"""
 apps_profile = self.profile.applications
-aids_card = self.card.read_aids()
 apps_taken = []
+
+# When the profile does not feature any applications, then we are done 
already
+if not apps_profile:
+return []
+
+# Read AIDs from card and match them against the applications defined 
by the
+# card profile
+aids_card = self.card.read_aids()
 if aids_card:
 aids_taken = []
 print("AIDs on card:")
@@ -1407,6 +1423,8 @@
 applications : List of CardApplications present on card
 sw : List of status word definitions
 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