dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/33964 )
Change subject: pysim-test: rename pysim-test.sh to pySim-prog_test.sh
......................................................................
pysim-test: rename pysim-test.sh to pySim-prog_test.sh
We now have pySim-shell and pySim-trace. Let's give pysim-test.sh a more
distinctive name so that it is clear to which program it refers.
Related: OS#6094
Change-Id: I438f63f9580ebd3c7cc78cc5dab13c9937ac6e3a
---
M contrib/jenkins.sh
D tests/pysim-test.sh
2 files changed, 14 insertions(+), 231 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/64/33964/1
diff --git a/contrib/jenkins.sh b/contrib/jenkins.sh
index 583400b..93dc4bc 100755
--- a/contrib/jenkins.sh
+++ b/contrib/jenkins.sh
@@ -28,7 +28,7 @@
# Run the test with physical cards
cd pysim-testdata
- ../tests/pysim-test.sh
+ ../tests/pySim-prog_test.sh
../tests/pySim-trace_test.sh
;;
"pylint")
diff --git a/tests/pysim-test.sh b/tests/pysim-test.sh
deleted file mode 100755
index 4004c18..0000000
--- a/tests/pysim-test.sh
+++ /dev/null
@@ -1,230 +0,0 @@
-#!/bin/bash
-
-# Utility to verify the functionality of pysim-prog.py
-#
-# (C) 2018 by Sysmocom s.f.m.c. GmbH
-# All Rights Reserved
-#
-# Author: Philipp Maier
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-PYSIM_PROG=../pySim-prog.py
-PYSIM_READ=../pySim-read.py
-TEMPFILE=temp.tmp
-PYTHON=python3
-
-set -e
-
-echo "pysim-test - a test program to test pysim-prog.py"
-echo "================================================="
-
-# Generate a list of the cards we expect to see by checking which .ok files
-# are present
-function gen_card_list {
- N_CARDS=0
-
- echo "Expecting to see the following cards:"
-
- for I in *.data ; do
- CARD_NAMES[$N_CARDS]=${I%.*}
- CARD_SEEN[$N_CARDS]=0
- N_CARDS=$((N_CARDS+1))
- done
-
- for I in $(seq 0 $((N_CARDS-1))); do
- echo ${CARD_NAMES[$I]}
- done
-}
-
-# Increment counter in card list for a specified card name (type)
-function inc_card_list {
- CARD_NAME=$1
- for I in $(seq 0 $((N_CARDS-1))); do
- if [ $CARD_NAME = ${CARD_NAMES[$I]} ]; then
- CARD_SEEN[$I]=$((${CARD_NAMES[$I]}+1))
- fi
- done
-}
-
-# Check the card list, each card must be seen exactly one times
-function check_card_list {
- for I in $(seq 0 $((N_CARDS-1))); do
- if [ ${CARD_SEEN[$I]} -ne 1 ]; then
- echo "Error: Card ${CARD_NAMES[$I]} seen ${CARD_SEEN[$I]} times!"
- exit 1
- fi
- done
-
- echo "All cards seen -- everything ok!"
-}
-
-# Verify the contents of a card by reading them and then diffing against the
-# previously created .ok file
-function check_card {
- TERMINAL=$1
- CARD_NAME=$2
- echo "Verifying card ..."
- stat ./$CARD_NAME.ok > /dev/null
- $PYTHON $PYSIM_READ -p $TERMINAL > $TEMPFILE
- set +e
- CARD_DIFF=$(diff $TEMPFILE ./$CARD_NAME.ok)
- set -e
-
- if [ "$CARD_DIFF" != "" ]; then
- echo "Card contents do not match the test data:"
- echo "Expected: $CARD_NAME.ok"
- echo "------------8<------------"
- cat "$CARD_NAME.ok"
- echo "------------8<------------"
- echo "Got:"
- echo "------------8<------------"
- cat $TEMPFILE
- echo "------------8<------------"
- rm *.tmp
- exit 1
- fi
-
- inc_card_list $CARD_NAME
-
- echo "Card contents match the test data -- success!"
- rm $TEMPFILE
-}
-
-# Read out the card using pysim-read and store the result as .ok file. This
-# data will be used later in order to verify the results of our write tests.
-function gen_ok_file {
- TERMINAL=$1
- CARD_NAME=$2
- $PYTHON $PYSIM_READ -p $TERMINAL > "$CARD_NAME.ok"
- echo "Generated file: $CARD_NAME.ok"
- echo "------------8<------------"
- cat "$CARD_NAME.ok"
- echo "------------8<------------"
-}
-
-# Find out the type (card name) of the card that is installed in the specified
-# reader
-function probe_card {
- TERMINAL=$1
- RESULT=$(timeout 5 $PYSIM_PROG -p $TERMINAL -T | cut -d ":" -f 2 | tail -n 1 | xargs)
- echo $RESULT
-}
-
-# Read out all cards and store the results as .ok files
-function gen_ok_files {
- echo "== OK FILE GENERATION =="
- for I in $(seq 0 $((N_TERMINALS-1))); do
- echo "Probing card in terminal #$I"
- CARD_NAME=$(probe_card $I)
- if [ -z "$CARD_NAME" ]; then
- echo "Error: Unresponsive card!"
- exit 1
- fi
- echo "Card is of type: $CARD_NAME"
- gen_ok_file $I $CARD_NAME
- done
-}
-
-# Execute tests. Each card is programmed and the contents are checked
-# afterwards.
-function run_test {
- for I in $(seq 0 $((N_TERMINALS-1))); do
- echo "== EXECUTING TEST =="
- echo "Probing card in terminal #$I"
- CARD_NAME=$(probe_card $I)
- if [ -z "$CARD_NAME" ]; then
- echo "Error: Unresponsive card!"
- exit 1
- fi
- echo "Card is of type: $CARD_NAME"
-
- # Make sure some default data is set
- MCC=001
- MNC=01
- ICCID=1122334455667788990
- KI=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
- OPC=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
- IMSI=001010000000001
- MSISDN=6766266
- ADM=00000000
- ADM_HEX=""
- ADM_OPT="-a"
-
- source "$CARD_NAME.data"
- if [ -n "$ADM_HEX" ]; then
- ADM_OPT="-A"
- ADM=$ADM_HEX
- fi
- $PYTHON $PYSIM_PROG -p $I -t $CARD_NAME -o $OPC -k $KI -x $MCC -y $MNC -i $IMSI -s $ICCID --msisdn $MSISDN $ADM_OPT $ADM
- check_card $I $CARD_NAME
- echo ""
- done
-}
-
-function usage {
- echo "Options:"
- echo "-n: number of card terminals"
- echo "-o: generate .ok files"
-}
-
-# Make sure that the pathes to the python scripts always work, regardless from
-# where the script is called.
-CURDIR=$PWD
-SCRIPTDIR=$(dirname $0)
-cd $SCRIPTDIR
-PYSIM_PROG=$(realpath $PYSIM_PROG)
-PYSIM_READ=$(realpath $PYSIM_READ)
-cd $CURDIR
-
-OPT_N_TERMINALS=0
-OPT_GEN_OK_FILES=0
-while getopts ":hon:" OPT; do
- case $OPT in
- h)
- usage
- exit 0
- ;;
- o)
- OPT_GEN_OK_FILES=1
- ;;
- n)
- OPT_N_TERMINALS=$OPTARG
- ;;
- \?)
- echo "Invalid option: -$OPTARG" >&2
- exit 1
- ;;
- esac
-done
-
-N_TERMINALS=$OPT_N_TERMINALS
-
-# Generate a list of available cards, if no explicit reader number is given
-# then the number of cards will be used as reader number.
-gen_card_list
-if [ $N_TERMINALS -eq 0 ]; then
- N_TERMINALS=$N_CARDS
-fi
-echo "Number of card terminals installed: $N_TERMINALS"
-echo ""
-
-if [ $OPT_GEN_OK_FILES -eq 1 ]; then
- gen_ok_files
- exit 0
-else
- run_test
- check_card_list
- exit 0
-fi
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/33964
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I438f63f9580ebd3c7cc78cc5dab13c9937ac6e3a
Gerrit-Change-Number: 33964
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-MessageType: newchange
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/33962 )
Change subject: pySim-trace: catch StopIteration exception on trace file end
......................................................................
pySim-trace: catch StopIteration exception on trace file end
When the trace file end is reaced, pyShark raises a StopIteration
exception. Let's catch this exception and exit gracefully.
Related: OS#6094
Change-Id: I6ab5689b909333531d08bf46e5dfea59b161a79e
---
M pySim-trace.py
1 file changed, 18 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/62/33962/1
diff --git a/pySim-trace.py b/pySim-trace.py
index 4561723..5990e32 100755
--- a/pySim-trace.py
+++ b/pySim-trace.py
@@ -102,7 +102,11 @@
"""Main loop of tracer: Iterates over all Apdu received from source."""
while True:
# obtain the next APDU from the source (blocking read)
- apdu = self.source.read()
+ try:
+ apdu = self.source.read()
+ except StopIteration:
+ print("no more data, stop iteration.")
+ return 0
if isinstance(apdu, CardReset):
self.rs.reset()
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/33962
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I6ab5689b909333531d08bf46e5dfea59b161a79e
Gerrit-Change-Number: 33962
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-MessageType: newchange
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/33963 )
Change subject: tests: add test script for pySim-trace
......................................................................
tests: add test script for pySim-trace
pySim-trace has no test coverage yet. Let's use a script to run a
GSAMTAP pcacp through it and check that no exceptions are raised.
Related: OS#6094
Change-Id: Icfabfa7c59968021eef0399991bd05b92467d8d2
---
M contrib/jenkins.sh
A tests/pySim-trace_test.sh
A tests/pySim-trace_test_gsmtap.pcapng
3 files changed, 34 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/63/33963/1
diff --git a/contrib/jenkins.sh b/contrib/jenkins.sh
index 0309877..583400b 100755
--- a/contrib/jenkins.sh
+++ b/contrib/jenkins.sh
@@ -29,6 +29,7 @@
# Run the test with physical cards
cd pysim-testdata
../tests/pysim-test.sh
+ ../tests/pySim-trace_test.sh
;;
"pylint")
# Print pylint version
diff --git a/tests/pySim-trace_test.sh b/tests/pySim-trace_test.sh
new file mode 100755
index 0000000..0ec5e0f
--- /dev/null
+++ b/tests/pySim-trace_test.sh
@@ -0,0 +1,20 @@
+#/bin/bash
+
+PYSIM_TRACE=../pySim-trace.py
+GSMTAP_TRACE=pySim-trace_test_gsmtap.pcapng
+
+echo "pySim-trace_test - a test program to test pySim-trace.py"
+echo "========================================================"
+
+$PYSIM_TRACE gsmtap-pyshark-pcap -f $GSMTAP_TRACE
+if [ $? -ne 0 ]; then
+ echo ""
+ echo "========================================================"
+ echo "Testrun with $GSMTAP_TRACE failed."
+ exit 1
+fi
+
+echo ""
+echo "========================================================"
+echo "trace parsed without problems -- everything ok!"
+
diff --git a/tests/pySim-trace_test_gsmtap.pcapng b/tests/pySim-trace_test_gsmtap.pcapng
new file mode 100644
index 0000000..35c3003
--- /dev/null
+++ b/tests/pySim-trace_test_gsmtap.pcapng
Binary files differ
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/33963
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Icfabfa7c59968021eef0399991bd05b92467d8d2
Gerrit-Change-Number: 33963
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-MessageType: newchange
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/33959 )
Change subject: pySim-trace: add commandline option --show-raw-apdu
......................................................................
pySim-trace: add commandline option --show-raw-apdu
The trace log currently only shows the parsed APDU. However, depending
on the problem to investigate it may be required to see the raw APDU
string as well. Let's add an option for this.
Related: OS#6094
Change-Id: I1a3bc54c459e45ed3154479759ceecdc26db9d37
---
M pySim-trace.py
1 file changed, 24 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/59/33959/1
diff --git a/pySim-trace.py b/pySim-trace.py
index d457bf4..453ee43 100755
--- a/pySim-trace.py
+++ b/pySim-trace.py
@@ -83,10 +83,13 @@
# parameters
self.suppress_status = kwargs.get('suppress_status', True)
self.suppress_select = kwargs.get('suppress_select', True)
+ self.show_raw_apdu = kwargs.get('show_raw_apdu', False)
self.source = kwargs.get('source', None)
- def format_capdu(self, inst: ApduCommand):
+ def format_capdu(self, apdu: Apdu, inst: ApduCommand):
"""Output a single decoded + processed ApduCommand."""
+ if self.show_raw_apdu:
+ print(apdu)
print("%02u %-16s %-35s %-8s %s %s" % (inst.lchan_nr, inst._name, inst.path_str, inst.col_id, inst.col_sw, inst.processed))
print("===============================")
@@ -95,7 +98,6 @@
while True:
# obtain the next APDU from the source (blocking read)
apdu = self.source.read()
- #print(apdu)
if isinstance(apdu, CardReset):
self.rs.reset()
@@ -113,7 +115,7 @@
if self.suppress_status and isinstance(inst, UiccStatus):
continue
#print(inst)
- self.format_capdu(inst)
+ self.format_capdu(apdu, inst)
option_parser = argparse.ArgumentParser(description='Osmocom pySim high-level SIM card trace decoder',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
@@ -128,6 +130,9 @@
help="""
Don't suppress displaying STATUS APDUs. We normally suppress them as they don't provide any
information that was not already received in resposne to the most recent SEELCT.""")
+global_group.add_argument('--show-raw-apdu', action='store_true', dest='show_raw_apdu',
+ help="""Show the raw APDU in addition to its parsed form.""")
+
subparsers = option_parser.add_subparsers(help='APDU Source', dest='source', required=True)
@@ -172,7 +177,8 @@
elif opts.source == 'gsmtap-pyshark-pcap':
s = PysharkGsmtapPcap(opts.pcap_file)
- tracer = Tracer(source=s, suppress_status=opts.suppress_status, suppress_select=opts.suppress_select)
+ tracer = Tracer(source=s, suppress_status=opts.suppress_status, suppress_select=opts.suppress_select,
+ show_raw_apdu=opts.show_raw_apdu)
logger.info('Entering main loop...')
tracer.main()
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/33959
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I1a3bc54c459e45ed3154479759ceecdc26db9d37
Gerrit-Change-Number: 33959
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-MessageType: newchange
Attention is currently required from: Hoernchen.
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-trx/+/33944 )
Change subject: ms: restructure the va code to add rach support
......................................................................
Patch Set 3: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/33944
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Change-Id: I4a5cedc8c9a3289c75ce7b914eac286e601ebed0
Gerrit-Change-Number: 33944
Gerrit-PatchSet: 3
Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: laforge <laforge(a)osmocom.org>
Gerrit-Attention: Hoernchen <ewild(a)sysmocom.de>
Gerrit-Comment-Date: Thu, 27 Jul 2023 12:10:52 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment