rtp_decoder.h (3560B)
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 size_t 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 * prints the output of a random buffer in hexadecimal 77 */ 78 void hexdump(const void *ptr, size_t size); 79 80 /* 81 * the function usage() prints an error message describing how this 82 * program should be called, then calls exit() 83 */ 84 void usage(char *prog_name); 85 86 /* 87 * transforms base64 key into octet 88 */ 89 char *decode_sdes(char *in, char *out); 90 91 /* 92 * pcap handling 93 */ 94 void rtp_decoder_handle_pkt(u_char *arg, 95 const struct pcap_pkthdr *hdr, 96 const u_char *bytes); 97 98 rtp_decoder_t rtp_decoder_alloc(void); 99 100 void rtp_decoder_dealloc(rtp_decoder_t rtp_ctx); 101 102 int rtp_decoder_init(rtp_decoder_t dcdr, 103 srtp_policy_t policy, 104 rtp_decoder_mode_t mode, 105 size_t rtp_packet_offset, 106 uint32_t roc); 107 108 int rtp_decoder_deinit(rtp_decoder_t decoder); 109 110 void rtp_decoder_srtp_log_handler(srtp_log_level_t level, 111 const char *msg, 112 void *data); 113 114 void rtp_decoder_srtp_log_handler(srtp_log_level_t level, 115 const char *msg, 116 void *data); 117 118 #endif /* RTP_DECODER_H */