aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)AuthorFilesLines
2022-09-05pySim-shell.py: make it work with cmd2 >= v2.4.0fixeria/cmd2Vadim Yanitskiy1-16/+16
In v2.3.0 both cmd2.{fg,bg} have been deprecated in favour of cmd2.{Fg,Bg}. In v2.4.0 both cmd2.{fg,bg} have been removed. See https://github.com/python-cmd2/cmd2/blob/master/CHANGELOG.md Change-Id: I7ca95e85fc45ba66fd9ba6bea1fec2bae0e892c0
2022-09-05pySim-shell.py: make it work with cmd2 >= v2.0.0Vadim Yanitskiy1-5/+5
* Argument 'use_ipython' was renamed to 'use_ipython'. * Class 'Settable' requires the reference to the object that holds the settable attribute. See https://github.com/python-cmd2/cmd2/releases/tag/2.0.0. Change-Id: Ia38f0ca5c3f41395f8fe850adae37f5af4e3fe19
2022-09-05README.md: update installation instructions for DebianVadim Yanitskiy1-3/+8
Change-Id: Icefa33570a34960a4fff145f3c1b6585d867605c
2022-09-05README.md: update git URLs (git -> https; gitea)Vadim Yanitskiy1-2/+2
Change-Id: Ia86979f656557e442b0f432b0646aa7661c293e9
2022-09-05README.md: list recent dependencies from requirements.txtVadim Yanitskiy1-0/+3
Change-Id: Ia486dbc7f630c1404e51728b5353cf5a0d643415
2022-09-05README.md: fix module name: s/serial/pyserial/Vadim Yanitskiy1-1/+1
Change-Id: I5fd308fb161cd5bd5f702845691296877e523248
2022-09-05README.md,requirements.txt: add missing construct version infoVadim Yanitskiy2-2/+2
Change-Id: I90da0df431f0d7dbfa4aa428366fbf0e35db388f Related: OS#5666
2022-09-05Bump minimum required construct version to v2.9.51Vadim Yanitskiy1-1/+1
With this version I can get all unittests passing: python -m unittest discover tests/ We're passing argument 'path' to stream_read_entire(), which was added in [1] and become available since v2.9.51. Change-Id: I4223c83570d333ad8d79bc2aa2d8bcc580156cff Related: [1] bfe71315b027e18e62f00ec4de75043992fd2316 construct.git Related: OS#5666
2022-09-05construct: use Python's API for int<->bytes conversionVadim Yanitskiy1-3/+3
Argument 'signed' was added in [1] and become available since v2.10.63. Therefore using bytes2integer() and integer2bytes() from construct.core bumps the minimum required version of construct to v2.10.63. For instance, debian:bullseye currently ships v2.10.58. There is no strict requirement to use construct's API, so let's use Python's API instead. This allows using older construct versions from the v2.9.xx family. Change-Id: I613dbfebe993f9c19003635371941710fc1b1236 Related: [1] 660ddbe2d9a351731ad7976351adbf413809a715 construct.git Related: OS#5666
2022-09-05contrib/jenkins.sh: install dependencies from requirements.txtVadim Yanitskiy1-9/+1
Change-Id: I99af496e9a3758ea624ca484f4fbc51b262ffaf4
2022-09-05contrib/jenkins.sh: execute this script with -x and -eVadim Yanitskiy1-3/+1
-x Print commands and their arguments as they are executed -e Exit immediately if a command exits with a non-zero status Change-Id: I13af70ef770936bec00b050b6c4f988e53ee2833
2022-08-30contrib/jenkins.sh: speed up pylint by running multiple processesVadim Yanitskiy1-1/+1
Use multiple processes to speed up pylint. Specifying -j0 will auto-detect the number of processors available to use. On AMD Ryzen 7 3700X this significantly reduces the exec time: $ time python -m pylint -j1 ... pySim *.py real 0m12.409s user 0m12.149s sys 0m0.136s $ time python -m pylint -j0 ... pySim *.py real 0m5.541s user 0m58.496s sys 0m1.213s Change-Id: I76d1696c27ddcab358526f807c4a0a7f0d4c85d4
2022-08-30contrib/jenkins.sh: pylint v2.15 is unstable, pin v2.14.5Vadim Yanitskiy1-1/+1
pylint v2.15 is crashing, let's fall-back to a known to work v2.14.5. Change-Id: Ie29be6ec6631ff2b3d8cd6b2dd9ac0ed8f505e4f Related: https://github.com/PyCQA/pylint/issues/7375 Related: OS#5668
2022-08-21proactive: Send a Terminal Response automatically after a FetchChristian Amsüss1-7/+43
Change-Id: I43bc994e7517b5907fb40a98d84797c54056c47d
2022-08-21proactive: Avoid clobbering the output of the command that triggered the FETCHChristian Amsüss1-4/+9
Change-Id: I2b794a5c5bc808b9703b4bc679c119341a0ed41c
2022-08-06pySim-shell: Use pySim.cat definitions to print decoded proactive cmdsHarald Welte1-4/+14
Register a ProactiveHandler with pySim.transport and call the decoder from pySim.cat to print a decoded version: Example usage (exact data only works on my specific card due to the encrpyted payload): pySIM-shell (MF/ADF.USIM)> envelope_sms 400881214365877ff6227052000000000302700000201506393535b000118dd46f4ad6b015922f62292350d60af4af191adcbbc35cf4 FETCH: d0378103011300820281838b2c410008812143658700f621027100001c12b000119660ebdb81be189b5e4389e9e7ab2bc0954f963ad869ed7c SendShortMessage(CommandDetails({'command_number': 1, 'type_of_command': 19, 'command_qualifier': 0}),DeviceIdentities({'source_dev_id': 'uicc', 'dest_dev_id': 'network'}),SMS_TPDU({'tpdu': '410008812143658700f621027100001c12b000119660ebdb81be189b5e4389e9e7ab2bc0954f963ad869ed7c'})) SW: 9000, data: d0378103011300820281838b2c410008812143658700f621027100001c12b000119660ebdb81be189b5e4389e9e7ab2bc0954f963ad869ed7c Change-Id: Ia4cdf06a44f46184d0da318bdf67077bc8ac9a1a
2022-08-06pySim.transport: Add mechanism for handling for CAT/USAT proactive cmdsHarald Welte1-5/+31
This introduces an optional argument to the LinkBase class constructor, where the application can pass an instance of a ProactiveHandler derived class in order to handle the proactive commands that the LinkBase is automatically fetching whenever the card indicates so. Change-Id: I844504e2fc1b27ce4fc7ede20b2307e698baa0f6
2022-08-06Add TLV definitions for *a lot more* CAT / USAT data objectsHarald Welte1-15/+874
This adds deciding for the bulk of the TLV objects used in the ETSI CAT (Card Application Toolkit) and 3GPP USAT (USIM Application Toolkit) systems. This patch just adds the definitions, but doesn't use them anywhere yet. Change-Id: I0c66912dbc10164e040e2fec358cef13c45a66ec
2022-08-06tlv: Use self._compute_tag() method rather than direct self.tagHarald Welte1-1/+1
The TLV_IE.from_tlv() method is part of a base class that is inherited by more specific classes. The official way to obtain the tag is the inherited-class-provided self._compute_tag() method, and *not* a direct reference to the self.tag member. This allows for some more obscure TLV parsers, such as the upcoming one for Proactive Commands in the CAT/OTA context. Change-Id: I0cd70e31567edc5a0584336efcb5e4282734f6dd
2022-07-30ts_31_102: Add missing imports for envelope_sms commandHarald Welte1-0/+1
The envelope_sms command fails due to some missing imports prior to this patch. Change-Id: I98e692745e7e1cfbc64b88b248700b1e54915b96
2022-07-30ts_31_102: Fix terminal_profile, envelope and envelope_sms commandsHarald Welte1-6/+6
In commit Ib88bb7d12faaac7d149ee1f6379bc128b83bbdd5 I accidentially broke those commands by adding argparse definitions for better documentation. When adding the @cmd2.with_argparser decorator, the method argument changes from the raw string to an argparse.Namespace object. This patch fixes the below exception: pySIM-shell (MF/ADF.USIM)> terminal_profile ffffffff Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/cmd2/cmd2.py", line 2129, in onecmd_plus_hooks stop = self.onecmd(statement, add_to_history=add_to_history) File "/usr/local/lib/python3.10/dist-packages/cmd2/cmd2.py", line 2559, in onecmd stop = func(statement) File "/usr/local/lib/python3.10/dist-packages/cmd2/decorators.py", line 336, in cmd_wrapper return func(*args_list, **kwargs) File "/space/home/laforge/projects/git/pysim/pySim/ts_31_102.py", line 1274, in do_terminal_profile (data, sw) = self._cmd.card._scc.terminal_profile(arg) File "/space/home/laforge/projects/git/pysim/pySim/commands.py", line 583, in terminal_profile data_length = len(payload) // 2 TypeError: object of type 'Namespace' has no len() Change-Id: Ia861eeb2970627d3ecfd0ca73f75ca571c6885b2 Fixes: Ib88bb7d12faaac7d149ee1f6379bc128b83bbdd5
2022-07-30Fix printing of SwMatchError after introduction of logical channelsHarald Welte1-2/+2
the interpret_sw() method was moved from RuntimeState to RuntimeLchan in Change-Id I7aa994b625467d4e46a2edd8123240b930305360 - but the code in pySim/exceptions.py was not adjusted accordingly. Change-Id: I0614436c99c6a6ebc22c4dc14fb361c5f5f16686
2022-07-25apdu/ts_102_221: SELECT: allow select of SELFHarald Welte1-2/+2
While in the pySim-shell, it's useful to filter the currently selected file from the choice of available files for select, this doesn't apply for the tracing case: It's perfectly valid for the UE to SELECT the file that's already selected right now. The operation basically becomes equivalent to a STATUS. Change-Id: I1a20fb3ba70426333ac34448c6cb782c51363965
2022-07-25apdu/ts_102_221: SELECT: allow select of parent/ancestor DFsHarald Welte1-2/+2
We need to pass the 'PARENT' flag to get_selectables() to be able to track SELECT on any of the parent/ancestor DF FID. Change-Id: Ia7ac627d5edccb97160c90688d720d887fad6ec7
2022-07-25filesystem: We can select not just immediate parent DF but all ancestorsHarald Welte1-2/+16
I didn't check the specs, but at least experience with real-world cards (and modems) shows that it's not just permitted to select the immediate parent DF, but all ancestors of the currently selected file. So adjust the get_selectables() method to not just return the immediate parent, but to recurse all the way up and report the FID of any ancestor DF. Change-Id: Ic9037aa9a13af6fb0c2c22b673aa4afa78575b49
2022-07-24apdu/ts_102_221: Fix SELECT of 3f00Harald Welte1-2/+4
In order to be able to explicitly select the MF via 3f00, we need to pass the 'MF' to get_selectables(), so the record is included in the list of selectable files from the current working directory. Change-Id: I27085896142fe547a6e93e01e63e59bbc65c8b8a
2022-07-24apdu/ts_102_221: Implement SELECT case "df_ef_or_mf_by_file_id"Harald Welte1-0/+11
This was [sadly] simply missing from the implementation so far. Change-Id: I7bbd13ce29f5adc1ca3ca01bffabbe02dd17db20
2022-07-24filesystem.py: Make CardDF.get_selectables() respect the flagsHarald Welte1-2/+4
All other get_selectables() understand a flag like 'FIDS' to request only the hexadecimal FIDs and not the file names. However, the CardEF.get_selectables() ignored those flags and unconditionally returned the names. Change-Id: Icdc37cae3eecd36d167da76c30224b9d48c844fd
2022-07-24pySim-trace: Don't print argparse object at start-upHarald Welte1-1/+0
Change-Id: I881471d026457d8ffcfdbd412c7aae0d0bff9344
2022-07-24pySim-trace: Fix --no-suppress-{select.status} command line argumentsHarald Welte1-3/+5
The Tracer implemented those options and the argparser handled it, but we didn't ever connect the two. Change-Id: I7d7d5fc475a8d09efdb63d3d6f1cc1de1996687b
2022-07-24pySim-trace: Support SELECT with empty response bodyHarald Welte1-1/+3
If the modem/UE doesn't ask for the FCP to be returned, a SELECT can exit with 9000 and no response body. Don't crash in that case. Change-Id: I66788717bec921bc54575e60f3f81adc80584dbc
2022-07-23sim-rest-server: Report meaningful error message if PIN is blockedHarald Welte1-5/+15
Instead of a cryptic backtrace, we now return a meaningful error like this: {"error": {"message": "Security Status not satisfied - Card PIN enabled?", "status_word": "6982"} Change-Id: I6dafd37dfd9fa3d52ca2c2e5ec37a6d274ba651b Closes: OS#5606
2022-07-23sim-rest-server: Render error messages as JSONHarald Welte1-54/+64
Let's make sure even error messages are returned in JSON format. While at it, also reduce some code duplication between the 'auth' and 'info' route handlers by using the klein handle_errors decorator instead of manual exception catching. Change-Id: I1e0364e28ba7ce7451993f57c8228f9a7ade6b0e Closes: OS#5607
2022-07-23pySim-shell: Add a "version" command to print the pySim package versionHarald Welte1-0/+5
It may be interesting to know which pySim-shell version a user is running. Change-Id: Ib9a1fbff71aa8a2cfbaca9e23efcf7c68bf5af1a Closes: OS#5459
2022-07-23Introduce APDU/TPDU trace decoderHarald Welte15-2/+1855
This introduces a new pySim.apdu module hierarchy, which contains classes that represent TPDU/APDUs as exchanged between SIM/UICC/USIM/ISIM card and UE. It contains instruction level decoders for SELECT, READ BINARY and friends, and then uses the pySim.filesystem.Runtime{Lchan,State} classes to keep track of the currently selected EF/DF/ADF for each logical channel, and uses the file-specific decoder classes of pySim to decode the actual file content that is being read or written. This provides a much more meaningful decode of protocol traces than wireshark will ever be able to give us. Furthermore, there's the new pySim.apdu_source set of classes which provides "input plugins" for obtaining APDU traces in a variety of formats. So far, GSMTAP UDP live capture and pyshark based RSPRO live and pcap file reading are imlpemented. Change-Id: I862d93163d495a294364168f7818641e47b18c0a Closes: OS#5126
2022-07-23sysmocom_sja2: Prevent KeyError/None exception on encodeHarald Welte1-3/+3
Fix a bug in the pySim.sysmocom_sja2 module, where we defined unnamed bits in BitStruct without a default value causing exceptions like this: EXCEPTION of type 'KeyError' occurred with message: 'None' Change-Id: Ib2da5adda4fae374ab14bb8100f338691aef719a Closes: OS#5575
2022-07-21ts_31_102: Fix EF_EPSLOCI argument orderingHarald Welte1-2/+2
We were invoking the constructor with the description as 4th positional argument, but that was actually the 'size' argument in this case. Let's swap the order to be aligned with other file constructors. Change-Id: I9acee757f096fef0d8bacbec3b52f56267cd52f6
2022-07-21filesystem: Use Tuple for record lengthHarald Welte6-47/+47
The size should be a *tuple*. In reality we so far passed a set. The problem with the set is that ordering is not guaranteed, and hence we cannot assume the first and second item have meaning (minimum vs. default record length). Change-Id: I470f4e69c83cb2761861b3350bf8d49e31f4d957
2022-07-21filesystem: Use Tuple for transparent file sizeHarald Welte7-70/+72
As the documentation strings say: The size should be a *tuple*. In reality we so far passed a set. The problem with the set is that ordering is not guaranteed, and hence we cannot assume the first and second item have meaning (minimum vs. default size). While at it, use a type annotation to catch such bugs easily. Change-Id: I553616f8c6c4aaa8f635b3d7d94e8e8f49ed5a56
2022-07-20introduce fully_qualified_path_str() methodHarald Welte2-20/+24
Reduce all the copy+pasted '/'.join(path_list) constructs with a method returning the formatted path string. Change-Id: I5e9bfb425c3a3fade13ca4ccd2b891a0c21ed56d
2022-07-20Never use Bytes without any 'Adapter'Harald Welte4-31/+34
Otherwise we have binary/bytes as values inside the dict, rather than a hexadecimal string. That's ugly when printing without json formatting. Change-Id: Ia3e7c4791d11bd4e3719a43d58e11e05ec986d1f
2022-07-20EF.AD: Avoid NotImplementedErrror regarding network namesHarald Welte1-2/+4
Even while we don't yet have a proper decoder, let's at least represent the network name as hex-string Change-Id: I4ed626699d1e4e484d4ffd04349676dadff626a0
2022-07-20tlv: Make NotImplementedError more verboseHarald Welte1-2/+2
This helps to understand immediately _what_ is not implemented for which type. Change-Id: I017eb4828e9deee80338024c41c93c0f78db3f3b
2022-07-20README: Mention the manual can also be built from the sourceHarald Welte1-1/+1
Change-Id: Ic73a9ebaecab1b14668aaffe4cd39b3749a19fc7
2022-07-18ts_31_102: Add support for obsolete EF.RPLMNAcTHarald Welte1-0/+10
This file existed in earlier specs like Release 3.8.0, but was removed in later revisions. Still, there are cards around implementing that older spec, so let's add a decoder. Change-Id: Ic7163b2a01f64ef1223cf15b8d0813d3edf5b61a
2022-07-17ts_31_102: Add support for DF.GSM-ACCESSHarald Welte2-7/+25
Change-Id: I244c3eea13587e6213062d9a58e821697614a86a
2022-07-17ts_31_102: Support for files of DF.V2X (Vehicle 2 X)Harald Welte2-1/+44
Change-Id: I7246f165aebbc42a685f36a7a6f973498b23b614
2022-07-17ts_31_102: Support for DF_MCS (Mission Critical Services)Harald Welte2-3/+69
Change-Id: I0485a14c7820f7b345eeba6109a93b6d4bc639bf
2022-07-17move EF_UServiceTable from ts_31_102 to ts_31_102_telecomHarald Welte3-90/+93
We want to use this class in an upcoming patch for DF_MCS support, and in order to avoid cyclic imports, EF_UServiceTable must be moved. Change-Id: I9cd6ab795bfd92f845eb943679a3d6302f1003ce
2022-07-17minimalistic support for DF.MULTIMEDIAHarald Welte2-2/+25
No decode of the payload of the files yet, but let's at least name them. Change-Id: I2d9c56bdea08fe6629978b6a1f7c139f487d075a