Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
packet-rtp.h
1 /* packet-rtp.h
2  *
3  * Routines for RTP dissection
4  * RTP = Real time Transport Protocol
5  *
6  * Copyright 2000, Philips Electronics N.V.
7  * Written by Andreas Sikkema <andreas.sikkema@philips.com>
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * SPDX-License-Identifier: GPL-2.0-or-later
14  */
15 
16 #include "epan/packet.h"
17 #include "ws_symbol_export.h"
18 
19 #include "packet-btavdtp.h"
20 
21 
22 #define RTP_MEDIA_AUDIO 1
23 #define RTP_MEDIA_VIDEO 2
24 #define RTP_MEDIA_OTHER 4
25 
26 struct _rtp_info {
27  unsigned int info_version;
28  gboolean info_padding_set;
29  gboolean info_marker_set;
30  guint32 info_media_types;
31  unsigned int info_payload_type;
32  unsigned int info_padding_count;
33  guint16 info_seq_num;
34  guint32 info_timestamp;
35  guint32 info_sync_src;
36  guint info_data_len; /* length of raw rtp data as reported */
37  gboolean info_all_data_present; /* FALSE if data is cut off */
38  guint info_payload_offset; /* start of payload relative to info_data */
39  guint info_payload_len; /* length of payload (incl padding) */
40  gboolean info_is_srtp;
41  guint32 info_setup_frame_num; /* the frame num of the packet that set this RTP connection */
42  const guint8* info_data; /* pointer to raw rtp data */
43  const gchar *info_payload_type_str;
44  gint info_payload_rate;
45  gboolean info_is_ed137;
46  const gchar *info_ed137_info;
47  /*
48  * info_data: pointer to raw rtp data = header + payload incl. padding.
49  * That should be safe because the "epan_dissect_t" constructed for the packet
50  * has not yet been freed when the taps are called.
51  * (destroying the "epan_dissect_t" will end up freeing all the tvbuffs
52  * and hence invalidating pointers to their data).
53  * See "add_packet_to_packet_list()" for details.
54  */
55 };
56 
57 /* definitions for SRTP dissection */
58 
59 /* Encryption algorithms */
60 #define SRTP_ENC_ALG_NOT_SET 0 /* Data not available/empty record */
61 #define SRTP_ENC_ALG_NULL 1 /* non-encrypted SRTP payload - may still be authenticated */
62 #define SRTP_ENC_ALG_AES_CM 2 /* SRTP default algorithm */
63 #define SRTP_ENC_ALG_AES_F8 3
64 
65 /* Authentication algorithms */
66 #define SRTP_AUTH_ALG_NONE 0 /* no auth tag in SRTP/RTP payload */
67 #define SRTP_AUTH_ALG_HMAC_SHA1 1 /* SRTP default algorithm */
68 
69 
70 #if 0 /* these are only needed once the dissector include the crypto functions to decrypt and/or authenticate */
71 struct srtp_key_info
72 {
73  guint8 *master_key; /* pointer to an wmem_file_scope'ed master key */
74  guint8 *master_salt; /* pointer to an wmem_file_scope'ed salt for this master key - NULL if no salt */
75  guint8 key_generation_rate; /* encoded as the power of 2, 0..24, or 255 (=zero rate) */
76  /* Either the MKI value is used (in which case from=to=0), or the <from,to> values are used (and MKI=0) */
77  guint32 from_roc; /* 32 MSBs of a 48 bit value - frame from which this key is valid (roll-over counter part) */
78  guint16 from_seq; /* 16 LSBs of a 48 bit value - frame from which this key is valid (sequence number part) */
79  guint32 to_roc; /* 32 MSBs of a 48 bit value - frame to which this key is valid (roll-over counter part) */
80  guint16 to_seq; /* 16 LSBs of a 48 bit value - frame to which this key is valid (sequence number part) */
81  guint32 mki; /* the MKI value associated with this key */
82 };
83 #endif
84 
85 struct srtp_info
86 {
87  guint encryption_algorithm; /* at present only NULL vs non-NULL matter */
88  guint auth_algorithm; /* at present only NULL vs non-NULL matter */
89  guint mki_len; /* number of octets used for the MKI in the RTP payload */
90  guint auth_tag_len; /* number of octets used for the Auth Tag in the RTP payload */
91 #if 0 /* these are only needed once the dissector include the crypto functions to decrypt and/or authenticate */
92  struct srtp_key_info **master_keys; /* an array of pointers to master keys and their info, the array and each key struct being wmem_file_scope'ed */
93  void *enc_alg_info, /* algorithm-dependent info struct - may be void for default alg with default params */
94  void *auth_alg_info /* algorithm-dependent info struct - void for default alg with default params */
95 #endif
96 };
97 
98 /* an opaque object holding the hash table - use accessor functions to create/destroy/find */
99 typedef struct _rtp_dyn_payload_t rtp_dyn_payload_t;
100 
101 /* RTP dynamic payload handling - use the following to create, insert, lookup, and free the
102  dynamic payload information. Internally, RTP creates the GHashTable with a wmem file scope
103  and increments the ref_count when it saves the info to conversations later. The calling
104  dissector (SDP, H.245, etc.) uses these functions as an interface. If the calling dissector
105  is done with the rtp_dyn_payload_t* for good, it should call rtp_dyn_payload_free() which
106  will decrement the ref_count and free's it if the ref_count is 0. In the worst case, it
107  will get free'd when the wmem file scope is over.
108 
109  This was changed because there were too many bugs with SDP's handling of memory ownership
110  of the GHashTable, with RTP freeing things SDP didn't think were free'ed. And also because
111  the GHashTables never got free'd in many cases by several dissectors.
112  */
113 
114 /* creates a new hashtable and sets ref_count to 1, returning the newly created object */
115 WS_DLL_PUBLIC
116 rtp_dyn_payload_t* rtp_dyn_payload_new(void);
117 
118 /* Creates a copy of the given dynamic payload information. */
119 rtp_dyn_payload_t* rtp_dyn_payload_dup(rtp_dyn_payload_t *rtp_dyn_payload);
120 
121 /* Inserts the given payload type key, for the encoding name and sample rate, into the hash table.
122  This makes copies of the encoding name, scoped to the life of the capture file or sooner if
123  rtp_dyn_payload_free is called. */
124 WS_DLL_PUBLIC
125 void rtp_dyn_payload_insert(rtp_dyn_payload_t *rtp_dyn_payload,
126  const guint pt,
127  const gchar* encoding_name,
128  const int sample_rate);
129 
130 /* Replaces the given payload type key in the hash table, with the encoding name and sample rate.
131  This makes copies of the encoding name, scoped to the life of the capture file or sooner if
132  rtp_dyn_payload_free is called. The replaced encoding name is free'd immediately. */
133 WS_DLL_PUBLIC
134 void rtp_dyn_payload_replace(rtp_dyn_payload_t *rtp_dyn_payload,
135  const guint pt,
136  const gchar* encoding_name,
137  const int sample_rate);
138 
139 /* removes the given payload type */
140 WS_DLL_PUBLIC
141 gboolean rtp_dyn_payload_remove(rtp_dyn_payload_t *rtp_dyn_payload, const guint pt);
142 
143 /* retrieves the encoding name for the given payload type; the string returned is only valid
144  until the entry is replaced, removed, or the hash table is destroyed, so duplicate it if
145  you need it long. */
146 WS_DLL_PUBLIC
147 const gchar* rtp_dyn_payload_get_name(rtp_dyn_payload_t *rtp_dyn_payload, const guint pt);
148 
149 /* retrieves the encoding name and sample rate for the given payload type, returning TRUE if
150  successful, else FALSE. The encoding string pointed to is only valid until the entry is
151  replaced, removed, or the hash table is destroyed, so duplicate it if you need it long. */
152 WS_DLL_PUBLIC
153 gboolean rtp_dyn_payload_get_full(rtp_dyn_payload_t *rtp_dyn_payload, const guint pt,
154  const gchar **encoding_name, int *sample_rate);
155 
156 /* Free's and destroys the dyn_payload hash table; internally this decrements the ref_count
157  and only free's it if the ref_count == 0. */
158 WS_DLL_PUBLIC
159 void rtp_dyn_payload_free(rtp_dyn_payload_t *rtp_dyn_payload);
160 
161 
162 #ifdef DEBUG_CONVERSATION
163 /* used for printing out debugging info, if DEBUG_CONVERSATION is defined */
164 void rtp_dump_dyn_payload(rtp_dyn_payload_t *rtp_dyn_payload);
165 #endif
166 
167 /* Info to save in RTP conversation / packet-info */
168 #define MAX_RTP_SETUP_METHOD_SIZE 7
170 {
171  gchar method[MAX_RTP_SETUP_METHOD_SIZE + 1];
172  guint32 frame_number; /* the frame where this conversation is started */
173  guint32 media_types;
174  rtp_dyn_payload_t *rtp_dyn_payload; /* the dynamic RTP payload info - see comments above */
175 
176  guint32 extended_seqno; /* the sequence number, extended to a 32-bit
177  * int to guarantee it increasing monotonically
178  */
179 
180  struct _rtp_private_conv_info *rtp_conv_info; /* conversation info private
181  * to the rtp dissector
182  */
183  struct srtp_info *srtp_info; /* SRTP context */
184  bta2dp_codec_info_t *bta2dp_info;
185  btvdp_codec_info_t *btvdp_info;
186 };
187 
188 /* Add an RTP conversation with the given details */
189 WS_DLL_PUBLIC
190 void rtp_add_address(packet_info *pinfo,
191  const port_type ptype,
192  address *addr, int port,
193  int other_port,
194  const gchar *setup_method,
195  guint32 setup_frame_number,
196  guint32 media_types,
197  rtp_dyn_payload_t *rtp_dyn_payload);
198 
199 /* Add an SRTP conversation with the given details */
200 WS_DLL_PUBLIC
201 void srtp_add_address(packet_info *pinfo,
202  const port_type ptype,
203  address *addr, int port,
204  int other_port,
205  const gchar *setup_method,
206  guint32 setup_frame_number,
207  guint32 media_types,
208  rtp_dyn_payload_t *rtp_dyn_payload,
209  struct srtp_info *srtp_info);
210 
211 /* Add an Bluetooth conversation with the given details */
212 void
213 bluetooth_add_address(packet_info *pinfo, address *addr, guint32 stream_number,
214  const gchar *setup_method, guint32 setup_frame_number,
215  guint32 media_types, void *data);
Definition: packet-rtp.c:86
Definition: packet_info.h:44
Definition: packet-rtp.h:169
Definition: packet-btavdtp.h:35
Definition: packet-rtp.h:85
Definition: packet-rtp.c:98
Definition: packet-btavdtp.h:26
Definition: packet-rtp.h:26
Definition: address.h:47