Commit Graph

117 Commits

Author SHA1 Message Date
Daniel Willmann c46a4eba43 pySim-prog: Use CSV format with headers
This way we can have optional fields like pin_adm in the file
Also require iccid as identifier for the SIM card
Set defaults for optional card parameters.

Change-Id: I0d317ea51d0cf582b82157eec6cdec074001a236
2019-09-03 20:11:48 +02:00
Daniel Willmann 7d38d74716 pySim-prog: Print out hex-escaped pin_adm in card parameters
Use h2b to convert pin_adm back to binary form for sysmoSIMgr2

Change-Id: Ia178c9938f3e6a4fbac24d767437894297d1e708
2019-09-03 18:41:05 +02:00
Philipp Maier 9f9c60937e pysim-testdate: Add test data for Wavemobile-sim
Change-Id: Id2baedf5ac6396a643f36444e8f570ad9c41fafb
2019-09-02 14:42:43 +02:00
Harald Welte 23888dab85 make writing SMSP optional
Change-Id: Ic5fdd397244cfe73b5b6a12883316072cc10f7b4
2019-08-28 23:20:02 +02:00
Daniel Willmann 67acdbc817 Make programming OPC optional
Change-Id: Ic600c325557918cb7d5b1fb179c01936a078c96c
2019-08-28 23:19:57 +02:00
Vadim Yanitskiy 35a96edb0d pySim-*.py: print info about selected reader interface
Change-Id: Idd791d7ef635e15915aab13274aefc15e70777b0
2019-05-10 22:24:21 +07:00
Max 5491c48e71 Don't try to parse result if select_file() failed
Change-Id: I25b859374e33654e58d07061926bf8529eab87f3
2019-05-10 17:03:58 +02:00
Max 89cfded971 Use reference array for reading ICCID
Change-Id: Iad0a328c6f0c9a4ab678efe068801849be48d8fc
2019-05-10 17:03:58 +02:00
Daniel Laszlo Sitzer 851e9c0f4c utils: add EF [H|O]PLMNwAcT decoding.
Allow decoding and pretty printing of PLMNwAcT, HPLMNwAcT and OPLMNwAct.

Includes unit tests for the added functions.

Change-Id: I9b8ca6ffd98f665690b84239d9a228e2c72c6ff9
2019-05-10 17:03:58 +02:00
Harald Welte 91d4ec7e7b import pysim-testdata of automatic testing to this repository
This test data is used by the jenkins build verification for pySim,
and it was previously located locally on the build slave.

By moving the testdata to this repository, any contributor can
modify both the code and the expected test results simultaneously.

Change-Id: I6714b091a114035d6aab8ba750c5f2b86e438467
2019-05-10 17:03:58 +02:00
Philipp Maier 6e507a7786 wavemobile-sim: write mnc-length field ine EF.AD
The length field in wavemobile sim cards is not set, so that the field
stays at its initial value, which is 0xFF. Lets write the correct mnc
length here.

Change-Id: Ieda0ce864bf3e8c7b92f062eaa3a5482c98507e2
Related: OS#3850
2019-04-01 16:33:48 +02:00
Philipp Maier 45daa925bd cosmetic: fix sourecode formatting
Change-Id: I4836826811ffb0aeb103d32eb874f5fa52af4186
2019-04-01 15:50:50 +02:00
Philipp Maier ee908ae195 sysmo-usim-sjs1: update EF.AD with correct MNC length
At the moment EF.AD, which contains the length of the MNC is not
updated. For two digit MNC (the usual case) this is fine since the
length is set to 2 by default. However, when one wants to set an MNC
with 3 digit length the file must be updated, otherwise the third digit
of the MNC is recognized as part of the MSIN.

Change-Id: I827092b2c7f7952f54b2d9f8dbda419a0dbfaf65
Related: OS#3850
2019-04-01 15:50:50 +02:00
Philipp Maier 2d15ea015e cards: sysmo-usim-sjs1: add programming of EF.PLMNsel, EF.PLMNwAcT and EF.OPLMNwAcT
The files EF.PLMNsel, EF.PLMNwAcT and EF.OPLMNwAcT are currently not
programmed for sysmo-usim-sjs1, lets add them.

Change-Id: I0cac3041f1902383d98d6dc211cf31ae6e3a610b
Related: OS#3850
2019-03-21 18:04:26 +01:00
Philipp Maier 91f26d7f0a commands: correct case of a TLV tag (A5 => a5)
The hexadecimal tag defintions of pytlv are case sensitive strings. So
'A5' is something different than 'a5'. Pytlv uses lower case letters for
the upper hexadecimal digits. Lets correct this.

Change-Id: I41a9933707783f6b1b68ebd91a365405ac0892d0
Related: OS#3850
2019-03-21 17:24:18 +01:00
Vadim Yanitskiy 9f9f5a6157 pySim-*.py: add command line option for Calypso reader
Change-Id: Ia895ced62d29e06ae8af05cd95c9d181fb53b9df
2018-10-29 02:45:54 +07:00
Vadim Yanitskiy 588f3aca3c pySim-*.py: refactor card reader driver initialization
This would facilitate adding new card reader drivers.

Change-Id: Ia893537786c95a6aab3a51fb1ba7169023d5ef97
2018-10-29 01:58:18 +07:00
Vadim Yanitskiy 1381ff15af pySim/transport: introduce Calypso based reader interface
This interface allows to use a Calypso based phone (e.g. Motorola
C1XX) as a SIM card reader. It basically implements a few L1CTL
messages that are used to interact with the SIM card through
the OsmocomBB 'layer1' firmware.

Please note, that this is an experimental implementation, and
there is a risk that SIM programming would fail. Nevertheless,
I've managed to program and read one of my SIMs a few times.

Change-Id: Iec8101140581bf9e2cf7cf3a0b54bdf1875fc51b
2018-10-29 01:58:11 +07:00
Daniel Willmann 4fa8f1c49b pySim-prog: Honor international '+' in SMSC number
The smsc no. programmed by pySim-prog would always be a national number
in the past. Check whether the first 'digit' is a + and indicate that it
is an international number.

Change-Id: Ia79913f5b0307e9786a5acea75c0811927be2eef
2018-10-05 13:19:17 +02:00
Ben Fox-Moore 0ec147513c utils: fix encoding/decoding of IMSI value
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
2018-09-26 18:14:19 +02:00
Philipp Maier c555e18ebb tests: add example test data for Wavemobile-SIM
Change-Id: If69cd2d8af6d544155b3088f77eb6ea4b789901d
Related: SYS#4245
2018-09-13 09:43:26 +02:00
Philipp Maier c8ce82a11f cards: Add support for Wavemobile SIM
Add support to handle Wavemobile sim cards. The support excludes some
parameters. For example it is not possible to write own KI keys yet.

Support covers the following files:
EF.SMSP
EF.IMSI
EF.ACC
EF.PLMNsel
EF.PLMNwAcT
EF.OPLMNwAcT

Not yet supported are:
EF.ICCID
KI (propretary file)
OPc (propritary file)

Change-Id: Ida3f37bd6e3ac995812aeddc9770f1ccd54ecf3f
Related: SYS#4245
2018-09-13 07:18:33 +00:00
Philipp Maier 11a2e3ca10 tests: add example file for sysmosim-gr1
Change-Id: I36cfa81f9029bfaedd2e802a2d709596dbeb20ab
Related: OS#3405
2018-08-23 10:44:51 +02:00
Philipp Maier a3de5a331e cards: do not feed ascii as adm for sysmosim-gr1
When sysmosom-gr1 is used with a custom ADM key, then the ADM string is
not fed through h2b() like we see it with sysmo-usim-sjs1 for example.

- feed the ADM to h2b() before use

Change-Id: I0b7cab380b89612ed3b8318e014161038335fe1b
Related: OS#3405
2018-08-23 10:44:33 +02:00
Philipp Maier 087feff7cb cards: autodetect sysmosim-gr1
The sysmosim-gr1 lacks the auto detection feature because no autodetect
is yet programmed inside the related class.

- add autodetect for sysmosim-gr1

Change-Id: Iec1f1ab6824ff2328baedd731b08df997df4da01
Related: OS#3405
2018-08-23 10:43:57 +02:00
Neels Hofmeyr 52f59aca78 readme: add 'serial' dep, cosmetically rearrange
Change-Id: I414b897ba4911b7428ddf807cb04a93700ee0193
2018-08-20 21:54:34 +02:00
Philipp Maier fb98dd6d6e commands: depend on pytlv only when it is actually needed
Some of the USIM-Card programming implementations do not need to look
at card responses, which means they also do not have to parse TLV
data. Lets depend on pytlv only in cases where TLV data has to be
parsed so that useser of cards that do not need at can go without
installing pytlv.

Change-Id: Ida841d74d9581e7f395751b0f74556a06a038de6
2018-07-25 18:52:58 +00:00
Philipp Maier 53b6dc216f readme: add info about dependencies
So far, the README.md file does not mention much about the
dependencies. This commt adds at lest the most important ones

Change-Id: I912bbf787e1408100183cade2113bf7617b86ffa
2018-07-25 18:52:58 +00:00
Alexander Couzens 73a0f047a1 add .gitreview
git review uses this file to build the git url.

Change-Id: Ia35aeb33d43ace3c71689d5acbb8d1259ccb7b42
2018-07-19 23:51:00 +02:00
Alexander Couzens 4731232aae contrib: add jenkins.sh
Run the tests.

Change-Id: I9308f097bf77d82e5ef78d1be551baf127726f74
2018-07-19 23:46:38 +02:00
Philipp Maier 7f340851fc tests: add test program to verify pysim-prog.py (and pysim-read.py)
Pysim now supports quite a number of different cards. Estimating
if changes in pysim introce regressions becomes increasingly difficult

The script that is added with this patch is intended to run as
atomated testsuit on real cards attached to a test system. However,
it can also be used by developers locally to check for regressions.

Change-Id: I8c6f95998272333bc757b34e3ab6be004e8cd674
Related: OS#3376
2018-07-19 07:55:42 +00:00
Philipp Maier af9ae8bd6e cards: return SW in method update_plmnsel() of class Card
The method update_plmnsel() does not return the status word yet, which
causes pysim-prog.py to print an error message that does not influence
the functionality but does not look nice.

- preserve the status word that is returned with update_binary() and
  return it properly like the other methods do.

Change-Id: I54e8e165f87365e8162b36d24efc8f0db62b66da
Related: SYS#4245
2018-07-13 11:38:04 +02:00
Philipp Maier 1be35bfa09 cosmetic: fix cut and paste error in comment
Change-Id: I506585f8b300bb7a3e20edad7eca134374581d76
2018-07-13 11:36:26 +02:00
Philipp Maier a2650496ce pySim-read: read contents of PLMN related files.
The files EF.PLMNsel, EF.PLMNwAcT, EF.OPLMNwAcT, EF.HPLMNAcT are not
yet printed by pysim-read. Lets add support for those files.

Change-Id: Ice802033adfa6fc1bccc76da47495eb29c3aef6c
Related: SYS#4245
2018-07-13 08:57:20 +00:00
Philipp Maier ea6bdf0b99 pySim-read: Print exception when reading of EF.MSISDN fails
At the moment the exception is catched, but there is only a vague
error message printed. However, the exception string usually tells
us the status word, so it is very valuable to see it. Lets make
sure that the exception string is printed here.

Change-Id: Icb30470b1c0eee6a15fc028da820e92bf9ded27a
2018-07-13 08:56:58 +00:00
Philipp Maier 589c1a4ff5 cosmetic: fix excess space in log output (typo)
There shouldn't be a space between the end of a sentence and a
punctuation mark.

Change-Id: I33f9b8c803ccd185ffa370d235363423d82ba9c7
2018-07-13 08:50:33 +00:00
Philipp Maier 5bf42600d4 cards: add update method for EF:PLMNsel to Card class
The Card class offers update methods for various EF, but for
PLMNsel there is no update method available yet. Lets add one.

Change-Id: I832f7bef70c92dc101b94ad871b6cafaa626e134
Related: SYS#4245
2018-07-11 23:25:58 +02:00
Philipp Maier ac9dde683f pysim-prog: add commandline option to probe cards
In some situations it may be helpful to know the card name (type)
we deal with in advance. So lets ad an to probe that only detects
the card and then exists.

- Add commandline option -T --probe

Change-Id: I57422d3819d52fd215ac8f13f890729aad2af76f
Related: OS#3376
2018-07-04 11:54:01 +00:00
Philipp Maier 0e3fcaa1bb commands: get file/record length from FCP (USIM)
Some of the methods SimCardCommands() have ways to determaine length
information from the card response. Regular sims use a format where
the length field is on a fixed position. USIMs use FCP templates
(format control parameters), which is a TLV encodecs string. So lets
distingish if we deal with an USIM (We can easily do this by looking
at the select control parameters) and extract the length info from
the FCP.

- If we deal with USIMs, use the FCP to determine length
  information

Change-Id: I068cf8a532e1c79a2d208e9d275c155ddb72713c
Related: SYS#4245
2018-07-03 15:17:16 +02:00
Philipp Maier 859e0fd1ce __init__: also fetch response bytes for USIMs automatically
The method send_apdu() first transmits the APDU in the cards direction.
The card may indicate that there is a response available by responding
with SW1=9F, where SW2 is the number of bytes. send_apdu() will then
craft a get-response APDU to pickup the response bytes. This mechanism
works fine for SIM, but USIM uses SW1=61 to indicate the availability
of a response, so lets also sense on SW1=61 to support USIMs as well.

- Also check on SW1=61 to see if a response is available

Change-Id: Ied7fb78873a7c4109de471c7a5e9c3701ba0c7d5
Related: SYS#4245
2018-07-03 13:17:04 +00:00
Philipp Maier f779231da2 csv: fix missing import (broken CSV support)
with Change I38f5d36d16b41b5d516a6a3e2ec1d09637883932, new constants
for file identifiers were introduced. When csv file input is used,
then pySim-prog.py uses one of these constans without importing
it from ts_51_011.py

- Add missing import

Change-Id: Ic5b067b16ec204c2ba2264b1ffb48d37be8d5eb3
2018-07-03 12:53:37 +00:00
Philipp Maier d4ebb6fdf4 __init__: allow wildcards in expected SW for send_apdu_checksw()
The method send_apdu_checksw() is used to check the SW of the final
response against some pre defined value. However, in many cases the
last two digits of the SW are used to return varying information
(e.g. length information or a more specific status info). To cover
those cases it would be helfpul to define status words that contain
wildcards (e.g. 61**) in order to be able to accept all SWs from
6100 to 61ff.

- When the user supplies an expected SW with wildcards, mask out
  those digits in the response before comparing

Change-Id: I5bfc0522b4228b5d9b3415f6e708abcf0da0a7b7
2018-06-18 09:43:56 +00:00
Philipp Maier d9824887c9 pysim-prog: also allow raw hex adm pins besides numeric ascii
At the momemnt pysim takes the supplied ADM pin number and interprets
it as ascii string. This ascii string (max 8 digitis) is then padded
with 0xff bytes if necessary and sent to the card.

This limits the range of possible ADM keys and it is not possible
to deal with situataions where the ADM pin consists of arbitrary
bytes. At the momemnt pysim-prog forbis anything that is longer
than 8 digits. Lets also check if there are 16 digits and if yes
interpret them as raw bytes.

- when the adm pin is 16 digits long, interpret the string as raw
  bytes (hex).

Change-Id: If0ac0d328c64b57bc4d45d985a4a516930053344
Related: SYS#4245
2018-06-13 09:30:53 +02:00
Todd Neal 9eeadfc46b add support for open cells SIM cards
Change-Id: I4df5681952eefd7a67f5e2b0a96a9e01c9d960d2
2018-04-26 11:11:45 -05:00
Martin Hauke 6cbecaaf5c transport/serial: Fix serial transport
Fix a typo that broke the serial transport.

Change-Id: I7fcc97d505a5369f9f14d4a2abda92b7114a58cd
2018-02-18 17:04:50 +01:00
Harald Welte d9d2b941eb Revert "pySim-prog: ADM code can be longer 8 digits, it's implementation specific."
This reverts commit a51592e180, which
broke the use of ADM pins on sysmoUSIM-SJS1 (and possibly others?)

The ADM pins have so far always been specified as ASCII decimal digits,
i.e. something like "-a 53204025" gets translated to hex "3533323034303235"

After the above patch this is broken and gets instead translated to
"53204025ffffffff" in hex which obviously breaks.  Let's revert back to
the old behavior to make it work again.

Change-Id: I3d68b7e09938a2fcb7a9a6a31048388cc3141f79
2018-01-23 16:25:55 +01:00
Alexander Chemeris 19fffa1db7 Make derive_milenage_opc and calculate_luhn publicly available through utils.py
Change-Id: I2effc85fd55da0981de0ada74dcb28b7e8e56a01
2018-01-11 13:06:43 +09:00
Alexander Chemeris e0d9d88cd5 cards: Add Fairwaves SIM implementation.
Change-Id: Ia10ac433d3b0482bdf727c31f65a10042152797b
2018-01-10 17:16:31 +09:00
Alexander Chemeris 8ad124a0b8 cards: Implement card type autodetection based on ATR.
Change-Id: I1099a96626c0ce74243b47a8fdfa25b0d76a1ef3
2018-01-10 17:12:10 +09:00
Alexander Chemeris 47c73abd04 pySim-prog: Replace magic numbers with a readable EF file name.
Change-Id: Ibda7d5a4132971e884f6d760baf20cd33025a2af
2018-01-10 17:12:10 +09:00