FreeCalypso > hg > themwi-interim
annotate mncc/main.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 | 847690ea7f4a |
children |
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 * Main module for ThemWi MNCC daemon. |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/errno.h> |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <signal.h> |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <syslog.h> |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <unistd.h> |
3
847690ea7f4a
mncc compiles in new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
15 #include <themwi/nanp/number_lookup.h> |
2
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "struct.h" |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 extern int mncc_socket; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 extern int mtcall_listener; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 extern struct socket_conn *mtcall_socket_head; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 struct socket_conn outcall_conn; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 static int max_fd; |
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 update_max_fd(newfd) |
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 if (newfd > max_fd) |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 max_fd = newfd; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
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 main(argc, argv) |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 char **argv; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 { |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fd_set fds; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 struct socket_conn *conn, **connp; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 int c; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 openlog("themwi-mncc", 0, LOG_LOCAL5); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (read_number_db() < 0) { |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 fprintf(stderr, "error reading number database\n"); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(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 if (open_mncc_socket() < 0) { |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 fprintf(stderr, "error connecting to GSM MNCC socket\n"); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 exit(1); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (create_mtcall_socket() < 0) { |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fprintf(stderr, "error creating MT call socket\n"); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 exit(1); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 signal(SIGPIPE, SIG_IGN); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 outcall_conn.fd = -1; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 /* main select loop */ |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 for (;;) { |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 FD_ZERO(&fds); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 FD_SET(mncc_socket, &fds); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 FD_SET(mtcall_listener, &fds); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 for (connp = &mtcall_socket_head; conn = *connp; ) { |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (conn->fd < 0) { |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 *connp = conn->next; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 free(conn); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 continue; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 FD_SET(conn->fd, &fds); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 connp = &conn->next; |
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 if (outcall_conn.fd >= 0) |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 FD_SET(outcall_conn.fd, &fds); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 c = select(max_fd+1, &fds, 0, 0, 0); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (c < 0) { |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 if (errno == EINTR) |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 continue; |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 syslog(LOG_CRIT, "select: %m"); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 exit(1); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (FD_ISSET(mncc_socket, &fds)) |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 mncc_socket_select(); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 if (FD_ISSET(mtcall_listener, &fds)) |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 mtsock_accept_handler(); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 for (conn = mtcall_socket_head; conn; conn = conn->next) |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (FD_ISSET(conn->fd, &fds)) |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 extsock_read_select(conn); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (outcall_conn.fd >= 0 && FD_ISSET(outcall_conn.fd, &fds)) |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 extsock_read_select(&outcall_conn); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 gc_call_list(); |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } |