Change in pysim[master]: pySim-prog, pySim-read, do not echo reader id

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Tue May 12 18:11:38 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/18221 )

Change subject: pySim-prog, pySim-read, do not echo reader id
......................................................................

pySim-prog, pySim-read, do not echo reader id

pySim-prog and pySim-read currently echo back the pcsc reader id (or
baudrate/socket, depending on the interface used). This makes the output
unecessarly undeterministic, which becomes a problem when verifying the
putput in tests. Lets not echo those variable, user supplied parameters
back. Also lets move the code that does the initalization to utils, so
that it can be used from pySim-prog and from pySim-read (code dup).

Change-Id: I243cc332f075d007b1c111292effcc610e874eb3
Related: OS#4503
---
M pySim-prog.py
M pySim-read.py
M pySim/utils.py
M pysim-testdata/Fairwaves-SIM.ok
M pysim-testdata/Wavemobile-SIM.ok
M pysim-testdata/fakemagicsim.ok
M pysim-testdata/sysmoISIM-SJA2.ok
M pysim-testdata/sysmoUSIM-SJS1.ok
M pysim-testdata/sysmosim-gr1.ok
M tests/pysim-test.sh
10 files changed, 32 insertions(+), 47 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  fixeria: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/pySim-prog.py b/pySim-prog.py
index c709959..67719b4 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -40,7 +40,7 @@
 
 from pySim.commands import SimCardCommands
 from pySim.cards import _cards_classes, card_detect
-from pySim.utils import h2b, swap_nibbles, rpad, derive_milenage_opc, calculate_luhn, dec_iccid
+from pySim.utils import h2b, swap_nibbles, rpad, derive_milenage_opc, calculate_luhn, dec_iccid, init_reader
 from pySim.ts_51_011 import EF
 from pySim.card_handler import *
 from pySim.utils import *
@@ -688,21 +688,7 @@
 	opts = parse_options()
 
 	# Init card reader driver
-	if opts.pcsc_dev is not None:
-		print("Using PC/SC reader (dev=%d) interface"
-			% opts.pcsc_dev)
-		from pySim.transport.pcsc import PcscSimLink
-		sl = PcscSimLink(opts.pcsc_dev)
-	elif opts.osmocon_sock is not None:
-		print("Using Calypso-based (OsmocomBB, sock=%s) reader interface"
-			% opts.osmocon_sock)
-		from pySim.transport.calypso import CalypsoSimLink
-		sl = CalypsoSimLink(sock_path=opts.osmocon_sock)
-	else: # Serial reader is default
-		print("Using serial reader (port=%s, baudrate=%d) interface"
-			% (opts.device, opts.baudrate))
-		from pySim.transport.serial import SerialSimLink
-		sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate)
+	sl = init_reader(opts)
 
 	# Create command layer
 	scc = SimCardCommands(transport=sl)
diff --git a/pySim-read.py b/pySim-read.py
index 33e93a7..df21531 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -34,8 +34,8 @@
 
 from pySim.commands import SimCardCommands
 from pySim.cards import card_detect, Card
-from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid, dec_msisdn, format_xplmn_w_act, dec_spn, dec_st
-
+from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid, dec_msisdn
+from pySim.utils import format_xplmn_w_act, dec_spn, dec_st, init_reader
 
 def parse_options():
 
@@ -72,21 +72,7 @@
 	opts = parse_options()
 
 	# Init card reader driver
-	if opts.pcsc_dev is not None:
-		print("Using PC/SC reader (dev=%d) interface"
-			% opts.pcsc_dev)
-		from pySim.transport.pcsc import PcscSimLink
-		sl = PcscSimLink(opts.pcsc_dev)
-	elif opts.osmocon_sock is not None:
-		print("Using Calypso-based (OsmocomBB, sock=%s) reader interface"
-			% opts.osmocon_sock)
-		from pySim.transport.calypso import CalypsoSimLink
-		sl = CalypsoSimLink(sock_path=opts.osmocon_sock)
-	else: # Serial reader is default
-		print("Using serial reader (port=%s, baudrate=%d) interface"
-			% (opts.device, opts.baudrate))
-		from pySim.transport.serial import SerialSimLink
-		sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate)
+	sl = init_reader(opts)
 
 	# Create command layer
 	scc = SimCardCommands(transport=sl)
diff --git a/pySim/utils.py b/pySim/utils.py
index dbc7337..a1689ca 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -436,3 +436,22 @@
 			s += "\t%s # %s\n" % (i2h(content), i2s(content))
 
 	return s
+
+def init_reader(opts):
+	"""
+	Init card reader driver
+	"""
+	if opts.pcsc_dev is not None:
+		print("Using PC/SC reader interface")
+		from pySim.transport.pcsc import PcscSimLink
+		sl = PcscSimLink(opts.pcsc_dev)
+	elif opts.osmocon_sock is not None:
+		print("Using Calypso-based (OsmocomBB) reader interface")
+		from pySim.transport.calypso import CalypsoSimLink
+		sl = CalypsoSimLink(sock_path=opts.osmocon_sock)
+	else: # Serial reader is default
+		print("Using serial reader interface")
+		from pySim.transport.serial import SerialSimLink
+		sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate)
+
+	return sl
diff --git a/pysim-testdata/Fairwaves-SIM.ok b/pysim-testdata/Fairwaves-SIM.ok
index 0dbd89f..e5fa1af 100644
--- a/pysim-testdata/Fairwaves-SIM.ok
+++ b/pysim-testdata/Fairwaves-SIM.ok
@@ -1,4 +1,4 @@
-Using PC/SC reader (dev=0) interface
+Using PC/SC reader interface
 Reading ...
 Autodetected card type: Fairwaves-SIM
 ICCID: 8988219000000117833
diff --git a/pysim-testdata/Wavemobile-SIM.ok b/pysim-testdata/Wavemobile-SIM.ok
index 2de0892..a5c3a8e 100644
--- a/pysim-testdata/Wavemobile-SIM.ok
+++ b/pysim-testdata/Wavemobile-SIM.ok
@@ -1,4 +1,4 @@
-Using PC/SC reader (dev=3) interface
+Using PC/SC reader interface
 Reading ...
 Autodetected card type: Wavemobile-SIM
 ICCID: 89445310150011013678
diff --git a/pysim-testdata/fakemagicsim.ok b/pysim-testdata/fakemagicsim.ok
index 80cf3d9..0168b13 100644
--- a/pysim-testdata/fakemagicsim.ok
+++ b/pysim-testdata/fakemagicsim.ok
@@ -1,4 +1,4 @@
-Using PC/SC reader (dev=5) interface
+Using PC/SC reader interface
 Reading ...
 Autodetected card type: fakemagicsim
 Can't read AIDs from SIM -- SW match failed! Expected 9000 and got 9404.
diff --git a/pysim-testdata/sysmoISIM-SJA2.ok b/pysim-testdata/sysmoISIM-SJA2.ok
index 57500eb..8559bdb 100644
--- a/pysim-testdata/sysmoISIM-SJA2.ok
+++ b/pysim-testdata/sysmoISIM-SJA2.ok
@@ -1,4 +1,4 @@
-Using PC/SC reader (dev=4) interface
+Using PC/SC reader interface
 Reading ...
 Autodetected card type: sysmoISIM-SJA2
 ICCID: 8988211900000000004
diff --git a/pysim-testdata/sysmoUSIM-SJS1.ok b/pysim-testdata/sysmoUSIM-SJS1.ok
index 408f211..75c3862 100644
--- a/pysim-testdata/sysmoUSIM-SJS1.ok
+++ b/pysim-testdata/sysmoUSIM-SJS1.ok
@@ -1,4 +1,4 @@
-Using PC/SC reader (dev=1) interface
+Using PC/SC reader interface
 Reading ...
 Autodetected card type: sysmoUSIM-SJS1
 ICCID: 1122334455667788990
diff --git a/pysim-testdata/sysmosim-gr1.ok b/pysim-testdata/sysmosim-gr1.ok
index 833ba83..3fba8e1 100644
--- a/pysim-testdata/sysmosim-gr1.ok
+++ b/pysim-testdata/sysmosim-gr1.ok
@@ -1,4 +1,4 @@
-Using PC/SC reader (dev=0) interface
+Using PC/SC reader interface
 Reading ...
 Autodetected card type: sysmosim-gr1
 Can't read AIDs from SIM -- SW match failed! Expected 9000 and got 9404.
diff --git a/tests/pysim-test.sh b/tests/pysim-test.sh
index a22c372..7ee9834 100755
--- a/tests/pysim-test.sh
+++ b/tests/pysim-test.sh
@@ -78,13 +78,7 @@
     stat ./$CARD_NAME.ok > /dev/null
     python $PYSIM_READ -p $TERMINAL > $TEMPFILE
     set +e
-    # Note: We ignore the first line of output in the diff because here
-    # pysim would print the device number of the reader and we do not
-    # want the test to fail just because the card is put into a different
-    # reader device.
-    tail -n +2 $CARD_NAME.ok > $CARD_NAME.ok.tmp
-    tail -n +2 $TEMPFILE > $CARD_NAME.chk.tmp
-    CARD_DIFF=$(diff $CARD_NAME.chk.tmp $CARD_NAME.ok.tmp)
+    CARD_DIFF=$(diff $TEMPFILE ./$CARD_NAME.ok)
     set -e
 
     if [ "$CARD_DIFF" != "" ]; then
@@ -104,7 +98,7 @@
     inc_card_list $CARD_NAME
 
     echo "Card contents match the test data -- success!"
-    rm *.tmp
+    rm $TEMPFILE
 }
 
 # Read out the card using pysim-read and store the result as .ok file. This

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I243cc332f075d007b1c111292effcc610e874eb3
Gerrit-Change-Number: 18221
Gerrit-PatchSet: 2
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200512/3d73d906/attachment.htm>


More information about the gerrit-log mailing list