b088693db8bf25668059144ed7469faa00326d47
[obnox/wireshark/wip.git] / epan / dissectors / 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$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998
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  * ToDo:
26  *
27  * References:
28  *
29  * http://www.techfest.com/networking/wan/frrel.htm
30  * http://www.frforum.com/5000/Approved/FRF.1.2/frf1_2.pdf
31  * http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/frame.htm#xtocid18
32  * http://www.net.aapt.com.au/techref/lmimess.htm
33  * http://www.raleigh.ibm.com:80/cgi-bin/bookmgr/BOOKS/EZ305800/1.2.4.4
34  */
35
36
37 #ifdef HAVE_CONFIG_H
38 # include "config.h"
39 #endif
40
41 #include <glib.h>
42 #include <epan/packet.h>
43 #include <epan/nlpid.h>
44
45 static int proto_lmi = -1;
46 static int hf_lmi_call_ref = -1;
47 static int hf_lmi_msg_type = -1;
48 static int hf_lmi_inf_ele = -1;
49 static int hf_lmi_inf_len = -1;
50
51 static int hf_lmi_rcd_type = -1;
52 static int hf_lmi_send_seq = -1;
53 static int hf_lmi_recv_seq = -1;
54 static int hf_lmi_dlci_high = -1;
55 static int hf_lmi_dlci_low = -1;
56 static int hf_lmi_new = -1;
57 static int hf_lmi_act = -1;
58
59 static gint ett_lmi = -1;
60 static gint ett_lmi_ele = -1;
61
62 #ifdef _OLD_
63 /*
64  * Bits in the address field.
65  */
66 #define LMI_CMD         0xf000  /* LMI Command */
67 #define LMI_SEQ         0x0fff  /* LMI Sequence number */
68
69 #endif
70
71 static const value_string msg_type_str[] = {
72         {0x75, "Status Enquiry"},
73         {0x7D, "Status"},
74         { 0,       NULL }
75         };
76
77 static const value_string element_type_str[] = {
78
79 /*** These are the ANSI values ***/
80         {0x01, "Report"},
81         {0x03, "Keep Alive"},
82         {0x07, "PVC Status"},
83
84 /*** These are the ITU values ***/
85         {0x51, "Report"},
86         {0x53, "Keep Alive"},
87         {0x07, "PVC Status"},
88
89         { 0,       NULL }
90         };
91
92 static const value_string record_type_str[] = {
93         {0x00, "Full Status"},
94         {0x01, "Link Integrity Verification Only"},
95         {0x02, "Single PVC"},
96         { 0,       NULL }
97         };
98
99 static const value_string pvc_status_new_str[] = {
100         {0x00, "PVC already present"},
101         {0x01, "PVC is new"},
102         { 0,       NULL }
103         };
104
105 static const value_string pvc_status_act_str[] = {
106         {0x00, "PVC is Inactive"},
107         {0x01, "PVC is Active"},
108         { 0,       NULL }
109         };
110
111 static void
112 dissect_lmi_report_type(tvbuff_t *tvb, int offset, proto_tree *tree)
113 {
114         proto_tree_add_uint(tree, hf_lmi_rcd_type, tvb, offset, 1, tvb_get_guint8( tvb, offset));
115 }
116
117 static void
118 dissect_lmi_link_int(tvbuff_t *tvb, int offset, proto_tree *tree)
119 {
120         proto_tree_add_uint(tree, hf_lmi_send_seq, tvb, offset, 1, tvb_get_guint8( tvb, offset));
121         ++offset;
122         proto_tree_add_uint(tree, hf_lmi_recv_seq, tvb, offset, 1, tvb_get_guint8( tvb, offset));
123
124 }
125
126 static void
127 dissect_lmi_pvc_status(tvbuff_t *tvb, int offset, proto_tree *tree)
128 {
129         proto_tree_add_uint(tree, hf_lmi_dlci_high, tvb, offset, 1, tvb_get_guint8( tvb, offset));
130         ++offset;
131         proto_tree_add_uint(tree, hf_lmi_dlci_low, tvb, offset, 1, tvb_get_guint8( tvb, offset));
132         ++offset;
133         proto_tree_add_uint(tree, hf_lmi_new, tvb, offset, 1, tvb_get_guint8( tvb, offset));
134         proto_tree_add_uint(tree, hf_lmi_act, tvb, offset, 1, tvb_get_guint8( tvb, offset));
135 }
136
137 static void
138 dissect_lmi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
139 {
140         proto_tree      *lmi_tree = NULL, *lmi_subtree;
141         proto_item      *ti;
142         int             offset = 2, len;
143         guint8          msg_type;
144         guint8          ele_id;
145
146         col_set_str(pinfo->cinfo, COL_PROTOCOL, "LMI");
147         col_clear(pinfo->cinfo, COL_INFO);
148
149         if (tree) {
150                 ti = proto_tree_add_item(tree, proto_lmi, tvb, 0, 3, FALSE);
151                 lmi_tree = proto_item_add_subtree(ti, ett_lmi_ele);
152
153                 proto_tree_add_item(lmi_tree, hf_lmi_call_ref, tvb, 0, 1, ENC_BIG_ENDIAN);
154         }
155         msg_type = tvb_get_guint8( tvb, 1);
156         if (check_col(pinfo->cinfo, COL_INFO)) {
157                 col_add_str(pinfo->cinfo, COL_INFO,
158                     val_to_str(msg_type, msg_type_str, "Unknown message type (0x%02x)"));
159         }
160         if (tree) {
161                 proto_tree_add_uint(lmi_tree, hf_lmi_msg_type, tvb, 1, 1, msg_type);
162
163         /* Display the LMI elements */
164                 while (tvb_reported_length_remaining(tvb, offset) > 0) {
165                         ele_id = tvb_get_guint8( tvb, offset);
166                         len =  tvb_get_guint8( tvb, offset + 1);
167
168                         ti = proto_tree_add_text(lmi_tree, tvb, offset, len + 2,
169                                 "Information Element: %s",
170                                 val_to_str(ele_id, element_type_str, "Unknown (%u)"));
171
172                         lmi_subtree = proto_item_add_subtree(ti, ett_lmi_ele);
173
174                         proto_tree_add_uint(lmi_subtree, hf_lmi_inf_ele, tvb, offset, 1,
175                                 ele_id);
176                         ++offset;
177                         proto_tree_add_uint(lmi_subtree, hf_lmi_inf_len, tvb, offset, 1, len);
178                         ++offset;
179                         if (( ele_id == 1) || (ele_id == 51))
180                                 dissect_lmi_report_type( tvb, offset, lmi_subtree);
181                         else if (( ele_id == 3) || (ele_id == 53))
182                                 dissect_lmi_link_int( tvb, offset, lmi_subtree);
183                         else if (( ele_id == 7) || (ele_id == 57))
184                                 dissect_lmi_pvc_status( tvb, offset, lmi_subtree);
185                         offset += len;
186                 }
187         }
188         else {
189                 lmi_tree = NULL;
190         }
191 }
192
193
194 void
195 proto_register_lmi(void)
196 {
197     static hf_register_info hf[] = {
198         { &hf_lmi_call_ref,
199           { "Call reference", "lmi.cmd", FT_UINT8, BASE_HEX, NULL, 0,
200                 NULL, HFILL }},
201
202         { &hf_lmi_msg_type,
203           { "Message Type", "lmi.msg_type", FT_UINT8, BASE_HEX, VALS(msg_type_str), 0,
204                 NULL, HFILL }},
205
206         { &hf_lmi_inf_ele,
207           { "Type", "lmi.inf_ele_type", FT_UINT8, BASE_DEC, VALS(element_type_str), 0,
208                 "Information Element Type", HFILL }},
209         { &hf_lmi_inf_len,
210           { "Length", "lmi.inf_ele_len", FT_UINT8, BASE_DEC, NULL, 0,
211                 "Information Element Length", HFILL }},
212
213         { &hf_lmi_rcd_type,
214           { "Record Type", "lmi.ele_rcd_type", FT_UINT8, BASE_DEC, VALS(record_type_str), 0,
215                 NULL, HFILL }},
216         { &hf_lmi_send_seq,
217           { "Send Seq", "lmi.send_seq", FT_UINT8, BASE_DEC, NULL, 0,
218                 "Send Sequence", HFILL }},
219         { &hf_lmi_recv_seq,
220           { "Recv Seq", "lmi.recv_seq", FT_UINT8, BASE_DEC, NULL, 0,
221                 "Receive Sequence", HFILL }},
222         { &hf_lmi_dlci_high,
223           { "DLCI High", "lmi.dlci_hi", FT_UINT8, BASE_DEC, NULL, 0x3f,
224                 "DLCI High bits", HFILL }},
225         { &hf_lmi_dlci_low,
226           { "DLCI Low", "lmi.dlci_low", FT_UINT8, BASE_DEC, NULL, 0x78,
227                 "DLCI Low bits", HFILL }},
228         { &hf_lmi_new,
229           { "DLCI New", "lmi.dlci_new", FT_UINT8, BASE_DEC, VALS(pvc_status_new_str), 0x08,
230                 "DLCI New Flag", HFILL }},
231         { &hf_lmi_act,
232           { "DLCI Active","lmi.dlci_act", FT_UINT8, BASE_DEC, VALS(pvc_status_act_str), 0x02,
233                 "DLCI Active Flag", HFILL }},
234     };
235     static gint *ett[] = {
236         &ett_lmi,
237         &ett_lmi_ele,
238     };
239     proto_lmi = proto_register_protocol ("Local Management Interface", "LMI", "lmi");
240     proto_register_field_array (proto_lmi, hf, array_length(hf));
241     proto_register_subtree_array(ett, array_length(ett));
242
243 }
244
245 void
246 proto_reg_handoff_lmi(void)
247 {
248         dissector_handle_t lmi_handle;
249
250         lmi_handle = create_dissector_handle(dissect_lmi, proto_lmi);
251         dissector_add_uint("fr.ietf", NLPID_LMI, lmi_handle);
252 }