Fixed warning "Field width should have type 'int'".
[obnox/wireshark/wip.git] / plugins / docsis / packet-bintrngreq.c
1 /* packet-bintrngreq.c
2  * Routines for DOCSIS 3.0 Bonded Intial Ranging Request Message dissection.
3  * Copyright 2009, Geoffrey Kimball <gekimbal[AT]cisco.com>
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_bintrngreq = -1;
34 static int hf_docsis_bintrngreq = -1;
35 static int hf_docsis_bintrngreq_down_chid = -1;
36 static int hf_docsis_bintrngreq_mddsgid = -1;
37 static int hf_docsis_bintrngreq_capflags = -1;
38 static int hf_docsis_bintrngreq_up_chid = -1;
39 static int hf_docsis_bintrngreq_capflags_frag = -1;
40 static int hf_docsis_bintrngreq_capflags_encrypt = -1;
41
42
43 /* Initialize the subtree pointers */
44 static gint ett_docsis_bintrngreq = -1;
45
46 /* Code to actually dissect the packets */
47 static void
48 dissect_bintrngreq (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
49 {
50   proto_item *bintrngreq_item;
51   proto_tree *bintrngreq_tree;
52   guint16 md_ds_sg_id;
53
54   md_ds_sg_id = tvb_get_ntohs (tvb, 0);
55
56   col_clear (pinfo->cinfo, COL_INFO);
57   col_add_fstr (pinfo->cinfo, COL_INFO, "Bonded Ranging Request: MD-DS-SG-ID = %u (0x%X)",
58                                         md_ds_sg_id, md_ds_sg_id );
59
60   if (tree)
61   {
62     guint16 offset = 0;
63     bintrngreq_item = proto_tree_add_protocol_format (tree, proto_docsis_bintrngreq,
64                                                                                    tvb, offset, tvb_length_remaining (tvb, 0),
65                                                                                    "Bonded Initial Ranging Request");
66     bintrngreq_tree = proto_item_add_subtree (bintrngreq_item, ett_docsis_bintrngreq);
67     proto_tree_add_item (bintrngreq_tree, hf_docsis_bintrngreq_capflags,
68                                                    tvb, offset, 1, FALSE);
69     proto_tree_add_item( bintrngreq_tree, hf_docsis_bintrngreq_capflags_frag,
70                                                    tvb, offset, 1, FALSE );
71     proto_tree_add_item( bintrngreq_tree, hf_docsis_bintrngreq_capflags_encrypt,
72                                                    tvb, offset, 1, FALSE );
73     offset++;
74     proto_tree_add_item (bintrngreq_tree, hf_docsis_bintrngreq_mddsgid,
75                                                    tvb, offset, 1, FALSE);
76     offset++;
77     proto_tree_add_item (bintrngreq_tree, hf_docsis_bintrngreq_down_chid,
78                                                    tvb, offset, 1, FALSE);
79     offset++;
80     proto_tree_add_item (bintrngreq_tree, hf_docsis_bintrngreq_up_chid,
81                                                    tvb, offset, 1, FALSE);
82   }
83 }
84
85 /* Register the protocol with Wireshark */
86
87 /* 
88  * this format is required because a script is used to build the C function  
89  * that calls all the protocol registration.
90  */ 
91 void
92 proto_register_docsis_bintrngreq (void)
93 {
94   /* Setup list of header fields  See Section 1.6.1 for details*/
95   static hf_register_info hf[] = {
96     {&hf_docsis_bintrngreq,
97      {"RNG-REQ Message", "docsis_bintrngreq",
98       FT_BYTES, BASE_NONE, NULL, 0x0,
99       "Ranging Request Message", HFILL}
100     },
101     {&hf_docsis_bintrngreq_capflags,
102      {"Capability Flags", "docsis_bintrngreq.capflags",
103       FT_UINT8, BASE_HEX, NULL, 0x0,
104       NULL, HFILL}
105     },
106     { &hf_docsis_bintrngreq_capflags_frag,
107      {"Pre-3.0 Fragmentation", "docsis_bintrngreq.capflags.frag",
108       FT_BOOLEAN, 8, NULL, (1<<7),
109       "Pre-3.0 DOCSIS fragmentation is supported prior to registration", HFILL }
110     },
111     { &hf_docsis_bintrngreq_capflags_encrypt,
112      {"Early Auth. & Encrypt", "docsis_bintrngreq.capflags.encrypt",
113       FT_BOOLEAN, 8, NULL, (1<<6),
114       "Early Authentication and Encryption supported", HFILL }
115     },
116     {&hf_docsis_bintrngreq_mddsgid,
117      {"MD-DS-SG-ID", "docsis_bintrngreq.mddsgid",
118       FT_UINT8, BASE_HEX_DEC, NULL, 0x0,
119       "MAC Domain Downstream Service Group Identifier", HFILL}
120     },
121     {&hf_docsis_bintrngreq_down_chid,
122      {"DS Chan ID ", "docsis_bintrngreq.downchid",
123       FT_UINT8, BASE_HEX_DEC, NULL, 0x0,
124       NULL, HFILL}
125     },
126     {&hf_docsis_bintrngreq_up_chid,
127      {"US Chan ID ", "docsis_bintrngreq.upchid",
128       FT_UINT8, BASE_HEX_DEC, NULL, 0x0,
129       NULL, HFILL}
130     },
131   };
132
133 /* Setup protocol subtree array */
134   static gint *ett[] = {
135     &ett_docsis_bintrngreq,
136   };
137
138 /* Register the protocol name and description */
139   proto_docsis_bintrngreq = proto_register_protocol ("DOCSIS Bonded Initial Ranging Message",
140                                                  "DOCSIS B-INT-RNG-REQ",
141                                                  "docsis_bintrngreq");
142
143 /* Required function calls to register the header fields and subtrees used */
144   proto_register_field_array (proto_docsis_bintrngreq, hf, array_length (hf));
145   proto_register_subtree_array (ett, array_length (ett));
146
147   register_dissector ("docsis_bintrngreq", dissect_bintrngreq, proto_docsis_bintrngreq);
148 }
149
150
151 /* If this dissector uses sub-dissector registration add a registration routine.
152    This format is required because a script is used to find these routines and
153    create the code that calls these routines.
154 */
155 void
156 proto_reg_handoff_docsis_bintrngreq (void)
157 {
158   dissector_handle_t docsis_bintrngreq_handle;
159
160   docsis_bintrngreq_handle = find_dissector ("docsis_bintrngreq");
161   dissector_add ("docsis_mgmt", 0x22, docsis_bintrngreq_handle);
162 }