annotate rtp-gsmfr-extr.c @ 5:7c85a7a913f7

rtp-gsmfr-dump: treat stream discontinuities as non-fatal
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 May 2023 06:46:46 +0000
parents 210dfa39f573
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program reads a pcap file, extracts packets belonging to a
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * particular RTP stream as identified by a source or destination
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * IP:port, verifies that an unbroken RTP stream is present, in
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * GSM FR or EFR codec, and writes the FR/EFR frame stream to our
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * extended-libgsm format binary file, to be fed to decoding test
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * programs.
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <sys/types.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <sys/socket.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <netinet/in.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <arpa/inet.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <stdio.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <stdlib.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <string.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <strings.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include <pcap/pcap.h>
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 static pcap_t *pcap;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static in_addr_t match_ip_addr;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static u_short match_udp_port;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 static unsigned iphdr_addr_offset, udphdr_port_offset;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 static unsigned link_hdr_len, ethertype_offset;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 static FILE *outfile;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 static int stream_init_flag;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 static unsigned last_seq, last_tstamp, stream_ssrc;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 static void
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 check_dl_type()
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int dltype;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 dltype = pcap_datalink(pcap);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 switch (dltype) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 case DLT_EN10MB:
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 link_hdr_len = 14;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 ethertype_offset = 12;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 break;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 case DLT_RAW:
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 link_hdr_len = 0;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 break;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 case DLT_LINUX_SLL:
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 link_hdr_len = 16;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 ethertype_offset = 14;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 break;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 default:
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 fprintf(stderr, "error: unsupported data link type %d\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 dltype);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 static void
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 rtp_stream_logic(rtp_hdr, pkt_idx)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 u_char *rtp_hdr;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 unsigned pkt_idx;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 unsigned cur_seq, cur_tstamp, cur_ssrc;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 cur_seq = (rtp_hdr[2] << 8) | rtp_hdr[3];
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 cur_tstamp = (rtp_hdr[4] << 24) | (rtp_hdr[5] << 16) |
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 (rtp_hdr[6] << 8) | rtp_hdr[7];
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 cur_ssrc = (rtp_hdr[8] << 24) | (rtp_hdr[9] << 16) |
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 (rtp_hdr[10] << 8) | rtp_hdr[11];
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (stream_init_flag) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (cur_ssrc != stream_ssrc) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 "error in packet #%u: SSRC change from 0x%08X to 0x%08X\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 pkt_idx, stream_ssrc, cur_ssrc);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (cur_seq != last_seq + 1 &&
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 (cur_seq != 0 || last_seq != 0xFFFF)) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 "error in packet #%u: seq break from 0x%04X to 0x%04X\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 pkt_idx, last_seq, cur_seq);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (cur_tstamp != last_tstamp + 160) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 "error in packet #%u: timestamp break from 0x%08X to 0x%08X\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 pkt_idx, last_tstamp, cur_tstamp);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 } else {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 stream_init_flag = 1;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 stream_ssrc = cur_ssrc;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 last_seq = cur_seq;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 last_tstamp = cur_tstamp;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 static void
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 process_packet(pkt, caplen, pkt_idx)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 u_char *pkt;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 unsigned caplen, pkt_idx;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 unsigned udplen, payload_len;
2
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
100 u_char synth_bfi[2];
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (caplen < link_hdr_len + 28)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 if (link_hdr_len) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 if (pkt[ethertype_offset] != 0x08)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 if (pkt[ethertype_offset+1] != 0x00)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 pkt += link_hdr_len;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 caplen -= link_hdr_len;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 /* check IP header */
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 if (pkt[0] != 0x45)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 if (pkt[9] != 17) /* UDP */
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (bcmp(pkt + iphdr_addr_offset, &match_ip_addr, 4))
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 /* check UDP header */
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 if (bcmp(pkt + 20 + udphdr_port_offset, &match_udp_port, 2))
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 return;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 /* it is our target - now scrutinize it */
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 udplen = (pkt[24] << 8) | pkt[25];
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 if (caplen < udplen + 20) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 "error: packet #%u is truncated in the capture\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 pkt_idx);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 if (udplen < 20) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 "error in packet #%u: UDP length is too short for RTP header\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 pkt_idx);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 if (pkt[28] != 0x80) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 "error in packet #%u: unsupported RTP header structure\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 pkt_idx);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 rtp_stream_logic(pkt + 28, pkt_idx);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 payload_len = udplen - 20;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 switch (payload_len) {
2
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
145 case 0:
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
146 synth_bfi[0] = 0xBF;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
147 synth_bfi[1] = 0;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
148 emit_synth_bfi:
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
149 fwrite(synth_bfi, 1, 2, outfile);
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
150 return;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
151 case 1:
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
152 if ((pkt[40] & 0xF6) != 0xE6)
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
153 break;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
154 traulike_bfi:
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
155 synth_bfi[0] = 0xBF;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
156 synth_bfi[1] = pkt[40] & 1;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
157 goto emit_synth_bfi;
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 case 2:
2
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
159 if (pkt[40] != 0xBF)
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 break;
2
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
161 emit_payload:
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
162 fwrite(pkt + 40, 1, payload_len, outfile);
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
163 return;
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 case 31:
2
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
165 if ((pkt[40] & 0xF0) != 0xC0)
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
166 break;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
167 goto emit_payload;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
168 case 32:
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
169 if ((pkt[40] & 0xF4) != 0xE0)
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 break;
2
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
171 if ((pkt[41] & 0xF0) != 0xC0)
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
172 break;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
173 if (pkt[40] & 2)
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
174 goto traulike_bfi;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
175 fwrite(pkt + 41, 1, 31, outfile);
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
176 return;
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 case 33:
2
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
178 if ((pkt[40] & 0xF0) != 0xD0)
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
179 break;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
180 goto emit_payload;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
181 case 34:
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
182 if ((pkt[40] & 0xF4) != 0xE0)
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
183 break;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
184 if ((pkt[41] & 0xF0) != 0xD0)
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 break;
2
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
186 if (pkt[40] & 2)
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
187 goto traulike_bfi;
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
188 fwrite(pkt + 41, 1, 33, outfile);
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
189 return;
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 }
2
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
191 fprintf(stderr, "error in packet #%u: unsupported payload\n", pkt_idx);
210dfa39f573 rtp-gsmfr-extr: support new TRAUlike RTP payload format
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
192 exit(1);
0
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 main(argc, argv)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 char **argv;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 char errbuf[PCAP_ERRBUF_SIZE];
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 u_char *pkt;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 struct pcap_pkthdr pkthdr;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 unsigned pkt_idx;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 if (argc != 6) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 "usage: %s pcap-file src|dest ip-addr udp-port outfile\n",
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 argv[0]);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 pcap = pcap_open_offline(argv[1], errbuf);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 if (!pcap) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 fprintf(stderr, "%s: %s\n", argv[1], errbuf);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 check_dl_type();
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 if (!strcmp(argv[2], "src")) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 iphdr_addr_offset = 12;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 udphdr_port_offset = 0;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 } else if (!strcmp(argv[2], "dest")) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 iphdr_addr_offset = 16;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 udphdr_port_offset = 2;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 } else {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 fprintf(stderr,
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 "error: direction argument must be \"src\" or \"dest\"\n");
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 match_ip_addr = inet_addr(argv[3]);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 if (match_ip_addr == INADDR_NONE) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 fprintf(stderr, "error: IP address argument is invalid\n");
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 match_udp_port = htons(strtoul(argv[4], 0, 0));
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 outfile = fopen(argv[5], "w");
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 if (!outfile) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 perror(argv[5]);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 for (pkt_idx = 0; ; pkt_idx++) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 pkt = pcap_next(pcap, &pkthdr);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 if (!pkt)
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 break;
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 process_packet(pkt, (unsigned) pkthdr.caplen, pkt_idx);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 if (!stream_init_flag) {
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 fprintf(stderr, "error: specified RTP stream not found\n");
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 exit(1);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 }
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 fclose(outfile);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 exit(0);
05ff0f7ac977 initial commit: split from gsm-codec-lib
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 }