Changeset 1811 for pjproject/trunk
- Timestamp:
- Feb 21, 2008 3:38:36 PM (17 years ago)
- Location:
- pjproject/trunk/pjnath
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/include/pjnath/stun_msg.h
r1443 r1811 70 70 * STUN/TURN Send Indication as defined by draft-ietf-behave-turn 71 71 */ 72 PJ_STUN_SEND_INDICATION_METHOD = 4, 73 74 /** 75 * STUN/TURN Data Indication as defined by draft-ietf-behave-turn 76 */ 77 PJ_STUN_DATA_INDICATION_METHOD = 5, 78 79 /** 80 * STUN/TURN Set Active Destination as defined by draft-ietf-behave-turn 81 */ 82 PJ_STUN_SET_ACTIVE_DESTINATION_METHOD = 6, 83 84 /** 85 * STUN/TURN Connect method as defined by draft-ietf-behave-turn 86 */ 87 PJ_STUN_CONNECT_METHOD = 7, 88 89 /** 90 * STUN/TURN Connect Status indication method. 91 */ 92 PJ_STUN_CONNECT_STATUS_METHOD = 8 72 PJ_STUN_REFRESH_METHOD = 4, 73 74 /** 75 * All known methods. 76 */ 77 PJ_STUN_METHOD_MAX 93 78 }; 94 79 … … 133 118 #define PJ_STUN_IS_REQUEST(msg_type) (((msg_type) & 0x0110) == 0x0000) 134 119 120 135 121 /** 136 122 * Determine if the message type is a successful response. … … 141 127 * The response bit in the message type. 142 128 */ 143 #define PJ_STUN_RESPONSE_BIT (0x0100) 129 #define PJ_STUN_SUCCESS_RESPONSE_BIT (0x0100) 130 144 131 145 132 /** … … 158 145 #define PJ_STUN_IS_RESPONSE(msg_type) (((msg_type) & 0x0100) == 0x0100) 159 146 147 160 148 /** 161 149 * Determine if the message type is an indication message. … … 163 151 #define PJ_STUN_IS_INDICATION(msg_type) (((msg_type) & 0x0110) == 0x0010) 164 152 165 166 153 /** 167 154 * The error response bit in the message type. … … 221 208 222 209 /** 223 * STUN/TURN Send Indication 224 */ 225 PJ_STUN_SEND_INDICATION = 0x0014, 226 227 /** 228 * STUN/TURN Data Indication 229 */ 230 PJ_STUN_DATA_INDICATION = 0x0015, 231 232 /** 233 * STUN/TURN Set Active Destination Request 234 */ 235 PJ_STUN_SET_ACTIVE_DESTINATION_REQUEST = 0x0006, 236 237 /** 238 * STUN/TURN Set Active Destination Response 239 */ 240 PJ_STUN_SET_ACTIVE_DESTINATION_RESPONSE = 0x0106, 241 242 /** 243 * STUN/TURN Set Active Destination Error Response 244 */ 245 PJ_STUN_SET_ACTIVE_DESTINATION_ERROR_RESPONSE = 0x0116, 246 247 /** 248 * STUN/TURN Connect Request 249 */ 250 PJ_STUN_CONNECT_REQUEST = 0x0007, 251 252 /** 253 * STUN/TURN Connect Response 254 */ 255 PJ_STUN_CONNECT_RESPONSE = 0x0107, 256 257 /** 258 * STUN/TURN Connect Error Response 259 */ 260 PJ_STUN_CONNECT_ERROR_RESPONSE = 0x0117, 261 262 /** 263 * STUN/TURN Connect Status Indication 264 */ 265 PJ_STUN_CONNECT_STATUS_INDICATION = 0x0018 266 210 * STUN/TURN REFRESH Request 211 */ 212 PJ_STUN_REFRESH_REQUEST = 0x0004, 213 214 /** 215 * Successful response to STUN REFRESH request 216 */ 217 PJ_STUN_REFRESH_RESPONSE = 0x0104, 218 219 /** 220 * Error response to STUN REFRESH request. 221 */ 222 PJ_STUN_REFRESH_ERROR_RESPONSE = 0x0114 267 223 268 224 } pj_stun_msg_type; … … 286 242 PJ_STUN_ATTR_UNKNOWN_ATTRIBUTES = 0x000A,/**< UNKNOWN-ATTRIBUTES. */ 287 243 PJ_STUN_ATTR_REFLECTED_FROM = 0x000B,/**< REFLECTED-FROM (deprecatd)*/ 288 PJ_STUN_ATTR_LIFETIME = 0x000D,/**< LIFETIME attribute. */ 244 PJ_STUN_ATTR_CHANNEL_NUMBER = 0x000C,/**< TURN CHANNEL-NUMBER */ 245 PJ_STUN_ATTR_LIFETIME = 0x000D,/**< TURN LIFETIME attr. */ 289 246 PJ_STUN_ATTR_MAGIC_COOKIE = 0x000F,/**< MAGIC-COOKIE attr (deprec)*/ 290 PJ_STUN_ATTR_BANDWIDTH = 0x0010,/**< BANDWIDTH attribute*/291 PJ_STUN_ATTR_ REMOTE_ADDR = 0x0012,/**< REMOTE-ADDRESS attribute*/247 PJ_STUN_ATTR_BANDWIDTH = 0x0010,/**< TURN BANDWIDTH attr. */ 248 PJ_STUN_ATTR_PEER_ADDR = 0x0012,/**< TURN PEER-ADDRESS attr. */ 292 249 PJ_STUN_ATTR_DATA = 0x0013,/**< DATA attribute. */ 293 250 PJ_STUN_ATTR_REALM = 0x0014,/**< REALM attribute. */ … … 340 297 //PJ_STUN_SC_UNKNOWN_USERNAME = 436, /**< Unknown Username */ 341 298 #endif 342 PJ_STUN_SC_ NO_BINDING = 437, /**< No Binding.*/299 PJ_STUN_SC_ALLOCATION_MISMATCH = 437, /**< TURN Alloc Mismatch */ 343 300 PJ_STUN_SC_STALE_NONCE = 438, /**< Stale Nonce */ 344 301 PJ_STUN_SC_TRANSITIONING = 439, /**< Transitioning. */ 345 302 PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO = 442, /**< Unsupported Transport or 346 Protocol */347 PJ_STUN_SC_INVALID_IP_ADDR = 443, /**< Invalid IP Address 348 PJ_STUN_SC_INVALID_PORT = 444, /**< Invalid Port 303 Protocol (TURN) */ 304 PJ_STUN_SC_INVALID_IP_ADDR = 443, /**< Invalid IP Address(TURN)*/ 305 PJ_STUN_SC_INVALID_PORT = 444, /**< Invalid Port (TURN) */ 349 306 PJ_STUN_SC_OPER_TCP_ONLY = 445, /**< Operation for TCP Only */ 350 307 PJ_STUN_SC_CONNECTION_FAILURE = 446, /**< Connection Failure */ … … 847 804 848 805 /** 806 * This describes TURN CHANNEL-NUMBER attribute. In this library, 807 * this attribute is represented with 32bit integer. Application may 808 * use #PJ_STUN_GET_CH_NB() and #PJ_STUN_SET_CH_NB() to extract/set 809 * channel number value from the 32bit integral value. 810 * 811 * The CHANNEL-NUMBER attribute contains the number of the channel. 812 * It is a 16-bit unsigned integer, followed by a two-octet RFFU field 813 * which MUST be set to 0 on transmission and ignored on reception. 814 815 \verbatim 816 0 1 2 3 817 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 818 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 819 | Channel Number | RFFU | 820 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 821 \endverbatim 822 */ 823 typedef struct pj_stun_uint_attr pj_stun_channel_number_attr; 824 825 /** 826 * Get 16bit channel number from 32bit integral value. 827 */ 828 #define PJ_STUN_GET_CH_NB(u32) pj_ntohs((pj_uint16_t)(u32>>16)) 829 830 /** 831 * Convert 16bit channel number into 32bit integral value. 832 */ 833 #define PJ_STUN_SET_CH_NB(chnum) (((pj_uint32_t)pj_htons(chnum)) << 16) 834 835 836 /** 849 837 * This describes STUN LIFETIME attribute. 850 838 * The lifetime attribute represents the duration for which the server … … 866 854 867 855 /** 868 * This describes the STUN REMOTE-ADDRESS attribute. 869 * The REMOTE-ADDRESS specifies the address and port of the peer as seen 870 * from the STUN relay server. 871 */ 872 typedef struct pj_stun_sockaddr_attr pj_stun_remote_addr_attr; 856 * This describes the STUN PEER-ADDRESS attribute. 857 * The PEER-ADDRESS specifies the address and port of the peer as seen 858 * from the TURN server. It is encoded in the same way as XOR-MAPPED- 859 * ADDRESS. 860 */ 861 typedef struct pj_stun_sockaddr_attr pj_stun_peer_addr_attr; 873 862 874 863 … … 886 875 * This describes the STUN RELAY-ADDRESS attribute. 887 876 * The RELAY-ADDRESS is present in Allocate responses. It specifies the 888 * address and port that the server allocated to the client. 877 * address and port that the server allocated to the client. It is 878 * encoded in the same way as XOR-MAPPED-ADDRESS. 889 879 */ 890 880 typedef struct pj_stun_sockaddr_attr pj_stun_relay_addr_attr; … … 910 900 911 901 /** 912 * This describes the STUN REQUESTED-PORT-PROPS attribute. 902 * This describes the TURN REQUESTED-PORT-PROPS attribute, encoded as 903 * STUN 32bit integer attribute. Few macros are provided to manipulate 904 * the values in this attribute: #PJ_STUN_GET_RPP_BITS(), 905 * #PJ_STUN_SET_RPP_BITS(), #PJ_STUN_GET_RPP_PORT(), and 906 * #PJ_STUN_SET_RPP_PORT(). 907 * 913 908 * This attribute allows the client to request certain properties for 914 909 * the port that is allocated by the server. The attribute can be used … … 919 914 \verbatim 920 915 921 0 1 2 3 922 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 923 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 924 | Reserved = 0 |B| A | 925 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 926 927 \endverbatim 916 0 1 2 3 917 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 918 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 919 | Reserved = 0 | A | Specific Port Number | 920 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 921 922 \endverbatim 923 924 * The two bits labeled A in the diagram above are for requested port 925 * alignment and have the following meaning: 926 * 927 * - 00 no specific port alignment 928 * - 01 odd port number 929 * - 10 even port number 930 * - 11 even port number; reserve next higher port 928 931 */ 929 932 typedef struct pj_stun_uint_attr pj_stun_req_port_props_attr; 930 933 931 932 /** 933 * This describes the STUN REQUESTED-TRANSPORT attribute. 934 /** 935 * Get the 2 bits requested port alignment value from a 32bit integral 936 * value of TURN REQUESTED-PORT-PROPS attribute. 937 */ 938 #define PJ_STUN_GET_RPP_BITS(u32) ((u32 >> 16) & 0x03) 939 940 /** 941 * Convert 2 bits requested port alignment value to a 32bit integral 942 * value of TURN REQUESTED-PORT-PROPS attribute. 943 */ 944 #define PJ_STUN_SET_RPP_BITS(A) (A << 16) 945 946 /** 947 * Get the port number in TURN REQUESTED-PORT-PROPS attribute. The port 948 * number is returned in host byte order. 949 */ 950 #define PJ_STUN_GET_RPP_PORT(u32) pj_ntons((pj_uint16_t)(u32 & 0x0000FFFFL)) 951 952 /** 953 * Convert port number in host byte order to 32bit value to be encoded in 954 * TURN REQUESTED-PORT-PROPS attribute. 955 */ 956 #define PJ_STUN_SET_RPP_PORT(port) ((pj_uint32_t)pj_htons((pj_uint16_t)(port))) 957 958 959 /** 960 * This describes the TURN REQUESTED-TRANSPORT attribute, encoded in 961 * STUN generic integer attribute. 962 * 934 963 * This attribute is used by the client to request a specific transport 935 * protocol for the allocated transport address. It is a 32 bit 936 * unsigned integer. Its values are: 0x0000 for UDP and 0x0000 for TCP. 964 * protocol for the allocated transport address. It has the following 965 * format: 966 967 \verbatim 968 969 0 1 2 3 970 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 971 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 972 | Protocol | RFFU | 973 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 974 975 976 \endverbatim 977 978 * The Protocol field specifies the desired protocol. The codepoints 979 * used in this field are taken from those allowed in the Protocol field 980 * in the IPv4 header and the NextHeader field in the IPv6 header 981 * [Protocol-Numbers]. This specification only allows the use of 982 * codepoint 17 (User Datagram Protocol). 983 * 984 * The RFFU field is set to zero on transmission and ignored on 985 * receiption. It is reserved for future uses. 937 986 */ 938 987 typedef struct pj_stun_uint_attr pj_stun_req_transport_attr; 939 988 940 941 /** 942 * This describes the STUN REQUESTED-IP attribute. 989 /** 990 * Get protocol value from 32bit TURN REQUESTED-TRANSPORT attribute. 991 */ 992 #define PJ_STUN_GET_RT_PROTO(u32) (u32 >> 24) 993 994 /** 995 * Convert protocol value to be placed in 32bit TURN REQUESTED-TRANSPORT 996 * attribute. 997 */ 998 #define PJ_STUN_SET_RT_PROTO(proto) (((pj_uint32_t)(proto)) << 24) 999 1000 1001 1002 /** 1003 * This describes the TURN REQUESTED-IP attribute. 943 1004 * The REQUESTED-IP attribute is used by the client to request that a 944 * specific IP address be allocated to it. 1005 * specific IP address be allocated by the TURN server. This attribute 1006 * is needed since it is anticipated that TURN servers will be multi- 1007 * homed so as to be able to allocate more than 64k transport addresses. 1008 * As a consequence, a client needing a second transport address on the 1009 * same interface as a previous one can use this attribute to request a 1010 * remote address from the same TURN server interface as the TURN 1011 * client's previous remote address. 1012 * 1013 * The format of this attribute is identical to XOR-MAPPED-ADDRESS. 1014 * However, the port component of the attribute MUST be ignored by the 1015 * server. If a client wishes to request a specific IP address and 1016 * port, it uses both the REQUESTED-IP and REQUESTED-PORT-PROPS 1017 * attributes. 945 1018 */ 946 1019 typedef struct pj_stun_sockaddr_attr pj_stun_req_ip_attr; -
pjproject/trunk/pjnath/src/pjnath/stun_msg.c
r1654 r1811 34 34 static int padding_char; 35 35 36 static const char *stun_method_names[ ] =36 static const char *stun_method_names[PJ_STUN_METHOD_MAX] = 37 37 { 38 38 "Unknown", /* 0 */ … … 40 40 "Shared Secret", /* 2 */ 41 41 "Allocate", /* 3 */ 42 "Send", /* 4 */ 43 "Data", /* 5 */ 44 "Set Active Destination", /* 6 */ 45 "Connect", /* 7 */ 46 "Connect Status" /* 8 */ 42 "Refresh", /* 4 */ 47 43 }; 48 44 … … 64 60 //{ PJ_STUN_SC_MISSING_NONCE, "Missing Nonce"}, 65 61 //{ PJ_STUN_SC_UNKNOWN_USERNAME, "Unknown Username"}, 66 { PJ_STUN_SC_ NO_BINDING, "No Binding"},62 { PJ_STUN_SC_ALLOCATION_MISMATCH, "Allocation Mismatch"}, 67 63 { PJ_STUN_SC_STALE_NONCE, "Stale Nonce"}, 68 64 { PJ_STUN_SC_TRANSITIONING, "Active Destination Already Set"}, … … 217 213 }, 218 214 { 219 /* ID 0x000C is not assigned*/220 NULL,221 NULL,222 NULL215 /* PJ_STUN_ATTR_CHANNEL_NUMBER (0x000C) */ 216 "CHANNEL-NUMBER", 217 &decode_uint_attr, 218 &encode_uint_attr 223 219 }, 224 220 { … … 253 249 }, 254 250 { 255 /* PJ_STUN_ATTR_ REMOTE_ADDRESS, */256 " REMOTE-ADDRESS",257 &decode_ sockaddr_attr,251 /* PJ_STUN_ATTR_PEER_ADDRESS, */ 252 "PEER-ADDRESS", 253 &decode_xored_sockaddr_attr, 258 254 &encode_sockaddr_attr 259 255 }, … … 279 275 /* PJ_STUN_ATTR_RELAY_ADDRESS, */ 280 276 "RELAY-ADDRESS", 281 &decode_ sockaddr_attr,277 &decode_xored_sockaddr_attr, 282 278 &encode_sockaddr_attr 283 279 }, … … 351 347 /* PJ_STUN_ATTR_REQUESTED_IP, */ 352 348 "REQUESTED-IP", 353 &decode_ sockaddr_attr,349 &decode_xored_sockaddr_attr, 354 350 &encode_sockaddr_attr 355 351 }, … … 1732 1728 msg_type |= PJ_STUN_ERROR_RESPONSE_BIT; 1733 1729 else 1734 msg_type |= PJ_STUN_ RESPONSE_BIT;1730 msg_type |= PJ_STUN_SUCCESS_RESPONSE_BIT; 1735 1731 1736 1732 status = pj_stun_msg_create(pool, msg_type, req_msg->hdr.magic, -
pjproject/trunk/pjnath/src/pjnath/stun_msg_dump.c
r1654 r1811 72 72 case PJ_STUN_ATTR_CHANGED_ADDR: 73 73 case PJ_STUN_ATTR_REFLECTED_FROM: 74 case PJ_STUN_ATTR_ REMOTE_ADDR:74 case PJ_STUN_ATTR_PEER_ADDR: 75 75 case PJ_STUN_ATTR_RELAY_ADDR: 76 76 case PJ_STUN_ATTR_XOR_MAPPED_ADDR: … … 97 97 ", INVALID ADDRESS FAMILY!\n"); 98 98 } 99 APPLY(); 100 } 101 break; 102 103 case PJ_STUN_ATTR_CHANNEL_NUMBER: 104 { 105 const pj_stun_uint_attr *attr; 106 107 attr = (const pj_stun_uint_attr*)ahdr; 108 len = pj_ansi_snprintf(p, end-p, 109 ", chnum=%u (0x%x)\n", 110 (int)PJ_STUN_GET_CH_NB(attr->value), 111 (int)PJ_STUN_GET_CH_NB(attr->value)); 99 112 APPLY(); 100 113 }
Note: See TracChangeset
for help on using the changeset viewer.