aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)AuthorFilesLines
2020-09-15HACK: support for SIM factory file formatssysmocom/factoryHarald Welte5-0/+367
Change-Id: I23cd37fc06b6e2d21964fd4f2694d9ee3c6012d4
2020-08-31fix 'TabError: inconsistent use of tabs and spaces in indentation'Harald Welte1-3/+3
those errors appear with python 3.8.5 otherwise Change-Id: I5e8a41a8aa9abdd0162c4635ccf9bfe736cca27e
2020-08-28Add support for ADF_USIM/EF_EHPLMNHarald Welte5-4/+83
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
2020-06-23utils.py: Add helper method to encode ePDG IdentifierSupreeth Herle1-0/+18
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
2020-06-23pySim-read.py: Enable parsing of Home ePDG Identifier in USIMSupreeth Herle5-1/+18
As per TS 31.102, version 13.4.0 Release 13, this EF can found under ADF.USIM at File Id 6ff3. Also, if service n°106 and service n°107 are available, this file shall be present. Change-Id: I68114d328d1af5682a5bc1fa7642882e80b5de4d
2020-06-23utils.py: Handle parsing of ePDGId TLV with zero lengthSupreeth Herle1-0/+4
Change-Id: Ie05ae010948884765363bd9dbc2b0d764ff8d42a
2020-06-09utils.py add LOCI EFs decode functionsSebastian Viviani2-0/+36
The LOCI, PSLOCI and EPSLOCI contain some info, including the PLMN, added helper functions to decode it Change-Id: Ibb513ff7d1dc6d33b354ae26cbd9c390ea3c8efc
2020-06-03commands.py: fix read_binary for lengths > 256Sebastian Viviani1-2/+11
fixed commit with commented changes Change-Id: Ie9c61caa1412606254b44a3a24f26ad44950e73a
2020-06-03ts_31_102.py: add EF_ADF_mapSebastian Viviani4-5/+111
the EF files in the USIM ADF are different to the ones int the GSM dir so added the dictionary to avoid conflicts and hardcoded values the 'DIR' one was added in ts_51_011.py, not sure if it should be there as it's not in that standard, but did it for simplicity Change-Id: I458380bf46b2986662ecdede2551c22cd9be92ba
2020-06-02Implement Generic SIM Access interface as per 3GPP TS 27.007Vadim Yanitskiy4-0/+146
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>
2020-05-28utils: fix list comprehension in h2s(): ignore upper case paddingVadim Yanitskiy1-1/+2
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>
2020-05-22cards: remove empty erase() methods.Philipp Maier1-20/+4
Some of the cards do not implement the erase method that each card should have. However, having an empty method in each of those classes does not make too much sense. Lets rather have an erase method in the superclass (Card) that prints a warning to inform the user that erasing the spcified card is not supported. Change-Id: If5add960ec0cab58a01d8f83e6af8cb86ec70a8d
2020-05-22cards: add methods to help erasing of file contentsPhilipp Maier1-0/+10
Resetting the contents of a file before re-writing it with parameters might be helpful when implementing the currently empty erase() methods of the various card implementations. Lets add two methods, one for resetting a binary file and one for resetting a specific record in a record oriented file Change-Id: I3c3a4ef3d3f358404af307a68a20b7059f1a9e8d
2020-05-22utils: do not crash when all bytes of EF.IMSI are 0xFFPhilipp Maier1-0/+2
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
2020-05-17commands: add features to verify data written to filesPhilipp Maier1-4/+20
When writing to files we often just write without making sure that the actual file contents actually written. Lets add features to do a read-after-write verification when writing to files. Change-Id: I7be842004102f4998af376790c97647c107be3d5
2020-05-17commands: add method to determine size of a non record oriented filePhilipp Maier1-0/+4
For record oriented files we have the methods record_size() and record_count() to determine the dimensions of a record oriented file, however, we miss a similar function for regular binary files. Lets add a method binary_size() to quickly determine the size of a non record oriented file Change-Id: I0593f2de7f34d5654a19e949dc567a236e44e20c
2020-05-17pysim-prog: move ADM sanitation to utils.pyPhilipp Maier2-21/+32
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
2020-05-17cards: reset uninitalized EF.ADPhilipp Maier1-2/+7
The contents of EF.AD me be uninitalized (all bytes set to 0xff). If this is the case reset all bytes of the file to 0x00 and continue the update of EF.AD with this value. Change-Id: I57cf53e0c540469f11b6d85bd3daf3f9e14c237e
2020-05-13Treat MCC and MNC as strings, not integersHarald Welte8-22/+33
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
2020-05-12pySim-prog, pySim-read, do not echo reader idPhilipp Maier10-47/+32
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
2020-05-12cards: remove len calculationPhilipp Maier1-1/+0
The method update_ad() caluclates the size of the data it had just read from EF.AD, but the result is never used, lets remove that line Change-Id: Id38c0dc725ab6874de3ea60132482a09372abe9e
2020-05-11Add option to specify MNC length in non-batch programming scneariosSupreeth Herle1-0/+5
Change-Id: Ied56a28d46a4c9c0c516d73fa257daeef7b50b61
2020-05-11utils.py: Add helper method to parse ePDG Identifier from hex stringSupreeth Herle1-0/+34
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
2020-05-11Introduce function for converting bytes list in (hex or int) to stringSupreeth Herle1-0/+4
This function is needed for conversion of bytes list output of TLV parser to representable string Change-Id: I8c1e39ccf9fb517d465e73f69c720e7fdde02ded
2020-05-11Import TLV parsing related function from https://github.com/mitshell/cardSupreeth Herle1-0/+39
The functions are imported from the git commit 2a81963790e27eb6b188359af169c45afb6d3aaf from master branch Change-Id: I5c7fdbd122e696d272f7480785d0c17ad2af138c
2020-05-09Fix writing of EF.HPLMNwAcT on sysmoISIM-SJA2Harald Welte2-10/+16
Change-Id: I9372a1a1f10fbe916659a8a50fe0e164987b2d5d Closes: OS#4532
2020-04-27Enable parsing of ISIM Service table (IST)Supreeth Herle2-0/+19
As per TS 31.103, This EF indicates which ISIM services are available. If a service is not indicated as available in the ISIM, the ME shall not select this service. Parsing of IST is achieved by first selecting the ISIM application using its AID. This is followed by selecting EF.IST with File ID - 6f07 in ADF.ISIM Change-Id: I3f0a7227360b72a707dc1bcc4cc9c8a4ec7ad2b2
2020-04-27Extend parsing and printing of Service table to ISIMSupreeth Herle1-1/+4
Change-Id: I7657432df76e9de5e4e5fdecfd717d8363de8270
2020-04-27Define mapping between ISIM Service Number and its descriptionSupreeth Herle1-0/+46
This commit introduces a lookup table which maps ISIM Service Number to its description. The mapping is defined in 3GPP TS 31.103 version 14.2.0 Release 14, 4.2.7 EF.IST (ISIM Service Table) Change-Id: Iad51d0804259df47729308b461062f794b135e66
2020-04-27Enable parsing of USIM Service table (UST)Supreeth Herle5-0/+166
As per TS.31.102, This EF indicates which USIM services are available. If a service is not indicated as available in the USIM, the ME shall not select this service. Parsing of UST is achieved by first selecting the USIM application using its AID. This is followed by selecting EF.UST with File ID - 6f38 in ADF.USIM Change-Id: I54dbbd40bd3d22cee81f7c32e58cd946f8564257
2020-04-27Remove redundant functionsSupreeth Herle2-30/+0
Change-Id: I2dfb5b662b8a4f351e4a629040b405c182e58e8d
2020-04-27Use helper method to print available service in EF.SSTSupreeth Herle7-243/+244
Change-Id: I375475e9f7210dae4e8da7258d6824dc2d54cf4c
2020-04-27utils.py: Add helper method to parse and print Service TableSupreeth Herle1-0/+31
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
2020-04-27pySim-read.py: Add ability to read Cards with correct CLA, P1 and P2 bytesSupreeth Herle1-1/+11
Initially the Card is read assuming a UICC SIM, but in case its not, an error 6e00 will be thrown indicating CLA not supported and Card has just Classic SIM application. Ref: https://web.archive.org/web/20090630004017/http://cheef.ru/docs/HowTo/APDU.info The above link provides the bytes to use for CLA, P1, P2 in APDU Change-Id: Ifea328eff3a381d7b82118e22d2bc0ec5f8a87e4
2020-04-16cards.py: Added method to select ADF by its full AIDSupreeth Herle2-0/+19
If AID of the desired ADF is in the list of AIDs of the Card/Card subclass object then ADF is selected or else None is returned Change-Id: Ie5f29eec14f099add1d0978e3e7d4ed3c9130854
2020-04-16Populate AIDs present on the UICCSupreeth Herle3-2/+7
Change-Id: I4d0d8f5f1e8cb252be55a2995b730927cfa7004d
2020-04-16Define mapping between USIM Service Number and its descriptionSupreeth Herle1-0/+138
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-16Add ability to parse SIM Service Table (EF.SST)Supreeth Herle8-2/+264
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-01utils.py: Add helper method to parse Service TableSupreeth Herle1-0/+22
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-01Define mapping between SIM Service Number and its descriptionSupreeth Herle1-0/+63
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-01Use the generic method read_binary of card class to read ADSupreeth Herle1-1/+1
Change-Id: Ie7f62913caed95f482445962954857bb69b58078
2020-04-01Move parsing of MSISDN to generic Card classSupreeth Herle2-6/+11
Change-Id: I5b726bc0dc8c8e5eb42f209b1fe0f35a46ac91be
2020-04-01Use the generic method read_binary of card class to read ACCSupreeth Herle1-1/+1
Change-Id: I92a02c74d64b3120055163548fc128ed6e0650a4
2020-04-01Move parsing of HPLMNAcT to generic Card classSupreeth Herle2-2/+9
Change-Id: I46c863c118dcbef89455c34289ed25e5a342f35b
2020-04-01Move parsing of OPLMNwAcT to generic Card classSupreeth Herle2-2/+9
Change-Id: I8050bd103a7085b2631ddc4e567d15e05f9428f2
2020-04-01Move parsing of PLMNwAcT to generic Card classSupreeth Herle2-2/+9
Change-Id: I14d7c2dc51fac6d5cf4a708a77ad23d252ba6094
2020-04-01Use the generic method read_binary of card class to read PLMNselSupreeth Herle1-1/+1
Change-Id: I0a683c479cd41ccc6a93c23434c73793cb5dc186
2020-04-01pySim-read.py: Use the method declared in cards.py to read SPNSupreeth Herle1-5/+4
Change-Id: I71c29e2d9d62c50d352556710e63ba398269a5c7
2020-04-01Use the generic method read_record of card class to read SMSPSupreeth Herle1-1/+1
Change-Id: I911c5339a739fbdd9d41e61b63f2410c8358815b
2020-04-01Use read_binary function of card class to read GID2 and reduce code duplicationSupreeth Herle2-8/+1
Change-Id: I5d80fcc1446a6691b8e2a09bcec558148fa31ab2