Skip to content

Commit

Permalink
Replace gprs_ra_id with modern osmo_routing_area_id
Browse files Browse the repository at this point in the history
The new modern osmo_routing_area_id is more flexible
and allow to access PLMN, LAC more convient.

Depends: Iaef54cac541913534af00f40483723e9952a6807 (libosmocore)
Change-Id: Ia41eb8f51d3836b1bc65325ff1ec6bdb16e20c7e
  • Loading branch information
lynxis committed Aug 20, 2024
1 parent 35c178e commit 12ed86d
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 67 deletions.
5 changes: 3 additions & 2 deletions include/osmocom/sgsn/gprs_gmm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

struct sgsn_mm_ctx;
struct gprs_llc_llme;
struct osmo_routing_area_id;

int gsm48_tx_gmm_auth_ciph_req(struct sgsn_mm_ctx *mm,
const struct osmo_auth_vector *vec,
Expand All @@ -28,8 +29,8 @@ void gsm0408_gprs_access_denied(struct sgsn_mm_ctx *mmctx, int gmm_cause);
void gsm0408_gprs_access_cancelled(struct sgsn_mm_ctx *mmctx, int gmm_cause);
void gsm0408_gprs_authenticate(struct sgsn_mm_ctx *mmctx);

int gprs_gmm_rx_suspend(struct gprs_ra_id *raid, uint32_t tlli);
int gprs_gmm_rx_resume(struct gprs_ra_id *raid, uint32_t tlli,
int gprs_gmm_rx_suspend(struct osmo_routing_area_id *raid, uint32_t tlli);
int gprs_gmm_rx_resume(struct osmo_routing_area_id *raid, uint32_t tlli,
uint8_t suspend_ref);

int gsm0408_gprs_rcvmsg_gb(struct msgb *msg, struct gprs_llc_llme *llme,
Expand Down
2 changes: 1 addition & 1 deletion include/osmocom/sgsn/gprs_sndcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct gprs_sndcp_entity {
struct llist_head list;

/* FIXME: move this RA_ID up to the LLME or even higher */
struct gprs_ra_id ra_id;
struct osmo_routing_area_id ra_id;
/* reference to the LLC Entity below this SNDCP entity */
struct gprs_llc_lle *lle;
/* The NSAPI we shall use on top of LLC */
Expand Down
2 changes: 1 addition & 1 deletion include/osmocom/sgsn/gtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct sgsn_pdp_ctx *sgsn_create_pdp_ctx(struct sgsn_ggsn_ctx *ggsn,
uint16_t nsapi,
struct tlv_parsed *tp);

int sgsn_gtp_data_req(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
int sgsn_gtp_data_req(struct osmo_routing_area_id *ra_id, int32_t tlli, uint8_t nsapi,
struct msgb *msg, uint32_t npdu_len, uint8_t *npdu);
int sgsn_delete_pdp_ctx(struct sgsn_pdp_ctx *pctx);
int send_act_pdp_cont_acc(struct sgsn_pdp_ctx *pctx);
8 changes: 4 additions & 4 deletions include/osmocom/sgsn/mmctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct sgsn_mm_ctx {
char imei[GSM23003_IMEISV_NUM_DIGITS+1];
/* Opt: Software Version Numbber / TS 23.195 */
char msisdn[GSM_EXTENSION_LENGTH];
struct gprs_ra_id ra;
struct osmo_routing_area_id ra;
struct {
uint16_t cell_id; /* Gb only */
uint32_t cell_id_age; /* Gb only */
Expand Down Expand Up @@ -253,19 +253,19 @@ static inline bool sgsn_mm_ctx_is_authenticated(struct sgsn_mm_ctx *ctx)

/* look-up a SGSN MM context based on TLLI + RAI */
struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli,
const struct gprs_ra_id *raid);
const struct osmo_routing_area_id *raid);
struct sgsn_mm_ctx *sgsn_mm_ctx_by_ptmsi(uint32_t tmsi);
struct sgsn_mm_ctx *sgsn_mm_ctx_by_imsi(const char *imsi);
struct sgsn_mm_ctx *sgsn_mm_ctx_by_ue_ctx(const void *uectx);
struct sgsn_mm_ctx *sgsn_mm_ctx_by_llme(const struct gprs_llc_llme *llme);

/* look-up by matching TLLI and P-TMSI (think twice before using this) */
struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli_and_ptmsi(uint32_t tlli,
const struct gprs_ra_id *raid);
const struct osmo_routing_area_id *raid);

/* Allocate a new SGSN MM context */
struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_gb(uint32_t tlli,
const struct gprs_ra_id *raid);
const struct osmo_routing_area_id *raid);
struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_iu(void *uectx);

void sgsn_mm_ctx_cleanup_free(struct sgsn_mm_ctx *ctx);
Expand Down
8 changes: 6 additions & 2 deletions src/sgsn/gprs_bssgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <osmocom/gprs/gprs_bssgp.h>
#include <osmocom/gprs/gprs_ns2.h>

#include <osmocom/gsm/gsm48.h>

#include <osmocom/sgsn/gprs_llc.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/sgsn_rim.h>
Expand All @@ -35,6 +37,7 @@
int sgsn_bssgp_rx_prim(struct osmo_prim_hdr *oph)
{
struct osmo_bssgp_prim *bp;
struct osmo_routing_area_id ra_id = {};
bp = container_of(oph, struct osmo_bssgp_prim, oph);

switch (oph->sap) {
Expand All @@ -45,11 +48,12 @@ int sgsn_bssgp_rx_prim(struct osmo_prim_hdr *oph)
}
break;
case SAP_BSSGP_GMM:
gprs_rai_to_osmo(&ra_id, bp->ra_id);
switch (oph->primitive) {
case PRIM_BSSGP_GMM_SUSPEND:
return gprs_gmm_rx_suspend(bp->ra_id, bp->tlli);
return gprs_gmm_rx_suspend(&ra_id, bp->tlli);
case PRIM_BSSGP_GMM_RESUME:
return gprs_gmm_rx_resume(bp->ra_id, bp->tlli,
return gprs_gmm_rx_resume(&ra_id, bp->tlli,
bp->u.resume.suspend_ref);
}
break;
Expand Down
42 changes: 21 additions & 21 deletions src/sgsn/gprs_gmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ int gsm48_tx_gmm_att_ack(struct sgsn_mm_ctx *mm)
t = osmo_tdef_get(sgsn->cfg.T_defs, 3312, OSMO_TDEF_S, -1);
aa->ra_upd_timer = gprs_secs_to_tmr_floor(t);
aa->radio_prio = 0x44; /* lowest */
gsm48_encode_ra(&aa->ra_id, &mm->ra);
osmo_routing_area_id_encode_buf((uint8_t *) &aa->ra_id, sizeof(struct gsm48_ra_id), &mm->ra);

#if 0
/* Optional: P-TMSI signature */
Expand Down Expand Up @@ -1195,7 +1195,7 @@ static int gsm48_rx_gmm_att_req(struct sgsn_mm_ctx *ctx, struct msgb *msg,
uint8_t msnc_len, att_type, mi_len, ms_ra_acc_cap_len;
uint16_t drx_par;
char mi_log_string[32];
struct gprs_ra_id ra_id;
struct osmo_routing_area_id ra_id;
uint16_t cid = 0;
enum gsm48_gmm_cause reject_cause;
struct osmo_mobile_identity mi;
Expand All @@ -1210,10 +1210,10 @@ static int gsm48_rx_gmm_att_req(struct sgsn_mm_ctx *ctx, struct msgb *msg,

if (!MSG_IU_UE_CTX(msg)) {
/* Gb mode */
cid = bssgp_parse_cell_id(&ra_id, msgb_bcid(msg));
bssgp_parse_cell_id2(&ra_id, &cid, msgb_bcid(msg), 8);
} else {
#ifdef BUILD_IU
ra_id = MSG_IU_UE_CTX(msg)->ra_id;
gprs_rai_to_osmo(&ra_id, &MSG_IU_UE_CTX(msg)->ra_id);
#else
LOGMMCTXP(LOGL_ERROR, ctx, "Cannot handle Iu Attach Request, built without Iu support\n");
return -ENOTSUP;
Expand Down Expand Up @@ -1515,7 +1515,7 @@ static int gsm48_tx_gmm_ra_upd_ack(struct sgsn_mm_ctx *mm)
t = osmo_tdef_get(sgsn->cfg.T_defs, 3312, OSMO_TDEF_S, -1);
rua->ra_upd_timer = gprs_secs_to_tmr_floor(t);

gsm48_encode_ra(&rua->ra_id, &mm->ra);
osmo_routing_area_id_encode_buf((uint8_t *)&rua->ra_id, sizeof(struct gsm48_ra_id), &mm->ra);

#if 0
/* Optional: P-TMSI signature */
Expand Down Expand Up @@ -1622,7 +1622,7 @@ static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg,
struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
uint8_t *cur = gh->data;
uint8_t ms_ra_acc_cap_len;
struct gprs_ra_id old_ra_id;
struct osmo_routing_area_id old_ra_id;
struct tlv_parsed tp;
uint8_t upd_type;
enum gsm48_gmm_cause reject_cause = GMM_CAUSE_PROTO_ERR_UNSPEC;
Expand All @@ -1642,7 +1642,7 @@ static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg,
get_value_string(gprs_upd_t_strs, upd_type));

/* Old routing area identification 10.5.5.15 */
gsm48_parse_ra(&old_ra_id, cur);
osmo_routing_area_id_decode(&old_ra_id, cur, msgb_l3len(msg) - (cur - msgb_gmmh(msg)));
cur += 6;

/* MS Radio Access Capability 10.5.5.12a */
Expand Down Expand Up @@ -1709,34 +1709,34 @@ static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg,
msgb_tlli(msg),
mmctx->p_tmsi, mmctx->p_tmsi_old,
mmctx->gb.tlli, mmctx->gb.tlli_new,
osmo_rai_name(&mmctx->ra));
osmo_rai_name2(&mmctx->ra));
/* A RAT change will trigger the common procedure
* below after handling the RAT change. Protect it
* here from being called twice */
if (!mmctx_did_rat_change(mmctx, msg))
osmo_fsm_inst_dispatch(mmctx->gmm_fsm, E_GMM_COMMON_PROC_INIT_REQ, NULL);

}
} else if (!gprs_ra_id_equals(&mmctx->ra, &old_ra_id) ||
} else if (osmo_rai_cmp(&mmctx->ra, &old_ra_id) ||
mmctx->gmm_fsm->state == ST_GMM_DEREGISTERED)
{
/* We've received either a RAU for a MS which isn't registered
* or a RAU with an unknown RA ID. As long the SGSN doesn't support
* PS handover we treat this as invalid RAU */
struct gprs_ra_id new_ra_id;
struct osmo_routing_area_id new_ra_id = {};
char new_ra[32];

bssgp_parse_cell_id(&new_ra_id, msgb_bcid(msg));
osmo_rai_name_buf(new_ra, sizeof(new_ra), &new_ra_id);
bssgp_parse_cell_id2(&new_ra_id, NULL, msgb_bcid(msg), 8);
osmo_rai_name2_buf(new_ra, sizeof(new_ra), &new_ra_id);

if (mmctx->gmm_fsm->state == ST_GMM_DEREGISTERED)
LOGMMCTXP(LOGL_INFO, mmctx,
"Rejecting RAU - GMM state is deregistered. Old RA: %s New RA: %s\n",
osmo_rai_name(&old_ra_id), new_ra);
osmo_rai_name2(&old_ra_id), new_ra);
else
LOGMMCTXP(LOGL_INFO, mmctx,
"Rejecting RAU - Old RA doesn't match MM. Old RA: %s New RA: %s\n",
osmo_rai_name(&old_ra_id), new_ra);
osmo_rai_name2(&old_ra_id), new_ra);

reject_cause = GMM_CAUSE_IMPL_DETACHED;
goto rejected;
Expand All @@ -1757,10 +1757,10 @@ static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg,
mmctx = sgsn_mm_ctx_by_llme(llme);
if (mmctx) {
char old_ra_id_name[32];
osmo_rai_name_buf(old_ra_id_name, sizeof(old_ra_id_name), &old_ra_id);
osmo_rai_name2_buf(old_ra_id_name, sizeof(old_ra_id_name), &old_ra_id);
LOGMMCTXP(LOGL_NOTICE, mmctx,
"Rx RA Update Request with unexpected TLLI=%08x Old RA=%s (expected Old RA: %s)!\n",
msgb_tlli(msg), old_ra_id_name, osmo_rai_name(&mmctx->ra));
msgb_tlli(msg), old_ra_id_name, osmo_rai_name2(&mmctx->ra));
/* mmctx will be released (and its llme un assigned) after REJECT below. */
}
}
Expand All @@ -1784,7 +1784,7 @@ static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg,

/* Update the MM context with the new RA-ID */
if (mmctx->ran_type == MM_CTX_T_GERAN_Gb && msgb_bcid(msg)) {
bssgp_parse_cell_id(&mmctx->ra, msgb_bcid(msg));
bssgp_parse_cell_id2(&mmctx->ra, NULL, msgb_bcid(msg), 8);
/* Update the MM context with the new (i.e. foreign) TLLI */
mmctx->gb.tlli = msgb_tlli(msg);
}
Expand Down Expand Up @@ -2292,7 +2292,7 @@ int gsm0408_gprs_force_reattach(struct sgsn_mm_ctx *mmctx)
return rc;
}

int gprs_gmm_rx_suspend(struct gprs_ra_id *raid, uint32_t tlli)
int gprs_gmm_rx_suspend(struct osmo_routing_area_id *raid, uint32_t tlli)
{
struct sgsn_mm_ctx *mmctx;

Expand All @@ -2314,7 +2314,7 @@ int gprs_gmm_rx_suspend(struct gprs_ra_id *raid, uint32_t tlli)
return 0;
}

int gprs_gmm_rx_resume(struct gprs_ra_id *raid, uint32_t tlli,
int gprs_gmm_rx_resume(struct osmo_routing_area_id *raid, uint32_t tlli,
uint8_t suspend_ref)
{
struct sgsn_mm_ctx *mmctx;
Expand Down Expand Up @@ -2355,10 +2355,10 @@ int gsm0408_gprs_rcvmsg_gb(struct msgb *msg, struct gprs_llc_llme *llme,
struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
uint8_t pdisc = gsm48_hdr_pdisc(gh);
struct sgsn_mm_ctx *mmctx;
struct gprs_ra_id ra_id;
struct osmo_routing_area_id ra_id = {};
int rc = -EINVAL;

bssgp_parse_cell_id(&ra_id, msgb_bcid(msg));
bssgp_parse_cell_id2(&ra_id, NULL, msgb_bcid(msg), 8);
mmctx = sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &ra_id);
if (mmctx) {
rate_ctr_inc(rate_ctr_group_get_ctr(mmctx->ctrg, GMM_CTR_PKTS_SIG_IN));
Expand Down
2 changes: 1 addition & 1 deletion src/sgsn/gprs_sndcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ int sndcp_ll_unitdata_ind(struct msgb *msg, struct gprs_llc_lle *lle,
return -EIO;
}
/* FIXME: move this RA_ID up to the LLME or even higher */
bssgp_parse_cell_id(&sne->ra_id, msgb_bcid(msg));
bssgp_parse_cell_id2(&sne->ra_id, NULL, msgb_bcid(msg), 8);

mmctx = sgsn_mm_ctx_by_tlli(msgb_tlli(msg), &sne->ra_id);
if (!mmctx) {
Expand Down
4 changes: 2 additions & 2 deletions src/sgsn/gprs_subscriber.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ struct gprs_subscr *gprs_subscr_get_or_create_by_mmctx(struct sgsn_mm_ctx *mmctx

osmo_strlcpy(subscr->imei, mmctx->imei, sizeof(subscr->imei));

if (subscr->lac != mmctx->ra.lac)
subscr->lac = mmctx->ra.lac;
if (subscr->lac != mmctx->ra.lac.lac)
subscr->lac = mmctx->ra.lac.lac;

subscr->sgsn_data->mm = mmctx;
mmctx->subscr = gprs_subscr_get(subscr);
Expand Down
12 changes: 6 additions & 6 deletions src/sgsn/mmctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,21 @@ struct sgsn_mm_ctx *sgsn_mm_ctx_by_llme(const struct gprs_llc_llme *llme)

/* look-up a SGSN MM context based on TLLI + RAI */
struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli,
const struct gprs_ra_id *raid)
const struct osmo_routing_area_id *raid)
{
struct sgsn_mm_ctx *ctx;

llist_for_each_entry(ctx, &sgsn->mm_list, list) {
if ((tlli == ctx->gb.tlli || tlli == ctx->gb.tlli_new) &&
gprs_ra_id_equals(raid, &ctx->ra))
!osmo_rai_cmp(raid, &ctx->ra))
return ctx;
}

return NULL;
}

struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli_and_ptmsi(uint32_t tlli,
const struct gprs_ra_id *raid)
const struct osmo_routing_area_id *raid)
{
struct sgsn_mm_ctx *ctx;
int tlli_type;
Expand All @@ -153,7 +153,7 @@ struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli_and_ptmsi(uint32_t tlli,
llist_for_each_entry(ctx, &sgsn->mm_list, list) {
if ((gprs_tmsi2tlli(ctx->p_tmsi, tlli_type) == tlli ||
gprs_tmsi2tlli(ctx->p_tmsi_old, tlli_type) == tlli) &&
gprs_ra_id_equals(raid, &ctx->ra))
!osmo_rai_cmp(raid, &ctx->ra))
return ctx;
}

Expand Down Expand Up @@ -239,7 +239,7 @@ struct sgsn_mm_ctx *sgsn_mm_ctx_alloc(uint32_t rate_ctr_id)
}
/* Allocate a new SGSN MM context for GERAN_Gb */
struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_gb(uint32_t tlli,
const struct gprs_ra_id *raid)
const struct osmo_routing_area_id *raid)
{
struct sgsn_mm_ctx *ctx;

Expand Down Expand Up @@ -267,7 +267,7 @@ struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_iu(void *uectx)
return NULL;

/* Need to get RAID from IU conn */
ctx->ra = ue_ctx->ra_id;
gprs_rai_to_osmo(&ctx->ra, &ue_ctx->ra_id);
ctx->ran_type = MM_CTX_T_UTRAN_Iu;
ctx->iu.ue_ctx = ue_ctx;
ctx->iu.ue_ctx->rab_assign_addr_enc = sgsn->cfg.iu.rab_assign_addr_enc;
Expand Down
6 changes: 3 additions & 3 deletions src/sgsn/sgsn_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ enum sgsn_auth_state sgsn_auth_state(struct sgsn_mm_ctx *mmctx)
/* We simply assume that the IMSI exists, as long as it is part
* of 'our' network */
snprintf(mccmnc, sizeof(mccmnc), "%s%s",
osmo_mcc_name(mmctx->ra.mcc),
osmo_mnc_name(mmctx->ra.mnc, mmctx->ra.mnc_3_digits));
if (strncmp(mccmnc, mmctx->imsi, mmctx->ra.mnc_3_digits ? 6 : 5) == 0)
osmo_mcc_name(mmctx->ra.lac.plmn.mcc),
osmo_mnc_name(mmctx->ra.lac.plmn.mnc, mmctx->ra.lac.plmn.mnc_3_digits));
if (strncmp(mccmnc, mmctx->imsi, mmctx->ra.lac.plmn.mnc_3_digits ? 6 : 5) == 0)
return SGSN_AUTH_ACCEPTED;
}

Expand Down
4 changes: 2 additions & 2 deletions src/sgsn/sgsn_cdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static int cdr_snprintf_mm(char *buf, size_t size, const char *ev,
mmctx->imei,
mmctx->msisdn,
mmctx->gb.cell_id,
mmctx->ra.lac,
mmctx->ra.lac.lac,
mmctx->hlr,
ev);
return ret;
Expand Down Expand Up @@ -194,7 +194,7 @@ static int cdr_snprintf_pdp(char *buf, size_t size, const char *ev,
pdp->mm ? pdp->mm->imei : "N/A",
pdp->mm ? pdp->mm->msisdn : "N/A",
pdp->mm ? pdp->mm->gb.cell_id : -1,
pdp->mm ? pdp->mm->ra.lac : -1,
pdp->mm ? pdp->mm->ra.lac.lac : -1,
pdp->mm ? pdp->mm->hlr : "N/A",
ev,
(unsigned long ) duration,
Expand Down
Loading

0 comments on commit 12ed86d

Please sign in to comment.