Add a few more menu items.
[obnox/wireshark/wip.git] / plugins / docsis / packet-dbcreq.c
1 /* packet-dbcreq.c
2  * Routines for DOCSIS 3.0 Dynamic Bonding Change Request Message dissection.
3  * Copyright 2010, Guido Reismueller <g.reismueller[AT]avm.de>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <epan/packet.h>
31
32 /* Initialize the protocol and registered fields */
33 static int proto_docsis_dbcreq = -1;
34 static int hf_docsis_dbcreq_tranid = -1;
35 static int hf_docsis_dbcreq_number_of_fragments = -1;
36 static int hf_docsis_dbcreq_fragment_sequence_number = -1;
37 static dissector_handle_t docsis_tlv_handle;
38
39 /* Initialize the subtree pointers */
40 static gint ett_docsis_dbcreq = -1;
41
42 /* Code to actually dissect the packets */
43 static void
44 dissect_dbcreq (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
45 {
46   proto_item *dbcreq_item;
47   proto_tree *dbcreq_tree = NULL;
48   guint16 transid;
49   tvbuff_t *next_tvb;
50
51   transid = tvb_get_ntohs (tvb, 0);
52
53   col_clear (pinfo->cinfo, COL_INFO);
54   col_add_fstr (pinfo->cinfo, COL_INFO,
55             "Dynamic Bonding Change Request: Tran-Id = %u", transid);
56
57   if (tree)
58   {
59     dbcreq_item = proto_tree_add_protocol_format (tree, proto_docsis_dbcreq,
60                                                                                    tvb, 0, -1,
61                                                                                    "Dynamic Bonding Change Request");
62     dbcreq_tree = proto_item_add_subtree (dbcreq_item, ett_docsis_dbcreq);
63     proto_tree_add_item (dbcreq_tree, hf_docsis_dbcreq_tranid,
64                                                    tvb, 0, 2, FALSE);
65     proto_tree_add_item( dbcreq_tree, hf_docsis_dbcreq_number_of_fragments,
66                                                    tvb, 2, 1, FALSE );
67     proto_tree_add_item( dbcreq_tree, hf_docsis_dbcreq_fragment_sequence_number ,
68                                                    tvb, 3, 1, FALSE );
69   }
70   /* Call Dissector for Appendix C TLV's */
71   next_tvb = tvb_new_subset_remaining (tvb, 4);
72   call_dissector (docsis_tlv_handle, next_tvb, pinfo, dbcreq_tree);
73 }
74
75 /* Register the protocol with Wireshark */
76
77 /*
78  * this format is required because a script is used to build the C function
79  * that calls all the protocol registration.
80  */
81 void
82 proto_register_docsis_dbcreq (void)
83 {
84   /* Setup list of header fields  See Section 1.6.1 for details*/
85   static hf_register_info hf[] = {
86     {&hf_docsis_dbcreq_tranid,
87      {"Transaction Id", "docsis_dbcreq.tranid",
88       FT_UINT16, BASE_DEC, NULL, 0x0,
89       NULL, HFILL}
90      },
91     {&hf_docsis_dbcreq_number_of_fragments,
92      {"Number of Fragments", "docsis_dbcreq.number_of_fragments",
93       FT_UINT8, BASE_HEX_DEC, NULL, 0x0,
94       NULL, HFILL}
95     },
96     {&hf_docsis_dbcreq_fragment_sequence_number,
97      {"Fragment Seq No", "docsis_dbcreq.fragment_sequence_number",
98       FT_UINT8, BASE_HEX_DEC, NULL, 0x0,
99       NULL, HFILL}
100     },
101   };
102
103 /* Setup protocol subtree array */
104   static gint *ett[] = {
105     &ett_docsis_dbcreq,
106   };
107
108 /* Register the protocol name and description */
109   proto_docsis_dbcreq = proto_register_protocol ("DOCSIS Dynamic Bonding Change Request",
110                                                  "DOCSIS DBC-REQ",
111                                                  "docsis_dbcreq");
112
113 /* Required function calls to register the header fields and subtrees used */
114   proto_register_field_array (proto_docsis_dbcreq, hf, array_length (hf));
115   proto_register_subtree_array (ett, array_length (ett));
116
117   register_dissector ("docsis_dbcreq", dissect_dbcreq, proto_docsis_dbcreq);
118 }
119
120
121 /* If this dissector uses sub-dissector registration add a registration routine.
122    This format is required because a script is used to find these routines and
123    create the code that calls these routines.
124 */
125 void
126 proto_reg_handoff_docsis_dbcreq (void)
127 {
128   dissector_handle_t docsis_dbcreq_handle;
129
130   docsis_dbcreq_handle = find_dissector ("docsis_dbcreq");
131   docsis_tlv_handle = find_dissector ("docsis_tlv");
132   dissector_add_uint ("docsis_mgmt", 0x24, docsis_dbcreq_handle);
133 }