libosmocore/src
Neels Hofmeyr 83025bf1a6 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 current osmo CNI programs, replacing the Mobile
Identity coding with this new API. Deprecate the old MI API.
osmo-bsc: I71c3b4c65dbfdfa51409e09d4868aea83225338a
osmo-msc: Ic3f969e739654c1e8c387aedeeba5cce07fe2307
osmo-sgsn: I4cacb10bac419633ca0c14f244f9903f7f517b49
Note that some GPRS and SGs related coding is done here in libosmocore and
hence currently remains using the old implementation (see previous version of
this patch: Ic3f969e739654c1e8c387aedeeba5cce07fe2307).

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.
As a result, applications using osmo_mobile_identity will be stricter in
rejecting coding mistakes (some of which we currently have in our test suites,
and which we'll need to fix).

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.

This patch was first merged as Ic3f969e739654c1e8c387aedeeba5cce07fe2307 and
caused test fallout, because it re-implemented old API with the new stricter
decoding. In this patch version, old API remains 1:1 unchanged to avoid such
fallout. Applications will soon switch to the new osmo_mobile_identity API and
become stricter on MI coding when that happens, not implicitly by a new
libosmocore version.

Change-Id: If4f7be606e54cfa1c59084cf169785b1cbda5cf5
2020-06-16 15:17:48 +02:00
..
codec codec: Add functions for AMR s->d bits and d->s bits 2020-05-14 14:51:22 +02:00
coding gsm0505_amr_dtx: add missing value strings 2020-05-12 18:13:30 +00:00
ctrl Bump version: 1.1.0.107-afce-dirty → 1.2.0 2019-08-06 18:02:02 +02:00
gb Revert "add osmo_mobile_identity API" 2020-06-16 09:21:08 +02:00
gsm add osmo_mobile_identity API 2020-06-16 15:17:48 +02:00
pseudotalloc pseudotalloc: Simplistic wrapper of talloc_named() 2019-07-31 10:16:07 +02:00
sim sim: When decoding SW, take application specific SW into account 2020-05-05 19:41:12 +00:00
usb usb: Add osmo_libusb_find_open_claim() all-in-one API 2020-05-12 05:43:21 +00:00
vty enable vty xml dumping to stdout 2020-05-18 13:55:08 +02:00
Makefile.am add crcXXgen.c.tpl to EXTRA_DIST 2020-01-07 17:25:51 +01:00
application.c application.c: drop wrong \references of osmo_init_ignore_signals() 2019-04-25 02:23:52 +07:00
backtrace.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
bitcomp.c bitcomp.c: fix missing Doxygen group closing tag 2019-04-25 02:23:52 +07:00
bits.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
bitvec.c bitvec: avoid redundant zero-initialization in bitvec_alloc() 2020-02-19 18:33:39 +07:00
context.c context: Add support for [per-thread] global talloc contexts 2019-08-27 13:43:31 +02:00
conv.c conv: prevent theoretical NULL pointer dereference in osmo_conv_encode() 2020-02-09 04:27:47 +07:00
conv_acc.c conv_acc: Our code requires SSSE3, not just SSE3 2017-11-17 11:44:22 +01:00
conv_acc_generic.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
conv_acc_sse.c conv_acc: Our code requires SSSE3, not just SSE3 2017-11-17 11:44:22 +01:00
conv_acc_sse_avx.c conv_acc: Our code requires SSSE3, not just SSE3 2017-11-17 11:44:22 +01:00
conv_acc_sse_impl.h Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
counter.c counters: add osmo_counters_count() returns the amount of counters 2017-12-05 16:06:27 +01:00
crc16.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
crcXXgen.c.tpl Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
exec.c exec: osmo_system_nowait2: initalize *pw pointer with NULL 2020-05-12 11:03:51 +00:00
fsm.c fsm: refuse state chg and events after term 2019-10-29 17:28:30 +01:00
gsmtap_util.c gsmtap_makemsg_ex: NULL for unknown chan_type 2020-05-20 06:05:38 +00:00
isdnhdlc.c isdnhdlc: Port from kernel to userspace 2018-05-11 21:57:46 +02:00
logging.c logging: do not allow multiple calls of log_init() 2020-05-12 17:51:25 +02:00
logging_gsmtap.c logging_gsmtap.c: document all params of log_target_create_gsmtap() 2019-03-27 08:56:21 +01:00
logging_syslog.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
loggingrb.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
macaddr.c osmo_get_macaddr: Fix buffer read out of bounds 2018-04-18 08:57:56 +00:00
msgb.c make all library-internal static buffers thread-local 2019-06-04 10:47:30 +02:00
msgfile.c memleak: osmo_config_list_parse: getline() needs free also on error 2017-11-18 10:30:57 +00:00
panic.c osmo_panic(): Annotate as __attribute__ ((noreturn)) 2018-06-29 20:32:57 +02:00
plugin.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
prbs.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
prim.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
rate_ctr.c Revert "Print error message if application fails to call rate_ctr_init()" 2019-05-10 11:52:58 +02:00
rbtree.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
select.c Drop old BSC references in fd check configure option 2020-05-11 17:24:16 +00:00
sercomm.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
serial.c cosmetic: clarify c_iflag in osmo_serial_init() 2019-09-28 13:00:48 +02:00
signal.c Revert "signal.c: Make non-exported tall_sigh_ctx static" 2019-03-22 13:25:01 +01:00
sockaddr_str.c osmo_sockaddr_str: deprecate osmo_sockaddr_str_*_32n() 2019-11-24 19:59:35 +01:00
socket.c socket: Add osmo_sock_mcast_iface_set() to bind multicast to device 2020-03-10 19:08:51 +01:00
stat_item.c add osmo_stat_item_inc/osmo_stat_item_dec to set it relative 2019-05-07 13:20:57 +00:00
stats.c stats: Change timer to timerfd to make it a true interval timer. 2020-05-09 16:25:48 +03:00
stats_statsd.c statsd: fix rendering for groups with idx==0 2020-05-10 00:32:44 +03:00
strrb.c Fix/Update copyright notices; Add SPDX annotation 2017-11-13 01:35:12 +09:00
tdef.c tdef: Return correct snprintf value for osmo_tdef_range_str_buf() 2019-10-18 09:20:58 +00:00
timer.c timer.c: make timers thread safe 2020-04-19 02:21:05 +02:00
timer_clockgettime.c Fix embedded (arm-none-eabi) builds 2018-06-28 10:30:34 +02:00
timer_gettimeofday.c timer: Document osmo_gettimeofday API 2018-03-01 12:33:03 +00:00
use_count.c add osmo_use_count API 2019-04-08 13:47:17 +00:00
utils.c add osmo_mobile_identity API 2020-06-16 15:17:48 +02:00
write_queue.c select: Rename BSC_FD_* constants to OSMO_FD_* 2019-03-21 16:02:01 +00:00