libosmo-sigtran  2.3.0.34-f51d.202609021800
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 #include <stdint.h>
25 #include <stdint.h>
26 
27 #define XUA_HDR(class, type) ((struct xua_common_hdr) { .spare = 0, .msg_class = (class), .msg_type = (type) })
28 
29 struct msgb;
30 struct osmo_sccp_addr;
31 struct osmo_sccp_gt;
32 
33 struct xua_msg {
34  struct llist_head entry; /* Allows queueing a xua_msg into a llist */
35  struct xua_common_hdr hdr;
37 
38  struct llist_head headers;
39 };
40 
41 struct xua_msg_part {
42  struct llist_head entry;
43 
44  uint16_t tag;
45  uint16_t len;
46  uint8_t *dat;
47 
48  /* TODO: keep small data in the struct for perf reasons */
49 };
50 
51 #define XUA_MSG_PART_CLASS_MAX_LEN UINT16_MAX
53  uint16_t tag;
54  bool mandatory;
55  bool multiple; /* whether more than one IE are possible in the msg */
56  uint16_t len_min;
57  uint16_t len_max;
58 };
59 #define XUA_MSG_PART_CLASS(tag_, mandatory_, multiple_, len_min_, len_max_) \
60  { .tag = (tag_), \
61  .mandatory = (mandatory_), \
62  .multiple = (multiple_), \
63  .len_min = (len_min_), \
64  .len_max = (len_max_) \
65  }
66 #define XUA_MSG_PART_CLASS_UNBOUND(tag, mandatory) \
67  XUA_MSG_PART_CLASS((tag), (mandatory), false, 0, XUA_MSG_PART_CLASS_MAX_LEN)
68 #define XUA_MSG_PART_CLASS_FIXED(tag, mandatory, len) \
69  XUA_MSG_PART_CLASS((tag), (mandatory), false, (len), (len))
70 #define XUA_MSG_PART_CLASS_U32(tag, mandatory) \
71  XUA_MSG_PART_CLASS_FIXED((tag), (mandatory), sizeof(uint32_t))
72 #define XUA_MSG_PART_CLASS_EOF \
73  XUA_MSG_PART_CLASS(0, false, false, 0, 0)
74 
75 struct xua_msg_class {
76  const char *name;
77  const struct value_string *msgt_names;
78  const struct value_string *iei_names;
79  const struct xua_msg_part_class *ies[256];
80 };
81 
82 struct xua_dialect {
83  const char *name;
84  uint16_t port;
85  uint16_t ppid;
87  const struct xua_msg_class *class[256];
88 };
89 
91  uint8_t msg_class;
92  uint8_t msg_type;
93  int event;
94 };
95 
96 extern const struct xua_dialect xua_dialect_sua;
97 extern const struct xua_dialect xua_dialect_m3ua;
98 
99 void osmo_xua_msg_tall_ctx_init(void *ctx);
100 
101 struct xua_msg *xua_msg_alloc(void);
102 void xua_msg_free(struct xua_msg *msg);
103 struct xua_msg *xua_msg_copy(const struct xua_msg *xua_in);
104 
105 int xua_msg_add_data(struct xua_msg *msg, uint16_t tag, uint16_t len, const uint8_t *dat);
106 int xua_msg_add_u32_data(struct xua_msg *msg, uint16_t tag, uint16_t len, const uint8_t *dat);
107 
108 struct xua_msg_part *xua_msg_find_tag(const struct xua_msg *msg, uint16_t tag);
109 int xua_msg_free_tag(struct xua_msg *xua, uint16_t tag);
110 int xua_msg_copy_part(struct xua_msg *xua_out, uint16_t tag_out,
111  const struct xua_msg *xua_in, uint16_t tag_in);
112 
113 struct xua_msg *xua_from_msg(const int version, uint16_t len, uint8_t *data);
114 struct msgb *xua_to_msg(const int version, struct xua_msg *msg);
115 
116 struct xua_msg *xua_from_nested(struct xua_msg_part *outer);
117 
118 int msgb_t16l16vp_put(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *data);
119 int msgb_t16l16vp_put_u32(struct msgb *msg, uint16_t tag, uint32_t val);
120 int xua_msg_add_u32(struct xua_msg *xua, uint16_t iei, uint32_t val);
121 uint32_t xua_msg_part_get_u32(const struct xua_msg_part *part);
122 uint32_t xua_msg_get_u32(const struct xua_msg *xua, uint16_t iei);
123 const uint32_t *xua_msg_get_u32p(const struct xua_msg *xua, uint16_t iei, uint32_t *out);
124 const char *xua_msg_part_get_str(const struct xua_msg_part *part);
125 const char *xua_msg_get_str(const struct xua_msg *xua, uint16_t iei);
126 int xua_msg_get_len(const struct xua_msg *xua, uint16_t iei);
127 void xua_part_add_gt(struct msgb *msg, const struct osmo_sccp_gt *gt);
128 int xua_msg_add_sccp_addr(struct xua_msg *xua, uint16_t iei, const struct osmo_sccp_addr *addr);
129 
130 const char *xua_class_msg_name(const struct xua_msg_class *xmc, uint16_t msg_type);
131 const char *xua_class_iei_name(const struct xua_msg_class *xmc, uint16_t iei);
132 char *xua_hdr_dump(const struct xua_msg *xua, const struct xua_dialect *dialect);
133 char *xua_msg_dump(const struct xua_msg *xua, const struct xua_dialect *dialect);
134 int xua_dialect_check_all_ies(const struct xua_dialect *dialect, const struct xua_msg *xua);
135 int xua_dialect_check_all_ies_ext(const struct xua_dialect *dialect, const struct xua_msg_class *xmc,
136  uint8_t msg_type, const struct xua_msg_part_class *ies,
137  const struct xua_msg *xua);
138 
139 int xua_msg_event_map(const struct xua_msg *xua,
140  const struct xua_msg_event_map *maps,
141  unsigned int num_maps);
void osmo_xua_msg_tall_ctx_init(void *ctx)
Definition: xua_msg.c:40
uint8_t msg_type
Definition: sccp_scmg.h:0
struct xua_msg_part * xua_msg_find_tag(const struct xua_msg *msg, uint16_t tag)
Definition: xua_msg.c:134
void xua_msg_free(struct xua_msg *msg)
Definition: xua_msg.c:57
char * xua_hdr_dump(const struct xua_msg *xua, const struct xua_dialect *dialect)
Definition: xua_msg.c:523
const struct xua_dialect xua_dialect_m3ua
Definition: m3ua.c:508
const uint32_t * xua_msg_get_u32p(const struct xua_msg *xua, uint16_t iei, uint32_t *out)
Definition: xua_msg.c:349
int xua_msg_free_tag(struct xua_msg *xua, uint16_t tag)
Definition: xua_msg.c:145
int xua_msg_get_len(const struct xua_msg *xua, uint16_t iei)
Definition: xua_msg.c:381
int xua_msg_add_data(struct xua_msg *msg, uint16_t tag, uint16_t len, const uint8_t *dat)
Definition: xua_msg.c:77
struct xua_msg * xua_msg_alloc(void)
Definition: xua_msg.c:45
char * xua_msg_dump(const struct xua_msg *xua, const struct xua_dialect *dialect)
Definition: xua_msg.c:598
void xua_part_add_gt(struct msgb *msg, const struct osmo_sccp_gt *gt)
Definition: xua_msg.c:389
int msgb_t16l16vp_put(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *data)
Definition: xua_msg.c:295
int xua_dialect_check_all_ies(const struct xua_dialect *dialect, const struct xua_msg *xua)
Definition: xua_msg.c:579
int msgb_t16l16vp_put_u32(struct msgb *msg, uint16_t tag, uint32_t val)
Definition: xua_msg.c:321
const char * xua_msg_get_str(const struct xua_msg *xua, uint16_t iei)
Definition: xua_msg.c:373
int xua_msg_add_u32(struct xua_msg *xua, uint16_t iei, uint32_t val)
Definition: xua_msg.c:328
int xua_msg_add_u32_data(struct xua_msg *msg, uint16_t tag, uint16_t len, const uint8_t *dat)
Definition: xua_msg.c:103
uint32_t xua_msg_part_get_u32(const struct xua_msg_part *part)
Definition: xua_msg.c:334
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:159
struct xua_msg * xua_from_msg(const int version, uint16_t len, uint8_t *data)
Definition: xua_msg.c:199
int xua_msg_add_sccp_addr(struct xua_msg *xua, uint16_t iei, const struct osmo_sccp_addr *addr)
Definition: xua_msg.c:427
const char * xua_msg_part_get_str(const struct xua_msg_part *part)
Definition: xua_msg.c:358
const struct xua_dialect xua_dialect_sua
Definition: sua.c:550
uint32_t xua_msg_get_u32(const struct xua_msg *xua, uint16_t iei)
Definition: xua_msg.c:340
struct xua_msg * xua_from_nested(struct xua_msg_part *outer)
Definition: xua_msg.c:234
struct msgb * xua_to_msg(const int version, struct xua_msg *msg)
Definition: xua_msg.c:251
const char * xua_class_msg_name(const struct xua_msg_class *xmc, uint16_t msg_type)
Definition: xua_msg.c:499
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:483
struct xua_msg * xua_msg_copy(const struct xua_msg *xua_in)
Definition: xua_msg.c:62
int xua_dialect_check_all_ies_ext(const struct xua_dialect *dialect, const struct xua_msg_class *xmc, uint8_t msg_type, const struct xua_msg_part_class *ies, const struct xua_msg *xua)
Definition: xua_msg.c:539
const char * xua_class_iei_name(const struct xua_msg_class *xmc, uint16_t iei)
Definition: xua_msg.c:511
Definition: mtp_sap.h:42
Definition: sccp_sap.h:183
Definition: sccp_sap.h:175
Definition: xua_types.h:31
Definition: xua_msg.h:82
uint16_t port
Definition: xua_msg.h:84
uint16_t ppid
Definition: xua_msg.h:85
int log_subsys
Definition: xua_msg.h:86
const char * name
Definition: xua_msg.h:83
Definition: xua_msg.h:75
const char * name
Definition: xua_msg.h:76
const struct value_string * iei_names
Definition: xua_msg.h:78
const struct value_string * msgt_names
Definition: xua_msg.h:77
const struct xua_msg_part_class * ies[256]
Definition: xua_msg.h:79
Definition: xua_msg.h:90
uint8_t msg_type
Definition: xua_msg.h:92
uint8_t msg_class
Definition: xua_msg.h:91
int event
Definition: xua_msg.h:93
Definition: xua_msg.h:52
uint16_t len_min
Definition: xua_msg.h:56
uint16_t tag
Definition: xua_msg.h:53
bool mandatory
Definition: xua_msg.h:54
bool multiple
Definition: xua_msg.h:55
uint16_t len_max
Definition: xua_msg.h:57
Definition: xua_msg.h:41
struct llist_head entry
Definition: xua_msg.h:42
uint8_t * dat
Definition: xua_msg.h:46
uint16_t tag
Definition: xua_msg.h:44
uint16_t len
Definition: xua_msg.h:45
Definition: xua_msg.h:33
struct llist_head entry
Definition: xua_msg.h:34
struct osmo_mtp_transfer_param mtp
Definition: xua_msg.h:36
struct xua_common_hdr hdr
Definition: xua_msg.h:35
struct llist_head headers
Definition: xua_msg.h:38
uint8_t data[0]
Definition: tcap_as_loadshare.c:2
uint16_t tag
Definition: xua_types.h:0
uint16_t len
Definition: xua_types.h:1
uint8_t version
Definition: xua_types.h:0