Max has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/12020 )

Change subject: LCLS, TS 48.008: add GCR IE encoding/decoding
......................................................................

LCLS, TS 48.008: add GCR IE encoding/decoding

* add functions to encode Global Call. Ref. from TS 29.205 as 3GPP TS
  48.008 §3.2.2.115 information element
* add corresponding tests

Change-Id: I82ce0207dc8de50689a8806c6471ad7fbae6219d
---
M include/osmocom/gsm/gsm0808_utils.h
M src/gsm/gsm0808_utils.c
M src/gsm/libosmogsm.map
M tests/gsm0808/gsm0808_test.c
M tests/gsm0808/gsm0808_test.ok
5 files changed, 123 insertions(+), 0 deletions(-)

Approvals:
  Pau Espin Pedrol: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/gsm/gsm0808_utils.h 
b/include/osmocom/gsm/gsm0808_utils.h
index 5d5803b..22050b5 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -27,6 +27,7 @@

 #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>
@@ -82,6 +83,10 @@
                                    const struct sockaddr_storage *ss);
 int gsm0808_dec_aoip_trasp_addr(struct sockaddr_storage *ss,
                                const uint8_t *elem, uint8_t len);
+
+uint8_t gsm0808_enc_gcr(struct msgb *msg, const struct osmo_gcr_parsed *g);
+int gsm0808_dec_gcr(struct osmo_gcr_parsed *g, const struct tlv_parsed *tp);
+
 uint8_t gsm0808_enc_speech_codec(struct msgb *msg,
                                 const struct gsm0808_speech_codec *sc);
 int gsm0808_dec_speech_codec(struct gsm0808_speech_codec *sc,
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 38a8664..a04adde 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -508,6 +508,41 @@
        return (int)(elem - old_elem);
 }

+/*! Create BSSMAP Global Call Reference, 3GPP TS 48.008 §3.2.2.115.
+ *  \param[out] msg Message Buffer for appending IE
+ *  \param[in] g Global Call Reference, 3GPP TS 29.205 Table B 2.1.9.1
+ *  \returns number of bytes added to \a msg or 0 on error */
+uint8_t gsm0808_enc_gcr(struct msgb *msg, const struct osmo_gcr_parsed *g)
+{
+       uint8_t enc, *len = msgb_tl_put(msg, GSM0808_IE_GLOBAL_CALL_REF);
+
+       enc = osmo_enc_gcr(msg, g);
+       if (!enc)
+               return 0;
+
+       *len = enc;
+       return enc + 2; /* type (1 byte) + length (1 byte) */
+}
+
+/*! Decode BSSMAP Global Call Reference, 3GPP TS 29.205 Table B 2.1.9.1.
+ *  \param[out] gcr Caller-provided memory to store Global Call Reference
+ *  \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_gcr(struct osmo_gcr_parsed *gcr, const struct tlv_parsed *tp)
+{
+       int ret;
+       const uint8_t *buf = TLVP_VAL_MINLEN(tp, GSM0808_IE_GLOBAL_CALL_REF, 
OSMO_GCR_MIN_LEN);
+       if (!buf)
+               return -EINVAL;
+
+       ret = osmo_dec_gcr(gcr, buf, TLVP_LEN(tp, GSM0808_IE_GLOBAL_CALL_REF));
+       if (ret < 0)
+               return -ENOENT;
+
+       return 2 + ret;
+}
+
 /*! Encode TS 08.08 Encryption Information IE
  *  \param[out] msg Message Buffer to which IE is to be appended
  *  \param[in] ei Encryption Information to be encoded
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index e85ed6d..94ae76a 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -219,6 +219,8 @@
 gsm0808_lcls_config_names;
 gsm0808_lcls_control_names;
 gsm0808_lcls_status_names;
+gsm0808_enc_gcr;
+gsm0808_dec_gcr;

 gsm29118_msgb_alloc;
 gsm29118_create_alert_req;
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index 63b8720..f0f3165 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -22,6 +22,8 @@
 #include <osmocom/gsm/gsm0808_utils.h>
 #include <osmocom/gsm/protocol/gsm_08_08.h>
 #include <osmocom/gsm/protocol/gsm_08_58.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/core/application.h>

 #include <stdio.h>
 #include <stdlib.h>
@@ -597,6 +599,75 @@
        msgb_free(in_msg);
 }

+static void test_enc_dec_gcr()
+{
+       static const uint8_t res[] = {
+               GSM0808_IE_GLOBAL_CALL_REF,
+               0x0d, /* GCR length */
+               0x03, /* .net_len */
+               0xf1, 0xf2, 0xf3, /* .net */
+               0x02, /* .node length */
+               0xde, 0xad, /* .node */
+               0x05, /* length of Call. Ref. */
+               0x41, 0x42, 0x43, 0x44, 0x45 /* .cr - Call. Ref. */
+       };
+       uint8_t len;
+       struct msgb *msg;
+       struct osmo_gcr_parsed p = { 0 }, g = {
+               .net_len = 3,
+               .net = { 0xf1, 0xf2, 0xf3 },
+               .node = 0xDEAD,
+               .cr = { 0x41, 0x42, 0x43, 0x44, 0x45 },
+       };
+       int rc;
+       struct tlv_parsed tp;
+       msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "global 
call reference");
+       if (!msg)
+               return;
+
+       len = gsm0808_enc_gcr(msg, &g);
+       printf("Testing Global Call Reference IE encoder...\n\t%d bytes added: 
%s\n",
+              len, len == ARRAY_SIZE(res) ? "OK" : "FAIL");
+
+       if (!msgb_eq_data_print(msg, res, ARRAY_SIZE(res)))
+               abort();
+
+       rc = osmo_bssap_tlv_parse(&tp, msgb_data(msg), msgb_length(msg));
+       if (rc < 0) {
+               printf("parsing failed: %s [%s]\n", strerror(-rc), 
msgb_hexdump(msg));
+               abort();
+       }
+
+       rc = gsm0808_dec_gcr(&p, &tp);
+       if (rc < 0) {
+               printf("decoding failed: %s [%s]\n", strerror(-rc), 
msgb_hexdump(msg));
+               abort();
+       }
+
+       if (p.net_len != g.net_len) {
+               printf("Network ID length parsed wrong: %u != %u\n", p.net_len, 
g.net_len);
+               abort();
+       }
+
+       if (p.node != g.node) {
+               printf("Node ID parsed wrong: 0x%X != 0x%X\n", p.node, g.node);
+               abort();
+       }
+
+       if (memcmp(p.net, g.net, g.net_len) != 0) {
+               printf("Network ID parsed wrong: %s\n", osmo_hexdump(p.net, 
p.net_len));
+               abort();
+       }
+
+       if (memcmp(p.cr, g.cr, 5) != 0) {
+               printf("Call ref. ID parsed wrong: %s\n", osmo_hexdump(p.cr, 
5));
+               abort();
+       }
+
+       printf("\tdecoded %d bytes: %s\n", rc, rc == len ? "OK" : "FAIL");
+       msgb_free(msg);
+}
+
 static void test_enc_dec_aoip_trasp_addr_v4()
 {
        struct sockaddr_storage enc_addr;
@@ -1790,6 +1861,10 @@

 int main(int argc, char **argv)
 {
+       void *ctx = talloc_named_const(NULL, 0, "gsm0808 test");
+       msgb_talloc_ctx_init(ctx, 0);
+       osmo_init_logging2(ctx, NULL);
+
        printf("Testing generation of GSM0808 messages\n");
        test_gsm0808_enc_cause();
        test_create_layer3();
@@ -1813,6 +1888,9 @@
        test_create_paging();
        test_create_dtap();
        test_prepend_dtap();
+
+       test_enc_dec_gcr();
+
        test_enc_dec_aoip_trasp_addr_v4();
        test_enc_dec_aoip_trasp_addr_v6();
        test_gsm0808_enc_dec_speech_codec();
diff --git a/tests/gsm0808/gsm0808_test.ok b/tests/gsm0808/gsm0808_test.ok
index e5833d0..d5857e3 100644
--- a/tests/gsm0808/gsm0808_test.ok
+++ b/tests/gsm0808/gsm0808_test.ok
@@ -22,6 +22,9 @@
 Testing creating Paging Request
 Testing creating DTAP
 Testing prepend DTAP
+Testing Global Call Reference IE encoder...
+       15 bytes added: OK
+       decoded 15 bytes: OK
 test_gsm0808_enc_dec_cell_id_list_lac: encoded: 1a 07 05 01 24 ab cd 56 78 (rc 
= 9)
 ------- test_cell_id_list_add
      cell_id_list == CGI[0]:{}

--
To view, visit https://gerrit.osmocom.org/12020
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I82ce0207dc8de50689a8806c6471ad7fbae6219d
Gerrit-Change-Number: 12020
Gerrit-PatchSet: 19
Gerrit-Owner: Max <msur...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <msur...@sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofm...@sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pes...@sysmocom.de>
Gerrit-CC: Stefan Sperling <s...@stsp.name>

Reply via email to