📄 stun_msg.h
字号:
/* $Id: stun_msg.h 1275 2007-05-15 10:42:56Z bennylp $ */
/*
* Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJNATH_STUN_MSG_H__
#define __PJNATH_STUN_MSG_H__
/**
* @file stun_msg.h
* @brief STUN message components.
*/
#include <pjnath/types.h>
#include <pj/sock.h>
PJ_BEGIN_DECL
/* **************************************************************************/
/**
* @defgroup PJNATH_STUN_MSG STUN Message Representation and Parsing
* @brief Low-level representation and parsing of STUN messages.
* @ingroup PJNATH_STUN
* @{
*/
/**
* STUN magic cookie.
*/
#define PJ_STUN_MAGIC 0x2112A442
/**
* STUN method constants.
*/
enum pj_stun_method_e
{
/**
* STUN Binding method as defined by RFC 3489-bis.
*/
PJ_STUN_BINDING_METHOD = 1,
/**
* STUN Shared Secret method as defined by RFC 3489-bis.
*/
PJ_STUN_SHARED_SECRET_METHOD = 2,
/**
* STUN/TURN Allocate method as defined by draft-ietf-behave-turn
*/
PJ_STUN_ALLOCATE_METHOD = 3,
/**
* STUN/TURN Send Indication as defined by draft-ietf-behave-turn
*/
PJ_STUN_SEND_INDICATION_METHOD = 4,
/**
* STUN/TURN Data Indication as defined by draft-ietf-behave-turn
*/
PJ_STUN_DATA_INDICATION_METHOD = 5,
/**
* STUN/TURN Set Active Destination as defined by draft-ietf-behave-turn
*/
PJ_STUN_SET_ACTIVE_DESTINATION_METHOD = 6,
/**
* STUN/TURN Connect method as defined by draft-ietf-behave-turn
*/
PJ_STUN_CONNECT_METHOD = 7,
/**
* STUN/TURN Connect Status indication method.
*/
PJ_STUN_CONNECT_STATUS_METHOD = 8
};
/**
* Retrieve the STUN method from the message-type field of the STUN
* message.
*/
#define PJ_STUN_GET_METHOD(msg_type) ((msg_type) & 0xFEEF)
/**
* STUN message classes constants.
*/
enum pj_stun_msg_class_e
{
/**
* This specifies that the message type is a STUN request message.
*/
PJ_STUN_REQUEST_CLASS = 0,
/**
* This specifies that the message type is a STUN indication message.
*/
PJ_STUN_INDICATION_CLASS = 1,
/**
* This specifies that the message type is a STUN successful response.
*/
PJ_STUN_SUCCESS_CLASS = 2,
/**
* This specifies that the message type is a STUN error response.
*/
PJ_STUN_ERROR_CLASS = 3
};
/**
* Determine if the message type is a request.
*/
#define PJ_STUN_IS_REQUEST(msg_type) (((msg_type) & 0x0110) == 0x0000)
/**
* Determine if the message type is a successful response.
*/
#define PJ_STUN_IS_SUCCESS_RESPONSE(msg_type) (((msg_type) & 0x0110) == 0x0100)
/**
* The response bit in the message type.
*/
#define PJ_STUN_RESPONSE_BIT (0x0100)
/**
* Determine if the message type is an error response.
*/
#define PJ_STUN_IS_ERROR_RESPONSE(msg_type) (((msg_type) & 0x0110) == 0x0110)
/**
* The error response bit in the message type.
*/
#define PJ_STUN_ERROR_RESPONSE_BIT (0x0110)
/**
* Determine if the message type is a response.
*/
#define PJ_STUN_IS_RESPONSE(msg_type) (((msg_type) & 0x0100) == 0x0100)
/**
* Determine if the message type is an indication message.
*/
#define PJ_STUN_IS_INDICATION(msg_type) (((msg_type) & 0x0110) == 0x0010)
/**
* The error response bit in the message type.
*/
#define PJ_STUN_INDICATION_BIT (0x0010)
/**
* This enumeration describes STUN message types.
*/
typedef enum pj_stun_msg_type
{
/**
* STUN BINDING request.
*/
PJ_STUN_BINDING_REQUEST = 0x0001,
/**
* Successful response to STUN BINDING-REQUEST.
*/
PJ_STUN_BINDING_RESPONSE = 0x0101,
/**
* Error response to STUN BINDING-REQUEST.
*/
PJ_STUN_BINDING_ERROR_RESPONSE = 0x0111,
/**
* STUN SHARED-SECRET reqeust.
*/
PJ_STUN_SHARED_SECRET_REQUEST = 0x0002,
/**
* Successful response to STUN SHARED-SECRET reqeust.
*/
PJ_STUN_SHARED_SECRET_RESPONSE = 0x0102,
/**
* Error response to STUN SHARED-SECRET reqeust.
*/
PJ_STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112,
/**
* STUN/TURN Allocate Request
*/
PJ_STUN_ALLOCATE_REQUEST = 0x0003,
/**
* Successful response to STUN/TURN Allocate Request
*/
PJ_STUN_ALLOCATE_RESPONSE = 0x0103,
/**
* Failure response to STUN/TURN Allocate Request
*/
PJ_STUN_ALLOCATE_ERROR_RESPONSE = 0x0113,
/**
* STUN/TURN Send Indication
*/
PJ_STUN_SEND_INDICATION = 0x0014,
/**
* STUN/TURN Data Indication
*/
PJ_STUN_DATA_INDICATION = 0x0015,
/**
* STUN/TURN Set Active Destination Request
*/
PJ_STUN_SET_ACTIVE_DESTINATION_REQUEST = 0x0006,
/**
* STUN/TURN Set Active Destination Response
*/
PJ_STUN_SET_ACTIVE_DESTINATION_RESPONSE = 0x0106,
/**
* STUN/TURN Set Active Destination Error Response
*/
PJ_STUN_SET_ACTIVE_DESTINATION_ERROR_RESPONSE = 0x0116,
/**
* STUN/TURN Connect Request
*/
PJ_STUN_CONNECT_REQUEST = 0x0007,
/**
* STUN/TURN Connect Response
*/
PJ_STUN_CONNECT_RESPONSE = 0x0107,
/**
* STUN/TURN Connect Error Response
*/
PJ_STUN_CONNECT_ERROR_RESPONSE = 0x0117,
/**
* STUN/TURN Connect Status Indication
*/
PJ_STUN_CONNECT_STATUS_INDICATION = 0x0018
} pj_stun_msg_type;
/**
* This enumeration describes STUN attribute types.
*/
typedef enum pj_stun_attr_type
{
PJ_STUN_ATTR_MAPPED_ADDR = 0x0001,/**< MAPPED-ADDRESS. */
PJ_STUN_ATTR_RESPONSE_ADDR = 0x0002,/**< RESPONSE-ADDRESS (deprcatd)*/
PJ_STUN_ATTR_CHANGE_REQUEST = 0x0003,/**< CHANGE-REQUEST (deprecated)*/
PJ_STUN_ATTR_SOURCE_ADDR = 0x0004,/**< SOURCE-ADDRESS (deprecated)*/
PJ_STUN_ATTR_CHANGED_ADDR = 0x0005,/**< CHANGED-ADDRESS (deprecatd)*/
PJ_STUN_ATTR_USERNAME = 0x0006,/**< USERNAME attribute. */
PJ_STUN_ATTR_PASSWORD = 0x0007,/**< PASSWORD attribute. */
PJ_STUN_ATTR_MESSAGE_INTEGRITY = 0x0008,/**< MESSAGE-INTEGRITY. */
PJ_STUN_ATTR_ERROR_CODE = 0x0009,/**< ERROR-CODE. */
PJ_STUN_ATTR_UNKNOWN_ATTRIBUTES = 0x000A,/**< UNKNOWN-ATTRIBUTES. */
PJ_STUN_ATTR_REFLECTED_FROM = 0x000B,/**< REFLECTED-FROM (deprecatd)*/
PJ_STUN_ATTR_LIFETIME = 0x000D,/**< LIFETIME attribute. */
PJ_STUN_ATTR_MAGIC_COOKIE = 0x000F,/**< MAGIC-COOKIE attr (deprec)*/
PJ_STUN_ATTR_BANDWIDTH = 0x0010,/**< BANDWIDTH attribute */
PJ_STUN_ATTR_REMOTE_ADDR = 0x0012,/**< REMOTE-ADDRESS attribute */
PJ_STUN_ATTR_DATA = 0x0013,/**< DATA attribute. */
PJ_STUN_ATTR_REALM = 0x0014,/**< REALM attribute. */
PJ_STUN_ATTR_NONCE = 0x0015,/**< NONCE attribute. */
PJ_STUN_ATTR_RELAY_ADDR = 0x0016,/**< RELAY-ADDRESS attribute. */
PJ_STUN_ATTR_REQ_ADDR_TYPE = 0x0017,/**< REQUESTED-ADDRESS-TYPE */
PJ_STUN_ATTR_REQ_PORT_PROPS = 0x0018,/**< REQUESTED-PORT-PROPS */
PJ_STUN_ATTR_REQ_TRANSPORT = 0x0019,/**< REQUESTED-TRANSPORT */
PJ_STUN_ATTR_XOR_MAPPED_ADDR = 0x0020,/**< XOR-MAPPED-ADDRESS */
PJ_STUN_ATTR_TIMER_VAL = 0x0021,/**< TIMER-VAL attribute. */
PJ_STUN_ATTR_REQ_IP = 0x0022,/**< REQUESTED-IP attribute */
PJ_STUN_ATTR_XOR_REFLECTED_FROM = 0x0023,/**< XOR-REFLECTED-FROM */
PJ_STUN_ATTR_PRIORITY = 0x0024,/**< PRIORITY */
PJ_STUN_ATTR_USE_CANDIDATE = 0x0025,/**< USE-CANDIDATE */
PJ_STUN_ATTR_XOR_INTERNAL_ADDR = 0x0026,/**< XOR-INTERNAL-ADDRESS */
PJ_STUN_ATTR_END_MANDATORY_ATTR,
PJ_STUN_ATTR_START_EXTENDED_ATTR= 0x8021,
PJ_STUN_ATTR_SERVER = 0x8022,/**< SERVER attribute. */
PJ_STUN_ATTR_ALTERNATE_SERVER = 0x8023,/**< ALTERNATE-SERVER. */
PJ_STUN_ATTR_REFRESH_INTERVAL = 0x8024,/**< REFRESH-INTERVAL. */
PJ_STUN_ATTR_FINGERPRINT = 0x8028,/**< FINGERPRINT attribute. */
PJ_STUN_ATTR_ICE_CONTROLLED = 0x8029,/**< ICE-CCONTROLLED attribute.*/
PJ_STUN_ATTR_ICE_CONTROLLING = 0x802a,/**< ICE-CCONTROLLING attribute*/
PJ_STUN_ATTR_END_EXTENDED_ATTR
} pj_stun_attr_type;
/**
* STUN error codes, which goes into STUN ERROR-CODE attribute.
*/
typedef enum pj_stun_status
{
PJ_STUN_SC_TRY_ALTERNATE = 300, /**< Try Alternate */
PJ_STUN_SC_BAD_REQUEST = 400, /**< Bad Request */
PJ_STUN_SC_UNAUTHORIZED = 401, /**< Unauthorized */
PJ_STUN_SC_UNKNOWN_ATTRIBUTE = 420, /**< Unknown Attribute */
PJ_STUN_SC_STALE_CREDENTIALS = 430, /**< Stale Credentials */
PJ_STUN_SC_INTEGRITY_CHECK_FAILURE = 431, /**< Integrity Chk Fail */
PJ_STUN_SC_MISSING_USERNAME = 432, /**< Missing Username */
PJ_STUN_SC_USE_TLS = 433, /**< Use TLS */
PJ_STUN_SC_MISSING_REALM = 434, /**< Missing Realm */
PJ_STUN_SC_MISSING_NONCE = 435, /**< Missing Nonce */
PJ_STUN_SC_UNKNOWN_USERNAME = 436, /**< Unknown Username */
PJ_STUN_SC_NO_BINDING = 437, /**< No Binding. */
PJ_STUN_SC_STALE_NONCE = 438, /**< Stale Nonce */
PJ_STUN_SC_TRANSITIONING = 439, /**< Transitioning. */
PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO = 442, /**< Unsupported Transport or
Protocol */
PJ_STUN_SC_INVALID_IP_ADDR = 443, /**< Invalid IP Address */
PJ_STUN_SC_INVALID_PORT = 444, /**< Invalid Port */
PJ_STUN_SC_OPER_TCP_ONLY = 445, /**< Operation for TCP Only */
PJ_STUN_SC_CONNECTION_FAILURE = 446, /**< Connection Failure */
PJ_STUN_SC_CONNECTION_TIMEOUT = 447, /**< Connection Timeout */
PJ_STUN_SC_ALLOCATION_QUOTA_REACHED = 486, /**< Allocation Quota Reached
(TURN) */
PJ_STUN_SC_ROLE_CONFLICT = 487, /**< Role Conflict */
PJ_STUN_SC_SERVER_ERROR = 500, /**< Server Error */
PJ_STUN_SC_INSUFFICIENT_CAPACITY = 507, /**< Insufficient Capacity
(TURN) */
PJ_STUN_SC_GLOBAL_FAILURE = 600 /**< Global Failure */
} pj_stun_status;
/**
* This structure describes STUN message header. A STUN message has the
* following format:
*
* \verbatim
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0 0| STUN Message Type | Message Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Magic Cookie |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Transaction ID
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\endverbatim
*/
typedef struct pj_stun_msg_hdr
{
/**
* STUN message type, which the first two bits must be zeroes.
*/
pj_uint16_t type;
/**
* The message length is the size, in bytes, of the message not
* including the 20 byte STUN header.
*/
pj_uint16_t length;
/**
* The magic cookie is a fixed value, 0x2112A442 (PJ_STUN_MAGIC constant).
* In the previous version of this specification [15] this field was part
* of the transaction ID.
*/
pj_uint32_t magic;
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -