FreeCalypso > hg > themwi-system-sw
annotate sip-manual-out/uac.c @ 85:70c3c8ebee33
sip-in: handle MNCC RTP bogons from OsmoMSC
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 20 Sep 2022 22:47:53 -0800 |
parents | d7b6b8973a83 |
children | a4450ae8fd09 |
rev | line source |
---|---|
71
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement processing of SIP responses to the requests we sent out. |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/socket.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <netinet/in.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <arpa/inet.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <string.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <strings.h> |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "../libsip/parse.h" |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "../libsip/out_msg.h" |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #define MAX_TO_TAG 63 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 extern char *get_single_header(); |
73
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
19 extern char *extract_to_tag(); |
71
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 extern struct in_addr sip_bind_ip; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 extern unsigned sip_bind_port; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 extern char call_id[], from_uri[], to_uri[]; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 char to_tag[MAX_TO_TAG+1]; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 add_req_boilerplate(msg, cseq) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 struct sip_msg_out *msg; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 char *cseq; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 char strbuf[256]; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 int rc; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 sprintf(strbuf, "SIP/2.0/UDP %s:%u", |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 inet_ntoa(sip_bind_ip), sip_bind_port); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 rc = out_msg_add_header(msg, "Via", strbuf); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 return rc; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 rc = out_msg_add_header(msg, "From", from_uri); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return rc; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (to_tag[0]) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 sprintf(strbuf, "<%s>;tag=%s", to_uri, to_tag); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 rc = out_msg_add_header(msg, "To", strbuf); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } else |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 rc = out_msg_add_header(msg, "To", to_uri); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return rc; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 rc = out_msg_add_header(msg, "Call-ID", call_id); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return rc; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 rc = out_msg_add_header(msg, "CSeq", cseq); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 return rc; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return out_msg_add_header(msg, "Max-Forwards", "70"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 add_contact_header(msg) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 struct sip_msg_out *msg; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 char strbuf[80]; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 sprintf(strbuf, "<sip:%s:%u;transport=udp>", |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 inet_ntoa(sip_bind_ip), sip_bind_port); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 return out_msg_add_header(msg, "Contact", strbuf); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 static void |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 send_ack(sin) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 struct sockaddr_in *sin; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 struct sip_msg_out msg; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 int rc; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 rc = start_request_out_msg(&msg, "ACK", to_uri); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (rc < 0) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 msg_size_err: fprintf(stderr, "composing ACK message: size error\n"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 return; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 rc = add_req_boilerplate(&msg, "1 ACK"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (rc < 0) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 goto msg_size_err; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 out_msg_finish(&msg); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 sip_tx_packet(&msg, sin); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 static void |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 handle_invite_response(msg, sin) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 struct sip_pkt_rx *msg; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 struct sockaddr_in *sin; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 { |
73
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
92 char *tag; |
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
93 |
71
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 printf("Response to INVITE: %s\n", msg->status_str); |
73
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
95 tag = extract_to_tag(msg, to_uri); |
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
96 if (tag) { |
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
97 printf("To tag: %s\n", tag); |
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
98 if (strlen(tag) <= MAX_TO_TAG) |
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
99 strcpy(to_tag, tag); |
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
100 else |
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
101 printf("To tag exceeds length limit!\n"); |
d7b6b8973a83
sip-manual-out: handle To tag
Mychaela Falconia <falcon@freecalypso.org>
parents:
71
diff
changeset
|
102 } |
71
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 if (msg->status_code >= 200) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 printf("Sending ACK\n"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 send_ack(sin); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 void |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 process_sip_response(msg, sin) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 struct sip_pkt_rx *msg; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 struct sockaddr_in *sin; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 char *call_id_hdr, *cseq_hdr; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 call_id_hdr = get_single_header(msg, "Call-ID", "i", (int *) 0); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (!call_id_hdr) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 printf("Got SIP response w/o Call-ID header\n"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 return; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 if (strcmp(call_id_hdr, call_id)) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 printf("Got SIP response with wrong Call-ID\n"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 return; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 cseq_hdr = get_single_header(msg, "CSeq", (char *) 0, (int *) 0); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 if (!cseq_hdr) { |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 printf("Got SIP response w/o CSeq header\n"); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 return; |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 } |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 if (!strcmp(cseq_hdr, "1 INVITE")) |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 handle_invite_response(msg, sin); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 else |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 printf("Got SIP resp for our Call-ID with unknown CSeq %s\n", |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 cseq_hdr); |
d74b545a3c2a
sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |