This method helps in encoding of Service Tables in EF.SST, EF.UST, EF.EST, EF.IST.
Takes original hex string of EF.SST, EF.UST, EF.EST, EF.IST, Service number,
Service to be enabled or disable flag as input and outputs the modified Service Table.
Change-Id: I0c97317d5a17aa0df720659d021b5cbf7d30edcc
If the EF.EHPLMN exists, it contains the "Equivalent Home PLMN List".
The odd part of that list is that it is not just a list of additional
PLMN identities, but if the first digits of the IMSI are *not* listed
in EF.EHPLMN, then the MCC/MNC of the IMSI prefix is suddently no
longer considered the home network, but the subscriber is roaming.
See TS 23.122: "If the HPLMN code derived from the IMSI is not present
in the EHPLMN list, then it shall be treated as a Visited PLMN for PLMN
selection purposes."
Change-Id: I22d96ab4a424ec5bc1fb02f5e80165c646a748d3
This method encodes ePDG Id so it can be stored to EF.ePDGId or EF.ePDGIdEm.
See 3GPP TS 31.102 version 13.4.0 Release 13, section 4.2.102 and 4.2.104.
Resulting hex string is made of tag value + length + address type + address.
tag value for home ePDG identifier is 80
address type: 0x00 (FQDN), 0x01 (IPv4), 0x02 (IPv6), other (Reserved)
ePDG FQDN example: epdg.mnc001.mcc001.3gppnetwork.org
Note: Only FQDN format is supported for now
Change-Id: I864bda5505e9061391a727add294a6e90c50f9ef
The LOCI, PSLOCI and EPSLOCI contain some info,
including the PLMN, added helper functions to
decode it
Change-Id: Ibb513ff7d1dc6d33b354ae26cbd9c390ea3c8efc
According to 3GPP TS 27.007, sections 8.17 and 8.18, the modem
may *optionally* provide Generic and/or Restricted SIM Access
to the TE (Terminal Equipment) by means of the AT commands.
This basically means that a modem can act as a card reader.
Generic SIM Access allows the TE to send raw PDUs in the format
as described in 3GPP TS 51.011 directly to the SIM card, while
Restricted SIM Access is more limited, and thus is not really
interesting to us.
This change implements a new transport called ModemATCommandLink,
so using it a SIM card can be read and/or programmed without the
need to remove it from the modem's socket. A downside of this
approach is relatively slow I/O speed compared to PC/SC readers.
Tested with Quectel EC20:
$ ./pySim-read.py --modem-dev /dev/ttyUSB2
Change-Id: I20bc00315e2c7c298f46283852865c1416047bc6
Signed-off-by: Vadim Yanitskiy <axilirator@gmail.com>
By definition, h2s() is supposed to skip padding in the given
hexstring, so it was working fine for 'ff', but not for 'FF'.
Change-Id: I2c5d72a0f7f2796115116737f9f7b5299021f6a3
Signed-off-by: Vadim Yanitskiy <axilirator@gmail.com>
In case try to decode the contents of an uninitalized EF.IMSI, the
function dec_imsi() would crash because it truncates all 0xFF from the
swapped version of the EF.IMSI contents and then accesses the first
element of the buffer. This always works for EF.IMSI contents that
contain valid IMSI data, but if all bytes are set to 0xFF, then no data
is left in the buffer after truncating, so lets check if we even have
bytes left before we move on with the decoding.
Change-Id: I93874a1d7e0b87d39e4b06a5c504643cfabb451c
The lower part of gen_parameters() in pySim-prog.py contains some code
that checks whether the ADM pin supplied in its hexadecimal or in its
string form and generates a sanitised pin_adm from that. Lets separate
this part as it may become useful elsewhere too.
Change-Id: Ifead29724cc13a91de9e2e89314d7fb23c063d50
A MNC of 02 and 002 are *not* equal. The former is a two-digit MNC
and the latter is a three-digit MNC. Hence, we shouldn't treat
MNCs as integer values as we have no clue how many leading zeroes
(if any) the user entered.
Change-Id: I9d1d07a64888c76703c3e430bbdd822080c05819
Closes: OS#4523
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
The hex string consists of contains zero or more ePDG identifier data objects.
Each ePDG Identifier TLV data object consists of tag value of '80', length, address type, identifier.
TS 31.102 version 13.4.0 Release 13. The same parsing method applies for both EF.ePDGId and EF.ePDGIdEm
Change-Id: I96fb129d178cfd7ec037989526da77899ae8d344
The functions are imported from the git commit 2a81963790e27eb6b188359af169c45afb6d3aaf from master branch
Change-Id: I5c7fdbd122e696d272f7480785d0c17ad2af138c
This method helps in printing Service Tables in EF.SST, EF.UST, EF.IST.
Takes hex string of Service table, parses it and prints available service along with its description.
Change-Id: Ie1e82e07ead2e28314a5794661e6b2ced0acd72a
This method helps in parsing Service Tables in EF.SST, EF.UST, EF.EST, EF.IST.
Takes hex string as input and output a list of available/enabled services.
Change-Id: I9b72efdb84ba7be4a40928a008a59c67f6fb71d4
This change implements programming of EF.MSISDN as per 3GPP TS 31.102,
sections 4.2.26 and 4.4.2.3, excluding the following fields:
- Alpha Identifier (currently 'FF'O * 20),
- Capability/Configuration1 Record Identifier ('FF'O),
- Extension1 Record Identifier ('FF'O).
This feature is introduced exclusively for sysmoUSIM-SJS1.
Othere SIM card types need to be tested.
Change-Id: Ie033a0ffc3697ae562eaa7a241a0f6af6c2b0594
This change implements parsing of EF.MSISDN (and thus EF.ADN)
as per 3GPP TS 31.102, sections 4.2.26 and 4.4.2.3.
Example (commercial SIM card from 401/02):
EF.MSISDN: ffffffffffffffffffffffffffff07917787028982f7ffffffffffff
Decoded (NPI=1 ToN=1): +77782098287
Note that sysmoUSIM-SJS1 in the test setup has malformed
EF.MSISDN, so that's why the test output is changed.
Change-Id: Ie914ae83d787e3f1a90f9f305bffd45053b8c863
In case the MCC/MNC are not supplied with a CSV file we cut out the
missing values from the IMSI string. Lets use a function to do this and
also check the input parameters.
Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8
At the moment MNC and MCC are represented as integer numbers inside the
parameter array while all other parameters are represented as strings.
Lets use strings for MNC/MCC as well to simplify the parameter handling.
We will also not loose the length information in case of leading zeros.
Change-Id: Ia2333921a4863f0f26ee923ca796e62ec5e2d59a
Allow decoding and pretty printing of PLMNwAcT, HPLMNwAcT and OPLMNwAct.
Includes unit tests for the added functions.
Change-Id: I9b8ca6ffd98f665690b84239d9a228e2c72c6ff9
When programming or reading a SIM with an IMSI shorter than 15, the IMSI
value is incorrectly encoded/decoded.
The code pads the the IMSI value with 0xF from the left but padding from
the right would be correct.
It also encodes the length as half the number of digits in the IMSI
(rounded up). This isn't correct for even length IMSIs. With even length
IMSIs, the odd/even parity bit bumps the last digit into an extra byte,
which should be counted as well.
- Fix endcoding of IMSI value
- Fix decoding of IMSI value
Change-Id: I9ae4ca4eb7c2965e601a7108843d052ff613beb9
Patch-by: Ben Foxmoore
Closes: SYS#3552
It should fix the following observed error:
~/pysim$ ./pySim-read.py -p0
Reading ...
ICCID:
Traceback (most recent call last):
File "./pySim-read.py", line 99, in <module>
print("IMSI: %s" % (dec_imsi(res),))
File "/home/lab434/pysim/pySim/utils.py", line 57, in dec_imsi
l = int(ef[0:2]) * 2 # Length of the IMSI string
ValueError: invalid literal for int() with base 10: 'ff'
Change-Id: I7d3ecbf9edd190d1941816796cee60e3957d5943