media/mtransport/third_party/nICEr/src/stun/stun.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/mtransport/third_party/nICEr/src/stun/stun.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,214 @@
     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 +#ifndef _STUN_H
    1.38 +#define _STUN_H
    1.39 +
    1.40 +#ifdef WIN32
    1.41 +#include <winsock2.h>
    1.42 +#else
    1.43 +#include <sys/param.h>
    1.44 +#include <sys/socket.h>
    1.45 +#include <net/if.h>
    1.46 +#ifndef LINUX
    1.47 +#if !defined(__OpenBSD__) && !defined(__NetBSD__)
    1.48 +#include <net/if_var.h>
    1.49 +#endif
    1.50 +#include <net/if_dl.h>
    1.51 +#include <net/if_types.h>
    1.52 +#endif
    1.53 +#ifndef BSD
    1.54 +#include <net/route.h>
    1.55 +#endif
    1.56 +#include <netinet/in.h>
    1.57 +#ifndef LINUX
    1.58 +#include <netinet/in_var.h>
    1.59 +#endif
    1.60 +#include <arpa/inet.h>
    1.61 +#include <netdb.h>
    1.62 +#endif
    1.63 +#include <time.h>
    1.64 +
    1.65 +#include "nr_api.h"
    1.66 +#include "stun_msg.h"
    1.67 +#include "stun_build.h"
    1.68 +#include "stun_codec.h"
    1.69 +#include "stun_hint.h"
    1.70 +#include "stun_util.h"
    1.71 +#include "nr_socket.h"
    1.72 +#include "stun_client_ctx.h"
    1.73 +#include "stun_server_ctx.h"
    1.74 +#include "stun_proc.h"
    1.75 +
    1.76 +#define NR_STUN_VERSION                 "rfc3489bis-11"
    1.77 +#define NR_STUN_PORT                    3478
    1.78 +
    1.79 +/* STUN attributes */
    1.80 +#define NR_STUN_ATTR_MAPPED_ADDRESS          0x0001
    1.81 +#define NR_STUN_ATTR_USERNAME                0x0006
    1.82 +#define NR_STUN_ATTR_MESSAGE_INTEGRITY       0x0008
    1.83 +#define NR_STUN_ATTR_ERROR_CODE              0x0009
    1.84 +#define NR_STUN_ATTR_UNKNOWN_ATTRIBUTES      0x000A
    1.85 +#define NR_STUN_ATTR_REALM                   0x0014
    1.86 +#define NR_STUN_ATTR_NONCE                   0x0015
    1.87 +#define NR_STUN_ATTR_XOR_MAPPED_ADDRESS      0x0020
    1.88 +#define NR_STUN_ATTR_SERVER                  0x8022
    1.89 +#define NR_STUN_ATTR_ALTERNATE_SERVER        0x8023
    1.90 +#define NR_STUN_ATTR_FINGERPRINT             0x8028
    1.91 +
    1.92 +/* for backwards compatibility with obsolete versions of the STUN spec */
    1.93 +#define NR_STUN_ATTR_OLD_XOR_MAPPED_ADDRESS  0x8020
    1.94 +
    1.95 +#ifdef USE_STUND_0_96
    1.96 +#define NR_STUN_ATTR_OLD_CHANGE_REQUEST      0x0003
    1.97 +#endif /* USE_STUND_0_96 */
    1.98 +
    1.99 +#ifdef USE_RFC_3489_BACKWARDS_COMPATIBLE
   1.100 +/* for backwards compatibility with obsolete versions of the STUN spec */
   1.101 +#define NR_STUN_ATTR_OLD_PASSWORD            0x0007
   1.102 +#define NR_STUN_ATTR_OLD_RESPONSE_ADDRESS    0x0002
   1.103 +#define NR_STUN_ATTR_OLD_SOURCE_ADDRESS      0x0004
   1.104 +#define NR_STUN_ATTR_OLD_CHANGED_ADDRESS     0x0005
   1.105 +#endif /* USE_RFC_3489_BACKWARDS_COMPATIBLE */
   1.106 +
   1.107 +#ifdef USE_ICE
   1.108 +/* ICE attributes */
   1.109 +#define NR_STUN_ATTR_PRIORITY                0x0024
   1.110 +#define NR_STUN_ATTR_USE_CANDIDATE           0x0025
   1.111 +#define NR_STUN_ATTR_ICE_CONTROLLED          0x8029
   1.112 +#define NR_STUN_ATTR_ICE_CONTROLLING         0x802A
   1.113 +#endif /* USE_ICE */
   1.114 +
   1.115 +#ifdef USE_TURN
   1.116 +/* TURN attributes */
   1.117 +#define NR_STUN_ATTR_LIFETIME                0x000d
   1.118 +#define NR_STUN_ATTR_XOR_PEER_ADDRESS        0x0012
   1.119 +#define NR_STUN_ATTR_DATA                    0x0013
   1.120 +#define NR_STUN_ATTR_XOR_RELAY_ADDRESS       0x0016
   1.121 +#define NR_STUN_ATTR_REQUESTED_TRANSPORT     0x0019
   1.122 +
   1.123 +#define NR_STUN_ATTR_REQUESTED_TRANSPORT_UDP     17
   1.124 +#endif /* USE_TURN */
   1.125 +
   1.126 +/*
   1.127 + *                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.128 + *                |M|M|M|M|M|C|M|M|M|C|M|M|M|M|
   1.129 + *                |1|1|9|8|7|1|6|5|4|0|3|2|1|0|
   1.130 + *                |1|0| | | | | | | | | | | | |
   1.131 + *                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.132 + *
   1.133 + *      Figure 3: Format of STUN Message Type Field
   1.134 + */
   1.135 +#define NR_STUN_METHOD_TYPE_BITS(m) \
   1.136 +        ((((m) & 0xf80) << 2) | (((m) & 0x070) << 1) | ((m) & 0x00f))
   1.137 +
   1.138 +#define NR_STUN_CLASS_TYPE_BITS(c) \
   1.139 +        ((((c) & 0x002) << 7) | (((c) & 0x001) << 4))
   1.140 +
   1.141 +#define NR_STUN_GET_TYPE_METHOD(t) \
   1.142 +        ((((t) >> 2) & 0xf80) | (((t) >> 1) & 0x070) | ((t) & 0x00f))
   1.143 +
   1.144 +#define NR_STUN_GET_TYPE_CLASS(t) \
   1.145 +        ((((t) >> 7) & 0x002) | (((t) >> 4) & 0x001))
   1.146 +
   1.147 +#define NR_STUN_TYPE(m,c)  (NR_STUN_METHOD_TYPE_BITS((m)) | NR_STUN_CLASS_TYPE_BITS((c)))
   1.148 +
   1.149 +/* building blocks for message types */
   1.150 +#define NR_METHOD_BINDING          0x001
   1.151 +#define NR_CLASS_REQUEST           0x0
   1.152 +#define NR_CLASS_INDICATION        0x1
   1.153 +#define NR_CLASS_RESPONSE          0x2
   1.154 +#define NR_CLASS_ERROR_RESPONSE    0x3
   1.155 +
   1.156 +/* define types for STUN messages */
   1.157 +#define NR_STUN_MSG_BINDING_REQUEST                 NR_STUN_TYPE(NR_METHOD_BINDING, \
   1.158 +                                                                 NR_CLASS_REQUEST)
   1.159 +#define NR_STUN_MSG_BINDING_INDICATION              NR_STUN_TYPE(NR_METHOD_BINDING, \
   1.160 +                                                                 NR_CLASS_INDICATION)
   1.161 +#define NR_STUN_MSG_BINDING_RESPONSE                NR_STUN_TYPE(NR_METHOD_BINDING, \
   1.162 +                                                                 NR_CLASS_RESPONSE)
   1.163 +#define NR_STUN_MSG_BINDING_ERROR_RESPONSE          NR_STUN_TYPE(NR_METHOD_BINDING, \
   1.164 +                                                                 NR_CLASS_ERROR_RESPONSE)
   1.165 +
   1.166 +#ifdef USE_TURN
   1.167 +/* building blocks for TURN message types */
   1.168 +#define NR_METHOD_ALLOCATE                 0x003
   1.169 +#define NR_METHOD_REFRESH                  0x004
   1.170 +
   1.171 +#define NR_METHOD_SEND                     0x006
   1.172 +#define NR_METHOD_DATA                     0x007
   1.173 +#define NR_METHOD_CREATE_PERMISSION        0x008
   1.174 +#define NR_METHOD_CHANNEL_BIND             0x009
   1.175 +
   1.176 +/* define types for a TURN message */
   1.177 +#define NR_STUN_MSG_ALLOCATE_REQUEST                NR_STUN_TYPE(NR_METHOD_ALLOCATE, \
   1.178 +                                                                 NR_CLASS_REQUEST)
   1.179 +#define NR_STUN_MSG_ALLOCATE_RESPONSE               NR_STUN_TYPE(NR_METHOD_ALLOCATE, \
   1.180 +                                                                 NR_CLASS_RESPONSE)
   1.181 +#define NR_STUN_MSG_ALLOCATE_ERROR_RESPONSE         NR_STUN_TYPE(NR_METHOD_ALLOCATE, \
   1.182 +                                                                 NR_CLASS_ERROR_RESPONSE)
   1.183 +#define NR_STUN_MSG_REFRESH_REQUEST                 NR_STUN_TYPE(NR_METHOD_REFRESH, \
   1.184 +                                                                 NR_CLASS_REQUEST)
   1.185 +#define NR_STUN_MSG_REFRESH_RESPONSE                NR_STUN_TYPE(NR_METHOD_REFRESH, \
   1.186 +                                                                 NR_CLASS_RESPONSE)
   1.187 +#define NR_STUN_MSG_REFRESH_ERROR_RESPONSE          NR_STUN_TYPE(NR_METHOD_REFRESH, \
   1.188 +                                                                 NR_CLASS_ERROR_RESPONSE)
   1.189 +
   1.190 +#define NR_STUN_MSG_SEND_INDICATION                 NR_STUN_TYPE(NR_METHOD_SEND, \
   1.191 +                                                                 NR_CLASS_INDICATION)
   1.192 +#define NR_STUN_MSG_DATA_INDICATION                 NR_STUN_TYPE(NR_METHOD_DATA, \
   1.193 +                                                                 NR_CLASS_INDICATION)
   1.194 +
   1.195 +#define NR_STUN_MSG_PERMISSION_REQUEST                 NR_STUN_TYPE(NR_METHOD_CREATE_PERMISSION, \
   1.196 +                                                                    NR_CLASS_REQUEST)
   1.197 +#define NR_STUN_MSG_PERMISSION_RESPONSE                NR_STUN_TYPE(NR_METHOD_CREATE_PERMISSION, \
   1.198 +                                                                    NR_CLASS_RESPONSE)
   1.199 +#define NR_STUN_MSG_PERMISSION_ERROR_RESPONSE          NR_STUN_TYPE(NR_METHOD_CREATE_PERMISSION, \
   1.200 +                                                                    NR_CLASS_ERROR_RESPONSE)
   1.201 +
   1.202 +#define NR_STUN_MSG_CHANNEL_BIND_REQUEST                 NR_STUN_TYPE(NR_METHOD_CHANNEL_BIND, \
   1.203 +                                                                      NR_CLASS_REQUEST)
   1.204 +#define NR_STUN_MSG_CHANNEL_BIND_RESPONSE                NR_STUN_TYPE(NR_METHOD_CHANNEL_BIND, \
   1.205 +                                                                      NR_CLASS_RESPONSE)
   1.206 +#define NR_STUN_MSG_CHANNEL_BIND_ERROR_RESPONSE          NR_STUN_TYPE(NR_METHOD_CHANNEL_BIND, \
   1.207 +                                                                      NR_CLASS_ERROR_RESPONSE)
   1.208 +
   1.209 +
   1.210 +#endif /* USE_TURN */
   1.211 +
   1.212 +
   1.213 +#define NR_STUN_AUTH_RULE_OPTIONAL      (1<<0)
   1.214 +#define NR_STUN_AUTH_RULE_SHORT_TERM    (1<<8)
   1.215 +#define NR_STUN_AUTH_RULE_LONG_TERM     (1<<9)
   1.216 +
   1.217 +#endif

mercurial