jolly has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/32931 )
Change subject: ASCI: Add IE transcoding according to 3GPP TS 48.008 ......................................................................
ASCI: Add IE transcoding according to 3GPP TS 48.008
Change-Id: Ic1fc714bb04228a7f32e9925811e21c8efc610bd --- M include/osmocom/gsm/gsm0808_utils.h M src/gsm/gsm0808_utils.c M src/gsm/libosmogsm.map 3 files changed, 468 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/31/32931/1
diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h index 85244a5..7b6c4e1 100644 --- a/include/osmocom/gsm/gsm0808_utils.h +++ b/include/osmocom/gsm/gsm0808_utils.h @@ -23,14 +23,14 @@ */ #pragma once
-struct sockaddr_storage; - #include <osmocom/gsm/protocol/gsm_08_08.h> #include <osmocom/gsm/protocol/gsm_04_08.h> #include <osmocom/gsm/gsm29205.h> #include <osmocom/gsm/gsm23003.h> #include <osmocom/gsm/gsm_utils.h> #include <osmocom/gsm/tlv.h> +#include <osmocom/gsm/gsm48.h> +#include <sys/socket.h>
/*! (225-1)/2 is the maximum number of elements in a cell identifier list. */ #define GSM0808_CELL_ID_LIST2_MAXLEN 127 @@ -62,6 +62,126 @@ unsigned int id_list_len; };
+/*! Parsed representation of a Priority IE (GGPP TS 48.008 3.2.2.18) */ +struct gsm0808_priority { + /* Preemtion Capability indicator */ + bool pci; + /* Priority level: 1 == hightest, 14 == lowest */ + uint8_t priority_level; + /* Queuing allowed indicator */ + bool qa; + /* Preemtion Vulnerability indicator */ + bool pvi; +}; + +/*! Parsed representation of a VGCS Feature Flags IE (3GPP TS 48.008 3.2.2.88) */ +struct gsm0808_vgcs_feature_flags { + /* Talker priority supported */ + bool tp_ind; + /* A-interface circuit sharing supported */ + bool as_ind_circuit; + /* A-interface link sharing supported */ + bool as_ind_link; + /* BSS supports re-establishment */ + bool bss_res; + /* Talker channel parameter supported */ + bool tcp; +}; + +/* TS 48.008 3.2.2.52 */ +enum gsm0808_assignment_requirement { + GSM0808_ASRQ_DELAY_ALLOWED = 0x00, + GSM0808_ASRQ_IMMEDIATE = 0x01, + GSM0808_ASRQ_IMMEDIATE_ON_DEMAND = 0x02, +}; + +/* TS 48.008 Table 10.5.8 */ +enum gsm0808_service_flag { + GSM0808_SF_VBS = 0, + GSM0808_SF_VGCS = 1, +}; + +enum gsm0808_call_priority { + GSM0808_CALL_PRIORITY_NONE = 0x00, + GSM0808_CALL_PRIORITY_LEVEL_4 = 0x01, + GSM0808_CALL_PRIORITY_LEVEL_3 = 0x02, + GSM0808_CALL_PRIORITY_LEVEL_2 = 0x03, + GSM0808_CALL_PRIORITY_LEVEL_1 = 0x04, + GSM0808_CALL_PRIORITY_LEVEL_0 = 0x05, + GSM0808_CALL_PRIORITY_LEVEL_B = 0x06, + GSM0808_CALL_PRIORITY_LEVEL_A = 0x07, +}; + +/*! Parsed representation of a Group Call Reference IE (3GPP TS 48.008 3.2.2.55) */ +struct gsm0808_group_callref { + /* Group or Broadcast Call Reference */ + uint32_t callref; + /* Service flag */ + enum gsm0808_service_flag sf; + /* Acknowledgement flag */ + bool af; + /* Call piorioity */ + enum gsm0808_call_priority call_priority; + /* Ciphering information (key number to use; 0 == no ciphering) */ + uint8_t ciphering_info; +}; + +/* TS 48.008 3.2.2.26 */ +enum gsm0808_downlink_dtx_flag { + GSM0808_DTX_FLAG_ALLOW = 0, + GSM0808_DTX_FLAG_FORBID = 1, +}; + +/*! Parsed representation of a Cell Identifier List Segment IE (3GPP TS 48.008 3.2.2.27a) */ +struct gsm0808_cell_id_list_segment { + uint8_t seq_last; + uint8_t seq_number; + struct gsm0808_cell_id_list2 cil; +}; + +/*! Parsed representation of a Circuit Pool List IE (3GPP TS 48.008 3.2.2.26) */ +#define CIRCUIT_POOL_LIST_MAXLEN 252 +struct gsm0808_circuit_pool_list { + uint8_t pool[CIRCUIT_POOL_LIST_MAXLEN]; + unsigned int list_len; +}; + +/* 3GPP TS 48.008 Table 3.2.2.90.1 Talker Priority */ +enum gsm0808_talker_priority { + GSM0808_TALKER_NORMAL_PRIORITY = 0x00, + GSM0808_TALKER_PRIVILEGED_PRIORITY = 0x01, + GSM0808_TALKER_EMERGENCY_PRIORITY = 0x02, +}; + +/*! Parsed representation of a Layer 3 Information IE (3GPP TS 48.008 3.2.2.24) */ +#define LAYER_3_INFORMATION_MAXLEN 252 +struct gsm0808_layer_3_information { + uint8_t l3[LAYER_3_INFORMATION_MAXLEN]; + unsigned int l3_len; +}; + +/*! Parsed representation of a Talker Identity IE (3GPP TS 48.008 3.2.2.91) */ +#define TALKER_IDENTITY_MAXLEN 17 +struct gsm0808_talker_identity { + uint8_t talker_id[TALKER_IDENTITY_MAXLEN]; + unsigned int id_bits; +}; + +/* 3GPP TS 48.008 3.2.2.94 VGCS/VBS Cell Status */ +enum gsm0808_vgcs_vbs_cell_status { + GSM0808_CSTAT_ESTABLISHED = 0x00, + GSM0808_CSTAT_NOT_ESTABLISHED1 = 0x01, + GSM0808_CSTAT_RELEASED_NO_USER = 0x02, + GSM0808_CSTAT_NOT_ESTABLISHED2 = 0x03, +}; + +/*! Parsed representation of a SMS to VGCS IE (3GPP TS 48.008 3.2.2.92) */ +#define SMS_TO_VGCS_MAXLEN 252 +struct gsm0808_sms_to_vgcs { + uint8_t sms[SMS_TO_VGCS_MAXLEN]; + unsigned int sms_len; +}; + /*! LCLS-related parameters from 3GPP TS 48.008 */ struct osmo_lcls { enum gsm0808_lcls_config config; /**< §3.2.2.116 Configuration */ @@ -303,4 +423,19 @@ char *gsm0808_channel_type_name_buf(char *buf, size_t buf_len, const struct gsm0808_channel_type *ct); char *gsm0808_channel_type_name_c(const void *ctx, const struct gsm0808_channel_type *ct);
+uint8_t gsm0808_enc_group_callref(struct msgb *msg, const struct gsm0808_group_callref *gc); +int gsm0808_dec_group_callref(struct gsm0808_group_callref *gc, const uint8_t *elem, uint8_t len); +uint8_t gsm0808_enc_priority(struct msgb *msg, const struct gsm0808_priority *pri); +int gsm0808_dec_priority(struct gsm0808_priority *pri, const uint8_t *elem, uint8_t len); +uint8_t gsm0808_enc_vgcs_feature_flags(struct msgb *msg, const struct gsm0808_vgcs_feature_flags *ff); +int gsm0808_dec_vgcs_feature_flags(struct gsm0808_vgcs_feature_flags *ff, const uint8_t *elem, uint8_t len); +uint8_t gsm0808_enc_talker_identity(struct msgb *msg, const struct gsm0808_talker_identity *ti); +int gsm0808_dec_talker_identity(struct gsm0808_talker_identity *ti, const uint8_t *elem, uint8_t len); +uint8_t gsm0808_enc_assign_req(struct msgb *msg, const enum gsm0808_assignment_requirement ar); +int gsm0808_dec_assign_req(enum gsm0808_assignment_requirement *ar, const uint8_t *elem, uint8_t len); +uint8_t gsm0808_enc_cell_id_list_segment(struct msgb *msg, uint8_t ie_type, + const struct gsm0808_cell_id_list_segment *ci); +int gsm0808_dec_cell_id_list_segment(struct gsm0808_cell_id_list_segment *ci, const uint8_t *elem, uint8_t len); +int gsm0808_dec_call_id(uint32_t *ci, const uint8_t *elem, uint8_t len); + /*! @} */ diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c index efa9305..0f04b04 100644 --- a/src/gsm/gsm0808_utils.c +++ b/src/gsm/gsm0808_utils.c @@ -2210,4 +2210,313 @@ return gsm0808_channel_type_name_buf(buf, 128, ct); }
+/*! Encode Group Call Reference IE (3GPP TS 48.008 3.2.2.55). + * \param[out] msg Message Buffer to which IE is to be appended + * \param[in] gc Group Call Reference to be encoded + * \returns number of bytes appended to \a msg */ +uint8_t gsm0808_enc_group_callref(struct msgb *msg, const struct gsm0808_group_callref *gc) +{ + uint8_t *old_tail; + uint8_t *tlv_len; + uint8_t *ptr; + + OSMO_ASSERT(msg); + OSMO_ASSERT(gc); + + msgb_put_u8(msg, GSM0808_IE_GROUP_CALL_REFERENCE); + tlv_len = msgb_put(msg, 1); + old_tail = msg->tail; + + ptr = msgb_put(msg, 5); + osmo_store32be(gc->callref << 5, ptr); + ptr[3] |= gc->sf << 4; + ptr[3] |= gc->af << 3; + ptr[3] |= gc->call_priority; + ptr[4] |= gc->ciphering_info << 4; + + *tlv_len = (uint8_t) (msg->tail - old_tail); + return *tlv_len + 2; +} + +/*! Decode Group Call Reference IE (3GPP TS 48.008 3.2.2.55). + * \param[out] gc Group Call Reference structure to store data + * \param[in] elem IE value to be decoded. + * \param[in] len Length of \a elem in bytes. + * \returns number of bytes parsed; negative on error */ +int gsm0808_dec_group_callref(struct gsm0808_group_callref *gc, const uint8_t *elem, uint8_t len) +{ + OSMO_ASSERT(gc); + OSMO_ASSERT(elem); + + if (len != 5) + return -EINVAL; + + gc->callref = osmo_load32be(elem) >> 5; + gc->sf = (elem[3] >> 4) & 0x1; + gc->af = (elem[3] >> 3) & 0x1; + gc->call_priority = elem[3] & 0x7; + gc->ciphering_info = elem[4] >> 4; + + return 5; +} + +/*! Encode Priority IE (3GPP TS 48.008 3.2.2.18). + * \param[out] msg Message Buffer to which IE is to be appended + * \param[in] pri Priority to be encoded + * \returns number of bytes appended to \a msg */ +uint8_t gsm0808_enc_priority(struct msgb *msg, const struct gsm0808_priority *pri) +{ + uint8_t *old_tail; + uint8_t *tlv_len; + uint8_t *ptr; + + OSMO_ASSERT(msg); + OSMO_ASSERT(pri); + + msgb_put_u8(msg, GSM0808_IE_PRIORITY); + tlv_len = msgb_put(msg, 1); + old_tail = msg->tail; + + ptr = msgb_put(msg, 1); + ptr[0] = pri->pci << 6; + ptr[0] |= pri->priority_level << 2; + ptr[0] |= pri->qa << 1; + ptr[0] |= pri->pvi; + + *tlv_len = (uint8_t) (msg->tail - old_tail); + return *tlv_len + 2; +} + +/*! Decode Priority IE (3GPP TS 48.008 3.2.2.18). + * \param[out] pri Priority structure to store data + * \param[in] elem IE value to be decoded. + * \param[in] len Length of \a elem in bytes. + * \returns number of bytes parsed; negative on error */ +int gsm0808_dec_priority(struct gsm0808_priority *pri, const uint8_t *elem, uint8_t len) +{ + OSMO_ASSERT(pri); + OSMO_ASSERT(elem); + + if (len != 1) + return -EINVAL; + + pri->pci = (elem[0] >> 6) & 0x1; + pri->priority_level = (elem[0] >> 2) & 0xf; + pri->qa = (elem[0] >> 1) & 0x1; + pri->pvi = elem[0] & 0x1; + + return 1; +} + +/*! Encode VGCS Feature Flags IE (3GPP TS 48.008 3.2.2.88). + * \param[out] msg Message Buffer to which IE is to be appended + * \param[in] ff VGCS Feature Flags to be encoded + * \returns number of bytes appended to \a msg */ +uint8_t gsm0808_enc_vgcs_feature_flags(struct msgb *msg, const struct gsm0808_vgcs_feature_flags *ff) +{ + uint8_t *old_tail; + uint8_t *tlv_len; + uint8_t *ptr; + + OSMO_ASSERT(msg); + OSMO_ASSERT(ff); + + msgb_put_u8(msg, GSM0808_IE_VGCS_FEATURE_FLAGS); + tlv_len = msgb_put(msg, 1); + old_tail = msg->tail; + + ptr = msgb_put(msg, 1); + ptr[0] = ff->tcp << 4; + ptr[0] |= ff->bss_res << 3; + ptr[0] |= ff->as_ind_link << 2; + ptr[0] |= ff->as_ind_circuit << 1; + ptr[0] |= ff->tp_ind; + + *tlv_len = (uint8_t) (msg->tail - old_tail); + return *tlv_len + 2; +} + +/*! Decode VGCS Feature Flags IE (3GPP TS 48.008 3.2.2.88). + * \param[out] ff VGCS Feature Flags structure to store data + * \param[in] elem IE value to be decoded. + * \param[in] len Length of \a elem in bytes. + * \returns number of bytes parsed; negative on error */ +int gsm0808_dec_vgcs_feature_flags(struct gsm0808_vgcs_feature_flags *ff, const uint8_t *elem, uint8_t len) +{ + OSMO_ASSERT(ff); + OSMO_ASSERT(elem); + + if (len != 1) + return -EINVAL; + + ff->tcp = (elem[0] >> 4) & 0x1; + ff->bss_res = (elem[0] >> 3) & 0x1; + ff->as_ind_link = (elem[0] >> 2) & 0x1; + ff->as_ind_circuit = (elem[0] >> 1) & 0x1; + ff->tp_ind = elem[0] & 0x1; + + return 1; +} + +/*! Encode Talker Identity IE (3GPP TS 48.008 3.2.2.91). + * \param[out] msg Message Buffer to which IE is to be appended + * \param[in] ti Talker Identity to be encoded + * \returns number of bytes appended to \a msg */ +uint8_t gsm0808_enc_talker_identity(struct msgb *msg, const struct gsm0808_talker_identity *ti) +{ + uint8_t *old_tail; + uint8_t *tlv_len; + uint8_t *ptr; + unsigned int bytes; + + OSMO_ASSERT(msg); + OSMO_ASSERT(ti); + + msgb_put_u8(msg, GSM0808_IE_TALKER_IDENTITY); + tlv_len = msgb_put(msg, 1); + old_tail = msg->tail; + + bytes = (ti->id_bits + 7) >> 3; + ptr = msgb_put(msg, 1 + bytes); + ptr[0] = -ti->id_bits & 0x7; + memcpy(ptr + 1, ti->talker_id, bytes); + + *tlv_len = (uint8_t) (msg->tail - old_tail); + return *tlv_len + 2; +} + +/*! Decode Talker Identity IE (3GPP TS 48.008 3.2.2.91). + * \param[out] ti Talker Identity structure to store data + * \param[in] elem IE value to be decoded. + * \param[in] len Length of \a elem in bytes. + * \returns number of bytes parsed; negative on error */ +int gsm0808_dec_talker_identity(struct gsm0808_talker_identity *ti, const uint8_t *elem, uint8_t len) +{ + OSMO_ASSERT(ti); + OSMO_ASSERT(elem); + + if (len < 2) + return -EINVAL; + unsigned int bytes; + + bytes = len - 1; + if (bytes > TALKER_IDENTITY_MAXLEN) + return -EINVAL; + ti->id_bits = (bytes << 3) - (elem[0] & 0x7); + memcpy(ti->talker_id, elem + 1, bytes); + + return len; +} + +/*! Encode Assignment Requirements IE (3GPP TS 48.008 3.2.2.52). + * \param[out] msg Message Buffer to which IE is to be appended + * \param[in] ar Assignment Requirement to be encoded + * \returns number of bytes appended to \a msg */ +uint8_t gsm0808_enc_assign_req(struct msgb *msg, const enum gsm0808_assignment_requirement ar) +{ + uint8_t *ptr; + + OSMO_ASSERT(msg); + + msgb_put_u8(msg, GSM0808_IE_ASSIGNMENT_REQUIREMENT); + + ptr = msgb_put(msg, 1); + ptr[0] = ar; + + return 2; +} + +/*! Decode Assignment Requirements IE (3GPP TS 48.008 3.2.2.52). + * \param[out] ar Assignment Requirements enum to store data + * \param[in] elem IE value to be decoded. + * \param[in] len Length of \a elem in bytes. + * \returns number of bytes parsed; negative on error */ +int gsm0808_dec_assign_req(enum gsm0808_assignment_requirement *ar, const uint8_t *elem, uint8_t len) +{ + OSMO_ASSERT(ar); + OSMO_ASSERT(elem); + + if (len != 1) + return -EINVAL; + + *ar = elem[0]; + + return 1; +} + +/*! Encode Cell Identifier List Segment IE (3GPP TS 48.008 3.2.2.27a). + * \param[out] msg Message Buffer to which IE is to be appended + * \param[in] ie_type Type of IE to use (5 different lists are specified.) + * \param[in] ci Cell Identifier List Segment to be encoded + * \returns number of bytes appended to \a msg */ +uint8_t gsm0808_enc_cell_id_list_segment(struct msgb *msg, uint8_t ie_type, + const struct gsm0808_cell_id_list_segment *ci) +{ + uint8_t *old_tail; + uint8_t *tlv_len; + uint8_t *ptr; + int rc; + + OSMO_ASSERT(msg); + OSMO_ASSERT(ci); + + msgb_put_u8(msg, ie_type); + tlv_len = msgb_put(msg, 1); + old_tail = msg->tail; + + ptr = msgb_put(msg, 1); + ptr[0] = ci->seq_last << 4; + ptr[0] |= ci->seq_number; + + rc = gsm0808_enc_cell_id_list2(msg, &ci->cil); + if (rc <= 0) + return rc; + + *tlv_len = (uint8_t) (msg->tail - old_tail); + return *tlv_len + 2; +} + +/*! Decode Cell Identifier List Segment IE (3GPP TS 48.008 3.2.2.27a). + * \param[out] ci Cell Identifier List Segment structure to store data + * \param[in] elem IE value to be decoded. + * \param[in] len Length of \a elem in bytes. + * \returns number of bytes parsed; negative on error */ +int gsm0808_dec_cell_id_list_segment(struct gsm0808_cell_id_list_segment *ci, const uint8_t *elem, uint8_t len) +{ + int rc; + + OSMO_ASSERT(ci); + OSMO_ASSERT(elem); + + if (len < 1) + return -EINVAL; + + ci->seq_last = elem[0] >> 4; + ci->seq_number = elem[0] & 0x0f; + + rc = gsm0808_dec_cell_id_list2(&ci->cil, elem + 1, len - 1); + if (rc < 0) + return rc; + + return len; +} + +/*! Decode Call Identifier IE (3GPP TS 48.008 3.2.2.105). + * \param[out] ci Call Identifier structure to store data + * \param[in] elem IE value to be decoded. + * \param[in] len Length of \a elem in bytes. + * \returns number of bytes parsed; negative on error */ +int gsm0808_dec_call_id(uint32_t *ci, const uint8_t *elem, uint8_t len) +{ + OSMO_ASSERT(ci); + OSMO_ASSERT(elem); + + if (len != 4) + return -EINVAL; + + *ci = osmo_load32le(elem); + + return 4; +} + /*! @} */ diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map index 52cda4c..c37e87c 100644 --- a/src/gsm/libosmogsm.map +++ b/src/gsm/libosmogsm.map @@ -231,6 +231,19 @@ gsm0808_enc_cell_id_list2; gsm0808_dec_cell_id_list; gsm0808_dec_cell_id_list2; +gsm0808_enc_group_callref; +gsm0808_dec_group_callref; +gsm0808_enc_priority; +gsm0808_dec_priority; +gsm0808_enc_vgcs_feature_flags; +gsm0808_dec_vgcs_feature_flags; +gsm0808_enc_talker_identity; +gsm0808_dec_talker_identity; +gsm0808_enc_assign_req; +gsm0808_dec_assign_req; +gsm0808_enc_cell_id_list_segment; +gsm0808_dec_cell_id_list_segment; +gsm0808_dec_call_id; gsm0808_cell_id_list_add; gsm0808_cell_id_to_list; gsm0808_cell_id_to_cgi;