comparison mncc/outcall.c @ 167:2ebad02adbe5

themwi-mncc: route outbound calls to themwi-sip-out
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 18:08:34 -0800
parents
children
comparison
equal deleted inserted replaced
166:8adcd220c6cf 167:2ebad02adbe5
1 /*
2 * In this module we handle routing of outbound MO calls
3 * to the outcall socket provided by themwi-sip-out.
4 */
5
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <sys/un.h>
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <strings.h>
14 #include <syslog.h>
15 #include <unistd.h>
16 #include "../include/mncc.h"
17 #include "../include/gsm48_const.h"
18 #include "struct.h"
19
20 extern struct socket_conn outcall_conn;
21
22 static char outcall_socket_pathname[] = "/var/gsm/outcall_socket";
23
24 connect_outcall_socket()
25 {
26 struct sockaddr_un sa;
27 unsigned sa_len;
28 int fd, rc;
29
30 if (outcall_conn.fd >= 0)
31 return(0);
32 fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
33 if (fd < 0) {
34 syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m");
35 return(-1);
36 }
37 fill_sockaddr_un(outcall_socket_pathname, &sa, &sa_len);
38 rc = connect(fd, (struct sockaddr *) &sa, sa_len);
39 if (rc < 0) {
40 syslog(LOG_ERR, "connect to %s: %m", outcall_socket_pathname);
41 close(fd);
42 return(-1);
43 }
44 update_max_fd(fd);
45 outcall_conn.fd = fd;
46 return(0);
47 }
48
49 void
50 outbound_mo_setup(call, msg)
51 struct gsm_call *call;
52 struct gsm_mncc *msg;
53 {
54 int rc;
55
56 rc = connect_outcall_socket();
57 if (rc < 0) {
58 syslog(LOG_ERR, "rejecting MO call 0x%x: outbound gateway down",
59 msg->callref);
60 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
61 GSM48_CC_CAUSE_DEST_OOO);
62 call->gc_flag = 1;
63 return;
64 }
65 call->socket = &outcall_conn;
66 call->socket_ref = msg->callref;
67 outcall_conn.ncalls++;
68 mncc_signal_to_socket(call, msg);
69 }