xua: Generalize the m2ua_msg and call it xua_msg
Generalize, this requires various API modifications but that is the most sane path forward.
This commit is contained in:
parent
4d244d3c31
commit
7046633c02
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
struct xua_msg *xua_msg_alloc(void);
|
||||
void xua_msg_free(struct xua_msg *msg);
|
||||
|
||||
int m2ua_msg_add_data(struct m2ua_msg *msg, uint16_t tag, uint16_t len, uint8_t *dat);
|
||||
int xua_msg_add_data(struct xua_msg *msg, uint16_t tag, uint16_t len, uint8_t *dat);
|
||||
|
||||
struct m2ua_msg_part *m2ua_msg_find_tag(struct m2ua_msg *msg, uint16_t tag);
|
||||
struct xua_msg_part *xua_msg_find_tag(struct xua_msg *msg, uint16_t tag);
|
||||
|
||||
struct m2ua_msg *m2ua_from_msg(uint16_t len, uint8_t *data);
|
||||
struct msgb *m2ua_to_msg(struct m2ua_msg *msg);
|
||||
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);
|
||||
|
||||
void m2ua_set_log_area(int log_area);
|
||||
|
||||
#endif
|
||||
void xua_set_log_area(int log_area);
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue