annotate sip-in/disconnect.c @ 160:4b35a5a400f1

mgw/dtmf_defs.h: reduce DTMF_MIN_FRAMES to 5 (100 ms)
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 13:05:26 -0800
parents e499e8db8b82
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement call disconnection and clearing procedures.
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
7 #include <sys/time.h>
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <netinet/in.h>
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <syslog.h>
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../include/mncc.h"
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
16 #include "../include/gsm48_const.h"
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "call.h"
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 void
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 disconnect_mncc(call, cause_loc, cause_val)
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 struct call *call;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 struct gsm_mncc msg;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 switch (call->mncc_state) {
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 case MNCC_STATE_NO_EXIST:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 case MNCC_STATE_DISCONNECT:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 case MNCC_STATE_RELEASE:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 return;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 bzero(&msg, sizeof(struct gsm_mncc));
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 msg.msg_type = MNCC_DISC_REQ;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 msg.callref = call->mncc_callref;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 mncc_set_cause(&msg, cause_loc, cause_val);
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 send_mncc_to_gsm(&msg, sizeof(struct gsm_mncc));
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 call->mncc_state = MNCC_STATE_DISCONNECT;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 void
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 disconnect_tmgw(call)
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 struct call *call;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 switch (call->mgw_state) {
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 case MGW_STATE_NO_EXIST:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 case MGW_STATE_CONNECTING:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 case MGW_STATE_DELETING:
128
5685412bd6aa sip-in: pass DTMF start & stop to themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
47 case MGW_STATE_DTMF_OP:
141
e499e8db8b82 sip-in: handle call hold and retrieve
Mychaela Falconia <falcon@freecalypso.org>
parents: 128
diff changeset
48 case MGW_STATE_HOLD_OP:
e499e8db8b82 sip-in: handle call hold and retrieve
Mychaela Falconia <falcon@freecalypso.org>
parents: 128
diff changeset
49 case MGW_STATE_RETRIEVE_OP:
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case MGW_STATE_ALLOCATED:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 case MGW_STATE_COMPLETE:
141
e499e8db8b82 sip-in: handle call hold and retrieve
Mychaela Falconia <falcon@freecalypso.org>
parents: 128
diff changeset
53 case MGW_STATE_HELD:
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 tmgw_send_dlcx(call);
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 default:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 syslog(LOG_CRIT,
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 "FATAL: invalid MGW state 0x%x in disconnect_tmgw()",
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 call->mgw_state);
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 exit(1);
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
63
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
64 static char *
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
65 cause_to_invite_err(cause)
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
66 struct gsm_mncc_cause *cause;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
67 {
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
68 switch (cause->value) {
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
69 case GSM48_CC_CAUSE_CALL_REJECTED:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
70 return "403 Call rejected";
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
71 case GSM48_CC_CAUSE_UNASSIGNED_NR:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
72 return "404 Unassigned number";
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
73 case GSM48_CC_CAUSE_USER_NOTRESPOND:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
74 return "480 User not responding";
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
75 case GSM48_CC_CAUSE_RESOURCE_UNAVAIL:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
76 return "503 GSM network resource unavailable";
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
77 case GSM48_CC_CAUSE_TEMP_FAILURE:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
78 return "503 Temporary failure";
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
79 case GSM48_CC_CAUSE_SWITCH_CONG:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
80 return "503 Switch congestion at MSC";
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
81 case GSM48_CC_CAUSE_USER_BUSY:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
82 return "486 User busy";
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
83 case GSM48_CC_CAUSE_DEST_OOO:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
84 return "502 Destination out of order";
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
85 case GSM48_CC_CAUSE_NETWORK_OOO:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
86 return "503 Network out of order";
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
87 default:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
88 return "480 Unavailable (unspecified)";
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
89 }
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
90 }
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
91
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
92 void
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
93 disconnect_sip(call, cause)
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
94 struct call *call;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
95 struct gsm_mncc_cause *cause;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
96 {
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
97 switch (call->sip_state) {
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
98 case SIP_STATE_INVITE_PROC:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
99 case SIP_STATE_RINGING:
108
0d6435808bcd sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents: 83
diff changeset
100 case SIP_STATE_RINGING_REL:
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
101 strcpy(call->invite_fail, cause_to_invite_err(cause));
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
102 signal_invite_error(call);
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
103 break;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
104 case SIP_STATE_INVITE_200:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
105 /* have to wait for SIP ACK, then send BYE */
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
106 break;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
107 case SIP_STATE_CONNECTED:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
108 initiate_bye(call);
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
109 break;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
110 }
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
111 }