HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-ancp.c
blob4240dad51b402bb7b829f9e9c1a8098ca6b3f93a
1 /* packet-ancp.c
3 * Dissector for ANCP - Access Node Control Protocol
5 * More info on the protocol can be found on IETF:
6 * http://tools.ietf.org/wg/ancp/
7 * http://tools.ietf.org/html/draft-ietf-ancp-protocol-09
9 * Copyright 2010, Aniruddha.A (anira@cisco.com)
11 * $Id$
13 * Wireshark - Network traffic analyzer
14 * By Gerald Combs <gerald@wireshark.org>
15 * Copyright 1998 Gerald Combs
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include "config.h"
34 #include <epan/packet.h>
35 #include <epan/wmem/wmem.h>
36 #include <epan/dissectors/packet-tcp.h>
37 #include <epan/tap.h>
38 #include <epan/stats_tree.h>
40 #define ANCP_PORT 6068 /* The ANCP TCP port:draft-ietf-ancp-protocol-09.txt */
42 #define ANCP_MIN_HDR 4
43 #define ANCP_GSMP_ETHER_TYPE 0x880C
44 #define TECH_TYPE_DSL 0x5
46 #define ANCP_RESULT_MASK 0xF0
47 #define ANCP_CODE_MASK 0x0FFF
48 #define ANCP_I_FLAG_MASK 0x80
49 #define ANCP_SUBMSG_MASK 0x7FFF
50 #define ADJ_CODE_MASK 0x7F /* excluding MSB M-Flag */
52 #define ANCP_MTYPE_ADJ 10
53 #define ANCP_MTYPE_PORT_MGMT 32
54 #define ANCP_MTYPE_PORT_UP 80
55 #define ANCP_MTYPE_PORT_DN 81
57 /* Topology Discovery Extensions */
58 #define TLV_DSL_LINE_ATTRIBUTES 0x04
59 #define TLV_DSL_LINE_STATE 0x8F
60 #define TLV_DSL_TYPE 0x91
62 /* Port Management Extensions */
63 #define TLV_PING_PARAMS 0x07
64 #define TLV_PING_OPAQUE_DATA 0x08
65 #define TLV_PING_RES_STR 0x09
67 #define SKIPPADDING(_ofst, _len) \
68 do { \
69 if ((_len) % 4) \
70 _ofst += (4 - ((_len) % 4)); \
71 } while(0)
73 void proto_register_ancp(void);
74 void proto_reg_handoff_ancp(void);
76 static int hf_ancp_len = -1;
77 static int hf_ancp_ver = -1;
78 static int hf_ancp_mtype = -1;
79 static int hf_ancp_timer = -1;
80 static int hf_ancp_adj_code = -1;
81 static int hf_ancp_sender_name = -1;
82 static int hf_ancp_receiver_name = -1;
83 static int hf_ancp_sender_port = -1;
84 static int hf_ancp_receiver_port = -1;
85 static int hf_ancp_p_info = -1;
86 static int hf_ancp_sender_instance = -1;
87 static int hf_ancp_p_id = -1;
88 static int hf_ancp_receiver_instance = -1;
89 static int hf_ancp_tech_type = -1;
90 static int hf_ancp_num_tlvs = -1;
91 static int hf_ancp_tot_len = -1;
92 static int hf_ancp_cap = -1;
93 static int hf_ancp_result = -1;
94 static int hf_ancp_code = -1;
95 static int hf_ancp_trans_id = -1;
96 static int hf_ancp_i_flag = -1;
97 static int hf_ancp_submsg_num = -1;
98 static int hf_ancp_port = -1;
99 static int hf_ancp_port_sess_num = -1;
100 static int hf_ancp_evt_seq_num = -1;
101 static int hf_ancp_label = -1;
102 static int hf_ancp_reserved = -1;
103 static int hf_ancp_blk_len = -1;
104 static int hf_ancp_num_ext_tlvs = -1;
105 static int hf_ancp_ext_tlv_type = -1;
106 static int hf_ancp_dsl_line_stlv_type = -1;
107 static int hf_ancp_dsl_line_stlv_value = -1;
108 static int hf_ancp_ext_tlv_value_str = -1;
109 static int hf_ancp_oam_opaque = -1;
110 static int hf_ancp_oam_loopb_cnt = -1;
111 static int hf_ancp_oam_timeout = -1;
113 static gint ett_ancp_len = -1;
114 static gint ett_ancp_ver = -1;
115 static gint ett_ancp_mtype = -1;
116 static gint ett_ancp_timer = -1;
117 static gint ett_ancp_adj_code = -1;
118 static gint ett_ancp_sender_name = -1;
119 static gint ett_ancp_receiver_name = -1;
120 static gint ett_ancp_sender_port = -1;
121 static gint ett_ancp_receiver_port = -1;
122 static gint ett_ancp_p_info = -1;
123 static gint ett_ancp_sender_instance = -1;
124 static gint ett_ancp_p_id = -1;
125 static gint ett_ancp_receiver_instance = -1;
126 static gint ett_ancp_tech_type = -1;
127 static gint ett_ancp_num_tlvs = -1;
128 static gint ett_ancp_tot_len = -1;
129 static gint ett_ancp_cap = -1;
130 static gint ett_ancp_result = -1;
131 static gint ett_ancp_code = -1;
132 static gint ett_ancp_trans_id = -1;
133 static gint ett_ancp_i_flag = -1;
134 static gint ett_ancp_submsg_num = -1;
135 static gint ett_ancp_port = -1;
136 static gint ett_ancp_port_sess_num= -1;
137 static gint ett_ancp_evt_seq_num = -1;
138 static gint ett_ancp_label = -1;
139 static gint ett_ancp_reserved = -1;
140 static gint ett_ancp_blk_len = -1;
141 static gint ett_ancp_num_ext_tlvs = -1;
142 static gint ett_ancp_ext_tlv_type = -1;
143 static gint ett_ancp_dsl_line_stlv_type = -1;
144 static gint ett_ancp_dsl_line_stlv_val = -1;
145 static gint ett_ancp_ext_tlv_value_str = -1;
146 static gint ett_ancp_oam_opaque = -1;
147 static gint ett_ancp_oam_loopb_cnt = -1;
148 static gint ett_ancp_oam_timeout = -1;
150 static int proto_ancp = -1;
152 /* ANCP stats - Tap interface */
153 static const guint8 *st_str_packets = "Total Packets";
154 static const guint8 *st_str_packet_types = "ANCP Packet Types";
155 static const guint8 *st_str_adj_pack_types = "ANCP Adjacency Packet Types";
157 static int st_node_packets = -1;
158 static int st_node_packet_types = -1;
159 static int st_node_adj_pack_types = -1;
160 static int ancp_tap = -1;
162 struct ancp_tap_t {
163 gint ancp_mtype;
164 gint ancp_adjcode; /* valid for ancp adjacency message only */
167 /* Value Strings */
168 static const value_string mtype_names[] = {
169 { 10, "Adjacency" },
170 { 32, "Port-Management" },
171 { 80, "Port-Up" },
172 { 81, "Port-Down" },
173 { 0, NULL }
176 static const value_string adj_code_names[] = {
177 { 1, "Syn" },
178 { 2, "SynAck" },
179 { 3, "Ack" },
180 { 4, "Rstack" },
181 { 0, NULL }
184 static const value_string captype_names[] = {
185 { 1, "Dynamic-Topology-Discovery" },
186 { 2, "Line-Configuration" },
187 { 3, "Transactional-Multicast" },
188 { 4, "OAM" },
189 { 0, NULL }
192 static const value_string resulttype_names[] = {
193 { 0, "Ignore" },
194 { 1, "NAck" },
195 { 2, "AckAll" },
196 { 3, "Success" },
197 { 4, "Failure" },
198 { 0, NULL }
201 static const value_string codetype_names[] = { /* For now, these are OAM codes*/
202 { 0x500, "Access-line-doesn't-exist" },
203 { 0x501, "Loopback-Test-Timeout" },
204 { 0x502, "Reserved" },
205 { 0x503, "DSL-line-status-showtime" },
206 { 0x504, "DSL-line-status-idle" },
207 { 0x505, "DSL-line-status-silent" },
208 { 0x506, "DSL-line-status-training" },
209 { 0x507, "DSL-line-integrity-error" },
210 { 0x508, "DSLAM resource-unavailable" },
211 { 0x509, "Invalid Test Parameter" },
212 { 0, NULL }
215 static const value_string techtype_str[] = {
216 { 0x01, "PON" },
217 { 0x05, "DSL" },
218 { 0, NULL }
221 static const value_string dsl_line_attrs[] = {
222 { 0x91, "DSL-Type" },
223 { 0x81, "Actual-Net-Data-Rate-Upstream" },
224 { 0x82, "Actual-Net-Data-Rate-Downstream" },
225 { 0x83, "Minimum-Net-Data-Rate-Upstream" },
226 { 0x84, "Minimum-Net-Data-Rate-Downstream" },
227 { 0x85, "Attainable-Net-Data-Rate-Upstream" },
228 { 0x86, "Attainable-Net-Data-Rate-Downstream" },
229 { 0x87, "Maximum-Net-Data-Rate-Upstream" },
230 { 0x88, "Maximum-Net-Data-Rate-Downstream" },
231 { 0x89, "Minimum-Net-Low-Power-Data-Rate-Upstream" },
232 { 0x8A, "Minimum-Net-Low-Power-Data-Rate-Downstream" },
233 { 0x8B, "Maximum-Interleaving-Delay-Upstream" },
234 { 0x8C, "Actual-Interleaving-Delay-Upstream" },
235 { 0x8D, "Maximum-Interleaving-Delay-Downstream" },
236 { 0x8E, "Actual-Interleaving-Delay-Downstream" },
237 { 0x8F, "DSL line state" },
238 { 0x90, "Access Loop Encapsulation" },
239 { 0, NULL }
242 static const value_string dsl_line_attr_units[] = {
243 { 0x91, "" },
244 { 0x81, "Kb/sec" },
245 { 0x82, "Kb/sec" },
246 { 0x83, "Kb/sec" },
247 { 0x84, "Kb/sec" },
248 { 0x85, "Kb/sec" },
249 { 0x86, "Kb/sec" },
250 { 0x87, "Kb/sec" },
251 { 0x88, "Kb/sec" },
252 { 0x89, "Kb/sec" },
253 { 0x8A, "Kb/sec" },
254 { 0x8B, "msec" },
255 { 0x8C, "msec" },
256 { 0x8D, "msec" },
257 { 0x8E, "msec" },
258 { 0x8F, "" },
259 { 0x90, "" },
260 { 0, NULL }
263 static const value_string dsl_line_type_names[] = {
264 { 1, "ADSL1" },
265 { 2, "ADSL2" },
266 { 3, "ADSL2+" },
267 { 4, "VDSL1" },
268 { 5, "VDSL2" },
269 { 6, "SDSL" },
270 { 0, NULL }
273 static const value_string dsl_line_state_names[] = {
274 { 1, "Showtime" },
275 { 2, "Idle" },
276 { 3, "Silent" },
277 { 0, NULL }
280 static const value_string ext_tlv_types[] = {
281 { 0x01, "Access-Loop-Circuit-ID" },
282 { 0x02, "Access-Loop-Remote-ID" },
283 { 0x03, "Access-Aggregation-Circuit-ID-ASCII" },
284 { 0x04, "DSL Line Attributes" },
285 { 0x06, "Access-Aggregation-Circuit-ID-Binary" },
286 { 0x07, "OAM-Loopback-Test-Parameters" },
287 { 0x08, "Opaque-Data" },
288 { 0x09, "OAM-Loopback-Test-Response-String" },
289 { 0, NULL }
292 static void
293 dissect_ancp_port_up_dn_mgmt(tvbuff_t *tvb, proto_tree *ancp_tree, gint offset)
295 guint8 tech_type;
297 proto_tree_add_item(ancp_tree, hf_ancp_port, tvb, offset, 4, ENC_BIG_ENDIAN);
298 offset += 4;
300 proto_tree_add_item(ancp_tree, hf_ancp_port_sess_num, tvb, offset, 4, ENC_BIG_ENDIAN);
301 offset += 4;
303 proto_tree_add_item(ancp_tree, hf_ancp_evt_seq_num, tvb, offset, 4, ENC_BIG_ENDIAN);
304 offset += 4;
306 proto_tree_add_item(ancp_tree, hf_ancp_label, tvb, offset, 8, ENC_BIG_ENDIAN);
307 offset += 8;
309 /* Start of the Extension Block */
310 proto_tree_add_item(ancp_tree, hf_ancp_reserved, tvb, offset, 1, ENC_BIG_ENDIAN);
311 offset += 1;
313 * We have already displayed the message type in the common header dissect
314 * so need not display this again here - skip it
316 offset += 1; /* Message type in Ext Blk */
318 proto_tree_add_item(ancp_tree, hf_ancp_tech_type, tvb, offset, 1, ENC_BIG_ENDIAN);
319 tech_type = tvb_get_guint8(tvb, offset);
320 offset += 1;
322 proto_tree_add_item(ancp_tree, hf_ancp_blk_len, tvb, offset, 1, ENC_BIG_ENDIAN);
323 offset += 1;
325 if (tech_type == TECH_TYPE_DSL) {
326 proto_item *sti;
327 proto_tree *tlv_tree;
328 guint16 tlen, ttype;
329 gint16 num_tlvs, num_stlvs;
331 proto_tree_add_item(ancp_tree, hf_ancp_num_ext_tlvs, tvb, offset, 2, ENC_BIG_ENDIAN);
332 num_tlvs = tvb_get_ntohs(tvb, offset);
333 offset += 2;
335 sti = proto_tree_add_item(ancp_tree, hf_ancp_len, tvb, offset, 2, ENC_BIG_ENDIAN);
336 proto_item_append_text(sti, " (Extension Block)");
337 offset += 2;
339 /* Create a TLV sub tree */
340 tlv_tree = proto_item_add_subtree(sti, ett_ancp_len);
342 for( ;num_tlvs; num_tlvs--) {
343 proto_tree_add_item(tlv_tree, hf_ancp_ext_tlv_type, tvb, offset, 2, ENC_BIG_ENDIAN);
344 ttype = tvb_get_ntohs(tvb, offset);
345 offset += 2;
347 sti = proto_tree_add_item(tlv_tree, hf_ancp_len, tvb, offset, 2, ENC_BIG_ENDIAN);
348 tlen = tvb_get_ntohs(tvb, offset);
349 offset += 2;
352 * Extension Block is common for event message and port
353 * management message, but the TLVs that can appear
354 * are different
356 switch (ttype) {
357 case TLV_DSL_LINE_ATTRIBUTES:
359 proto_tree *dsl_tree;
360 guint16 stlvtype, stlvlen;
361 gint val;
363 /* Create a DSL Attribute SubTree */
364 dsl_tree = proto_item_add_subtree(sti, ett_ancp_ext_tlv_type);
365 num_stlvs = tlen / 8; /* TODO - better way? */
366 for ( ;num_stlvs; num_stlvs--) {
367 proto_tree_add_item(dsl_tree,
368 hf_ancp_dsl_line_stlv_type, tvb, offset,
369 2, ENC_BIG_ENDIAN);
370 stlvtype = tvb_get_ntohs(tvb, offset);
371 offset += 2;
372 /* Skip sub-tlv-len display for now */
373 stlvlen = tvb_get_ntohs(tvb, offset);
374 offset += 2; /* Sub TLV Length */
376 sti = proto_tree_add_item(dsl_tree,
377 hf_ancp_dsl_line_stlv_value, tvb, offset,
378 stlvlen, ENC_BIG_ENDIAN);
379 val = tvb_get_ntohl(tvb, offset);
380 offset += stlvlen; /* Except loop-encap, rest are 4B */
382 switch (stlvtype) {
383 case TLV_DSL_LINE_STATE:
384 proto_item_append_text(sti, " (%s)",
385 val_to_str(val, dsl_line_state_names,
386 "Unknown (0x%02x)"));
387 break;
388 case TLV_DSL_TYPE:
389 proto_item_append_text(sti, " (%s)",
390 val_to_str(val, dsl_line_type_names,
391 "Unknown (0x%02x)"));
392 break;
394 default:
395 /* Add Unit */
396 proto_item_append_text(sti, " %s",
397 val_to_str(stlvtype,
398 dsl_line_attr_units,
399 "Unknown (0x%02x)"));
400 break;
402 SKIPPADDING(offset, stlvlen);
404 break;
406 case TLV_PING_OPAQUE_DATA:
407 /* 2 32b values*/
408 proto_tree_add_item(tlv_tree, hf_ancp_oam_opaque,
409 tvb, offset, 4, ENC_BIG_ENDIAN);
410 offset += 4;
411 proto_tree_add_item(tlv_tree, hf_ancp_oam_opaque,
412 tvb, offset, 4, ENC_BIG_ENDIAN);
413 offset += 4;
414 break;
415 case TLV_PING_PARAMS:
416 /* Count (1B) Timeout (1B), 2B empty */
417 proto_tree_add_item(tlv_tree,
418 hf_ancp_oam_loopb_cnt, tvb, offset, 1, ENC_BIG_ENDIAN);
419 offset += 1;
420 proto_tree_add_item(tlv_tree,
421 hf_ancp_oam_timeout, tvb, offset, 1, ENC_BIG_ENDIAN);
422 offset += 1;
423 /* Lets not bother about 2B until IETF WG figures out */
424 offset += 2;
425 break;
426 default:
427 /* Assume TLV value is string - covers ALCID, OAM resp */
428 proto_tree_add_item(tlv_tree, hf_ancp_ext_tlv_value_str,
429 tvb, offset, tlen, ENC_ASCII|ENC_NA);
430 offset += tlen;
431 SKIPPADDING(offset, tlen);
432 break;
433 } /* end switch {ttype} */
434 } /* end for {numtlvs} */
435 } /* end if {DSL} */
438 static void
439 dissect_ancp_adj_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ancp_tree,
440 gint offset, struct ancp_tap_t *ancp_info
443 proto_item *sti;
444 proto_tree *ancp_cap_tree;
445 guint8 byte, numcaps, adjcode;
446 guint16 tlv_len;
448 sti = proto_tree_add_item(ancp_tree, hf_ancp_timer, tvb, offset, 1,
449 ENC_BIG_ENDIAN);
450 offset += 1;
451 proto_item_append_text(sti, " msec");
453 sti = proto_tree_add_item(ancp_tree, hf_ancp_adj_code, tvb, offset, 1,
454 ENC_BIG_ENDIAN);
455 byte = tvb_get_guint8(tvb, offset);
456 offset += 1;
457 adjcode = byte & ADJ_CODE_MASK;
458 ancp_info->ancp_adjcode = adjcode; /* stats */
459 proto_item_append_text(sti, " (%s, M Flag %s)",
460 val_to_str(adjcode, adj_code_names, "Unknown (0x%02x)"),
461 (byte >> 7) ? "Set" : "Unset");
462 col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)",
463 val_to_str(adjcode, adj_code_names, "Unknown (0x%02x)"));
465 proto_tree_add_item(ancp_tree, hf_ancp_sender_name, tvb, offset, 6, ENC_NA);
466 offset += 6;
468 proto_tree_add_item(ancp_tree, hf_ancp_receiver_name, tvb,offset, 6, ENC_NA);
469 offset += 6;
471 proto_tree_add_item(ancp_tree, hf_ancp_sender_port, tvb, offset, 4, ENC_BIG_ENDIAN);
472 offset += 4;
474 proto_tree_add_item(ancp_tree, hf_ancp_receiver_port, tvb,offset, 4, ENC_BIG_ENDIAN);
475 offset += 4;
477 sti = proto_tree_add_item(ancp_tree, hf_ancp_p_info, tvb,
478 offset, 1, ENC_BIG_ENDIAN);
479 byte = tvb_get_guint8(tvb, offset);
480 offset += 1;
481 proto_item_append_text(sti, " (Type = %d, Flag = %d)",
482 byte >> 4, byte & 0x0F);
484 proto_tree_add_item(ancp_tree, hf_ancp_sender_instance, tvb, offset, 3, ENC_BIG_ENDIAN);
485 offset += 3;
487 proto_tree_add_item(ancp_tree, hf_ancp_p_id, tvb, offset, 1, ENC_BIG_ENDIAN);
488 offset += 1;
490 proto_tree_add_item(ancp_tree, hf_ancp_receiver_instance, tvb, offset, 3, ENC_BIG_ENDIAN);
491 offset += 3;
493 proto_tree_add_item(ancp_tree, hf_ancp_tech_type, tvb, offset, 1, ENC_BIG_ENDIAN);
494 offset += 1;
496 sti = proto_tree_add_item(ancp_tree, hf_ancp_num_tlvs, tvb, offset, 1, ENC_BIG_ENDIAN);
497 numcaps = tvb_get_guint8(tvb, offset);
498 offset += 1;
500 /* Start the capability subtree */
501 ancp_cap_tree = proto_item_add_subtree(sti, ett_ancp_tot_len);
503 proto_tree_add_item(ancp_cap_tree, hf_ancp_tot_len, tvb, offset, 2, ENC_BIG_ENDIAN);
504 offset += 2;
506 for ( ;numcaps; numcaps--) {
507 sti = proto_tree_add_item(ancp_cap_tree, hf_ancp_cap, tvb, offset, 2, ENC_BIG_ENDIAN);
508 offset += 2;
510 tlv_len = tvb_get_ntohs(tvb, offset);
511 offset += 2;
512 proto_item_append_text(sti, " (%d bytes)", tlv_len);
513 /* TODO - if there are non boolean caps, validate before use */
517 static void
518 ancp_stats_tree_init(stats_tree *st)
520 st_node_packets = stats_tree_create_node(st, st_str_packets, 0, TRUE);
521 st_node_packet_types = stats_tree_create_pivot(st, st_str_packet_types,
522 st_node_packets);
523 st_node_adj_pack_types = stats_tree_create_node(st, st_str_adj_pack_types,
524 st_node_packets, TRUE);
527 static int
528 ancp_stats_tree_packet(stats_tree* st, packet_info* pinfo _U_,
529 epan_dissect_t* edt _U_ , const void* p)
531 struct ancp_tap_t *pi = (struct ancp_tap_t *) p;
533 tick_stat_node(st, st_str_packets, 0, FALSE);
534 stats_tree_tick_pivot(st, st_node_packet_types,
535 val_to_str(pi->ancp_mtype, mtype_names,
536 "Unknown packet type (%d)"));
537 if (pi->ancp_mtype == ANCP_MTYPE_ADJ)
538 stats_tree_tick_pivot(st, st_node_adj_pack_types,
539 val_to_str(pi->ancp_adjcode, adj_code_names,
540 "Unknown Adjacency packet (%d)"));
541 return 1;
544 static int
545 dissect_ancp_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
547 gint offset;
548 guint8 mtype;
549 struct ancp_tap_t *ancp_info;
550 proto_item *ti;
551 proto_item *sti;
552 proto_tree *ancp_tree;
553 guint8 byte;
555 offset = 0;
556 if (tvb_get_ntohs(tvb, offset) != ANCP_GSMP_ETHER_TYPE)
557 return 0; /* XXX: this dissector is not a heuristic dissector */
558 /* Should do "expert" & dissect rest as "data" */
559 /* (after setting COL_PROTOCOL & etc) ? */
561 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ANCP");
562 col_clear(pinfo->cinfo, COL_INFO);
564 ancp_info = wmem_new(wmem_packet_scope(), struct ancp_tap_t);
565 ancp_info->ancp_mtype = 0;
566 ancp_info->ancp_adjcode = 0;
568 ti = proto_tree_add_item(tree, proto_ancp, tvb, 0, -1, ENC_NA);
570 ancp_tree = proto_item_add_subtree(ti, ett_ancp_len);
572 offset = 2; /* skip ether type */
574 proto_tree_add_item(ancp_tree, hf_ancp_len, tvb, offset, 2, ENC_BIG_ENDIAN);
575 offset += 2;
577 sti = proto_tree_add_item(ancp_tree, hf_ancp_ver, tvb, offset, 1, ENC_BIG_ENDIAN);
578 byte = tvb_get_guint8(tvb, offset);
579 offset += 1;
580 proto_item_append_text(sti, " (%d.%d)", byte >> 4, byte & 0x0F);
582 sti = proto_tree_add_item(ancp_tree, hf_ancp_mtype, tvb, offset, 1, ENC_BIG_ENDIAN);
583 mtype = tvb_get_guint8(tvb, offset); /* ANCP message type */
584 ancp_info->ancp_mtype = mtype; /* stats */
585 offset += 1;
587 col_add_fstr(pinfo->cinfo, COL_INFO, "%s Message",
588 val_to_str(mtype, mtype_names, "Unknown (0x%02x)"));
590 if (mtype != ANCP_MTYPE_ADJ) {
591 /* Dissect common header */
592 proto_tree_add_item(ancp_tree, hf_ancp_result, tvb, offset, 1,
593 ENC_BIG_ENDIAN); /* treat as 1B, but dont change offset */
595 proto_tree_add_item(ancp_tree, hf_ancp_code, tvb, offset, 2,
596 ENC_BIG_ENDIAN);
597 offset += 2;
599 proto_tree_add_item(ancp_tree, hf_ancp_p_id, tvb, offset,
600 1, ENC_BIG_ENDIAN);
601 offset += 1;
603 proto_tree_add_item(ancp_tree, hf_ancp_trans_id, tvb,
604 offset, 3, ENC_BIG_ENDIAN);
605 offset += 3;
607 proto_tree_add_item(ancp_tree, hf_ancp_i_flag, tvb, offset, 1,
608 ENC_BIG_ENDIAN); /* treat as 1B, but dont change offset */
610 sti = proto_tree_add_item(ancp_tree, hf_ancp_submsg_num, tvb,
611 offset, 2, ENC_BIG_ENDIAN);
612 offset += 2;
615 * Lets not display the 'Length' field now, it is anyway same
616 * as GSMP Length
617 * which we have already displayed at the start of the dissect
619 offset += 2; /* Length */
622 switch(mtype) {
623 case ANCP_MTYPE_ADJ:
624 dissect_ancp_adj_msg(tvb, pinfo, ancp_tree, offset, ancp_info);
625 break;
626 case ANCP_MTYPE_PORT_DN:
627 /* FALL THRU */
628 case ANCP_MTYPE_PORT_MGMT:
629 /* FALL THRU */
630 case ANCP_MTYPE_PORT_UP:
631 dissect_ancp_port_up_dn_mgmt(tvb, ancp_tree, offset);
632 break;
633 default:
634 proto_item_append_text(sti, " (Unknown Message %d)", mtype);
635 break;
637 tap_queue_packet(ancp_tap, pinfo, ancp_info);
639 return tvb_length(tvb);
642 static guint
643 get_ancp_msg_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
645 return (guint)tvb_get_ntohs(tvb, offset + 2) + 4; /* 2B len + 4B hdr */
648 static int
649 dissect_ancp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
651 tcp_dissect_pdus(tvb, pinfo, tree, TRUE, ANCP_MIN_HDR,
652 get_ancp_msg_len, dissect_ancp_message, data);
654 return tvb_length(tvb);
657 void
658 proto_register_ancp(void)
660 static hf_register_info hf[] = {
661 { &hf_ancp_len,
662 { "Length", "ancp.len",
663 FT_UINT16, BASE_DEC,
664 NULL, 0x0,
665 NULL, HFILL }
667 { &hf_ancp_ver,
668 { "Version", "ancp.ver",
669 FT_UINT8, BASE_HEX,
670 NULL, 0x0,
671 NULL, HFILL }
673 { &hf_ancp_mtype,
674 { "Message Type", "ancp.mtype",
675 FT_UINT8, BASE_DEC,
676 VALS(mtype_names), 0x0,
677 NULL, HFILL }
679 { &hf_ancp_timer,
680 { "Timer", "ancp.timer",
681 FT_UINT8, BASE_DEC,
682 NULL, 0x0,
683 NULL, HFILL }
685 { &hf_ancp_adj_code,
686 { "Code", "ancp.adjcode", /* this is diff from code */
687 FT_UINT8, BASE_DEC, /* for Adjacency msg only */
688 NULL, ADJ_CODE_MASK,
689 NULL, HFILL }
691 { &hf_ancp_sender_name,
692 { "Sender Name", "ancp.sender_name",
693 FT_ETHER, BASE_NONE,
694 NULL, 0x0,
695 NULL, HFILL }
697 { &hf_ancp_receiver_name,
698 { "Receiver Name", "ancp.receiver_name",
699 FT_ETHER, BASE_NONE,
700 NULL, 0x0,
701 NULL, HFILL }
703 { &hf_ancp_sender_port,
704 { "Sender Port", "ancp.sender_port",
705 FT_UINT64, BASE_DEC,
706 NULL, 0x0,
707 NULL, HFILL }
709 { &hf_ancp_receiver_port,
710 { "Receiver Port", "ancp.receiver_port",
711 FT_UINT64, BASE_DEC,
712 NULL, 0x0,
713 NULL, HFILL }
715 { &hf_ancp_p_info,
716 { "Partition Info", "ancp.partition_info",
717 FT_UINT8, BASE_HEX,
718 NULL, 0x0,
719 NULL, HFILL }
721 { &hf_ancp_sender_instance,
722 { "Sender Instance", "ancp.sender_instance",
723 FT_UINT24, BASE_DEC,
724 NULL, 0x0,
725 NULL, HFILL }
727 { &hf_ancp_p_id,
728 { "Partition ID", "ancp.partition_id",
729 FT_UINT8, BASE_DEC,
730 NULL, 0x0,
731 NULL, HFILL }
733 { &hf_ancp_receiver_instance,
734 { "Receiver Instance", "ancp.receiver_instance",
735 FT_UINT24, BASE_DEC,
736 NULL, 0x0,
737 NULL, HFILL }
739 { &hf_ancp_tech_type,
740 { "Tech Type", "ancp.tech_type",
741 FT_UINT8, BASE_DEC,
742 VALS(techtype_str), 0x0,
743 NULL, HFILL }
745 { &hf_ancp_num_tlvs,
746 { "Num TLVs", "ancp.num_tlvs",
747 FT_UINT8, BASE_DEC,
748 NULL, 0x0,
749 NULL, HFILL }
751 { &hf_ancp_tot_len,
752 { "Length", "ancp.tot_len", /* name just Len to reuse*/
753 FT_UINT16, BASE_DEC,
754 NULL, 0x0,
755 NULL, HFILL }
757 { &hf_ancp_cap,
758 { "Capability", "ancp.capability",
759 FT_UINT16, BASE_DEC,
760 VALS(captype_names), 0x0,
761 NULL, HFILL }
763 { &hf_ancp_result,
764 { "Result", "ancp.result",
765 FT_UINT8, BASE_DEC,
766 VALS(resulttype_names), ANCP_RESULT_MASK,
767 NULL, HFILL }
769 { &hf_ancp_code,
770 { "Code", "ancp.code",
771 FT_UINT16, BASE_HEX,
772 VALS(codetype_names), ANCP_CODE_MASK,
773 NULL, HFILL }
775 { &hf_ancp_trans_id,
776 { "Transaction ID", "ancp.transaction_id",
777 FT_UINT24, BASE_DEC,
778 NULL, 0x0,
779 NULL, HFILL }
781 { &hf_ancp_i_flag,
782 { "I Flag", "ancp.i_flag",
783 FT_BOOLEAN, 8,
784 TFS(&tfs_set_notset), ANCP_I_FLAG_MASK,
785 NULL, HFILL }
787 { &hf_ancp_submsg_num,
788 { "SubMessage Number", "ancp.submessage_number",
789 FT_UINT16, BASE_DEC,
790 NULL, ANCP_SUBMSG_MASK,
791 NULL, HFILL }
793 { &hf_ancp_port,
794 { "Port", "ancp.port",
795 FT_UINT32, BASE_DEC,
796 NULL, 0x0,
797 NULL, HFILL }
799 { &hf_ancp_port_sess_num,
800 { "Port Session Number", "ancp.port_sess_num",
801 FT_UINT32, BASE_DEC,
802 NULL, 0x0,
803 NULL, HFILL }
805 { &hf_ancp_evt_seq_num,
806 { "Event Sequence Number", "ancp.evt_seq_num",
807 FT_UINT32, BASE_DEC,
808 NULL, 0x0,
809 NULL, HFILL }
811 { &hf_ancp_label,
812 { "Label", "ancp.label", /* Not used in proto */
813 FT_UINT64, BASE_HEX,
814 NULL, 0x0,
815 NULL, HFILL }
817 { &hf_ancp_reserved,
818 { "Reserved", "ancp.reserved",
819 FT_UINT8, BASE_DEC,
820 NULL, 0x0,
821 NULL, HFILL }
823 { &hf_ancp_blk_len,
824 { "Block Length", "ancp.blk_len",
825 FT_UINT8, BASE_DEC,
826 NULL, 0x0,
827 NULL, HFILL }
829 { &hf_ancp_num_ext_tlvs,
830 { "Num TLVs", "ancp.ext_tlvs.count",
831 FT_UINT16, BASE_DEC,
832 NULL, 0x0,
833 NULL, HFILL }
835 { &hf_ancp_ext_tlv_type,
836 { "TLV", "ancp.ext_tlv.type",
837 FT_UINT16, BASE_DEC,
838 VALS(ext_tlv_types), 0x0,
839 NULL, HFILL }
841 { &hf_ancp_dsl_line_stlv_type,
842 { "Sub-TLV", "ancp.sub_tlv_type",
843 FT_UINT16, BASE_HEX,
844 VALS(dsl_line_attrs), 0x0,
845 NULL, HFILL }
847 { &hf_ancp_dsl_line_stlv_value,
848 { "Value", "ancp.dsl_line_param",
849 FT_UINT32, BASE_DEC,
850 NULL, 0x0,
851 NULL, HFILL }
853 { &hf_ancp_ext_tlv_value_str,
854 { "Value", "ancp.ext_tlv.value",
855 FT_STRING, BASE_NONE,
856 NULL, 0x0,
857 NULL, HFILL }
859 { &hf_ancp_oam_opaque,
860 { "Opaque", "ancp.oam.opaque", /* There will be 2 such 32b vals */
861 FT_UINT32, BASE_DEC,
862 NULL, 0x0,
863 NULL, HFILL }
865 { &hf_ancp_oam_loopb_cnt,
866 { "OAM Loopback Count", "ancp.oam.loopback_count",
867 FT_UINT8, BASE_DEC,
868 NULL, 0x0,
869 NULL, HFILL }
871 { &hf_ancp_oam_timeout,
872 { "OAM Timeout", "ancp.oam.timeout",
873 FT_UINT8, BASE_DEC,
874 NULL, 0x0,
875 NULL, HFILL }
879 /* Setup protocol subtree array */
880 static gint *ett[] = {
881 &ett_ancp_len,
882 &ett_ancp_ver,
883 &ett_ancp_mtype,
884 &ett_ancp_timer,
885 &ett_ancp_adj_code,
886 &ett_ancp_sender_name,
887 &ett_ancp_receiver_name,
888 &ett_ancp_sender_port,
889 &ett_ancp_receiver_port,
890 &ett_ancp_p_info,
891 &ett_ancp_sender_instance,
892 &ett_ancp_p_id,
893 &ett_ancp_receiver_instance,
894 &ett_ancp_tech_type,
895 &ett_ancp_num_tlvs,
896 &ett_ancp_tot_len,
897 &ett_ancp_cap,
898 &ett_ancp_result,
899 &ett_ancp_code,
900 &ett_ancp_trans_id,
901 &ett_ancp_i_flag,
902 &ett_ancp_submsg_num,
903 &ett_ancp_port,
904 &ett_ancp_port_sess_num,
905 &ett_ancp_evt_seq_num,
906 &ett_ancp_label,
907 &ett_ancp_reserved,
908 &ett_ancp_blk_len,
909 &ett_ancp_num_ext_tlvs,
910 &ett_ancp_ext_tlv_type,
911 &ett_ancp_dsl_line_stlv_type,
912 &ett_ancp_dsl_line_stlv_val,
913 &ett_ancp_ext_tlv_value_str,
914 &ett_ancp_oam_opaque,
915 &ett_ancp_oam_loopb_cnt,
916 &ett_ancp_oam_timeout,
919 proto_ancp = proto_register_protocol (
920 "Access Node Control Protocol",
921 "ANCP",
922 "ancp"
925 proto_register_field_array(proto_ancp, hf, array_length(hf));
926 proto_register_subtree_array(ett, array_length(ett));
927 ancp_tap = register_tap("ancp");
930 void
931 proto_reg_handoff_ancp(void)
933 dissector_handle_t ancp_handle;
935 ancp_handle = new_create_dissector_handle(dissect_ancp, proto_ancp);
936 dissector_add_uint("tcp.port", ANCP_PORT, ancp_handle);
937 stats_tree_register("ancp", "ancp", "ANCP", 0,
938 ancp_stats_tree_packet, ancp_stats_tree_init, NULL);