<p>dexter has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/23689">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pySim-shell: allow generic USIM/ISIM cards to be used<br><br>At the moment the card is automatically detected. This means that<br>pySim-shell will only support the specific types of simcards we support<br>in pySim-prog. However pySim-shell is more generic and would in theory<br>work with any SIM/USIM/ISIM card as long as only the 3GPP specified<br>features are used.<br><br>Lets add a generic card that acts as a dummy in case we want to operate<br>a generic simcard.<br><br>Change-Id: Ie1fa42400d236928659a7e5d34225487161d4b83<br>Related: OS#4963<br>---<br>M pySim-shell.py<br>M pySim/cards.py<br>2 files changed, 34 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/89/23689/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim-shell.py b/pySim-shell.py</span><br><span>index 29138cc..e7e3dc5 100755</span><br><span>--- a/pySim-shell.py</span><br><span>+++ b/pySim-shell.py</span><br><span>@@ -38,7 +38,7 @@</span><br><span> from pySim.exceptions import *</span><br><span> from pySim.commands import SimCardCommands</span><br><span> from pySim.transport import init_reader</span><br><span style="color: hsl(0, 100%, 40%);">-from pySim.cards import card_detect, Card</span><br><span style="color: hsl(120, 100%, 40%);">+from pySim.cards import card_detect, Card, GenericUsimIsim</span><br><span> from pySim.utils import h2b, swap_nibbles, rpad, h2s</span><br><span> from pySim.utils import dec_st, sanitize_pin_adm, tabulate_str_list, is_hex</span><br><span> from pySim.card_handler import card_handler</span><br><span>@@ -431,6 +431,9 @@</span><br><span>   parser.add_option("-A", "--pin-adm-hex", dest="pin_adm_hex",</span><br><span>                   help="ADM PIN used for provisioning, as hex string (16 characters long",</span><br><span>           )</span><br><span style="color: hsl(120, 100%, 40%);">+     parser.add_option("-U", "--generic-usim", dest="generic_usim", default=False, action='store_true',</span><br><span style="color: hsl(120, 100%, 40%);">+                      help="Use a generic ISIM/USIM class instead of a specific (autodetected) card class",</span><br><span style="color: hsl(120, 100%, 40%);">+               )</span><br><span> </span><br><span>        (options, args) = parser.parse_args()</span><br><span> </span><br><span>@@ -458,10 +461,13 @@</span><br><span> </span><br><span>        card_handler = card_handler(sl)</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-     card = card_detect("auto", scc)</span><br><span style="color: hsl(0, 100%, 40%);">-       if card is None:</span><br><span style="color: hsl(0, 100%, 40%);">-                print("No card detected!")</span><br><span style="color: hsl(0, 100%, 40%);">-            sys.exit(2)</span><br><span style="color: hsl(120, 100%, 40%);">+   if opts.generic_usim:</span><br><span style="color: hsl(120, 100%, 40%);">+         card = GenericUsimIsim(scc)</span><br><span style="color: hsl(120, 100%, 40%);">+   else:</span><br><span style="color: hsl(120, 100%, 40%);">+         card = card_detect("auto", scc)</span><br><span style="color: hsl(120, 100%, 40%);">+             if card is None:</span><br><span style="color: hsl(120, 100%, 40%);">+                      print("No card detected!")</span><br><span style="color: hsl(120, 100%, 40%);">+                  sys.exit(2)</span><br><span> </span><br><span>      profile = CardProfileUICC()</span><br><span>  profile.add_application(CardApplicationUSIM)</span><br><span>diff --git a/pySim/cards.py b/pySim/cards.py</span><br><span>index 8ac80bf..d193f08 100644</span><br><span>--- a/pySim/cards.py</span><br><span>+++ b/pySim/cards.py</span><br><span>@@ -1448,6 +1448,29 @@</span><br><span>           return</span><br><span> </span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+class GenericUsimIsim(UsimCard, IsimCard):</span><br><span style="color: hsl(120, 100%, 40%);">+    """</span><br><span style="color: hsl(120, 100%, 40%);">+    GenericUsimIsim</span><br><span style="color: hsl(120, 100%, 40%);">+       """</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  name = 'GenericUsimIsim'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self, ssc):</span><br><span style="color: hsl(120, 100%, 40%);">+              super(GenericUsimIsim, self).__init__(ssc)</span><br><span style="color: hsl(120, 100%, 40%);">+            self._scc.cla_byte = "00"</span><br><span style="color: hsl(120, 100%, 40%);">+           self._scc.sel_ctrl = "0004" #request an FCP</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       @classmethod</span><br><span style="color: hsl(120, 100%, 40%);">+  def autodetect(kls, scc):</span><br><span style="color: hsl(120, 100%, 40%);">+             return kls(scc)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     def verify_adm(self, key):</span><br><span style="color: hsl(120, 100%, 40%);">+            return "9000"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     def program(self, p):</span><br><span style="color: hsl(120, 100%, 40%);">+         return</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> # In order for autodetection ...</span><br><span> _cards_classes = [ FakeMagicSim, SuperSim, MagicSim, GrcardSim,</span><br><span>               SysmoSIMgr1, SysmoSIMgr2, SysmoUSIMgr1, SysmoUSIMSJS1,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/23689">change 23689</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/23689"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ie1fa42400d236928659a7e5d34225487161d4b83 </div>
<div style="display:none"> Gerrit-Change-Number: 23689 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>