annotate sip-out/disconnect.c @ 209:e80f158333c5

mgw: correct PCMU decoding table
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 May 2023 21:43:02 -0800
parents e54b0a9e322f
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"
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
17 #include "../include/out_routes.h"
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "call.h"
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
20 extern unsigned sip_linger_timeout;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
21
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 void
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 disconnect_mncc(call, cause_loc, cause_val)
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 struct call *call;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 struct gsm_mncc msg;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
28 if (!call->mncc)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
29 return;
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 switch (call->mncc_state) {
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 case MNCC_STATE_DISCONNECT:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 case MNCC_STATE_RELEASE:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 return;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 bzero(&msg, sizeof(struct gsm_mncc));
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 msg.msg_type = MNCC_DISC_REQ;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 msg.callref = call->mncc_callref;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 mncc_set_cause(&msg, cause_loc, cause_val);
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
39 send_mncc_to_sock(call->mncc, &msg, sizeof(struct gsm_mncc));
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 call->mncc_state = MNCC_STATE_DISCONNECT;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
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 void
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 disconnect_tmgw(call)
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 struct call *call;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 switch (call->mgw_state) {
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 case MGW_STATE_NO_EXIST:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 case MGW_STATE_DELETING:
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
50 case MGW_STATE_MDCX_IBT:
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
51 case MGW_STATE_MDCX_CONN:
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
52 case MGW_STATE_MDCX_HOLD:
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
53 case MGW_STATE_MDCX_RETR:
128
5685412bd6aa sip-in: pass DTMF start & stop to themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
54 case MGW_STATE_DTMF_OP:
64
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 case MGW_STATE_ALLOCATED:
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
57 case MGW_STATE_IBT_CONN:
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 case MGW_STATE_COMPLETE:
141
e499e8db8b82 sip-in: handle call hold and retrieve
Mychaela Falconia <falcon@freecalypso.org>
parents: 128
diff changeset
59 case MGW_STATE_HELD:
64
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 tmgw_send_dlcx(call);
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return;
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 default:
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 syslog(LOG_CRIT,
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 "FATAL: invalid MGW state 0x%x in disconnect_tmgw()",
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 call->mgw_state);
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 exit(1);
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
1f863c63f96b sip-in: beginning of disconnect handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
69
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
70 void
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
71 disconnect_sip(call)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
72 struct call *call;
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
73 {
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
74 if (!call->sip_call_exists)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
75 return;
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
76 switch (call->sip_state) {
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
77 case SIP_STATE_INV_SENT:
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
78 call->sip_state = SIP_STATE_ACCEPT_100;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
79 sip_mark_end_time(call, sip_linger_timeout);
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
80 break;
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
81 case SIP_STATE_100_RCVD:
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 141
diff changeset
82 initiate_sip_cancel(call);
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
83 break;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
84 case SIP_STATE_CONNECTED:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
85 initiate_bye(call);
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
86 break;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
87 }
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
88 }