aboutsummaryrefslogtreecommitdiffstats
path: root/src/encoding.cpp
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2020-08-21 16:21:23 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2020-08-24 01:12:16 +0000
commit59fc0bda6e85b6fee1038a83ddc3099d0bdcfbcb (patch)
treeacd40021c1321219dc7cd293780bd0a52a14a63d /src/encoding.cpp
parent0052051c07af63da98137c9f8e3b3119642eb587 (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/encoding.cpp')
-rw-r--r--src/encoding.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/encoding.cpp b/src/encoding.cpp
index 9dfd7c93..881dc61a 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -30,6 +30,7 @@
extern "C" {
#include <osmocom/gprs/protocol/gsm_04_60.h>
#include <osmocom/gsm/protocol/gsm_04_08.h>
+#include <osmocom/gsm/gsm48.h>
}
#include <stdbool.h>
@@ -720,8 +721,10 @@ void Encoding::write_packet_downlink_assignment(RlcMacDownlink_t * block,
}
/* Generate paging request. See 44.018, sections 10 and 9.1.22 */
-int Encoding::write_paging_request(bitvec * dest, const uint8_t *mi, uint8_t mi_len)
+int Encoding::write_paging_request(bitvec * dest, const struct osmo_mobile_identity *mi)
{
+ uint8_t mi_buf[GSM48_MID_MAX_SIZE];
+ int mi_len;
unsigned wp = 0;
int plen;
@@ -732,8 +735,11 @@ int Encoding::write_paging_request(bitvec * dest, const uint8_t *mi, uint8_t mi_
bitvec_write_field(dest, &wp,0x0,4); // Page Mode
bitvec_write_field(dest, &wp,0x0,4); // Channel Needed
+ mi_len = osmo_mobile_identity_encode_buf(mi_buf, sizeof(mi_buf), mi, true);
+ if (mi_len <= 0)
+ return mi_len;
bitvec_write_field(dest, &wp, mi_len, 8); // Mobile Identity length
- bitvec_set_bytes(dest, mi, mi_len); // Mobile Identity
+ bitvec_set_bytes(dest, mi_buf, mi_len); // Mobile Identity
wp += mi_len * 8;
OSMO_ASSERT(wp % 8 == 0);