From 80401adcb03a28fc077b2a8651680f2c95a03657 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 11 Sep 2015 19:48:06 +0200 Subject: [PATCH] ranap: Parse InitialUE message and hex-print NAS PDU --- src/hnbgw_ranap.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/hnbgw_ranap.c b/src/hnbgw_ranap.c index 8947ca54..2b099afe 100644 --- a/src/hnbgw_ranap.c +++ b/src/hnbgw_ranap.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -349,11 +350,58 @@ static int ranap_rx_init_reset(struct hnb_context *hnb, ANY_t *in) DEBUGP(DMAIN, "RESET.req\n"); + /* FIXME: Actually we have to wait for some guard time? */ + /* FIXME: Reset all resources related to this HNB/RNC */ ranap_tx_reset_ack(hnb, ies.cN_DomainIndicator); return 0; } +int ranap_parse_lai(struct gprs_ra_id *ra_id, const RANAP_LAI_t *lai) +{ + uint8_t *ptr = lai->pLMNidentity.buf; + + /* TS 25.413 9.2.3.55 */ + if (lai->pLMNidentity.size != 3) + return -1; + + ra_id->mcc = (ptr[0] & 0xF) * 100 + + (ptr[0] >> 4) * 10 + + (ptr[1] & 0xF); + ra_id->mnc = (ptr[2] & 0xF) + + (ptr[2] >> 4) * 10; + if ((ptr[1] >> 4) != 0xF) + ra_id->mnc += (ptr[1] >> 4) * 100; + + ra_id->lac = asn1str_to_u16(&lai->lAC); + + /* TS 25.413 9.2.3.6 */ + if (ra_id->lac == 0 || ra_id->lac == 0xfffe) + return -1; + + return 0; +} + +static int ranap_rx_init_ue_msg(struct hnb_context *hnb, ANY_t *in) +{ + RANAP_InitialUE_MessageIEs_t ies; + struct gprs_ra_id ra_id; + int rc; + + rc = ranap_decode_initialue_messageies(&ies, in); + if (rc < 0) + return rc; + + /* location area ID of the serving cell */ + ranap_parse_lai(&ra_id, &ies.lai); + + DEBUGP(DMAIN, "%u-%u-%u: InitialUE: %s\n", ra_id.mcc, ra_id.mnc, + ra_id.lac, osmo_hexdump(ies.nas_pdu.buf, ies.nas_pdu.size)); + /* FIXME: hand NAS PDU into MSC */ + + return 0; +} + static int ranap_rx_initiating_msg(struct hnb_context *hnb, RANAP_InitiatingMessage_t *imsg) { int rc; @@ -362,6 +410,9 @@ static int ranap_rx_initiating_msg(struct hnb_context *hnb, RANAP_InitiatingMess case RANAP_ProcedureCode_id_Reset: rc = ranap_rx_init_reset(hnb, &imsg->value); break; + case RANAP_ProcedureCode_id_InitialUE_Message: + rc = ranap_rx_init_ue_msg(hnb, &imsg->value); + break; } }