aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2023-07-17 12:16:51 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2023-07-17 14:15:20 +0200
commit6c83527e62c27c22dbfbccb7a1cacaf2fa3194a0 (patch)
tree849263a48c2252a570828089c621df44f94724db
parentd04e3e708bcdd8af26f072393d91088eb66e4bf3 (diff)
paging: also accept zero length IMSI strings 3
When an IMMEDIATE ASSIGNMENT MAC block (from PCUIF) is added to the paging queue, then also an IMSI is required. The paging queue uses the last three digits of the IMSI to calculate the paging group. In case no IMSI is given, the MAC block is rejected. This was handeled differently before. Even an IMSI of length 0 would still be interpreted as "000" and not rejected. See also: I9f3799916e8102bf1ce0f21891f2d24f43091f01 Let's restore the behaviour we had before and accept short IMSI strings again. Change-Id: Iab1c3f1c39dd59bb53aa74b2c9e9e135e3985e0b Related: OS#6099
-rw-r--r--src/common/paging.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/common/paging.c b/src/common/paging.c
index b1aad7c3..edc2c1f8 100644
--- a/src/common/paging.c
+++ b/src/common/paging.c
@@ -270,6 +270,27 @@ int paging_add_identity(struct paging_state *ps, uint8_t paging_group,
return 0;
}
+/* Convert the last three digits of a given IMSI string to their decimal representation. In case the given IMSI string
+ * is shorter than three or zero digits, it will be assumed as "000" */
+static uint16_t convert_imsi_to_decimal(const char *imsi)
+{
+ uint16_t _imsi;
+ size_t imsi_len = strlen(imsi);
+
+ /* Tha paging group is calculated from the last three digits of the IMSI */
+ if (imsi_len < 3) {
+ LOGP(DPAG, LOGL_ERROR, "short IMSI (%zu digits), will assume \"000\" to calculate paging group\n", imsi_len);
+ _imsi = 0;
+ } else {
+ imsi = imsi + imsi_len - 3;
+ _imsi = 100 * ((*(imsi++)) - '0');
+ _imsi += 10 * ((*(imsi++)) - '0');
+ _imsi += (*(imsi++)) - '0';
+ }
+
+ return _imsi;
+}
+
/* Add a ready formatted MAC block message to the paging queue, this can be an IMMEDIATE ASSIGNMENT, or a
* PAGING COMMAND (from the PCU) */
int paging_add_macblock(struct paging_state *ps, uint32_t tlli, const char *imsi, bool confirm, const uint8_t *macblock)
@@ -278,7 +299,6 @@ int paging_add_macblock(struct paging_state *ps, uint32_t tlli, const char *imsi
struct paging_record *pr;
uint16_t paging_group;
uint16_t _imsi;
- size_t imsi_len = strlen(imsi);
check_congestion(ps);
@@ -289,15 +309,7 @@ int paging_add_macblock(struct paging_state *ps, uint32_t tlli, const char *imsi
return -ENOSPC;
}
- /* Tha paging group is calculated from the last three digits of the IMSI */
- if (imsi_len < 3) {
- LOGP(DPAG, LOGL_ERROR, "IMSI with invalid length %zu (expecting at least the last 3 digits)\n", imsi_len);
- return -EINVAL;
- }
- imsi = imsi + imsi_len - 3;
- _imsi = 100 * ((*(imsi++)) - '0');
- _imsi += 10 * ((*(imsi++)) - '0');
- _imsi += (*(imsi++)) - '0';
+ _imsi = convert_imsi_to_decimal(imsi);
paging_group = gsm0502_calc_paging_group(&ps->chan_desc, _imsi);
group_q = &ps->paging_queue[paging_group];