libosmocore/src/gsm
Neels Hofmeyr d1ceca9d48 add osmo_mobile_identity API
Implement better API around 3GPP TS 24.008 Mobile Identity coding.

struct osmo_mobile_identity is a decoded representation of the raw Mobile
Identity, with a string representation as well as dedicated raw uint32_t TMSI.
The aim is to remove all uncertainty about decoded buffer sizes / data types.

I have patches ready for all osmo programs, completely replacing the Mobile
Identity coding with this new API. Hence deprecate the old MI API.

New API functions provide properly size-checking implementations of:
- decoding a raw MI from a bunch of MI octets;
- locating and decoding MI from a full 3GPP TS 24.008 Complete Layer 3 msgb;
- encoding to a buffer;
- encoding to the end of a msgb.

Other than the old gsm48_generate_mid(), omit a TLV tag and length from
encoding. Many callers manually stripped the tag and value after calling
gsm48_generate_mid(). The aim is to leave writing a TL to the caller entirely,
especially since some callers need to use a TvL, i.e. support a variable-size
length of 8 or 16 bit.

New validity checks so far not implemented anywhere else:
- stricter validation of number of digits of IMSI, IMEI, IMEI-SV MI.
- stricter on filler nibbles to be 0xf.

Rationale:

While implementing osmo-bsc's MSC pooling feature in osmo-bsc, this API will be
used to reduce the number of times a Mobile Identity is extracted from a raw
RSL message.

Extracting the Mobile Identity from messages has numerous duplicate
implementations across our code with various levels of specialization.
https://xkcd.com/927/

To name a few:
- libosmocore: gsm48_mi_to_string(), osmo_mi_name_buf()
- osmo-bsc: extract_sub()
- osmo-msc: mm_rx_loc_upd_req(), cm_serv_reuse_conn(), gsm48_rx_mm_serv_req(),
  vlr_proc_acc_req()

We have existing functions to produce a human readable string from a Mobile
Identity, more or less awkward:
- gsm48_mi_to_string() decodes a TMSI as a decimal number. These days we use
  hexadecimal TMSI everywhere.
- osmo_mi_name_buf() decodes the BCD digits from a raw MI every time, so we'd
  need to pass around the raw message bytes. Also, osmo_mi_name_buf() has the
  wrong signature, it should return a length like snprintf().
- osmo-bsc's extract_sub() first uses gsm48_mi_to_string() which encodes the
  raw uint32_t TMSI to a string, and then calls strtoul() via
  tmsi_from_string() to code those back to a raw uint32_t.

Each of the above implementations employ their own size overflow checks, each
invoke osmo_bcd2str() and implement their own TMSI osmo_load32be() handling.
Too much code dup, let's hope that each and every one is correct.

In osmo-bsc, I am now implementing MSC pooling, and need to extract NRI bits
from a TMSI Mobile Identity. Since none of the above functions are general
enough to be re-used, I found myself again copy-pasting Mobile Identity code:
locating the MI in a 24.008 message with proper size checks, decoding MI
octets.

This time I would like it to become a generally re-usable API.

Change-Id: Ic3f969e739654c1e8c387aedeeba5cce07fe2307
2020-06-12 16:35:26 +02:00
..
milenage add osmo_auth_c3() (separate from gsm_milenage()) 2017-12-18 23:05:24 +00:00
Makefile.am add gsm23236: MSC pooling: TMSI and NRI utility functions 2020-06-10 14:20:49 +02:00
a5.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
abis_nm.c make all library-internal static buffers thread-local 2019-06-04 10:47:30 +02:00
apn.c make all library-internal static buffers thread-local 2019-06-04 10:47:30 +02:00
auth_comp128v1.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
auth_comp128v23.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
auth_core.c Use define for key buffers 2018-12-20 09:51:02 +00:00
auth_milenage.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
auth_xor.c libosmogsm: add support for XOR authentication 2019-11-22 17:39:42 +00:00
bts_features.c Introduce BTS_FEAT_ETWS_PN for communicating ETWS PN capability 2019-09-05 11:16:56 +00:00
cbsp.c cbsp: Fix decoding of WRITE-REPLACE payload 2019-09-01 22:32:24 +02:00
comp128.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
comp128v23.c comp128v23 (minor): update original code site and author 2018-08-04 17:23:23 +02:00
gan.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
gea.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
gprs_cipher_core.c Fix embedded build 2017-12-04 09:40:32 +00:00
gprs_gea.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
gprs_rlc.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
gsm48.c add osmo_mobile_identity API 2020-06-12 16:35:26 +02:00
gsm48_arfcn_range_encode.c port arfcn range encode support from osmo-bsc 2019-01-12 09:51:05 +00:00
gsm48_ie.c gsm48_decode_bcd_number2: fix ENOSPC edge case 2019-06-07 11:01:51 +02:00
gsm48_rest_octets.c rest_octets: fix encoding of 3G Early Classmark Sending Restriction 2020-05-05 02:03:51 +07:00
gsm0341.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
gsm0411_smc.c SMS: Add value_string for TS 04.11 CP and RP state 2018-01-24 16:50:59 +01:00
gsm0411_smr.c SMS: Add value_string for TS 04.11 CP and RP state 2018-01-24 16:50:59 +01:00
gsm0411_utils.c libosmogsm: (re)introduce gsm48_push_l3hdr() 2018-08-05 23:21:43 +07:00
gsm0414.c doxygen: unify use of \file across the board 2017-06-23 00:18:23 +00:00
gsm0480.c 04.80: Deprecate gsm0480_create_ussd_resp() 2019-11-30 12:39:39 +00:00
gsm0502.c libosmogsm: add Doxygen docs for gsm0502_hop_seq_gen() 2020-05-15 17:56:41 +00:00
gsm0808.c add osmo_mobile_identity API 2020-06-12 16:35:26 +02:00
gsm0808_utils.c gsm0808_utils: Add gsm0808_get_cipher_reject_cause() back with a deprecation notice. 2020-05-14 09:02:39 +00:00
gsm23003.c fix isdigit taking unsigned as input 2019-06-13 13:49:30 +00:00
gsm23236.c add gsm23236: MSC pooling: TMSI and NRI utility functions 2020-06-10 14:20:49 +02:00
gsm29118.c add osmo_mobile_identity API 2020-06-12 16:35:26 +02:00
gsm29205.c LCLS: add string dump helpers 2019-02-26 09:16:38 +00:00
gsm48049.c gsm/gsm48049.c: fix use of GNU 'missing =' extension in designator 2020-01-21 18:34:04 +07:00
gsm_04_08_gprs.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
gsm_utils.c gsm: gsm_utils: Fix return type of API ms_class_gmsk_dbm() and add unit tests 2019-11-04 12:41:22 +01:00
gsup.c gsup: Introduce OSMO_GSUP_NUM_VECTORS_REQ_IE 2019-12-09 10:54:30 +00:00
gsup_sms.c GSUP/SMS: introduce MO-/MT-FORWARD-SM messages 2018-12-18 21:52:01 +07:00
i460_mux.c Implement ITU-T I.460 multiplex / demultiplex 2020-05-28 13:08:52 +00:00
ipa.c ipa: Fix ipa_ccm_id_resp_parse on big endian systems 2019-03-28 12:22:36 +00:00
kasumi.c gsm: kasumi: Fix dynamic-stack-buffer-overflow on out buffers not multiple of 64 bits 2018-05-17 12:13:04 +02:00
lapd_core.c lapd_core: Fix log line being about LAPD and not LAPDm 2020-06-08 21:16:54 +02:00
lapdm.c lapd/lapdm: print user-defined string name instead of (dl=%p) 2020-06-08 21:16:54 +02:00
libosmogsm.map add osmo_mobile_identity API 2020-06-12 16:35:26 +02:00
mncc.c mncc: properly export osmo_mncc_name() 2018-05-24 12:19:45 +02:00
oap.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
oap_client.c oap_client: Fix license: GPLv2+ instead of AGPLv3+ 2019-05-27 23:26:45 +02:00
rsl.c gsm_08_58: Add vendor-specific Message Type for ETWS Primary Warning 2019-09-05 11:16:56 +00:00
rxlev_stat.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
sysinfo.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
tlv_parser.c TLV: Add one-shot TLV encoder 2019-05-19 07:33:32 +00:00