Commit Graph

81 Commits

Author SHA1 Message Date
Harald Welte d6e16decad libosmosim: Support Microsoft smart card discovery process
Our class/instruction tables (used mainly by simtrace cardem host
software) only contain support for those instructions permitted
in the related card specification.

Microsoft blindly tries CLA=0xCA with INS=0x00 which is not somethin
that the GSM SIM, ETSI UICC or 3GPP USIM specs specify, and which
hence results in log output like this:

DLINP DEBUG [0] <= osmo_st2_cardem_request_sw_tx(sw=6a88)
DLGLOBAL INFO => DATA: flags=0x01 (HDR ), 00 ca 7f 68 00
DLGLOBAL ERROR Unknown APDU case 0
DLGLOBAL FATAL Failed to recognize APDU, terminating

Let's adjust to microsoft and *always* support their instructions
no matter which osim_cla_ins_card_profile was used.

Special thanks to Eric Wild for pointing me to this unexpected
behaviour of PC/SC on modern Windows.

Change-Id: I424964c0afab643e6a5d7824d91c2c86b0d3f25b
Related: SYS#6617
2023-11-28 22:50:01 +01:00
Harald Welte 42602ec932 sim/class_tables: Prevent out-of-bounds access
The INS tables always must be declared with 256 elements, even
if they only use some of them.  We never know which random INS
code might be used to index them.

This was not discovered until now as the only known user of those
tables is always using the SIM/UICC/USIM table and not the plain
ISO7816 table.

Change-Id: I6739f469f6e84eed9aab403cc481ebff86df0181
2023-11-28 21:22:19 +00:00
Karsten Ohme 433218a6ef APDU parsing support for GlobalPlatform GET RESPONSE
This patch adds GET RESPONSE support for GlobalPlatform command. Android is using
this to get the response data on SGP.22 eUICCs.
simtrace2-cardem-pcsc is failing otherwise e.g. on an xingtera camera with Android.

Change-Id: I5ae3165f172f9c949550ee4a07fe70e91f1a037c
2023-09-24 17:48:13 +00:00
Pau Espin 5f15e4199c Bump version: 1.7.0.119-b31a-dirty → 1.8.0
Change-Id: I5e953cedc041371a9c192f58348b673a787f542e
2023-02-07 11:20:42 +01:00
Pau Espin 88955fb550 Fix all references to config.h
config.h is created in $(top_buildir)/config.h.
Let's make sure all CPPFLAGS add correct -Ipath includes,
and that all code includes the correct file.

Change-Id: Ie9ea38bb009bc715b01cde4d66d181f7bec2e7bd
2023-01-18 19:04:36 +01:00
Pau Espin a50ed5fda8 Makefile.am: Remove unexsiting all_includes variable
Change-Id: I9bc7de6f85558e55265c6cc965bc7fe97a6736ee
2023-01-18 19:04:36 +01:00
Pau Espin d4c3dc8d59 Move src/*.{c,h} to src/core/
This way we have all libosmocore.so in an own subdir instead of having
lots of files in the parent dir, which also contains subdirs to other
libraries.
This also matches the schema under include/osmocom/.

Change-Id: I6c76fafebdd5e961aed88bbecd2c16bc69d580e2
2023-01-18 17:14:06 +01:00
Vadim Yanitskiy dd20f7c3c3 {gb,sim,usb}: ensure -no-undefined is present in *_la_LDFLAGS
Make sure that there is no undefined references in shared libraries.

Inspired by GitHub PR#6 [1] by Michael Dickens.  Tweaked by me.

Change-Id: I7ddd6c75935b0f25d78a948f1577656d77a204e3
Related: [1] https://github.com/osmocom/libosmocore/pull/6
2022-08-05 11:48:38 +00:00
Harald Welte d6a49ce9ad sim/class_tables: Add GET IDENTITY, SUSPEND UICC, EXCHANGE CAPABILITIES
This brings the tables up-to-date with Release 16 of both
ETSI 102 221 + 3GPP TS 31.102 specifications.

Change-Id: I7100f326f45f1f8742363eace0531a4ef3f049c0
2022-07-20 18:33:07 +02:00
Pau Espin a1584d237b Bump version: 1.6.0.132-0239-dirty → 1.7.0
Change-Id: Idb0d20aa4336a69cb100e140fb1fa9e7ac25b984
2022-06-28 17:00:51 +02:00
Karsten Ohme 6772dd7c01 APDU parsing support for GlobalPlatform
This patch addes support for GlobalPlatform command. Android is using
STORE DATA commands on a logical channel.
simtrace2-cardem-pcsc is failing otherwise e.g. on an Pixel 4 with Android 12.

Change-Id: Ib734fc852e7b63b9efdc414adccbd796a572eb55
2022-06-13 19:09:04 +00:00
Philipp Maier 9802c14489 reader: more meaningful null pointer check in get_sw
At the moment msgb_apdu_de(resp) is used to check if the msgb that is
handed over to get_sw is properly populated with data.

However, since msgb_apdu_de() is just adding an offset, which cannot be
0 to ->l2h the returned value also can never be NULL. This means that we
cannot use msgb_apdu_de() to detect if resp contains a nullpointer.

Lets check if ->l2h is not NULL instead. This will make sure that ->l2h
is populated.

Change-Id: I32bc56c9264c01911a4f4b4f911b09e955205010
Related: OS#5560
2022-05-24 17:59:40 +02:00
Oliver Smith 04bfb7165b treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I5050285e75cf120407a1d883e99b3c4bcae8ffd7
2021-12-14 12:44:03 +01:00
Pau Espin c7deaf28aa Bump version: 1.5.1.282-ab5e-dirty → 1.6.0
Change-Id: Ia3ac0a36b9e898996f596c6d2787e03cd59bfc11
2021-11-16 13:08:23 +01:00
Harald Welte 20199da02d sim: Add osim_card_{reset,close}() API
This is required to reset and close a card under software control
after opening it with osim_card_open()

Change-Id: Ie9ec66db4d54fdb1331f4ae05ca3ca4274912e9d
2021-06-01 20:29:17 +02:00
Harald Welte a912d192f1 sim: Remove 'printf' from library code
Those were really meant as an early debugging aid and should not
have survived this long.

Change-Id: I4e9a80ced15686734d4485c232c5936f566cfd76
2021-04-25 21:09:23 +02:00
Harald Welte 22117a7164 sim: Obtain card ATR when opening the card
Change-Id: I42e387535c40f371b06f384af0ca5dc1e42ed00e
2021-04-25 21:09:23 +02:00
Pau Espin Pedrol f286fdc87e Bump version: 1.4.0.535-e387-dirty → 1.5.0
Change-Id: I3bc0826c0000be4d76235ed6b5be86d216ea2e4d
2021-02-23 14:03:31 +01:00
Harald Welte 702c998391 card_fs_usim: Add definitions of DF.ProSe and DF.ACDC
those are the only two sub-directories of Release 15 we didn't cover
yet.

Change-Id: I1f85430cbb0041766b0725df9fa97c5a82e4f38d
2020-11-17 09:56:01 +00:00
Harald Welte f396b96e66 card_fs_usim.c: Add support for DF.5GS directory
card_fs_usim already contained definitions up to Rel-15, but somehow
didn't add the DF.5GS yet.

Change-Id: I9f8102dc7e5a865193ff9930dfc48c5f2e6ecbcf
2020-11-10 15:33:49 +00:00
Harald Welte 5c5713e869 Bump version: 1.3.0.173-51974 → 1.4.0
Change-Id: I4fc6dd4f727c8ff5a64865bbb87e1d9feb7c5174
2020-08-13 11:06:36 +02:00
Harald Welte 3a6bedf1e5 sim: When decoding SW, take application specific SW into account
So far we only looked at SW definitions of the card profile. However,
if we have a currently selected application, we also must check
that application for SW definitions.

This breaks ABI and API all over the place, but as there are no
known users beyond osmo-sim-test, this is acceptable.

Change-Id: I3a1d60898529c173f73587e34c155660ba5f5fb1
2020-05-05 19:41:12 +00:00
Harald Welte 2954aa9b8a sim: Add HPSIM application support
Change-Id: I883faae5e170803b8301d10c8b9fad7892da009c
2020-03-21 16:31:17 +01:00
Harald Welte e92f3628a8 card_fs_{usim,isim}: Update to 15.7.0 / Release 15
Various new files and some new status words have been defined
by now. Let's add them.

Change-Id: Ia007281bcb61dcd8260d0a77203abeff21d5255f
2020-03-21 16:31:17 +01:00
Harald Welte 58d173ade1 osmo-sim-test: Also [attempt to] dump DF.GSM on USIM cards
an USIM application can very well exist on a UICC without supporting
classic DF.GSM access.  However, most commonly, both are found on
cards.

Change-Id: I6180a3f81a7d3006e8ece4302c2433db2588bfaa
2020-03-21 16:31:17 +01:00
Harald Welte 429adecfd8 sim: re-structure how we support cards + applications
Before this change, a card application (USIM, ISIM, ...) didn't
exist as a separate concept from a card profile.  This meant,
we had a manual combination of UICC card profile with USIM application,
and another one of UICC card profile and ISIM application.  But what
if there's a combined USIM+ISIM?

In reality, applications exist as separate objects, on top of an
ETSI UICC.  Lets therefore register all known applications to the
osim library core, and add code to osmo-sim-test which dynamically
detects all applications present on a given card (by reading EF.DIR).

Change-Id: Ic4b4ac433a9976842b30a017fb0fc347d87201cd
2020-03-21 16:31:17 +01:00
Harald Welte bf90d747ad sim: add osim_file_desc_find_aid()
Change-Id: I80468c8c4f4590c262019f42285e8d8fd3444f7f
2020-03-21 16:31:17 +01:00
Harald Welte 2d284df17b card_fs_sim: Avoid '/' in file names
... as that doesn't work if we want to create a similarly-named
file in the local file system.

Change-Id: Ib8734e2e4b81c915ab0fbd0d9b6662275b1d33d1
2020-03-21 16:24:53 +01:00
Harald Welte b8c1da1762 sim: card_fs_usim.c: Fix FID of EF.EXT4
The 3GPP spec document also contains this error at one point, and
it seems I copied it from there :/

Change-Id: I7ad9f491c06f6540747b77017678ee37e6a1550d
2020-03-21 11:31:12 +01:00
Harald Welte 3c44a646bd libosmosim: Build irrespective of PC/SC support
libosmosim contains a variety of definitions and utility fuinctions
useful when working with SIM card [protocol].  They can not only
be used with PC/SC readers but also in other contexts.

Change-Id: I741940d3dc2a5653c760e9d1597d7f08afb3b631
2020-03-16 11:28:21 +01:00
Eric Wild 18caa87778 pcsc: don't leak memory
Change-Id: I183882ff2eae82754d55189b154863fad9cce4aa
2020-01-29 14:41:18 +01:00
Pau Espin 2862f9082e Bump version: 1.2.0.108-c6a8-dirty → 1.3.0
Change-Id: I5698bfe45467a8b0e44549105aaf27b8da500de8
2020-01-02 18:42:30 +01:00
Eric Wild 94cd4acef8 sim: allow opening reader# > 0
Change-Id: I4b1abc8d8aae4bd9a32f927269d7ebfef902d7c5
2019-12-09 12:54:43 +01:00
Harald Welte ca18c9df7d sim/class_tables: Fix typo in comment
Change-Id: I837c8303a7bb47b690cc8841cf5cafba8ac338af
2019-09-28 13:00:48 +02:00
Pau Espin 922d276035 Bump version: 1.1.0.107-afce-dirty → 1.2.0
Change-Id: I05dd1f2725e05f856f1d27c9201a0005de101b8f
2019-08-06 18:02:02 +02:00
Harald Welte 171ef826e1 make all library-internal static buffers thread-local
We have a number of library-internal static global buffers which are
mainly used for various stringification functions.  This worked as
all of the related Osmocom programs were strictly single-threaded.

Let's make those buffers at least thread-local.  This way every thread
gets their own set of buffers, and it's safe for multiple threads to
execute the same functions once.  They're of course still not
re-entrant.  If you need re-entrancy, you will need to use the _c()
or _buf() suffix version of those functions and work with your own
(stack or heap) buffers.

Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07
2019-06-04 10:47:30 +02:00
Pau Espin 1fcdd0d1b8 Bump version: 1.0.1.143-cc72c → 1.1.0
Change-Id: I351411ca5913c8b40f23287ec7c9ebfe11bd2bb0
2019-05-07 18:36:51 +02:00
Harald Welte 179f35702e Add _c versions of functions that otherwise return static buffers
We have a habit of returning static buffers from some functions,
particularly when generating some kind of string values.  This is
convenient in terms of memory management, but it comes at the expense
of not being thread-safe, and not allowing for two calls of the
related function within one printf() statement.

Let's introduce _c suffix versions of those functions where the
caller passes in a talloc context from which the output buffer shall
be allocated.

Change-Id: I8481c19b68ff67cfa22abb93c405ebcfcb0ab19b
2019-04-10 22:42:32 +00:00
Harald Welte 4a62eda225 Add _buf() functions to bypass static string buffers
We have a number of static buffers in use in libosmo*.  This means
the related functions are not usable in a thread-safe way.  While
we so far don't have many multi-threaded programs in the osmocom
universe, the static buffers also prevent us from calling the same
e.g. string-ify function twice within a single printf() call.

Let's make sure there's an alternative function in all those cases,
where the user can pass in a caller-allocated buffer + size, and make
the 'classic' function with the static buffer a wrapper around that
_buf() variant.

Change-Id: Ibf85f79e93244f53b2684ff6f1095c5b41203e05
2019-04-03 18:03:14 +02:00
Pau Espin 13154ffabd Bump version: 0.10.2.284-bc47-dirty → 0.11.0
Remark: For libosmogb and libosmogsm, LIBVERSION was
already bumped in c4fce1425e.

Change-Id: Ib4fa53a9bb9954ae48d0a610ba9a81dd8e8b4ef6
2018-05-03 15:47:11 +02:00
Thorsten Alteholz 5a9dbf81a2 fix spelling
fix for some spelling issues found by lintian

Signed-off-by: Thorsten Alteholz <osmocom@alteholz.de>
Change-Id: I69976ecae6939d9ff51bfe4ce7374890c6563b82
2018-04-08 19:13:25 +02:00
Neels Hofmeyr c4fce1425e implement support for 3-digit MNC with leading zeros
Enable representing three-digit MNC with leading zeros. The MNCs 23 and 023 are
actually different; so far we treated both as 23. Re-encode an incoming BCD or
string of 023 as it were, i.e. not dropping the leading zero as 23.

Break ABI compatibility by changing the size and ordering of structs
gprs_ra_id, osmo_plmn_id, osmo_cell_global_id, ... by adding an mnc_3_digits
flag.

Change ordering in gprs_ra_id because the canonical oder is {Mobile Country
Code, Mobile Network Code}, so have the mcc member first.

ABI compatibility cannot be maintained for struct gprs_ra_id, since it is a
direct member of structs bssgp_bvc_ctx and bssgp_paging_info, and even just
adding a flag to the end would cause ABI changes of those structs. Similarly,
osmo_plmn_id is a direct member of osmo_location_area_id, and so forth.

Add new API to set and read this additional flag to preserve leading zeros:
- osmo_plmn_to_bcd(), osmo_plmn_from_bcd() after
  gsm48_mcc_mnc_to_bcd() and gsm48_mcc_mnc_from_bcd().
- gsm48_decode_lai2(), gsm48_generate_lai2() after
  gsm48_decode_lai(), gsm48_generate_lai().
- gsm0808_create_layer3_2() after gsm0808_create_layer3() and gsm0808_create_layer3_aoip().
- various osmo_*_name() functions in gsm23003.h (osmo_rai_name() still in
  gsm48.h close to struct gprs_ra_id definition). The amount and duplication of
  these may seem a bit overboard, but IMO they do make sense in this way.
  Though most code will soon see patches unifying the data structures used, in
  some cases (vty, ctrl) they are required singled out. Without these
  functions, the formatting ("%0*u", mnc_3_digits ?  3 : 2, mnc) would be
  duplicated all over our diverse repositories.

In various log output, include the leading MNC zeros.

Mark one TODO in card_fs_sim.c, I am not sure how to communicate a leading zero
to/from a SIM card FS. The focus here is on the core network / BSS.

To indicate ABI incompatibility, bump libosmogsm and libosmogb LIBVERSIONs;
adjust debian files accordingly.

Implementation choices:

- The default behavior upon zero-initialization will be the mnc_3_digits flag
  set to false, which yields exactly the previous behavior.

- I decided against packing the mnc with the mnc_3_digits field into a
  sub-struct because it would immediately break all builds of dependent
  projects: it would require immediate merging of numerous patches in other
  repositories, and it would make compiling older code against a newer
  libosmocore unneccessarily hard.

Change-Id: Id2240f7f518494c9df6c8bda52c0d5092f90f221
2018-02-28 19:26:33 +01:00
Harald Welte e08da97570 Fix/Update copyright notices; Add SPDX annotation
Let's fix some erroneous/accidential references to wrong license,
update copyright information where applicable and introduce a
SPDX-License-Identifier to all files.

Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-11-13 01:35:12 +09:00
Max ba1059c173 Move additional libraries to appropriate place
According to
https://www.gnu.org/software/automake/manual/automake.html#Libtool-Flags
the libraries supposed to be added to *_LDADD or *_LIBADD
while *_LDFLAGS should contain additional libtool linking
flags. Previously we used both. Let's unify this and move all the
libraries into proper automake variable. While at it - also add
libosmocore.la for tests to LDADD since all the tests link against it
anyway.

Change-Id: Ia657a66db75df831421af5df1175a992da5ba80f
2017-10-30 13:50:31 +01:00
Harald Welte faee5dead6 Tag/Release version 0.10.0
It's been way too long since the last release.  Almost one year and
468 commits.

A brief summary of the changes below:

* Doxygen for libosmo{coding,gb}
* pseudotalloc for embedded builds, jenkins for arm-none-gnueabi
* --disable-doxygen, --disable-ctrl, --disable-simd
* update debian packaging
* gsm0503 coding routines
* osmo_hton[sl]
* statistics.h -> counter.h
* QCDIAG in gsmtap
* llist_{first,last}_entry()
* llist_count()
* LOGPSRC() macro
* msgb_pull_to_l2()
* msgb_printf()
* prbs
* osmo_sock_init2()
* osmo_sock_mcast_{name,loop_set,ttl_set,all_set,subscribe,ip}()
* OSMO_STRINGIFY()
* OSMO_VALUE_STRING()
* OSMO_BYTES_FOR_BITS()
* osmo_talloc_asprintf()
* osmo_sub_auth_type_name()
* osmo_sub_auth_data support for IND/SQN_MS
* osmo_fsm ctrl interface
* ctrl_handle_alloc2()
* ctrl_interface_setup_dynip2()
* OSMO_CTRL_PORT_HLR
* bssgp_tx_bvc_ptp_reset()
* gprs_ns_inst connect/remote_{ip,port}
* osmo_gprs_{ul,dl}_block_size_{bits,bytes}()
* osmo_gprs_{dl,ul}_cs_by_block_bytes()
* gprs_ns_pdu_strings[]
* more BSSGP cause values
* abis_nm_admin_name()
* AoIP support in gsm0808
* gsm_fn_as_gsmtime_str()
* osmo_dump_gsmtime()
* gsup charging support
* ipa_ccm_make_id_resp()
* ipa_ccm_make_id_resp_from_req()
* struct gsm48_gprs_susp_req
* gsm_04_14.h
* rsl measurement preprocessing related IEs
* abis_nm_event_cause_names[]
* abis_nm_sw_desc and friends
* more SYSINFO_TYPE_ values
* osmo_earfcn_bit_size_ext()
* t16lv_put()
* msgb_t16lv_put()
* tlvp_val16be()
* tlvp_val32be()
* osmo_tlvp_copy()
* osmo_tlvp_merge()
* many additional VTY nodes
* cmd_node.name member
* bitvec_set_u64()
* bitvec_rl_curbit
* ctrl_lookup_register()
* osmo_fsm_find_by_name()
* osmo_fsm_inst_find_by_name()
* osmo_fsm_inst_find_by_id()

Change-Id: Ieb5db2e910a90db780ea058b3280f2facbd68d76
2017-10-27 20:18:49 +02:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
Considering the various styles and implications found in the sources, edit
scores of files to follow the same API doc guidelines around the doxygen
grouping and the \file tag.

Many files now show a short description in the generated API doc that was so
far only available as C comment.

The guidelines and reasoning behind it is documented at
https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation

In some instances, remove file comments and add to the corresponding group
instead, to be shared among several files (e.g. bitvec).

Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23 00:18:23 +00:00
Neels Hofmeyr 87e4550585 doxygen: enable AUTOBRIEF, drop \brief
Especially for short descriptions, it is annoying to have to type \brief for
every single API doc.

Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes
the first sentence of an API doc as the brief description.

Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-06-23 00:18:22 +00:00
Pau Espin 92274453e7 card_fs_uicc.c: Fix unused compilation warning
This array of bytes is not yet used but is referring to some specs. They
may be used in the future, so leave it there but mark it explicitly as
unused.

Change-Id: I0a61d17f9989ecddafbc68d4b9446853e4c15159
2017-06-18 10:40:18 +02:00
Vadim Yanitskiy d1c7323f3c sim/core.c: drop useless double assignment
Change-Id: I3bfcabd80b57aeb7f110b306350802e6e82c847a
2017-06-13 20:21:58 +07:00
Holger Hans Peter Freyther 6030ce844e sim: Link to libtalloc as symbols of it are used here
A DSO should link to the libraries that it is using. Linking to
libtalloc will resolve these warnings:

Change-Id: I4c8d5e80e194b9d9b4fa2424c4a22377ecee9c7a
dpkg-shlibdeps: warning: symbol _talloc_zero used by debian/libosmosim0/usr/lib/i386-linux-gnu/libosmosim.so.0.0.0 found in none of the libraries
dpkg-shlibdeps: warning: symbol _talloc_free used by debian/libosmosim0/usr/lib/i386-linux-gnu/libosmosim.so.0.0.0 found in none of the libraries
dpkg-shlibdeps: warning: symbol talloc_strndup used by debian/libosmosim0/usr/lib/i386-linux-gnu/libosmosim.so.0.0.0 found in none of the libraries
dpkg-shlibdeps: warning: symbol talloc_strdup used by debian/libosmosim0/usr/lib/i386-linux-gnu/libosmosim.so.0.0.0 found in none of the libraries
dpkg-shlibdeps: warning: symbol _talloc_memdup used by debian/libosmosim0/usr/lib/i386-linux-gnu/libosmosim.so.0.0.0 found in none of the libraries
2017-01-24 14:26:11 +01:00