FreeCalypso > hg > themwi-system-sw
annotate sip-in/mncc_sock.c @ 123:a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 29 Sep 2022 17:21:11 -0800 |
parents | 245dc4837b56 |
children |
rev | line source |
---|---|
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
2 * In this module we implement our connection to the MNCC daemon's |
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
3 * mtcall socket. |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
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 #include <sys/types.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/socket.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/un.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <syslog.h> |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "../include/mncc.h" |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
15 static char mtcall_socket_pathname[] = "/var/gsm/mtcall_socket"; |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
17 int gsm_socket, gsm_is_connected; |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
19 connect_gsm_mtcall() |
15
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 struct sockaddr_un sa; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 unsigned sa_len; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int rc; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
25 if (gsm_is_connected) |
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
26 return(0); |
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
27 gsm_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0); |
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
28 if (gsm_socket < 0) { |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 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
|
30 return(-1); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
32 fill_sockaddr_un(mtcall_socket_pathname, &sa, &sa_len); |
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
33 rc = connect(gsm_socket, (struct sockaddr *) &sa, sa_len); |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (rc < 0) { |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
35 syslog(LOG_ERR, "connect to %s: %m", mtcall_socket_pathname); |
57
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
56
diff
changeset
|
36 close(gsm_socket); |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return(-1); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
39 update_max_fd(gsm_socket); |
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
40 gsm_is_connected = 1; |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return(0); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 void |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
45 gsm_socket_select() |
15
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 union mncc_msg msg; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 int rc; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
50 rc = recv(gsm_socket, &msg, sizeof msg, 0); |
105
9213ec8b434b
sip-in: handle themwi-mncc shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents:
63
diff
changeset
|
51 if (rc <= 0) { |
9213ec8b434b
sip-in: handle themwi-mncc shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents:
63
diff
changeset
|
52 syslog(LOG_ERR, "mtcall socket disconnected"); |
106
245dc4837b56
sip-in: fix bugs in last commit
Mychaela Falconia <falcon@freecalypso.org>
parents:
105
diff
changeset
|
53 close(gsm_socket); |
245dc4837b56
sip-in: fix bugs in last commit
Mychaela Falconia <falcon@freecalypso.org>
parents:
105
diff
changeset
|
54 gsm_is_connected = 0; |
105
9213ec8b434b
sip-in: handle themwi-mncc shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents:
63
diff
changeset
|
55 shutdown_gsm_conn(); |
106
245dc4837b56
sip-in: fix bugs in last commit
Mychaela Falconia <falcon@freecalypso.org>
parents:
105
diff
changeset
|
56 return; |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (rc < 4) { |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
59 syslog(LOG_CRIT, "short read from mtcall socket: %d bytes", rc); |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 exit(1); |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
63
e5aee661e3b2
sip-in: beginning to handle incoming MNCC messages from themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
62 msg_from_mncc(&msg, rc); |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
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 send_mncc_to_gsm(msg, msglen) |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 union mncc_msg *msg; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 unsigned msglen; |
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 { |
56
7005d5c535e8
sip-in: mtcall socket connection implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
69 return send(gsm_socket, msg, msglen, 0); |
15
ccc5ab6d8388
first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |