FreeCalypso > hg > themwi-system-sw
annotate sip-in/invite.c @ 110:c1c94b7fc2e2
sip-in call clearing: DEAD_SIP transition implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 28 Sep 2022 18:37:19 -0800 |
parents | 9b87894704eb |
children | bfc97065bf51 |
rev | line source |
---|---|
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement our handling of SIP INVITE method. |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
8117d8ee44a5
sip-in: beginning of INVITE 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> |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <netinet/in.h> |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
9 #include <arpa/inet.h> |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
11 #include <stdint.h> |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <string.h> |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <strings.h> |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <syslog.h> |
66
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
16 #include "../include/gsm48_const.h" |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "../libsip/parse.h" |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "../libsip/uas_basic.h" |
51
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
19 #include "../libsip/grok_from.h" |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
20 #include "../libsip/req_supp.h" |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
21 #include "../libsip/sdp.h" |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "../libsip/out_msg.h" |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
23 #include "call.h" |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
25 extern struct in_addr sip_bind_ip; |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
26 extern unsigned sip_bind_port; |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
27 extern int cfg_use_100rel; |
104
ce3b1db7d1d7
sip-in: force-pcma-codec config option to use PCMA when both are offered
Mychaela Falconia <falcon@freecalypso.org>
parents:
77
diff
changeset
|
28 extern int cfg_force_pcma; |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
29 extern struct call *call_list; |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
30 extern unsigned sip_linger_error; |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
31 |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
32 extern struct call *find_call_by_sip_id(); |
50
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
33 extern char *get_single_header(); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
34 |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
35 fill_invite_resp_from_call(msg, call) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
36 struct sip_msg_out *msg; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
37 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
38 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
39 char cseq_str[32]; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
40 int rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
41 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
42 rc = out_msg_add_header(msg, "From", call->invite_from); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
43 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
44 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
45 rc = out_msg_add_header(msg, "To", call->invite_to); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
46 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
47 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
48 rc = out_msg_add_header(msg, "Call-ID", call->sip_call_id); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
49 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
50 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
51 sprintf(cseq_str, "%u INVITE", call->invite_cseq); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
52 rc = out_msg_add_header(msg, "CSeq", cseq_str); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
53 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
54 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
55 return out_msg_add_header(msg, "Via", call->invite_via); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
56 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
57 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
58 fill_invite_200_resp(msg, call) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
59 struct sip_msg_out *msg; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
60 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
61 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
62 char contact_str[80]; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
63 struct sdp_gen sdp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
64 int rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
65 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
66 start_response_out_msg(msg, "200 CONNECT"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
67 rc = fill_invite_resp_from_call(msg, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
68 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
69 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
70 sprintf(contact_str, "<sip:%s:%u;transport=udp>", |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
71 inet_ntoa(sip_bind_ip), sip_bind_port); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
72 rc = out_msg_add_header(msg, "Contact", contact_str); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
73 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
74 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
75 rc = out_msg_add_header(msg, "Content-Type", "application/sdp"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
76 if (rc < 0) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
77 return rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
78 bzero(&sdp, sizeof sdp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
79 sdp.conn_ip = call->pstn_rtp_local.sin_addr; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
80 sdp.conn_port = ntohs(call->pstn_rtp_local.sin_port); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
81 sdp.codec_mask = call->use_pcma ? SDP_CODEC_MASK_PCMA |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
82 : SDP_CODEC_MASK_PCMU; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
83 sdp.session_id = (sdp.conn_port << 16) | call->sdp_addend; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
84 sdp.owner_ip = sip_bind_ip; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
85 return out_msg_finish_sdp(msg, &sdp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
86 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
87 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
88 static void |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
89 invite_new_call(req, ess, sin) |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 struct sip_pkt_rx *req; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 struct uas_parse_hdrs *ess; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 struct sockaddr_in *sin; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 { |
77
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
94 static unsigned cycle_tag_num, cycle_sdp_addend; |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 char uri_user[13], *called_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 struct sip_msg_out resp; |
51
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
97 struct grok_from gfrom; |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
98 struct supported_ext supp_ext; |
50
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
99 char *hval, *unsup_ext; |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
100 int ext_100rel_req, ext_100rel_sup, use_100rel, use_pcma; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
101 struct sdp_parse sdp_parse; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
102 struct sdp_gen sdp_gen; |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
103 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
104 char *dp; |
76
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
105 unsigned req_uri_len, to_hdr_len, copylen; |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 int rc; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 /* extract called number from Request-URI */ |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 rc = user_from_sip_uri(req->req_uri, uri_user, 12); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 if (rc < 0) { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 not_nanp: start_response_out_msg(&resp, |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 "416 Request-URI is not a NANP number"); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 error_resp: rc = add_resp_basic_headers(&resp, ess, req->req_method); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 if (rc < 0) { |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
115 error_resp_toolong: syslog(LOG_ERR, |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
116 "INVITE early error response length exceeded"); |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 return; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 out_msg_finish(&resp); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 sip_tx_packet(&resp, sin); |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
121 return; |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 } |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 if (uri_user[0] == '+') { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 if (grok_number_string(uri_user+1, 0) != 11 || |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 uri_user[1] != '1') |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 called_nanp = uri_user + 2; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 } else switch (grok_number_string(uri_user)) { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 case 10: |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 called_nanp = uri_user; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 break; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 case 11: |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 if (uri_user[0] != '1') |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 called_nanp = uri_user + 1; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 break; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 default: |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 } |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 if (!is_nanp_valid_prefix(called_nanp)) |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 /* it is valid NANP - but is it one of ours? */ |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 refresh_number_db(); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 if (!is_nanp_locally_owned(called_nanp)) { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 start_response_out_msg(&resp, |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 "404 Called number does not belong here"); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 goto error_resp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 } |
51
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
149 /* parse and validate From header */ |
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
150 rc = grok_from_header(ess->from, &gfrom); |
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
151 if (rc < 0) { |
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
152 start_response_out_msg(&resp, "400 Malformed From header"); |
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
153 goto error_resp; |
36a30349b490
sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
50
diff
changeset
|
154 } |
76
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
155 /* validate To header for the purpose of tag addition */ |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
156 req_uri_len = strlen(req->req_uri); |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
157 to_hdr_len = strlen(ess->to); |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
158 if (to_hdr_len == req_uri_len) { |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
159 if (strcasecmp(ess->to, req->req_uri)) { |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
160 bad_to_header: start_response_out_msg(&resp, "400 Bad To header"); |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
161 goto error_resp; |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
162 } |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
163 } else if (to_hdr_len == req_uri_len + 2) { |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
164 if (ess->to[0] != '<') |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
165 goto bad_to_header; |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
166 if (strncasecmp(ess->to+1, req->req_uri, req_uri_len)) |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
167 goto bad_to_header; |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
168 if (ess->to[req_uri_len+1] != '>') |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
169 goto bad_to_header; |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
170 } else |
21276f045026
sip-in: validate To header prior to tag addition
Mychaela Falconia <falcon@freecalypso.org>
parents:
66
diff
changeset
|
171 goto bad_to_header; |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
172 /* check 100rel and catch any unsupported requirements */ |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
173 supp_ext.name = "100rel"; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
174 supp_ext.req_flag = &ext_100rel_req; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
175 supp_ext.sup_flag = &ext_100rel_sup; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
176 ext_100rel_req = ext_100rel_sup = 0; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
177 rc = parse_require_supported(req, &supp_ext, 1, &unsup_ext); |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
178 if (rc < 0) { |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
179 start_response_out_msg(&resp, "420 Extension not supported"); |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
180 rc = out_msg_add_header(&resp, "Unsupported", unsup_ext); |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
181 if (rc < 0) |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
182 goto error_resp_toolong; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
183 goto error_resp; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
184 } |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
185 if (ext_100rel_req) |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
186 use_100rel = 1; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
187 else if (ext_100rel_sup) |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
188 use_100rel = cfg_use_100rel; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
189 else |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
190 use_100rel = 0; |
50
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
191 /* did the caller send an SDP message body? */ |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
192 if (!req->msg_body_len) { |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
193 start_response_out_msg(&resp, "415 Missing SDP body"); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
194 error_415: rc = out_msg_add_header(&resp, "Accept", "application/sdp"); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
195 if (rc < 0) |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
196 goto error_resp_toolong; |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
197 goto error_resp; |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
198 } |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
199 hval = get_single_header(req, "Content-Type", "c", (int *) 0); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
200 if (!hval) { |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
201 start_response_out_msg(&resp, |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
202 "415 Missing Content-Type header"); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
203 goto error_415; |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
204 } |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
205 if (strcasecmp(hval, "application/sdp")) { |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
206 start_response_out_msg(&resp, "415 Unsupported Content-Type"); |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
207 goto error_415; |
daf1c26d7ae2
sip-in: check INVITE Content-Type header
Mychaela Falconia <falcon@freecalypso.org>
parents:
49
diff
changeset
|
208 } |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
209 rc = parse_incoming_sdp(req->msg_body, req->msg_body_len, &sdp_parse); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
210 if (rc < 0) { |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
211 start_response_out_msg(&resp, "488 Malformed SDP body"); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
212 goto error_resp; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
213 } |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
214 switch (sdp_parse.codec_mask) { |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
215 case SDP_CODEC_MASK_PCMU: |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
216 use_pcma = 0; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
217 break; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
218 case SDP_CODEC_MASK_PCMA: |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
219 case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF: |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
220 use_pcma = 1; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
221 break; |
104
ce3b1db7d1d7
sip-in: force-pcma-codec config option to use PCMA when both are offered
Mychaela Falconia <falcon@freecalypso.org>
parents:
77
diff
changeset
|
222 case SDP_CODEC_MASK_BOTH: |
ce3b1db7d1d7
sip-in: force-pcma-codec config option to use PCMA when both are offered
Mychaela Falconia <falcon@freecalypso.org>
parents:
77
diff
changeset
|
223 use_pcma = cfg_force_pcma; |
ce3b1db7d1d7
sip-in: force-pcma-codec config option to use PCMA when both are offered
Mychaela Falconia <falcon@freecalypso.org>
parents:
77
diff
changeset
|
224 break; |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
225 default: |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
226 start_response_out_msg(&resp, |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
227 "488 Unsupported codec selection"); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
228 rc = add_resp_basic_headers(&resp, ess, req->req_method); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
229 if (rc < 0) |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
230 goto error_resp_toolong; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
231 rc = out_msg_add_header(&resp, "Content-Type", |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
232 "application/sdp"); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
233 if (rc < 0) |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
234 goto error_resp_toolong; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
235 bzero(&sdp_gen, sizeof sdp_gen); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
236 sdp_gen.owner_ip = sip_bind_ip; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
237 sdp_gen.conn_ip = sip_bind_ip; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
238 sdp_gen.codec_mask = SDP_CODEC_MASK_BOTH; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
239 rc = out_msg_finish_sdp(&resp, &sdp_gen); |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
240 if (rc < 0) |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
241 goto error_resp_toolong; |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
242 sip_tx_packet(&resp, sin); |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
243 return; |
55
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
244 } |
f1d59210f7b2
sip-in INVITE processing: grok SDP
Mychaela Falconia <falcon@freecalypso.org>
parents:
51
diff
changeset
|
245 /* SIP INVITE validation done - check if GSM service is up */ |
57
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
246 rc = connect_gsm_mtcall(); |
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
247 if (rc < 0) { |
107
372209628038
sip-in: handle themwi-mgw shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
248 gsm_offline: start_response_out_msg(&resp, "480 GSM service is offline"); |
57
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
249 goto error_resp; |
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
250 } |
107
372209628038
sip-in: handle themwi-mgw shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
251 rc = connect_tmgw_socket(); |
372209628038
sip-in: handle themwi-mgw shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
252 if (rc < 0) |
372209628038
sip-in: handle themwi-mgw shutdown without terminating
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
253 goto gsm_offline; |
57
d61d0136f6a5
sip-in INVITE processing: return "GSM service is offline" indication
Mychaela Falconia <falcon@freecalypso.org>
parents:
55
diff
changeset
|
254 /* stateful processing begins */ |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
255 call = malloc(sizeof(struct call) + strlen(ess->call_id) + |
77
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
256 strlen(ess->from) + req_uri_len + strlen(ess->via) + 19); |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
257 if (!call) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
258 syslog(LOG_CRIT, "failed malloc for incoming call!"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
259 start_response_out_msg(&resp, |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
260 "503 Gateway resource allocation failure"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
261 goto error_resp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
262 } |
77
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
263 cycle_tag_num++; |
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
264 if (cycle_tag_num >= 1000000) |
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
265 cycle_tag_num = 0; |
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
266 cycle_sdp_addend++; |
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
267 if (cycle_sdp_addend >= 0x10000) |
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
268 cycle_sdp_addend = 0; |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
269 bzero(call, sizeof(struct call)); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
270 dp = (char *)(call + 1); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
271 copylen = strlen(ess->call_id) + 1; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
272 call->sip_call_id = dp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
273 bcopy(ess->call_id, dp, copylen); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
274 dp += copylen; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
275 copylen = strlen(ess->from) + 1; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
276 call->invite_from = dp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
277 bcopy(ess->from, dp, copylen); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
278 dp += copylen; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
279 call->invite_to = dp; |
77
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
280 *dp++ = '<'; |
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
281 bcopy(req->req_uri, dp, req_uri_len); |
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
282 dp += req_uri_len; |
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
283 *dp++ = '>'; |
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
284 sprintf(dp, ";tag=in%06u", cycle_tag_num); |
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
285 dp += 14; |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
286 copylen = strlen(ess->via) + 1; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
287 call->invite_via = dp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
288 bcopy(ess->via, dp, copylen); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
289 call->invite_cseq = ess->cseq_num; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
290 bcopy(sin, &call->udp_sin, sizeof(struct sockaddr_in)); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
291 bcopy(called_nanp, call->called_nanp, 11); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
292 call->from_uri = call->invite_from + (gfrom.uri - ess->from); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
293 call->from_uri_len = gfrom.uri_len; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
294 call->from_user = call->invite_from + (gfrom.user - ess->from); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
295 call->from_user_len = gfrom.user_len; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
296 call->use_100rel = use_100rel; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
297 call->pstn_rtp_remote.sin_family = AF_INET; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
298 call->pstn_rtp_remote.sin_addr = sdp_parse.ip_addr; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
299 call->pstn_rtp_remote.sin_port = htons(sdp_parse.audio_port); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
300 call->use_pcma = use_pcma; |
77
fe39404092d9
sip-in: generate To tags
Mychaela Falconia <falcon@freecalypso.org>
parents:
76
diff
changeset
|
301 call->sdp_addend = cycle_sdp_addend; |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
302 /* generate 100 response */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
303 start_response_out_msg(&resp, "100 Proceeding"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
304 rc = fill_invite_resp_from_call(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
305 if (rc < 0) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
306 syslog(LOG_ERR, "INVITE 100 response length exceeded"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
307 free(call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
308 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
309 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
310 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
311 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
312 /* add to call list */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
313 call->next = call_list; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
314 call_list = call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
315 /* send CRCX to TMGW */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
316 tmgw_send_crcx(call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
317 call->overall_state = OVERALL_STATE_CRCX; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
318 call->sip_state = SIP_STATE_INVITE_PROC; |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 } |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
320 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
321 static void |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
322 invite_existing_call(req, ess, sin, call) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
323 struct sip_pkt_rx *req; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
324 struct uas_parse_hdrs *ess; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
325 struct sockaddr_in *sin; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
326 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
327 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
328 struct sip_msg_out resp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
329 int rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
330 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
331 if (ess->cseq_num != call->invite_cseq) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
332 start_response_out_msg(&resp, "501 Re-INVITE not supported"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
333 rc = add_resp_basic_headers(&resp, ess, req->req_method); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
334 if (rc < 0) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
335 syslog(LOG_ERR, |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
336 "sending 501 Re-INVITE error: response length exceeded"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
337 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
338 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
339 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
340 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
341 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
342 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
343 /* it's a retransmission, not a re-INVITE */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
344 switch (call->sip_state) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
345 case SIP_STATE_INVITE_PROC: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
346 start_response_out_msg(&resp, "100 Proceeding"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
347 fill_invite_resp_from_call(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
348 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
349 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
350 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
351 case SIP_STATE_RINGING: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
352 start_response_out_msg(&resp, "180 Ringing"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
353 fill_invite_resp_from_call(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
354 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
355 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
356 return; |
108
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
357 case SIP_STATE_RINGING_REL: |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
358 start_response_out_msg(&resp, "180 Ringing"); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
359 fill_invite_resp_from_call(&resp, call); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
360 out_msg_add_header(&resp, "Require", "100rel"); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
361 out_msg_add_header(&resp, "RSeq", "1"); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
362 out_msg_finish(&resp); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
363 sip_tx_packet(&resp, sin); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
364 return; |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
365 case SIP_STATE_INVITE_200: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
366 case SIP_STATE_CONNECTED: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
367 fill_invite_200_resp(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
368 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
369 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
370 case SIP_STATE_INVITE_ERR: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
371 start_response_out_msg(&resp, call->invite_fail); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
372 fill_invite_resp_from_call(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
373 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
374 sip_tx_packet(&resp, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
375 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
376 default: |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
377 /* silently discard */ |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
378 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
379 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
380 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
381 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
382 void |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
383 handle_sip_invite(req, ess, sin) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
384 struct sip_pkt_rx *req; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
385 struct uas_parse_hdrs *ess; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
386 struct sockaddr_in *sin; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
387 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
388 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
389 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
390 call = find_call_by_sip_id(ess->call_id); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
391 if (call) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
392 invite_existing_call(req, ess, sin, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
393 else |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
394 invite_new_call(req, ess, sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
395 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
396 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
397 void |
65
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
398 signal_invite_ringing(call) |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
399 struct call *call; |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
400 { |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
401 struct sip_msg_out resp; |
108
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
402 int rc; |
65
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
403 |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
404 start_response_out_msg(&resp, "180 Ringing"); |
108
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
405 rc = fill_invite_resp_from_call(&resp, call); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
406 if (rc < 0) { |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
407 msg_size_err: syslog(LOG_ERR, "INVITE 180 response length exceeded"); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
408 call->sip_state = SIP_STATE_MSG_SIZE_ERR; |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
409 call->overall_state = OVERALL_STATE_TEARDOWN; |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
410 disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU, |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
411 GSM48_CC_CAUSE_INTERWORKING); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
412 disconnect_tmgw(call); |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
413 sip_mark_end_time(call, sip_linger_error); |
108
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
414 return; |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
415 } |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
416 if (call->use_100rel) { |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
417 rc = out_msg_add_header(&resp, "Require", "100rel"); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
418 if (rc < 0) |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
419 goto msg_size_err; |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
420 rc = out_msg_add_header(&resp, "RSeq", "1"); |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
421 if (rc < 0) |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
422 goto msg_size_err; |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
423 } |
65
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
424 out_msg_finish(&resp); |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
425 sip_tx_packet(&resp, &call->udp_sin); |
108
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
426 if (call->use_100rel) { |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
427 call->sip_state = SIP_STATE_RINGING_REL; |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
428 call->sip_tx_count = 1; |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
429 } else |
0d6435808bcd
sip-in: implement 100rel for 180 Ringing response
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
430 call->sip_state = SIP_STATE_RINGING; |
65
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
431 } |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
432 |
7c0309df59f8
sip-in: handling of ALERTING state
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
433 void |
66
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
434 signal_invite_200(call) |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
435 struct call *call; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
436 { |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
437 struct sip_msg_out resp; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
438 int rc; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
439 |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
440 rc = fill_invite_200_resp(&resp, call); |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
441 if (rc < 0) { |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
442 syslog(LOG_ERR, "INVITE 200 response length exceeded"); |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
443 call->sip_state = SIP_STATE_MSG_SIZE_ERR; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
444 call->overall_state = OVERALL_STATE_TEARDOWN; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
445 disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU, |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
446 GSM48_CC_CAUSE_INTERWORKING); |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
447 disconnect_tmgw(call); |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
448 sip_mark_end_time(call, sip_linger_error); |
66
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
449 return; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
450 } |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
451 sip_tx_packet(&resp, &call->udp_sin); |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
452 call->sip_state = SIP_STATE_INVITE_200; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
453 call->sip_tx_count = 1; |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
454 } |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
455 |
5beb51de1bae
sip-in: got as far as propagating GSM CC CONNECT to INVITE 200
Mychaela Falconia <falcon@freecalypso.org>
parents:
65
diff
changeset
|
456 void |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
457 signal_invite_error(call) |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
458 struct call *call; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
459 { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
460 struct sip_msg_out resp; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
461 int rc; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
462 |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
463 start_response_out_msg(&resp, call->invite_fail); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
464 rc = fill_invite_resp_from_call(&resp, call); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
465 if (rc < 0) { |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
466 syslog(LOG_ERR, "INVITE late error response length exceeded"); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
467 call->sip_state = SIP_STATE_MSG_SIZE_ERR; |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
468 sip_mark_end_time(call, sip_linger_error); |
110
c1c94b7fc2e2
sip-in call clearing: DEAD_SIP transition implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
109
diff
changeset
|
469 transition_dead_sip(call); |
60
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
470 return; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
471 } |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
472 out_msg_finish(&resp); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
473 sip_tx_packet(&resp, &call->udp_sin); |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
474 call->sip_state = SIP_STATE_INVITE_ERR; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
475 call->sip_tx_count = 1; |
02761f1ae5e5
sip-in INVITE processing: got as far as CRCX completion
Mychaela Falconia <falcon@freecalypso.org>
parents:
57
diff
changeset
|
476 } |