annotate sip-out/invite.c @ 163:bfa9f0c0f0ac

sip-out: handle incoming BYE as UAS
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 14:45:31 -0800
parents 51cf5ea7f320
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we handle responses to INVITE.
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/time.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <netinet/in.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <syslog.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../include/gsm48_const.h"
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../include/out_routes.h"
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../libsip/parse.h"
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "../libsip/sdp.h"
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "../libsip/out_msg.h"
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "call.h"
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern char *get_single_header();
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern char *extract_to_tag();
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
157
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
25 extern unsigned sip_linger_invite_err;
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern unsigned sip_linger_response_err;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 check_sdp_present(msg)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 struct sip_pkt_rx *msg;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 char *hval;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (!msg->msg_body_len)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 hval = get_single_header(msg, "Content-Type", "c", (int *) 0);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (!hval)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (!strcasecmp(hval, "application/sdp"))
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return 1;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 else
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 return 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 static
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 extract_sdp(call, msg)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 struct call *call;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 struct sip_pkt_rx *msg;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 struct sdp_parse sdp_parse;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 int rc, use_pcma;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 rc = parse_incoming_sdp(msg->msg_body, msg->msg_body_len, &sdp_parse);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (rc < 0)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return rc;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 switch (sdp_parse.codec_mask) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 case SDP_CODEC_MASK_PCMU:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 case SDP_CODEC_MASK_BOTH:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 use_pcma = 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 break;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 case SDP_CODEC_MASK_PCMA:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 use_pcma = 1;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 break;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 default:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return -2;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 call->pstn_rtp_remote.sin_family = AF_INET;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 call->pstn_rtp_remote.sin_addr = sdp_parse.ip_addr;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 call->pstn_rtp_remote.sin_port = htons(sdp_parse.audio_port);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 call->use_pcma = use_pcma;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 return 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 static void
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 handle_1xx(call, msg, tag, sin)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 struct call *call;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 struct sip_pkt_rx *msg;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 char *tag;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 struct sockaddr_in *sin;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 int rc;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 switch (call->sip_state) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 case SIP_STATE_INV_SENT:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 call->sip_state = SIP_STATE_100_RCVD;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 /* FALL THRU */
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 case SIP_STATE_100_RCVD:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (msg->status_code == 180)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 call->overall_state = OVERALL_STATE_RINGING;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 if (check_sdp_present(msg) &&
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 call->mgw_state == MGW_STATE_ALLOCATED) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 rc = extract_sdp(call, msg);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 if (rc < 0) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 syslog(LOG_ERR, "bad SDP in %03u response",
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 msg->status_code);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 call->overall_state = OVERALL_STATE_TEARDOWN;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 GSM48_CC_CAUSE_BEARER_CA_UNAVAIL);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 disconnect_tmgw(call);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 initiate_sip_cancel(call);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 tmgw_send_mdcx_connect(call, 1);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 } else if (msg->status_code == 180)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 mncc_signal_alerting(call);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 case SIP_STATE_ACCEPT_100:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 initiate_sip_cancel(call);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 static
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 send_ack(call, tag, sin)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 struct call *call;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 char *tag;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 struct sockaddr_in *sin;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 struct sip_msg_out msg;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 int rc;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 rc = start_request_out_msg(&msg, "ACK", call->to_uri);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 if (rc < 0)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 return rc;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 rc = add_req_boilerplate(&msg, call, "1 ACK", tag);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 if (rc < 0)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 return rc;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 out_msg_finish(&msg);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 sip_tx_packet(&msg, sin);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 return 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 static void
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 handle_200(call, msg, tag, sin)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 struct call *call;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 struct sip_pkt_rx *msg;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 char *tag;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 struct sockaddr_in *sin;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 int rc;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 switch (call->sip_state) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 case SIP_STATE_INV_SENT:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 case SIP_STATE_100_RCVD:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 rc = send_ack(call, tag, sin);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 if (rc < 0) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 syslog(LOG_CRIT,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 "ACK to %03u response exceeds msg size!",
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 msg->status_code);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 call->overall_state = OVERALL_STATE_TEARDOWN;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 GSM48_CC_CAUSE_DEST_OOO);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 disconnect_tmgw(call);
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 158
diff changeset
155 call->sip_state = SIP_STATE_MSG_SIZE_ERR;
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 sip_mark_end_time(call, sip_linger_response_err);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 if (tag)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 strcpy(call->to_tag, tag);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 call->sip_state = SIP_STATE_CONNECTED;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 if (!check_sdp_present(msg)) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 syslog(LOG_ERR, "error: %03u response has no SDP",
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 msg->status_code);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 call->overall_state = OVERALL_STATE_TEARDOWN;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 GSM48_CC_CAUSE_DEST_OOO);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 disconnect_tmgw(call);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 initiate_bye(call);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 rc = extract_sdp(call, msg);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 if (rc < 0) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 syslog(LOG_ERR, "bad SDP in %03u response",
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 msg->status_code);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 call->overall_state = OVERALL_STATE_TEARDOWN;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 GSM48_CC_CAUSE_BEARER_CA_UNAVAIL);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 disconnect_tmgw(call);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 initiate_bye(call);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 call->overall_state = OVERALL_STATE_CONNECTED;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 switch (call->mgw_state) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 case MGW_STATE_ALLOCATED:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 case MGW_STATE_IBT_CONN:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 tmgw_send_mdcx_connect(call, 0);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 case MGW_STATE_MDCX_IBT:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 default:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 syslog(LOG_CRIT,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 "FATAL: invalid MGW state 0x%x on INVITE %03u response",
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 call->mgw_state, msg->status_code);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 exit(1);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 case SIP_STATE_CONNECTED:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 case SIP_STATE_BYE_SENT:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 if (tag && call->to_tag[0] && strcmp(call->to_tag, tag)) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 syslog(LOG_ERR,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 "received %u response with different To tag, ignoring",
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 msg->status_code);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 send_ack(call, call->to_tag, sin);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 case SIP_STATE_CANCEL_SENT:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 case SIP_STATE_ACCEPT_100:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 case SIP_STATE_ACCEPT_200:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 rc = send_ack(call, tag, sin);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 if (rc < 0) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 syslog(LOG_CRIT,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 "ACK to %03u response exceeds msg size!",
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 msg->status_code);
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 158
diff changeset
215 call->sip_state = SIP_STATE_MSG_SIZE_ERR;
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 sip_mark_end_time(call, sip_linger_response_err);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 if (tag)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 strcpy(call->to_tag, tag);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 initiate_bye(call);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 case SIP_STATE_ENDED:
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 158
diff changeset
224 case SIP_STATE_MSG_SIZE_ERR:
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 default:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 syslog(LOG_CRIT,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 "FATAL: invalid SIP state 0x%x on INVITE %03u response",
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 call->sip_state, msg->status_code);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 exit(1);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233
158
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
234 static int
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
235 sip_error_to_gsm_cause(sip_status_code)
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
236 unsigned sip_status_code;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
237 {
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
238 /* mapping taken from osmo-sip-connector */
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
239 switch (sip_status_code) {
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
240 case 400:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
241 return GSM48_CC_CAUSE_TEMP_FAILURE;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
242 case 401:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
243 case 402:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
244 case 403:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
245 return GSM48_CC_CAUSE_CALL_REJECTED;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
246 case 404:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
247 return GSM48_CC_CAUSE_UNASSIGNED_NR;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
248 case 405:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
249 return GSM48_CC_CAUSE_SERV_OPT_UNAVAIL;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
250 case 406:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
251 return GSM48_CC_CAUSE_CHAN_UNACCEPT;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
252 case 407:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
253 return GSM48_CC_CAUSE_CALL_REJECTED;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
254 case 408:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
255 return GSM48_CC_CAUSE_RECOVERY_TIMER;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
256 case 410:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
257 return GSM48_CC_CAUSE_NUMBER_CHANGED;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
258 case 413:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
259 case 414:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
260 return GSM48_CC_CAUSE_INTERWORKING;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
261 case 415:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
262 return GSM48_CC_CAUSE_SERV_OPT_UNIMPL;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
263 case 416:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
264 return GSM48_CC_CAUSE_INVAL_TRANS_ID;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
265 case 420:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
266 case 421:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
267 case 423:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
268 return GSM48_CC_CAUSE_INTERWORKING;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
269 case 480:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
270 return GSM48_CC_CAUSE_USER_NOTRESPOND;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
271 case 481:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
272 return GSM48_CC_CAUSE_TEMP_FAILURE;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
273 case 482:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
274 case 483:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
275 return GSM48_CC_CAUSE_PRE_EMPTION;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
276 case 484:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
277 return GSM48_CC_CAUSE_INV_NR_FORMAT;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
278 case 485:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
279 return GSM48_CC_CAUSE_NO_ROUTE;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
280 case 486:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
281 return GSM48_CC_CAUSE_USER_BUSY;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
282 case 488:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
283 return GSM48_CC_CAUSE_INCOMPAT_DEST;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
284 case 500:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
285 return GSM48_CC_CAUSE_TEMP_FAILURE;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
286 case 501:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
287 return GSM48_CC_CAUSE_SERV_OPT_UNIMPL;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
288 case 502:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
289 return GSM48_CC_CAUSE_DEST_OOO;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
290 case 503:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
291 return GSM48_CC_CAUSE_RESOURCE_UNAVAIL;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
292 case 504:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
293 return GSM48_CC_CAUSE_RECOVERY_TIMER;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
294 case 505:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
295 case 513:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
296 return GSM48_CC_CAUSE_INTERWORKING;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
297 case 600:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
298 return GSM48_CC_CAUSE_USER_BUSY;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
299 case 603:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
300 return GSM48_CC_CAUSE_CALL_REJECTED;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
301 case 604:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
302 return GSM48_CC_CAUSE_NO_ROUTE;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
303 case 606:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
304 return GSM48_CC_CAUSE_INCOMPAT_DEST;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
305 default:
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
306 return GSM48_CC_CAUSE_NORMAL_UNSPEC;
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
307 }
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
308 }
51cf5ea7f320 sip-out: map INVITE errors to GSM cause values
Mychaela Falconia <falcon@freecalypso.org>
parents: 157
diff changeset
309
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 static void
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 handle_error(call, msg, tag, sin)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 struct call *call;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 struct sip_pkt_rx *msg;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 char *tag;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 struct sockaddr_in *sin;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 {
157
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
317 int rc;
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318
163
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 158
diff changeset
319 if (call->sip_state == SIP_STATE_MSG_SIZE_ERR)
bfa9f0c0f0ac sip-out: handle incoming BYE as UAS
Mychaela Falconia <falcon@freecalypso.org>
parents: 158
diff changeset
320 return;
157
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
321 rc = send_ack(call, tag, sin);
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
322 if (rc < 0)
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
323 syslog(LOG_CRIT, "ACK to %03u response exceeds msg size!",
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
324 msg->status_code);
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
325 switch (call->sip_state) {
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
326 case SIP_STATE_INV_SENT:
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
327 case SIP_STATE_100_RCVD:
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
328 call->overall_state = OVERALL_STATE_TEARDOWN;
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
329 disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND,
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
330 sip_error_to_gsm_cause(msg->status_code));
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
331 disconnect_tmgw(call);
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
332 call->sip_state = SIP_STATE_ENDED;
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
333 sip_mark_end_time(call, sip_linger_invite_err);
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
334 return;
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
335 case SIP_STATE_CANCEL_SENT:
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
336 case SIP_STATE_ACCEPT_100:
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
337 case SIP_STATE_ACCEPT_200:
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
338 call->sip_state = SIP_STATE_ENDED;
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
339 sip_mark_end_time(call, sip_linger_invite_err);
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
340 return;
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
341 case SIP_STATE_CONNECTED:
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
342 case SIP_STATE_BYE_SENT:
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
343 case SIP_STATE_ENDED:
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
344 return;
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
345 default:
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
346 syslog(LOG_CRIT,
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
347 "FATAL: invalid SIP state 0x%x on INVITE %03u response",
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
348 call->sip_state, msg->status_code);
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
349 exit(1);
7643b779dbea sip-out: handle INVITE errors, except for cause mapping
Mychaela Falconia <falcon@freecalypso.org>
parents: 156
diff changeset
350 }
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 void
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 handle_invite_response(call, msg, sin)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 struct call *call;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 struct sip_pkt_rx *msg;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 struct sockaddr_in *sin;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358 {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 char *tag;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361 tag = extract_to_tag(msg, call->to_uri);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 if (tag) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 if (!*tag) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364 syslog(LOG_ERR,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365 "To tag in INVITE %03u response is null",
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366 msg->status_code);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 tag = 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368 } else if (strlen(tag) > MAX_SIP_TO_TAG) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 syslog(LOG_ERR,
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370 "To tag in INVITE %03u response exceeds length limit",
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371 msg->status_code);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372 tag = 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375 if (msg->status_code >= 100 && msg->status_code <= 199)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 handle_1xx(call, msg, tag, sin);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 else if (msg->status_code >= 200 && msg->status_code <= 299)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 handle_200(call, msg, tag, sin);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
379 else
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380 handle_error(call, msg, tag, sin);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
381 }