From 5da8f7e7d6d9f735ec42febeb0d1ecdd25c1a116 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 4 Jan 2019 02:50:04 +0100 Subject: add gsm0808_create_common_id() Change-Id: Id055df109cf67754854641ce6486523027f4d801 --- include/osmocom/gsm/gsm0808.h | 2 ++ src/gsm/gsm0808.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/osmocom/gsm/gsm0808.h b/include/osmocom/gsm/gsm0808.h index 373b4341..461e5b8e 100644 --- a/include/osmocom/gsm/gsm0808.h +++ b/include/osmocom/gsm/gsm0808.h @@ -302,6 +302,8 @@ struct msgb *gsm0808_create_handover_performed(const struct gsm0808_handover_per struct msgb *gsm0808_create_dtap(struct msgb *msg, uint8_t link_id); void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id); +struct msgb *gsm0808_create_common_id(const char *imsi); + const struct tlv_definition *gsm0808_att_tlvdef(void); /*! Parse BSSAP TLV structure using \ref tlv_parse */ diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c index f9f7b582..38218d69 100644 --- a/src/gsm/gsm0808.c +++ b/src/gsm/gsm0808.c @@ -1258,6 +1258,32 @@ struct msgb *gsm0808_create_dtap(struct msgb *msg_l3, uint8_t link_id) return msg; } +/*! Crate BSSMAP Common ID message. + * \param[in] imsi Subscriber's IMSI to send in the Common ID message. + * \return allocated msgb with BSSMAP Common ID message. + */ +struct msgb *gsm0808_create_common_id(const char *imsi) +{ + uint8_t mid_buf[GSM48_MI_SIZE + 2]; + int mid_len; + struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "CommonID"); + if (!msg) + return NULL; + OSMO_ASSERT(strlen(imsi) <= GSM48_MI_SIZE); + + /* Message Type, 3.2.2.1 */ + msgb_v_put(msg, BSS_MAP_MSG_COMMON_ID); + + /* mandatory IMSI 3.2.2.6 */ + mid_len = gsm48_generate_mid_from_imsi(mid_buf, imsi); + msgb_tlv_put(msg, GSM0808_IE_IMSI, mid_len - 2, mid_buf + 2); + + /* prepend header with final length */ + msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg)); + + return msg; +} + /* As per 3GPP TS 48.008 version 11.7.0 Release 11 */ static const struct tlv_definition bss_att_tlvdef = { .def = { -- cgit v1.2.3