annotate mncc/mtsock.c @ 14:44c1d4d787e9 default tip

themwi-test-mtc: add option to set bearer cap
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 28 Nov 2024 20:37:23 +0000
parents 053f04687106
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement the MT call socket
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * to which other ThemWi system sw components connect
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * in order to send MT calls toward the GSM network.
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/stat.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/socket.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <sys/un.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdint.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <string.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <strings.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <syslog.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <unistd.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "../include/mncc.h"
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "struct.h"
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static char mtcall_socket_pathname[] = "/var/gsm/mtcall_socket";
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int mtcall_listener;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 struct socket_conn *mtcall_socket_head;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 create_mtcall_socket()
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 struct sockaddr_un sa;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 unsigned sa_len;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 int rc;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 mtcall_listener = socket(AF_UNIX, SOCK_SEQPACKET, 0);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (mtcall_listener < 0) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m");
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(-1);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 unlink(mtcall_socket_pathname);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 fill_sockaddr_un(mtcall_socket_pathname, &sa, &sa_len);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 rc = bind(mtcall_listener, (struct sockaddr *) &sa, sa_len);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (rc < 0) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 syslog(LOG_ERR, "bind to %s: %m", mtcall_socket_pathname);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 return(-1);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 rc = listen(mtcall_listener, 3);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (rc < 0) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 syslog(LOG_CRIT, "listen on UNIX socket: %m");
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return(-1);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 chmod(mtcall_socket_pathname, 0775);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 update_max_fd(mtcall_listener);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return(0);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 void
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 mtsock_accept_handler()
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 struct sockaddr_un sa;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 socklen_t sa_len;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 int fd;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 struct socket_conn *conn;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 sa_len = sizeof sa;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 fd = accept(mtcall_listener, (struct sockaddr *) &sa, &sa_len);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (fd < 0) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 syslog(LOG_CRIT, "accept on UNIX socket: %m");
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 exit(1);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 conn = malloc(sizeof(struct socket_conn));
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (!conn) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 syslog(LOG_CRIT, "malloc for mtcall socket conn: %m");
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 close(fd);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 syslog(LOG_INFO, "new MT call socket connection");
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 bzero(conn, sizeof(struct socket_conn));
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 conn->fd = fd;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 conn->next = mtcall_socket_head;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 mtcall_socket_head = conn;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 update_max_fd(fd);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }