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