Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * rtp.h |
| 3 | * |
| 4 | * rtp interface for srtp reference implementation |
| 5 | * |
| 6 | * David A. McGrew |
| 7 | * Cisco Systems, Inc. |
| 8 | * |
| 9 | * data types: |
| 10 | * |
| 11 | * rtp_msg_t an rtp message (the data that goes on the wire) |
| 12 | * rtp_sender_t sender side socket and rtp info |
| 13 | * rtp_receiver_t receiver side socket and rtp info |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * |
David McGrew | 7629bf2 | 2006-06-08 17:00:25 +0000 | [diff] [blame] | 19 | * Copyright (c) 2001-2006, Cisco Systems, Inc. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 20 | * All rights reserved. |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions |
| 24 | * are met: |
| 25 | * |
| 26 | * Redistributions of source code must retain the above copyright |
| 27 | * notice, this list of conditions and the following disclaimer. |
| 28 | * |
| 29 | * Redistributions in binary form must reproduce the above |
| 30 | * copyright notice, this list of conditions and the following |
| 31 | * disclaimer in the documentation and/or other materials provided |
| 32 | * with the distribution. |
| 33 | * |
| 34 | * Neither the name of the Cisco Systems, Inc. nor the names of its |
| 35 | * contributors may be used to endorse or promote products derived |
| 36 | * from this software without specific prior written permission. |
| 37 | * |
| 38 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 39 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 40 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 41 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 42 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 43 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 44 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 45 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 46 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 47 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 48 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 49 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 50 | * |
| 51 | */ |
| 52 | |
| 53 | |
| 54 | #ifndef RTP_H |
| 55 | #define RTP_H |
| 56 | |
Marcus Sundberg | 4254d0a | 2005-10-02 20:16:47 +0000 | [diff] [blame] | 57 | #ifdef HAVE_NETINET_IN_H |
| 58 | # include <netinet/in.h> |
| 59 | #elif defined HAVE_WINSOCK2_H |
| 60 | # include <winsock2.h> |
| 61 | #endif |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 62 | |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 63 | //#include "srtp_priv.h" |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 64 | #include "srtp.h" |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 65 | /* |
| 66 | * RTP_HEADER_LEN indicates the size of an RTP header |
| 67 | */ |
| 68 | #define RTP_HEADER_LEN 12 |
| 69 | |
| 70 | /* |
| 71 | * RTP_MAX_BUF_LEN defines the largest RTP packet in the rtp.c implementation |
| 72 | */ |
| 73 | #define RTP_MAX_BUF_LEN 16384 |
| 74 | |
| 75 | |
| 76 | typedef srtp_hdr_t rtp_hdr_t; |
| 77 | |
| 78 | typedef struct { |
| 79 | srtp_hdr_t header; |
| 80 | char body[RTP_MAX_BUF_LEN]; |
| 81 | } rtp_msg_t; |
| 82 | |
| 83 | typedef struct rtp_sender_ctx_t { |
| 84 | rtp_msg_t message; |
| 85 | int socket; |
| 86 | srtp_ctx_t *srtp_ctx; |
| 87 | struct sockaddr_in addr; /* reciever's address */ |
| 88 | } rtp_sender_ctx_t; |
| 89 | |
| 90 | typedef struct rtp_receiver_ctx_t { |
| 91 | rtp_msg_t message; |
| 92 | int socket; |
| 93 | srtp_ctx_t *srtp_ctx; |
| 94 | struct sockaddr_in addr; /* receiver's address */ |
| 95 | } rtp_receiver_ctx_t; |
| 96 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 97 | |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 98 | typedef struct rtp_sender_ctx_t *rtp_sender_t; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 99 | |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 100 | typedef struct rtp_receiver_ctx_t *rtp_receiver_t; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 101 | |
Jonathan Lennox | 986f6d0 | 2010-05-17 19:28:39 +0000 | [diff] [blame] | 102 | int |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 103 | rtp_sendto(rtp_sender_t sender, const void* msg, int len); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 104 | |
Jonathan Lennox | 986f6d0 | 2010-05-17 19:28:39 +0000 | [diff] [blame] | 105 | int |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 106 | rtp_recvfrom(rtp_receiver_t receiver, void *msg, int *len); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 107 | |
| 108 | int |
Jonathan Lennox | 75b3687 | 2010-05-21 00:30:21 +0000 | [diff] [blame] | 109 | rtp_receiver_init(rtp_receiver_t rcvr, int sock, |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 110 | struct sockaddr_in addr, unsigned int ssrc); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 111 | |
| 112 | int |
Jonathan Lennox | 75b3687 | 2010-05-21 00:30:21 +0000 | [diff] [blame] | 113 | rtp_sender_init(rtp_sender_t sender, int sock, |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 114 | struct sockaddr_in addr, unsigned int ssrc); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * srtp_sender_init(...) initializes an rtp_sender_t |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 118 | */ |
| 119 | |
| 120 | int |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 121 | srtp_sender_init(rtp_sender_t rtp_ctx, /* structure to be init'ed */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 122 | struct sockaddr_in name, /* socket name */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 123 | srtp_sec_serv_t security_services, /* sec. servs. to be used */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 124 | unsigned char *input_key /* master key/salt in hex */ |
| 125 | ); |
| 126 | |
| 127 | int |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 128 | srtp_receiver_init(rtp_receiver_t rtp_ctx, /* structure to be init'ed */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 129 | struct sockaddr_in name, /* socket name */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 130 | srtp_sec_serv_t security_services, /* sec. servs. to be used */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 131 | unsigned char *input_key /* master key/salt in hex */ |
| 132 | ); |
| 133 | |
| 134 | |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 135 | int |
| 136 | rtp_sender_init_srtp(rtp_sender_t sender, const srtp_policy_t *policy); |
| 137 | |
| 138 | int |
Jonathan Lennox | 8cae72f | 2010-05-17 19:19:10 +0000 | [diff] [blame] | 139 | rtp_sender_deinit_srtp(rtp_sender_t sender); |
| 140 | |
| 141 | int |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 142 | rtp_receiver_init_srtp(rtp_receiver_t sender, const srtp_policy_t *policy); |
| 143 | |
Jonathan Lennox | 8cae72f | 2010-05-17 19:19:10 +0000 | [diff] [blame] | 144 | int |
| 145 | rtp_receiver_deinit_srtp(rtp_receiver_t sender); |
| 146 | |
David McGrew | d083205 | 2006-07-13 19:04:53 +0000 | [diff] [blame] | 147 | |
| 148 | rtp_sender_t |
Jonathan Lennox | ed3ab2b | 2010-05-17 19:42:26 +0000 | [diff] [blame] | 149 | rtp_sender_alloc(void); |
David McGrew | d083205 | 2006-07-13 19:04:53 +0000 | [diff] [blame] | 150 | |
Jonathan Lennox | 8cae72f | 2010-05-17 19:19:10 +0000 | [diff] [blame] | 151 | void |
| 152 | rtp_sender_dealloc(rtp_sender_t rtp_ctx); |
| 153 | |
David McGrew | d083205 | 2006-07-13 19:04:53 +0000 | [diff] [blame] | 154 | rtp_receiver_t |
Jonathan Lennox | ed3ab2b | 2010-05-17 19:42:26 +0000 | [diff] [blame] | 155 | rtp_receiver_alloc(void); |
David McGrew | d083205 | 2006-07-13 19:04:53 +0000 | [diff] [blame] | 156 | |
Jonathan Lennox | 8cae72f | 2010-05-17 19:19:10 +0000 | [diff] [blame] | 157 | void |
| 158 | rtp_receiver_dealloc(rtp_receiver_t rtp_ctx); |
| 159 | |
David McGrew | d083205 | 2006-07-13 19:04:53 +0000 | [diff] [blame] | 160 | |
David McGrew | 1a2ab2c | 2006-07-12 22:48:44 +0000 | [diff] [blame] | 161 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 162 | #endif /* RTP_H */ |