libosmo-sigtran 2.1.0.187-fd10 Osmocom SIGTRAN library

xua_msg.h
Go to the documentation of this file.
1/* Routines for generating and parsing messages */
2/* (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18#pragma once
19
20#include "xua_types.h"
21
22#include <osmocom/core/linuxlist.h>
23#include <osmocom/sigtran/mtp_sap.h>
24
25#define XUA_HDR(class, type) ((struct xua_common_hdr) { .spare = 0, .msg_class = (class), .msg_type = (type) })
26
27 struct msgb;
28 struct osmo_sccp_addr;
29 struct osmo_sccp_gt;
30
31 struct xua_msg {
32 struct llist_head entry; /* Allows queueing a xua_msg into a llist */
33 struct xua_common_hdr hdr;
34 struct osmo_mtp_transfer_param mtp;
35
36 struct llist_head headers;
37};
38
39 struct xua_msg_part {
40 struct llist_head entry;
41
42 uint16_t tag;
43 uint16_t len;
44 uint8_t *dat;
45
46 /* TODO: keep small data in the struct for perf reasons */
47};
48
49 struct xua_msg_class {
50 const char *name;
51 const struct value_string *msgt_names;
52 const struct value_string *iei_names;
53 const uint16_t *mand_ies[256];
54};
55
56 struct xua_dialect {
57 const char *name;
58 uint16_t port;
59 uint16_t ppid;
60 int log_subsys;
61 const struct xua_msg_class *class[256];
62};
63
64 struct xua_msg_event_map {
65 uint8_t msg_class;
66 uint8_t msg_type;
67 int event;
68};
69
70 extern const struct xua_dialect xua_dialect_sua;
71 extern const struct xua_dialect xua_dialect_m3ua;
72
73 void osmo_xua_msg_tall_ctx_init(void *ctx);
74
75 struct xua_msg *xua_msg_alloc(void);
76 void xua_msg_free(struct xua_msg *msg);
77 struct xua_msg *xua_msg_copy(const struct xua_msg *xua_in);
78
79 int xua_msg_add_data(struct xua_msg *msg, uint16_t tag, uint16_t len, const uint8_t *dat);
80 int xua_msg_add_u32_data(struct xua_msg *msg, uint16_t tag, uint16_t len, const uint8_t *dat);
81
82 struct xua_msg_part *xua_msg_find_tag(const struct xua_msg *msg, uint16_t tag);
83 int xua_msg_free_tag(struct xua_msg *xua, uint16_t tag);
84 int xua_msg_copy_part(struct xua_msg *xua_out, uint16_t tag_out,
85 const struct xua_msg *xua_in, uint16_t tag_in);
86
87 struct xua_msg *xua_from_msg(const int version, uint16_t len, uint8_t *data);
88 struct msgb *xua_to_msg(const int version, struct xua_msg *msg);
89
90 struct xua_msg *xua_from_nested(struct xua_msg_part *outer);
91
92 int msgb_t16l16vp_put(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *data);
93 int msgb_t16l16vp_put_u32(struct msgb *msg, uint16_t tag, uint32_t val);
94 int xua_msg_add_u32(struct xua_msg *xua, uint16_t iei, uint32_t val);
95uint32_t xua_msg_part_get_u32(const struct xua_msg_part *part);
96uint32_t xua_msg_get_u32(const struct xua_msg *xua, uint16_t iei);
97 const uint32_t *xua_msg_get_u32p(const struct xua_msg *xua, uint16_t iei, uint32_t *out);
98 const char *xua_msg_part_get_str(const struct xua_msg_part *part);
99 const char *xua_msg_get_str(const struct xua_msg *xua, uint16_t iei);
100 int xua_msg_get_len(const struct xua_msg *xua, uint16_t iei);
101 void xua_part_add_gt(struct msgb *msg, const struct osmo_sccp_gt *gt);
102 int xua_msg_add_sccp_addr(struct xua_msg *xua, uint16_t iei, const struct osmo_sccp_addr *addr);
103
104 const char *xua_class_msg_name(const struct xua_msg_class *xmc, uint16_t msg_type);
105 const char *xua_class_iei_name(const struct xua_msg_class *xmc, uint16_t iei);
106 char *xua_hdr_dump(const struct xua_msg *xua, const struct xua_dialect *dialect);
107 char *xua_msg_dump(const struct xua_msg *xua, const struct xua_dialect *dialect);
108 int xua_dialect_check_all_mand_ies(const struct xua_dialect *dialect, struct xua_msg *xua);
109
110 int xua_msg_event_map(const struct xua_msg *xua,
111 const struct xua_msg_event_map *maps,
112 unsigned int num_maps);
osmo_xua_msg_tall_ctx_init
void osmo_xua_msg_tall_ctx_init(void *ctx)
Definition: xua_msg.c:39
mtp_sap.h
msg_type
uint8_t msg_type
Definition: sccp_scmg.h:0
xua_hdr_dump
char * xua_hdr_dump(const struct xua_msg *xua, const struct xua_dialect *dialect)
Definition: xua_msg.c:522
xua_class_iei_name
const char * xua_class_iei_name(const struct xua_msg_class *xmc, uint16_t iei)
Definition: xua_msg.c:510
xua_msg_free
void xua_msg_free(struct xua_msg *msg)
Definition: xua_msg.c:56
xua_msg_dump
char * xua_msg_dump(const struct xua_msg *xua, const struct xua_dialect *dialect)
Definition: xua_msg.c:569
xua_msg_get_u32p
const uint32_t * xua_msg_get_u32p(const struct xua_msg *xua, uint16_t iei, uint32_t *out)
Definition: xua_msg.c:348
xua_dialect_m3ua
const struct xua_dialect xua_dialect_m3ua
Definition: m3ua.c:288
xua_msg_free_tag
int xua_msg_free_tag(struct xua_msg *xua, uint16_t tag)
Definition: xua_msg.c:144
xua_msg_get_str
const char * xua_msg_get_str(const struct xua_msg *xua, uint16_t iei)
Definition: xua_msg.c:372
xua_msg_get_len
int xua_msg_get_len(const struct xua_msg *xua, uint16_t iei)
Definition: xua_msg.c:380
xua_to_msg
struct msgb * xua_to_msg(const int version, struct xua_msg *msg)
Definition: xua_msg.c:250
xua_msg_add_data
int xua_msg_add_data(struct xua_msg *msg, uint16_t tag, uint16_t len, const uint8_t *dat)
Definition: xua_msg.c:76
xua_from_msg
struct xua_msg * xua_from_msg(const int version, uint16_t len, uint8_t *data)
Definition: xua_msg.c:198
xua_part_add_gt
void xua_part_add_gt(struct msgb *msg, const struct osmo_sccp_gt *gt)
Definition: xua_msg.c:388
msgb_t16l16vp_put
int msgb_t16l16vp_put(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *data)
Definition: xua_msg.c:294
msgb_t16l16vp_put_u32
int msgb_t16l16vp_put_u32(struct msgb *msg, uint16_t tag, uint32_t val)
Definition: xua_msg.c:320
xua_msg_add_u32
int xua_msg_add_u32(struct xua_msg *xua, uint16_t iei, uint32_t val)
Definition: xua_msg.c:327
xua_msg_add_u32_data
int xua_msg_add_u32_data(struct xua_msg *msg, uint16_t tag, uint16_t len, const uint8_t *dat)
Definition: xua_msg.c:102
xua_msg_part_get_u32
uint32_t xua_msg_part_get_u32(const struct xua_msg_part *part)
Definition: xua_msg.c:333
xua_from_nested
struct xua_msg * xua_from_nested(struct xua_msg_part *outer)
Definition: xua_msg.c:233
xua_msg_find_tag
struct xua_msg_part * xua_msg_find_tag(const struct xua_msg *msg, uint16_t tag)
Definition: xua_msg.c:133
xua_msg_copy_part
int xua_msg_copy_part(struct xua_msg *xua_out, uint16_t tag_out, const struct xua_msg *xua_in, uint16_t tag_in)
Definition: xua_msg.c:158
xua_msg_copy
struct xua_msg * xua_msg_copy(const struct xua_msg *xua_in)
Definition: xua_msg.c:61
xua_msg_add_sccp_addr
int xua_msg_add_sccp_addr(struct xua_msg *xua, uint16_t iei, const struct osmo_sccp_addr *addr)
Definition: xua_msg.c:426
xua_dialect_sua
const struct xua_dialect xua_dialect_sua
Definition: sua.c:221
xua_msg_get_u32
uint32_t xua_msg_get_u32(const struct xua_msg *xua, uint16_t iei)
Definition: xua_msg.c:339
xua_msg_part_get_str
const char * xua_msg_part_get_str(const struct xua_msg_part *part)
Definition: xua_msg.c:357
xua_msg_alloc
struct xua_msg * xua_msg_alloc(void)
Definition: xua_msg.c:44
xua_msg_event_map
int xua_msg_event_map(const struct xua_msg *xua, const struct xua_msg_event_map *maps, unsigned int num_maps)
Map from a xua_msg (class+type) to an event.
Definition: xua_msg.c:482
xua_class_msg_name
const char * xua_class_msg_name(const struct xua_msg_class *xmc, uint16_t msg_type)
Definition: xua_msg.c:498
xua_dialect_check_all_mand_ies
int xua_dialect_check_all_mand_ies(const struct xua_dialect *dialect, struct xua_msg *xua)
Definition: xua_msg.c:537
osmo_mtp_transfer_param
Definition: mtp_sap.h:42
osmo_sccp_addr
Definition: sccp_sap.h:183
osmo_sccp_gt
Definition: sccp_sap.h:175
xua_common_hdr
Definition: xua_types.h:31
xua_dialect
Definition: xua_msg.h:56
xua_dialect::port
uint16_t port
Definition: xua_msg.h:58
xua_dialect::ppid
uint16_t ppid
Definition: xua_msg.h:59
xua_dialect::log_subsys
int log_subsys
Definition: xua_msg.h:60
xua_dialect::name
const char * name
Definition: xua_msg.h:57
xua_msg_class
Definition: xua_msg.h:49
xua_msg_class::mand_ies
const uint16_t * mand_ies[256]
Definition: xua_msg.h:53
xua_msg_class::name
const char * name
Definition: xua_msg.h:50
xua_msg_class::iei_names
const struct value_string * iei_names
Definition: xua_msg.h:52
xua_msg_class::msgt_names
const struct value_string * msgt_names
Definition: xua_msg.h:51
xua_msg_event_map
Definition: xua_msg.h:64
xua_msg_event_map::msg_type
uint8_t msg_type
Definition: xua_msg.h:66
xua_msg_event_map::msg_class
uint8_t msg_class
Definition: xua_msg.h:65
xua_msg_event_map::event
int event
Definition: xua_msg.h:67
xua_msg_part
Definition: xua_msg.h:39
xua_msg_part::entry
struct llist_head entry
Definition: xua_msg.h:40
xua_msg_part::dat
uint8_t * dat
Definition: xua_msg.h:44
xua_msg_part::tag
uint16_t tag
Definition: xua_msg.h:42
xua_msg_part::len
uint16_t len
Definition: xua_msg.h:43
xua_msg
Definition: xua_msg.h:31
xua_msg::entry
struct llist_head entry
Definition: xua_msg.h:32
xua_msg::mtp
struct osmo_mtp_transfer_param mtp
Definition: xua_msg.h:34
xua_msg::hdr
struct xua_common_hdr hdr
Definition: xua_msg.h:33
xua_msg::headers
struct llist_head headers
Definition: xua_msg.h:36
xua_types.h
tag
uint16_t tag
Definition: xua_types.h:0
len
uint16_t len
Definition: xua_types.h:1
data
uint8_t data[0]
Definition: xua_types.h:5
version
uint8_t version
Definition: xua_types.h:0