aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/gsm/gsm0808_utils.h4
-rw-r--r--src/gsm/gsm0808.c19
-rw-r--r--src/gsm/gsm0808_utils.c54
-rw-r--r--src/gsm/libosmogsm.map4
-rw-r--r--tests/gsm0808/gsm0808_test.c33
5 files changed, 78 insertions, 36 deletions
diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h
index 22050b54..4a2233e7 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -84,8 +84,8 @@ uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg,
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_lcls(struct msgb *msg, const struct osmo_lcls *lcls);
+int gsm0808_dec_lcls(struct osmo_lcls *lcls, const struct tlv_parsed *tp);
uint8_t gsm0808_enc_speech_codec(struct msgb *msg,
const struct gsm0808_speech_codec *sc);
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index 69da57da..485e0632 100644
--- a/src/gsm/gsm0808.c
+++ b/src/gsm/gsm0808.c
@@ -488,23 +488,8 @@ struct msgb *gsm0808_create_ass2(const struct gsm0808_channel_type *ct,
if (kc)
msgb_tv_fixed_put(msg, GSM0808_IE_KC_128, 16, kc);
- if (lcls) {
- /* LCLS: §3.2.2.115 Global Call Reference */
- if (lcls->gcr)
- gsm0808_enc_gcr(msg, lcls->gcr);
-
- /* LCLS: §3.2.2.116 Configuration */
- if (lcls->config != GSM0808_LCLS_CFG_NA)
- msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, lcls->config);
-
- /* LCLS: §3.2.2.117 Connection Status Control */
- if (lcls->control != GSM0808_LCLS_CSC_NA)
- msgb_tv_put(msg, GSM0808_IE_LCLS_CONN_STATUS_CTRL, lcls->control);
-
- /* LCLS: §3.2.2.118 Correlation-Not-Needed */
- if (!lcls->corr_needed)
- msgb_v_put(msg, GSM0808_IE_LCLS_CORR_NOT_NEEDED);
- }
+ if (lcls)
+ gsm0808_enc_lcls(msg, lcls);
/* push the bssmap header */
msg->l3h =
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index aa0d3d7a..2a458c38 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -512,7 +512,7 @@ int gsm0808_dec_channel_type(struct gsm0808_channel_type *ct,
* \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)
+static 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);
@@ -528,7 +528,7 @@ uint8_t gsm0808_enc_gcr(struct msgb *msg, const struct osmo_gcr_parsed *g)
* \param[out] gcr Caller-provided memory to store Global Call Reference
* \param[in] tp IE values to be decoded
* \returns number of bytes parsed; negative on error */
-int gsm0808_dec_gcr(struct osmo_gcr_parsed *gcr, const struct tlv_parsed *tp)
+static 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);
@@ -542,6 +542,56 @@ int gsm0808_dec_gcr(struct osmo_gcr_parsed *gcr, const struct tlv_parsed *tp)
return 2 + ret;
}
+/*! Add LCLS parameters to a given msgb, 3GPP TS 48.008 §3.2.2.115 - 3.2.2.120.
+ * \param[out] msg Message Buffer for appending IE
+ * \param[in] lcls LCLS-related data
+ * \returns number of bytes added to \a msg or 0 on error */
+uint8_t gsm0808_enc_lcls(struct msgb *msg, const struct osmo_lcls *lcls)
+{
+ uint8_t enc = 0;
+
+ /* LCLS: §3.2.2.115 Global Call Reference */
+ if (lcls->gcr)
+ enc = gsm0808_enc_gcr(msg, lcls->gcr);
+
+ /* LCLS: §3.2.2.116 Configuration */
+ if (lcls->config != GSM0808_LCLS_CFG_NA) {
+ msgb_tv_put(msg, GSM0808_IE_LCLS_CONFIG, lcls->config);
+ enc += 2;
+ }
+
+ /* LCLS: §3.2.2.117 Connection Status Control */
+ if (lcls->control != GSM0808_LCLS_CSC_NA) {
+ msgb_tv_put(msg, GSM0808_IE_LCLS_CONN_STATUS_CTRL, lcls->control);
+ enc += 2;
+ }
+
+ /* LCLS: §3.2.2.118 Correlation-Not-Needed */
+ if (!lcls->corr_needed) {
+ msgb_v_put(msg, GSM0808_IE_LCLS_CORR_NOT_NEEDED);
+ enc++;
+ }
+
+ return enc;
+}
+
+/*! Decode LCLS parameters to a given msgb, 3GPP TS 48.008 §3.2.2.115 - 3.2.2.120.
+ * \param[out] lcls Caller-provided memory to store LCLS-related data
+ * \param[in] tp IE values to be decoded
+ * \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;
+
+ 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;
+
+ return 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 90c21954..76b3fd02 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -220,8 +220,8 @@ gsm0808_channel_type_name;
gsm0808_lcls_config_names;
gsm0808_lcls_control_names;
gsm0808_lcls_status_names;
-gsm0808_enc_gcr;
-gsm0808_dec_gcr;
+gsm0808_enc_lcls;
+gsm0808_dec_lcls;
gsm29118_msgb_alloc;
gsm29118_create_alert_req;
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index ebdfc29c..40e2b87b 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -668,7 +668,7 @@ static void test_prepend_dtap()
msgb_free(in_msg);
}
-static void test_enc_dec_gcr()
+static void test_enc_dec_lcls()
{
static const uint8_t res[] = {
GSM0808_IE_GLOBAL_CALL_REF,
@@ -690,11 +690,18 @@ static void test_enc_dec_gcr()
};
int rc;
struct tlv_parsed tp;
- msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "global call reference");
+ struct osmo_lcls lcls_out = { .gcr = &p }, lcls_in = {
+ .gcr = &g,
+ .config = GSM0808_LCLS_CFG_NA,
+ .control = GSM0808_LCLS_CSC_NA,
+ .corr_needed = true,
+ };
+
+ msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM, "LCLS IE");
if (!msg)
return;
- len = gsm0808_enc_gcr(msg, &g);
+ 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");
@@ -707,29 +714,29 @@ static void test_enc_dec_gcr()
abort();
}
- rc = gsm0808_dec_gcr(&p, &tp);
+ rc = gsm0808_dec_lcls(&lcls_out, &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);
+ if (lcls_out.gcr->net_len != g.net_len) {
+ printf("Network ID length parsed wrong: %u != %u\n", lcls_out.gcr->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);
+ if (lcls_out.gcr->node != g.node) {
+ printf("Node ID parsed wrong: 0x%X != 0x%X\n", lcls_out.gcr->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));
+ if (memcmp(lcls_out.gcr->net, g.net, g.net_len) != 0) {
+ printf("Network ID parsed wrong: %s\n", osmo_hexdump(lcls_out.gcr->net, lcls_out.gcr->net_len));
abort();
}
- if (memcmp(p.cr, g.cr, 5) != 0) {
- printf("Call ref. ID parsed wrong: %s\n", osmo_hexdump(p.cr, 5));
+ if (memcmp(lcls_out.gcr->cr, g.cr, 5) != 0) {
+ printf("Call ref. ID parsed wrong: %s\n", osmo_hexdump(lcls_out.gcr->cr, 5));
abort();
}
@@ -1959,7 +1966,7 @@ int main(int argc, char **argv)
test_create_dtap();
test_prepend_dtap();
- test_enc_dec_gcr();
+ test_enc_dec_lcls();
test_enc_dec_aoip_trasp_addr_v4();
test_enc_dec_aoip_trasp_addr_v6();