annotate sip-out/uac_out.c @ 198:cf1ba5d65188

mgw: start using project-global rtp_defs.h
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 29 Mar 2023 20:06:40 -0800
parents e54b0a9e322f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement generation of outgoing SIP messages
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * in the UAC role.
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/socket.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/time.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <netinet/in.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdint.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <string.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <strings.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <syslog.h>
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../include/gsm48_const.h"
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../include/out_routes.h"
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "../libsip/out_msg.h"
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "../libsip/sdp.h"
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "call.h"
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern struct call *find_call_by_sip_id();
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern struct in_addr sip_bind_ip;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 extern unsigned sip_bind_port;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern unsigned max_forwards;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 extern struct timeval cur_event_time;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 add_req_boilerplate(msg, call, cseq, to_tag)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 struct sip_msg_out *msg;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 char *cseq, *to_tag;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 char strbuf[256];
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 int rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 sprintf(strbuf, "SIP/2.0/UDP %s:%u",
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 inet_ntoa(sip_bind_ip), sip_bind_port);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 rc = out_msg_add_header(msg, "Via", strbuf);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 rc = out_msg_add_header(msg, "From", call->from_header);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (to_tag && to_tag[0]) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 sprintf(strbuf, "<%s>;tag=%s", call->to_uri, to_tag);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 rc = out_msg_add_header(msg, "To", strbuf);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 } else
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 rc = out_msg_add_header(msg, "To", call->to_uri);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 rc = out_msg_add_header(msg, "Call-ID", call->sip_call_id);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 rc = out_msg_add_header(msg, "CSeq", cseq);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 sprintf(strbuf, "%u", max_forwards);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return out_msg_add_header(msg, "Max-Forwards", strbuf);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 add_contact_header(msg)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 struct sip_msg_out *msg;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 char strbuf[80];
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 sprintf(strbuf, "<sip:%s:%u;transport=udp>",
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 inet_ntoa(sip_bind_ip), sip_bind_port);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return out_msg_add_header(msg, "Contact", strbuf);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 fill_invite_req_msg(msg, call)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 struct sip_msg_out *msg;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 struct sdp_gen sdp;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 int rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 rc = start_request_out_msg(msg, "INVITE", call->to_uri);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 rc = add_req_boilerplate(msg, call, "1 INVITE", (char *) 0);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 rc = add_contact_header(msg);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 rc = out_msg_add_header(msg, "Content-Type", "application/sdp");
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 bzero(&sdp, sizeof sdp);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 sdp.conn_ip = call->pstn_rtp_local.sin_addr;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 sdp.conn_port = ntohs(call->pstn_rtp_local.sin_port);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 sdp.codec_mask = SDP_CODEC_MASK_BOTH;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 sdp.session_id = sdp.conn_port << 16;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 sdp.owner_ip = sip_bind_ip;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 return out_msg_finish_sdp(msg, &sdp);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 fill_cancel_req_msg(msg, call)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 struct sip_msg_out *msg;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 int rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 rc = start_request_out_msg(msg, "CANCEL", call->to_uri);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 rc = add_req_boilerplate(msg, call, "1 CANCEL", (char *) 0);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 out_msg_finish(msg);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 return 0;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 fill_bye_req_msg(msg, call)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 struct sip_msg_out *msg;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 int rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 rc = start_request_out_msg(msg, "BYE", call->to_uri);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 rc = add_req_boilerplate(msg, call, "2 BYE", call->to_tag);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 if (rc < 0)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 return rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 out_msg_finish(msg);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 return 0;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 void
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 start_sip_out(call)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 struct sip_msg_out msg;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 int rc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 sprintf(call->sip_call_id, "%08u_%u@%s",
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 (unsigned)(cur_event_time.tv_sec % 100000000),
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 ntohs(call->pstn_rtp_local.sin_port), inet_ntoa(sip_bind_ip));
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 if (find_call_by_sip_id(call->sip_call_id)) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 syslog(LOG_ERR, "generated Call-ID collision!");
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 call->overall_state = OVERALL_STATE_TEARDOWN;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 GSM48_CC_CAUSE_SWITCH_CONG);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 disconnect_tmgw(call);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 sprintf(call->from_header, "<sip:%s@%s>;tag=out%u", call->from_user,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 inet_ntoa(sip_bind_ip), ntohs(call->pstn_rtp_local.sin_port));
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 rc = fill_invite_req_msg(&msg, call);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 if (rc < 0) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 syslog(LOG_CRIT, "generated SIP INVITE req exceeds msg size!");
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 call->overall_state = OVERALL_STATE_TEARDOWN;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 GSM48_CC_CAUSE_NETWORK_OOO);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 disconnect_tmgw(call);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 sip_tx_packet(&msg, &call->udp_sin);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 call->overall_state = OVERALL_STATE_SIP_OUT;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 call->sip_call_exists = 1;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 call->sip_state = SIP_STATE_INV_SENT;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 call->sip_tx_count = 1;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 void
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 initiate_sip_cancel(call)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 struct sip_msg_out msg;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 fill_cancel_req_msg(&msg, call);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 sip_tx_packet(&msg, &call->udp_sin);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 call->sip_state = SIP_STATE_CANCEL_SENT;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 call->sip_tx_count = 1;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 void
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 initiate_bye(call)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 struct sip_msg_out msg;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 fill_bye_req_msg(&msg, call);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 sip_tx_packet(&msg, &call->udp_sin);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 call->sip_state = SIP_STATE_BYE_SENT;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 call->sip_tx_count = 1;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 }