libosmo-sigtran  1.9.0.4-dc82
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>
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 {
34 
35  struct llist_head headers;
36 };
37 
38 struct xua_msg_part {
39  struct llist_head entry;
40 
41  uint16_t tag;
42  uint16_t len;
43  uint8_t *dat;
44 
45  /* TODO: keep small data in the struct for perf reasons */
46 };
47 
48 struct xua_msg_class {
49  const char *name;
50  const struct value_string *msgt_names;
51  const struct value_string *iei_names;
52  const uint16_t *mand_ies[256];
53 };
54 
55 struct xua_dialect {
56  const char *name;
57  uint16_t port;
58  uint16_t ppid;
60  const struct xua_msg_class *class[256];
61 };
62 
64  uint8_t msg_class;
65  uint8_t msg_type;
66  int event;
67 };
68 
69 extern const struct xua_dialect xua_dialect_sua;
70 extern const struct xua_dialect xua_dialect_m3ua;
71 
72 void osmo_xua_msg_tall_ctx_init(void *ctx);
73 
74 struct xua_msg *xua_msg_alloc(void);
75 void xua_msg_free(struct xua_msg *msg);
76 
77 int xua_msg_add_data(struct xua_msg *msg, uint16_t tag, uint16_t len, const uint8_t *dat);
78 
79 struct xua_msg_part *xua_msg_find_tag(const struct xua_msg *msg, uint16_t tag);
80 int xua_msg_free_tag(struct xua_msg *xua, uint16_t tag);
81 int xua_msg_copy_part(struct xua_msg *xua_out, uint16_t tag_out,
82  const struct xua_msg *xua_in, uint16_t tag_in);
83 
84 struct xua_msg *xua_from_msg(const int version, uint16_t len, uint8_t *data);
85 struct msgb *xua_to_msg(const int version, struct xua_msg *msg);
86 
87 struct xua_msg *xua_from_nested(struct xua_msg_part *outer);
88 
89 int msgb_t16l16vp_put(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *data);
90 int msgb_t16l16vp_put_u32(struct msgb *msg, uint16_t tag, uint32_t val);
91 int xua_msg_add_u32(struct xua_msg *xua, uint16_t iei, uint32_t val);
92 uint32_t xua_msg_part_get_u32(const struct xua_msg_part *part);
93 uint32_t xua_msg_get_u32(const struct xua_msg *xua, uint16_t iei);
94 const uint32_t *xua_msg_get_u32p(const struct xua_msg *xua, uint16_t iei, uint32_t *out);
95 const char *xua_msg_part_get_str(const struct xua_msg_part *part);
96 const char *xua_msg_get_str(const struct xua_msg *xua, uint16_t iei);
97 int xua_msg_get_len(const struct xua_msg *xua, uint16_t iei);
98 void xua_part_add_gt(struct msgb *msg, const struct osmo_sccp_gt *gt);
99 int xua_msg_add_sccp_addr(struct xua_msg *xua, uint16_t iei, const struct osmo_sccp_addr *addr);
100 
101 const char *xua_class_msg_name(const struct xua_msg_class *xmc, uint16_t msg_type);
102 const char *xua_class_iei_name(const struct xua_msg_class *xmc, uint16_t iei);
103 char *xua_hdr_dump(struct xua_msg *xua, const struct xua_dialect *dialect);
104 char *xua_msg_dump(struct xua_msg *xua, const struct xua_dialect *dialect);
105 int xua_dialect_check_all_mand_ies(const struct xua_dialect *dialect, struct xua_msg *xua);
106 
107 int xua_msg_event_map(const struct xua_msg *xua,
108  const struct xua_msg_event_map *maps,
109  unsigned int num_maps);
int log_subsys
Definition: xua_msg.h:59
uint8_t version
Definition: xua_types.h:67
int msgb_t16l16vp_put_u32(struct msgb *msg, uint16_t tag, uint32_t val)
Definition: xua_msg.c:273
struct xua_msg * xua_from_nested(struct xua_msg_part *outer)
Definition: xua_msg.c:186
uint16_t port
Definition: xua_msg.h:57
Definition: xua_msg.h:55
uint8_t * dat
Definition: xua_msg.h:43
uint8_t msg_type
Definition: sccp_scmg.h:38
int msgb_t16l16vp_put(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *data)
Definition: xua_msg.c:247
uint16_t len
Definition: xua_msg.h:42
const char * xua_msg_part_get_str(const struct xua_msg_part *part)
Definition: xua_msg.c:310
char * xua_msg_dump(struct xua_msg *xua, const struct xua_dialect *dialect)
Definition: xua_msg.c:522
const struct value_string * msgt_names
Definition: xua_msg.h:50
struct xua_msg * xua_msg_alloc(void)
Definition: xua_msg.c:44
int xua_msg_add_u32(struct xua_msg *xua, uint16_t iei, uint32_t val)
Definition: xua_msg.c:280
const char * name
Definition: xua_msg.h:49
Definition: xua_msg.h:38
uint8_t msg_type
Definition: xua_msg.h:65
int xua_msg_add_data(struct xua_msg *msg, uint16_t tag, uint16_t len, const uint8_t *dat)
Definition: xua_msg.c:61
uint8_t msg_class
Definition: xua_msg.h:64
Definition: xua_msg.h:63
struct xua_msg * xua_from_msg(const int version, uint16_t len, uint8_t *data)
Definition: xua_msg.c:151
void osmo_xua_msg_tall_ctx_init(void *ctx)
Definition: xua_msg.c:39
int xua_msg_free_tag(struct xua_msg *xua, uint16_t tag)
Definition: xua_msg.c:97
uint16_t tag
Definition: xua_msg.h:41
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:111
uint16_t tag
Definition: xua_types.h:67
const char * xua_class_msg_name(const struct xua_msg_class *xmc, uint16_t msg_type)
Definition: xua_msg.c:451
int xua_msg_add_sccp_addr(struct xua_msg *xua, uint16_t iei, const struct osmo_sccp_addr *addr)
Definition: xua_msg.c:379
const struct xua_dialect xua_dialect_sua
Definition: sua.c:218
Definition: xua_msg.h:48
void xua_msg_free(struct xua_msg *msg)
Definition: xua_msg.c:56
struct msgb * xua_to_msg(const int version, struct xua_msg *msg)
Definition: xua_msg.c:203
const char * xua_class_iei_name(const struct xua_msg_class *xmc, uint16_t iei)
Definition: xua_msg.c:463
int event
Definition: xua_msg.h:66
Definition: mtp_sap.h:36
Definition: xua_types.h:31
const char * name
Definition: xua_msg.h:56
Definition: sccp_sap.h:183
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:435
Definition: sccp_sap.h:175
struct xua_common_hdr hdr
Definition: xua_msg.h:32
char * xua_hdr_dump(struct xua_msg *xua, const struct xua_dialect *dialect)
Definition: xua_msg.c:475
Definition: xua_msg.h:31
uint8_t data[0]
Definition: xua_types.h:72
uint16_t ppid
Definition: xua_msg.h:58
const uint32_t * xua_msg_get_u32p(const struct xua_msg *xua, uint16_t iei, uint32_t *out)
Definition: xua_msg.c:301
struct llist_head headers
Definition: xua_msg.h:35
struct xua_msg_part * xua_msg_find_tag(const struct xua_msg *msg, uint16_t tag)
Definition: xua_msg.c:86
uint32_t xua_msg_get_u32(const struct xua_msg *xua, uint16_t iei)
Definition: xua_msg.c:292
int xua_dialect_check_all_mand_ies(const struct xua_dialect *dialect, struct xua_msg *xua)
Definition: xua_msg.c:490
const struct value_string * iei_names
Definition: xua_msg.h:51
const struct xua_dialect xua_dialect_m3ua
Definition: m3ua.c:273
uint16_t len
Definition: xua_types.h:68
uint32_t xua_msg_part_get_u32(const struct xua_msg_part *part)
Definition: xua_msg.c:286
const char * xua_msg_get_str(const struct xua_msg *xua, uint16_t iei)
Definition: xua_msg.c:325
int xua_msg_get_len(const struct xua_msg *xua, uint16_t iei)
Definition: xua_msg.c:333
void xua_part_add_gt(struct msgb *msg, const struct osmo_sccp_gt *gt)
Definition: xua_msg.c:341
struct osmo_mtp_transfer_param mtp
Definition: xua_msg.h:33