rtp_decoder.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef RTP_DECODER_H
  47. #define RTP_DECODER_H
  48. #include "srtp_priv.h"
  49. #include "rtp.h"
  50. #define DEFAULT_RTP_OFFSET 42
  51. typedef enum {
  52. mode_rtp = 0,
  53. mode_rtcp,
  54. mode_rtcp_mux,
  55. } rtp_decoder_mode_t;
  56. typedef struct rtp_decoder_ctx_t {
  57. srtp_policy_t policy;
  58. srtp_ctx_t *srtp_ctx;
  59. rtp_decoder_mode_t mode;
  60. int rtp_offset;
  61. struct timeval start_tv;
  62. int frame_nr;
  63. int error_cnt;
  64. int rtp_cnt;
  65. int rtcp_cnt;
  66. } rtp_decoder_ctx_t;
  67. typedef struct rtp_decoder_ctx_t *rtp_decoder_t;
  68. /*
  69. * prints the output of a random buffer in hexadecimal
  70. */
  71. void hexdump(const void *ptr, size_t size);
  72. /*
  73. * the function usage() prints an error message describing how this
  74. * program should be called, then calls exit()
  75. */
  76. void usage(char *prog_name);
  77. /*
  78. * transforms base64 key into octet
  79. */
  80. char *decode_sdes(char *in, char *out);
  81. /*
  82. * pcap handling
  83. */
  84. void rtp_decoder_handle_pkt(u_char *arg,
  85. const struct pcap_pkthdr *hdr,
  86. const u_char *bytes);
  87. rtp_decoder_t rtp_decoder_alloc(void);
  88. void rtp_decoder_dealloc(rtp_decoder_t rtp_ctx);
  89. int rtp_decoder_init(rtp_decoder_t dcdr,
  90. srtp_policy_t policy,
  91. rtp_decoder_mode_t mode,
  92. int rtp_packet_offset);
  93. int rtp_decoder_deinit(rtp_decoder_t decoder);
  94. void rtp_decoder_srtp_log_handler(srtp_log_level_t level,
  95. const char *msg,
  96. void *data);
  97. void rtp_decoder_srtp_log_handler(srtp_log_level_t level,
  98. const char *msg,
  99. void *data);
  100. #endif /* RTP_DECODER_H */