4
* Portions Copyright (C) 2013 Crocodile RCS Ltd
6
* Based on "ser_stun.h". Copyright (C) 2001-2003 FhG Fokus
8
* This file is part of Kamailio, a free SIP server.
10
* Kamailio is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version
15
* Kamailio is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
#include "../../str.h"
30
#include "../../tcp_conn.h"
31
#include "../../ip_addr.h"
32
#include "../../stun.h"
34
/* STUN message types supported by Kamailio */
35
#define BINDING_REQUEST 0x0001
36
#define BINDING_RESPONSE 0x0101
37
#define BINDING_ERROR_RESPONSE 0x0111
39
/* common STUN attributes */
40
#define MAPPED_ADDRESS_ATTR 0x0001
41
#define USERNAME_ATTR 0x0006
42
#define MESSAGE_INTEGRITY_ATTR 0x0008
43
#define ERROR_CODE_ATTR 0x0009
44
#define UNKNOWN_ATTRIBUTES_ATTR 0x000A
46
/* STUN attributes defined by rfc5389 */
47
#define REALM_ATTR 0x0014
48
#define NONCE_ATTR 0x0015
49
#define XOR_MAPPED_ADDRESS_ATTR 0x0020
50
#define FINGERPRINT_ATTR 0x8028
51
#define SOFTWARE_ATTR 0x8022
52
#define ALTERNATE_SERVER_ATTR 0x8023
54
/* STUN attributes defined by rfc3489 */
55
#define RESPONSE_ADDRESS_ATTR 0x0002
56
#define CHANGE_REQUEST_ATTR 0x0003
57
#define SOURCE_ADDRESS_ATTR 0x0004
58
#define CHANGED_ADDRESS_ATTR 0x0005
59
#define REFLECTED_FROM_ATTR 0x000b
61
/* STUN error codes supported by Kamailio */
62
#define RESPONSE_OK 200
63
#define TRY_ALTERNATE_ERR 300
64
#define BAD_REQUEST_ERR 400
65
#define UNAUTHORIZED_ERR 401
66
#define UNKNOWN_ATTRIBUTE_ERR 420
67
#define STALE_CREDENTIALS_ERR 430
68
#define INTEGRITY_CHECK_ERR 431
69
#define MISSING_USERNAME_ERR 432
70
#define USE_TLS_ERR 433
71
#define MISSING_REALM_ERR 434
72
#define MISSING_NONCE_ERR 435
73
#define UNKNOWN_USERNAME_ERR 436
74
#define STALE_NONCE_ERR 438
75
#define SERVER_ERROR_ERR 500
76
#define GLOBAL_FAILURE_ERR 600
78
#define TRY_ALTERNATE_TXT "Try Alternate"
79
#define BAD_REQUEST_TXT "Bad Request"
80
#define UNAUTHORIZED_TXT "Unauthorized"
81
#define UNKNOWN_ATTRIBUTE_TXT "Unknown Attribute"
82
#define STALE_CREDENTIALS_TXT "Stale Credentials"
83
#define INTEGRITY_CHECK_TXT "Integrity Check Failure"
84
#define MISSING_USERNAME_TXT "Missing Username"
85
#define USE_TLS_TXT "Use TLS"
86
#define MISSING_REALM_TXT "Missing Realm"
87
#define MISSING_NONCE_TXT "Missing Nonce"
88
#define UNKNOWN_USERNAME_TXT "Unknown Username"
89
#define STALE_NONCE_TXT "Stale Nonce"
90
#define SERVER_ERROR_TXT "Server Error"
91
#define GLOBAL_FAILURE_TXT "Global Failure"
94
#define MAGIC_COOKIE_2B 0x2112 /* because of XOR for port */
95
#define MANDATORY_ATTR 0x7fff
98
#define STUN_MSG_LEN 516
101
#define IPV4_FAMILY 0x0001
102
#define IPV6_FAMILY 0x0002
103
#define FATAL_ERROR -1
107
#ifndef SHA_DIGEST_LENGTH
108
#define SHA_DIGEST_LENGTH 20
111
/** padd len to a multiple of sz.
112
* sz must be a power of the form 2^k (e.g. 2, 4, 8, 16 ...)
114
#define PADD_TO(len, sz) (((len) + (sz)-1) & (~((sz) - 1)))
116
#define PADDED_TO_FOUR(len) PADD_TO(len, 4)
117
#define PADDED_TO_SIXTYFOUR(len) PADD_TO(len, 64)
119
struct stun_ip_addr {
120
USHORT_T family; /* 0x01: IPv4; 0x02: IPv6 */
127
USHORT_T empty; /* number of free bytes in buf before it'll be necessary
128
to realloc the buf */
131
struct stun_unknown_att {
133
struct stun_unknown_att* next;
138
struct stun_ip_addr ip_addr; /* XOR values for rfc3489bis, normal values
140
struct stun_buffer msg;
141
UCHAR_T old; /* true: the format of message is in accordance with
145
int process_stun_msg(char* buf, unsigned len, struct receive_info* ri);
147
#endif /* _kam_stun_h */