FreeCalypso > hg > themwi-system-sw
annotate mncc/mtsock.c @ 32:b3f74df7b808
beginning of themwi-mgw
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 09 Jul 2022 22:51:44 -0800 |
parents | 660126bd5f59 |
children | db7ed6a55ba4 |
rev | line source |
---|---|
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement the MT call socket |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * to which other ThemWi system sw components connect |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * in order to send MT calls toward the GSM network. |
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 |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/socket.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <sys/un.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdint.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <string.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <strings.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <syslog.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "../include/mncc.h" |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "struct.h" |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static char mtcall_socket_pathname[] = "/var/gsm/mtcall_socket"; |
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 int mtcall_listener; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 struct socket_conn *mtcall_socket_head; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 create_mtcall_socket() |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 { |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 struct sockaddr_un sa; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 unsigned sa_len; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int rc; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 mtcall_listener = socket(AF_UNIX, SOCK_SEQPACKET, 0); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (mtcall_listener < 0) { |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 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
|
33 return(-1); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 unlink(mtcall_socket_pathname); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 fill_sockaddr_un(mtcall_socket_pathname, &sa, &sa_len); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 rc = bind(mtcall_listener, (struct sockaddr *) &sa, sa_len); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (rc < 0) { |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 syslog(LOG_ERR, "bind to %s: %m", mtcall_socket_pathname); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return(-1); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 rc = listen(mtcall_listener, 3); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (rc < 0) { |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 syslog(LOG_CRIT, "listen on UNIX socket: %m"); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return(-1); |
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 update_max_fd(mtcall_listener); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return(0); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 void |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 mtsock_accept_handler() |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 { |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 struct sockaddr_un sa; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 socklen_t sa_len; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 int fd; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 struct socket_conn *conn; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 |
25
fd43f179ff1d
themwi-mncc: need to initialize sa_len before accept call
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
59 sa_len = sizeof sa; |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 fd = accept(mtcall_listener, (struct sockaddr *) &sa, &sa_len); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (fd < 0) { |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 syslog(LOG_CRIT, "accept on UNIX socket: %m"); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 exit(1); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 conn = malloc(sizeof(struct socket_conn)); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (!conn) { |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 syslog(LOG_CRIT, "malloc for mtcall socket conn: %m"); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 close(fd); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 return; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
28
660126bd5f59
themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents:
25
diff
changeset
|
71 syslog(LOG_INFO, "new MT call socket connection"); |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 bzero(conn, sizeof(struct socket_conn)); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 conn->fd = fd; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 conn->next = mtcall_socket_head; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 mtcall_socket_head = conn; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 update_max_fd(fd); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |