aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-03-23 12:19:00 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-03-23 12:28:06 +0100
commit7046633c02d15939d4953f1860f38be28f42667e (patch)
treed3af5fcf1c4d886f654d27cc747e8ce4decb1ae2
parent4d244d3c31486f4e353dc997c92fa46129d82406 (diff)
xua: Generalize the m2ua_msg and call it xua_msg
Generalize, this requires various API modifications but that is the most sane path forward.
-rw-r--r--include/sigtran/Makefile.am2
-rw-r--r--include/sigtran/m2ua_types.h17
-rw-r--r--include/sigtran/xua_msg.h (renamed from include/sigtran/m2ua_msg.h)29
-rw-r--r--include/sigtran/xua_types.h17
-rw-r--r--src/Makefile.am4
-rw-r--r--src/xua_msg.c (renamed from src/m2ua_msg.c)72
-rw-r--r--tests/m2ua/Makefile.am2
-rw-r--r--tests/m2ua/m2ua_test.c23
8 files changed, 81 insertions, 85 deletions
diff --git a/include/sigtran/Makefile.am b/include/sigtran/Makefile.am
index 053530a..aa0f95c 100644
--- a/include/sigtran/Makefile.am
+++ b/include/sigtran/Makefile.am
@@ -1,2 +1,2 @@
-sigtran_HEADERS = m3ua_types.h xua_types.h m2ua_types.h m2ua_msg.h
+sigtran_HEADERS = m3ua_types.h xua_types.h xua_msg.h m2ua_types.h
sigtrandir = $(includedir)/osmocom/sigtran
diff --git a/include/sigtran/m2ua_types.h b/include/sigtran/m2ua_types.h
index d6854e8..7184f54 100644
--- a/include/sigtran/m2ua_types.h
+++ b/include/sigtran/m2ua_types.h
@@ -89,16 +89,6 @@ enum {
M2UA_IIM_DEREG_RSP, /* Deregistration Response (DEREG RSP) */
};
-struct m2ua_common_hdr {
- uint8_t version;
- uint8_t spare;
- uint8_t msg_class;
- uint8_t msg_type;
- uint32_t msg_length;
- uint8_t data[0];
-} __attribute__((packed));
-
-
/**
* Tag Values for M2UA
*/
@@ -124,13 +114,6 @@ enum {
M2UA_TAG_DEREG_STATUS, /* De-Registration Status */
};
-struct m2ua_parameter_hdr {
- uint16_t tag;
- uint16_t len;
- uint8_t data[0];
-} __attribute__((packed));
-
-
/**
* 3.3.1.5 State Request
*/
diff --git a/include/sigtran/m2ua_msg.h b/include/sigtran/xua_msg.h
index e878edd..9cc8632 100644
--- a/include/sigtran/m2ua_msg.h
+++ b/include/sigtran/xua_msg.h
@@ -15,24 +15,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+#pragma once
-
-#ifndef m2ua_msg_h
-#define m2ua_msg_h
-
-#include "m2ua_types.h"
+#include "xua_types.h"
#include <osmocom/core/linuxlist.h>
struct msgb;
-struct m2ua_msg {
- struct m2ua_common_hdr hdr;
+struct xua_msg {
+ struct xua_common_hdr hdr;
struct llist_head headers;
};
-struct m2ua_msg_part {
+struct xua_msg_part {
struct llist_head entry;
uint16_t tag;
@@ -43,16 +40,14 @@ struct m2ua_msg_part {
};
-struct m2ua_msg *m2ua_msg_alloc(void);
-void m2ua_msg_free(struct m2ua_msg *msg);
-
-int m2ua_msg_add_data(struct m2ua_msg *msg, uint16_t tag, uint16_t len, uint8_t *dat);
+struct xua_msg *xua_msg_alloc(void);
+void xua_msg_free(struct xua_msg *msg);
-struct m2ua_msg_part *m2ua_msg_find_tag(struct m2ua_msg *msg, uint16_t tag);
+int xua_msg_add_data(struct xua_msg *msg, uint16_t tag, uint16_t len, uint8_t *dat);
-struct m2ua_msg *m2ua_from_msg(uint16_t len, uint8_t *data);
-struct msgb *m2ua_to_msg(struct m2ua_msg *msg);
+struct xua_msg_part *xua_msg_find_tag(struct xua_msg *msg, uint16_t tag);
-void m2ua_set_log_area(int log_area);
+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);
-#endif
+void xua_set_log_area(int log_area);
diff --git a/include/sigtran/xua_types.h b/include/sigtran/xua_types.h
index 7a74d91..6568283 100644
--- a/include/sigtran/xua_types.h
+++ b/include/sigtran/xua_types.h
@@ -1,5 +1,7 @@
#pragma once
+#include <stdint.h>
+
/**
* Common tag values used by all user adaption layers
*/
@@ -26,3 +28,18 @@ enum {
MUA_TAG_CORREL_ID, /* Correlation Id */
};
+struct xua_common_hdr {
+ uint8_t version;
+ uint8_t spare;
+ uint8_t msg_class;
+ uint8_t msg_type;
+ uint32_t msg_length;
+ uint8_t data[0];
+} __attribute__((packed));
+
+
+struct xua_parameter_hdr {
+ uint16_t tag;
+ uint16_t len;
+ uint8_t data[0];
+} __attribute__((packed));
diff --git a/src/Makefile.am b/src/Makefile.am
index 584c3bd..fa47e85 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,8 +2,8 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)
AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS)
sccpdir = $(libdir)
-sccp_LIBRARIES = libsccp.a libmtp.a libm2ua.a
+sccp_LIBRARIES = libsccp.a libmtp.a libxua.a
libsccp_a_SOURCES = sccp.c
libmtp_a_SOURCES = mtp_pcap.c
-libm2ua_a_SOURCES = m2ua_msg.c
+libxua_a_SOURCES = xua_msg.c
diff --git a/src/m2ua_msg.c b/src/xua_msg.c
index 8e053e9..e10b942 100644
--- a/src/m2ua_msg.c
+++ b/src/xua_msg.c
@@ -16,7 +16,7 @@
*
*/
-#include <sigtran/m2ua_msg.h>
+#include <sigtran/xua_msg.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/logging.h>
@@ -26,16 +26,16 @@
#include <string.h>
-static void *tall_m2ua;
-static int DM2UA = -1;
+static void *tall_xua;
+static int DXUA = -1;
-struct m2ua_msg *m2ua_msg_alloc(void)
+struct xua_msg *xua_msg_alloc(void)
{
- struct m2ua_msg *msg;
+ struct xua_msg *msg;
- msg = talloc_zero(tall_m2ua, struct m2ua_msg);
+ msg = talloc_zero(tall_xua, struct xua_msg);
if (!msg) {
- LOGP(DM2UA, LOGL_ERROR, "Failed to allocate.\n");
+ LOGP(DXUA, LOGL_ERROR, "Failed to allocate.\n");
return NULL;
}
@@ -43,17 +43,17 @@ struct m2ua_msg *m2ua_msg_alloc(void)
return msg;
}
-void m2ua_msg_free(struct m2ua_msg *msg)
+void xua_msg_free(struct xua_msg *msg)
{
talloc_free(msg);
}
-int m2ua_msg_add_data(struct m2ua_msg *msg, uint16_t tag,
+int xua_msg_add_data(struct xua_msg *msg, uint16_t tag,
uint16_t len, uint8_t *dat)
{
- struct m2ua_msg_part *part;
+ struct xua_msg_part *part;
- part = talloc_zero(msg, struct m2ua_msg_part);
+ part = talloc_zero(msg, struct xua_msg_part);
if (!part)
return -1;
@@ -73,34 +73,34 @@ int m2ua_msg_add_data(struct m2ua_msg *msg, uint16_t tag,
return 0;
}
-struct m2ua_msg_part *m2ua_msg_find_tag(struct m2ua_msg *m2ua, uint16_t tag)
+struct xua_msg_part *xua_msg_find_tag(struct xua_msg *xua, uint16_t tag)
{
- struct m2ua_msg_part *part;
+ struct xua_msg_part *part;
- llist_for_each_entry(part, &m2ua->headers, entry)
+ llist_for_each_entry(part, &xua->headers, entry)
if (part->tag == tag)
return part;
return NULL;
}
-struct m2ua_msg *m2ua_from_msg(uint16_t len, uint8_t *data)
+struct xua_msg *xua_from_msg(const int version, uint16_t len, uint8_t *data)
{
- struct m2ua_parameter_hdr *par;
- struct m2ua_common_hdr *hdr;
- struct m2ua_msg *msg;
+ struct xua_parameter_hdr *par;
+ struct xua_common_hdr *hdr;
+ struct xua_msg *msg;
uint16_t pos, par_len, padding;
int rc;
- msg = m2ua_msg_alloc();
+ msg = xua_msg_alloc();
if (!msg)
return NULL;
if (len < sizeof(*hdr))
goto fail;
- hdr = (struct m2ua_common_hdr *) data;
- if (hdr->version != M2UA_VERSION)
+ hdr = (struct xua_common_hdr *) data;
+ if (hdr->version != version)
goto fail;
if (ntohl(hdr->msg_length) > len)
goto fail;
@@ -109,13 +109,13 @@ struct m2ua_msg *m2ua_from_msg(uint16_t len, uint8_t *data)
pos = sizeof(*hdr);
while (pos + sizeof(*par) < len) {
- par = (struct m2ua_parameter_hdr *) &data[pos];
+ par = (struct xua_parameter_hdr *) &data[pos];
par_len = ntohs(par->len);
if (pos + par_len > len || par_len < 4)
goto fail;
- rc = m2ua_msg_add_data(msg, ntohs(par->tag),
+ rc = xua_msg_add_data(msg, ntohs(par->tag),
par_len - 4, par->data);
if (rc != 0)
goto fail;
@@ -131,33 +131,33 @@ struct m2ua_msg *m2ua_from_msg(uint16_t len, uint8_t *data)
return msg;
fail:
- LOGP(DM2UA, LOGL_ERROR, "Failed to parse.\n");
- m2ua_msg_free(msg);
+ LOGP(DXUA, LOGL_ERROR, "Failed to parse.\n");
+ xua_msg_free(msg);
return NULL;
}
-struct msgb *m2ua_to_msg(struct m2ua_msg *m2ua)
+struct msgb *xua_to_msg(const int version, struct xua_msg *xua)
{
- struct m2ua_msg_part *part;
- struct m2ua_common_hdr *hdr;
+ struct xua_msg_part *part;
+ struct xua_common_hdr *hdr;
struct msgb *msg;
uint8_t rest;
- msg = msgb_alloc_headroom(2048, 512, "m2ua msg");
+ msg = msgb_alloc_headroom(2048, 512, "xua msg");
if (!msg) {
- LOGP(DM2UA, LOGL_ERROR, "Failed to allocate.\n");
+ LOGP(DXUA, LOGL_ERROR, "Failed to allocate.\n");
return NULL;
}
msg->l2h = msgb_put(msg, sizeof(*hdr));
- hdr = (struct m2ua_common_hdr *) msg->l2h;
- memcpy(hdr, &m2ua->hdr, sizeof(*hdr));
+ hdr = (struct xua_common_hdr *) msg->l2h;
+ memcpy(hdr, &xua->hdr, sizeof(*hdr));
/* make sure that is right */
- hdr->version = M2UA_VERSION;
+ hdr->version = version;
hdr->spare = 0;
- llist_for_each_entry(part, &m2ua->headers, entry) {
+ llist_for_each_entry(part, &xua->headers, entry) {
msgb_put_u16(msg, part->tag);
msgb_put_u16(msg, part->len + 4);
if (part->dat) {
@@ -178,7 +178,7 @@ struct msgb *m2ua_to_msg(struct m2ua_msg *m2ua)
return msg;
}
-void m2ua_set_log_area(int log_area)
+void xua_set_log_area(int log_area)
{
- DM2UA = log_area;
+ DXUA = log_area;
}
diff --git a/tests/m2ua/Makefile.am b/tests/m2ua/Makefile.am
index 7299e9b..33618ef 100644
--- a/tests/m2ua/Makefile.am
+++ b/tests/m2ua/Makefile.am
@@ -5,4 +5,4 @@ EXTRA_DIST = m2ua_test.ok
noinst_PROGRAMS = m2ua_test
m2ua_test_SOURCES = m2ua_test.c
-m2ua_test_LDADD = $(top_builddir)/src/libm2ua.a $(LIBOSMOCORE_LIBS)
+m2ua_test_LDADD = $(top_builddir)/src/libxua.a $(LIBOSMOCORE_LIBS)
diff --git a/tests/m2ua/m2ua_test.c b/tests/m2ua/m2ua_test.c
index 1699d92..e432f96 100644
--- a/tests/m2ua/m2ua_test.c
+++ b/tests/m2ua/m2ua_test.c
@@ -15,7 +15,8 @@
*
*/
-#include <sigtran/m2ua_msg.h>
+#include <sigtran/xua_msg.h>
+#include <sigtran/m2ua_types.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/msgb.h>
@@ -46,9 +47,9 @@ static uint8_t data[] = {
static void test_asp_up(void)
{
- struct m2ua_msg_part *part;
- struct m2ua_msg *m2u = m2ua_from_msg(ARRAY_SIZE(asp_up), asp_up);
- struct msgb *msg = m2ua_to_msg(m2u);
+ struct xua_msg_part *part;
+ struct xua_msg *m2u = xua_from_msg(M2UA_VERSION, ARRAY_SIZE(asp_up), asp_up);
+ struct msgb *msg = xua_to_msg(M2UA_VERSION, m2u);
const uint8_t res[] = { 0xac, 0x10, 0x01, 0x51 };
printf("Testing ASP UP parsing.\n");
@@ -63,7 +64,7 @@ static void test_asp_up(void)
FAIL("Wrong memory");
}
- part = m2ua_msg_find_tag(m2u, 0x11);
+ part = xua_msg_find_tag(m2u, 0x11);
if (!part)
FAIL("Could not find part");
if (part->len != 4)
@@ -71,15 +72,15 @@ static void test_asp_up(void)
if (memcmp(part->dat, res, 4) != 0)
FAIL("Wrong result for the tag\n");
- m2ua_msg_free(m2u);
+ xua_msg_free(m2u);
msgb_free(msg);
}
static void test_data(void)
{
- struct m2ua_msg_part *part;
- struct m2ua_msg *m2u = m2ua_from_msg(ARRAY_SIZE(data), data);
- struct msgb *msg = m2ua_to_msg(m2u);
+ struct xua_msg_part *part;
+ struct xua_msg *m2u = xua_from_msg(M2UA_VERSION, ARRAY_SIZE(data), data);
+ struct msgb *msg = xua_to_msg(M2UA_VERSION, m2u);
printf("Testing parsing of data.\n");
@@ -93,7 +94,7 @@ static void test_data(void)
FAIL("Wrong memory");
}
- part = m2ua_msg_find_tag(m2u, 0x300);
+ part = xua_msg_find_tag(m2u, 0x300);
if (!part)
FAIL("Could not find part");
if (part->len != 22) {
@@ -101,7 +102,7 @@ static void test_data(void)
FAIL("Part is not of length 22\n");
}
- m2ua_msg_free(m2u);
+ xua_msg_free(m2u);
msgb_free(msg);
}