From 4f4905fac590be8feea0b22010444ed40d7b11b5 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Fri, 30 Nov 2018 13:36:12 +0100 Subject: gsm0808: add encoder for cause codes and use it At the moment the all gsm0808 cause codes are encoded directly using the tlv API directly to put a one byte TLV field. This works ok for most situations where the cause code consists of a single byte. However, gsm0808 specifies a two byte cause code model where cause codes may be extended up to two bytes. Instead of implementing the encoding over and over and again, let's rather have an encoder function we can call. - Add an encoder function that can generate single byte and extended cause codeds and makes the length decision automatically. - Use only this function to append cause codes Change-Id: I71d58fad89502a43532f60717ca022c15c73f8bb --- src/gsm/gsm0808_utils.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/gsm/gsm0808_utils.c') diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c index c58d8284..38a8664c 100644 --- a/src/gsm/gsm0808_utils.c +++ b/src/gsm/gsm0808_utils.c @@ -48,6 +48,32 @@ * \file gsm0808_utils.c */ +/*! Encode TS 08.08 AoIP Cause IE + * \param[out] msg Message Buffer to which to append IE + * \param[in] cause Cause code to be used in IE + * \returns number of bytes added to \a msg */ +uint8_t gsm0808_enc_cause(struct msgb *msg, uint16_t cause) +{ + /* See also 3GPP TS 48.008 3.2.2.5 Cause */ + uint8_t *old_tail; + bool extended; + + old_tail = msg->tail; + + extended = gsm0808_cause_ext(cause >> 8); + + msgb_put_u8(msg, GSM0808_IE_CAUSE); + if (extended) { + msgb_put_u8(msg, 2); + msgb_put_u16(msg, cause); + } else { + msgb_put_u8(msg, 1); + msgb_put_u8(msg, (uint8_t) (cause & 0xFF)); + } + + return (uint8_t) (msg->tail - old_tail); +} + /*! Encode TS 08.08 AoIP transport address IE * \param[out] msg Message Buffer to which to append IE * \param[in] ss Socket Address to be used in IE -- cgit v1.2.3