HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-asap.c
blobc20d8bbbc5a3eac040ec520a19ba2f91c3eb97c0
1 /* packet-asap.c
2 * Routines for Aggregate Server Access Protocol (ASAP)
3 * It is hopefully (needs testing) compliant to
4 * RFC 5352
5 * RFC 5354
6 * RFC 5356
7 * http://www.ietf.org/internet-drafts/draft-dreibholz-asap-hropt-03.txt
8 * http://www.ietf.org/internet-drafts/draft-dreibholz-rserpool-delay-02.txt
10 * The code is not as simple as possible for the current protocol
11 * but allows to be easily adopted to future versions of the protocol.
12 * I will reconsider this after the protocol is an RFC.
14 * TODO:
15 * - check message lengths
17 * Copyright 2004, 2005, 2006, 2007 Michael Tuexen <tuexen [AT] fh-muenster.de>
18 * Copyright 2008 Thomas Dreibholz <dreibh [AT] iem.uni-due.de>
20 * $Id$
22 * Wireshark - Network traffic analyzer
23 * By Gerald Combs <gerald@wireshark.org>
24 * Copyright 1998 Gerald Combs
26 * Copied from README.developer
28 * This program is free software; you can redistribute it and/or
29 * modify it under the terms of the GNU General Public License
30 * as published by the Free Software Foundation; either version 2
31 * of the License, or (at your option) any later version.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
43 #include "config.h"
45 #include <epan/packet.h>
46 #include <epan/to_str.h>
47 #include <epan/sctpppids.h>
49 void proto_register_asap(void);
50 void proto_reg_handoff_asap(void);
52 /* Initialize the protocol and registered fields */
53 static int proto_asap = -1;
54 static int hf_cause_code = -1;
55 static int hf_cause_length = -1;
56 static int hf_cause_info = -1;
57 static int hf_cause_padding = -1;
58 static int hf_message_type = -1;
59 static int hf_message_flags = -1;
60 static int hf_message_length = -1;
61 static int hf_parameter_type = -1;
62 static int hf_parameter_length = -1;
63 static int hf_parameter_value = -1;
64 static int hf_parameter_padding = -1;
65 static int hf_parameter_ipv4_address = -1;
66 static int hf_parameter_ipv6_address = -1;
67 static int hf_dccp_port = -1;
68 static int hf_dccp_reserved = -1;
69 static int hf_dccp_service_code = -1;
70 static int hf_sctp_port = -1;
71 static int hf_transport_use = -1;
72 static int hf_tcp_port = -1;
73 static int hf_udp_port = -1;
74 static int hf_udp_reserved = -1;
75 static int hf_udp_lite_port = -1;
76 static int hf_udp_lite_reserved = -1;
77 static int hf_policy_type = -1;
78 static int hf_policy_value = -1;
79 static int hf_policy_weight = -1;
80 static int hf_policy_priority = -1;
81 static int hf_policy_load = -1;
82 static int hf_policy_degradation = -1;
83 static int hf_policy_loaddpf = -1;
84 static int hf_policy_weightdpf = -1;
85 static int hf_policy_distance = -1;
86 static int hf_pool_handle = -1;
87 static int hf_pe_pe_identifier = -1;
88 static int hf_home_enrp_id = -1;
89 static int hf_reg_life = -1;
90 static int hf_server_identifier = -1;
91 static int hf_cookie = -1;
92 static int hf_pe_identifier = -1;
93 static int hf_pe_checksum = -1;
94 static int hf_hropt_items = -1;
95 static int hf_home_enrp_server_bit = -1;
96 static int hf_reject_bit = -1;
98 /* Initialize the subtree pointers */
99 static gint ett_asap = -1;
100 static gint ett_asap_parameter = -1;
101 static gint ett_asap_cause = -1;
102 static gint ett_asap_flags = -1;
104 static void
105 dissect_parameters(tvbuff_t *, proto_tree *);
106 static void
107 dissect_parameter(tvbuff_t *, proto_tree *);
108 static void
109 dissect_asap(tvbuff_t *, packet_info *, proto_tree *);
111 #define ADD_PADDING(x) ((((x) + 3) >> 2) << 2)
113 #define ASAP_UDP_PORT 3863
114 #define ASAP_TCP_PORT 3863
115 #define ASAP_SCTP_PORT 3863
117 /* Dissectors for error causes. This is common for ASAP and ENRP. */
119 #define CAUSE_CODE_LENGTH 2
120 #define CAUSE_LENGTH_LENGTH 2
121 #define CAUSE_HEADER_LENGTH (CAUSE_CODE_LENGTH + CAUSE_LENGTH_LENGTH)
123 #define CAUSE_HEADER_OFFSET 0
124 #define CAUSE_CODE_OFFSET CAUSE_HEADER_OFFSET
125 #define CAUSE_LENGTH_OFFSET (CAUSE_CODE_OFFSET + CAUSE_CODE_LENGTH)
126 #define CAUSE_INFO_OFFSET (CAUSE_LENGTH_OFFSET + CAUSE_LENGTH_LENGTH)
128 static void
129 dissect_unknown_cause(tvbuff_t *cause_tvb, proto_tree *cause_tree, proto_item *cause_item)
131 guint16 code, length, cause_info_length;
133 code = tvb_get_ntohs(cause_tvb, CAUSE_CODE_OFFSET);
134 length = tvb_get_ntohs(cause_tvb, CAUSE_LENGTH_OFFSET);
135 cause_info_length = length - CAUSE_HEADER_LENGTH;
136 if (cause_info_length > 0)
137 proto_tree_add_item(cause_tree, hf_cause_info, cause_tvb, CAUSE_INFO_OFFSET, cause_info_length, ENC_NA);
138 proto_item_append_text(cause_item, " (code %u and %u byte%s information)", code, cause_info_length, plurality(cause_info_length, "", "s"));
141 #define UNRECOGNIZED_PARAMETER_CAUSE_CODE 0x1
142 #define UNRECONGNIZED_MESSAGE_CAUSE_CODE 0x2
143 #define INVALID_VALUES 0x3
144 #define NON_UNIQUE_PE_IDENTIFIER 0x4
145 #define POOLING_POLICY_INCONSISTENT_CAUSE_CODE 0x5
146 #define LACK_OF_RESOURCES_CAUSE_CODE 0x6
147 #define INCONSISTENT_TRANSPORT_TYPE_CAUSE_CODE 0x7
148 #define INCONSISTENT_DATA_CONTROL_CONFIGURATION_CAUSE_CODE 0x8
149 #define UNKNOWN_POOL_HANDLE 0x9
150 #define REJECTION_DUE_TO_SECURITY_CAUSE_CODE 0xa
152 static const value_string cause_code_values[] = {
153 { UNRECOGNIZED_PARAMETER_CAUSE_CODE, "Unrecognized parameter" },
154 { UNRECONGNIZED_MESSAGE_CAUSE_CODE, "Unrecognized message" },
155 { INVALID_VALUES, "Invalid values" },
156 { NON_UNIQUE_PE_IDENTIFIER, "Non-unique PE identifier" },
157 { POOLING_POLICY_INCONSISTENT_CAUSE_CODE, "Pooling policy inconsistent" },
158 { LACK_OF_RESOURCES_CAUSE_CODE, "Lack of resources" },
159 { INCONSISTENT_TRANSPORT_TYPE_CAUSE_CODE, "Inconsistent transport type" },
160 { INCONSISTENT_DATA_CONTROL_CONFIGURATION_CAUSE_CODE, "Inconsistent data/control type" },
161 { UNKNOWN_POOL_HANDLE, "Unknown pool handle" },
162 { REJECTION_DUE_TO_SECURITY_CAUSE_CODE, "Rejected due to security considerations" },
163 { 0, NULL } };
165 static void
166 dissect_error_cause(tvbuff_t *cause_tvb, proto_tree *parameter_tree)
168 guint16 code, length, padding_length;
169 proto_item *cause_item;
170 proto_tree *cause_tree;
171 tvbuff_t *parameter_tvb, *message_tvb;
173 code = tvb_get_ntohs(cause_tvb, CAUSE_CODE_OFFSET);
174 length = tvb_get_ntohs(cause_tvb, CAUSE_LENGTH_OFFSET);
175 padding_length = tvb_length(cause_tvb) - length;
177 cause_item = proto_tree_add_text(parameter_tree, cause_tvb, CAUSE_HEADER_OFFSET, tvb_length(cause_tvb),
178 "%s", val_to_str_const(code, cause_code_values, "Unknown error cause"));
179 cause_tree = proto_item_add_subtree(cause_item, ett_asap_cause);
181 proto_tree_add_item(cause_tree, hf_cause_code, cause_tvb, CAUSE_CODE_OFFSET, CAUSE_CODE_LENGTH, ENC_BIG_ENDIAN);
182 proto_tree_add_item(cause_tree, hf_cause_length, cause_tvb, CAUSE_LENGTH_OFFSET, CAUSE_LENGTH_LENGTH, ENC_BIG_ENDIAN);
184 switch(code) {
185 case UNRECOGNIZED_PARAMETER_CAUSE_CODE:
186 parameter_tvb = tvb_new_subset_remaining(cause_tvb, CAUSE_INFO_OFFSET);
187 dissect_parameter(parameter_tvb, cause_tree);
188 break;
189 case UNRECONGNIZED_MESSAGE_CAUSE_CODE:
190 message_tvb = tvb_new_subset_remaining(cause_tvb, CAUSE_INFO_OFFSET);
191 dissect_asap(message_tvb, NULL, cause_tree);
192 break;
193 case INVALID_VALUES:
194 parameter_tvb = tvb_new_subset_remaining(cause_tvb, CAUSE_INFO_OFFSET);
195 dissect_parameter(parameter_tvb, cause_tree);
196 break;
197 case NON_UNIQUE_PE_IDENTIFIER:
198 break;
199 case POOLING_POLICY_INCONSISTENT_CAUSE_CODE:
200 parameter_tvb = tvb_new_subset_remaining(cause_tvb, CAUSE_INFO_OFFSET);
201 dissect_parameter(parameter_tvb, cause_tree);
202 break;
203 case LACK_OF_RESOURCES_CAUSE_CODE:
204 break;
205 case INCONSISTENT_TRANSPORT_TYPE_CAUSE_CODE:
206 parameter_tvb = tvb_new_subset_remaining(cause_tvb, CAUSE_INFO_OFFSET);
207 dissect_parameter(parameter_tvb, cause_tree);
208 break;
209 case INCONSISTENT_DATA_CONTROL_CONFIGURATION_CAUSE_CODE:
210 break;
211 case UNKNOWN_POOL_HANDLE:
212 break;
213 case REJECTION_DUE_TO_SECURITY_CAUSE_CODE:
214 break;
215 default:
216 dissect_unknown_cause(cause_tvb, cause_tree, cause_item);
217 break;
219 if (padding_length > 0)
220 proto_tree_add_item(cause_tree, hf_cause_padding, cause_tvb, CAUSE_HEADER_OFFSET + length, padding_length, ENC_NA);
223 static void
224 dissect_error_causes(tvbuff_t *error_causes_tvb, proto_tree *parameter_tree)
226 guint16 length, total_length;
227 gint offset;
228 tvbuff_t *error_cause_tvb;
230 offset = 0;
231 while(tvb_reported_length_remaining(error_causes_tvb, offset) > 0) {
232 length = tvb_get_ntohs(error_causes_tvb, offset + CAUSE_LENGTH_OFFSET);
233 total_length = ADD_PADDING(length);
234 error_cause_tvb = tvb_new_subset(error_causes_tvb, offset , total_length, total_length);
235 dissect_error_cause(error_cause_tvb, parameter_tree);
236 offset += total_length;
240 /* Dissectors for parameters. This is common for ASAP and ENRP. */
242 #define PARAMETER_TYPE_LENGTH 2
243 #define PARAMETER_LENGTH_LENGTH 2
244 #define PARAMETER_HEADER_LENGTH (PARAMETER_TYPE_LENGTH + PARAMETER_LENGTH_LENGTH)
246 #define PARAMETER_HEADER_OFFSET 0
247 #define PARAMETER_TYPE_OFFSET PARAMETER_HEADER_OFFSET
248 #define PARAMETER_LENGTH_OFFSET (PARAMETER_TYPE_OFFSET + PARAMETER_TYPE_LENGTH)
249 #define PARAMETER_VALUE_OFFSET (PARAMETER_LENGTH_OFFSET + PARAMETER_LENGTH_LENGTH)
251 #define IPV4_ADDRESS_LENGTH 4
252 #define IPV4_ADDRESS_OFFSET PARAMETER_VALUE_OFFSET
254 static void
255 dissect_ipv4_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
257 proto_tree_add_item(parameter_tree, hf_parameter_ipv4_address, parameter_tvb, IPV4_ADDRESS_OFFSET, IPV4_ADDRESS_LENGTH, ENC_BIG_ENDIAN);
258 proto_item_append_text(parameter_item, " (%s)", tvb_ip_to_str(parameter_tvb, IPV4_ADDRESS_OFFSET));
261 #define IPV6_ADDRESS_LENGTH 16
262 #define IPV6_ADDRESS_OFFSET PARAMETER_VALUE_OFFSET
264 static void
265 dissect_ipv6_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
267 proto_tree_add_item(parameter_tree, hf_parameter_ipv6_address, parameter_tvb, IPV6_ADDRESS_OFFSET, IPV6_ADDRESS_LENGTH, ENC_NA);
268 proto_item_append_text(parameter_item, " (%s)", tvb_ip6_to_str(parameter_tvb, IPV6_ADDRESS_OFFSET));
271 #define DCCP_PORT_LENGTH 2
272 #define DCCP_RESERVED_LENGTH 2
273 #define DCCP_SERVICE_CODE_LENGTH 4
274 #define DCCP_PORT_OFFSET PARAMETER_VALUE_OFFSET
275 #define DCCP_RESERVED_OFFSET (DCCP_PORT_OFFSET + DCCP_PORT_LENGTH)
276 #define DCCP_SERVICE_CODE_OFFSET (DCCP_RESERVED_OFFSET + DCCP_RESERVED_LENGTH)
277 #define DCCP_ADDRESS_OFFSET (DCCP_SERVICE_CODE_OFFSET + DCCP_SERVICE_CODE_LENGTH)
279 static void
280 dissect_dccp_transport_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
282 tvbuff_t *parameters_tvb;
284 proto_tree_add_item(parameter_tree, hf_dccp_port, parameter_tvb, DCCP_PORT_OFFSET, DCCP_PORT_LENGTH, ENC_BIG_ENDIAN);
285 proto_tree_add_item(parameter_tree, hf_dccp_reserved, parameter_tvb, DCCP_RESERVED_OFFSET, DCCP_RESERVED_LENGTH, ENC_BIG_ENDIAN);
286 proto_tree_add_item(parameter_tree, hf_dccp_service_code, parameter_tvb, DCCP_SERVICE_CODE_OFFSET, DCCP_SERVICE_CODE_LENGTH, ENC_BIG_ENDIAN);
288 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, DCCP_ADDRESS_OFFSET);
289 dissect_parameters(parameters_tvb, parameter_tree);
292 #define TRANSPORT_USE_DATA_ONLY 0
293 #define TRANSPORT_USE_DATA_PLUS_CONTROL 1
295 static const value_string transport_use_values[] = {
296 { TRANSPORT_USE_DATA_ONLY, "Data only" },
297 { TRANSPORT_USE_DATA_PLUS_CONTROL, "Data plus control" },
298 { 0, NULL } };
300 #define SCTP_PORT_LENGTH 2
301 #define SCTP_TRANSPORT_USE_LENGTH 2
302 #define SCTP_PORT_OFFSET PARAMETER_VALUE_OFFSET
303 #define SCTP_TRANSPORT_USE_OFFSET (SCTP_PORT_OFFSET + SCTP_PORT_LENGTH)
304 #define SCTP_ADDRESS_OFFSET (SCTP_TRANSPORT_USE_OFFSET + SCTP_TRANSPORT_USE_LENGTH)
306 static void
307 dissect_sctp_transport_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
309 tvbuff_t *parameters_tvb;
311 proto_tree_add_item(parameter_tree, hf_sctp_port, parameter_tvb, SCTP_PORT_OFFSET, SCTP_PORT_LENGTH, ENC_BIG_ENDIAN);
312 proto_tree_add_item(parameter_tree, hf_transport_use, parameter_tvb, SCTP_TRANSPORT_USE_OFFSET, SCTP_TRANSPORT_USE_LENGTH, ENC_BIG_ENDIAN);
314 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, SCTP_ADDRESS_OFFSET);
315 dissect_parameters(parameters_tvb, parameter_tree);
318 #define TCP_PORT_LENGTH 2
319 #define TCP_TRANSPORT_USE_LENGTH 2
320 #define TCP_PORT_OFFSET PARAMETER_VALUE_OFFSET
321 #define TCP_TRANSPORT_USE_OFFSET (TCP_PORT_OFFSET + TCP_PORT_LENGTH)
322 #define TCP_ADDRESS_OFFSET (TCP_TRANSPORT_USE_OFFSET + TCP_TRANSPORT_USE_LENGTH)
324 static void
325 dissect_tcp_transport_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
327 tvbuff_t *parameters_tvb;
329 proto_tree_add_item(parameter_tree, hf_tcp_port, parameter_tvb, TCP_PORT_OFFSET, TCP_PORT_LENGTH, ENC_BIG_ENDIAN);
330 proto_tree_add_item(parameter_tree, hf_transport_use, parameter_tvb, TCP_TRANSPORT_USE_OFFSET, TCP_TRANSPORT_USE_LENGTH, ENC_BIG_ENDIAN);
332 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, TCP_ADDRESS_OFFSET);
333 dissect_parameters(parameters_tvb, parameter_tree);
336 #define UDP_PORT_LENGTH 2
337 #define UDP_RESERVED_LENGTH 2
338 #define UDP_PORT_OFFSET PARAMETER_VALUE_OFFSET
339 #define UDP_RESERVED_OFFSET (UDP_PORT_OFFSET + UDP_PORT_LENGTH)
340 #define UDP_ADDRESS_OFFSET (UDP_RESERVED_OFFSET + UDP_RESERVED_LENGTH)
342 static void
343 dissect_udp_transport_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
345 tvbuff_t *parameters_tvb;
347 proto_tree_add_item(parameter_tree, hf_udp_port, parameter_tvb, UDP_PORT_OFFSET, UDP_PORT_LENGTH, ENC_BIG_ENDIAN);
348 proto_tree_add_item(parameter_tree, hf_udp_reserved, parameter_tvb, UDP_RESERVED_OFFSET, UDP_RESERVED_LENGTH, ENC_BIG_ENDIAN);
350 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, UDP_ADDRESS_OFFSET);
351 dissect_parameters(parameters_tvb, parameter_tree);
354 #define UDP_LITE_PORT_LENGTH 2
355 #define UDP_LITE_RESERVED_LENGTH 2
356 #define UDP_LITE_PORT_OFFSET PARAMETER_VALUE_OFFSET
357 #define UDP_LITE_RESERVED_OFFSET (UDP_LITE_PORT_OFFSET + UDP_LITE_PORT_LENGTH)
358 #define UDP_LITE_ADDRESS_OFFSET (UDP_LITE_RESERVED_OFFSET + UDP_LITE_RESERVED_LENGTH)
360 static void
361 dissect_udp_lite_transport_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
363 tvbuff_t *parameters_tvb;
365 proto_tree_add_item(parameter_tree, hf_udp_lite_port, parameter_tvb, UDP_LITE_PORT_OFFSET, UDP_LITE_PORT_LENGTH, ENC_BIG_ENDIAN);
366 proto_tree_add_item(parameter_tree, hf_udp_lite_reserved, parameter_tvb, UDP_LITE_RESERVED_OFFSET, UDP_LITE_RESERVED_LENGTH, ENC_BIG_ENDIAN);
368 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, UDP_LITE_ADDRESS_OFFSET);
369 dissect_parameters(parameters_tvb, parameter_tree);
372 #define POLICY_TYPE_LENGTH 4
373 #define POLICY_WEIGHT_LENGTH 4
374 #define POLICY_PRIORITY_LENGTH 4
375 #define POLICY_LOAD_LENGTH 4
376 #define POLICY_DEGRADATION_LENGTH 4
377 #define POLICY_LUDPF_LOADDPF_LENGTH 4
378 #define POLICY_LUDPF_DISTANCE_LENGTH 4
379 #define POLICY_WRANDDPF_WEIGHTDPF_LENGTH 4
380 #define POLICY_WRANDDPF_DISTANCE_LENGTH 4
382 #define POLICY_TYPE_OFFSET PARAMETER_VALUE_OFFSET
383 #define POLICY_VALUE_OFFSET (POLICY_TYPE_OFFSET + POLICY_TYPE_LENGTH)
384 #define POLICY_WEIGHT_OFFSET POLICY_VALUE_OFFSET
385 #define POLICY_PRIORITY_OFFSET POLICY_VALUE_OFFSET
386 #define POLICY_LOAD_OFFSET POLICY_VALUE_OFFSET
387 #define POLICY_DEGRADATION_OFFSET (POLICY_LOAD_OFFSET + POLICY_LOAD_LENGTH)
389 #define POLICY_LUDPF_LOADDPF_OFFSET (POLICY_LOAD_OFFSET + POLICY_LOAD_LENGTH)
390 #define POLICY_LUDPF_DISTANCE_OFFSET (POLICY_LUDPF_LOADDPF_OFFSET + POLICY_LUDPF_LOADDPF_LENGTH)
391 #define POLICY_WRANDDPF_WEIGHTDPF_OFFSET (POLICY_WEIGHT_OFFSET + POLICY_WEIGHT_LENGTH)
392 #define POLICY_WRANDDPF_DISTANCE_OFFSET (POLICY_WRANDDPF_WEIGHTDPF_OFFSET + POLICY_WRANDDPF_WEIGHTDPF_LENGTH)
395 #define ROUND_ROBIN_POLICY 0x00000001
396 #define WEIGHTED_ROUND_ROBIN_POLICY 0x00000002
397 #define RANDOM_POLICY 0x00000003
398 #define WEIGHTED_RANDOM_POLICY 0x00000004
399 #define PRIORITY_POLICY 0x00000005
400 #define LEAST_USED_POLICY 0x40000001
401 #define LEAST_USED_WITH_DEG_POLICY 0x40000002
402 #define PRIORITY_LEAST_USED_POLICY 0x40000003
403 #define RANDOMIZED_LEAST_USED_POLICY 0x40000004
405 #define PRIORITY_LEAST_USED_DEG_POLICY 0xb0001003
406 #define WEIGHTED_RANDOM_DPF_POLICY 0xb0002001
407 #define LEAST_USED_DPF_POLICY 0xb0002002
409 static const value_string policy_type_values[] = {
410 { ROUND_ROBIN_POLICY, "Round Robin (RR)" },
411 { WEIGHTED_ROUND_ROBIN_POLICY, "Weighted Round Robin (WRR)" },
412 { RANDOM_POLICY, "Random (RAND)"},
413 { WEIGHTED_RANDOM_POLICY, "Weighted Random (WRAND)" },
414 { PRIORITY_POLICY, "Priority (PRI)" },
415 { LEAST_USED_POLICY, "Least Used (LU)" },
416 { LEAST_USED_WITH_DEG_POLICY, "Least Used with Degradation (LUD)" },
417 { PRIORITY_LEAST_USED_POLICY, "Priority Least Used (PLU)" },
418 { PRIORITY_LEAST_USED_DEG_POLICY, "Priority Least Used with Degradation (PLUD)" },
419 { RANDOMIZED_LEAST_USED_POLICY, "Randomized Least Used (RLU)" },
420 { LEAST_USED_DPF_POLICY, "Least Used with Delay Penalty Factor (LU-DPF)" },
421 { WEIGHTED_RANDOM_DPF_POLICY, "Weighted Random with Delay Penalty Factor (WRAND-DPF)" },
422 { 0, NULL } };
424 static void
425 dissect_pool_member_selection_policy_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
427 guint32 type;
428 guint length;
430 proto_tree_add_item(parameter_tree, hf_policy_type, parameter_tvb, POLICY_TYPE_OFFSET, POLICY_TYPE_LENGTH, ENC_BIG_ENDIAN);
431 type = tvb_get_ntohl(parameter_tvb, POLICY_TYPE_OFFSET);
432 switch (type) {
433 case RANDOM_POLICY:
434 case ROUND_ROBIN_POLICY:
435 break;
436 case WEIGHTED_RANDOM_POLICY:
437 case WEIGHTED_ROUND_ROBIN_POLICY:
438 proto_tree_add_item(parameter_tree, hf_policy_weight, parameter_tvb, POLICY_WEIGHT_OFFSET, POLICY_WEIGHT_LENGTH, ENC_BIG_ENDIAN);
439 break;
440 case PRIORITY_POLICY:
441 proto_tree_add_item(parameter_tree, hf_policy_priority, parameter_tvb, POLICY_PRIORITY_OFFSET, POLICY_PRIORITY_LENGTH, ENC_BIG_ENDIAN);
442 break;
443 case LEAST_USED_POLICY:
444 case RANDOMIZED_LEAST_USED_POLICY:
445 proto_tree_add_double_format_value(parameter_tree, hf_policy_load, parameter_tvb, POLICY_LOAD_OFFSET, POLICY_LOAD_LENGTH,
446 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff, "%1.2f%%",
447 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff);
448 break;
449 case LEAST_USED_WITH_DEG_POLICY:
450 case PRIORITY_LEAST_USED_POLICY:
451 proto_tree_add_double_format_value(parameter_tree, hf_policy_load, parameter_tvb, POLICY_LOAD_OFFSET, POLICY_LOAD_LENGTH,
452 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff, "%1.2f%%",
453 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff);
454 proto_tree_add_double_format_value(parameter_tree, hf_policy_degradation, parameter_tvb, POLICY_DEGRADATION_OFFSET, POLICY_DEGRADATION_LENGTH,
455 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_DEGRADATION_OFFSET) / (double)0xffffffff, "%1.2f%%",
456 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_DEGRADATION_OFFSET) / (double)0xffffffff);
457 break;
458 case LEAST_USED_DPF_POLICY:
459 proto_tree_add_double_format_value(parameter_tree, hf_policy_load, parameter_tvb, POLICY_LOAD_OFFSET, POLICY_LOAD_LENGTH,
460 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff, "%1.2f%%",
461 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff);
462 proto_tree_add_double_format_value(parameter_tree, hf_policy_loaddpf, parameter_tvb, POLICY_LUDPF_LOADDPF_OFFSET, POLICY_LUDPF_LOADDPF_LENGTH,
463 tvb_get_ntohl(parameter_tvb, POLICY_LUDPF_LOADDPF_OFFSET) / (double)0xffffffff, "%1.5f",
464 tvb_get_ntohl(parameter_tvb, POLICY_LUDPF_LOADDPF_OFFSET) / (double)0xffffffff);
465 proto_tree_add_item(parameter_tree, hf_policy_distance, parameter_tvb, POLICY_LUDPF_DISTANCE_OFFSET, POLICY_LUDPF_DISTANCE_LENGTH, ENC_BIG_ENDIAN);
466 break;
467 case WEIGHTED_RANDOM_DPF_POLICY:
468 proto_tree_add_item(parameter_tree, hf_policy_weight, parameter_tvb, POLICY_WEIGHT_OFFSET, POLICY_WEIGHT_LENGTH, ENC_BIG_ENDIAN);
469 proto_tree_add_double_format_value(parameter_tree, hf_policy_weightdpf, parameter_tvb, POLICY_WRANDDPF_WEIGHTDPF_OFFSET, POLICY_WRANDDPF_WEIGHTDPF_LENGTH,
470 tvb_get_ntohl(parameter_tvb, POLICY_WRANDDPF_WEIGHTDPF_OFFSET) / (double)0xffffffff, "%1.5f",
471 tvb_get_ntohl(parameter_tvb, POLICY_WRANDDPF_WEIGHTDPF_OFFSET) / (double)0xffffffff);
472 proto_tree_add_item(parameter_tree, hf_policy_distance, parameter_tvb, POLICY_WRANDDPF_DISTANCE_OFFSET, POLICY_WRANDDPF_DISTANCE_LENGTH, ENC_BIG_ENDIAN);
473 break;
474 default:
475 length = tvb_length(parameter_tvb) - POLICY_VALUE_OFFSET;
476 if (length > 0) {
477 proto_tree_add_item(parameter_tree, hf_policy_value, parameter_tvb, POLICY_VALUE_OFFSET, length, ENC_NA);
479 break;
483 #define POOL_HANDLE_OFFSET PARAMETER_VALUE_OFFSET
485 static void
486 dissect_pool_handle_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
488 guint16 handle_length;
489 proto_item* pi;
490 char* tmp;
492 handle_length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET) - PARAMETER_HEADER_LENGTH;
493 pi = proto_tree_add_item(parameter_tree, hf_pool_handle, parameter_tvb, POOL_HANDLE_OFFSET, handle_length, ENC_NA);
495 tmp = (gchar*)tvb_get_string(wmem_packet_scope(), parameter_tvb, POOL_HANDLE_OFFSET, handle_length);
496 proto_item_append_text(pi, " (%s)", tmp);
499 #define PE_PE_IDENTIFIER_LENGTH 4
500 #define HOME_ENRP_INDENTIFIER_LENGTH 4
501 #define REGISTRATION_LIFE_LENGTH 4
503 #define PE_PE_IDENTIFIER_OFFSET PARAMETER_VALUE_OFFSET
504 #define HOME_ENRP_INDENTIFIER_OFFSET (PE_PE_IDENTIFIER_OFFSET + PE_PE_IDENTIFIER_LENGTH)
505 #define REGISTRATION_LIFE_OFFSET (HOME_ENRP_INDENTIFIER_OFFSET + HOME_ENRP_INDENTIFIER_LENGTH)
506 #define USER_TRANSPORT_PARAMETER_OFFSET (REGISTRATION_LIFE_OFFSET + REGISTRATION_LIFE_LENGTH)
508 static void
509 dissect_pool_element_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
511 tvbuff_t* parameters_tvb;
512 proto_item* pi;
514 proto_tree_add_item(parameter_tree, hf_pe_pe_identifier, parameter_tvb, PE_PE_IDENTIFIER_OFFSET, PE_PE_IDENTIFIER_LENGTH, ENC_BIG_ENDIAN);
515 proto_tree_add_item(parameter_tree, hf_home_enrp_id, parameter_tvb, HOME_ENRP_INDENTIFIER_OFFSET, HOME_ENRP_INDENTIFIER_LENGTH, ENC_BIG_ENDIAN);
516 pi = proto_tree_add_item(parameter_tree, hf_reg_life, parameter_tvb, REGISTRATION_LIFE_OFFSET, REGISTRATION_LIFE_LENGTH, ENC_BIG_ENDIAN);
517 proto_item_append_text(pi, "ms");
519 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, USER_TRANSPORT_PARAMETER_OFFSET);
520 dissect_parameters(parameters_tvb, parameter_tree);
523 #define SERVER_ID_LENGTH 4
524 #define SERVER_ID_OFFSET PARAMETER_VALUE_OFFSET
525 #define SERVER_TRANSPORT_OFFSET (SERVER_ID_OFFSET + SERVER_ID_LENGTH)
527 static void
528 dissect_server_information_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
530 tvbuff_t *parameters_tvb;
532 proto_tree_add_item(parameter_tree, hf_server_identifier, parameter_tvb, SERVER_ID_OFFSET, SERVER_ID_LENGTH, ENC_BIG_ENDIAN);
534 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, SERVER_TRANSPORT_OFFSET);
535 dissect_parameters(parameters_tvb, parameter_tree);
538 #define ERROR_CAUSES_OFFSET PARAMETER_VALUE_OFFSET
540 static void
541 dissect_operation_error_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
543 tvbuff_t *error_causes_tvb;
545 error_causes_tvb = tvb_new_subset_remaining(parameter_tvb, ERROR_CAUSES_OFFSET);
546 dissect_error_causes(error_causes_tvb, parameter_tree);
549 #define COOKIE_OFFSET PARAMETER_VALUE_OFFSET
551 static void
552 dissect_cookie_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
554 guint16 cookie_length;
556 cookie_length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET) - PARAMETER_HEADER_LENGTH;
557 if (cookie_length > 0)
558 proto_tree_add_item(parameter_tree, hf_cookie, parameter_tvb, COOKIE_OFFSET, cookie_length, ENC_NA);
559 proto_item_append_text(parameter_item, " (%u byte%s)", cookie_length, plurality(cookie_length, "", "s"));
562 #define PE_IDENTIFIER_LENGTH 4
563 #define PE_IDENTIFIER_OFFSET PARAMETER_VALUE_OFFSET
565 static void
566 dissect_pe_identifier_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
568 proto_tree_add_item(parameter_tree, hf_pe_identifier, parameter_tvb, PE_IDENTIFIER_OFFSET, PE_IDENTIFIER_LENGTH, ENC_BIG_ENDIAN);
569 proto_item_append_text(parameter_item, " (0x%x)", tvb_get_ntohl(parameter_tvb, PE_IDENTIFIER_OFFSET));
572 #define PE_CHECKSUM_LENGTH 2
573 #define PE_CHECKSUM_OFFSET PARAMETER_VALUE_OFFSET
575 static void
576 dissect_pe_checksum_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
578 proto_tree_add_item(parameter_tree, hf_pe_checksum, parameter_tvb, PE_CHECKSUM_OFFSET, PE_CHECKSUM_LENGTH, ENC_BIG_ENDIAN);
579 proto_item_append_text(parameter_item, " (0x%x)", tvb_get_ntohs(parameter_tvb, PE_CHECKSUM_OFFSET));
582 #define HROPT_ITEMS_LENGTH 4
583 #define HROPT_ITEMS_OFFSET PARAMETER_VALUE_OFFSET
585 static void
586 dissect_handle_resolution_option_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
588 proto_tree_add_item(parameter_tree, hf_hropt_items, parameter_tvb, HROPT_ITEMS_OFFSET, HROPT_ITEMS_LENGTH, ENC_BIG_ENDIAN);
591 static void
592 dissect_unknown_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
594 guint16 type, parameter_value_length;
596 type = tvb_get_ntohs(parameter_tvb, PARAMETER_TYPE_OFFSET);
597 parameter_value_length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET) - PARAMETER_HEADER_LENGTH;
599 if (parameter_value_length > 0)
600 proto_tree_add_item(parameter_tree, hf_parameter_value, parameter_tvb, PARAMETER_VALUE_OFFSET, parameter_value_length, ENC_NA);
602 proto_item_append_text(parameter_item, " (type %u and %u byte%s value)", type, parameter_value_length, plurality(parameter_value_length, "", "s"));
605 #define IPV4_ADDRESS_PARAMETER_TYPE 0x01
606 #define IPV6_ADDRESS_PARAMETER_TYPE 0x02
607 #define DCCP_TRANSPORT_PARAMETER_TYPE 0x03
608 #define SCTP_TRANSPORT_PARAMETER_TYPE 0x04
609 #define TCP_TRANSPORT_PARAMETER_TYPE 0x05
610 #define UDP_TRANSPORT_PARAMETER_TYPE 0x06
611 #define UDP_LITE_TRANSPORT_PARAMETER_TYPE 0x07
612 #define POOL_MEMBER_SELECTION_POLICY_PARAMETER_TYPE 0x08
613 #define POOL_HANDLE_PARAMETER_TYPE 0x09
614 #define POOL_ELEMENT_PARAMETER_TYPE 0x0a
615 #define SERVER_INFORMATION_PARAMETER_TYPE 0x0b
616 #define OPERATION_ERROR_PARAMETER_TYPE 0x0c
617 #define COOKIE_PARAMETER_TYPE 0x0d
618 #define PE_IDENTIFIER_PARAMETER_TYPE 0x0e
619 #define PE_CHECKSUM_PARAMETER_TYPE 0x0f
620 #define HANDLE_RESOLUTION_OPTION_PARAMETER_TYPE 0x803f
622 static const value_string parameter_type_values[] = {
623 { IPV4_ADDRESS_PARAMETER_TYPE, "IPV4 Address Parameter" },
624 { IPV6_ADDRESS_PARAMETER_TYPE, "IPV6 Address Parameter" },
625 { DCCP_TRANSPORT_PARAMETER_TYPE, "DCCP Transport Address Parameter" },
626 { SCTP_TRANSPORT_PARAMETER_TYPE, "SCTP Transport Address Parameter" },
627 { TCP_TRANSPORT_PARAMETER_TYPE, "TCP Transport Address Parameter" },
628 { UDP_TRANSPORT_PARAMETER_TYPE, "UDP Transport Address Parameter" },
629 { UDP_LITE_TRANSPORT_PARAMETER_TYPE, "UDP-Lite Transport Address Parameter" },
630 { POOL_MEMBER_SELECTION_POLICY_PARAMETER_TYPE, "Pool Member Selection Policy Parameter" },
631 { POOL_HANDLE_PARAMETER_TYPE, "Pool Handle Parameter" },
632 { POOL_ELEMENT_PARAMETER_TYPE, "Pool Element Parameter" },
633 { SERVER_INFORMATION_PARAMETER_TYPE, "Server Information Parameter" },
634 { OPERATION_ERROR_PARAMETER_TYPE, "Operation Error Parameter" },
635 { COOKIE_PARAMETER_TYPE, "Cookie Parameter" },
636 { PE_IDENTIFIER_PARAMETER_TYPE, "Pool Element Identifier Parameter" },
637 { PE_CHECKSUM_PARAMETER_TYPE, "PE Checksum Parameter" },
638 { HANDLE_RESOLUTION_OPTION_PARAMETER_TYPE, "Handle Resolution Option Parameter" },
639 { 0, NULL } };
642 static void
643 dissect_parameter(tvbuff_t *parameter_tvb, proto_tree *asap_tree)
645 guint16 type, length, padding_length;
646 proto_item *parameter_item;
647 proto_tree *parameter_tree;
649 /* extract tag and length from the parameter */
650 type = tvb_get_ntohs(parameter_tvb, PARAMETER_TYPE_OFFSET);
651 length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
652 padding_length = tvb_length(parameter_tvb) - length;
654 /* create proto_tree stuff */
655 parameter_item = proto_tree_add_text(asap_tree, parameter_tvb, PARAMETER_HEADER_OFFSET, tvb_length(parameter_tvb), "%s", val_to_str_const(type, parameter_type_values, "Unknown Parameter"));
656 parameter_tree = proto_item_add_subtree(parameter_item, ett_asap_parameter);
658 /* add tag and length to the asap tree */
659 proto_tree_add_item(parameter_tree, hf_parameter_type, parameter_tvb, PARAMETER_TYPE_OFFSET, PARAMETER_TYPE_LENGTH, ENC_BIG_ENDIAN);
660 proto_tree_add_item(parameter_tree, hf_parameter_length, parameter_tvb, PARAMETER_LENGTH_OFFSET, PARAMETER_LENGTH_LENGTH, ENC_BIG_ENDIAN);
662 switch(type) {
663 case IPV4_ADDRESS_PARAMETER_TYPE:
664 dissect_ipv4_parameter(parameter_tvb, parameter_tree, parameter_item);
665 break;
666 case IPV6_ADDRESS_PARAMETER_TYPE:
667 dissect_ipv6_parameter(parameter_tvb, parameter_tree, parameter_item);
668 break;
669 case DCCP_TRANSPORT_PARAMETER_TYPE:
670 dissect_dccp_transport_parameter(parameter_tvb, parameter_tree);
671 break;
672 case SCTP_TRANSPORT_PARAMETER_TYPE:
673 dissect_sctp_transport_parameter(parameter_tvb, parameter_tree);
674 break;
675 case TCP_TRANSPORT_PARAMETER_TYPE:
676 dissect_tcp_transport_parameter(parameter_tvb, parameter_tree);
677 break;
678 case UDP_TRANSPORT_PARAMETER_TYPE:
679 dissect_udp_transport_parameter(parameter_tvb, parameter_tree);
680 break;
681 case UDP_LITE_TRANSPORT_PARAMETER_TYPE:
682 dissect_udp_lite_transport_parameter(parameter_tvb, parameter_tree);
683 break;
684 case POOL_MEMBER_SELECTION_POLICY_PARAMETER_TYPE:
685 dissect_pool_member_selection_policy_parameter(parameter_tvb, parameter_tree);
686 break;
687 case POOL_HANDLE_PARAMETER_TYPE:
688 dissect_pool_handle_parameter(parameter_tvb, parameter_tree);
689 break;
690 case POOL_ELEMENT_PARAMETER_TYPE:
691 dissect_pool_element_parameter(parameter_tvb, parameter_tree);
692 break;
693 case SERVER_INFORMATION_PARAMETER_TYPE:
694 dissect_server_information_parameter(parameter_tvb, parameter_tree);
695 break;
696 case OPERATION_ERROR_PARAMETER_TYPE:
697 dissect_operation_error_parameter(parameter_tvb, parameter_tree);
698 break;
699 case COOKIE_PARAMETER_TYPE:
700 dissect_cookie_parameter(parameter_tvb, parameter_tree, parameter_item);
701 break;
702 case PE_IDENTIFIER_PARAMETER_TYPE:
703 dissect_pe_identifier_parameter(parameter_tvb, parameter_tree, parameter_item);
704 break;
705 case PE_CHECKSUM_PARAMETER_TYPE:
706 dissect_pe_checksum_parameter(parameter_tvb, parameter_tree, parameter_item);
707 break;
708 case HANDLE_RESOLUTION_OPTION_PARAMETER_TYPE:
709 dissect_handle_resolution_option_parameter(parameter_tvb, parameter_tree);
710 break;
711 default:
712 dissect_unknown_parameter(parameter_tvb, parameter_tree, parameter_item);
713 break;
716 if (padding_length > 0)
717 proto_tree_add_item(parameter_tree, hf_parameter_padding, parameter_tvb, PARAMETER_HEADER_OFFSET + length, padding_length, ENC_NA);
720 static void
721 dissect_parameters(tvbuff_t *parameters_tvb, proto_tree *tree)
723 gint offset, length, total_length, remaining_length;
724 tvbuff_t *parameter_tvb;
726 offset = 0;
727 while((remaining_length = tvb_length_remaining(parameters_tvb, offset)) > 0) {
728 length = tvb_get_ntohs(parameters_tvb, offset + PARAMETER_LENGTH_OFFSET);
729 total_length = ADD_PADDING(length);
730 if (remaining_length >= length)
731 total_length = MIN(total_length, remaining_length);
732 /* create a tvb for the parameter including the padding bytes */
733 parameter_tvb = tvb_new_subset(parameters_tvb, offset, total_length, total_length);
734 dissect_parameter(parameter_tvb, tree);
735 /* get rid of the handled parameter */
736 offset += total_length;
740 /* Dissectors for messages. This is specific to ASAP */
742 #define MESSAGE_TYPE_LENGTH 1
743 #define MESSAGE_FLAGS_LENGTH 1
744 #define MESSAGE_LENGTH_LENGTH 2
746 #define MESSAGE_TYPE_OFFSET 0
747 #define MESSAGE_FLAGS_OFFSET (MESSAGE_TYPE_OFFSET + MESSAGE_TYPE_LENGTH)
748 #define MESSAGE_LENGTH_OFFSET (MESSAGE_FLAGS_OFFSET + MESSAGE_FLAGS_LENGTH)
749 #define MESSAGE_VALUE_OFFSET (MESSAGE_LENGTH_OFFSET + MESSAGE_LENGTH_LENGTH)
751 #define REGISTRATION_MESSAGE_TYPE 0x01
752 #define DEREGISTRATION_MESSAGE_TYPE 0x02
753 #define REGISTRATION_RESPONSE_MESSAGE_TYPE 0x03
754 #define DEREGISTRATION_RESPONSE_MESSAGE_TYPE 0x04
755 #define HANDLE_RESOLUTION_MESSAGE_TYPE 0x05
756 #define HANDLE_RESOLUTION_RESPONSE_MESSAGE_TYPE 0x06
757 #define ENDPOINT_KEEP_ALIVE_MESSAGE_TYPE 0x07
758 #define ENDPOINT_KEEP_ALIVE_ACK_MESSAGE_TYPE 0x08
759 #define ENDPOINT_UNREACHABLE_MESSAGE_TYPE 0x09
760 #define SERVER_ANNOUNCE_MESSAGE_TYPE 0x0a
761 #define COOKIE_MESSAGE_TYPE 0x0b
762 #define COOKIE_ECHO_MESSAGE_TYPE 0x0c
763 #define BUSINESS_CARD_MESSAGE_TYPE 0x0d
764 #define ERROR_MESSAGE_TYPE 0x0e
766 static const value_string message_type_values[] = {
767 { REGISTRATION_MESSAGE_TYPE, "ASAP Registration" },
768 { DEREGISTRATION_MESSAGE_TYPE, "ASAP Deregistration" },
769 { REGISTRATION_RESPONSE_MESSAGE_TYPE, "ASAP Registration Response" },
770 { DEREGISTRATION_RESPONSE_MESSAGE_TYPE, "ASAP Deregistration Response" },
771 { HANDLE_RESOLUTION_MESSAGE_TYPE, "ASAP Handle Resolution" },
772 { HANDLE_RESOLUTION_RESPONSE_MESSAGE_TYPE, "ASAP Handle Resolution Response" },
773 { ENDPOINT_KEEP_ALIVE_MESSAGE_TYPE, "ASAP Endpoint Keep-Alive" },
774 { ENDPOINT_KEEP_ALIVE_ACK_MESSAGE_TYPE, "ASAP Endpoint Keep-Alive Acknowledgement" },
775 { ENDPOINT_UNREACHABLE_MESSAGE_TYPE, "ASAP Endpoint Unreachable" },
776 { SERVER_ANNOUNCE_MESSAGE_TYPE, "ASAP Server Announce" },
777 { COOKIE_MESSAGE_TYPE, "ASAP Cookie" },
778 { COOKIE_ECHO_MESSAGE_TYPE, "ASAP Cookie Echo" },
779 { BUSINESS_CARD_MESSAGE_TYPE, "ASAP Business Card" },
780 { ERROR_MESSAGE_TYPE, "ASAP Error" },
781 { 0, NULL } };
783 #define SERVER_IDENTIFIER_OFFSET MESSAGE_VALUE_OFFSET
784 #define SERVER_IDENTIFIER_LENGTH 4
786 #define HOME_ENRP_SERVER_BIT_MASK 0x01
787 #define REJECT_BIT_MASK 0x01
789 static const true_false_string home_enrp_server_bit_value = {
790 "Want to be new ENRP server",
791 "Do not want to be new ENRP server"
794 static const true_false_string reject_bit_value = {
795 "Rejected",
796 "Accepted"
799 static void
800 dissect_asap_message(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *asap_tree)
802 tvbuff_t *parameters_tvb;
803 proto_item *flags_item;
804 proto_tree *flags_tree;
805 guint8 type;
808 type = tvb_get_guint8(message_tvb, MESSAGE_TYPE_OFFSET);
809 /* pinfo is NULL only if dissect_asap_message is called via dissect_error_cause */
810 if (pinfo)
811 col_add_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str_const(type, message_type_values, "Unknown ASAP type"));
813 if (asap_tree) {
814 proto_tree_add_item(asap_tree, hf_message_type, message_tvb, MESSAGE_TYPE_OFFSET, MESSAGE_TYPE_LENGTH, ENC_BIG_ENDIAN);
815 flags_item = proto_tree_add_item(asap_tree, hf_message_flags, message_tvb, MESSAGE_FLAGS_OFFSET, MESSAGE_FLAGS_LENGTH, ENC_BIG_ENDIAN);
816 flags_tree = proto_item_add_subtree(flags_item, ett_asap_flags);
817 if (type == REGISTRATION_RESPONSE_MESSAGE_TYPE) {
818 proto_tree_add_item(flags_tree, hf_reject_bit, message_tvb, MESSAGE_FLAGS_OFFSET, MESSAGE_FLAGS_LENGTH, ENC_BIG_ENDIAN);
820 if (type == ENDPOINT_KEEP_ALIVE_MESSAGE_TYPE) {
821 proto_tree_add_item(flags_tree, hf_home_enrp_server_bit, message_tvb, MESSAGE_FLAGS_OFFSET, MESSAGE_FLAGS_LENGTH, ENC_BIG_ENDIAN);
823 proto_tree_add_item(asap_tree, hf_message_length, message_tvb, MESSAGE_LENGTH_OFFSET, MESSAGE_LENGTH_LENGTH, ENC_BIG_ENDIAN);
824 if ((type == SERVER_ANNOUNCE_MESSAGE_TYPE) || (type == ENDPOINT_KEEP_ALIVE_MESSAGE_TYPE)) {
825 proto_tree_add_item(asap_tree, hf_server_identifier, message_tvb, SERVER_IDENTIFIER_OFFSET, SERVER_IDENTIFIER_LENGTH, ENC_BIG_ENDIAN);
826 parameters_tvb = tvb_new_subset_remaining(message_tvb, MESSAGE_VALUE_OFFSET + SERVER_IDENTIFIER_LENGTH);
827 } else {
828 parameters_tvb = tvb_new_subset_remaining(message_tvb, MESSAGE_VALUE_OFFSET);
830 dissect_parameters(parameters_tvb, asap_tree);
834 static void
835 dissect_asap(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree)
837 proto_item *asap_item;
838 proto_tree *asap_tree;
840 /* pinfo is NULL only if dissect_asap is called from dissect_error_cause */
841 if (pinfo)
842 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ASAP");
844 /* In the interest of speed, if "tree" is NULL, don't do any work not
845 necessary to generate protocol tree items. */
846 if (tree) {
847 /* create the asap protocol tree */
848 asap_item = proto_tree_add_item(tree, proto_asap, message_tvb, 0, -1, ENC_NA);
849 asap_tree = proto_item_add_subtree(asap_item, ett_asap);
850 } else {
851 asap_tree = NULL;
853 /* dissect the message */
854 dissect_asap_message(message_tvb, pinfo, asap_tree);
857 /* Register the protocol with Wireshark */
858 void
859 proto_register_asap(void)
862 /* Setup list of header fields */
863 static hf_register_info hf[] = {
864 { &hf_message_type, { "Type", "asap.message_type", FT_UINT8, BASE_DEC, VALS(message_type_values), 0x0, NULL, HFILL } },
865 { &hf_message_flags, { "Flags", "asap.message_flags", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
866 { &hf_message_length, { "Length", "asap.message_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
867 { &hf_cause_code, { "Cause Code", "asap.cause_code", FT_UINT16, BASE_HEX, VALS(cause_code_values), 0x0, NULL, HFILL } },
868 { &hf_cause_length, { "Cause Length", "asap.cause_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
869 { &hf_cause_info, { "Cause Info", "asap.cause_info", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
870 { &hf_cause_padding, { "Padding", "asap.cause_padding", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
871 { &hf_parameter_type, { "Parameter Type", "asap.parameter_type", FT_UINT16, BASE_HEX, VALS(parameter_type_values), 0x0, NULL, HFILL } },
872 { &hf_parameter_length, { "Parameter Length", "asap.parameter_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
873 { &hf_parameter_value, { "Parameter Value", "asap.parameter_value", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
874 { &hf_parameter_padding, { "Padding", "asap.parameter_padding", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
875 { &hf_parameter_ipv4_address, { "IP Version 4 Address", "asap.ipv4_address", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL } },
876 { &hf_parameter_ipv6_address, { "IP Version 6 Address", "asap.ipv6_address", FT_IPv6, BASE_NONE, NULL, 0x0, NULL, HFILL } },
877 { &hf_dccp_port, { "Port", "asap.dccp_transport_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
878 { &hf_dccp_reserved, { "Reserved", "asap.dccp_transport_reserved", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
879 { &hf_dccp_service_code, { "Service Code", "asap.dccp_transport_service_code", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
880 { &hf_sctp_port, { "Port", "asap.sctp_transport_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
881 { &hf_transport_use, { "Transport Use", "asap.transport_use", FT_UINT16, BASE_DEC, VALS(transport_use_values), 0x0, NULL, HFILL } },
882 { &hf_tcp_port, { "Port", "asap.tcp_transport_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
883 { &hf_udp_port, { "Port", "asap.udp_transport_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
884 { &hf_udp_reserved, { "Reserved", "asap.udp_transport_reserved", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
885 { &hf_udp_lite_port, { "Port", "asap.udp_lite_transport_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
886 { &hf_udp_lite_reserved, { "Reserved", "asap.udp_lite_transport_reserved", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
887 { &hf_policy_type, { "Policy Type", "asap.pool_member_selection_policy_type", FT_UINT32, BASE_HEX, VALS(policy_type_values), 0x0, NULL, HFILL } },
888 { &hf_policy_weight, { "Policy Weight", "asap.pool_member_selection_policy_weight", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
889 { &hf_policy_priority, { "Policy Priority", "asap.pool_member_selection_policy_priority", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
890 { &hf_policy_load, { "Policy Load", "asap.pool_member_selection_policy_load", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
891 { &hf_policy_degradation, { "Policy Degradation", "asap.pool_member_selection_policy_degradation", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
892 { &hf_policy_loaddpf, { "Policy Load DPF", "asap.pool_member_selection_policy_load_dpf", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
893 { &hf_policy_weightdpf, { "Policy Weight DPF", "asap.pool_member_selection_policy_weight_dpf", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
894 { &hf_policy_distance, { "Policy Distance", "asap.pool_member_selection_policy_distance", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
895 { &hf_policy_value, { "Policy Value", "asap.pool_member_selection_policy_value", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
896 { &hf_pool_handle, { "Pool Handle", "asap.pool_handle_pool_handle", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
897 { &hf_pe_pe_identifier, { "PE Identifier", "asap.pool_element_pe_identifier", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
898 { &hf_home_enrp_id, { "Home ENRP Server Identifier", "asap.pool_element_home_enrp_server_identifier", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
899 { &hf_reg_life, { "Registration Life", "asap.pool_element_registration_life", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
900 { &hf_cookie, { "Cookie", "asap.cookie", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
901 { &hf_pe_identifier, { "PE Identifier", "asap.pe_identifier", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
902 { &hf_pe_checksum, { "PE Checksum", "asap.pe_checksum", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
903 { &hf_hropt_items, { "Items", "asap.hropt_items", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
904 { &hf_server_identifier, { "Server Identifier", "asap.server_identifier", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
905 { &hf_home_enrp_server_bit, { "H Bit", "asap.h_bit", FT_BOOLEAN, 8, TFS(&home_enrp_server_bit_value), HOME_ENRP_SERVER_BIT_MASK, NULL, HFILL } },
906 { &hf_reject_bit, { "R Bit", "asap.r_bit", FT_BOOLEAN, 8, TFS(&reject_bit_value), REJECT_BIT_MASK, NULL, HFILL } },
909 /* Setup protocol subtree array */
910 static gint *ett[] = {
911 &ett_asap,
912 &ett_asap_flags,
913 &ett_asap_parameter,
914 &ett_asap_cause,
917 /* Register the protocol name and description */
918 proto_asap = proto_register_protocol("Aggregate Server Access Protocol", "ASAP", "asap");
920 /* Required function calls to register the header fields and subtrees used */
921 proto_register_field_array(proto_asap, hf, array_length(hf));
922 proto_register_subtree_array(ett, array_length(ett));
926 void
927 proto_reg_handoff_asap(void)
929 dissector_handle_t asap_handle;
931 asap_handle = create_dissector_handle(dissect_asap, proto_asap);
932 dissector_add_uint("sctp.ppi", ASAP_PAYLOAD_PROTOCOL_ID, asap_handle);
933 dissector_add_uint("udp.port", ASAP_UDP_PORT, asap_handle);
934 dissector_add_uint("tcp.port", ASAP_TCP_PORT, asap_handle);
935 dissector_add_uint("sctp.port", ASAP_SCTP_PORT, asap_handle);