<p>neels <strong>uploaded patch set #2</strong> to this change.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/18858">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">add osmo_mobile_identity API<br><br>Implement better API around 3GPP TS 24.008 Mobile Identity coding.<br><br>struct osmo_mobile_identity is a decoded representation of the raw Mobile<br>Identity, with a string representation as well as dedicated raw uint32_t TMSI.<br>The aim is to remove all uncertainty about decoded buffer sizes / data types.<br><br>I have patches ready for current osmo CNI programs, replacing the Mobile<br>Identity coding with this new API. Deprecate the old MI API.<br>osmo-bsc: I71c3b4c65dbfdfa51409e09d4868aea83225338a<br>osmo-msc: Ic3f969e739654c1e8c387aedeeba5cce07fe2307<br>osmo-sgsn: I4cacb10bac419633ca0c14f244f9903f7f517b49<br>Note that some GPRS and SGs related coding is done here in libosmocore and<br>hence currently remains using the old implementation (see previous version of<br>this patch: Ic3f969e739654c1e8c387aedeeba5cce07fe2307).<br><br>New API functions provide properly size-checking implementations of:<br>- decoding a raw MI from a bunch of MI octets;<br>- locating and decoding MI from a full 3GPP TS 24.008 Complete Layer 3 msgb;<br>- encoding to a buffer;<br>- encoding to the end of a msgb.<br><br>Other than the old gsm48_generate_mid(), omit a TLV tag and length from<br>encoding. Many callers manually stripped the tag and value after calling<br>gsm48_generate_mid(). The aim is to leave writing a TL to the caller entirely,<br>especially since some callers need to use a TvL, i.e. support a variable-size<br>length of 8 or 16 bit.<br><br>New validity checks so far not implemented anywhere else:<br>- stricter validation of number of digits of IMSI, IMEI, IMEI-SV MI.<br>- stricter on filler nibbles to be 0xf.<br>As a result, applications using osmo_mobile_identity will be stricter in<br>rejecting coding mistakes (some of which we currently have in our test suites,<br>and which we'll need to fix).<br><br>Rationale:<br><br>While implementing osmo-bsc's MSC pooling feature in osmo-bsc, this API will be<br>used to reduce the number of times a Mobile Identity is extracted from a raw<br>RSL message.<br><br>Extracting the Mobile Identity from messages has numerous duplicate<br>implementations across our code with various levels of specialization.<br>https://xkcd.com/927/<br><br>To name a few:<br>- libosmocore: gsm48_mi_to_string(), osmo_mi_name_buf()<br>- osmo-bsc: extract_sub()<br>- osmo-msc: mm_rx_loc_upd_req(), cm_serv_reuse_conn(), gsm48_rx_mm_serv_req(),<br>  vlr_proc_acc_req()<br><br>We have existing functions to produce a human readable string from a Mobile<br>Identity, more or less awkward:<br>- gsm48_mi_to_string() decodes a TMSI as a decimal number. These days we use<br>  hexadecimal TMSI everywhere.<br>- osmo_mi_name_buf() decodes the BCD digits from a raw MI every time, so we'd<br>  need to pass around the raw message bytes. Also, osmo_mi_name_buf() has the<br>  wrong signature, it should return a length like snprintf().<br>- osmo-bsc's extract_sub() first uses gsm48_mi_to_string() which encodes the<br>  raw uint32_t TMSI to a string, and then calls strtoul() via<br>  tmsi_from_string() to code those back to a raw uint32_t.<br><br>Each of the above implementations employ their own size overflow checks, each<br>invoke osmo_bcd2str() and implement their own TMSI osmo_load32be() handling.<br>Too much code dup, let's hope that each and every one is correct.<br><br>In osmo-bsc, I am now implementing MSC pooling, and need to extract NRI bits<br>from a TMSI Mobile Identity. Since none of the above functions are general<br>enough to be re-used, I found myself again copy-pasting Mobile Identity code:<br>locating the MI in a 24.008 message with proper size checks, decoding MI<br>octets.<br><br>This time I would like it to become a generally re-usable API.<br><br>This patch was first merged as Ic3f969e739654c1e8c387aedeeba5cce07fe2307 and<br>caused test fallout, because it re-implemented old API with the new stricter<br>decoding. In this patch version, old API remains 1:1 unchanged to avoid such<br>fallout. Applications will soon switch to the new osmo_mobile_identity API and<br>become stricter on MI coding when that happens, not implicitly by a new<br>libosmocore version.<br><br>Change-Id: If4f7be606e54cfa1c59084cf169785b1cbda5cf5<br>---<br>M include/osmocom/core/utils.h<br>M include/osmocom/gsm/gsm48.h<br>M src/gsm/gsm48.c<br>M src/gsm/libosmogsm.map<br>M src/utils.c<br>M tests/gsm0408/gsm0408_test.c<br>M tests/gsm0408/gsm0408_test.ok<br>M tests/utils/utils_test.c<br>M tests/utils/utils_test.ok<br>9 files changed, 1,011 insertions(+), 15 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/58/18858/2</pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/18858">change 18858</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/18858"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: If4f7be606e54cfa1c59084cf169785b1cbda5cf5 </div>
<div style="display:none"> Gerrit-Change-Number: 18858 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: neels <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-MessageType: newpatchset </div>