FreeCalypso > hg > themwi-interim
annotate mncc/mncc_sock.c @ 11:aa2ba9b432af
mtctest: implement play and play-stop commands
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 09 Jun 2024 04:32:57 +0000 |
| parents | 053f04687106 |
| 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 * In this module we implement low-level handling |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * of the main MNCC socket that connects to OsmoMSC. |
|
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 |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/socket.h> |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/un.h> |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <syslog.h> |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "../include/mncc.h" |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static char mncc_socket_pathname[] = "/var/gsm/mncc_socket"; |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int mncc_socket; |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 open_mncc_socket() |
|
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 struct sockaddr_un sa; |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 unsigned sa_len; |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int rc; |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 mncc_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (mncc_socket < 0) { |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 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
|
28 return(-1); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 fill_sockaddr_un(mncc_socket_pathname, &sa, &sa_len); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 rc = connect(mncc_socket, (struct sockaddr *) &sa, sa_len); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (rc < 0) { |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 syslog(LOG_ERR, "connect to %s: %m", mncc_socket_pathname); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(-1); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 update_max_fd(mncc_socket); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return(0); |
|
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 |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 void |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 mncc_socket_select() |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 { |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 union mncc_msg msg; |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 int rc; |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 rc = recv(mncc_socket, &msg, sizeof msg, 0); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (rc < 0) { |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 syslog(LOG_CRIT, "error reading from MNCC socket: %m"); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (rc < 4) { |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 syslog(LOG_CRIT, "short read from MNCC socket: %d bytes", rc); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 exit(1); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 mncc_msg_from_gsm(&msg, rc); |
|
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 |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 send_mncc_to_gsm(msg, msglen) |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 union mncc_msg *msg; |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 unsigned msglen; |
|
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 return send(mncc_socket, msg, msglen, 0); |
|
053f04687106
mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
