4 #ifndef __KINESIS_VIDEO_WEBRTC_CLIENT_STUN_PACKAGER__
5 #define __KINESIS_VIDEO_WEBRTC_CLIENT_STUN_PACKAGER__
21 #define STUN_HEADER_LEN (UINT16) 20
22 #define STUN_HEADER_TYPE_LEN (UINT16) 2
23 #define STUN_HEADER_DATA_LEN (UINT16) 2
24 #define STUN_HEADER_MAGIC_COOKIE (UINT32) 0x2112A442
25 #define STUN_HEADER_MAGIC_COOKIE_LE (UINT32) 0x42A41221
26 #define STUN_HEADER_MAGIC_COOKIE_LEN SIZEOF(STUN_HEADER_MAGIC_COOKIE)
27 #define STUN_HEADER_TRANSACTION_ID_LEN (UINT16) 12
35 #define STUN_ATTRIBUTE_HEADER_TYPE_LEN (UINT16) 2
36 #define STUN_ATTRIBUTE_HEADER_DATA_LEN (UINT16) 2
37 #define STUN_ATTRIBUTE_HEADER_LEN (UINT16)(STUN_ATTRIBUTE_HEADER_TYPE_LEN + STUN_ATTRIBUTE_HEADER_DATA_LEN)
39 #define STUN_ATTRIBUTE_ADDRESS_FAMILY_LEN (UINT16) 2
40 #define STUN_ATTRIBUTE_ADDRESS_PORT_LEN (UINT16) 2
41 #define STUN_ATTRIBUTE_ADDRESS_HEADER_LEN (UINT16)(STUN_ATTRIBUTE_ADDRESS_FAMILY_LEN + STUN_ATTRIBUTE_ADDRESS_PORT_LEN)
46 #define STUN_ATTRIBUTE_FINGERPRINT_LEN (UINT16) 4
51 #define STUN_ATTRIBUTE_PRIORITY_LEN (UINT16) 4
56 #define STUN_ATTRIBUTE_LIFETIME_LEN (UINT16) 4
58 #define STUN_ATTRIBUTE_CHANNEL_NUMBER_LEN (UINT16) 4
63 #define STUN_ATTRIBUTE_CHANGE_REQUEST_FLAG_LEN (UINT16) 4
68 #define STUN_ATTRIBUTE_ICE_CONTROL_LEN (UINT16) 8
73 #define STUN_ATTRIBUTE_REQUESTED_TRANSPORT_PROTOCOL_LEN (UINT16) 4
78 #define STUN_ATTRIBUTE_FLAG_LEN (UINT16) 0
83 #define STUN_TRANSACTION_ID_LEN (UINT16) 12
88 #define STUN_HMAC_VALUE_LEN KVS_SHA1_DIGEST_LENGTH
93 #define STUN_ATTRIBUTE_MAX_COUNT 20
98 #define STUN_PACKET_ALLOCATION_SIZE 2048
100 #define STUN_SEND_INDICATION_OVERHEAD_SIZE 36
101 #define STUN_SEND_INDICATION_APPLICATION_DATA_OFFSET 36
102 #define STUN_SEND_INDICATION_APPLICATION_DATA_LEN_OFFSET 34
103 #define STUN_SEND_INDICATION_XOR_PEER_ADDRESS_OFFSET 28
104 #define STUN_SEND_INDICATION_XOR_PEER_ADDRESS_PORT_OFFSET 26
110 #define STUN_FINGERPRINT_ATTRIBUTE_XOR_VALUE (UINT32) 0x5354554e
112 #define STUN_ERROR_CODE_PACKET_ERROR_CLASS_OFFSET 2
113 #define STUN_ERROR_CODE_PACKET_ERROR_CODE_OFFSET 3
114 #define STUN_ERROR_CODE_PACKET_ERROR_PHRASE_OFFSET 4
115 #define STUN_PACKET_TRANSACTION_ID_OFFSET 8
120 #define STUN_ATTRIBUTE_CHANGE_REQUEST_FLAG_CHANGE_IP 4
121 #define STUN_ATTRIBUTE_CHANGE_REQUEST_FLAG_CHANGE_PORT 2
127 #define GET_STUN_ERROR_CODE(pClass, pCode) ((UINT16) ((*(PUINT8) (pClass)) * 100 + *(PUINT8) (pCode)))
132 #define PACKAGE_STUN_ATTR_HEADER(pBuf, type, dataLen) \
133 putInt16((PINT16) (pBuf), (UINT16) (type)); \
134 putInt16((PINT16) ((pBuf) + STUN_ATTRIBUTE_HEADER_TYPE_LEN), (UINT16) (dataLen));
168 #define STUN_PACKET_IS_TYPE_ERROR(pPacketBuffer) \
169 ((getInt16(*(PINT16) pPacketBuffer) == STUN_PACKET_TYPE_BINDING_RESPONSE_ERROR) || \
170 (getInt16(*(PINT16) pPacketBuffer) == STUN_PACKET_TYPE_SHARED_SECRET_ERROR_RESPONSE) || \
171 (getInt16(*(PINT16) pPacketBuffer) == STUN_PACKET_TYPE_ALLOCATE_ERROR_RESPONSE) || \
172 (getInt16(*(PINT16) pPacketBuffer) == STUN_PACKET_TYPE_REFRESH_ERROR_RESPONSE) || \
173 (getInt16(*(PINT16) pPacketBuffer) == STUN_PACKET_TYPE_CREATE_PERMISSION_ERROR_RESPONSE) || \
174 (getInt16(*(PINT16) pPacketBuffer) == STUN_PACKET_TYPE_CHANNEL_BIND_ERROR_RESPONSE))
struct StunAttributeFingerprint * PStunAttributeFingerprint
STUN_ERROR_CODE
Definition: Stun.h:179
@ STUN_ERROR_STALE_NONCE
Definition: Stun.h:181
@ STUN_ERROR_UNAUTHORIZED
Definition: Stun.h:180
STATUS appendStunUsernameAttribute(PStunPacket, PCHAR)
Definition: Stun.c:1159
STATUS appendStunChannelNumberAttribute(PStunPacket, UINT16)
Definition: Stun.c:1650
STUN_ATTRIBUTE_TYPE
Definition: Stun.h:187
@ STUN_ATTRIBUTE_TYPE_ICE_CONTROLLING
Definition: Stun.h:204
@ STUN_ATTRIBUTE_TYPE_XOR_MAPPED_ADDRESS
Definition: Stun.h:199
@ STUN_ATTRIBUTE_TYPE_USE_CANDIDATE
Definition: Stun.h:201
@ STUN_ATTRIBUTE_TYPE_DONT_FRAGMENT
Definition: Stun.h:214
@ STUN_ATTRIBUTE_TYPE_EVEN_PORT
Definition: Stun.h:212
@ STUN_ATTRIBUTE_TYPE_ERROR_CODE
Definition: Stun.h:196
@ STUN_ATTRIBUTE_TYPE_NONCE
Definition: Stun.h:210
@ STUN_ATTRIBUTE_TYPE_PASSWORD
Definition: Stun.h:194
@ STUN_ATTRIBUTE_TYPE_RESPONSE_ADDRESS
Definition: Stun.h:189
@ STUN_ATTRIBUTE_TYPE_REFLECTED_FROM
Definition: Stun.h:198
@ STUN_ATTRIBUTE_TYPE_REALM
Definition: Stun.h:209
@ STUN_ATTRIBUTE_TYPE_CHANGED_ADDRESS
Definition: Stun.h:192
@ STUN_ATTRIBUTE_TYPE_UNKNOWN_ATTRIBUTES
Definition: Stun.h:197
@ STUN_ATTRIBUTE_TYPE_LIFETIME
Definition: Stun.h:206
@ STUN_ATTRIBUTE_TYPE_REQUESTED_TRANSPORT
Definition: Stun.h:213
@ STUN_ATTRIBUTE_TYPE_XOR_RELAYED_ADDRESS
Definition: Stun.h:211
@ STUN_ATTRIBUTE_TYPE_DATA
Definition: Stun.h:208
@ STUN_ATTRIBUTE_TYPE_CHANNEL_NUMBER
Definition: Stun.h:205
@ STUN_ATTRIBUTE_TYPE_XOR_PEER_ADDRESS
Definition: Stun.h:207
@ STUN_ATTRIBUTE_TYPE_USERNAME
Definition: Stun.h:193
@ STUN_ATTRIBUTE_TYPE_MAPPED_ADDRESS
Definition: Stun.h:188
@ STUN_ATTRIBUTE_TYPE_SOURCE_ADDRESS
Definition: Stun.h:191
@ STUN_ATTRIBUTE_TYPE_PRIORITY
Definition: Stun.h:200
@ STUN_ATTRIBUTE_TYPE_RESERVATION_TOKEN
Definition: Stun.h:215
@ STUN_ATTRIBUTE_TYPE_MESSAGE_INTEGRITY
Definition: Stun.h:195
@ STUN_ATTRIBUTE_TYPE_FINGERPRINT
Definition: Stun.h:202
@ STUN_ATTRIBUTE_TYPE_CHANGE_REQUEST
Definition: Stun.h:190
@ STUN_ATTRIBUTE_TYPE_ICE_CONTROLLED
Definition: Stun.h:203
struct StunAttributeRequestedTransport * PStunAttributeRequestedTransport
STATUS xorIpAddress(PKvsIpAddress, PBYTE)
Definition: Stun.c:1229
STATUS freeStunPacket(PStunPacket *)
Definition: Stun.c:1066
struct StunAttributeIceControl * PStunAttributeIceControl
STATUS appendStunIceControllAttribute(PStunPacket, STUN_ATTRIBUTE_TYPE, UINT64)
Definition: Stun.c:1574
struct StunAttributeAddress * PStunAttributeAddress
STATUS appendStunRealmAttribute(PStunPacket, PCHAR)
Definition: Stun.c:1416
struct StunAttributeData * PStunAttributeData
struct StunAttributeFlag * PStunAttributeFlag
struct StunAttributeNonce * PStunAttributeNonce
struct StunAttributeHeader * PStunAttributeHeader
struct StunAttributePriority * PStunAttributePriority
STATUS serializeStunPacket(PStunPacket, PBYTE, UINT32, BOOL, BOOL, PBYTE, PUINT32)
Definition: Stun.c:70
STATUS appendStunFlagAttribute(PStunPacket, STUN_ATTRIBUTE_TYPE)
Definition: Stun.c:1291
struct StunAttributeChangeRequest * PStunAttributeChangeRequest
STATUS appendStunNonceAttribute(PStunPacket, PBYTE, UINT16)
Definition: Stun.c:1459
#define STUN_HMAC_VALUE_LEN
Definition: Stun.h:88
STATUS updateStunNonceAttribute(PStunPacket, PBYTE, UINT16)
Definition: Stun.c:1501
STATUS getFirstAvailableStunAttribute(PStunPacket, PStunAttributeHeader *)
Definition: Stun.c:1742
struct StunPacket * PStunPacket
struct StunHeader * PStunHeader
UINT16 getPackagedStunAttributeSize(PStunAttributeHeader)
Definition: Stun.c:1683
STATUS appendStunErrorCodeAttribute(PStunPacket, PCHAR, UINT16)
Definition: Stun.c:1529
STATUS getStunAttribute(PStunPacket, STUN_ATTRIBUTE_TYPE, PStunAttributeHeader *)
Definition: Stun.c:1204
struct StunAttributeMessageIntegrity * PStunAttributeMessageIntegrity
STATUS appendStunAddressAttribute(PStunPacket, STUN_ATTRIBUTE_TYPE, PKvsIpAddress)
Definition: Stun.c:1126
STATUS appendStunChangeRequestAttribute(PStunPacket, UINT32)
Definition: Stun.c:1351
STATUS appendStunPriorityAttribute(PStunPacket, UINT32)
Definition: Stun.c:1259
struct StunAttributeRealm * PStunAttributeRealm
STUN_PACKET_TYPE
Definition: Stun.h:139
@ STUN_PACKET_TYPE_REFRESH_SUCCESS_RESPONSE
Definition: Stun.h:154
@ STUN_PACKET_TYPE_ALLOCATE_ERROR_RESPONSE
Definition: Stun.h:159
@ STUN_PACKET_TYPE_BINDING_INDICATION
Definition: Stun.h:148
@ STUN_PACKET_TYPE_SEND_INDICATION
Definition: Stun.h:149
@ STUN_PACKET_TYPE_BINDING_RESPONSE_ERROR
Definition: Stun.h:157
@ STUN_PACKET_TYPE_CREATE_PERMISSION_ERROR_RESPONSE
Definition: Stun.h:161
@ STUN_PACKET_TYPE_ALLOCATE_SUCCESS_RESPONSE
Definition: Stun.h:153
@ STUN_PACKET_TYPE_SHARED_SECRET_RESPONSE
Definition: Stun.h:152
@ STUN_PACKET_TYPE_SEND
Definition: Stun.h:144
@ STUN_PACKET_TYPE_SHARED_SECRET_REQUEST
Definition: Stun.h:141
@ STUN_PACKET_TYPE_DATA_INDICATION
Definition: Stun.h:150
@ STUN_PACKET_TYPE_ALLOCATE
Definition: Stun.h:142
@ STUN_PACKET_TYPE_DATA
Definition: Stun.h:145
@ STUN_PACKET_TYPE_REFRESH
Definition: Stun.h:143
@ STUN_PACKET_TYPE_SHARED_SECRET_ERROR_RESPONSE
Definition: Stun.h:158
@ STUN_PACKET_TYPE_CHANNEL_BIND_ERROR_RESPONSE
Definition: Stun.h:162
@ STUN_PACKET_TYPE_BINDING_REQUEST
Definition: Stun.h:140
@ STUN_PACKET_TYPE_CREATE_PERMISSION
Definition: Stun.h:146
@ STUN_PACKET_TYPE_CHANNEL_BIND_REQUEST
Definition: Stun.h:147
@ STUN_PACKET_TYPE_BINDING_RESPONSE_SUCCESS
Definition: Stun.h:151
@ STUN_PACKET_TYPE_CREATE_PERMISSION_SUCCESS_RESPONSE
Definition: Stun.h:155
@ STUN_PACKET_TYPE_CHANNEL_BIND_SUCCESS_RESPONSE
Definition: Stun.h:156
@ STUN_PACKET_TYPE_REFRESH_ERROR_RESPONSE
Definition: Stun.h:160
STATUS stunPackageIpAddr(PStunHeader, STUN_ATTRIBUTE_TYPE, PKvsIpAddress, PBYTE, PUINT32)
Definition: Stun.c:4
STATUS appendStunDataAttribute(PStunPacket, PBYTE, UINT16)
Definition: Stun.c:1608
struct StunAttributeChannelNumber * PStunAttributeChannelNumber
STATUS createStunPacket(STUN_PACKET_TYPE, PBYTE, PStunPacket *)
Definition: Stun.c:1081
struct StunAttributeErrorCode * PStunAttributeErrorCode
STATUS appendStunRequestedTransportAttribute(PStunPacket, UINT8)
Definition: Stun.c:1383
struct StunAttributeUsername * PStunAttributeUsername
STATUS deserializeStunPacket(PBYTE, UINT32, PBYTE, UINT32, PStunPacket *)
Definition: Stun.c:517
struct StunAttributeLifetime * PStunAttributeLifetime
#define STUN_TRANSACTION_ID_LEN
Definition: Stun.h:83
STATUS appendStunLifetimeAttribute(PStunPacket, UINT32)
Definition: Stun.c:1319
Definition: Include_i.h:99
StunAttributeHeader attribute
Definition: Stun.h:245
KvsIpAddress address
Definition: Stun.h:246
StunAttributeHeader attribute
Definition: Stun.h:346
UINT32 changeFlag
Definition: Stun.h:349
StunAttributeHeader attribute
Definition: Stun.h:338
UINT16 channelNumber
Definition: Stun.h:340
UINT16 reserve
Definition: Stun.h:342
PBYTE data
Definition: Stun.h:334
UINT16 paddedLength
Definition: Stun.h:332
StunAttributeHeader attribute
Definition: Stun.h:329
UINT16 paddedLength
Definition: Stun.h:317
StunAttributeHeader attribute
Definition: Stun.h:312
PCHAR errorPhrase
Definition: Stun.h:319
UINT16 errorCode
Definition: Stun.h:314
StunAttributeHeader attribute
Definition: Stun.h:262
UINT32 crc32Fingerprint
Definition: Stun.h:263
StunAttributeHeader attribute
Definition: Stun.h:272
UINT64 tieBreaker
Definition: Stun.h:325
StunAttributeHeader attribute
Definition: Stun.h:323
UINT32 lifetime
Definition: Stun.h:282
StunAttributeHeader attribute
Definition: Stun.h:281
StunAttributeHeader attribute
Definition: Stun.h:276
UINT16 paddedLength
Definition: Stun.h:306
PBYTE nonce
Definition: Stun.h:308
StunAttributeHeader attribute
Definition: Stun.h:303
StunAttributeHeader attribute
Definition: Stun.h:267
UINT32 priority
Definition: Stun.h:268
PCHAR realm
Definition: Stun.h:299
UINT16 paddedLength
Definition: Stun.h:295
StunAttributeHeader attribute
Definition: Stun.h:292
StunAttributeHeader attribute
Definition: Stun.h:286
PCHAR userName
Definition: Stun.h:258
StunAttributeHeader attribute
Definition: Stun.h:251
UINT16 paddedLength
Definition: Stun.h:254
StunHeader header
Definition: Stun.h:359
UINT32 allocationSize
Definition: Stun.h:365
UINT32 attributesCount
Definition: Stun.h:362
PStunAttributeHeader * attributeList
Definition: Stun.h:368