From Joerg Mayer: explicitly fill in all members of a
[obnox/wireshark/wip.git] / packet-lmi.c
1 /* packet-lmi.c
2  * Routines for Frame Relay Local Management Interface (LMI) disassembly
3  * Copyright 2001, Jeffrey C. Foster <jfoste@woodward.com>
4  *
5  * $Id: packet-lmi.c,v 1.5 2001/06/18 02:17:48 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.org>
9  * Copyright 1998
10  *
11  * 
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  * 
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  * 
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  *
26  * ToDo:
27  *
28  * References:
29  *
30  * http://www.techfest.com/networking/wan/frrel.htm
31  * http://www.frforum.com/5000/frf1_2.pdf
32  * http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/frame.htm#xtocid125314
33  * http://www.net.aapt.com.au/techref/lmimess.htm
34  * http://www.raleigh.ibm.com:80/cgi-bin/bookmgr/BOOKS/EZ305800/1.2.4.4
35  */
36
37
38 #ifdef HAVE_CONFIG_H
39 # include "config.h"
40 #endif
41
42 #ifdef HAVE_SYS_TYPES_H
43 # include <sys/types.h>
44 #endif
45
46 #include <stdio.h>
47 #include <glib.h>
48 #include <string.h>
49 #include "packet.h"
50 #include "nlpid.h"
51
52 static int proto_lmi = -1;
53 static int hf_lmi_call_ref = -1;
54 static int hf_lmi_msg_type = -1;
55 static int hf_lmi_inf_ele = -1;
56 static int hf_lmi_inf_len = -1;
57                         
58 static int hf_lmi_rcd_type = -1;
59 static int hf_lmi_send_seq = -1;
60 static int hf_lmi_recv_seq = -1;
61 static int hf_lmi_dlci_high = -1;
62 static int hf_lmi_dlci_low = -1;
63 static int hf_lmi_new = -1;
64 static int hf_lmi_act = -1;
65
66 static gint ett_lmi = -1;
67 static gint ett_lmi_ele = -1;
68
69 #ifdef _OLD_
70 /*
71  * Bits in the address field.
72  */
73 #define LMI_CMD         0xf000  /* LMI Command */
74 #define LMI_SEQ         0x0fff  /* LMI Sequence number */
75
76 #endif
77
78 static const value_string msg_type_str[] = {
79         {0x75, "Status Enquiry"},
80         {0x7D, "Status"},
81         { 0,       NULL }
82         };
83
84 static const value_string element_type_str[] = {
85
86 /*** These are the ANSI values ***/
87         {0x01, "Report"},
88         {0x03, "Keep Alive"},
89         {0x07, "PVC Status"},
90
91 /*** These are the ITU values ***/
92         {0x51, "Report"},
93         {0x53, "Keep Alive"},
94         {0x07, "PVC Status"},
95
96         { 0,       NULL }
97         };
98
99 static const value_string record_type_str[] = {
100         {0x00, "Full Status"},
101         {0x01, "Link Integrity Verification Only"},
102         {0x02, "Single PVC"},
103         { 0,       NULL }
104         };
105
106 static const value_string pvc_status_new_str[] = {
107         {0x00, "PVC already present"},
108         {0x01, "PVC is new"},
109         { 0,       NULL }
110         };
111
112 static const value_string pvc_status_act_str[] = {
113         {0x00, "PVC is Inactive"},
114         {0x01, "PVC is Active"},
115         { 0,       NULL }
116         };
117
118 static void
119 dissect_lmi_report_type(tvbuff_t *tvb, int offset, proto_tree *tree)
120 {
121         proto_tree_add_uint(tree, hf_lmi_rcd_type, tvb, offset, 1, tvb_get_guint8( tvb, offset));
122 }
123
124 static void
125 dissect_lmi_link_int(tvbuff_t *tvb, int offset, proto_tree *tree)
126 {
127         proto_tree_add_uint(tree, hf_lmi_send_seq, tvb, offset, 1, tvb_get_guint8( tvb, offset));
128         ++offset;
129         proto_tree_add_uint(tree, hf_lmi_recv_seq, tvb, offset, 1, tvb_get_guint8( tvb, offset));
130
131 }
132
133 static void
134 dissect_lmi_pvc_status(tvbuff_t *tvb, int offset, proto_tree *tree)
135 {
136         proto_tree_add_uint(tree, hf_lmi_dlci_high, tvb, offset, 1, tvb_get_guint8( tvb, offset));
137         ++offset;
138         proto_tree_add_uint(tree, hf_lmi_dlci_low, tvb, offset, 1, tvb_get_guint8( tvb, offset));
139         ++offset;
140         proto_tree_add_uint(tree, hf_lmi_new, tvb, offset, 1, tvb_get_guint8( tvb, offset));
141         proto_tree_add_uint(tree, hf_lmi_act, tvb, offset, 1, tvb_get_guint8( tvb, offset));
142 }
143
144 static void
145 dissect_lmi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
146 {
147         proto_tree      *lmi_tree, *lmi_subtree;
148         proto_item      *ti;
149         int             offset = 2, len;
150         guint8          ele_id;
151
152         if (check_col(pinfo->fd, COL_PROTOCOL))
153                 col_set_str(pinfo->fd, COL_PROTOCOL, "LMI");
154
155         if (tree) {
156                 ti = proto_tree_add_item(tree, proto_lmi, tvb, 0, 3, FALSE);
157                 lmi_tree = proto_item_add_subtree(ti, ett_lmi_ele);
158
159                 proto_tree_add_uint(lmi_tree, hf_lmi_call_ref, tvb, 0, 1, tvb_get_guint8( tvb, 0));
160                 proto_tree_add_uint(lmi_tree, hf_lmi_msg_type,  tvb, 1, 1,  tvb_get_guint8( tvb, 1));
161
162         /* Display the LMI elements */
163                 while( offset < tvb_length( tvb)){
164                         ele_id = tvb_get_guint8( tvb, offset);
165                         len =  tvb_get_guint8( tvb, offset + 1);
166
167                         ti = proto_tree_add_uint(lmi_tree, hf_lmi_inf_ele, tvb, offset, len + 2, 
168                                 tvb_get_guint8( tvb, offset));
169
170                         lmi_subtree = proto_item_add_subtree(ti, ett_lmi_ele);
171
172                         proto_tree_add_uint(lmi_subtree, hf_lmi_inf_ele, tvb, offset, 1,
173                                 tvb_get_guint8( tvb, offset));
174                         ++offset;
175                         len =  tvb_get_guint8( tvb, offset);
176                         proto_tree_add_uint(lmi_subtree, hf_lmi_inf_len, tvb, offset, 1, len);
177                         ++offset;
178                         if (( ele_id == 1) || (ele_id == 51))   
179                                 dissect_lmi_report_type( tvb, offset, lmi_subtree);
180                         else if (( ele_id == 3) || (ele_id == 53))      
181                                 dissect_lmi_link_int( tvb, offset, lmi_subtree);
182                         else if (( ele_id == 7) || (ele_id == 57))      
183                                 dissect_lmi_pvc_status( tvb, offset, lmi_subtree);
184                         offset += len;
185                 }       
186         }
187         else {
188                 lmi_tree = NULL;
189         }
190 }
191
192
193 void
194 proto_register_lmi(void)
195 {
196     static hf_register_info hf[] = {
197         { &hf_lmi_call_ref,
198           { "Call reference", "lmi.cmd", FT_UINT8, BASE_HEX, NULL, 0, 
199                 "Call Reference", HFILL }},
200
201         { &hf_lmi_msg_type,
202           { "Message Type", "lmi.msg_type", FT_UINT8, BASE_HEX, VALS(msg_type_str), 0, 
203                 "Message Type", HFILL }},
204
205         { &hf_lmi_inf_ele,
206           { "Information Element", "lmi.inf_ele", FT_UINT8, BASE_DEC, VALS(element_type_str), 0,
207                 "Information Element", HFILL }},
208         { &hf_lmi_inf_ele,
209           { "Type", "lmi.inf_ele_type", FT_UINT8, BASE_DEC, VALS(element_type_str), 0,
210                 "Information Element Type", HFILL }},
211         { &hf_lmi_inf_len,
212           { "Length", "lmi.inf_ele_len", FT_UINT8, BASE_DEC, NULL, 0,
213                 "Information Element Length", HFILL }},
214
215         { &hf_lmi_rcd_type,
216           { "Record Type", "lmi.ele_rcd_type", FT_UINT8, BASE_DEC, VALS(record_type_str), 0,
217                 "Record Type", HFILL }},
218         { &hf_lmi_send_seq,
219           { "Send Seq", "lmi.send_seq", FT_UINT8, BASE_DEC, NULL, 0,
220                 "Send Sequence", HFILL }},
221         { &hf_lmi_recv_seq,
222           { "Recv Seq", "lmi.recv_seq", FT_UINT8, BASE_DEC, NULL, 0,
223                 "Receive Sequence", HFILL }},
224         { &hf_lmi_dlci_high,
225           { "DLCI High", "lmi.dlci_hi", FT_UINT8, BASE_DEC, NULL, 0x3f,
226                 "DLCI High bits", HFILL }},
227         { &hf_lmi_dlci_low,
228           { "DLCI Low", "lmi.dlci_low", FT_UINT8, BASE_DEC, NULL, 0x78,
229                 "DLCI Low bits", HFILL }},
230         { &hf_lmi_new,
231           { "DLCI New", "lmi.dlci_new", FT_UINT8, BASE_DEC, VALS(pvc_status_new_str), 0x08,
232                 "DLCI New Flag", HFILL }},
233         { &hf_lmi_act,
234           { "DLCI Active","lmi.dlci_act", FT_UINT8, BASE_DEC, VALS(pvc_status_act_str), 0x02,
235                 "DLCI Active Flag", HFILL }},
236     };
237     static gint *ett[] = {
238         &ett_lmi,
239         &ett_lmi_ele,
240     };
241     proto_lmi = proto_register_protocol ("Local Management Interface", "LMI", "lmi");
242     proto_register_field_array (proto_lmi, hf, array_length(hf));
243     proto_register_subtree_array(ett, array_length(ett));
244
245 }
246
247 void
248 proto_reg_handoff_lmi(void)
249 {
250         dissector_add("fr.ietf", NLPID_LMI, dissect_lmi, proto_lmi);
251 }