Project Alice
Loading...
Searching...
No Matches
pcp_msg_structs.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2014 by Cisco Systems, Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef PCP_MSG_STRUCTS_H_
27#define PCP_MSG_STRUCTS_H_
28
29#ifdef _MSC_VER
30#pragma warning (push)
31#pragma warning (disable:4200)
32#endif // _MSC_VER
33#define PCP_MAX_LEN 1100
34#define PCP_OPCODE_ANNOUNCE 0
35#define PCP_OPCODE_MAP 1
36#define PCP_OPCODE_PEER 2
37#define PCP_OPCODE_SADSCP 3
38#define NATPMP_OPCODE_ANNOUNCE 0
39#define NATPMP_OPCODE_MAP_UDP 1
40#define NATPMP_OPCODE_MAP_TCP 2
41
42/* Possible response codes sent by server, as a result of client request*/
43#define PCP_RES_SUCCESS 0
44#define PCP_RES_UNSUPP_VERSION 1
45#define PCP_RES_NOT_AUTHORIZED 2
46#define PCP_RES_MALFORMED_REQUEST 3
47#define PCP_RES_UNSUPP_OPCODE 4
48#define PCP_RES_UNSUPP_OPTION 5
49#define PCP_RES_MALFORMED_OPTION 6
50#define PCP_RES_NETWORK_FAILURE 7
51#define PCP_RES_NO_RESOURCES 8
52#define PCP_RES_UNSUPP_PROTOCOL 9
53#define PCP_RES_USER_EX_QUOTA 10
54#define PCP_RES_CANNOT_PROVIDE_EXTERNAL 11
55#define PCP_RES_ADDRESS_MISMATCH 12
56#define PCP_RES_EXCESSIVE_REMOTE_PEERS 13
57
58typedef enum pcp_options {
62 PCP_OPTION_DEVICEID=96, /*private range */
68
69#pragma pack(push,1)
70
71#ifndef MAX_USER_ID
72#define MAX_USER_ID 512
73#endif
74#ifndef MAX_DEViCE_ID_STR
75#define MAX_DEVICE_ID 32
76#endif
77#ifndef MAX_GEO_STR
78#define MAX_GEO_STR 32
79#endif
80
81/* PCP common request header*/
82typedef struct pcp_request {
85 uint16_t reserved;
87 uint32_t ip[4]; /* ipv4 will be represented
88 by the ipv4 mapped ipv6 */
91
92/* PCP common response header*/
93typedef struct pcp_response {
95 /* R indicates Request (0) or Response (1)
96 Opcode is 7 bit value specifying operation MAP or PEER */
98 /* reserved bits, must be 0 on transmission and must be ignored on
99 reception */
102 /* an unsigned 32-bit integer, in seconds {0, 2^32-1}*/
104 /* epoch indicates how long has PCP server had its current mappings
105 it increases by 1 every second */
107 /* For requests that were successfully parsed this must be sent as 0 */
111
112typedef struct pcp_options_hdr {
113 /* Most significant bit indicates if this option is mandatory (0)
114 or optional (1) */
116 /* MUST be set to 0 on transmission and MUST be ignored on reception */
118 /* indicates the length of the enclosed data in octets (see RFC) */
119 uint16_t len;
122
123typedef struct nat_pmp_announce_req {
127
128typedef struct nat_pmp_announce_resp {
131 uint16_t result;
135
136typedef struct nat_pmp_map_req {
139 uint16_t reserved;
140 uint16_t int_port;
141 uint16_t ext_port;
144
145typedef struct nat_pmp_map_resp {
148 uint16_t result;
150 uint16_t int_port;
151 uint16_t ext_port;
154
158 uint16_t result;
161
162struct pcp_nonce {
164};
165
166/* same for both request and response */
167typedef struct pcp_map_v2 {
171 uint16_t int_port;
172 uint16_t ext_port;
173 uint32_t ext_ip[4]; /* ipv4 will be represented by the ipv4 mapped ipv6 */
176
177/* same for both request and response */
178typedef struct pcp_map_v1 {
181 uint16_t int_port;
182 uint16_t ext_port;
183 uint32_t ext_ip[4]; /* ipv4 will be represented by the ipv4 mapped ipv6 */
186
187/* same for both request and response */
188typedef struct pcp_peer_v1 {
191 uint16_t int_port;
192 uint16_t ext_port;
193 uint32_t ext_ip[4]; /* ipv4 will be represented by the ipv4 mapped ipv6 */
194 uint16_t peer_port;
195 uint16_t reserved1;
199
200/* same for both request and response */
201typedef struct pcp_peer_v2 {
205 uint16_t int_port;
206 uint16_t ext_port;
207 uint32_t ext_ip[4]; /* ipv4 will be represented by the ipv4 mapped ipv6 */
208 uint16_t peer_port;
209 uint16_t reserved1;
213
214typedef struct pcp_sadscp_req {
218 char app_name[0];
220
221typedef struct pcp_sadscp_resp {
226
227typedef struct pcp_location_option {
230 uint16_t len;
231 //float latitude;
232 //float longitude;
235
236typedef struct pcp_userid_option {
239 uint16_t len;
242
243typedef struct pcp_deviceid_option {
246 uint16_t len;
247 // uint32_t device_class;
250
251#define FOREACH_DEVICE(DEVICE) \
252 DEVICE(smartphone) \
253 DEVICE(iphone) \
254 DEVICE(unknown)
255
256#define GENERATE_ENUM(ENUM) ENUM,
257#define GENERATE_STRING(STRING) #STRING ,
258
259typedef enum DEVICE_ENUM {
262
266 uint16_t len;
269
270typedef struct pcp_3rd_party_option {
273 uint16_t len;
277
278typedef struct pcp_filter_option {
281 uint16_t len;
288
292 uint16_t len;
295#define PCP_DSCP_MASK ((1<<6)-1)
297 /* most significant bit is used for response */
299//#define PCP_FLOW_OPTION_RESP_P (1<<7)
302
303typedef struct pcp_metadata_option {
306 uint16_t len;
310
311#pragma pack(pop)
312
313#ifdef _MSC_VER
314#pragma warning (pop)
315#endif // _MSC_VER
316#endif /* PCP_MSG_STRUCTS_H_ */
uint uint32_t
uchar uint8_t
struct nat_pmp_announce_resp nat_pmp_announce_resp_t
struct pcp_flow_priority_option pcp_flow_priority_option_t
pcp_options
@ PCP_OPTION_PREF_FAIL
@ PCP_OPTION_FILTER
@ PCP_OPTION_LOCATION
@ PCP_OPTION_FLOW_PRIORITY
@ PCP_OPTION_USERID
@ PCP_OPTION_3RD_PARTY
@ PCP_OPTION_METADATA
@ PCP_OPTION_DEVICEID
struct pcp_response pcp_response_t
#define MAX_DEVICE_ID
struct pcp_location_option pcp_location_option_t
struct pcp_deviceid_option pcp_deviceid_option_t
struct pcp_userid_option pcp_userid_option_t
struct pcp_prefer_fail_option pcp_prefer_fail_option_t
struct pcp_peer_v2 pcp_peer_v2_t
struct pcp_sadscp_req pcp_sadscp_req_t
enum DEVICE_ENUM device_enum_e
struct nat_pmp_map_resp nat_pmp_map_resp_t
struct pcp_metadata_option pcp_metadata_option_t
struct pcp_sadscp_resp pcp_sadscp_resp_t
struct pcp_map_v1 pcp_map_v1_t
struct pcp_request pcp_request_t
struct pcp_peer_v1 pcp_peer_v1_t
struct nat_pmp_map_req nat_pmp_map_req_t
struct pcp_map_v2 pcp_map_v2_t
#define MAX_GEO_STR
struct pcp_3rd_party_option pcp_3rd_party_option_t
enum pcp_options pcp_options_t
struct nat_pmp_inv_version_resp nat_pmp_inv_version_resp_t
struct pcp_filter_option pcp_filter_option_t
struct pcp_options_hdr pcp_options_hdr_t
#define GENERATE_ENUM(ENUM)
DEVICE_ENUM
#define MAX_USER_ID
struct nat_pmp_announce_req nat_pmp_announce_req_t
#define FOREACH_DEVICE(DEVICE)
char deviceid[MAX_DEVICE_ID]
uint32_t filter_peer_ip[4]
char location[MAX_GEO_STR]
uint8_t protocol
uint32_t ext_ip[4]
uint8_t next_data[0]
uint16_t ext_port
uint8_t reserved[3]
uint16_t int_port
uint8_t reserved[3]
uint32_t ext_ip[4]
uint16_t int_port
struct pcp_nonce nonce
uint16_t ext_port
uint8_t next_data[0]
uint8_t protocol
uint32_t n[3]
uint8_t next_data[0]
uint8_t reserved[3]
uint16_t int_port
uint32_t ext_ip[4]
uint32_t peer_ip[4]
uint8_t protocol
uint16_t reserved1
uint16_t peer_port
uint16_t ext_port
uint8_t next_data[0]
uint8_t protocol
uint32_t ext_ip[4]
struct pcp_nonce nonce
uint16_t int_port
uint8_t reserved[3]
uint32_t peer_ip[4]
uint16_t ext_port
uint16_t peer_port
uint16_t reserved1
uint8_t next_data[0]
uint8_t r_opcode
uint32_t ip[4]
uint8_t next_data[0]
uint32_t req_lifetime
uint16_t reserved
uint32_t lifetime
uint8_t result_code
uint32_t reserved1[3]
uint32_t epochtime
uint8_t r_opcode
uint8_t next_data[0]
struct pcp_nonce nonce
uint8_t tolerance_fields
uint8_t app_name_length
struct pcp_nonce nonce
uint8_t reserved[3]
char userid[MAX_USER_ID]