1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/mtransport/third_party/nICEr/src/stun/stun_msg.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,206 @@ 1.4 +/* 1.5 +Copyright (c) 2007, Adobe Systems, Incorporated 1.6 +All rights reserved. 1.7 + 1.8 +Redistribution and use in source and binary forms, with or without 1.9 +modification, are permitted provided that the following conditions are 1.10 +met: 1.11 + 1.12 +* Redistributions of source code must retain the above copyright 1.13 + notice, this list of conditions and the following disclaimer. 1.14 + 1.15 +* Redistributions in binary form must reproduce the above copyright 1.16 + notice, this list of conditions and the following disclaimer in the 1.17 + documentation and/or other materials provided with the distribution. 1.18 + 1.19 +* Neither the name of Adobe Systems, Network Resonance nor the names of its 1.20 + contributors may be used to endorse or promote products derived from 1.21 + this software without specific prior written permission. 1.22 + 1.23 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.25 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.26 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.27 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.28 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.29 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.30 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.31 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.32 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.33 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.34 +*/ 1.35 + 1.36 + 1.37 + 1.38 +#ifndef _stun_msg_h 1.39 +#define _stun_msg_h 1.40 + 1.41 +#include "csi_platform.h" 1.42 +#include "nr_api.h" 1.43 +#include "transport_addr.h" 1.44 + 1.45 +#define NR_STUN_MAX_USERNAME_BYTES 513 1.46 +#define NR_STUN_MAX_ERROR_CODE_REASON_BYTES 763 1.47 +#define NR_STUN_MAX_ERROR_CODE_REASON_CHARS 128 1.48 +#define NR_STUN_MAX_REALM_BYTES 763 1.49 +#define NR_STUN_MAX_REALM_CHARS 128 1.50 +#define NR_STUN_MAX_NONCE_BYTES 763 1.51 +#define NR_STUN_MAX_NONCE_CHARS 128 1.52 +#define NR_STUN_MAX_SERVER_BYTES 763 1.53 +#define NR_STUN_MAX_SERVER_CHARS 128 1.54 +#define NR_STUN_MAX_STRING_SIZE 763 /* any possible string */ 1.55 +#define NR_STUN_MAX_UNKNOWN_ATTRIBUTES 16 1.56 +#define NR_STUN_MAX_MESSAGE_SIZE 2048 1.57 + 1.58 +#define NR_STUN_MAGIC_COOKIE 0x2112A442 1.59 +#define NR_STUN_MAGIC_COOKIE2 0xc5cb4e1d /* used recognize old stun messages */ 1.60 + 1.61 +typedef struct { UCHAR octet[12]; } UINT12; 1.62 + 1.63 +typedef struct nr_stun_attr_error_code_ { 1.64 + UINT2 number; 1.65 + char reason[NR_STUN_MAX_ERROR_CODE_REASON_BYTES+1]; /* +1 for \0 */ 1.66 +} nr_stun_attr_error_code; 1.67 + 1.68 +typedef struct nr_stun_attr_fingerprint_ { 1.69 + UINT4 checksum; 1.70 + int valid; 1.71 +} nr_stun_attr_fingerprint; 1.72 + 1.73 +typedef struct nr_stun_attr_message_integrity_ { 1.74 + UCHAR hash[20]; 1.75 + int unknown_user; 1.76 + UCHAR password[1024]; 1.77 + int passwordlen; 1.78 + int valid; 1.79 +} nr_stun_attr_message_integrity; 1.80 + 1.81 +typedef struct nr_stun_attr_unknown_attributes_ { 1.82 + UINT2 attribute[NR_STUN_MAX_UNKNOWN_ATTRIBUTES]; 1.83 + int num_attributes; 1.84 +} nr_stun_attr_unknown_attributes; 1.85 + 1.86 +typedef struct nr_stun_attr_xor_mapped_address_ { 1.87 + nr_transport_addr masked; 1.88 + nr_transport_addr unmasked; 1.89 +} nr_stun_attr_xor_mapped_address; 1.90 + 1.91 +typedef struct nr_stun_attr_data_ { 1.92 + UCHAR data[NR_STUN_MAX_MESSAGE_SIZE]; 1.93 + int length; 1.94 +} nr_stun_attr_data; 1.95 + 1.96 + 1.97 +typedef struct nr_stun_encoded_attribute_ { 1.98 + UINT2 type; 1.99 + UINT2 length; 1.100 + UCHAR value[NR_STUN_MAX_MESSAGE_SIZE]; 1.101 +} nr_stun_encoded_attribute; 1.102 + 1.103 +typedef struct nr_stun_message_attribute_ { 1.104 + UINT2 type; 1.105 + UINT2 length; 1.106 + union { 1.107 + nr_transport_addr address; 1.108 + nr_transport_addr alternate_server; 1.109 + nr_stun_attr_error_code error_code; 1.110 + nr_stun_attr_fingerprint fingerprint; 1.111 + nr_transport_addr mapped_address; 1.112 + nr_stun_attr_message_integrity message_integrity; 1.113 + char nonce[NR_STUN_MAX_NONCE_BYTES+1]; /* +1 for \0 */ 1.114 + char realm[NR_STUN_MAX_REALM_BYTES+1]; /* +1 for \0 */ 1.115 + nr_stun_attr_xor_mapped_address relay_address; 1.116 + char server_name[NR_STUN_MAX_SERVER_BYTES+1]; /* +1 for \0 */ 1.117 + nr_stun_attr_unknown_attributes unknown_attributes; 1.118 + char username[NR_STUN_MAX_USERNAME_BYTES+1]; /* +1 for \0 */ 1.119 + nr_stun_attr_xor_mapped_address xor_mapped_address; 1.120 + 1.121 +#ifdef USE_ICE 1.122 + UINT4 priority; 1.123 + UINT8 ice_controlled; 1.124 + UINT8 ice_controlling; 1.125 +#endif /* USE_ICE */ 1.126 + 1.127 +#ifdef USE_TURN 1.128 + UINT4 lifetime_secs; 1.129 + nr_transport_addr remote_address; 1.130 + UCHAR requested_transport; 1.131 + nr_stun_attr_data data; 1.132 +#endif /* USE_TURN */ 1.133 + 1.134 +#ifdef USE_STUND_0_96 1.135 + UINT4 change_request; 1.136 +#endif /* USE_STUND_0_96 */ 1.137 + 1.138 + /* make sure there's enough room here to place any possible 1.139 + * attribute */ 1.140 + UCHAR largest_possible_attribute[NR_STUN_MAX_MESSAGE_SIZE]; 1.141 + } u; 1.142 + nr_stun_encoded_attribute *encoding; 1.143 + int encoding_length; 1.144 + char *name; 1.145 + char *type_name; 1.146 + int invalid; 1.147 + TAILQ_ENTRY(nr_stun_message_attribute_) entry; 1.148 +} nr_stun_message_attribute; 1.149 + 1.150 +typedef TAILQ_HEAD(nr_stun_message_attribute_head_,nr_stun_message_attribute_) nr_stun_message_attribute_head; 1.151 + 1.152 +typedef struct nr_stun_message_header_ { 1.153 + UINT2 type; 1.154 + UINT2 length; 1.155 + UINT4 magic_cookie; 1.156 + UINT12 id; 1.157 +} nr_stun_message_header; 1.158 + 1.159 +typedef struct nr_stun_message_ { 1.160 + char *name; 1.161 + UCHAR buffer[NR_STUN_MAX_MESSAGE_SIZE]; 1.162 + int length; 1.163 + nr_stun_message_header header; 1.164 + int comprehension_required_unknown_attributes; 1.165 + int comprehension_optional_unknown_attributes; 1.166 + nr_stun_message_attribute_head attributes; 1.167 +} nr_stun_message; 1.168 + 1.169 +int nr_stun_message_create(nr_stun_message **msg); 1.170 +int nr_stun_message_create2(nr_stun_message **msg, UCHAR *buffer, int length); 1.171 +int nr_stun_message_destroy(nr_stun_message **msg); 1.172 + 1.173 +int nr_stun_message_attribute_create(nr_stun_message *msg, nr_stun_message_attribute **attr); 1.174 +int nr_stun_message_attribute_destroy(nr_stun_message *msg, nr_stun_message_attribute **attr); 1.175 + 1.176 +int nr_stun_message_has_attribute(nr_stun_message *msg, UINT2 type, nr_stun_message_attribute **attribute); 1.177 + 1.178 +int nr_stun_message_add_alternate_server_attribute(nr_stun_message *msg, nr_transport_addr *alternate_server); 1.179 +int nr_stun_message_add_error_code_attribute(nr_stun_message *msg, UINT2 number, char *reason); 1.180 +int nr_stun_message_add_fingerprint_attribute(nr_stun_message *msg); 1.181 +int nr_stun_message_add_message_integrity_attribute(nr_stun_message *msg, Data *password); 1.182 +int nr_stun_message_add_nonce_attribute(nr_stun_message *msg, char *nonce); 1.183 +int nr_stun_message_add_realm_attribute(nr_stun_message *msg, char *realm); 1.184 +int nr_stun_message_add_server_attribute(nr_stun_message *msg, char *server_name); 1.185 +int nr_stun_message_add_unknown_attributes_attribute(nr_stun_message *msg, nr_stun_attr_unknown_attributes *unknown_attributes); 1.186 +int nr_stun_message_add_username_attribute(nr_stun_message *msg, char *username); 1.187 +int nr_stun_message_add_xor_mapped_address_attribute(nr_stun_message *msg, nr_transport_addr *mapped_address); 1.188 + 1.189 +#ifdef USE_ICE 1.190 +int nr_stun_message_add_ice_controlled_attribute(nr_stun_message *msg, UINT8 ice_controlled); 1.191 +int nr_stun_message_add_ice_controlling_attribute(nr_stun_message *msg, UINT8 ice_controlling); 1.192 +int nr_stun_message_add_priority_attribute(nr_stun_message *msg, UINT4 priority); 1.193 +int nr_stun_message_add_use_candidate_attribute(nr_stun_message *msg); 1.194 +#endif /* USE_ICE */ 1.195 + 1.196 +#ifdef USE_TURN 1.197 +int nr_stun_message_add_data_attribute(nr_stun_message *msg, UCHAR *data, int length); 1.198 +int nr_stun_message_add_lifetime_attribute(nr_stun_message *msg, UINT4 lifetime_secs); 1.199 +int nr_stun_message_add_requested_transport_attribute(nr_stun_message *msg, UCHAR transport); 1.200 +int 1.201 +nr_stun_message_add_xor_peer_address_attribute(nr_stun_message *msg, nr_transport_addr *peer_address); 1.202 +#endif /* USE_TURN */ 1.203 + 1.204 +#ifdef USE_STUND_0_96 1.205 +int nr_stun_message_add_change_request_attribute(nr_stun_message *msg, UINT4 change_request); 1.206 +#endif /* USE_STUND_0_96 */ 1.207 + 1.208 +#endif 1.209 +