The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
sigtran.h
Go to the documentation of this file.
1 /*
2  * @copyright (c) 2016, Network RADIUS SAS (license@networkradius.com)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of Network RADIUS SAS nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /**
29  * $Id: c8deb64a8427b16d00790913ba1ecd115511c204 $
30  * @file sigtran.h
31  * @brief Declarations for various sigtran functions.
32  *
33  * @author Arran Cudbard-Bell
34  *
35  * @copyright 2016 Network RADIUS SAS (license@networkradius.com)
36  */
37 #include <osmocom/core/linuxlist.h>
38 #include <osmocom/core/timer.h>
39 #include <osmocom/sccp/sccp.h>
40 #include <osmocom/core/select.h>
41 
42 typedef enum {
43  SIGTRAN_REQUEST_THREAD_REGISTER, //!< New worker thread to register.
44  SIGTRAN_REQUEST_THREAD_UNREGISTER, //!< Worker thread to unregister.
45  SIGTRAN_REQUEST_LINK_UP, //!< Bring up a link.
46  SIGTRAN_REQUEST_LINK_DOWN, //!< Take down a link.
47  SIGTRAN_REQUEST_MAP_SEND_AUTH_INFO, //!< Request auth info.
48  SIGTRAN_REQUEST_EXIT //!< Causes the event loop to exit.
49 #ifndef NDEBUG
51 #endif
53 
54 typedef enum {
55  SIGTRAN_RESPONSE_OK, //!< Request succeeded
56  SIGTRAN_RESPONSE_NOOP, //!< Request did nothing
57  SIGTRAN_RESPONSE_NOTFOUND, //!< User or device Not found.
58  SIGTRAN_RESPONSE_FAIL //!< Request failed.
60 
61 /** Vector types
62  *
63  */
64 typedef enum {
65  SIGTRAN_VECTOR_TYPE_SIM_TRIPLETS, //!< RAND, SRES, Kc.
66  SIGTRAN_VECTOR_TYPE_UMTS_QUINTUPLETS //!< RAND, XRES, CK, IK, AUTN.
68 
69 /** Request and response from the event loop
70  *
71  * We allocate the whole thing on the client side, as the client
72  * will be blocked waiting on the response from the event loop,
73  * and won't mind extra memory being allocated from this ctx.
74  */
75 typedef struct sigtran_transaction {
76  fr_rb_node_t node; //!< Entry in the tree of transactions.
77 
78  struct {
79  sigtran_request_type_t type; //!< Type of request
80  void *data; //!< Data for the request.
82  struct {
83  sigtran_response_type_t type; //!< Type of response
84  void *data; //!< Data for the response.
86 
87  struct {
89  struct osmo_fd *ofd; //!< The FD the txn was received on.
90  struct osmo_timer_list timer; //!< Timer data.
91 
92 
93  uint32_t otid; //!< Transaction ID.
94  uint8_t invoke_id; //!< Sequence number (within transaction).
95 
96  bool defunct; //!< Response should be deleted and not
97  ///< processed.
98  } ctx;
100 
102  char const *address; //!< Address digits.
103 
104  uint8_t tt; //!< Translation type.
105  bool tt_is_set; //!< Translation_type was provided.
106 
107  uint8_t es; //!< Encoding scheme.
108  bool es_is_set; //!< Encoding scheme is set.
109 
110  uint8_t np; //!< Numbering plan
111  bool np_is_set; //!< Numbering plan is set.
112 
113  uint8_t nai; //!< Nature of address indicator.
114  bool nai_is_set; //!< Nature of address indicator is set.
116 
117 /** Structure representing a complete Q.173 SCCP address
118  *
119  */
120 typedef struct sigtran_sccp_address {
121  uint32_t pc; //!< 14bit point code.
122  bool pc_is_set; //!< Point code is set.
123 
124  uint8_t ssn; //!< Subsystem number.
125  bool ssn_is_set; //!< Subsystem number is set.
126 
128  bool gt_is_set; //!< Whether a global title was specified.
130 
131 typedef struct sigtran_m3ua_route {
132  uint32_t dpc; //!< Destination point code.
133  bool dpc_is_set; //!< Whether the DPC was set.
134 
135  uint32_t *opc; //!< Origin point code.
136 
137  uint32_t *si; //!< Service indicator.
139 
140 /** Configures a M3UA/MTP3/SCCP stack
141  *
142  */
143 typedef struct sigtran_conn_conf {
144  fr_ipaddr_t sctp_dst_ipaddr; //!< IP of the Service Gateway.
145  uint16_t sctp_dst_port; //!< SCTP port of the service gateway.
146 
147  fr_ipaddr_t sctp_src_ipaddr; //!< Local IP to originate traffic from.
148  uint16_t sctp_src_port; //!< Local port to originate traffic from.
149 
151 
152  uint32_t mtp3_dpc, mtp3_opc; //!< MTP3 point codes (24bit!).
159 
160  bool m3ua_routes_is_set; //!< Routes section was provided.
161  sigtran_m3ua_route_t m3ua_routes; //!< Routes to register with SG.
162 
163 
164  bool sccp_route_on_ssn; //!< Whether we should route on subsystem
165  //!< number.
166  bool sccp_ai8; //!< Address indicator bit 8
167 
168  sigtran_sccp_address_t sccp_calling; //!< The called SCCP address.
169  struct sockaddr_sccp sccp_calling_sockaddr; //!< Parsed version of the above.
170  sigtran_sccp_address_t sccp_called; //!< The calling SCCP address.
171  struct sockaddr_sccp sccp_called_sockaddr; //!< Parsed version of the above
172 
173  tmpl_t *map_version; //!< Application context version.
175 
176 /** Represents a connection to a remote SS7 entity
177  *
178  * Holds data necessary for M3UA/MTP3/SCCP.
179  */
180 typedef struct sigtran_conn {
182 
184  struct mtp_link_set *mtp3_link_set;
185  struct mtp_link *mtp3_link;
187 
188 /** MAP send auth info request.
189  *
190  */
192  sigtran_conn_t const *conn; //!< Connection to send request on.
193  uint8_t *imsi; //!< BCD encoded IMSI.
194  uint8_t version; //!< Application context version.
195  unsigned int num_vectors; //!< Number of vectors requested.
197 
198 typedef struct sigtran_vector sigtran_vector_t;
199 
200 /** Authentication vector returned by HLR
201  *
202  */
204  union {
205  struct {
206  uint8_t *rand; //!< Random challenge.
207  uint8_t *xres;
208  uint8_t *ck; //!< Encryption key.
209  uint8_t *ik; //!< Integrity key.
210  uint8_t *authn; //!< Authentication response.
211  } umts;
212  struct {
213  uint8_t *rand; //!< Random challenge.
214  uint8_t *sres; //!< Signing response.
215  uint8_t *kc; //!< Encryption key.
216  } sim;
217  };
218  sigtran_vector_type_t type; //!< Type of vector returned.
219 
220  sigtran_vector_t *next; //!< Next vector in list.
221 };
222 
223 /** MAP send auth info response
224  *
225  */
227  int error;
228  sigtran_vector_t *vector; //!< Linked list of vectors.
230 
231 typedef struct rlm_sigtran {
232  sigtran_conn_t const *conn; //!< Linkset associated with this instance.
233 
234  sigtran_conn_conf_t conn_conf; //!< Connection configuration
235 
236  tmpl_t *imsi; //!< Subscriber identifier.
238 
239 typedef struct rlm_sigtran_thread {
240  int fd; //!< File descriptor
242 
243 extern int ctrl_pipe[2];
244 extern uint8_t const ascii_to_tbcd[];
245 extern uint8_t const is_char_tbcd[];
246 
247 /*
248  * client.c
249  */
251 
253 
255 
257 
258 int sigtran_client_link_down(sigtran_conn_t const **conn);
259 
261  sigtran_conn_t const *conn, int fd);
262 
263 /*
264  * event.c
265  */
266 int sigtran_event_start(void);
267 
268 int sigtran_event_exit(void);
269 
270 int sigtran_event_submit(struct osmo_fd *ofd, sigtran_transaction_t *txn);
271 
272 /*
273  * sccp.c
274  */
275 int sigtran_tcap_outgoing(UNUSED struct msgb *msg_in, void *ctx, sigtran_transaction_t *txn, struct osmo_fd *ofd);
276 
277 void sigtran_sccp_incoming(struct mtp_link_set *set, struct msgb *msg, int sls);
278 
280 
281 int sigtran_sccp_global_init(void);
282 
283 void sigtran_sccp_global_free(void);
284 
285 /*
286  * sigtran.c
287  */
288 int sigtran_sccp_global_title(TALLOC_CTX *ctx, uint8_t **out, int gt_ind, char const *digits,
289  uint8_t tt, uint8_t np, uint8_t es, uint8_t nai);
290 
291 int sigtran_ascii_to_tbcd(TALLOC_CTX *ctx, uint8_t **out, char const *ascii);
292 
293 /*
294  * log.c
295  */
296 void sigtran_log_init(TALLOC_CTX *ctx);
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition: action.h:35
log_entry msg
Definition: acutest.h:794
#define UNUSED
Definition: build.h:313
IPv4/6 prefix.
Definition: merged_model.c:272
Stores all information relating to an event list.
Definition: event.c:411
unsigned short uint16_t
Definition: merged_model.c:31
unsigned int uint32_t
Definition: merged_model.c:33
unsigned char uint8_t
Definition: merged_model.c:30
static rs_t * conf
Definition: radsniff.c:53
rlm_rcode_t
Return codes indicating the result of the module call.
Definition: rcode.h:40
int ctrl_pipe[2]
Definition: event.c:78
sigtran_vector_type_t
Vector types.
Definition: sigtran.h:64
@ SIGTRAN_VECTOR_TYPE_UMTS_QUINTUPLETS
RAND, XRES, CK, IK, AUTN.
Definition: sigtran.h:66
@ SIGTRAN_VECTOR_TYPE_SIM_TRIPLETS
RAND, SRES, Kc.
Definition: sigtran.h:65
sigtran_request_type_t
Definition: sigtran.h:42
@ SIGTRAN_REQUEST_THREAD_REGISTER
New worker thread to register.
Definition: sigtran.h:43
@ SIGTRAN_REQUEST_MAP_SEND_AUTH_INFO
Request auth info.
Definition: sigtran.h:47
@ SIGTRAN_REQUEST_LINK_DOWN
Take down a link.
Definition: sigtran.h:46
@ SIGTRAN_REQUEST_THREAD_UNREGISTER
Worker thread to unregister.
Definition: sigtran.h:44
@ SIGTRAN_REQUEST_EXIT
Causes the event loop to exit.
Definition: sigtran.h:48
@ SIGTRAN_REQUEST_TEST
Definition: sigtran.h:50
@ SIGTRAN_REQUEST_LINK_UP
Bring up a link.
Definition: sigtran.h:45
bool dpc_is_set
Whether the DPC was set.
Definition: sigtran.h:133
sigtran_response_type_t
Definition: sigtran.h:54
@ SIGTRAN_RESPONSE_OK
Request succeeded.
Definition: sigtran.h:55
@ SIGTRAN_RESPONSE_NOOP
Request did nothing.
Definition: sigtran.h:56
@ SIGTRAN_RESPONSE_FAIL
Request failed.
Definition: sigtran.h:58
@ SIGTRAN_RESPONSE_NOTFOUND
User or device Not found.
Definition: sigtran.h:57
uint8_t ssn
Subsystem number.
Definition: sigtran.h:124
uint32_t mtp3_opc
MTP3 point codes (24bit!).
Definition: sigtran.h:152
int sigtran_client_thread_register(fr_event_list_t *el)
Called by a new thread to register a new req_pipe.
Definition: client.c:144
bool sccp_route_on_ssn
Whether we should route on subsystem number.
Definition: sigtran.h:164
struct mtp_link_set * mtp3_link_set
Definition: sigtran.h:184
uint16_t sctp_dst_port
SCTP port of the service gateway.
Definition: sigtran.h:145
int sigtran_ascii_to_tbcd(TALLOC_CTX *ctx, uint8_t **out, char const *ascii)
Definition: sigtran.c:93
bool nai_is_set
Nature of address indicator is set.
Definition: sigtran.h:114
unlang_action_t sigtran_client_map_send_auth_info(rlm_rcode_t *p_result, rlm_sigtran_t const *inst, request_t *request, sigtran_conn_t const *conn, int fd)
Create a MAP_SEND_AUTH_INFO request.
Definition: client.c:406
struct rlm_sigtran rlm_sigtran_t
sigtran_sccp_address_t sccp_called
The calling SCCP address.
Definition: sigtran.h:170
uint32_t sctp_timeout
Definition: sigtran.h:150
fr_rb_node_t node
Entry in the tree of transactions.
Definition: sigtran.h:76
uint8_t * imsi
BCD encoded IMSI.
Definition: sigtran.h:193
char const * address
Address digits.
Definition: sigtran.h:102
fr_ipaddr_t sctp_dst_ipaddr
IP of the Service Gateway.
Definition: sigtran.h:144
uint16_t sctp_src_port
Local port to originate traffic from.
Definition: sigtran.h:148
void sigtran_sccp_global_free(void)
Definition: sccp.c:385
int sigtran_sccp_global_title(TALLOC_CTX *ctx, uint8_t **out, int gt_ind, char const *digits, uint8_t tt, uint8_t np, uint8_t es, uint8_t nai)
Convert a global title to wire format for SCCP.
Definition: sigtran.c:170
uint8_t np
Numbering plan.
Definition: sigtran.h:110
struct sigtran_conn_conf sigtran_conn_conf_t
Configures a M3UA/MTP3/SCCP stack.
unsigned int num_vectors
Number of vectors requested.
Definition: sigtran.h:195
uint32_t m3ua_beat_interval
Definition: sigtran.h:158
fr_ipaddr_t sctp_src_ipaddr
Local IP to originate traffic from.
Definition: sigtran.h:147
struct sigtran_transaction::@164 response
void sigtran_log_init(TALLOC_CTX *ctx)
Patch our logging system into libosmo's.
Definition: log.c:62
int m3ua_traffic_mode
Definition: sigtran.h:156
int sigtran_tcap_outgoing(UNUSED struct msgb *msg_in, void *ctx, sigtran_transaction_t *txn, struct osmo_fd *ofd)
uint32_t pc
14bit point code.
Definition: sigtran.h:121
uint8_t const is_char_tbcd[]
Check is a char is valid Telephony Binary Coded Decimal.
Definition: sigtran.c:73
uint32_t mtp3_dpc
Definition: sigtran.h:152
tmpl_t * imsi
Subscriber identifier.
Definition: sigtran.h:236
int sigtran_event_submit(struct osmo_fd *ofd, sigtran_transaction_t *txn)
Send response.
Definition: event.c:283
struct rlm_sigtran_thread rlm_sigtran_thread_t
sigtran_conn_t const * conn
Linkset associated with this instance.
Definition: sigtran.h:232
bool pc_is_set
Point code is set.
Definition: sigtran.h:122
sigtran_conn_conf_t conn_conf
Connection configuration.
Definition: sigtran.h:234
struct sigtran_transaction::@163 request
int sigtran_event_start(void)
Start the libosmo event loop.
Definition: event.c:525
bool tt_is_set
Translation_type was provided.
Definition: sigtran.h:105
struct sigtran_conn sigtran_conn_t
Represents a connection to a remote SS7 entity.
void sigtran_sccp_incoming(struct mtp_link_set *set, struct msgb *msg, int sls)
uint32_t * si
Service indicator.
Definition: sigtran.h:137
int sigtran_client_thread_unregister(fr_event_list_t *el, int req_pipe_fd)
Signal that libosmo should unregister the other side of the pipe.
Definition: client.c:193
int sigtran_event_exit(void)
Signal that libosmo should exit.
Definition: event.c:581
sigtran_sccp_address_t sccp_calling
The called SCCP address.
Definition: sigtran.h:168
int sigtran_client_link_down(sigtran_conn_t const **conn)
Destroy a connection.
Definition: client.c:250
sigtran_vector_type_t type
Type of vector returned.
Definition: sigtran.h:218
tmpl_t * map_version
Application context version.
Definition: sigtran.h:173
bool sccp_ai8
Address indicator bit 8.
Definition: sigtran.h:166
struct sockaddr_sccp sccp_calling_sockaddr
Parsed version of the above.
Definition: sigtran.h:169
int fd
File descriptor.
Definition: sigtran.h:240
uint32_t * opc
Origin point code.
Definition: sigtran.h:135
bool es_is_set
Encoding scheme is set.
Definition: sigtran.h:108
sigtran_conn_t const * conn
Connection to send request on.
Definition: sigtran.h:192
sigtran_conn_conf_t * conf
Definition: sigtran.h:181
uint8_t version
Application context version.
Definition: sigtran.h:194
uint8_t es
Encoding scheme.
Definition: sigtran.h:107
sigtran_sccp_global_title_t gt
Definition: sigtran.h:127
int sigtran_sscp_init(sigtran_conn_t *conn)
Initialise libscctp.
Definition: sccp.c:360
struct sigtran_transaction sigtran_transaction_t
Request and response from the event loop.
sigtran_m3ua_route_t m3ua_routes
Routes to register with SG.
Definition: sigtran.h:161
bool gt_is_set
Whether a global title was specified.
Definition: sigtran.h:128
int sigtran_client_link_up(sigtran_conn_t const **out, sigtran_conn_conf_t const *conf)
Create a new connection.
Definition: client.c:225
struct sigtran_map_send_auth_info_res sigtran_map_send_auth_info_res_t
MAP send auth info response.
struct sigtran_transaction::@165 ctx
uint16_t m3ua_link_index
Definition: sigtran.h:153
uint16_t m3ua_routing_context
Definition: sigtran.h:154
struct sigtran_sccp_address sigtran_sccp_address_t
Structure representing a complete Q.173 SCCP address.
uint8_t const ascii_to_tbcd[]
Conversion table to transform ASCII to Telephony Binary Coded Decimal.
Definition: sigtran.c:50
int sigtran_client_do_transaction(int fd, sigtran_transaction_t *txn)
Definition: client.c:45
struct mtp_link * mtp3_link
Definition: sigtran.h:185
struct sigtran_sccp_global_title sigtran_sccp_global_title_t
char const * m3ua_traffic_mode_str
Definition: sigtran.h:155
sigtran_vector_t * vector
Linked list of vectors.
Definition: sigtran.h:228
uint8_t nai
Nature of address indicator.
Definition: sigtran.h:113
uint8_t tt
Translation type.
Definition: sigtran.h:104
sigtran_vector_t * next
Next vector in list.
Definition: sigtran.h:220
bool ssn_is_set
Subsystem number is set.
Definition: sigtran.h:125
uint32_t m3ua_ack_timeout
Definition: sigtran.h:157
uint32_t dpc
Destination point code.
Definition: sigtran.h:132
struct bsc_data * bsc_data
Definition: sigtran.h:183
struct sigtran_m3ua_route sigtran_m3ua_route_t
int sigtran_sccp_global_init(void)
Definition: sccp.c:371
bool np_is_set
Numbering plan is set.
Definition: sigtran.h:111
struct sockaddr_sccp sccp_called_sockaddr
Parsed version of the above.
Definition: sigtran.h:171
bool m3ua_routes_is_set
Routes section was provided.
Definition: sigtran.h:160
struct sigtran_map_send_auth_info_req sigtran_map_send_auth_info_req_t
MAP send auth info request.
Represents a connection to a remote SS7 entity.
Definition: sigtran.h:180
Configures a M3UA/MTP3/SCCP stack.
Definition: sigtran.h:143
MAP send auth info request.
Definition: sigtran.h:191
MAP send auth info response.
Definition: sigtran.h:226
Structure representing a complete Q.173 SCCP address.
Definition: sigtran.h:120
Request and response from the event loop.
Definition: sigtran.h:75
Authentication vector returned by HLR.
Definition: sigtran.h:203
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
static fr_event_list_t * el
static fr_slen_t data
Definition: value.h:1259
static size_t char ** out
Definition: value.h:984