FreeCalypso > hg > themwi-interim
diff mncc/outcall.c @ 2:053f04687106
mncc: initial import from old ThemWi
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 08 Jun 2024 23:12:12 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mncc/outcall.c Sat Jun 08 23:12:12 2024 +0000 @@ -0,0 +1,69 @@ +/* + * In this module we handle routing of outbound MO calls + * to the outcall socket provided by themwi-sip-out. + */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <syslog.h> +#include <unistd.h> +#include "../include/mncc.h" +#include "../include/gsm48_const.h" +#include "struct.h" + +extern struct socket_conn outcall_conn; + +static char outcall_socket_pathname[] = "/var/gsm/outcall_socket"; + +connect_outcall_socket() +{ + struct sockaddr_un sa; + unsigned sa_len; + int fd, rc; + + if (outcall_conn.fd >= 0) + return(0); + fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); + if (fd < 0) { + syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m"); + return(-1); + } + fill_sockaddr_un(outcall_socket_pathname, &sa, &sa_len); + rc = connect(fd, (struct sockaddr *) &sa, sa_len); + if (rc < 0) { + syslog(LOG_ERR, "connect to %s: %m", outcall_socket_pathname); + close(fd); + return(-1); + } + update_max_fd(fd); + outcall_conn.fd = fd; + return(0); +} + +void +outbound_mo_setup(call, msg) + struct gsm_call *call; + struct gsm_mncc *msg; +{ + int rc; + + rc = connect_outcall_socket(); + if (rc < 0) { + syslog(LOG_ERR, "rejecting MO call 0x%x: outbound gateway down", + msg->callref); + reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU, + GSM48_CC_CAUSE_DEST_OOO); + call->gc_flag = 1; + return; + } + call->socket = &outcall_conn; + call->socket_ref = msg->callref; + outcall_conn.ncalls++; + mncc_signal_to_socket(call, msg); +}