gbproxy: Use pointer to PTMSI value instead of MI
Currently, ptmsi_enc and new_ptmsi_enc point to the beginning of the mobile identity. Since all P-TMSI in 04.08 (MM) are encoded this way (1 byte header + 4 byte P-TMSI value). This is different to the P-TMSI encoding in 08.18 (BSSGP), where the P-TMSI is encoded into 4 byte without MI header. This patch changes the code to use pointers to the P-TMSI value, which is encoded in the same way in both specifications. Sponsored-by: On-Waves ehf
This commit is contained in:
parent
43b8f9f8a1
commit
49389178cc
|
@ -34,3 +34,4 @@ int gprs_str_to_apn(uint8_t *apn_enc, size_t max_len, const char *str);
|
|||
int gprs_is_mi_tmsi(const uint8_t *value, size_t value_len);
|
||||
int gprs_is_mi_imsi(const uint8_t *value, size_t value_len);
|
||||
int gprs_parse_mi_tmsi(const uint8_t *value, size_t value_len, uint32_t *tmsi);
|
||||
void gprs_parse_tmsi(const uint8_t *value, uint32_t *tmsi);
|
||||
|
|
|
@ -172,7 +172,7 @@ static int gbproxy_patch_ptmsi(uint8_t *ptmsi_enc,
|
|||
to_bss ?
|
||||
GBPROX_PEER_CTR_PTMSI_PATCHED_SGSN :
|
||||
GBPROX_PEER_CTR_PTMSI_PATCHED_BSS;
|
||||
memcpy(&ptmsi_be, ptmsi_enc + 1, sizeof(ptmsi_be));
|
||||
memcpy(&ptmsi_be, ptmsi_enc, sizeof(ptmsi_be));
|
||||
ptmsi = ntohl(ptmsi_be);
|
||||
|
||||
if (ptmsi == new_ptmsi)
|
||||
|
@ -184,7 +184,7 @@ static int gbproxy_patch_ptmsi(uint8_t *ptmsi_enc,
|
|||
log_text, ptmsi, new_ptmsi);
|
||||
|
||||
ptmsi_be = htonl(new_ptmsi);
|
||||
memcpy(ptmsi_enc + 1, &ptmsi_be, sizeof(ptmsi_be));
|
||||
memcpy(ptmsi_enc, &ptmsi_be, sizeof(ptmsi_be));
|
||||
|
||||
rate_ctr_inc(&peer->ctrg->ctr[counter]);
|
||||
|
||||
|
|
|
@ -481,13 +481,8 @@ struct gbproxy_link_info *gbproxy_get_link_info_ul(
|
|||
|
||||
if (!link_info && parse_ctx->ptmsi_enc && !parse_ctx->old_raid_is_foreign) {
|
||||
uint32_t bss_ptmsi;
|
||||
if (!gprs_parse_mi_tmsi(parse_ctx->ptmsi_enc, GSM48_TMSI_LEN,
|
||||
&bss_ptmsi))
|
||||
LOGP(DGPRS, LOGL_ERROR,
|
||||
"Failed to parse P-TMSI (TLLI is %08x)\n",
|
||||
parse_ctx->tlli);
|
||||
else
|
||||
link_info = gbproxy_link_info_by_ptmsi(peer, bss_ptmsi);
|
||||
gprs_parse_tmsi(parse_ctx->ptmsi_enc, &bss_ptmsi);
|
||||
link_info = gbproxy_link_info_by_ptmsi(peer, bss_ptmsi);
|
||||
}
|
||||
|
||||
if (link_info)
|
||||
|
@ -563,13 +558,7 @@ struct gbproxy_link_info *gbproxy_update_link_state_dl(
|
|||
* register new TLLI */
|
||||
uint32_t new_sgsn_ptmsi;
|
||||
uint32_t new_bss_ptmsi;
|
||||
if (!gprs_parse_mi_tmsi(parse_ctx->new_ptmsi_enc, GSM48_TMSI_LEN,
|
||||
&new_sgsn_ptmsi)) {
|
||||
LOGP(DGPRS, LOGL_ERROR,
|
||||
"Failed to parse new TLLI/PTMSI (current is %08x)\n",
|
||||
parse_ctx->tlli);
|
||||
return link_info;
|
||||
}
|
||||
gprs_parse_tmsi(parse_ctx->new_ptmsi_enc, &new_sgsn_ptmsi);
|
||||
new_bss_ptmsi = gbproxy_make_bss_ptmsi(peer, new_sgsn_ptmsi);
|
||||
|
||||
LOGP(DGPRS, LOGL_INFO,
|
||||
|
@ -584,13 +573,7 @@ struct gbproxy_link_info *gbproxy_update_link_state_dl(
|
|||
* TLLI, create a new link_info */
|
||||
/* TODO: Add a test case for this branch */
|
||||
uint32_t new_ptmsi;
|
||||
if (!gprs_parse_mi_tmsi(parse_ctx->new_ptmsi_enc, GSM48_TMSI_LEN,
|
||||
&new_ptmsi)) {
|
||||
LOGP(DGPRS, LOGL_ERROR,
|
||||
"Failed to parse new PTMSI (TLLI is %08x)\n",
|
||||
parse_ctx->tlli);
|
||||
return link_info;
|
||||
}
|
||||
gprs_parse_tmsi(parse_ctx->new_ptmsi_enc, &new_ptmsi);
|
||||
|
||||
LOGP(DGPRS, LOGL_INFO,
|
||||
"Adding TLLI %08x to list (SGSN, new P-TMSI is %08x)\n",
|
||||
|
@ -620,13 +603,7 @@ struct gbproxy_link_info *gbproxy_update_link_state_dl(
|
|||
return link_info;
|
||||
/* A new P-TMSI has been signalled in the message */
|
||||
|
||||
if (!gprs_parse_mi_tmsi(parse_ctx->new_ptmsi_enc,
|
||||
GSM48_TMSI_LEN, &new_ptmsi)) {
|
||||
LOGP(DGPRS, LOGL_ERROR,
|
||||
"Failed to parse new PTMSI (TLLI is %08x)\n",
|
||||
parse_ctx->tlli);
|
||||
return link_info;
|
||||
}
|
||||
gprs_parse_tmsi(parse_ctx->new_ptmsi_enc, &new_ptmsi);
|
||||
LOGP(DGPRS, LOGL_INFO,
|
||||
"Assigning new P-TMSI %08x\n", new_ptmsi);
|
||||
/* Setup P-TMSIs */
|
||||
|
|
|
@ -171,7 +171,7 @@ static int gprs_gb_parse_gmm_attach_req(uint8_t *data, size_t data_len,
|
|||
return 0;
|
||||
|
||||
if (gprs_is_mi_tmsi(value, value_len)) {
|
||||
parse_ctx->ptmsi_enc = value;
|
||||
parse_ctx->ptmsi_enc = value + 1;
|
||||
} else if (gprs_is_mi_imsi(value, value_len)) {
|
||||
parse_ctx->imsi = value;
|
||||
parse_ctx->imsi_len = value_len;
|
||||
|
@ -215,7 +215,7 @@ static int gprs_gb_parse_gmm_attach_ack(uint8_t *data, size_t data_len,
|
|||
if (tlv_match(&data, &data_len, GSM48_IE_GMM_ALLOC_PTMSI,
|
||||
&value, &value_len) > 0 &&
|
||||
gprs_is_mi_tmsi(value, value_len))
|
||||
parse_ctx->new_ptmsi_enc = value;
|
||||
parse_ctx->new_ptmsi_enc = value + 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ static int gprs_gb_parse_gmm_detach_req(uint8_t *data, size_t data_len,
|
|||
GSM48_IE_GMM_ALLOC_PTMSI, &value, &value_len) > 0)
|
||||
{
|
||||
if (gprs_is_mi_tmsi(value, value_len))
|
||||
parse_ctx->ptmsi_enc = value;
|
||||
parse_ctx->ptmsi_enc = value + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -351,7 +351,7 @@ static int gprs_gb_parse_gmm_ra_upd_ack(uint8_t *data, size_t data_len,
|
|||
if (tlv_match(&data, &data_len, GSM48_IE_GMM_ALLOC_PTMSI,
|
||||
&value, &value_len) > 0 &&
|
||||
gprs_is_mi_tmsi(value, value_len))
|
||||
parse_ctx->new_ptmsi_enc = value;
|
||||
parse_ctx->new_ptmsi_enc = value + 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ static int gprs_gb_parse_gmm_ptmsi_reall_cmd(uint8_t *data, size_t data_len,
|
|||
/* Allocated P-TMSI */
|
||||
if (lv_shift(&data, &data_len, &value, &value_len) > 0 &&
|
||||
gprs_is_mi_tmsi(value, value_len))
|
||||
parse_ctx->new_ptmsi_enc = value;
|
||||
parse_ctx->new_ptmsi_enc = value + 1;
|
||||
|
||||
if (v_fixed_shift(&data, &data_len, 6, &value) <= 0)
|
||||
return 0;
|
||||
|
@ -395,7 +395,7 @@ static int gprs_gb_parse_gmm_id_resp(uint8_t *data, size_t data_len,
|
|||
return 0;
|
||||
|
||||
if (gprs_is_mi_tmsi(value, value_len)) {
|
||||
parse_ctx->ptmsi_enc = value;
|
||||
parse_ctx->ptmsi_enc = value + 1;
|
||||
} else if (gprs_is_mi_imsi(value, value_len)) {
|
||||
parse_ctx->imsi = value;
|
||||
parse_ctx->imsi_len = value_len;
|
||||
|
@ -680,20 +680,15 @@ void gprs_gb_log_parse_context(struct gprs_gb_parse_context *parse_ctx,
|
|||
|
||||
if (parse_ctx->ptmsi_enc) {
|
||||
uint32_t ptmsi = GSM_RESERVED_TMSI;
|
||||
int ok;
|
||||
ok = gprs_parse_mi_tmsi(parse_ctx->ptmsi_enc, GSM48_TMSI_LEN, &ptmsi);
|
||||
LOGPC(DGPRS, LOGL_DEBUG, "%s PTMSI %08x%s",
|
||||
sep, ptmsi, ok ? "" : " (parse error)");
|
||||
gprs_parse_tmsi(parse_ctx->ptmsi_enc, &ptmsi);
|
||||
LOGPC(DGPRS, LOGL_DEBUG, "%s PTMSI %08x", sep, ptmsi);
|
||||
sep = ",";
|
||||
}
|
||||
|
||||
if (parse_ctx->new_ptmsi_enc) {
|
||||
uint32_t new_ptmsi = GSM_RESERVED_TMSI;
|
||||
int ok;
|
||||
ok = gprs_parse_mi_tmsi(parse_ctx->new_ptmsi_enc, GSM48_TMSI_LEN,
|
||||
&new_ptmsi);
|
||||
LOGPC(DGPRS, LOGL_DEBUG, "%s new PTMSI %08x%s",
|
||||
sep, new_ptmsi, ok ? "" : " (parse error)");
|
||||
gprs_parse_tmsi(parse_ctx->new_ptmsi_enc, &new_ptmsi);
|
||||
LOGPC(DGPRS, LOGL_DEBUG, "%s new PTMSI %08x", sep, new_ptmsi);
|
||||
sep = ",";
|
||||
}
|
||||
|
||||
|
|
|
@ -209,3 +209,11 @@ int gprs_parse_mi_tmsi(const uint8_t *value, size_t value_len, uint32_t *tmsi)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void gprs_parse_tmsi(const uint8_t *value, uint32_t *tmsi)
|
||||
{
|
||||
uint32_t tmsi_be;
|
||||
|
||||
memcpy(&tmsi_be, value, sizeof(tmsi_be));
|
||||
|
||||
*tmsi = ntohl(tmsi_be);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue