1 /* rtp_stream.h
2  * RTP streams summary addition for Wireshark
3  *
4  * Copyright 2003, Alcatel Business Systems
5  * By Lars Ruoff <lars.ruoff@gmx.net>
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * SPDX-License-Identifier: GPL-2.0-or-later
12  */
13 
14 #ifndef __RTP_STREAM_H__
15 #define __RTP_STREAM_H__
16 
17 #include <glib.h>
18 
19 #include "tap-rtp-analysis.h"
20 #include <stdio.h>
21 
22 #include "cfile.h"
23 
24 #include <epan/address.h>
25 #include <epan/tap.h>
26 
27 #include "ui/rtp_stream_id.h"
28 
29 /** @file
30  *  "RTP Streams" dialog box common routines.
31  *  @ingroup main_ui_group
32  */
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif /* __cplusplus */
37 
38 /** Defines an rtp stream */
39 typedef struct _rtpstream_info {
40     rtpstream_id_t  id;
41 
42     guint8          first_payload_type; /**< Numeric payload type */
43     const gchar    *first_payload_type_name; /**< Payload type name */
44     const gchar    *payload_type_names[256]; /**< Seen payload type names. Array index is payload type (byte), filled only during TAP_ANALYSE */
45     gchar          *all_payload_type_names; /**< All seen payload names for a stream in one string */
46 
47     gboolean        is_srtp;
48     guint32         packet_count;
49     gboolean        end_stream; /**< Used to track streams across payload types */
50     int             rtp_event;
51 
52     int             call_num; /**< Used to match call_num in voip_calls_info_t */
53     guint32         setup_frame_number; /**< frame number of setup message */
54     /* Start and stop packets needed for .num and .abs_ts */
55     frame_data     *start_fd;
56     frame_data     *stop_fd;
57     nstime_t        start_rel_time;     /**< relative start time from pinfo */
58     nstime_t        stop_rel_time;      /**< relative stop time from pinfo */
59     nstime_t        start_abs_time;     /**< abs start time from pinfo */
60     guint16         vlan_id;
61     gboolean        tag_vlan_error;
62     gboolean        tag_diffserv_error;
63 
64     tap_rtp_stat_t  rtp_stats;  /**< here goes the RTP statistics info */
65     gboolean        problem;    /**< if the streams had wrong sequence numbers or wrong timestamps */
66     const gchar    *ed137_info; /** pointer to static text, no freeing is required */
67 } rtpstream_info_t;
68 
69 /** tapping modes */
70 typedef enum
71 {
72     TAP_ANALYSE,
73     TAP_SAVE,
74     TAP_MARK
75 } tap_mode_t;
76 
77 typedef struct _rtpstream_tapinfo rtpstream_tapinfo_t;
78 
79 typedef void (*rtpstream_tap_reset_cb)(rtpstream_tapinfo_t *tapinfo);
80 typedef void (*rtpstream_tap_draw_cb)(rtpstream_tapinfo_t *tapinfo);
81 typedef void (*tap_mark_packet_cb)(rtpstream_tapinfo_t *tapinfo, frame_data *fd);
82 typedef void (*rtpstream_tap_error_cb)(GString *error_string);
83 
84 /* structure that holds the information about all detected streams */
85 /** struct holding all information of the tap */
86 struct _rtpstream_tapinfo {
87     rtpstream_tap_reset_cb tap_reset;       /**< tap reset callback */
88     rtpstream_tap_draw_cb tap_draw;         /**< tap draw callback */
89     tap_mark_packet_cb tap_mark_packet;     /**< packet marking callback */
90     void              *tap_data;            /**< data for tap callbacks */
91     int                nstreams; /**< number of streams in the list */
92     GList             *strinfo_list; /**< list of rtpstream_info_t* */
93     GHashTable        *strinfo_hash; /**< multihash of rtpstream_info_t **/
94                                      /*   multihash means that there can be */
95                                      /*   more values related to one hash key */
96     int                npackets; /**< total number of rtp packets of all streams */
97     /* used while tapping. user shouldn't modify these */
98     tap_mode_t         mode;
99     rtpstream_info_t  *filter_stream_fwd; /**< used as filter in some tap modes */
100     rtpstream_info_t  *filter_stream_rev; /**< used as filter in some tap modes */
101     FILE              *save_file;
102     gboolean           is_registered; /**< if the tap listener is currently registered or not */
103     gboolean           apply_display_filter; /**< if apply display filter during analyse */
104 };
105 
106 #if 0
107 #define RTP_STREAM_DEBUG(...) { \
108     char *RTP_STREAM_DEBUG_MSG = g_strdup_printf(__VA_ARGS__); \
109     ws_warning("rtp_stream: %s:%d %s", G_STRFUNC, __LINE__, RTP_STREAM_DEBUG_MSG); \
110     g_free(RTP_STREAM_DEBUG_MSG); \
111 }
112 #else
113 #define RTP_STREAM_DEBUG(...)
114 #endif
115 
116 /****************************************************************************/
117 /* INTERFACE */
118 
119 void show_tap_registration_error(GString *error_string);
120 
121 /**
122 * Scans all packets for RTP streams and updates the RTP streams list.
123 * (redissects all packets)
124 */
125 void rtpstream_scan(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, const char *fstring);
126 
127 /**
128 * Saves an RTP stream as raw data stream with timestamp information for later RTP playback.
129 * (redissects all packets)
130 */
131 gboolean rtpstream_save(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, rtpstream_info_t* stream, const gchar *filename);
132 
133 /**
134 * Marks all packets belonging to either of stream_fwd or stream_rev.
135 * (both can be NULL)
136 * (redissects all packets)
137 */
138 void rtpstream_mark(rtpstream_tapinfo_t *tapinfo, capture_file *cap_file, rtpstream_info_t* stream_fwd, rtpstream_info_t* stream_rev);
139 
140 /* Constant based on fix for bug 4119/5902: don't insert too many silence
141  * frames.
142  */
143 #define MAX_SILENCE_FRAMES 14400000
144 
145 #ifdef __cplusplus
146 }
147 #endif /* __cplusplus */
148 
149 #endif /* __RTP_STREAM_H__ */
150