annotate mncc/outcall.c @ 184:f8c40090a0a8

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