Fork me on GitHub
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
48 
51 int janus_sctp_init(void);
52 
54 void janus_sctp_deinit(void);
55 
56 
57 #define BUFFER_SIZE (1<<16)
58 #define NUMBER_OF_CHANNELS (100)
59 #define NUMBER_OF_STREAMS (16)
60 
61 #define DATA_CHANNEL_PPID_CONTROL 50
62 #define DATA_CHANNEL_PPID_DOMSTRING 51
63 #define DATA_CHANNEL_PPID_BINARY_PARTIAL 52
64 #define DATA_CHANNEL_PPID_BINARY 53
65 #define DATA_CHANNEL_PPID_DOMSTRING_PARTIAL 54
66 
67 #define DATA_CHANNEL_CLOSED 0
68 #define DATA_CHANNEL_CONNECTING 1
69 #define DATA_CHANNEL_OPEN 2
70 #define DATA_CHANNEL_CLOSING 3
71 
72 #define DATA_CHANNEL_FLAGS_SEND_REQ 0x00000001
73 #define DATA_CHANNEL_FLAGS_SEND_RSP 0x00000002
74 #define DATA_CHANNEL_FLAGS_SEND_ACK 0x00000004
75 
76 typedef struct janus_sctp_channel {
78  uint32_t id;
80  uint32_t pr_value;
82  uint16_t pr_policy;
84  uint16_t stream;
86  uint8_t unordered;
88  uint8_t state;
90  uint32_t flags;
91 } janus_sctp_channel;
92 
93 typedef struct janus_sctp_association {
95  void *dtls;
97  uint64_t handle_id;
99  struct janus_sctp_channel channels[NUMBER_OF_CHANNELS];
101  struct janus_sctp_channel *stream_channel[NUMBER_OF_STREAMS];
103  uint16_t stream_buffer[NUMBER_OF_STREAMS];
105  uint32_t stream_buffer_counter;
107  struct socket *sock;
109  uint16_t local_port;
111  uint16_t remote_port;
113  GQueue *in_messages;
115  GQueue *out_messages;
117  GThread *thread;
118 #ifdef DEBUG_SCTP
119  FILE *debug_dump;
120 #endif
121 
122  janus_mutex mutex;
123 } janus_sctp_association;
124 
125 typedef struct janus_sctp_message {
126  char *buffer;
127  size_t length;
128 } janus_sctp_message;
129 
130 
131 #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 */
132 #define DATA_CHANNEL_OPEN_RESPONSE 1
133 #define DATA_CHANNEL_ACK 2
134 
135 #define DATA_CHANNEL_RELIABLE 0x00
136 #define DATA_CHANNEL_RELIABLE_UNORDERED 0x80
137 #define DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT 0x01
138 #define DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT_UNORDERED 0x81
139 #define DATA_CHANNEL_PARTIAL_RELIABLE_TIMED 0x02
140 #define DATA_CHANNEL_PARTIAL_RELIABLE_TIMED_UNORDERED 0x82
141 
142 /* http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-05 */
143 typedef struct janus_datachannel_open_request {
145  uint8_t msg_type;
147  uint8_t channel_type;
149  uint16_t priority;
151  uint32_t reliability_params;
153  uint16_t label_length;
155  uint16_t protocol_length;
157  char label[0];
158  /* We ignore the Protocol field */
159 } janus_datachannel_open_request;
160 
161 typedef struct janus_datachannel_open_response {
163  uint8_t msg_type;
165  uint8_t error;
167  uint16_t flags;
169  uint16_t reverse_stream;
170 } janus_datachannel_open_response;
171 
172 typedef struct janus_datachannel_ack {
174  uint8_t msg_type;
175 } janus_datachannel_ack;
176 
177 
178 
184 janus_sctp_association *janus_sctp_association_create(void *dtls, uint64_t handle_id, uint16_t udp_port);
185 
188 int janus_sctp_association_setup(janus_sctp_association *sctp);
189 
192 void janus_sctp_association_destroy(janus_sctp_association *sctp);
193 
198 void janus_sctp_data_from_dtls(janus_sctp_association *sctp, char *buf, int len);
199 
204 void janus_sctp_send_data(janus_sctp_association *sctp, char *buf, int len);
205 
206 #endif
207 
208 #endif