Max has uploaded this change for review. ( https://gerrit.osmocom.org/12568


Change subject: LCLS: make GCR into static member of osmo_lcls
......................................................................

LCLS: make GCR into static member of osmo_lcls

Most of the time we'll have GCR filled anyway so it make sense to have
it as static parameter instead of a pointer to separately allocated
structure. Update tests to cover both static and dynamic osmo_lcls
allocation variants.

Change-Id: I905c36d8455911c68c30bc429379b7313dd46aea
---
M include/osmocom/gsm/gsm0808_utils.h
M src/gsm/gsm0808_utils.c
M tests/gsm0808/gsm0808_test.c
3 files changed, 28 insertions(+), 24 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/68/12568/1

diff --git a/include/osmocom/gsm/gsm0808_utils.h 
b/include/osmocom/gsm/gsm0808_utils.h
index 4a2233e..7c6f707 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -63,7 +63,8 @@
 struct osmo_lcls {
        enum gsm0808_lcls_config config;   /**< §3.2.2.116 Configuration */
        enum gsm0808_lcls_control control; /**< §3.2.2.117 Connection Status 
Control */
-       struct osmo_gcr_parsed *gcr;       /**< §3.2.2.115 Global Call 
Reference */
+       struct osmo_gcr_parsed gcr;        /**< §3.2.2.115 Global Call 
Reference */
+       bool gcr_available;
        bool corr_needed;                  /**< §3.2.2.118 
Correlation-Not-Needed */
 };

diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 2a458c3..9fcccae 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -551,8 +551,8 @@
        uint8_t enc = 0;

        /* LCLS: §3.2.2.115 Global Call Reference */
-       if (lcls->gcr)
-               enc = gsm0808_enc_gcr(msg, lcls->gcr);
+       if (lcls->gcr_available)
+               enc = gsm0808_enc_gcr(msg, &lcls->gcr);

        /* LCLS: §3.2.2.116 Configuration */
        if (lcls->config != GSM0808_LCLS_CFG_NA) {
@@ -581,10 +581,9 @@
  *  \returns GCR size or negative on error */
 int gsm0808_dec_lcls(struct osmo_lcls *lcls, const struct tlv_parsed *tp)
 {
-       int ret = gsm0808_dec_gcr(lcls->gcr, tp);
-       if (ret < 0)
-               return ret;
+       int ret = gsm0808_dec_gcr(&lcls->gcr, tp);

+       lcls->gcr_available = (ret < 0) ? false : true;
        lcls->config = tlvp_val8(tp, GSM0808_IE_LCLS_CONFIG, 
GSM0808_LCLS_CFG_NA);
        lcls->control = tlvp_val8(tp, GSM0808_IE_LCLS_CONN_STATUS_CTRL, 
GSM0808_LCLS_CSC_NA);
        lcls->corr_needed = TLVP_PRESENT(tp, GSM0808_IE_LCLS_CORR_NOT_NEEDED) ? 
false : true;
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index 546a487..76446ae 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -445,17 +445,17 @@
        struct sockaddr_in sin;
        struct gsm0808_speech_codec_list sc_list;
        uint32_t call_id = 0xDEADFACE;
-       struct osmo_gcr_parsed gcr = { .net_len = 3, .node = 0xFEED };
        uint8_t Kc[16];
        struct osmo_lcls lcls = {
                .config = GSM0808_LCLS_CFG_BOTH_WAY,
                .control = GSM0808_LCLS_CSC_CONNECT,
-               .gcr = &gcr,
+               .gcr = { .net_len = 3, .node = 0xFEED },
+               .gcr_available = true,
                .corr_needed = false
        };

-       memset(gcr.cr, 'A', 5);
-       memset(gcr.net, 'D', gcr.net_len);
+       memset(lcls.gcr.cr, 'A', 5);
+       memset(lcls.gcr.net, 'D', lcls.gcr.net_len);
        memset(Kc, 'E', 16);

        memset(&ct, 0, sizeof(ct));
@@ -682,16 +682,16 @@
        };
        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;
-       struct osmo_lcls lcls_out = { .gcr = &p }, lcls_in = {
-               .gcr = &g,
+       struct osmo_lcls *lcls_out, lcls_in = {
+               .gcr = {
+                       .net_len = 3,
+                       .net = { 0xf1, 0xf2, 0xf3 },
+                       .node = 0xDEAD,
+                       .cr = { 0x41, 0x42, 0x43, 0x44, 0x45 },
+               },
+               .gcr_available = true,
                .config = GSM0808_LCLS_CFG_NA,
                .control = GSM0808_LCLS_CSC_NA,
                .corr_needed = true,
@@ -701,6 +701,10 @@
        if (!msg)
                return;

+       lcls_out = talloc_zero(msg, struct osmo_lcls);
+       if (!lcls_out)
+               return;
+
        len = gsm0808_enc_lcls(msg, &lcls_in);
        printf("Testing Global Call Reference IE encoder...\n\t%d bytes added: 
%s\n",
               len, len == ARRAY_SIZE(res) ? "OK" : "FAIL");
@@ -714,25 +718,25 @@
                abort();
        }

-       rc = gsm0808_dec_lcls(&lcls_out, &tp);
+       rc = gsm0808_dec_lcls(lcls_out, &tp);
        if (rc < 0) {
                printf("decoding failed: %s [%s]\n", strerror(-rc), 
msgb_hexdump(msg));
                abort();
        }

-       if (lcls_out.config != lcls_in.config) {
+       if (lcls_out->config != lcls_in.config) {
                printf("LCLS Config parsed wrong: %s != %s\n",
-                      gsm0808_lcls_config_name(lcls_out.config), 
gsm0808_lcls_config_name(lcls_in.config));
+                      gsm0808_lcls_config_name(lcls_out->config), 
gsm0808_lcls_config_name(lcls_in.config));
                 abort();
         }

-       if (lcls_out.control != lcls_in.control) {
+       if (lcls_out->control != lcls_in.control) {
                printf("LCLS Control parsed wrong: %s != %s\n",
-                      gsm0808_lcls_control_name(lcls_out.control), 
gsm0808_lcls_control_name(lcls_in.control));
+                      gsm0808_lcls_control_name(lcls_out->control), 
gsm0808_lcls_control_name(lcls_in.control));
                 abort();
         }

-       if (!osmo_gcr_eq(lcls_out.gcr, lcls_in.gcr)) {
+       if (!osmo_gcr_eq(&lcls_out->gcr, &lcls_in.gcr)) {
                printf("GCR parsed wrong.\n");
                 abort();
         }

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I905c36d8455911c68c30bc429379b7313dd46aea
Gerrit-Change-Number: 12568
Gerrit-PatchSet: 1
Gerrit-Owner: Max <[email protected]>

Reply via email to