dexter has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-bts/+/32733 )
Change subject: paging: parse PCUIF data indication outside of paging.c
......................................................................
paging: parse PCUIF data indication outside of paging.c
The function paging_add_macblock takes a data and length parameter. The
first three byte of that string are the last three digits of the IMSI
from which the paging group is calculated.
As the layout of this data buffer is a property of the PCUIF interface
API, we should do this separation outside of paging.c. Also we should
supply the IMSI as a valid null terminated string since PCUIF v.11 also
uses this format.
Change-Id: I9f3799916e8102bf1ce0f21891f2d24f43091f01
Related: OS#5927
---
M include/osmo-bts/paging.h
M src/common/paging.c
M src/common/pcu_sock.c
3 files changed, 42 insertions(+), 15 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/33/32733/1
diff --git a/include/osmo-bts/paging.h b/include/osmo-bts/paging.h
index f1ae8e3..1afb254 100644
--- a/include/osmo-bts/paging.h
+++ b/include/osmo-bts/paging.h
@@ -37,8 +37,8 @@
/* 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,
- const uint8_t *data, uint8_t len);
+int paging_add_macblock(struct paging_state *ps, const char *imsi,
+ const uint8_t *macblock, uint8_t macblock_len);
/* generate paging message for given gsm time */
int paging_gen_msg(struct paging_state *ps, uint8_t *out_buf, struct gsm_time *gt,
diff --git a/src/common/paging.c b/src/common/paging.c
index 284b71c..5e11a98 100644
--- a/src/common/paging.c
+++ b/src/common/paging.c
@@ -269,12 +269,14 @@
/* 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,
- const uint8_t *data, uint8_t len)
+int paging_add_macblock(struct paging_state *ps, const char *imsi,
+ const uint8_t *macblock, uint8_t macblock_len)
{
struct llist_head *group_q;
struct paging_record *pr;
- uint16_t imsi, paging_group;
+ uint16_t paging_group;
+ uint16_t _imsi;
+ size_t imsi_len = strlen(imsi);
check_congestion(ps);
@@ -285,17 +287,21 @@
return -ENOSPC;
}
- if (len != GSM_MACBLOCK_LEN + 3) {
- LOGP(DPAG, LOGL_ERROR, "MAC block with invalid length %d (GSM_MACBLOCK_LEN +
3)\n", len);
+ if (macblock_len != GSM_MACBLOCK_LEN) {
+ LOGP(DPAG, LOGL_ERROR, "MAC block with invalid length %d (expecting
GSM_MACBLOCK_LEN)\n", macblock_len);
return -EINVAL;
}
- len -= 3;
- imsi = 100 * ((*(data++)) - '0');
- imsi += 10 * ((*(data++)) - '0');
- imsi += (*(data++)) - '0';
- paging_group = gsm0502_calc_paging_group(&ps->chan_desc, imsi);
-
+ /* 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';
+ paging_group = gsm0502_calc_paging_group(&ps->chan_desc, _imsi);
group_q = &ps->paging_queue[paging_group];
pr = talloc_zero(ps, struct paging_record);
@@ -305,7 +311,7 @@
LOGP(DPAG, LOGL_INFO, "Add MAC block to paging queue (group=%u)\n",
paging_group);
- memcpy(pr->u.macblock.msg, data, GSM_MACBLOCK_LEN);
+ memcpy(pr->u.macblock.msg, macblock, GSM_MACBLOCK_LEN);
/* enqueue the new message to the HEAD of the queue */
llist_add(&pr->list, group_q);
diff --git a/src/common/pcu_sock.c b/src/common/pcu_sock.c
index 00debad..2b5b99c 100644
--- a/src/common/pcu_sock.c
+++ b/src/common/pcu_sock.c
@@ -667,6 +667,7 @@
struct gsm_bts_trx_ts *ts;
struct msgb *msg;
int rc = 0;
+ char imsi[4] = { 0 };
LOGP(DPCU, LOGL_DEBUG, "Data request received: sapi=%s arfcn=%d "
"block=%d data=%s\n", sapi_string[data_req->sapi],
@@ -675,7 +676,8 @@
switch (data_req->sapi) {
case PCU_IF_SAPI_PCH:
- paging_add_macblock(bts->paging_state, data_req->data, data_req->len);
+ memcpy(imsi, data_req->data, 3);
+ paging_add_macblock(bts->paging_state, imsi, data_req->data + 3,
data_req->len-3);
break;
case PCU_IF_SAPI_AGCH:
msg = msgb_alloc(data_req->len, "pcu_agch");
--
To view, visit
https://gerrit.osmocom.org/c/osmo-bts/+/32733
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I9f3799916e8102bf1ce0f21891f2d24f43091f01
Gerrit-Change-Number: 32733
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-MessageType: newchange