Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-ancp.c
blobd6a80ddb90f6593215052621ff999793c1b2464c
1 /* packet-ancp.c
3 * Dissector for ANCP - Access Node Control Protocol
5 * More info on the protocol can be found on IETF:
6 * https://tools.ietf.org/wg/ancp/
7 * https://tools.ietf.org/html/draft-ietf-ancp-protocol-09
8 * https://tools.ietf.org/html/rfc6320
9 * https://tools.ietf.org/html/rfc7256
10 * https://www.iana.org/assignments/ancp/ancp.xhtml
12 * Copyright 2010, Aniruddha.A (anira@cisco.com)
13 * Uli Heilmeier, 2017; Update to RFC6320; current IANA registry types
15 * Wireshark - Network traffic analyzer
16 * By Gerald Combs <gerald@wireshark.org>
17 * Copyright 1998 Gerald Combs
19 * SPDX-License-Identifier: GPL-2.0-or-later
22 #include "config.h"
24 #include <epan/packet.h>
25 #include <epan/stats_tree.h>
26 #include <epan/tfs.h>
27 #include <epan/unit_strings.h>
28 #include <wsutil/ws_roundup.h>
29 #include "packet-tcp.h"
31 #define ANCP_PORT 6068 /* The ANCP TCP port */
33 #define ANCP_MIN_HDR 4
34 #define ANCP_GSMP_ETHER_TYPE 0x880C
35 #define TECH_TYPE_DSL 0x5
36 #define TECH_TYPE_PON 0x1
38 #define ANCP_RESULT_MASK 0xF0
39 #define ANCP_CODE_MASK 0x0FFF
40 #define ANCP_I_FLAG_MASK 0x80
41 #define ANCP_SUBMSG_MASK 0x7FFF
42 #define ADJ_CODE_MASK 0x7F /* excluding MSB M-Flag */
44 #define ANCP_MTYPE_ADJ 10
45 #define ANCP_MTYPE_PORT_MGMT 32
46 #define ANCP_MTYPE_PORT_UP 80
47 #define ANCP_MTYPE_PORT_DN 81
48 #define ANCP_MTYPE_ADJ_UPD 85
49 #define ANCP_MTYPE_GEN_RSP 91
50 #define ANCP_MTYPE_PROV 93
52 /* Topology Discovery Extensions */
53 #define TLV_DSL_LINE_ATTRIBUTES 0x04
54 #define TLV_DSL_LINE_STATE 0x8F
55 #define TLV_DSL_TYPE 0x91
57 /* Port Management Extensions */
58 #define TLV_PING_PARAMS 0x07
59 #define TLV_PING_OPAQUE_DATA 0x08
60 #define TLV_PING_RES_STR 0x09
62 void proto_register_ancp(void);
63 void proto_reg_handoff_ancp(void);
65 static dissector_handle_t ancp_handle;
67 static int hf_ancp_len;
68 static int hf_ancp_len2;
69 static int hf_ancp_ver;
70 static int hf_ancp_mtype;
71 static int hf_ancp_timer;
72 static int hf_ancp_adj_code;
73 static int hf_ancp_sender_name;
74 static int hf_ancp_receiver_name;
75 static int hf_ancp_sender_port;
76 static int hf_ancp_receiver_port;
77 static int hf_ancp_p_info;
78 static int hf_ancp_sender_instance;
79 static int hf_ancp_p_id;
80 static int hf_ancp_receiver_instance;
81 static int hf_ancp_tech_type;
82 static int hf_ancp_num_tlvs;
83 static int hf_ancp_tot_len;
84 static int hf_ancp_cap;
85 static int hf_ancp_result;
86 static int hf_ancp_code;
87 static int hf_ancp_trans_id;
88 static int hf_ancp_i_flag;
89 static int hf_ancp_submsg_num;
90 static int hf_ancp_pudm_unused;
91 static int hf_ancp_function;
92 static int hf_ancp_x_function;
93 static int hf_ancp_ext_flags_res;
94 static int hf_ancp_reserved;
95 static int hf_ancp_blk_len;
96 static int hf_ancp_num_ext_tlvs;
97 static int hf_ancp_ext_tlv_type;
98 static int hf_ancp_ext_tlv_len;
99 static int hf_ancp_dsl_line_stlv_type;
100 static int hf_ancp_dsl_line_stlv_len;
101 static int hf_ancp_dsl_line_stlv_value;
102 static int hf_ancp_ext_tlv_value_str;
103 static int hf_ancp_oam_opaque;
104 static int hf_ancp_oam_loopb_cnt;
105 static int hf_ancp_oam_timeout;
107 static int ett_ancp_len;
108 static int ett_ancp_ver;
109 static int ett_ancp_mtype;
110 static int ett_ancp_timer;
111 static int ett_ancp_adj_code;
112 static int ett_ancp_sender_name;
113 static int ett_ancp_receiver_name;
114 static int ett_ancp_sender_port;
115 static int ett_ancp_receiver_port;
116 static int ett_ancp_p_info;
117 static int ett_ancp_sender_instance;
118 static int ett_ancp_p_id;
119 static int ett_ancp_receiver_instance;
120 static int ett_ancp_tech_type;
121 static int ett_ancp_num_tlvs;
122 static int ett_ancp_tot_len;
123 static int ett_ancp_cap;
124 static int ett_ancp_result;
125 static int ett_ancp_code;
126 static int ett_ancp_trans_id;
127 static int ett_ancp_i_flag;
128 static int ett_ancp_submsg_num;
129 static int ett_ancp_port;
130 static int ett_ancp_port_sess_num;
131 static int ett_ancp_evt_seq_num;
132 static int ett_ancp_label;
133 static int ett_ancp_reserved;
134 static int ett_ancp_blk_len;
135 static int ett_ancp_num_ext_tlvs;
136 static int ett_ancp_ext_tlv_type;
137 static int ett_ancp_dsl_line_stlv_type;
138 static int ett_ancp_dsl_line_stlv_val;
139 static int ett_ancp_ext_tlv_value_str;
140 static int ett_ancp_oam_opaque;
141 static int ett_ancp_oam_loopb_cnt;
142 static int ett_ancp_oam_timeout;
144 static int proto_ancp;
146 /* ANCP stats - Tap interface */
147 static const uint8_t *st_str_packets = "Total Packets";
148 static const uint8_t *st_str_packet_types = "ANCP Packet Types";
149 static const uint8_t *st_str_adj_pack_types = "ANCP Adjacency Packet Types";
151 static int st_node_packets = -1;
152 static int st_node_packet_types = -1;
153 static int st_node_adj_pack_types = -1;
154 static int ancp_tap;
156 struct ancp_tap_t {
157 int ancp_mtype;
158 int ancp_adjcode; /* valid for ancp adjacency message only */
161 /* Value Strings */
162 static const value_string mtype_names[] = {
163 { 10, "Adjacency" },
164 { 32, "Port-Management" },
165 { 80, "Port-Up" },
166 { 81, "Port-Down" },
167 { 85, "Adjacency Update" },
168 { 91, "Generic Response" },
169 { 93, "Provisioning" },
170 { 144, "Multicast Replication Control" },
171 { 145, "Multicast Admission Control" },
172 { 146, "Bandwidth Reallocation Request" },
173 { 147, "Bandwidth Transfer" },
174 { 148, "Delegated Bandwidth Query" },
175 { 149, "Mulicast Flow Query" },
176 { 150, "Committed Bandwidth Report" },
177 { 0, NULL }
180 static const value_string adj_code_names[] = {
181 { 1, "Syn" },
182 { 2, "SynAck" },
183 { 3, "Ack" },
184 { 4, "Rstack" },
185 { 0, NULL }
188 static const value_string captype_names[] = {
189 { 1, "Dynamic-Topology-Discovery" },
190 { 2, "Line-Configuration" },
191 { 3, "Transactional-Multicast" },
192 { 4, "OAM" },
193 { 0, NULL }
196 static const value_string resulttype_names[] = {
197 { 0, "Ignore" },
198 { 1, "NAck" },
199 { 2, "AckAll" },
200 { 3, "Success" },
201 { 4, "Failure" },
202 { 0, NULL }
205 static const value_string codetype_names[] = {
206 { 0x000, "No result" },
207 { 0x002, "Invalid request message" },
208 { 0x006, "One or more of the specified ports are down" },
209 { 0x013, "Out of resources" },
210 { 0x051, "Request message type not implemented" },
211 { 0x053, "Malformed message" },
212 { 0x054, "Mandatory TLV missing" },
213 { 0x055, "Invalid TLV contents" },
214 { 0x064, "Command error" },
215 { 0x065, "Invalid flow address" },
216 { 0x066, "Mulicast flow does not exist" },
217 { 0x067, "Invalid preferred bandwith amount" },
218 { 0x068, "Inconsistent views of delegated bandwidth amount" },
219 { 0x069, "Bandwidth request conflict" },
220 { 0x500, "One or more of the specified ports do not exist" },
221 { 0x501, "Loopback test timed out" },
222 { 0x502, "Reserved" },
223 { 0x503, "DSL access line status showtime" },
224 { 0x504, "DSL access line status idle" },
225 { 0x505, "DSL access line status silent" },
226 { 0x506, "DSL access line status training" },
227 { 0x507, "DSL access line integrity error" },
228 { 0x508, "DSLAM resource not available" },
229 { 0x509, "Invalid test parameter" },
230 { 0, NULL }
233 static const value_string techtype_str[] = {
234 { 0x00, "Not technology dependent" },
235 { 0x01, "PON" },
236 { 0x05, "DSL" },
237 { 0xFF, "Reserved" },
238 { 0, NULL }
241 static const value_string dsl_line_attrs[] = {
242 { 0x91, "DSL-Type" },
243 { 0x81, "Actual-Net-Data-Rate-Upstream" },
244 { 0x82, "Actual-Net-Data-Rate-Downstream" },
245 { 0x83, "Minimum-Net-Data-Rate-Upstream" },
246 { 0x84, "Minimum-Net-Data-Rate-Downstream" },
247 { 0x85, "Attainable-Net-Data-Rate-Upstream" },
248 { 0x86, "Attainable-Net-Data-Rate-Downstream" },
249 { 0x87, "Maximum-Net-Data-Rate-Upstream" },
250 { 0x88, "Maximum-Net-Data-Rate-Downstream" },
251 { 0x89, "Minimum-Net-Low-Power-Data-Rate-Upstream" },
252 { 0x8A, "Minimum-Net-Low-Power-Data-Rate-Downstream" },
253 { 0x8B, "Maximum-Interleaving-Delay-Upstream" },
254 { 0x8C, "Actual-Interleaving-Delay-Upstream" },
255 { 0x8D, "Maximum-Interleaving-Delay-Downstream" },
256 { 0x8E, "Actual-Interleaving-Delay-Downstream" },
257 { 0x8F, "DSL line state" },
258 { 0x90, "Access Loop Encapsulation" },
259 { 0, NULL }
262 static const value_string dsl_line_attr_units[] = {
263 { 0x91, "" },
264 { 0x81, "Kb/sec" },
265 { 0x82, "Kb/sec" },
266 { 0x83, "Kb/sec" },
267 { 0x84, "Kb/sec" },
268 { 0x85, "Kb/sec" },
269 { 0x86, "Kb/sec" },
270 { 0x87, "Kb/sec" },
271 { 0x88, "Kb/sec" },
272 { 0x89, "Kb/sec" },
273 { 0x8A, "Kb/sec" },
274 { 0x8B, "msec" },
275 { 0x8C, "msec" },
276 { 0x8D, "msec" },
277 { 0x8E, "msec" },
278 { 0x8F, "" },
279 { 0x90, "" },
280 { 0, NULL }
283 static const value_string dsl_line_type_names[] = {
284 { 1, "ADSL1" },
285 { 2, "ADSL2" },
286 { 3, "ADSL2+" },
287 { 4, "VDSL1" },
288 { 5, "VDSL2" },
289 { 6, "SDSL" },
290 { 0, NULL }
293 static const value_string dsl_line_state_names[] = {
294 { 1, "Showtime" },
295 { 2, "Idle" },
296 { 3, "Silent" },
297 { 0, NULL }
300 static const value_string function_names[] = {
301 { 0, "Reserved" },
302 { 8, "Configure Connection Service Data" },
303 { 9, "Remote Loopback" },
304 { 0, NULL }
307 static const value_string ext_tlv_types[] = {
308 { 0x0000, "Reserved" },
309 { 0x0001, "Access-Loop-Circuit-ID" },
310 { 0x0002, "Access-Loop-Remote-ID" },
311 { 0x0003, "Access-Aggregation-Circuit-ID-ASCII" },
312 { 0x0004, "DSL Line Attributes" },
313 { 0x0005, "Service-Profile-Name" },
314 { 0x0006, "Access-Aggregation-Circuit-ID-Binary" },
315 { 0x0007, "OAM-Loopback-Test-Parameters" },
316 { 0x0008, "Opaque-Data" },
317 { 0x0009, "OAM-Loopback-Test-Response-String" },
318 { 0x0011, "Command" },
319 { 0x0013, "Multicast-Service-Profile" },
320 { 0x0015, "Bandwidth-Allocation" },
321 { 0x0016, "Bandwidth-Request" },
322 { 0x0018, "Multicast-Service-Profile-Name" },
323 { 0x0019, "Multicast-Flow" },
324 { 0x0021, "List-Action" },
325 { 0x0022, "Sequence-Number" },
326 { 0x0024, "White-List-CAC" },
327 { 0x0025, "MRepCtl-CAC" },
328 { 0x0081, "Actual-Net-Data-Rate-Upstream" },
329 { 0x0082, "Actual-Net-Data-Rate-Downstream" },
330 { 0x0083, "Minimum-Net-Data-Rate-Upstream" },
331 { 0x0084, "Minimum-Net-Data-Rate-Downstream" },
332 { 0x0085, "Attainable-Net-Data-Rate-Upstream" },
333 { 0x0086, "Attainable-Net-Data-Rate-Downstream" },
334 { 0x0087, "Maximum-Net-Data-Rate-Upstream" },
335 { 0x0088, "Maximum-Net-Data-Rate-Downstream" },
336 { 0x0089, "Minimum-Net-Low-Power-Data-Rate-Upstream" },
337 { 0x008A, "Minimum-Net-Low-Power-Data-Rate-Downstream" },
338 { 0x008B, "Maximum-Interleaving-Delay-Upstream" },
339 { 0x008C, "Actual-Interleaving-Delay-Upstream" },
340 { 0x008D, "Maximum-Interleaving-Delay-Downstream" },
341 { 0x008E, "Actual-Interleaving-Delay-Downstream" },
342 { 0x008F, "DSL-Line-State" },
343 { 0x0090, "Access-Loop-Encapsulation" },
344 { 0x0091, "DSL-Type" },
345 { 0x0092, "Request-Source-IP" },
346 { 0x0093, "Request-Source-MAC" },
347 { 0x0094, "Report-Buffering-Time" },
348 { 0x0095, "Committed-Bandwidth" },
349 { 0x0096, "Request-Source-Device-Id" },
350 { 0x0106, "Status-Info" },
351 { 0x1000, "Target (single access line variant)" },
352 { 0, NULL }
354 static value_string_ext ext_tlv_types_ext = VALUE_STRING_EXT_INIT(ext_tlv_types);
356 static int
357 dissect_ancp_tlv(tvbuff_t *tvb, proto_tree *tlv_tree, int offset)
359 uint16_t tlen, ttype;
360 int16_t num_stlvs;
361 proto_item *tti;
363 proto_tree_add_item(tlv_tree, hf_ancp_ext_tlv_type, tvb, offset, 2, ENC_BIG_ENDIAN);
364 ttype = tvb_get_ntohs(tvb, offset);
365 offset += 2;
367 tti = proto_tree_add_item(tlv_tree, hf_ancp_ext_tlv_len, tvb, offset, 2, ENC_BIG_ENDIAN);
368 tlen = tvb_get_ntohs(tvb, offset);
369 offset += 2;
372 * Extension Block is common for event message and port
373 * management message, but the TLVs that can appear
374 * are different
376 switch (ttype) {
377 case TLV_DSL_LINE_ATTRIBUTES:
379 proto_tree *dsl_tree;
380 uint16_t stlvtype, stlvlen;
381 int val;
383 /* Create a DSL Attribute SubTree */
384 dsl_tree = proto_item_add_subtree(tti, ett_ancp_ext_tlv_type);
385 num_stlvs = tlen / 8; /* TODO - better way? */
386 for ( ;num_stlvs; num_stlvs--) {
387 proto_tree_add_item(dsl_tree,
388 hf_ancp_dsl_line_stlv_type, tvb, offset,
389 2, ENC_BIG_ENDIAN);
390 stlvtype = tvb_get_ntohs(tvb, offset);
391 offset += 2;
392 proto_tree_add_item(dsl_tree,
393 hf_ancp_dsl_line_stlv_len, tvb, offset,
394 2, ENC_BIG_ENDIAN);
395 stlvlen = tvb_get_ntohs(tvb, offset);
396 offset += 2; /* Sub TLV Length */
398 tti = proto_tree_add_item(dsl_tree,
399 hf_ancp_dsl_line_stlv_value, tvb, offset,
400 stlvlen, ENC_BIG_ENDIAN);
401 val = tvb_get_ntohl(tvb, offset);
403 switch (stlvtype) {
404 case TLV_DSL_LINE_STATE:
405 proto_item_append_text(tti, " (%s)",
406 val_to_str(val, dsl_line_state_names,
407 "Unknown (0x%02x)"));
408 break;
409 case TLV_DSL_TYPE:
410 proto_item_append_text(tti, " (%s)",
411 val_to_str(val, dsl_line_type_names,
412 "Unknown (0x%02x)"));
413 break;
415 default:
416 /* Add Unit */
417 proto_item_append_text(tti, " %s",
418 val_to_str(stlvtype,
419 dsl_line_attr_units,
420 "Unknown (0x%02x)"));
421 break;
423 offset += WS_ROUNDUP_4(stlvlen); /* Except loop-encap, rest are 4B */
425 break;
427 case TLV_PING_OPAQUE_DATA:
428 /* 2 32b values*/
429 proto_tree_add_item(tlv_tree, hf_ancp_oam_opaque,
430 tvb, offset, 4, ENC_BIG_ENDIAN);
431 offset += 4;
432 proto_tree_add_item(tlv_tree, hf_ancp_oam_opaque,
433 tvb, offset, 4, ENC_BIG_ENDIAN);
434 offset += 4;
435 break;
436 case TLV_PING_PARAMS:
437 /* Count (1B) Timeout (1B), 2B empty */
438 proto_tree_add_item(tlv_tree,
439 hf_ancp_oam_loopb_cnt, tvb, offset, 1, ENC_BIG_ENDIAN);
440 offset += 1;
441 proto_tree_add_item(tlv_tree,
442 hf_ancp_oam_timeout, tvb, offset, 1, ENC_BIG_ENDIAN);
443 offset += 1;
444 /* Lets not bother about 2B until IETF WG figures out */
445 offset += 2;
446 break;
447 default:
448 /* Assume TLV value is string - covers ALCID, OAM resp */
449 proto_tree_add_item(tlv_tree, hf_ancp_ext_tlv_value_str,
450 tvb, offset, tlen, ENC_ASCII);
451 offset += WS_ROUNDUP_4(tlen);
452 break;
453 } /* end switch {ttype} */
454 return offset;
457 static void
458 dissect_ancp_port_up_dn_mgmt(tvbuff_t *tvb, proto_tree *ancp_tree, int offset, uint8_t mtype)
460 uint8_t tech_type;
461 int16_t num_tlvs;
462 proto_item *sti;
464 if (mtype == ANCP_MTYPE_PORT_MGMT) {
465 proto_tree_add_item(ancp_tree, hf_ancp_pudm_unused, tvb, offset, 14, ENC_NA);
466 offset += 14;
468 proto_tree_add_item(ancp_tree, hf_ancp_function, tvb, offset, 1, ENC_BIG_ENDIAN);
469 offset += 1;
471 proto_tree_add_item(ancp_tree, hf_ancp_x_function, tvb, offset, 1, ENC_BIG_ENDIAN);
472 offset += 1;
474 proto_tree_add_item(ancp_tree, hf_ancp_pudm_unused, tvb, offset, 4, ENC_NA);
475 offset += 4;
476 } else {
477 proto_tree_add_item(ancp_tree, hf_ancp_pudm_unused, tvb, offset, 20, ENC_NA);
478 offset += 20;
481 proto_tree_add_item(ancp_tree, hf_ancp_ext_flags_res, tvb, offset, 1, ENC_NA);
482 offset += 1;
484 proto_tree_add_item(ancp_tree, hf_ancp_mtype, tvb, offset, 1, ENC_BIG_ENDIAN);
485 offset += 1;
487 if (mtype == ANCP_MTYPE_PORT_MGMT) {
488 proto_tree_add_item(ancp_tree, hf_ancp_reserved, tvb, offset, 2, ENC_NA);
489 offset += 2;
490 tech_type = 0;
491 } else {
492 proto_tree_add_item(ancp_tree, hf_ancp_tech_type, tvb, offset, 1, ENC_BIG_ENDIAN);
493 tech_type = tvb_get_uint8(tvb, offset);
494 offset += 1;
496 proto_tree_add_item(ancp_tree, hf_ancp_reserved, tvb, offset, 1, ENC_NA);
497 offset += 1;
500 proto_tree_add_item(ancp_tree, hf_ancp_num_ext_tlvs, tvb, offset, 2, ENC_BIG_ENDIAN);
501 num_tlvs = tvb_get_ntohs(tvb, offset);
502 offset += 2;
504 sti = proto_tree_add_item(ancp_tree, hf_ancp_blk_len, tvb, offset, 2, ENC_BIG_ENDIAN);
505 offset += 2;
507 if (tech_type == TECH_TYPE_DSL || tech_type == TECH_TYPE_PON) {
508 proto_tree *tlv_tree;
510 /* Create a TLV sub tree */
511 tlv_tree = proto_item_add_subtree(sti, ett_ancp_len);
513 for( ;num_tlvs; num_tlvs--) {
514 offset = dissect_ancp_tlv(tvb, tlv_tree, offset);
515 } /* end for {numtlvs} */
516 } /* end if {DSL} */
519 static void
520 dissect_ancp_adj_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ancp_tree,
521 int offset, struct ancp_tap_t *ancp_info
524 proto_item *sti;
525 proto_tree *ancp_cap_tree;
526 uint8_t byte, numcaps, adjcode;
527 uint16_t tlv_len;
529 sti = proto_tree_add_item(ancp_tree, hf_ancp_timer, tvb, offset, 1,
530 ENC_BIG_ENDIAN);
531 offset += 1;
532 proto_item_append_text(sti, " msec");
534 sti = proto_tree_add_item(ancp_tree, hf_ancp_adj_code, tvb, offset, 1,
535 ENC_BIG_ENDIAN);
536 byte = tvb_get_uint8(tvb, offset);
537 offset += 1;
538 adjcode = byte & ADJ_CODE_MASK;
539 ancp_info->ancp_adjcode = adjcode; /* stats */
540 proto_item_append_text(sti, " (%s, M Flag %s)",
541 val_to_str(adjcode, adj_code_names, "Unknown (0x%02x)"),
542 (byte >> 7) ? "Set" : "Unset");
543 col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)",
544 val_to_str(adjcode, adj_code_names, "Unknown (0x%02x)"));
546 proto_tree_add_item(ancp_tree, hf_ancp_sender_name, tvb, offset, 6, ENC_NA);
547 offset += 6;
549 proto_tree_add_item(ancp_tree, hf_ancp_receiver_name, tvb,offset, 6, ENC_NA);
550 offset += 6;
552 proto_tree_add_item(ancp_tree, hf_ancp_sender_port, tvb, offset, 4, ENC_BIG_ENDIAN);
553 offset += 4;
555 proto_tree_add_item(ancp_tree, hf_ancp_receiver_port, tvb,offset, 4, ENC_BIG_ENDIAN);
556 offset += 4;
558 sti = proto_tree_add_item(ancp_tree, hf_ancp_p_info, tvb,
559 offset, 1, ENC_BIG_ENDIAN);
560 byte = tvb_get_uint8(tvb, offset);
561 offset += 1;
562 proto_item_append_text(sti, " (Type = %d, Flag = %d)",
563 byte >> 4, byte & 0x0F);
565 proto_tree_add_item(ancp_tree, hf_ancp_sender_instance, tvb, offset, 3, ENC_BIG_ENDIAN);
566 offset += 3;
568 proto_tree_add_item(ancp_tree, hf_ancp_p_id, tvb, offset, 1, ENC_BIG_ENDIAN);
569 offset += 1;
571 proto_tree_add_item(ancp_tree, hf_ancp_receiver_instance, tvb, offset, 3, ENC_BIG_ENDIAN);
572 offset += 3;
574 proto_tree_add_item(ancp_tree, hf_ancp_reserved, tvb, offset, 1, ENC_NA);
575 offset += 1;
577 sti = proto_tree_add_item(ancp_tree, hf_ancp_num_tlvs, tvb, offset, 1, ENC_BIG_ENDIAN);
578 numcaps = tvb_get_uint8(tvb, offset);
579 offset += 1;
581 /* Start the capability subtree */
582 ancp_cap_tree = proto_item_add_subtree(sti, ett_ancp_tot_len);
584 proto_tree_add_item(ancp_cap_tree, hf_ancp_tot_len, tvb, offset, 2, ENC_BIG_ENDIAN);
585 offset += 2;
587 for ( ;numcaps; numcaps--) {
588 sti = proto_tree_add_item(ancp_cap_tree, hf_ancp_cap, tvb, offset, 2, ENC_BIG_ENDIAN);
589 offset += 2;
591 tlv_len = tvb_get_ntohs(tvb, offset);
592 offset += 2;
593 proto_item_append_text(sti, " (%d bytes)", tlv_len);
594 /* TODO - if there are non boolean caps, validate before use */
598 static void
599 ancp_stats_tree_init(stats_tree *st)
601 st_node_packets = stats_tree_create_node(st, st_str_packets, 0, STAT_DT_INT, true);
602 st_node_packet_types = stats_tree_create_pivot(st, st_str_packet_types,
603 st_node_packets);
604 st_node_adj_pack_types = stats_tree_create_node(st, st_str_adj_pack_types,
605 st_node_packets, STAT_DT_INT, true);
608 static tap_packet_status
609 ancp_stats_tree_packet(stats_tree* st, packet_info* pinfo _U_,
610 epan_dissect_t* edt _U_ , const void* p, tap_flags_t flags _U_)
612 const struct ancp_tap_t *pi = (const struct ancp_tap_t *) p;
614 tick_stat_node(st, st_str_packets, 0, false);
615 stats_tree_tick_pivot(st, st_node_packet_types,
616 val_to_str(pi->ancp_mtype, mtype_names,
617 "Unknown packet type (%d)"));
618 if (pi->ancp_mtype == ANCP_MTYPE_ADJ)
619 stats_tree_tick_pivot(st, st_node_adj_pack_types,
620 val_to_str(pi->ancp_adjcode, adj_code_names,
621 "Unknown Adjacency packet (%d)"));
622 return TAP_PACKET_REDRAW;
625 static int
626 dissect_ancp_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
628 int offset;
629 uint8_t mtype;
630 struct ancp_tap_t *ancp_info;
631 proto_item *ti;
632 proto_item *sti;
633 proto_item *tti = NULL;
634 proto_tree *ancp_tree;
635 proto_tree *tlv_tree;
636 uint8_t byte;
637 uint16_t len;
639 offset = 0;
640 if (tvb_get_ntohs(tvb, offset) != ANCP_GSMP_ETHER_TYPE)
641 return 0; /* XXX: this dissector is not a heuristic dissector */
642 /* Should do "expert" & dissect rest as "data" */
643 /* (after setting COL_PROTOCOL & etc) ? */
645 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ANCP");
646 col_clear(pinfo->cinfo, COL_INFO);
648 ancp_info = wmem_new(pinfo->pool, struct ancp_tap_t);
649 ancp_info->ancp_mtype = 0;
650 ancp_info->ancp_adjcode = 0;
652 ti = proto_tree_add_item(tree, proto_ancp, tvb, 0, -1, ENC_NA);
654 ancp_tree = proto_item_add_subtree(ti, ett_ancp_len);
656 offset = 2; /* skip ether type */
658 proto_tree_add_item(ancp_tree, hf_ancp_len, tvb, offset, 2, ENC_BIG_ENDIAN);
659 len = tvb_get_ntohs(tvb, offset);
660 offset += 2;
662 sti = proto_tree_add_item(ancp_tree, hf_ancp_ver, tvb, offset, 1, ENC_BIG_ENDIAN);
663 byte = tvb_get_uint8(tvb, offset);
664 offset += 1;
665 proto_item_append_text(sti, " (%d.%d)", byte >> 4, byte & 0x0F);
667 sti = proto_tree_add_item(ancp_tree, hf_ancp_mtype, tvb, offset, 1, ENC_BIG_ENDIAN);
668 mtype = tvb_get_uint8(tvb, offset); /* ANCP message type */
669 ancp_info->ancp_mtype = mtype; /* stats */
670 offset += 1;
672 col_add_fstr(pinfo->cinfo, COL_INFO, "%s Message",
673 val_to_str(mtype, mtype_names, "Unknown (0x%02x)"));
675 if (mtype != ANCP_MTYPE_ADJ) {
676 /* Dissect common header */
677 proto_tree_add_item(ancp_tree, hf_ancp_result, tvb, offset, 1,
678 ENC_BIG_ENDIAN); /* treat as 1B, but don't change offset */
680 proto_tree_add_item(ancp_tree, hf_ancp_code, tvb, offset, 2,
681 ENC_BIG_ENDIAN);
682 offset += 2;
684 proto_tree_add_item(ancp_tree, hf_ancp_p_id, tvb, offset,
685 1, ENC_BIG_ENDIAN);
686 offset += 1;
688 proto_tree_add_item(ancp_tree, hf_ancp_trans_id, tvb,
689 offset, 3, ENC_BIG_ENDIAN);
690 offset += 3;
692 proto_tree_add_item(ancp_tree, hf_ancp_i_flag, tvb, offset, 1,
693 ENC_BIG_ENDIAN); /* treat as 1B, but don't change offset */
695 proto_tree_add_item(ancp_tree, hf_ancp_submsg_num, tvb,
696 offset, 2, ENC_BIG_ENDIAN);
697 offset += 2;
699 tti = proto_tree_add_item(ancp_tree, hf_ancp_len2, tvb, offset,
700 2, ENC_BIG_ENDIAN);
701 offset += 2; /* Length */
704 switch(mtype) {
705 case ANCP_MTYPE_ADJ:
706 dissect_ancp_adj_msg(tvb, pinfo, ancp_tree, offset, ancp_info);
707 break;
708 case ANCP_MTYPE_PORT_DN:
709 /* FALL THRU */
710 case ANCP_MTYPE_PORT_MGMT:
711 /* FALL THRU */
712 case ANCP_MTYPE_PORT_UP:
713 dissect_ancp_port_up_dn_mgmt(tvb, ancp_tree, offset, mtype);
714 break;
715 case ANCP_MTYPE_PROV:
716 /* FALL THRU */
717 case ANCP_MTYPE_GEN_RSP:
718 tlv_tree = proto_item_add_subtree(tti, ett_ancp_len);
720 while( offset < len + 4) {
721 offset = dissect_ancp_tlv(tvb, tlv_tree, offset);
723 break;
724 case ANCP_MTYPE_ADJ_UPD:
725 break;
726 default:
727 proto_item_append_text(sti, " (Unknown Message %d)", mtype);
728 break;
730 tap_queue_packet(ancp_tap, pinfo, ancp_info);
732 return tvb_reported_length(tvb);
735 static unsigned
736 get_ancp_msg_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
738 return (unsigned)tvb_get_ntohs(tvb, offset + 2) + 4; /* 2B len + 4B hdr */
741 static int
742 dissect_ancp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
744 tcp_dissect_pdus(tvb, pinfo, tree, true, ANCP_MIN_HDR,
745 get_ancp_msg_len, dissect_ancp_message, data);
747 return tvb_reported_length(tvb);
750 void
751 proto_register_ancp(void)
753 static hf_register_info hf[] = {
754 { &hf_ancp_len,
755 { "Length", "ancp.len",
756 FT_UINT16, BASE_DEC,
757 NULL, 0x0,
758 NULL, HFILL }
760 { &hf_ancp_len2,
761 { "Length", "ancp.len2",
762 FT_UINT16, BASE_DEC,
763 NULL, 0x0,
764 NULL, HFILL }
766 { &hf_ancp_ver,
767 { "Version", "ancp.ver",
768 FT_UINT8, BASE_HEX,
769 NULL, 0x0,
770 NULL, HFILL }
772 { &hf_ancp_mtype,
773 { "Message Type", "ancp.mtype",
774 FT_UINT8, BASE_DEC,
775 VALS(mtype_names), 0x0,
776 NULL, HFILL }
778 { &hf_ancp_timer,
779 { "Timer", "ancp.timer",
780 FT_UINT8, BASE_DEC|BASE_UNIT_STRING,
781 UNS(&units_milliseconds), 0x0,
782 NULL, HFILL }
784 { &hf_ancp_adj_code,
785 { "Code", "ancp.adjcode", /* this is diff from code */
786 FT_UINT8, BASE_DEC, /* for Adjacency msg only */
787 NULL, ADJ_CODE_MASK,
788 NULL, HFILL }
790 { &hf_ancp_sender_name,
791 { "Sender Name", "ancp.sender_name",
792 FT_ETHER, BASE_NONE,
793 NULL, 0x0,
794 NULL, HFILL }
796 { &hf_ancp_receiver_name,
797 { "Receiver Name", "ancp.receiver_name",
798 FT_ETHER, BASE_NONE,
799 NULL, 0x0,
800 NULL, HFILL }
802 { &hf_ancp_sender_port,
803 { "Sender Port", "ancp.sender_port",
804 FT_UINT64, BASE_DEC,
805 NULL, 0x0,
806 NULL, HFILL }
808 { &hf_ancp_receiver_port,
809 { "Receiver Port", "ancp.receiver_port",
810 FT_UINT64, BASE_DEC,
811 NULL, 0x0,
812 NULL, HFILL }
814 { &hf_ancp_p_info,
815 { "Partition Info", "ancp.partition_info",
816 FT_UINT8, BASE_HEX,
817 NULL, 0x0,
818 NULL, HFILL }
820 { &hf_ancp_sender_instance,
821 { "Sender Instance", "ancp.sender_instance",
822 FT_UINT24, BASE_DEC,
823 NULL, 0x0,
824 NULL, HFILL }
826 { &hf_ancp_p_id,
827 { "Partition ID", "ancp.partition_id",
828 FT_UINT8, BASE_DEC,
829 NULL, 0x0,
830 NULL, HFILL }
832 { &hf_ancp_receiver_instance,
833 { "Receiver Instance", "ancp.receiver_instance",
834 FT_UINT24, BASE_DEC,
835 NULL, 0x0,
836 NULL, HFILL }
838 { &hf_ancp_tech_type,
839 { "Tech Type", "ancp.tech_type",
840 FT_UINT8, BASE_DEC,
841 VALS(techtype_str), 0x0,
842 NULL, HFILL }
844 { &hf_ancp_num_tlvs,
845 { "Num TLVs", "ancp.num_tlvs",
846 FT_UINT8, BASE_DEC,
847 NULL, 0x0,
848 NULL, HFILL }
850 { &hf_ancp_tot_len,
851 { "Length", "ancp.tot_len", /* name just Len to reuse*/
852 FT_UINT16, BASE_DEC,
853 NULL, 0x0,
854 NULL, HFILL }
856 { &hf_ancp_cap,
857 { "Capability", "ancp.capability",
858 FT_UINT16, BASE_DEC,
859 VALS(captype_names), 0x0,
860 NULL, HFILL }
862 { &hf_ancp_result,
863 { "Result", "ancp.result",
864 FT_UINT8, BASE_DEC,
865 VALS(resulttype_names), ANCP_RESULT_MASK,
866 NULL, HFILL }
868 { &hf_ancp_code,
869 { "Code", "ancp.code",
870 FT_UINT16, BASE_HEX,
871 VALS(codetype_names), ANCP_CODE_MASK,
872 NULL, HFILL }
874 { &hf_ancp_trans_id,
875 { "Transaction ID", "ancp.transaction_id",
876 FT_UINT24, BASE_DEC,
877 NULL, 0x0,
878 NULL, HFILL }
880 { &hf_ancp_i_flag,
881 { "I Flag", "ancp.i_flag",
882 FT_BOOLEAN, 8,
883 TFS(&tfs_set_notset), ANCP_I_FLAG_MASK,
884 NULL, HFILL }
886 { &hf_ancp_submsg_num,
887 { "SubMessage Number", "ancp.submessage_number",
888 FT_UINT16, BASE_DEC,
889 NULL, ANCP_SUBMSG_MASK,
890 NULL, HFILL }
892 { &hf_ancp_pudm_unused,
893 { "Unused Bytes", "ancp.unused",
894 FT_BYTES, BASE_NONE,
895 NULL, 0x0,
896 NULL, HFILL }
898 { &hf_ancp_function,
899 { "Function", "ancp.function",
900 FT_UINT8, BASE_DEC,
901 VALS(function_names), 0x0,
902 NULL, HFILL }
904 { &hf_ancp_x_function,
905 { "X-Function", "ancp.x_function",
906 FT_UINT8, BASE_DEC,
907 NULL, 0x0,
908 NULL, HFILL }
910 { &hf_ancp_ext_flags_res,
911 { "Extension Flags Reserved", "ancp.ext_flags",
912 FT_BYTES, BASE_NONE,
913 NULL, 0x0,
914 NULL, HFILL }
916 { &hf_ancp_reserved,
917 { "Reserved", "ancp.reserved",
918 FT_BYTES, BASE_NONE,
919 NULL, 0x0,
920 NULL, HFILL }
922 { &hf_ancp_blk_len,
923 { "Block Length", "ancp.blk_len",
924 FT_UINT16, BASE_DEC,
925 NULL, 0x0,
926 NULL, HFILL }
928 { &hf_ancp_num_ext_tlvs,
929 { "Num TLVs", "ancp.ext_tlvs.count",
930 FT_UINT16, BASE_DEC,
931 NULL, 0x0,
932 NULL, HFILL }
934 { &hf_ancp_ext_tlv_type,
935 { "TLV Type", "ancp.ext_tlv.type",
936 FT_UINT16, BASE_DEC|BASE_EXT_STRING,
937 &ext_tlv_types_ext, 0x0,
938 NULL, HFILL }
940 { &hf_ancp_ext_tlv_len,
941 { "TLV Length", "ancp.ext_tlv.len",
942 FT_UINT16, BASE_DEC,
943 NULL, 0x0,
944 NULL, HFILL }
946 { &hf_ancp_dsl_line_stlv_type,
947 { "Sub-TLV", "ancp.sub_tlv_type",
948 FT_UINT16, BASE_HEX,
949 VALS(dsl_line_attrs), 0x0,
950 NULL, HFILL }
952 { &hf_ancp_dsl_line_stlv_len,
953 { "Sub-TLV Length", "ancp.sub_tlv_len",
954 FT_UINT16, BASE_DEC,
955 NULL, 0x0,
956 NULL, HFILL }
958 { &hf_ancp_dsl_line_stlv_value,
959 { "Value", "ancp.dsl_line_param",
960 FT_UINT32, BASE_DEC,
961 NULL, 0x0,
962 NULL, HFILL }
964 { &hf_ancp_ext_tlv_value_str,
965 { "Value", "ancp.ext_tlv.value",
966 FT_STRING, BASE_NONE,
967 NULL, 0x0,
968 NULL, HFILL }
970 { &hf_ancp_oam_opaque,
971 { "Opaque", "ancp.oam.opaque", /* There will be 2 such 32b vals */
972 FT_UINT32, BASE_DEC,
973 NULL, 0x0,
974 NULL, HFILL }
976 { &hf_ancp_oam_loopb_cnt,
977 { "OAM Loopback Count", "ancp.oam.loopback_count",
978 FT_UINT8, BASE_DEC,
979 NULL, 0x0,
980 NULL, HFILL }
982 { &hf_ancp_oam_timeout,
983 { "OAM Timeout", "ancp.oam.timeout",
984 FT_UINT8, BASE_DEC,
985 NULL, 0x0,
986 NULL, HFILL }
990 /* Setup protocol subtree array */
991 static int *ett[] = {
992 &ett_ancp_len,
993 &ett_ancp_ver,
994 &ett_ancp_mtype,
995 &ett_ancp_timer,
996 &ett_ancp_adj_code,
997 &ett_ancp_sender_name,
998 &ett_ancp_receiver_name,
999 &ett_ancp_sender_port,
1000 &ett_ancp_receiver_port,
1001 &ett_ancp_p_info,
1002 &ett_ancp_sender_instance,
1003 &ett_ancp_p_id,
1004 &ett_ancp_receiver_instance,
1005 &ett_ancp_tech_type,
1006 &ett_ancp_num_tlvs,
1007 &ett_ancp_tot_len,
1008 &ett_ancp_cap,
1009 &ett_ancp_result,
1010 &ett_ancp_code,
1011 &ett_ancp_trans_id,
1012 &ett_ancp_i_flag,
1013 &ett_ancp_submsg_num,
1014 &ett_ancp_port,
1015 &ett_ancp_port_sess_num,
1016 &ett_ancp_evt_seq_num,
1017 &ett_ancp_label,
1018 &ett_ancp_reserved,
1019 &ett_ancp_blk_len,
1020 &ett_ancp_num_ext_tlvs,
1021 &ett_ancp_ext_tlv_type,
1022 &ett_ancp_dsl_line_stlv_type,
1023 &ett_ancp_dsl_line_stlv_val,
1024 &ett_ancp_ext_tlv_value_str,
1025 &ett_ancp_oam_opaque,
1026 &ett_ancp_oam_loopb_cnt,
1027 &ett_ancp_oam_timeout,
1030 proto_ancp = proto_register_protocol (
1031 "Access Node Control Protocol",
1032 "ANCP",
1033 "ancp"
1036 proto_register_field_array(proto_ancp, hf, array_length(hf));
1037 proto_register_subtree_array(ett, array_length(ett));
1038 ancp_tap = register_tap("ancp");
1040 ancp_handle = register_dissector("ancp", dissect_ancp, proto_ancp);
1043 void
1044 proto_reg_handoff_ancp(void)
1046 dissector_add_uint_with_preference("tcp.port", ANCP_PORT, ancp_handle);
1047 stats_tree_register("ancp", "ancp", "ANCP", 0,
1048 ancp_stats_tree_packet, ancp_stats_tree_init, NULL);
1052 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1054 * Local variables:
1055 * c-basic-offset: 4
1056 * tab-width: 8
1057 * indent-tabs-mode: nil
1058 * End:
1060 * vi: set shiftwidth=4 tabstop=8 expandtab:
1061 * :indentSize=4:tabSize=8:noTabs=true: