comparison sip-in/mncc_sock.c @ 56:7005d5c535e8

sip-in: mtcall socket connection implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 08 Sep 2022 13:25:31 -0800
parents mncc/mncc_sock.c@ccc5ab6d8388
children d61d0136f6a5
comparison
equal deleted inserted replaced
55:f1d59210f7b2 56:7005d5c535e8
1 /*
2 * In this module we implement our connection to the MNCC daemon's
3 * mtcall socket.
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 <syslog.h>
13 #include "../include/mncc.h"
14
15 static char mtcall_socket_pathname[] = "/var/gsm/mtcall_socket";
16
17 int gsm_socket, gsm_is_connected;
18
19 connect_gsm_mtcall()
20 {
21 struct sockaddr_un sa;
22 unsigned sa_len;
23 int rc;
24
25 if (gsm_is_connected)
26 return(0);
27 gsm_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0);
28 if (gsm_socket < 0) {
29 syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m");
30 return(-1);
31 }
32 fill_sockaddr_un(mtcall_socket_pathname, &sa, &sa_len);
33 rc = connect(gsm_socket, (struct sockaddr *) &sa, sa_len);
34 if (rc < 0) {
35 syslog(LOG_ERR, "connect to %s: %m", mtcall_socket_pathname);
36 return(-1);
37 }
38 update_max_fd(gsm_socket);
39 gsm_is_connected = 1;
40 return(0);
41 }
42
43 void
44 gsm_socket_select()
45 {
46 union mncc_msg msg;
47 int rc;
48
49 rc = recv(gsm_socket, &msg, sizeof msg, 0);
50 if (rc < 0) {
51 syslog(LOG_CRIT, "error reading from mtcall socket: %m");
52 /* GSM disconnect handling to be implemented */
53 exit(1);
54 }
55 if (rc < 4) {
56 syslog(LOG_CRIT, "short read from mtcall socket: %d bytes", rc);
57 exit(1);
58 }
59 /* mncc_msg_from_gsm(&msg, rc); */
60 }
61
62 send_mncc_to_gsm(msg, msglen)
63 union mncc_msg *msg;
64 unsigned msglen;
65 {
66 return send(gsm_socket, msg, msglen, 0);
67 }