annotate sip-in/bye_in.c @ 104:ce3b1db7d1d7

sip-in: force-pcma-codec config option to use PCMA when both are offered
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 27 Sep 2022 21:52:07 -0800
parents a9944b66dcc5
children 0d6435808bcd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
79
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
80
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
2 * Here we implement our handling of incoming SIP BYE requests.
79
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <netinet/in.h>
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <syslog.h>
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "../include/gsm48_const.h"
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../libsip/parse.h"
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../libsip/uas_basic.h"
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../libsip/out_msg.h"
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "call.h"
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern struct call *find_call_by_sip_id();
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 void
80
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
23 handle_sip_bye(req, ess, sin)
79
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 struct sip_pkt_rx *req;
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct uas_parse_hdrs *ess;
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 struct sockaddr_in *sin;
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 struct call *call;
80
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
29 struct sip_msg_out resp;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
30 char cseq_str[32];
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
31 int rc;
79
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 call = find_call_by_sip_id(ess->call_id);
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (!call) {
80
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
35 start_response_out_msg(&resp, "481 Call-ID not found");
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
36 rc = add_resp_basic_headers(&resp, ess, req->req_method);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
37 if (rc < 0)
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
38 return;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
39 out_msg_finish(&resp);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
40 sip_tx_packet(&resp, sin);
79
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return;
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 switch (call->sip_state) {
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 case SIP_STATE_INVITE_PROC:
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 case SIP_STATE_RINGING:
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 case SIP_STATE_RINGING_PRACK:
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 call->overall_state = OVERALL_STATE_TEARDOWN;
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND,
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 GSM48_CC_CAUSE_NORM_CALL_CLEAR);
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 disconnect_tmgw(call);
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 strcpy(call->invite_fail, "487 Call attempt terminated");
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 signal_invite_error(call);
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 break;
80
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
54 case SIP_STATE_INVITE_200:
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
55 case SIP_STATE_CONNECTED:
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
56 call->overall_state = OVERALL_STATE_TEARDOWN;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
57 disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND,
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
58 GSM48_CC_CAUSE_NORM_CALL_CLEAR);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
59 disconnect_tmgw(call);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
60 call->sip_state = SIP_STATE_ENDED;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
61 break;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
62 case SIP_STATE_BYE_SENT:
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
63 call->sip_state = SIP_STATE_ENDED;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
64 break;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
65 case SIP_STATE_INVITE_ERR:
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
66 case SIP_STATE_ENDED:
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
67 break;
79
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 case SIP_STATE_MSG_SIZE_ERR:
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return;
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
80
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
71 /* send 200 response to BYE */
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
72 start_response_out_msg(&resp, "200 OK");
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
73 rc = out_msg_add_header(&resp, "From", call->invite_from);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
74 if (rc < 0) {
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
75 msg_size_err: syslog(LOG_ERR, "BYE 200 response length exceeded");
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
76 call->sip_state = SIP_STATE_MSG_SIZE_ERR;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
77 return;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
78 }
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
79 rc = out_msg_add_header(&resp, "To", call->invite_to);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
80 if (rc < 0)
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
81 goto msg_size_err;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
82 rc = out_msg_add_header(&resp, "Call-ID", call->sip_call_id);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
83 if (rc < 0)
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
84 goto msg_size_err;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
85 sprintf(cseq_str, "%u BYE", ess->cseq_num);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
86 rc = out_msg_add_header(&resp, "CSeq", cseq_str);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
87 if (rc < 0)
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
88 goto msg_size_err;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
89 rc = out_msg_add_header(&resp, "Via", ess->via);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
90 if (rc < 0)
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
91 goto msg_size_err;
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
92 out_msg_finish(&resp);
a9944b66dcc5 sip-in: handle incoming BYE
Mychaela Falconia <falcon@freecalypso.org>
parents: 79
diff changeset
93 sip_tx_packet(&resp, sin);
79
b0df2b200d77 sip-in: implement SIP CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 }