diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2020-08-21 16:21:23 +0200 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2020-08-24 01:12:16 +0000 |
commit | 59fc0bda6e85b6fee1038a83ddc3099d0bdcfbcb (patch) | |
tree | acd40021c1321219dc7cd293780bd0a52a14a63d /src/pdch.cpp | |
parent | 0052051c07af63da98137c9f8e3b3119642eb587 (diff) |
paging: pass struct osmo_mobile_identity, not encoded IE bytes
In get_paging_mi(), before this, an encoded buffer of Mobile Identity bytes is
returned. Code paths following this repeatedly decode the Mobile Identity
bytes, e.g. for logging. Also, in get_paging_mi(), since the TMSI is read in
from a different encoding than a typical Mobile Identity IE, the TMSI was
manually encoded into a typical Mobile Identity IE. This is essentially a code
dup of osmo_mobile_identity_encode(). Stop this madness.
Instead, in get_paging_mi(), return a decoded struct osmo_mobile_identity. Code
paths after this use the struct osmo_mobile_identity directly without repeated
decoding.
At the point of finally needing an encoded Mobile Identity IE (in
Encoding::write_paging_request()), do a proper osmo_mobile_identity_encode().
Since this may return errors, add an rc check for the caller of
write_paging_request(), gprs_rlcmac_paging_request().
A side effect is stricter validation of the Mobile Identity passing through the
Paging code path. Before, invalid MI might have passed through unnoticed.
Change-Id: Iad845acb0096b75dc453105c9c16b2252879b4ca
Diffstat (limited to 'src/pdch.cpp')
-rw-r--r-- | src/pdch.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/pdch.cpp b/src/pdch.cpp index af847241..fbbeddc5 100644 --- a/src/pdch.cpp +++ b/src/pdch.cpp @@ -266,15 +266,21 @@ free_ret: return NULL; } -bool gprs_rlcmac_pdch::add_paging(uint8_t chan_needed, const uint8_t *mi, uint8_t mi_len) +bool gprs_rlcmac_pdch::add_paging(uint8_t chan_needed, const struct osmo_mobile_identity *mi) { + int rc; struct gprs_rlcmac_paging *pag = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_paging); if (!pag) return false; pag->chan_needed = chan_needed; - pag->identity_lv[0] = mi_len; - memcpy(&pag->identity_lv[1], mi, mi_len); + rc = osmo_mobile_identity_encode_buf(pag->identity_lv + 1, sizeof(pag->identity_lv) - 1, mi, true); + if (rc <= 0) { + LOGP(DRLCMAC, LOGL_ERROR, "Cannot encode Mobile Identity (rc=%d)\n", rc); + talloc_free(pag); + return false; + } + pag->identity_lv[0] = rc; llist_add(&pag->list, &paging_list); |