5eef44901b0d9646d6329fd8da62a0fd560f2e29
[obnox/wireshark/wip.git] / plugins / docsis / packet-map.c
1 /* Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
2  *
3  * $Id$
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
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.
13  *
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.
18  *
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <epan/packet.h>
29
30 #define IUC_REQUEST 1
31 #define IUC_REQ_DATA 2
32 #define IUC_INIT_MAINT 3
33 #define IUC_STATION_MAINT 4
34 #define IUC_SHORT_DATA_GRANT 5
35 #define IUC_LONG_DATA_GRANT 6
36 #define IUC_NULL_IE 7
37 #define IUC_DATA_ACK 8
38 #define IUC_RESERVED9 9
39 #define IUC_RESERVED10 10
40 #define IUC_RESERVED11 11
41 #define IUC_RESERVED12 12
42 #define IUC_RESERVED13 13
43 #define IUC_RESERVED14 14
44 #define IUC_EXPANSION 15
45
46 /* Initialize the protocol and registered fields */
47 static int proto_docsis_map = -1;
48 static int hf_docsis_map_upstream_chid = -1;
49 static int hf_docsis_map_ucd_count = -1;
50 static int hf_docsis_map_numie = -1;
51 static int hf_docsis_map_alloc_start = -1;
52 static int hf_docsis_map_ack_time = -1;
53 static int hf_docsis_map_rng_start = -1;
54 static int hf_docsis_map_rng_end = -1;
55 static int hf_docsis_map_data_start = -1;
56 static int hf_docsis_map_data_end = -1;
57 static int hf_docsis_map_ie = -1;
58 static int hf_docsis_map_rsvd = -1;
59
60 static int hf_docsis_map_sid = -1;
61 static int hf_docsis_map_iuc = -1;
62 static int hf_docsis_map_offset = -1;
63
64 /* Initialize the subtree pointers */
65 static gint ett_docsis_map = -1;
66
67 /* Defined in packet-ucd.c */
68 extern value_string iuc_vals[];
69
70 /* Code to actually dissect the packets */
71 static void
72 dissect_map (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
73 {
74   guint8 i, numie;
75   int pos;
76   guint16 sid;
77   guint8 iuc;
78   guint16 offset;
79   guint32 ie, temp, mask;
80   proto_item *it, *item;
81   proto_tree *map_tree;
82   guint8 upchid, ucd_count;
83
84
85   numie = tvb_get_guint8 (tvb, 2);
86   upchid = tvb_get_guint8 (tvb, 0);
87   ucd_count = tvb_get_guint8 (tvb, 1);
88
89   col_clear (pinfo->cinfo, COL_INFO);
90   if (upchid > 0)
91         col_add_fstr (pinfo->cinfo, COL_INFO,
92                       "Map Message:  Channel ID = %u (U%u), UCD Count = %u,  # IE's = %u",
93                       upchid, upchid - 1, ucd_count, numie);
94   else
95         col_add_fstr (pinfo->cinfo, COL_INFO,
96                       "Map Message:  Channel ID = %u (Telephony Return), UCD Count = %u, # IE's = %u",
97                       upchid, ucd_count, numie);
98
99   if (tree)
100     {
101       it =
102         proto_tree_add_protocol_format (tree, proto_docsis_map, tvb, 0, -1,
103                                         "MAP Message");
104       map_tree = proto_item_add_subtree (it, ett_docsis_map);
105
106       proto_tree_add_item (map_tree, hf_docsis_map_upstream_chid, tvb, 0, 1,
107                            FALSE);
108       proto_tree_add_item (map_tree, hf_docsis_map_ucd_count, tvb, 1, 1,
109                            FALSE);
110       proto_tree_add_item (map_tree, hf_docsis_map_numie, tvb, 2, 1, FALSE);
111       proto_tree_add_item (map_tree, hf_docsis_map_rsvd, tvb, 3, 1, FALSE);
112       proto_tree_add_item (map_tree, hf_docsis_map_alloc_start, tvb, 4, 4,
113                            FALSE);
114       proto_tree_add_item (map_tree, hf_docsis_map_ack_time, tvb, 8, 4,
115                            FALSE);
116       proto_tree_add_item (map_tree, hf_docsis_map_rng_start, tvb, 12, 1,
117                            FALSE);
118       proto_tree_add_item (map_tree, hf_docsis_map_rng_end, tvb, 13, 1,
119                            FALSE);
120       proto_tree_add_item (map_tree, hf_docsis_map_data_start, tvb, 14, 1,
121                            FALSE);
122       proto_tree_add_item (map_tree, hf_docsis_map_data_end, tvb, 15, 1,
123                            FALSE);
124
125       pos = 16;
126       for (i = 0; i < numie; i++)
127         {
128           ie = tvb_get_ntohl (tvb, pos);
129           mask = 0xFFFC0000;
130           temp = (ie & mask);
131           temp = temp >> 18;
132           sid = (guint16) (temp & 0x3FFF);
133           mask = 0x3C000;
134           temp = (ie & mask);
135           temp = temp >> 14;
136           iuc = (guint8) (temp & 0x0F);
137           mask = 0x3FFF;
138           offset = (guint16) (ie & mask);
139           item = proto_tree_add_item(map_tree, hf_docsis_map_sid, tvb, pos, 4, FALSE);
140           PROTO_ITEM_SET_HIDDEN(item);
141           item = proto_tree_add_item(map_tree, hf_docsis_map_iuc, tvb, pos, 4, FALSE);
142           PROTO_ITEM_SET_HIDDEN(item);
143           item = proto_tree_add_item(map_tree, hf_docsis_map_offset, tvb, pos, 4, FALSE);
144           PROTO_ITEM_SET_HIDDEN(item);
145           if (sid == 0x3FFF)
146             proto_tree_add_uint_format (map_tree, hf_docsis_map_ie, tvb, pos, 4,
147                                       ie, "SID = 0x%x (All CM's), IUC = %s, Offset = %u",
148                                       sid, val_to_str (iuc, iuc_vals, "%d"),
149                                       offset);
150           else
151             proto_tree_add_uint_format (map_tree, hf_docsis_map_ie, tvb, pos, 4,
152                                       ie, "SID = %u, IUC = %s, Offset = %u",
153                                       sid, val_to_str (iuc, iuc_vals, "%d"),
154                                       offset);
155           pos = pos + 4;
156         }                       /* for... */
157     }                           /* if(tree) */
158
159
160 }
161
162
163
164
165 /* Register the protocol with Wireshark */
166
167 /* this format is require because a script is used to build the C function
168    that calls all the protocol registration.
169 */
170
171
172 void
173 proto_register_docsis_map (void)
174 {
175
176 /* Setup list of header fields  See Section 1.6.1 for details*/
177   static hf_register_info hf[] = {
178     {&hf_docsis_map_ucd_count,
179      {"UCD Count", "docsis_map.ucdcount",
180       FT_UINT8, BASE_DEC, NULL, 0x0,
181       "Map UCD Count", HFILL}
182      },
183     {&hf_docsis_map_upstream_chid,
184      {"Upstream Channel ID", "docsis_map.upchid",
185       FT_UINT8, BASE_DEC, NULL, 0x0,
186       NULL, HFILL}
187      },
188     {&hf_docsis_map_numie,
189      {"Number of IE's", "docsis_map.numie",
190       FT_UINT8, BASE_DEC, NULL, 0x0,
191       "Number of Information Elements", HFILL}
192      },
193     {&hf_docsis_map_alloc_start,
194      {"Alloc Start Time (minislots)", "docsis_map.allocstart",
195       FT_UINT32, BASE_DEC, NULL, 0x0,
196       NULL, HFILL}
197      },
198     {&hf_docsis_map_ack_time,
199      {"ACK Time (minislots)", "docsis_map.acktime",
200       FT_UINT32, BASE_DEC, NULL, 0x0,
201       NULL, HFILL}
202      },
203     {&hf_docsis_map_rng_start,
204      {"Ranging Backoff Start", "docsis_map.rng_start",
205       FT_UINT8, BASE_DEC, NULL, 0x0,
206       NULL, HFILL}
207      },
208     {&hf_docsis_map_rng_end,
209      {"Ranging Backoff End", "docsis_map.rng_end",
210       FT_UINT8, BASE_DEC, NULL, 0x0,
211       NULL, HFILL}
212      },
213     {&hf_docsis_map_data_start,
214      {"Data Backoff Start", "docsis_map.data_start",
215       FT_UINT8, BASE_DEC, NULL, 0x0,
216       NULL, HFILL}
217      },
218     {&hf_docsis_map_data_end,
219      {"Data Backoff End", "docsis_map.data_end",
220       FT_UINT8, BASE_DEC, NULL, 0x0,
221       NULL, HFILL}
222      },
223     {&hf_docsis_map_ie,
224      {"Information Element", "docsis_map.ie",
225       FT_UINT32, BASE_HEX, NULL, 0x0,
226       NULL, HFILL}
227      },
228     {&hf_docsis_map_rsvd,
229      {"Reserved [0x00]", "docsis_map.rsvd",
230       FT_UINT8, BASE_HEX, NULL, 0x0,
231       "Reserved Byte", HFILL}
232      },
233     {&hf_docsis_map_sid,
234      {"Service Identifier", "docsis_map.sid",
235       FT_UINT32, BASE_DEC, NULL, 0xFFFC0000,
236       NULL, HFILL}
237      },
238     {&hf_docsis_map_iuc,
239      {"Interval Usage Code", "docsis_map.iuc",
240       FT_UINT32, BASE_DEC, VALS(iuc_vals), 0x0003c000,
241       NULL, HFILL}
242      },
243     {&hf_docsis_map_offset,
244      {"Offset", "docsis_map.offset",
245       FT_UINT32, BASE_DEC, NULL, 0x00003fff,
246       NULL, HFILL}
247      },
248
249   };
250
251 /* Setup protocol subtree array */
252   static gint *ett[] = {
253     &ett_docsis_map,
254   };
255
256 /* Register the protocol name and description */
257   proto_docsis_map =
258     proto_register_protocol ("DOCSIS Upstream Bandwidth Allocation",
259                              "DOCSIS MAP", "docsis_map");
260
261 /* Required function calls to register the header fields and subtrees used */
262   proto_register_field_array (proto_docsis_map, hf, array_length (hf));
263   proto_register_subtree_array (ett, array_length (ett));
264
265   register_dissector ("docsis_map", dissect_map, proto_docsis_map);
266 }
267
268
269 /* If this dissector uses sub-dissector registration add a registration routine.
270    This format is required because a script is used to find these routines and
271    create the code that calls these routines.
272 */
273 void
274 proto_reg_handoff_docsis_map (void)
275 {
276   dissector_handle_t docsis_map_handle;
277
278   docsis_map_handle = find_dissector ("docsis_map");
279   dissector_add_uint ("docsis_mgmt", 0x03, docsis_map_handle);
280
281 }