Commit Graph

382 Commits

Author SHA1 Message Date
Supreeth Herle 475dcaa4a1 Define mapping between USIM Service Number and its description
This commit introduces a lookup table which maps USIM Service Number to its description.
The mapping is defined in 3GPP TS 31.102 version 13.4.0 Release 13, 4.2.8 EF.UST (USIM Service Table)

Change-Id: Ia9025a4be6ba29fe79ca4bf6c7a452188ea3d454
2020-04-16 07:38:28 +02:00
Supreeth Herle e26331ef72 Add ability to parse SIM Service Table (EF.SST)
As per TS.51.011, This EF indicates which services in the SIM are allocated, and whether, if allocated, the service is activated
.If a service is not indicated as available in the SIM, the ME shall not select this service.

Change-Id: Id28a35727adbaaa9df19b1adc621a0c51ad0e51b
2020-04-16 07:38:27 +02:00
Supreeth Herle 441c4a768f utils.py: Add helper method to parse Service Table
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
2020-04-01 11:06:59 +02:00
Supreeth Herle bf5d602588 Define mapping between SIM Service Number and its description
This commit introduces a lookup table which maps SIM Service Number to its description.
The mapping is defined in 3GPP TS 51.011 version 4.15.0 Release 4, 10.3.7 EF.SST (SIM Service Table)

Change-Id: I4a416bd8bff563ae08b1b3c053d2047da91667b4
2020-04-01 11:06:59 +02:00
Supreeth Herle 52ef675c31 Use the generic method read_binary of card class to read AD
Change-Id: Ie7f62913caed95f482445962954857bb69b58078
2020-04-01 11:06:25 +02:00
Supreeth Herle 6d66af653f Move parsing of MSISDN to generic Card class
Change-Id: I5b726bc0dc8c8e5eb42f209b1fe0f35a46ac91be
2020-04-01 11:05:26 +02:00
Supreeth Herle d1fb6fc359 Use the generic method read_binary of card class to read ACC
Change-Id: I92a02c74d64b3120055163548fc128ed6e0650a4
2020-04-01 11:04:43 +02:00
Supreeth Herle a850a47981 Move parsing of HPLMNAcT to generic Card class
Change-Id: I46c863c118dcbef89455c34289ed25e5a342f35b
2020-04-01 09:35:52 +02:00
Supreeth Herle 1757b263bf Move parsing of OPLMNwAcT to generic Card class
Change-Id: I8050bd103a7085b2631ddc4e567d15e05f9428f2
2020-04-01 09:35:52 +02:00
Supreeth Herle 140844052a Move parsing of PLMNwAcT to generic Card class
Change-Id: I14d7c2dc51fac6d5cf4a708a77ad23d252ba6094
2020-04-01 09:35:52 +02:00
Supreeth Herle 9efd8ef812 Use the generic method read_binary of card class to read PLMNsel
Change-Id: I0a683c479cd41ccc6a93c23434c73793cb5dc186
2020-04-01 09:34:57 +02:00
Supreeth Herle 846cefb0cd pySim-read.py: Use the method declared in cards.py to read SPN
Change-Id: I71c29e2d9d62c50d352556710e63ba398269a5c7
2020-04-01 09:33:29 +02:00
Supreeth Herle ebe6dbaef5 Use the generic method read_record of card class to read SMSP
Change-Id: I911c5339a739fbdd9d41e61b63f2410c8358815b
2020-04-01 09:32:49 +02:00
Supreeth Herle e573ccb53c Use read_binary function of card class to read GID2 and reduce code duplication
Change-Id: I5d80fcc1446a6691b8e2a09bcec558148fa31ab2
2020-04-01 09:21:20 +02:00
Supreeth Herle ad10d66baf cards.py: Add generic function to read EF record in card class
This is a generic function applicable for reading EF records which doesnt require further processing
such EF.SMSP etc while decoding and also to avoid code duplication.

Change-Id: Ic0b4aa11e962b4bb328447b11533136a29ff72d3
2020-04-01 09:14:54 +02:00
Supreeth Herle d21349a610 cards.py: Add generic function to read EF binary to card class
This is a generic function applicable for reading EFs which doesnt require further processing
such as GID1, GID2 etc while decoding and also to avoid code duplication.

Change-Id: If3d8fdddb26f9776c89fd442d1d95b83e0d1476b
2020-04-01 09:14:04 +02:00
Supreeth Herle c7f2f7413b Move parsing of GID2 to generic Card class
Change-Id: I3fe4b08c888a39cda7e7fce7a467f17908bdc3ad
2020-03-22 10:17:05 +01:00
Supreeth Herle 98a6927b27 Move parsing of GID1 to generic Card class
Change-Id: Ie96408b1eecd6fc2595d619f6f0e3af851dacecb
2020-03-22 10:17:05 +01:00
Supreeth Herle f9762dc98f pySim-read.py: Use the method declared in cards.py to read IMSI
Change-Id: I2709b040d956a3a2b9210aa78c82a6ccf482f761
2020-03-22 10:17:05 +01:00
Supreeth Herle 3566b8eb55 pySim-read.py: Use the method declared in cards.py to read ICCID
Change-Id: I0dcda1ea617f3febe246b360b95887c04e5d2629
2020-03-22 10:17:05 +01:00
Supreeth Herle 4c306ab200 pySim-read.py: Added a common card detection function for both pySim-prog.py and pySim-read.py
This function is used to detect the card type and return Card class/Card subclasses object
if its a know card or else None. Also, an initial step towards refactoring of code.

Change-Id: I71f57c6403dc933bd9d54f90df3d3fe105b4f66f
2020-03-22 10:17:03 +01:00
Supreeth Herle e4e98316a8 cards.py: Added parsing of all the AIDs in the UICC
Introduced a new member variable and a member function to Card class to fetch
and store the AIDs present in UICC. And, this variable (a list) is populated
by reading the EF 2f00 under MF 3f00 (function read_aids()).

Change-Id: I7ca77a73ebb42a8ba1381588d878040675d3019a
2020-03-19 10:27:48 +01:00
Supreeth Herle 0e90e6c3c6 pySim-read.py: support for reading GID2 from SIM
Change-Id: I0e893c3929aa1be6b55af296484811a7b94db560
2020-03-13 07:44:45 +00:00
Supreeth Herle ab46d625fc pySim-read.py: support for reading GID1 from SIM
Change-Id: I15d061daed20f770b9041977a0b1fc4fe44a8f95
2020-03-13 07:44:45 +00:00
Philipp Maier d950786525 sysmoISIM-SJA2: Add suport for USIM-only and ISIM-only cards
When pysim-prog programms the application specific files of ISIM and
USIM it selects the application by its AID first. If depending on the
card profile one of the applications is missing the selection of the
related ADF will fail. Lets check the presence of the AID first and if
it is not present lets skip the programming of the related files.

Change-Id: I0eec6ed244320fcd4dc410b6fab20df9c64ff906
Related: SYS#4817
2020-03-11 12:35:20 +01:00
Philipp Maier b3e11ea196 sysmiISIM-SJA2: add support for new card model / os version
There is a new card version with a different ATR, lets add the ATR for
this card to support it as well.

Change-Id: I222faea89c1df58c36a19b28449dffb84a956e74
Related: SYS#4817
2020-03-11 12:34:59 +01:00
Vadim Yanitskiy 9664b2e7fc cards: Python 3 fix: use the floor division operator //
Change-Id: I21de34133dbc5d859a5b744adc74f706ba2f0dd8
2020-02-27 02:20:47 +07:00
Vadim Yanitskiy edf873d04a commands: Python 3 fix: properly distinguish str and list
Unlike Python 2, in Python 3 strings also have attribute '__iter__'.
Because of that, a string could be passed to select_file(), that
actually expects a list as the first parameter.

P.S. Madness, Python 3 is just a new different language...
P.P.S. They should have renamed it not to confuse people.

Change-Id: I92af47abb6adff0271c55e7f278e8c5188f2be75
Fixes: OS#4419
2020-02-27 02:19:27 +07:00
Vadim Yanitskiy fa617ac20d transport/pcsc: explicitly specify T0 protocol
From pyscard user's guide [1]:

   == Selecting the card communication protocol ==

   By defaults, the connect() method of the CardConnection object
   will try to connect using either the T=0 or T=1 protocol.
   To force a connection protocol, you can pass the required
   protocol to the connect() method.

This means that a PC/SC ifd handler may automatically choose T=1
as the highest protocol if the card indicates both in its ATR [2].

Since pySim only supports T=0, let's select it explicitly.

[1] https://pyscard.sourceforge.io/user-guide.html
[2] https://github.com/acshk/acsccid/issues/16#issuecomment-501101972

Change-Id: Ifed4574aab98a86c3ebbeb191f36a8282103e775
2020-02-27 02:10:50 +07:00
Vadim Yanitskiy 41c22176e4 transport/pcsc: cosmetic: reuse the existing code of PcscSimLink
Change-Id: I5360df644032b95654e99ccaa5118952e8d55faf
2020-02-27 01:54:22 +07:00
Vadim Yanitskiy 7ba2428de5 utils: fix dec_msisdn(): properly detect international numbers
We should match the whole value of ToN, not just one LSB bit.

Change-Id: Idc51f09b3420d827a75a1161372e4e97c3ddfbc1
2020-02-27 01:54:10 +07:00
Vadim Yanitskiy 99affe1529 Py2 -> Py3: use the floor division operator // where possible
In Python 3, traditional division operator returns a float,
while we need a floor integer in the most cases.

Change-Id: I5565eb64a1ddea7075cbb142eaacaa5d494c87bb
2020-02-15 19:11:50 +00:00
Vadim Yanitskiy 4133080ced pySim-read.py: do not import json, it is not needed
Change-Id: I4ae1d71c5695c9cd8ddebea514847b0be6a24c6c
2020-02-15 19:11:50 +00:00
Supreeth Herle 5a541016fb pySim-prog.py: add support for MSISDN programming
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
2020-02-15 04:57:20 +07:00
Supreeth Herle 4b1c763395 pySim-read.py: fix reading and parsing of EF.MSISDN
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
2020-02-15 04:22:53 +07:00
Supreeth Herle d24f163513 Fix MCC and MCC representation in the output of pySim-read
Change-Id: Ie699c0a38d5ae90e4d6109e4574ce860e4044096
2020-02-15 03:26:49 +07:00
Supreeth Herle f442fb4d69 cards/sysmoUSIM-SJS1: support programming of EF.HPLMNwAcT
Change-Id: Ida93f4a00fe3b1d0f05d6eeda0e7873ce16d4c17
2020-02-15 03:26:49 +07:00
Supreeth Herle c8796a3184 cards/sysmoUSIM-SJS1: support programming of ACC bits
Change-Id: Id0ed9e5654dc0a70a4732bbe5787f1900789d580
2020-02-15 03:26:49 +07:00
Supreeth Herle 2d7859759e cards: fix reading of EF.HPLMNwAcT in Card.update_hplmn_act()
Change-Id: I35848059d6082c379246c8d695cb094c20780d15
2020-02-15 03:26:49 +07:00
Supreeth Herle 9ca41c1f26 cards: cosmetic/indentation fix: use tabs, not spaces
Change-Id: I5d9cbdb0ecbee783729d0a208d12f8e59ca957ff
2020-02-15 03:26:49 +07:00
Supreeth Herle 840a9e2a76 pySim-prog.py: add presence/length checks for user-provided SPN
Change-Id: I35fab9a85efda2b83f221a460d31c7d41db582b0
2020-02-15 03:26:49 +07:00
Supreeth Herle 6af4c21cdf pySim-read.py: print meaningful message when SPN is not set
Change-Id: I1d98520f33a8564c7d69f50a0811204f138f9dca
2020-02-15 03:25:47 +07:00
Vadim Yanitskiy a3bb334981 pySim-read.py: fix copy-paste: s/HPLMNAcT/PLMNsel/
Change-Id: I4a452a2e439cb713621a028cf0046339f50864b6
2020-02-14 22:46:38 +07:00
Vadim Yanitskiy 6727f0c02c Fix compatibility with Python 3: print() is a function
Change-Id: I5dd8e5daf420fc8667c5156bfacc8763d8895993
2020-02-14 22:46:38 +07:00
Vadim Yanitskiy fa1dc34152 testdata/sysmoUSIM-SJS1.ok: make it match the actual EF.HPLMNAcT
Change-Id: Ibe1bf274c15a3159b012c6fe07ef6a7cbf0adbdb
Related: OS#4383
2020-02-14 22:45:45 +07:00
Supreeth Herle e51643e87e Fix file permission
Change-Id: I893869329e9547e06386baf4d16a18e545042d62
2020-01-21 11:32:06 +01:00
Supreeth Herle 7947d92bc1 Added feature to program SPN into sysmoUSIM-SJS1 SIM cards
Change-Id: Ia0f1a36ecb3898eaa1cf9925864e13369b1f31ce
2020-01-21 11:31:56 +01:00
Supreeth Herle f829945117 Added feature to read Service Provider Name (SPN) from the SIM card
Change-Id: I8dc599a76c260ec2823ba5c9b22375b04a50daa8
2020-01-21 11:00:38 +01:00
Philipp Maier 0ad5bcfbc1 cards: Add support for sysmo-isim-sja2
The sysmo-isim-sja2 cards are not yet supported by pysim. Lets add
support for writing KI and OPC in ADF.USIM and ADF.ISIM as well as the
remaining common simcard parameters.

Related: SYS#4466
Change-Id: I23e2b46eac0e0dbc2b271983d448999f6a459ecf
2019-12-31 18:02:42 +01:00
Philipp Maier 07cd481954 Fixup: Fix automated tests
The Change I12e6b46787efb39c5745f4e7f3cdcca9209881b8 was not as
effective as expected. Diff is used wrongly so that no lines are
compared. Lets fix this

Change-Id: I1601d8a2b3e1c07fe1eba375ea8deae3d50bbef0
2019-12-31 18:02:42 +01:00