Amazon Kinesis Webrtc C SDK
Loading...
Searching...
No Matches
Sctp.h
Go to the documentation of this file.
1//
2// Sctp
3//
4
5#ifndef __KINESIS_VIDEO_WEBRTC_CLIENT_SCTP_SCTP__
6#define __KINESIS_VIDEO_WEBRTC_CLIENT_SCTP_SCTP__
7
8#pragma once
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14// 1200 - 12 (SCTP header Size)
15#define SCTP_MTU 1188
16#define SCTP_MAX_STREAMS 300 // outbound and inbound streams negotiated per association
17#define SCTP_ASSOCIATION_DEFAULT_PORT 5000
18#define SCTP_DCEP_HEADER_LENGTH 12
19#define SCTP_DCEP_LABEL_LEN_OFFSET 8
20#define SCTP_DCEP_LABEL_OFFSET 12
21#define SCTP_MAX_ALLOWABLE_PACKET_LENGTH (SCTP_DCEP_HEADER_LENGTH + MAX_DATA_CHANNEL_NAME_LEN + MAX_DATA_CHANNEL_PROTOCOL_LEN + 2)
22
23#define SCTP_SESSION_ACTIVE 0
24#define SCTP_SESSION_SHUTDOWN_INITIATED 1
25#define SCTP_SESSION_SHUTDOWN_COMPLETED 2
26
27#define DEFAULT_SCTP_SHUTDOWN_TIMEOUT 2 * HUNDREDS_OF_NANOS_IN_A_SECOND
28
29#define DEFAULT_USRSCTP_TEARDOWN_POLLING_INTERVAL (10 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)
30
31#define SCTP_TIMER_INTERVAL (100 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)
32#define SCTP_TIMER_START_DELAY (100 * HUNDREDS_OF_NANOS_IN_A_MILLISECOND)
33
34#define SCTP_CONTEXT_REFERENCE_WAIT_TIMEOUT (5 * HUNDREDS_OF_NANOS_IN_A_SECOND)
35
36// Values taken from defaults suggested by RFC 9260 spec: https://www.ietf.org/rfc/rfc9260.pdf
37
38// Max retransmits along a given single path. Typical default is 5
39#define SCTP_MAX_PATH_RETRANSMITS 5
40// Max retransmits across all paths for an endpoint association. Typical default is double max path retransmits
41#define SCTP_MAX_ASSOCIATION_RETRANSMITS 10
42// Retransmission timeout. Typical default is 60 seconds
43#define SCTP_RTO_MAX 60000
44
46
47enum {
50};
51
58
59// Callback that is fired when SCTP Association wishes to send packet
60typedef VOID (*SctpSessionOutboundPacketFunc)(UINT64, PBYTE, UINT32);
61
62// Callback that is fired when SCTP has a new DataChannel
63// Argument is ChannelID and ChannelName + Len. A failure means the channel was not taken: no DATA_CHANNEL_ACK is sent
64typedef STATUS (*SctpSessionDataChannelOpenFunc)(UINT64, UINT32, PBYTE, UINT32, PRtcDataChannelInit);
65
66// Callback that is fired when SCTP has a DataChannel Message.
67// Argument is ChannelID and Message + Len
68typedef VOID (*SctpSessionDataChannelMessageFunc)(UINT64, UINT32, BOOL, PBYTE, UINT32);
69
70// Callback that is fired when SCTP receives a DATA_CHANNEL_ACK. Argument is ChannelID
71typedef VOID (*SctpSessionDataChannelAckFunc)(UINT64, UINT32);
72
74typedef struct SctpContext {
75 // last time the periodic usrsctp timers were called
77 volatile ATOMIC_BOOL isSctpInitialized;
81
89
100
101STATUS initSctpSession();
102VOID deinitSctpSession();
103STATUS createSctpSession(PSctpSessionCallbacks, TIMER_QUEUE_HANDLE, PSctpSession*);
105STATUS putSctpPacket(PSctpSession, PBYTE, UINT32);
106// The last BOOL sends ordered whatever the channel's setting: an in-band channel until its DATA_CHANNEL_ACK, RFC 8832 section 6
107STATUS sctpSessionWriteMessage(PSctpSession, UINT32, BOOL, PBYTE, UINT32, PRtcDataChannelInit, BOOL);
108VOID sctpSessionSetSendInfo(struct sctp_sendv_spa*, UINT32, BOOL, PRtcDataChannelInit, BOOL);
110STATUS sctpSessionWriteDcep(PSctpSession, UINT32, PCHAR, UINT32, PRtcDataChannelInit);
111STATUS handleDcepPacket(PSctpSession, UINT32, PBYTE, SIZE_T);
112
113// Callbacks used by usrsctp
114INT32 onSctpOutboundPacket(PVOID, PVOID, ULONG, UINT8, UINT8);
115INT32 onSctpInboundPacket(struct socket*, union sctp_sockstore, PVOID, ULONG, struct sctp_rcvinfo, INT32, PVOID);
116// Callback to drive periodic SCTP timers
117STATUS sctpTimerCallback(UINT32, UINT64, UINT64);
118
119#ifdef __cplusplus
120}
121#endif
122#endif //__KINESIS_VIDEO_WEBRTC_CLIENT_SCTP_SCTP__
STATUS sctpTimerCallback(UINT32, UINT64, UINT64)
Definition Sctp.c:429
STATUS freeSctpSession(PSctpSession *)
Definition Sctp.c:239
VOID(* SctpSessionDataChannelMessageFunc)(UINT64, UINT32, BOOL, PBYTE, UINT32)
Definition Sctp.h:68
STATUS sctpSessionWriteDcep(PSctpSession, UINT32, PCHAR, UINT32, PRtcDataChannelInit)
Definition Sctp.c:345
STATUS createSctpSession(PSctpSessionCallbacks, TIMER_QUEUE_HANDLE, PSctpSession *)
Definition Sctp.c:173
@ DCEP_DATA_CHANNEL_OPEN
Definition Sctp.h:48
@ DCEP_DATA_CHANNEL_ACK
Definition Sctp.h:49
VOID(* SctpSessionOutboundPacketFunc)(UINT64, PBYTE, UINT32)
Definition Sctp.h:60
@ SCTP_PPID_STRING
Definition Sctp.h:45
@ SCTP_PPID_BINARY
Definition Sctp.h:45
@ SCTP_PPID_DCEP
Definition Sctp.h:45
@ SCTP_PPID_STRING_EMPTY
Definition Sctp.h:45
@ SCTP_PPID_BINARY_EMPTY
Definition Sctp.h:45
struct SctpContext * PSctpContext
#define SCTP_MAX_ALLOWABLE_PACKET_LENGTH
Definition Sctp.h:21
INT32 onSctpInboundPacket(struct socket *, union sctp_sockstore, PVOID, ULONG, struct sctp_rcvinfo, INT32, PVOID)
Definition Sctp.c:537
VOID deinitSctpSession()
Definition Sctp.c:163
struct SctpSession * PSctpSession
VOID dcepParseChannelParameters(PBYTE, PRtcDataChannelInit)
Definition Sctp.c:459
INT32 onSctpOutboundPacket(PVOID, PVOID, ULONG, UINT8, UINT8)
Definition Sctp.c:398
STATUS putSctpPacket(PSctpSession, PBYTE, UINT32)
Definition Sctp.c:418
STATUS(* SctpSessionDataChannelOpenFunc)(UINT64, UINT32, PBYTE, UINT32, PRtcDataChannelInit)
Definition Sctp.h:64
DATA_CHANNEL_TYPE
Definition Sctp.h:52
@ DCEP_DATA_CHANNEL_TIMED
Definition Sctp.h:56
@ DCEP_DATA_CHANNEL_RELIABLE_UNORDERED
Definition Sctp.h:54
@ DCEP_DATA_CHANNEL_RELIABLE_ORDERED
Definition Sctp.h:53
@ DCEP_DATA_CHANNEL_REXMIT
Definition Sctp.h:55
STATUS handleDcepPacket(PSctpSession, UINT32, PBYTE, SIZE_T)
Definition Sctp.c:477
STATUS initSctpSession()
Definition Sctp.c:144
VOID(* SctpSessionDataChannelAckFunc)(UINT64, UINT32)
Definition Sctp.h:71
VOID sctpSessionSetSendInfo(struct sctp_sendv_spa *, UINT32, BOOL, PRtcDataChannelInit, BOOL)
Definition Sctp.c:284
struct SctpSessionCallbacks * PSctpSessionCallbacks
STATUS sctpSessionWriteMessage(PSctpSession, UINT32, BOOL, PBYTE, UINT32, PRtcDataChannelInit, BOOL)
Definition Sctp.c:310
struct RtcDataChannelInit * PRtcDataChannelInit
Singleton context for SCTP global state.
Definition Sctp.h:74
MUTEX sctpContextLock
Definition Sctp.h:79
SIZE_T contextRefCnt
Definition Sctp.h:78
UINT64 lastTickTime
Definition Sctp.h:76
volatile ATOMIC_BOOL isSctpInitialized
Definition Sctp.h:77
Definition Sctp.h:82
SctpSessionDataChannelAckFunc dataChannelAckFunc
Definition Sctp.h:87
SctpSessionDataChannelOpenFunc dataChannelOpenFunc
Definition Sctp.h:85
SctpSessionOutboundPacketFunc outboundPacketFunc
Definition Sctp.h:84
UINT64 customData
Definition Sctp.h:83
SctpSessionDataChannelMessageFunc dataChannelMessageFunc
Definition Sctp.h:86
Definition Sctp.h:90
UINT32 packetSize
Definition Sctp.h:95
struct socket * socket
Definition Sctp.h:92
SctpSessionCallbacks sctpSessionCallbacks
Definition Sctp.h:96
struct sctp_sendv_spa spa
Definition Sctp.h:93
UINT32 timerTaskId
Definition Sctp.h:98
TIMER_QUEUE_HANDLE timerQueueHandle
Definition Sctp.h:97
volatile SIZE_T shutdownStatus
Definition Sctp.h:91
BYTE packet[(12+MAX_DATA_CHANNEL_NAME_LEN+MAX_DATA_CHANNEL_PROTOCOL_LEN+2)]
Definition Sctp.h:94