Commit Graph

671 Commits

Author SHA1 Message Date
Harald Welte 363edd9d34 ts_31_102: Add support for obsolete EF.RPLMNAcT
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-18 09:35:35 +02:00
Harald Welte d90ceb86be ts_31_102: Add support for DF.GSM-ACCESS
Change-Id: I244c3eea13587e6213062d9a58e821697614a86a
2022-07-17 22:12:06 +02:00
Harald Welte 228ae8e1dc ts_31_102: Support for files of DF.V2X (Vehicle 2 X)
Change-Id: I7246f165aebbc42a685f36a7a6f973498b23b614
2022-07-17 22:01:50 +02:00
Harald Welte 650f612d74 ts_31_102: Support for DF_MCS (Mission Critical Services)
Change-Id: I0485a14c7820f7b345eeba6109a93b6d4bc639bf
2022-07-17 22:01:29 +02:00
Harald Welte 6f8a870c65 move EF_UServiceTable from ts_31_102 to ts_31_102_telecom
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-17 21:55:37 +02:00
Harald Welte a0452216a4 minimalistic support for DF.MULTIMEDIA
No decode of the payload of the files yet, but let's at least
name them.

Change-Id: I2d9c56bdea08fe6629978b6a1f7c139f487d075a
2022-07-17 21:55:15 +02:00
Harald Welte a6c0f880da filesystem: Introduce the basic notion of 'logical channels'
cards can have multiple logical channels; each logical channel
has its own state of what is the current selected file + application.

Let's split the RuntimeState class into the global RuntimeState and the
per-lchan-specific RuntimeLchan class.

This code doesn't actually introduce any code that uses lchans other
than the basic logical channel (0), but just modifies the data model
to accomodate those in the future.

Change-Id: I7aa994b625467d4e46a2edd8123240b930305360
2022-07-17 21:55:15 +02:00
Harald Welte de4c14c0dc Add very simplistic DF_PHONEBOOK support
This at least gives us the names for the DF and those EFs inside.

Change-Id: I12f70ae78e219e765ecb44cacff421d64c7b3f19
2022-07-17 21:55:11 +02:00
Harald Welte afe093ce41 ts_31_103: Fix typos related to IMSConfigData + MudMidConfigData
s/neted/nested/

Change-Id: I9049ed12b8e7e6d1fdb7d19ed0b98ce8b46f9b0e
2022-07-17 21:52:57 +02:00
Harald Welte eb882052f5 ts_31_102: Fix FID in DF.HNB
The FID are all specified as 4f8x and not 4f0x

Change-Id: I0cfd623693a5017efe01bc6891640db22ba3f9f9
2022-07-17 21:52:57 +02:00
Harald Welte 4b00365c6e fileystem: Use human-readable ADF name if available.
When using __str__ for a CardDF we would get "DF(DF.TELECOM)"
but when using it on CardADF we would get ADF(a0000000871002)"
instead of "ADF(ADF.USIM)".  Let's fix that.

Change-Id: I5801a08bcc28cb222734af6d9ee835227f4fee69
2022-07-17 21:52:57 +02:00
Harald Welte 1e52b0d3b7 pySim-shell: Remove unused imports
Those might have been used some time ago, but they are not.

Change-Id: I00f096fc8049c0aebc1127f9a1725638d973af0e
2022-07-16 11:53:21 +02:00
Harald Welte 46a7a3fcc2 filesystem: keep track of currently selected ADF
As it is possible to select files relative to the currently selected
ADF, we should keep track of that.

Change-Id: I83c93fdcd23b1d3877644ef0bf72d330343fbbc7
2022-07-16 11:50:09 +02:00
Harald Welte d56f45d720 filesystem: raise exception only when applicable
We should first see if any of the files in the tree actually
require a service mapping before raising
ValueError('TODO: implement recursive service -> file mapping')

Change-Id: I9c339f0cac020e7eec7f4f840748040e5f77923d
2022-07-16 11:50:08 +02:00
Vadim Yanitskiy c655518654 pySim/ts_102_222.py: remove ununsed imports from 'cmd2'
Change-Id: If6c686c8248cd0ad4edb68b84886a6f5f558d0f7
2022-07-14 19:12:21 +07:00
Vadim Yanitskiy 0d9f088853 pySim-shell.py: remove unused imports of 'bg' from 'cmd2'
Change-Id: Ic2a73a98f322be391e54215bc5fc3358776da0ae
2022-07-14 19:11:25 +07:00
Harald Welte 6f8cf9b315 sim-rest-server: Set Content-Type: application/json on response
Change-Id: Ib80a650f3e8d3e3ee6295db6de0981dfc23d3feb
2022-07-08 20:47:46 +02:00
Harald Welte 77d510b4be scripts/deactivate-5g.script: Also disable service 126
Service 126 relates to DF.5GS/EF.UAC_AIC.  As we are deactivating that
file in the script, we should also disable the related EF.UST service.

Change-Id: Id35035aaf23b2163caed3197786288c87be03cfa
2022-07-08 20:47:35 +02:00
Vadim Yanitskiy 04b5d9d7ab Py2 -> Py3: do not inherit classes from object
https://stackoverflow.com/questions/4015417/why-do-python-classes-inherit-object/45062077

Change-Id: I15003ba591510d68f3235f71526ad5d8a456088e
2022-07-07 03:05:30 +07:00
Philipp Maier bda52830c9 cards: populate ADM1 key reference member
In class SimCard, we specify the key reference for ADM1 as 0x04. in the
UsimCard class, which inherits from SimCard nothing is specified, even
though ETSI TS 102 221 specifies 0x0A as key reference. Lets set the
member in UsimCard accordingly to be closer to the spec.

Note: For the moment this is a cosmetic fix, it does not change the
behaviour since all card classes derived from UsimCard set the key
reference properly.

Change-Id: I96af395b1832f4462a6043cca3bb3812fddac612
2022-06-21 09:56:49 +02:00
Philipp Maier 2403125a34 pySim-shell: set default ADM key reference
ETSI TS 102 221, Table 9.3 specifies 0x0A as default key reference for
ADM1. Lets make sure pySim-shell uses this key-reference if the card is
a generic UICC.

Change-Id: I8a96244269dc6619f39a5369502b15b83740ee45
2022-06-14 16:22:39 +02:00
Philipp Maier 541a9154da ts_102_221: The BTLV IEs FILE SIZE and TOTAL FILE SIZE have a min length
The TLV IEs FILE SIZE and TOTAL FILE SIZE have a minimum length of 2
byte. Even when the length is in the single digit range two bytes must
be used. See also: ETSI TS 102 221, section 11.1.1.4.1 and 11.1.1.4.2

Change-Id: Ief113ce8fe3bcae2c9fb2ff4138df9ccf98d26ff
2022-06-10 16:26:54 +02:00
Philipp Maier 40ea4a4a1c commands: add ".." notation to expand hexstrings
When updating files and records there are sometimes huge portions that
are just 0xff. Mostly this is at the end of a file or record that is not
completely used. Lets add a notation to tell PySim-shell how to fill
those sections.

Change-Id: Iedd7887bf7d706878f4a3beca8dbea456404610b
2022-06-03 10:26:58 +02:00
Philipp Maier f16ac6acf8 pySim-shell: catch exceptions from walk() while exporting
When we run the exporter we also get an error summary at the end.
However, if walk() throws an eception this stops the exporter
immediately and we won't get the summpary. Lets catch exceptions from
walk as well so that we are able to end gracefully.

Change-Id: I3edc250ef2a84550c5b821a72e207e4d685790a5
2022-06-03 10:18:09 +02:00
Philipp Maier 7b138b0d2d pySim-shell: extend walk() so that we can also have an action of ADF or DF
The walk() method that we use to traverse the whole file system tree is
currently only able to execute action callbacks on EFs. Lets add a
mechanism that allows us to have a second callback that is executed when
we hit a DF or ADF.

Change-Id: Iabcd78552a14a2d3f8f31273dda7731e1f640cdb
2022-06-03 08:17:57 +00:00
Philipp Maier e7d1b67d80 pySim-shell: match SW in apdu command
The apdu command has no option to match the resulting SW. Lets add a new
option for this.

Change-Id: Ic5a52d7cf533c51d111850eb6d8147011a48ae6c
2022-06-03 10:08:37 +02:00
Philipp Maier 7226c09569 pySim-shell: make APDU command available on the lowest level
The apdu command is used to communicate with the card on the lowest
possible level. Lets make it available even before a card profile (rs)
is avalable. This is especially useful when the card has no files on it,
in this situation pySim-shell will not be able to assign a profile to
the card at all. We can then use the apdu command to equip the card with
the most basic files and start over.

Change-Id: I601b8f17bd6af41dcbf7bbb53c75903dd46beee7
2022-06-03 08:07:42 +00:00
Philipp Maier 373b23c372 ts_102_221: fix SFI generation
The generation of the SFI does not work. The result is always a zero
length TLV IE.

Change-Id: Iaa38d2be4719f12c1d7b30a8befe278f1ed78ac1
2022-06-02 08:43:54 +00:00
Philipp Maier 6b8eedc501 filesystem: also return the encoded FCP from probe_file
he method probe_file returns the decoded FCP after it managed to
successfully probe the file. Lets also return the encoded FCP string, as
it is needed by the caller.

Change-Id: Ia5659e106fb0d6fb8b77506a10eba309e764723e
2022-06-01 18:10:04 +02:00
Philipp Maier 9a4091d93a pySim-shell: more generic export options
The as_json parameter has been added as an additional parameter to the
export function. Lets use a dictionary here and put the parameter in it.
This makes it easier to add more options in the future

Change-Id: Ie860eec918e7cdb01651642f4bc2474c9fb1924f
2022-05-30 11:53:22 +02:00
Philipp Maier ea81f75e94 pySim-shell: explain why we insist on a DF or ADF
Change-Id: I155cefb10864432d59a0a66410783b4c9772f8a4
2022-05-19 10:14:44 +02:00
Christian Amsüss e17e277a24 ts_102_222: Set number of records when creating linear files
This information is mandatory for linear files as per TS 102 221 V15
section 11.1.1.4.3. This might not have been spotted earlier because
cards of type sysmoISIM-SJA2 accept creation without it as well.

Change-Id: I8aeb869c601ee5d1c8b02da6d72eb3c50e347982
2022-05-06 11:04:51 +00:00
Vadim Yanitskiy e6b86872ce transport/pcsc: throw ReaderError with a message
Before this patch:

  $ ./pySim-shell.py -p 0
  Card reader initialization failed with an exception of type:
  <class 'pySim.exceptions.ReaderError'>

after:

  $ ./pySim-shell.py -p 0
  Card reader initialization failed with exception:
  No reader found for number 0

Change-Id: Id08c4990857f7083a8d1cefc90ff85fc20ab6fef
2022-04-25 18:24:41 +03:00
Vadim Yanitskiy b95445159b SimCard.reset(): fix SyntaxWarning: 'is' with a literal
Change-Id: I5860179acd1cb330e91dbe5b57cd60cd520f2d9d
2022-04-21 16:46:09 +03:00
Harald Welte c30bed235e ts_102_221: Add encode/write support of EF.ARR records
With this change, we can also encode/write EF.ARR records, not just
decode/read.

Change-Id: Id0da2b474d05aba12136b9cae402ad8326700182
2022-04-05 14:45:18 +02:00
Harald Welte 0dcdfbfe94 utils: Add DataObjectSequence.encode_multi()
This is the analogous to the decode_multi() method.

Change-Id: Ifdd1b1bd4d67f447638858c3e92742ca6f884bfa
2022-04-05 14:42:48 +02:00
Harald Welte 785d484709 utils: Fix bugs in DataObject encoders
The DataObject is some weird / rarely used different code than the
normal TLV encoder/decoder.  It has apparently so far only been used
for decoding, without testing the encoding side, resulting in related
bugs.

Let's fix those that I encountered today, and add a test case.

Change-Id: I31370066f43c22fc3ce9e2b9ee75986a652f6fc4
2022-04-05 14:33:00 +02:00
æstrid smith b7f35ac163 ts_31_103: Correct file-id of EF.DOMAIN in ADF.ISIM
While the short ID of this file is 05, the actual file-id is 6f03.
Reference to TS 31.103 section 4.2.3.

Change-Id: Idd572ab064ea38e74dffd583c27ea505b23214a2
2022-03-27 10:43:38 +00:00
Harald Welte ab91d874e4 ts_31_102: Avoid pylint false positive
This should avoid the following pylint error:

************* Module pySim.ts_31_102
pySim/ts_31_102.py:621:100: E0601: Using variable 'sw' before assignment (used-before-assignment)

Change-Id: I0bb9607cdab0e6e3cd17b4d27129a51a607bc0f2
2022-03-27 12:33:55 +02:00
Harald Welte aefd0649a2 pySim-shell: Add 'decode_hex' command for transparent + linear EF
These commands can be used to decode a user-provided hex-string,
instead of decoding the data read from the file.  This is useful
for quickly manually decoding some values read from other locations,
such as e.g. copy+pasted from a eSIM profile in ASN.1 value notation.

Change-Id: I81f73bce2c26e3e5dfc7538d223bb2d2483c7fa0
2022-03-01 16:48:22 +00:00
Harald Welte 34eb504b3b Initial support for GlobalPlatform
One can now select the Issuer Security Domain (hard-coded to
a000000003000000) and issue get_data requests.  FCI and other TLV
objects are dcoded, e.g.

pySIM-shell (MF)> select ADF.ISD
{
    "application_id": "a000000003000000",
    "proprietary_data": {
        "maximum_length_of_data_field_in_command_message": 255
    }
}
pySIM-shell (MF/ADF.ISD)> get_data CardData
{
    "card_data": [
        {
            "card_recognition_data": [
                {
                    "object_identifier": "2a864886fc6b01"
                },
                {
                    "card_management_type_and_version": [
                        {
                            "object_identifier": "2a864886fc6b02020101"
                        }
                    ]
                },
                {
                    "card_identification_scheme": [
                        {
                            "object_identifier": "2a864886fc6b03"
                        }
                    ]
                },
                {
                    "secure_channel_protocol_of_isd": [
                        {
                            "object_identifier": "2a864886fc6b040215"
                        }
                    ]
                }
            ]
        }
    ]
}

Change-Id: If11267d45ab7aa371eea8c143abd9320c32b54d0
2022-03-01 16:32:15 +00:00
Harald Welte a037762b04 ts_31_102: Further decode TAI in EF.OPL5G
The TAI is not just an opaque bytestring but it consists of 3 fields.

Change-Id: Ie5a5ce74713deb0e151218ae553d3f3d96cef17d
2022-02-25 15:45:09 +01:00
Harald Welte 3a5afff022 ts_31_102: Further decode LAI in EF_LOCI
Change-Id: I21d9356e541eb320848a373804781ae0bef7d012
2022-02-25 15:45:02 +01:00
Harald Welte 1459e45005 ts_51_011: Better decode of EF_OPL LAI
before:
{
    "lai": "62f2300000fffe",
    "pnn_record_id": 1
}

after:
{
    "lai": {
        "mcc_mnc": "262f03",
        "lac_min": "0000",
        "lac_max": "fffe"
    },
    "pnn_record_id": 1
}

Change-Id: I82581220e9c33a8e67cbefd5dfeb40bbc2c31179
2022-02-25 15:44:26 +01:00
Harald Welte 22a1cdde25 ts_51_011: Properly decode EF.OPL
The OPL has 7 bytes "LAI" as the LAI actually contains a LAC
range (so two more bytes for the end of the 16bit range).

Change-Id: I74bcf10b0a8977af0f2844044a812c5780af1706
2022-02-25 15:31:16 +01:00
Harald Welte dd45d8ee3b ts_31_102: Fix decoding of UServiceTable
range(0,7) in python is 0..6, and not 0..7, so we need range(0.8)
to produce the desired range covering all bits of a byte.

This resulted in services 8,16,24,... not being displayed in
the decoded output of EF.UST / EF.IST.

Change-Id: I22bbc481de342685352bf5b13d54931d3f37f9b7
2022-02-25 15:31:16 +01:00
Harald Welte 4ebeebffca ts_102_221: Fix decoding the 'num_of_rec' field
It is a 8bit integer, not a 16bit integer.  See TS 102 221 11.1.1.4.3

Change-Id: I3e258547dad21a248650cfbc02e0576268d3b3fd
2022-02-25 09:48:20 +01:00
Harald Welte 5e9bd93bbd ts_102_221: properly decode short file identifier
The SFI TLV contanins not the raw SFI, but it contains the SFI
shifted to left by 3 bits (for some strange reason).  So let's
un-shift it.

Change-Id: Ibc69b99010d2a25cbb69b6a3d1585d0cb63f1345
2022-02-25 09:37:40 +01:00
Harald Welte fa578bd601 add scripts/deactivate-ims.script to deactivate IMS related services
Change-Id: I0cd93c8fa0024dd9d93647c565190abe94d3097e
2022-02-21 09:57:09 +01:00
Harald Welte c89a1a99ca Add scripts/deacivate-5g.script
This script can be used to deactivate all 5G related services and files.

Change-Id: I5dc3e9f0ae76a7ae57484e5a3369e11ff02c7eca
2022-02-17 12:42:14 +01:00