Fork me on GitHub
sctp.h
Go to the documentation of this file.
1 
19 #ifndef _JANUS_SCTP_H
20 #define _JANUS_SCTP_H
21 
22 #ifdef HAVE_SCTP
23 
24 #define INET 1
25 #define INET6 1
26 
27 /* Uncomment the line below to enable SCTP debugging to files */
28 //~ #define DEBUG_SCTP
29 
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <sys/select.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
35 #include <pthread.h>
36 #include <unistd.h>
37 #include <stdint.h>
38 #include <stdarg.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <errno.h>
43 #include <usrsctp.h>
44 #include <glib.h>
45 
46 #include "mutex.h"
47 #include "refcount.h"
48 
49 
52 int janus_sctp_init(void);
53 
55 void janus_sctp_deinit(void);
56 
57 
58 #define BUFFER_SIZE (1<<16)
59 #define NUMBER_OF_CHANNELS (100)
60 #define NUMBER_OF_STREAMS (16)
61 
62 #define DATA_CHANNEL_PPID_CONTROL 50
63 #define DATA_CHANNEL_PPID_DOMSTRING 51
64 #define DATA_CHANNEL_PPID_BINARY_PARTIAL 52
65 #define DATA_CHANNEL_PPID_BINARY 53
66 #define DATA_CHANNEL_PPID_DOMSTRING_PARTIAL 54
67 
68 #define DATA_CHANNEL_CLOSED 0
69 #define DATA_CHANNEL_CONNECTING 1
70 #define DATA_CHANNEL_OPEN 2
71 #define DATA_CHANNEL_CLOSING 3
72 
73 #define DATA_CHANNEL_FLAGS_SEND_REQ 0x00000001
74 #define DATA_CHANNEL_FLAGS_SEND_RSP 0x00000002
75 #define DATA_CHANNEL_FLAGS_SEND_ACK 0x00000004
76 
77 struct janus_dtls_srtp;
78 struct janus_ice_handle;
79 
80 typedef struct janus_sctp_channel {
82  uint32_t id;
84  uint32_t pr_value;
86  uint16_t pr_policy;
88  uint16_t stream;
90  uint8_t unordered;
92  uint8_t state;
94  uint32_t flags;
95 } janus_sctp_channel;
96 
97 typedef struct janus_sctp_association {
99  struct janus_dtls_srtp *dtls;
101  struct janus_ice_handle *handle;
103  uint64_t handle_id;
105  struct janus_sctp_channel channels[NUMBER_OF_CHANNELS];
107  struct janus_sctp_channel *stream_channel[NUMBER_OF_STREAMS];
109  uint16_t stream_buffer[NUMBER_OF_STREAMS];
111  uint32_t stream_buffer_counter;
113  struct socket *sock;
115  uint16_t local_port;
117  uint16_t remote_port;
119  char *buffer;
121  size_t buflen;
123  size_t offset;
124 #ifdef DEBUG_SCTP
125  FILE *debug_dump;
126 #endif
127 
128  janus_mutex mutex;
130  volatile gint destroyed;
132  janus_refcount ref;
133 } janus_sctp_association;
134 
135 
136 #define DATA_CHANNEL_OPEN_REQUEST 3 /* FIXME was 0, but should be 3 as per http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-05 */
137 #define DATA_CHANNEL_OPEN_RESPONSE 1
138 #define DATA_CHANNEL_ACK 2
139 
140 #define DATA_CHANNEL_RELIABLE 0x00
141 #define DATA_CHANNEL_RELIABLE_UNORDERED 0x80
142 #define DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT 0x01
143 #define DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT_UNORDERED 0x81
144 #define DATA_CHANNEL_PARTIAL_RELIABLE_TIMED 0x02
145 #define DATA_CHANNEL_PARTIAL_RELIABLE_TIMED_UNORDERED 0x82
146 
147 /* http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-05 */
148 typedef struct janus_datachannel_open_request {
150  uint8_t msg_type;
152  uint8_t channel_type;
154  uint16_t priority;
156  uint32_t reliability_params;
158  uint16_t label_length;
160  uint16_t protocol_length;
162  char label[0];
163  /* We ignore the Protocol field */
164 } janus_datachannel_open_request;
165 
166 typedef struct janus_datachannel_open_response {
168  uint8_t msg_type;
170  uint8_t error;
172  uint16_t flags;
174  uint16_t reverse_stream;
175 } janus_datachannel_open_response;
176 
177 typedef struct janus_datachannel_ack {
179  uint8_t msg_type;
180 } janus_datachannel_ack;
181 
182 
183 
189 janus_sctp_association *janus_sctp_association_create(struct janus_dtls_srtp *dtls, struct janus_ice_handle *handle, uint16_t udp_port);
190 
193 void janus_sctp_association_destroy(janus_sctp_association *sctp);
194 
199 void janus_sctp_data_from_dtls(janus_sctp_association *sctp, char *buf, int len);
200 
205 void janus_sctp_send_data(janus_sctp_association *sctp, char *buf, int len);
206 
207 #endif
208 
209 #endif
Reference counter mechanism.
GMutex janus_mutex
Janus mutex implementation.
Definition: mutex.h:61
ogg_stream_state * stream
Definition: pp-opus.c:31
Definition: refcount.h:78
Janus ICE handle.
Definition: ice.h:249
Semaphors, Mutexes and Conditions.
Janus DTLS-SRTP handle.
Definition: dtls.h:56
guint64 handle_id
Handle identifier, guaranteed to be non-zero.
Definition: ice.h:253