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 <gst/gst.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 typedef enum 69 { 70 GST_DTLS_CONNECTION_STATE_NEW, 71 GST_DTLS_CONNECTION_STATE_CLOSED, 72 GST_DTLS_CONNECTION_STATE_FAILED, 73 GST_DTLS_CONNECTION_STATE_CONNECTING, 74 GST_DTLS_CONNECTION_STATE_CONNECTED, 75 } GstDtlsConnectionState; 76 77 GType gst_dtls_connection_state_get_type (void); 78 #define GST_DTLS_TYPE_CONNECTION_STATE (gst_dtls_connection_state_get_type ()) 79 80 /* 81 * GstDtlsConnection: 82 * 83 * A class that handles a single DTLS connection. 84 * Any connection needs to be created with the agent property set. 85 * Once the DTLS handshake is completed, on-encoder-key and on-decoder-key will be signalled. 86 */ 87 struct _GstDtlsConnection { 88 GObject parent_instance; 89 90 GstDtlsConnectionPrivate *priv; 91 }; 92 93 struct _GstDtlsConnectionClass { 94 GObjectClass parent_class; 95 }; 96 97 GType gst_dtls_connection_get_type(void) G_GNUC_CONST; 98 99 gboolean gst_dtls_connection_start(GstDtlsConnection *, gboolean is_client, GError **err); 100 void gst_dtls_connection_check_timeout(GstDtlsConnection *); 101 102 /* 103 * Stops the connections, it is not required to call this function. 104 */ 105 void gst_dtls_connection_stop(GstDtlsConnection *); 106 107 /* 108 * Closes the connection, the function will block until the connection has been stopped. 109 * If stop is called some time before, close will return instantly. 110 */ 111 void gst_dtls_connection_close(GstDtlsConnection *); 112 113 114 typedef gboolean (*GstDtlsConnectionSendCallback) (GstDtlsConnection * connection, gconstpointer data, gsize length, gpointer user_data); 115 116 /* 117 * Sets the callback that will be called whenever data needs to be sent. 118 */ 119 void gst_dtls_connection_set_send_callback(GstDtlsConnection *, GstDtlsConnectionSendCallback, gpointer, GDestroyNotify); 120 121 /* 122 * Sets the GstFlowReturn that be returned from gst_dtls_connection_send() if callback returns FALSE 123 */ 124 void gst_dtls_connection_set_flow_return(GstDtlsConnection *, GstFlowReturn); 125 126 /* 127 * Processes data that has been received, the transformation is done in-place. 128 * 129 * Returns: 130 * - GST_FLOW_EOS if the receive side of the DTLS connection was closed by 131 * the peer, i.e. close_notify was sent by the peer 132 * - GST_FLOW_ERROR + err if an error happened 133 * - GST_FLOW_OK + written >= 0 if processing was successful. ptr then 134 * contains the decoded bytes 135 */ 136 GstFlowReturn gst_dtls_connection_process(GstDtlsConnection *, gpointer ptr, gsize len, gsize *written, GError **err); 137 138 /* 139 * Will encode and send the given data. 140 * 141 * Sending with len == 0 will close the send side of the DTLS connection and 142 * no further data can be sent anymore in the future. This will also send the 143 * close_notify to the peer. 144 * 145 * Returns: 146 * - GST_FLOW_EOS if the send side of the DTLS connection was closed, i.e. 147 * we received an EOS before. 148 * - GST_FLOW_ERROR + err if an error happened 149 * - GST_FLOW_OK + written >= 0 if processing was successful 150 * - Any GstFlowReturn set with gst_dtls_connection_set_flow_return() 151 */ 152 GstFlowReturn gst_dtls_connection_send(GstDtlsConnection *, gconstpointer ptr, gsize len, gsize *written, GError **err); 153 154 G_END_DECLS 155 156 #endif /* gstdtlsconnection_h */ 157