This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHello Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/2279 to look at the new patch set (#2). xua_msg: Add xua_from_nested() helper function for nested IEs ... and add a test case to ensure it continues to work. Change-Id: Iee434886598b528d23ddce0490dcc782e0f5d6ae --- M include/osmocom/sigtran/xua_msg.h M src/xua_msg.c M tests/xua/xua_test.c M tests/xua/xua_test.ok 4 files changed, 86 insertions(+), 21 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/79/2279/2 diff --git a/include/osmocom/sigtran/xua_msg.h b/include/osmocom/sigtran/xua_msg.h index e0e1bcf..423adbc 100644 --- a/include/osmocom/sigtran/xua_msg.h +++ b/include/osmocom/sigtran/xua_msg.h @@ -82,6 +82,8 @@ struct xua_msg *xua_from_msg(const int version, uint16_t len, uint8_t *data); struct msgb *xua_to_msg(const int version, struct xua_msg *msg); +struct xua_msg *xua_from_nested(struct xua_msg_part *outer); + int msgb_t16l16vp_put(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *data); int msgb_t16l16vp_put_u32(struct msgb *msg, uint16_t tag, uint32_t val); int xua_msg_add_u32(struct xua_msg *xua, uint16_t iei, uint32_t val); diff --git a/src/xua_msg.c b/src/xua_msg.c index cb487c8..05430a4 100644 --- a/src/xua_msg.c +++ b/src/xua_msg.c @@ -112,12 +112,39 @@ return xua_msg_add_data(xua_out, tag_out, part->len, part->dat); } -struct xua_msg *xua_from_msg(const int version, uint16_t len, uint8_t *data) +static int xua_from_msg_common(struct xua_msg *msg, const uint8_t *data, uint16_t pos, uint16_t len) { struct xua_parameter_hdr *par; + uint16_t par_len, padding; + int rc; + + while (pos + sizeof(*par) < len) { + par = (struct xua_parameter_hdr *) &data[pos]; + par_len = ntohs(par->len); + + if (pos + par_len > len || par_len < 4) + return -1; + + rc = xua_msg_add_data(msg, ntohs(par->tag), + par_len - 4, par->data); + if (rc != 0) + return -1; + + pos += par_len; + + /* move over the padding */ + padding = (4 - (par_len % 4)) & 0x3; + pos += padding; + } + + return 0; +} + +struct xua_msg *xua_from_msg(const int version, uint16_t len, uint8_t *data) +{ struct xua_common_hdr *hdr; struct xua_msg *msg; - uint16_t pos, par_len, padding; + uint16_t pos; int rc; msg = xua_msg_alloc(); @@ -136,31 +163,33 @@ msg->hdr = *hdr; pos = sizeof(*hdr); - while (pos + sizeof(*par) < len) { - par = (struct xua_parameter_hdr *) &data[pos]; - par_len = ntohs(par->len); + rc = xua_from_msg_common(msg, data, pos, len); + if (rc < 0) + goto fail; - if (pos + par_len > len || par_len < 4) - goto fail; - - rc = xua_msg_add_data(msg, ntohs(par->tag), - par_len - 4, par->data); - if (rc != 0) - goto fail; - - pos += par_len; - - /* move over the padding */ - padding = (4 - (par_len % 4)) & 0x3; - pos += padding; - } - - /* TODO: parse */ return msg; fail: xua_msg_free(msg); return NULL; + +} + +struct xua_msg *xua_from_nested(struct xua_msg_part *outer) +{ + struct xua_msg *msg = xua_msg_alloc(); + int rc; + + if (!msg) + return NULL; + + rc = xua_from_msg_common(msg, outer->dat, 0, outer->len); + if (rc < 0) { + xua_msg_free(msg); + return NULL; + } + + return msg; } struct msgb *xua_to_msg(const int version, struct xua_msg *xua) diff --git a/tests/xua/xua_test.c b/tests/xua/xua_test.c index 74d91c4..d1aa564 100644 --- a/tests/xua/xua_test.c +++ b/tests/xua/xua_test.c @@ -1,4 +1,5 @@ /* (C) 2011 by Holger Hans Peter Freyther <zecke at selfish.org> + * (C) 2017 by Harald Welte <laforge at gnumonks.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -21,6 +22,7 @@ #include <osmocom/sigtran/xua_msg.h> #include <osmocom/sigtran/protocol/sua.h> +#include <osmocom/sigtran/protocol/m3ua.h> #include <osmocom/sigtran/sccp_sap.h> #include <osmocom/sigtran/sccp_helpers.h> @@ -355,6 +357,35 @@ } } +/* M3UA message with RKM-REG contents */ +static const uint8_t rkm_reg[] = { + 0x01, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x04, 0x00, 0x0e, 0x4d, 0x33, 0x55, 0x41, + 0x20, 0x72, 0x6f, 0x63, 0x6b, 0x73, 0x00, 0x00, 0x02, 0x07, 0x00, 0x14, 0x02, 0x0a, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x01, 0x02, 0x0b, 0x00, 0x08, 0x00, 0x00, 0x00, 0x17, +}; + +static void test_rkm(void) +{ + struct xua_msg *xua, *nested; + struct xua_msg_part *rkey; + + printf("Parsing M3UA Message\n"); + xua = xua_from_msg(M3UA_VERSION, sizeof(rkm_reg), (uint8_t *)rkm_reg); + OSMO_ASSERT(xua); + OSMO_ASSERT(xua->hdr.msg_class == M3UA_MSGC_RKM); + OSMO_ASSERT(xua->hdr.msg_type == M3UA_RKM_REG_REQ); + OSMO_ASSERT(xua_msg_find_tag(xua, M3UA_IEI_INFO_STRING)); + rkey = xua_msg_find_tag(xua, M3UA_IEI_ROUT_KEY); + OSMO_ASSERT(rkey); + OSMO_ASSERT(rkey->len == 16); + + printf("Parsing Nested M3UA Routing Key IE\n"); + nested = xua_from_nested(rkey); + OSMO_ASSERT(nested); + OSMO_ASSERT(xua_msg_get_u32(nested, M3UA_IEI_LOC_RKEY_ID) == 1); + OSMO_ASSERT(xua_msg_get_u32(nested, M3UA_IEI_DEST_PC) == 23); +} + static const struct log_info_cat default_categories[] = { [0] = { @@ -380,6 +411,7 @@ test_sccp_addr_parser(); test_helpers(); test_sccp2sua(); + test_rkm(); printf("All tests passed.\n"); return 0; diff --git a/tests/xua/xua_test.ok b/tests/xua/xua_test.ok index a9fba1d..2184902 100644 --- a/tests/xua/xua_test.ok +++ b/tests/xua/xua_test.ok @@ -128,4 +128,6 @@ PART(T=Data,L=154,D=6581974804260001984904510103df6c8188a181850201440201073080a780a08004012b30803012830110840107850791445776671697860120300682011884010400000000a306040142840105a306040151840105a306040131840105a309040112840105820102a309040111840105810101a306040114840100a30b0401418401043003830110a30b040141840104300382011800000000) Re-Encoding decoded SUA to SCCP SCCP Output: 09 81 03 0d 18 0a 12 07 00 12 04 53 84 09 00 17 0b 12 06 00 12 04 44 87 20 00 20 65 9a 65 81 97 48 04 26 00 01 98 49 04 51 01 03 df 6c 81 88 a1 81 85 02 01 44 02 01 07 30 80 a7 80 a0 80 04 01 2b 30 80 30 12 83 01 10 84 01 07 85 07 91 44 57 76 67 16 97 86 01 20 30 06 82 01 18 84 01 04 00 00 00 00 a3 06 04 01 42 84 01 05 a3 06 04 01 51 84 01 05 a3 06 04 01 31 84 01 05 a3 09 04 01 12 84 01 05 82 01 02 a3 09 04 01 11 84 01 05 81 01 01 a3 06 04 01 14 84 01 00 a3 0b 04 01 41 84 01 04 30 03 83 01 10 a3 0b 04 01 41 84 01 04 30 03 82 01 18 00 00 00 00 +Parsing M3UA Message +Parsing Nested M3UA Routing Key IE All tests passed. -- To view, visit https://gerrit.osmocom.org/2279 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newpatchset Gerrit-Change-Id: Iee434886598b528d23ddce0490dcc782e0f5d6ae Gerrit-PatchSet: 2 Gerrit-Project: libosmo-sccp Gerrit-Branch: master Gerrit-Owner: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder