annotate sip-in/sip_ack.c @ 197:73bbe7da45cd

add LICENSE
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 26 Mar 2023 15:29:48 -0800
parents c1c94b7fc2e2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
69
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement our handling of SIP ACK, the last step
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * in the 3-way INVITE handshake.
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/socket.h>
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
8 #include <sys/time.h>
69
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <netinet/in.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdint.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <string.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <strings.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <syslog.h>
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../libsip/parse.h"
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../libsip/uas_basic.h"
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "call.h"
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern struct call *find_call_by_sip_id();
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
22 extern unsigned sip_linger_acked;
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
23
69
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 void
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 handle_sip_ack(req, ess, sin)
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 struct sip_pkt_rx *req;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 struct uas_parse_hdrs *ess;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 struct sockaddr_in *sin;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 struct call *call;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 call = find_call_by_sip_id(ess->call_id);
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (!call)
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 return; /* ignore spurious ACK */
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 /* weed out wrong CSeq */
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (ess->cseq_num != call->invite_cseq)
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 return;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 switch (call->sip_state) {
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 case SIP_STATE_INVITE_200:
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
40 switch (call->overall_state) {
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
41 case OVERALL_STATE_ANSWERED:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
42 call->sip_state = SIP_STATE_CONNECTED;
87
9e9034ef476c sip-in: send CONNECT ACK to GSM upon SIP ACK after 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 83
diff changeset
43 send_mncc_connect_ack(call);
83
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
44 break;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
45 case OVERALL_STATE_TEARDOWN:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
46 initiate_bye(call);
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
47 break;
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
48 default:
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
49 syslog(LOG_CRIT,
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
50 "FATAL: invalid overall state 0x%x on SIP ACK",
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
51 call->overall_state);
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
52 exit(1);
3e3fbf44f9d7 sip-in: disconnect and call clearing implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 69
diff changeset
53 }
69
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 break;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 case SIP_STATE_INVITE_ERR:
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 call->sip_state = SIP_STATE_ENDED;
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
57 sip_mark_end_time(call, sip_linger_acked);
110
c1c94b7fc2e2 sip-in call clearing: DEAD_SIP transition implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 109
diff changeset
58 transition_dead_sip(call);
69
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 break;
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
8cf85edca543 sip-in: implement SIP ACK handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }