annotate sip-in/mncc_sock.c @ 105:9213ec8b434b

sip-in: handle themwi-mncc shutdown without terminating
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 27 Sep 2022 23:00:52 -0800
parents e5aee661e3b2
children 245dc4837b56
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
2 * In this module we implement our connection to the MNCC daemon's
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
3 * mtcall socket.
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/socket.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/un.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <syslog.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "../include/mncc.h"
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
15 static char mtcall_socket_pathname[] = "/var/gsm/mtcall_socket";
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
17 int gsm_socket, gsm_is_connected;
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
19 connect_gsm_mtcall()
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 struct sockaddr_un sa;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 unsigned sa_len;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int rc;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
25 if (gsm_is_connected)
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
26 return(0);
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
27 gsm_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0);
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
28 if (gsm_socket < 0) {
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m");
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(-1);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
32 fill_sockaddr_un(mtcall_socket_pathname, &sa, &sa_len);
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
33 rc = connect(gsm_socket, (struct sockaddr *) &sa, sa_len);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (rc < 0) {
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
35 syslog(LOG_ERR, "connect to %s: %m", mtcall_socket_pathname);
57
d61d0136f6a5 sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents: 56
diff changeset
36 close(gsm_socket);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 return(-1);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
39 update_max_fd(gsm_socket);
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
40 gsm_is_connected = 1;
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return(0);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 void
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
45 gsm_socket_select()
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 union mncc_msg msg;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 int rc;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
50 rc = recv(gsm_socket, &msg, sizeof msg, 0);
105
9213ec8b434b sip-in: handle themwi-mncc shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
51 if (rc <= 0) {
9213ec8b434b sip-in: handle themwi-mncc shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
52 syslog(LOG_ERR, "mtcall socket disconnected");
9213ec8b434b sip-in: handle themwi-mncc shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
53 shutdown_gsm_conn();
9213ec8b434b sip-in: handle themwi-mncc shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
54 gsm_is_connected = 0;
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (rc < 4) {
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
57 syslog(LOG_CRIT, "short read from mtcall socket: %d bytes", rc);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(1);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
63
e5aee661e3b2 sip-in: beginning to handle incoming MNCC messages from themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents: 57
diff changeset
60 msg_from_mncc(&msg, rc);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 send_mncc_to_gsm(msg, msglen)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 union mncc_msg *msg;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 unsigned msglen;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 {
56
7005d5c535e8 sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
67 return send(gsm_socket, msg, msglen, 0);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }