1 /*
2  * rtp_decoder.h
3  *
4  * decoder structures and functions for SRTP pcap decoder
5  *
6  * Bernardo Torres <bernardo@torresautomacao.com.br>
7  *
8  * Some structure and code from https://github.com/gteissier/srtp-decrypt
9  *
10  */
11 /*
12  *
13  * Copyright (c) 2001-2017 Cisco Systems, Inc.
14  * All rights reserved.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  *
20  *   Redistributions of source code must retain the above copyright
21  *   notice, this list of conditions and the following disclaimer.
22  *
23  *   Redistributions in binary form must reproduce the above
24  *   copyright notice, this list of conditions and the following
25  *   disclaimer in the documentation and/or other materials provided
26  *   with the distribution.
27  *
28  *   Neither the name of the Cisco Systems, Inc. nor the names of its
29  *   contributors may be used to endorse or promote products derived
30  *   from this software without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
36  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
37  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
39  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
43  * OF THE POSSIBILITY OF SUCH DAMAGE.
44  *
45  */
46 
47 #ifndef RTP_DECODER_H
48 #define RTP_DECODER_H
49 
50 #include "srtp_priv.h"
51 #include "rtp.h"
52 
53 #define DEFAULT_RTP_OFFSET 42
54 
55 typedef enum {
56     mode_rtp = 0,
57     mode_rtcp,
58     mode_rtcp_mux,
59 } rtp_decoder_mode_t;
60 
61 typedef struct rtp_decoder_ctx_t {
62     srtp_policy_t policy;
63     srtp_ctx_t *srtp_ctx;
64     rtp_decoder_mode_t mode;
65     int rtp_offset;
66     struct timeval start_tv;
67     int frame_nr;
68     int error_cnt;
69     int rtp_cnt;
70     int rtcp_cnt;
71 } rtp_decoder_ctx_t;
72 
73 typedef struct rtp_decoder_ctx_t *rtp_decoder_t;
74 
75 /*
76  * error to string
77  */
78 void rtp_print_error(srtp_err_status_t status, char *message);
79 
80 /*
81  * prints the output of a random buffer in hexadecimal
82  */
83 void hexdump(const void *ptr, size_t size);
84 
85 /*
86  * the function usage() prints an error message describing how this
87  * program should be called, then calls exit()
88  */
89 void usage(char *prog_name);
90 
91 /*
92  * transforms base64 key into octet
93  */
94 char *decode_sdes(char *in, char *out);
95 
96 /*
97  * pcap handling
98  */
99 void rtp_decoder_handle_pkt(u_char *arg,
100                             const struct pcap_pkthdr *hdr,
101                             const u_char *bytes);
102 
103 rtp_decoder_t rtp_decoder_alloc(void);
104 
105 void rtp_decoder_dealloc(rtp_decoder_t rtp_ctx);
106 
107 int rtp_decoder_init(rtp_decoder_t dcdr,
108                      srtp_policy_t policy,
109                      rtp_decoder_mode_t mode);
110 
111 int rtp_decoder_deinit(rtp_decoder_t decoder);
112 
113 void rtp_decoder_srtp_log_handler(srtp_log_level_t level,
114                                   const char *msg,
115                                   void *data);
116 
117 void rtp_decoder_srtp_log_handler(srtp_log_level_t level,
118                                   const char *msg,
119                                   void *data);
120 
121 #endif /* RTP_DECODER_H */
122