diff options
author | Benny Prijono <bennylp@teluu.com> | 2008-03-09 12:55:00 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2008-03-09 12:55:00 +0000 |
commit | 9e0ebffd26e56586f6f2ab0469144c3685fc388c (patch) | |
tree | 7c06e7a3db2b951290462c2ca9580ab5daf57b79 /pjnath/include | |
parent | fee9975ecfd058c88d5dd8648ec6ff6bc6ff40c3 (diff) |
More work for ticket #485: updated pjnath with TURN-07 and added authentication in the server
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1852 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjnath/include')
-rw-r--r-- | pjnath/include/pjnath/stun_msg.h | 84 | ||||
-rw-r--r-- | pjnath/include/pjnath/stun_session.h | 36 |
2 files changed, 68 insertions, 52 deletions
diff --git a/pjnath/include/pjnath/stun_msg.h b/pjnath/include/pjnath/stun_msg.h index 8946a71b..cde21fa9 100644 --- a/pjnath/include/pjnath/stun_msg.h +++ b/pjnath/include/pjnath/stun_msg.h @@ -297,11 +297,11 @@ typedef enum pj_stun_attr_type 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_PROPS = 0x0018,/**< REQUESTED-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_RESERVATION_TOKEN = 0x0022,/**< TURN RESERVATION-TOKEN */ PJ_STUN_ATTR_XOR_REFLECTED_FROM = 0x0023,/**< XOR-REFLECTED-FROM */ PJ_STUN_ATTR_PRIORITY = 0x0024,/**< PRIORITY */ PJ_STUN_ATTR_USE_CANDIDATE = 0x0025,/**< USE-CANDIDATE */ @@ -358,6 +358,8 @@ typedef enum pj_stun_status PJ_STUN_SC_SERVER_ERROR = 500, /**< Server Error */ PJ_STUN_SC_INSUFFICIENT_CAPACITY = 507, /**< Insufficient Capacity (TURN) */ + PJ_STUN_SC_INSUFFICIENT_PORT_CAPACITY=508, /**< Insufficient Port Capacity + (TURN) */ PJ_STUN_SC_GLOBAL_FAILURE = 600 /**< Global Failure */ } pj_stun_status; @@ -945,61 +947,48 @@ typedef struct pj_stun_sockaddr_attr pj_stun_relay_addr_attr; typedef struct pj_stun_uint_attr pj_stun_req_addr_type; /** - * This describes the TURN REQUESTED-PORT-PROPS attribute, encoded as + * This describes the TURN REQUESTED-PROPS attribute, encoded as * STUN 32bit integer attribute. Few macros are provided to manipulate * the values in this attribute: #PJ_STUN_GET_RPP_BITS(), * #PJ_STUN_SET_RPP_BITS(), #PJ_STUN_GET_RPP_PORT(), and * #PJ_STUN_SET_RPP_PORT(). - * + * * This attribute allows the client to request certain properties for - * the port that is allocated by the server. The attribute can be used - * with any transport protocol that has the notion of a 16 bit port - * space (including TCP and UDP). The attribute is 32 bits long. Its - * format is: + * the relayed transport address that is allocated by the server. The + * attribute is 32 bits long. Its format is: \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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Reserved = 0 | A | Specific Port Number | + | Prop-type | Reserved = 0 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ \endverbatim - * The two bits labeled A in the diagram above are for requested port - * alignment and have the following meaning: - * - * - 00 no specific port alignment - * - 01 odd port number - * - 10 even port number - * - 11 even port number; reserve next higher port - */ -typedef struct pj_stun_uint_attr pj_stun_req_port_props_attr; - -/** - * Get the 2 bits requested port alignment value from a 32bit integral - * value of TURN REQUESTED-PORT-PROPS attribute. - */ -#define PJ_STUN_GET_RPP_BITS(u32) ((u32 >> 16) & 0x03) - -/** - * Convert 2 bits requested port alignment value to a 32bit integral - * value of TURN REQUESTED-PORT-PROPS attribute. + * The field labeled "Prop-type" is an 8-bit field specifying the + * desired property. The rest of the attribute is RFFU (Reserved For + * Future Use) and MUST be set to 0 on transmission and ignored on + * reception. The values of the "Prop-type" field are: + * + * 0x00 (Reserved) + * 0x01 Even port number + * 0x02 Pair of ports */ -#define PJ_STUN_SET_RPP_BITS(A) (A << 16) +typedef struct pj_stun_uint_attr pj_stun_req_props_attr; /** - * Get the port number in TURN REQUESTED-PORT-PROPS attribute. The port - * number is returned in host byte order. + * Get the 8bit Prop-type value from a 32bit integral value of TURN + * TURN REQUESTED-PROPS attribute. */ -#define PJ_STUN_GET_RPP_PORT(u32) pj_ntohs((pj_uint16_t)(u32 & 0x0000FFFFL)) +#define PJ_STUN_GET_PROP_TYPE(u32) (u32 >> 24) /** - * Convert port number in host byte order to 32bit value to be encoded in - * TURN REQUESTED-PORT-PROPS attribute. + * Convert 8bit Prop-type value to a 32bit integral value of TURN + * REQUESTED-PROPS attribute. */ -#define PJ_STUN_SET_RPP_PORT(port) ((pj_uint32_t)pj_htons((pj_uint16_t)(port))) +#define PJ_STUN_SET_PROP_TYPE(PropType) (PropType << 24) /** @@ -1046,23 +1035,18 @@ typedef struct pj_stun_uint_attr pj_stun_req_transport_attr; /** - * This describes the TURN REQUESTED-IP attribute. - * The REQUESTED-IP attribute is used by the client to request that a - * specific IP address be allocated by the TURN server. This attribute - * is needed since it is anticipated that TURN servers will be multi- - * homed so as to be able to allocate more than 64k transport addresses. - * As a consequence, a client needing a second transport address on the - * same interface as a previous one can use this attribute to request a - * remote address from the same TURN server interface as the TURN - * client's previous remote address. + * This describes the TURN RESERVATION-TOKEN attribute. + * The RESERVATION-TOKEN attribute contains a token that uniquely + * identifies a relayed transport address being held in reserve by the + * server. The server includes this attribute in a success response to + * tell the client about the token, and the client includes this + * attribute in a subsequent Allocate request to request the server use + * that relayed transport address for the allocation. * - * The format of this attribute is identical to XOR-MAPPED-ADDRESS. - * However, the port component of the attribute MUST be ignored by the - * server. If a client wishes to request a specific IP address and - * port, it uses both the REQUESTED-IP and REQUESTED-PORT-PROPS - * attributes. + * The attribute value is a 64-bit-long field containing the token + * value. */ -typedef struct pj_stun_sockaddr_attr pj_stun_req_ip_attr; +typedef struct pj_stun_uint64_attr pj_stun_res_token_attr; /** * This describes the XOR-REFLECTED-FROM attribute, as described by diff --git a/pjnath/include/pjnath/stun_session.h b/pjnath/include/pjnath/stun_session.h index e0d93d31..2f096d57 100644 --- a/pjnath/include/pjnath/stun_session.h +++ b/pjnath/include/pjnath/stun_session.h @@ -293,7 +293,9 @@ PJ_DECL(pj_status_t) pj_stun_session_create_ind(pj_stun_session *sess, /** * Create a STUN response message. After the message has been * successfully created, application can send the message by calling - * pj_stun_session_send_msg(). + * pj_stun_session_send_msg(). Alternatively application may use + * pj_stun_session_respond() to create and send response in one function + * call. * * @param sess The STUN session instance. * @param req The STUN request where the response is to be created. @@ -315,7 +317,6 @@ PJ_DECL(pj_status_t) pj_stun_session_create_res(pj_stun_session *sess, const pj_str_t *err_msg, pj_stun_tx_data **p_tdata); - /** * Send STUN message to the specified destination. This function will encode * the pj_stun_msg instance to a packet buffer, and add credential or @@ -342,6 +343,37 @@ PJ_DECL(pj_status_t) pj_stun_session_send_msg(pj_stun_session *sess, pj_stun_tx_data *tdata); /** + * Create and send STUN response message. + * + * @param sess The STUN session instance. + * @param req The STUN request message to be responded. + * @param err_code Error code to be set in the response, if error response + * is to be created, according to pj_stun_status enumeration. + * This argument MUST be zero if successful response is + * to be created. + * @param err_msg Optional pointer for the error message string, when + * creating error response. If the value is NULL and the + * \a err_code is non-zero, then default error message will + * be used. + * @param cache Specify whether session should cache this response for + * future request retransmission. If TRUE, subsequent request + * retransmission will be handled by the session and it + * will not call request callback. + * @param dst_addr Destination address of the response (or equal to the + * source address of the original request). + * @param addr_len Address length. + * + * @return PJ_SUCCESS on success, or the appropriate error code. + */ +PJ_DECL(pj_status_t) pj_stun_session_respond(pj_stun_session *sess, + const pj_stun_msg *req, + unsigned code, + const char *err_msg, + pj_bool_t cache, + const pj_sockaddr_t *dst_addr, + unsigned addr_len); + +/** * Cancel outgoing STUN transaction. This operation is only valid for outgoing * STUN request, to cease retransmission of the request and destroy the * STUN client transaction that is used to send the request. |