aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/sigtran/xua_msg.h
blob: 9c3c49ca906f19cd4b3549e13170b09b864a69ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Routines for generating and parsing messages */
/* (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
#pragma once

#include "xua_types.h"

#include <osmocom/core/linuxlist.h>
#include <osmocom/sigtran/mtp_sap.h>

#define XUA_HDR(class, type)	((struct xua_common_hdr) { .spare = 0, .msg_class = (class), .msg_type = (type) })

struct msgb;
struct osmo_sccp_addr;
struct osmo_sccp_gt;

struct xua_msg {
	struct xua_common_hdr hdr;
	struct osmo_mtp_transfer_param mtp;

	struct llist_head headers;
};

struct xua_msg_part {
	struct llist_head entry;

	uint16_t tag;
	uint16_t len;
	uint8_t  *dat;

	/* TODO: keep small data in the struct for perf reasons */
};

struct xua_msg_class {
	const char *name;
	const struct value_string *msgt_names;
	const struct value_string *iei_names;
	const uint16_t *mand_ies[256];
};

struct xua_dialect {
	const char *name;
	uint16_t port;
	uint16_t ppid;
	int log_subsys;
	const struct xua_msg_class *class[256];
};

struct xua_msg_event_map {
	uint8_t msg_class;
	uint8_t msg_type;
	int event;
};

extern const struct xua_dialect xua_dialect_sua;
extern const struct xua_dialect xua_dialect_m3ua;

void osmo_xua_msg_tall_ctx_init(void *ctx);

#define xua_msg_alloc() _xua_msg_alloc(__FILE__, __LINE__)
struct xua_msg *_xua_msg_alloc(const char *file, int line);
void xua_msg_free(struct xua_msg *msg);

int xua_msg_add_data(struct xua_msg *msg, uint16_t tag, uint16_t len, uint8_t *dat);

struct xua_msg_part *xua_msg_find_tag(const struct xua_msg *msg, uint16_t tag);
int xua_msg_free_tag(struct xua_msg *xua, uint16_t tag);
int xua_msg_copy_part(struct xua_msg *xua_out, uint16_t tag_out,
		      const struct xua_msg *xua_in, uint16_t tag_in);

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);
uint32_t xua_msg_part_get_u32(struct xua_msg_part *part);
uint32_t xua_msg_get_u32(struct xua_msg *xua, uint16_t iei);
void xua_part_add_gt(struct msgb *msg, const struct osmo_sccp_gt *gt);
int xua_msg_add_sccp_addr(struct xua_msg *xua, uint16_t iei, const struct osmo_sccp_addr *addr);

const char *xua_class_msg_name(const struct xua_msg_class *xmc, uint16_t msg_type);
const char *xua_class_iei_name(const struct xua_msg_class *xmc, uint16_t iei);
char *xua_hdr_dump(struct xua_msg *xua, const struct xua_dialect *dialect);
char *xua_msg_dump(struct xua_msg *xua, const struct xua_dialect *dialect);
int xua_dialect_check_all_mand_ies(const struct xua_dialect *dialect, struct xua_msg *xua);

int xua_msg_event_map(const struct xua_msg *xua,
		      const struct xua_msg_event_map *maps,
		      unsigned int num_maps);