1 /* 2 * Copyright (c) 2014, Ericsson AB. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 * list of conditions and the following disclaimer in the documentation and/or other 12 * materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 23 * OF SUCH DAMAGE. 24 */ 25 26 #ifndef gstdtlsconnection_h 27 #define gstdtlsconnection_h 28 29 #include <glib-object.h> 30 31 G_BEGIN_DECLS 32 33 #define GST_TYPE_DTLS_CONNECTION (gst_dtls_connection_get_type()) 34 #define GST_DTLS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_DTLS_CONNECTION, GstDtlsConnection)) 35 #define GST_DTLS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_DTLS_CONNECTION, GstDtlsConnectionClass)) 36 #define GST_IS_DTLS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_DTLS_CONNECTION)) 37 #define GST_IS_DTLS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_DTLS_CONNECTION)) 38 #define GST_DTLS_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_DTLS_CONNECTION, GstDtlsConnectionClass)) 39 40 typedef struct _GstDtlsConnection GstDtlsConnection; 41 typedef struct _GstDtlsConnectionClass GstDtlsConnectionClass; 42 typedef struct _GstDtlsConnectionPrivate GstDtlsConnectionPrivate; 43 44 /** 45 * GstDtlsSrtpCipher: 46 * @GST_DTLS_SRTP_CIPHER_AES_128_ICM: aes-128-icm 47 * 48 * SRTP Cipher selected by the DTLS handshake, should match the enums in gstsrtp 49 */ 50 typedef enum { 51 GST_DTLS_SRTP_CIPHER_AES_128_ICM = 1 52 } GstDtlsSrtpCipher; 53 54 /** 55 * GstDtlsSrtpAuth: 56 * @GST_DTLS_SRTP_AUTH_HMAC_SHA1_32: hmac-sha1-32 57 * @GST_DTLS_SRTP_AUTH_HMAC_SHA1_80: hmac-sha1-80 58 * 59 * SRTP Auth selected by the DTLS handshake, should match the enums in gstsrtp 60 */ 61 typedef enum { 62 GST_DTLS_SRTP_AUTH_HMAC_SHA1_32 = 1, 63 GST_DTLS_SRTP_AUTH_HMAC_SHA1_80 = 2 64 } GstDtlsSrtpAuth; 65 66 #define GST_DTLS_SRTP_MASTER_KEY_LENGTH 30 67 68 /* 69 * GstDtlsConnection: 70 * 71 * A class that handles a single DTLS connection. 72 * Any connection needs to be created with the agent property set. 73 * Once the DTLS handshake is completed, on-encoder-key and on-decoder-key will be signalled. 74 */ 75 struct _GstDtlsConnection { 76 GObject parent_instance; 77 78 GstDtlsConnectionPrivate *priv; 79 }; 80 81 struct _GstDtlsConnectionClass { 82 GObjectClass parent_class; 83 }; 84 85 GType gst_dtls_connection_get_type(void) G_GNUC_CONST; 86 87 void gst_dtls_connection_start(GstDtlsConnection *, gboolean is_client); 88 void gst_dtls_connection_check_timeout(GstDtlsConnection *); 89 90 /* 91 * Stops the connections, it is not required to call this function. 92 */ 93 void gst_dtls_connection_stop(GstDtlsConnection *); 94 95 /* 96 * Closes the connection, the function will block until the connection has been stopped. 97 * If stop is called some time before, close will return instantly. 98 */ 99 void gst_dtls_connection_close(GstDtlsConnection *); 100 101 /* 102 * Sets the closure that will be called whenever data needs to be sent. 103 * 104 * The closure will get called with the following arguments: 105 * void cb(GstDtlsConnection *, gpointer data, gint length, gpointer user_data) 106 */ 107 void gst_dtls_connection_set_send_callback(GstDtlsConnection *, GClosure *); 108 109 /* 110 * Processes data that has been recevied, the transformation is done in-place. 111 * Returns the length of the plaintext data that was decoded, if no data is available, 0<= will be returned. 112 */ 113 gint gst_dtls_connection_process(GstDtlsConnection *, gpointer ptr, gint len); 114 115 /* 116 * If the DTLS handshake is completed this function will encode the given data. 117 * Returns the length of the data sent, or 0 if the DTLS handshake is not completed. 118 */ 119 gint gst_dtls_connection_send(GstDtlsConnection *, gpointer ptr, gint len); 120 121 G_END_DECLS 122 123 #endif /* gstdtlsconnection_h */ 124