Review at https://gerrit.osmocom.org/6204
pcu_sock: reorganize calculation of paging group pcu_sock.c:pcu_rx_data_req() needs to calculate the paging group at two positions, this commit adds a functions for that to avoid code duplication Change-Id: Iee8926d5bc017d912912916e4898e968bf4dd29b --- M src/libbsc/pcu_sock.c 1 file changed, 23 insertions(+), 19 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/04/6204/1 diff --git a/src/libbsc/pcu_sock.c b/src/libbsc/pcu_sock.c index 88867af..bfb9c7b 100644 --- a/src/libbsc/pcu_sock.c +++ b/src/libbsc/pcu_sock.c @@ -353,11 +353,30 @@ return rc; } +/* Helper function for pcu_rx_data_req() to extract paging group info */ +static uint8_t extract_paging_group(struct gsm_bts *bts, uint8_t *data) +{ + char imsi_digit_buf[4]; + uint8_t pag_grp; + + /* the first three bytes are the last three digits of + * the IMSI, which we need to compute the paging group */ + imsi_digit_buf[0] = data[0]; + imsi_digit_buf[1] = data[1]; + imsi_digit_buf[2] = data[2]; + imsi_digit_buf[3] = '\0'; + + pag_grp = gsm0502_calc_paging_group(&bts->si_common.chan_desc, + str_to_imsi(imsi_digit_buf)); + + return pag_grp; +} + + static int pcu_rx_data_req(struct gsm_bts *bts, uint8_t msg_type, struct gsm_pcu_if_data *data_req) { struct msgb *msg; - char imsi_digit_buf[4]; uint32_t tlli = -1; uint8_t pag_grp; int rc = 0; @@ -369,15 +388,7 @@ switch (data_req->sapi) { case PCU_IF_SAPI_PCH: - /* the first three bytes are the last three digits of - * the IMSI, which we need to compute the paging group */ - imsi_digit_buf[0] = data_req->data[0]; - imsi_digit_buf[1] = data_req->data[1]; - imsi_digit_buf[2] = data_req->data[2]; - imsi_digit_buf[3] = '\0'; - LOGP(DPCU, LOGL_DEBUG, "SAPI PCH imsi %s\n", imsi_digit_buf); - pag_grp = gsm0502_calc_paging_group(&bts->si_common.chan_desc, - str_to_imsi(imsi_digit_buf)); + pag_grp = extract_paging_group(bts,data_req->data); pcu_rx_rr_paging(bts, pag_grp, data_req->data+3); break; case PCU_IF_SAPI_AGCH: @@ -403,16 +414,9 @@ "invalid/small length %d\n", data_req->len); break; } - tlli = *((uint32_t *)data_req->data); - /* the first three bytes are the last three digits of - * the IMSI, which we need to compute the paging group */ - imsi_digit_buf[0] = data_req->data[4]; - imsi_digit_buf[1] = data_req->data[5]; - imsi_digit_buf[2] = data_req->data[6]; - imsi_digit_buf[3] = '\0'; - pag_grp = gsm0502_calc_paging_group(&bts->si_common.chan_desc, - str_to_imsi(imsi_digit_buf)); + memcpy(&tlli, data_req->data, sizeof(tlli)); + pag_grp = extract_paging_group(bts,data_req->data+4); msg = msgb_alloc(data_req->len - 7, "pcu_pch"); if (!msg) { -- To view, visit https://gerrit.osmocom.org/6204 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iee8926d5bc017d912912916e4898e968bf4dd29b Gerrit-PatchSet: 1 Gerrit-Project: osmo-bsc Gerrit-Branch: master Gerrit-Owner: lynxis lazus <lyn...@fe80.eu> Gerrit-Reviewer: dexter <pma...@sysmocom.de>