MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / plugins / docsis / packet-map.c
blob1c67a7c4557d76d2db9cd22719d8378eb82c0709
1 /* Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
3 * $Id$
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "config.h"
26 #include <epan/packet.h>
28 #define IUC_REQUEST 1
29 #define IUC_REQ_DATA 2
30 #define IUC_INIT_MAINT 3
31 #define IUC_STATION_MAINT 4
32 #define IUC_SHORT_DATA_GRANT 5
33 #define IUC_LONG_DATA_GRANT 6
34 #define IUC_NULL_IE 7
35 #define IUC_DATA_ACK 8
36 #define IUC_RESERVED9 9
37 #define IUC_RESERVED10 10
38 #define IUC_RESERVED11 11
39 #define IUC_RESERVED12 12
40 #define IUC_RESERVED13 13
41 #define IUC_RESERVED14 14
42 #define IUC_EXPANSION 15
44 /* Initialize the protocol and registered fields */
45 static int proto_docsis_map = -1;
46 static int hf_docsis_map_upstream_chid = -1;
47 static int hf_docsis_map_ucd_count = -1;
48 static int hf_docsis_map_numie = -1;
49 static int hf_docsis_map_alloc_start = -1;
50 static int hf_docsis_map_ack_time = -1;
51 static int hf_docsis_map_rng_start = -1;
52 static int hf_docsis_map_rng_end = -1;
53 static int hf_docsis_map_data_start = -1;
54 static int hf_docsis_map_data_end = -1;
55 static int hf_docsis_map_ie = -1;
56 static int hf_docsis_map_rsvd = -1;
58 static int hf_docsis_map_sid = -1;
59 static int hf_docsis_map_iuc = -1;
60 static int hf_docsis_map_offset = -1;
62 /* Initialize the subtree pointers */
63 static gint ett_docsis_map = -1;
65 /* Defined in packet-ucd.c */
66 extern value_string iuc_vals[];
68 /* Code to actually dissect the packets */
69 static void
70 dissect_map (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
72 guint8 i, numie;
73 int pos;
74 guint16 sid;
75 guint8 iuc;
76 guint16 offset;
77 guint32 ie, temp, mask;
78 proto_item *it, *item;
79 proto_tree *map_tree;
80 guint8 upchid, ucd_count;
83 numie = tvb_get_guint8 (tvb, 2);
84 upchid = tvb_get_guint8 (tvb, 0);
85 ucd_count = tvb_get_guint8 (tvb, 1);
87 if (upchid > 0)
88 col_add_fstr (pinfo->cinfo, COL_INFO,
89 "Map Message: Channel ID = %u (U%u), UCD Count = %u, # IE's = %u",
90 upchid, upchid - 1, ucd_count, numie);
91 else
92 col_add_fstr (pinfo->cinfo, COL_INFO,
93 "Map Message: Channel ID = %u (Telephony Return), UCD Count = %u, # IE's = %u",
94 upchid, ucd_count, numie);
96 if (tree)
98 it =
99 proto_tree_add_protocol_format (tree, proto_docsis_map, tvb, 0, -1,
100 "MAP Message");
101 map_tree = proto_item_add_subtree (it, ett_docsis_map);
103 proto_tree_add_item (map_tree, hf_docsis_map_upstream_chid, tvb, 0, 1,
104 ENC_BIG_ENDIAN);
105 proto_tree_add_item (map_tree, hf_docsis_map_ucd_count, tvb, 1, 1,
106 ENC_BIG_ENDIAN);
107 proto_tree_add_item (map_tree, hf_docsis_map_numie, tvb, 2, 1, ENC_BIG_ENDIAN);
108 proto_tree_add_item (map_tree, hf_docsis_map_rsvd, tvb, 3, 1, ENC_BIG_ENDIAN);
109 proto_tree_add_item (map_tree, hf_docsis_map_alloc_start, tvb, 4, 4,
110 ENC_BIG_ENDIAN);
111 proto_tree_add_item (map_tree, hf_docsis_map_ack_time, tvb, 8, 4,
112 ENC_BIG_ENDIAN);
113 proto_tree_add_item (map_tree, hf_docsis_map_rng_start, tvb, 12, 1,
114 ENC_BIG_ENDIAN);
115 proto_tree_add_item (map_tree, hf_docsis_map_rng_end, tvb, 13, 1,
116 ENC_BIG_ENDIAN);
117 proto_tree_add_item (map_tree, hf_docsis_map_data_start, tvb, 14, 1,
118 ENC_BIG_ENDIAN);
119 proto_tree_add_item (map_tree, hf_docsis_map_data_end, tvb, 15, 1,
120 ENC_BIG_ENDIAN);
122 pos = 16;
123 for (i = 0; i < numie; i++)
125 ie = tvb_get_ntohl (tvb, pos);
126 mask = 0xFFFC0000;
127 temp = (ie & mask);
128 temp = temp >> 18;
129 sid = (guint16) (temp & 0x3FFF);
130 mask = 0x3C000;
131 temp = (ie & mask);
132 temp = temp >> 14;
133 iuc = (guint8) (temp & 0x0F);
134 mask = 0x3FFF;
135 offset = (guint16) (ie & mask);
136 item = proto_tree_add_item(map_tree, hf_docsis_map_sid, tvb, pos, 4, ENC_BIG_ENDIAN);
137 PROTO_ITEM_SET_HIDDEN(item);
138 item = proto_tree_add_item(map_tree, hf_docsis_map_iuc, tvb, pos, 4, ENC_BIG_ENDIAN);
139 PROTO_ITEM_SET_HIDDEN(item);
140 item = proto_tree_add_item(map_tree, hf_docsis_map_offset, tvb, pos, 4, ENC_BIG_ENDIAN);
141 PROTO_ITEM_SET_HIDDEN(item);
142 if (sid == 0x3FFF)
143 proto_tree_add_uint_format (map_tree, hf_docsis_map_ie, tvb, pos, 4,
144 ie, "SID = 0x%x (All CM's), IUC = %s, Offset = %u",
145 sid, val_to_str (iuc, iuc_vals, "%d"),
146 offset);
147 else
148 proto_tree_add_uint_format (map_tree, hf_docsis_map_ie, tvb, pos, 4,
149 ie, "SID = %u, IUC = %s, Offset = %u",
150 sid, val_to_str (iuc, iuc_vals, "%d"),
151 offset);
152 pos = pos + 4;
153 } /* for... */
154 } /* if(tree) */
162 /* Register the protocol with Wireshark */
164 /* this format is require because a script is used to build the C function
165 that calls all the protocol registration.
169 void
170 proto_register_docsis_map (void)
173 /* Setup list of header fields See Section 1.6.1 for details*/
174 static hf_register_info hf[] = {
175 {&hf_docsis_map_ucd_count,
176 {"UCD Count", "docsis_map.ucdcount",
177 FT_UINT8, BASE_DEC, NULL, 0x0,
178 "Map UCD Count", HFILL}
180 {&hf_docsis_map_upstream_chid,
181 {"Upstream Channel ID", "docsis_map.upchid",
182 FT_UINT8, BASE_DEC, NULL, 0x0,
183 NULL, HFILL}
185 {&hf_docsis_map_numie,
186 {"Number of IE's", "docsis_map.numie",
187 FT_UINT8, BASE_DEC, NULL, 0x0,
188 "Number of Information Elements", HFILL}
190 {&hf_docsis_map_alloc_start,
191 {"Alloc Start Time (minislots)", "docsis_map.allocstart",
192 FT_UINT32, BASE_DEC, NULL, 0x0,
193 NULL, HFILL}
195 {&hf_docsis_map_ack_time,
196 {"ACK Time (minislots)", "docsis_map.acktime",
197 FT_UINT32, BASE_DEC, NULL, 0x0,
198 NULL, HFILL}
200 {&hf_docsis_map_rng_start,
201 {"Ranging Backoff Start", "docsis_map.rng_start",
202 FT_UINT8, BASE_DEC, NULL, 0x0,
203 NULL, HFILL}
205 {&hf_docsis_map_rng_end,
206 {"Ranging Backoff End", "docsis_map.rng_end",
207 FT_UINT8, BASE_DEC, NULL, 0x0,
208 NULL, HFILL}
210 {&hf_docsis_map_data_start,
211 {"Data Backoff Start", "docsis_map.data_start",
212 FT_UINT8, BASE_DEC, NULL, 0x0,
213 NULL, HFILL}
215 {&hf_docsis_map_data_end,
216 {"Data Backoff End", "docsis_map.data_end",
217 FT_UINT8, BASE_DEC, NULL, 0x0,
218 NULL, HFILL}
220 {&hf_docsis_map_ie,
221 {"Information Element", "docsis_map.ie",
222 FT_UINT32, BASE_HEX, NULL, 0x0,
223 NULL, HFILL}
225 {&hf_docsis_map_rsvd,
226 {"Reserved [0x00]", "docsis_map.rsvd",
227 FT_UINT8, BASE_HEX, NULL, 0x0,
228 "Reserved Byte", HFILL}
230 {&hf_docsis_map_sid,
231 {"Service Identifier", "docsis_map.sid",
232 FT_UINT32, BASE_DEC, NULL, 0xFFFC0000,
233 NULL, HFILL}
235 {&hf_docsis_map_iuc,
236 {"Interval Usage Code", "docsis_map.iuc",
237 FT_UINT32, BASE_DEC, VALS(iuc_vals), 0x0003c000,
238 NULL, HFILL}
240 {&hf_docsis_map_offset,
241 {"Offset", "docsis_map.offset",
242 FT_UINT32, BASE_DEC, NULL, 0x00003fff,
243 NULL, HFILL}
248 /* Setup protocol subtree array */
249 static gint *ett[] = {
250 &ett_docsis_map,
253 /* Register the protocol name and description */
254 proto_docsis_map =
255 proto_register_protocol ("DOCSIS Upstream Bandwidth Allocation",
256 "DOCSIS MAP", "docsis_map");
258 /* Required function calls to register the header fields and subtrees used */
259 proto_register_field_array (proto_docsis_map, hf, array_length (hf));
260 proto_register_subtree_array (ett, array_length (ett));
262 register_dissector ("docsis_map", dissect_map, proto_docsis_map);
266 /* If this dissector uses sub-dissector registration add a registration routine.
267 This format is required because a script is used to find these routines and
268 create the code that calls these routines.
270 void
271 proto_reg_handoff_docsis_map (void)
273 dissector_handle_t docsis_map_handle;
275 docsis_map_handle = find_dissector ("docsis_map");
276 dissector_add_uint ("docsis_mgmt", 0x03, docsis_map_handle);