Updated the frame relay dissector - dissect-fr.c
[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.1 2001/03/23 19:22:02 jfoster 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 "packet-osi.h"
51
52
53 static int proto_lmi = -1;
54 static int hf_lmi_call_ref = -1;
55 static int hf_lmi_msg_type = -1;
56 static int hf_lmi_inf_ele = -1;
57 static int hf_lmi_inf_len = -1;
58                         
59 static int hf_lmi_rcd_type = -1;
60 static int hf_lmi_send_seq = -1;
61 static int hf_lmi_recv_seq = -1;
62 static int hf_lmi_dlci_high = -1;
63 static int hf_lmi_dlci_low = -1;
64 static int hf_lmi_new = -1;
65 static int hf_lmi_act = -1;
66
67 static gint ett_lmi = -1;
68 static gint ett_lmi_ele = -1;
69
70 #define NLPID_LMI 0x09          /* NLPID value for LMI */
71
72 #ifdef _OLD_
73 /*
74  * Bits in the address field.
75  */
76 #define LMI_CMD         0xf000  /* LMI Command */
77 #define LMI_SEQ         0x0fff  /* LMI Sequence number */
78
79 #endif
80
81 static const value_string msg_type_str[] = {
82         {0x75, "Status Enquiry"},
83         {0x7D, "Status"},
84         { 0,       NULL }
85         };
86
87 static const value_string element_type_str[] = {
88
89 /*** These are the ANSI values ***/
90         {0x01, "Report"},
91         {0x03, "Keep Alive"},
92         {0x07, "PVC Status"},
93
94 /*** These are the ITU values ***/
95         {0x51, "Report"},
96         {0x53, "Keep Alive"},
97         {0x07, "PVC Status"},
98
99         { 0,       NULL }
100         };
101
102 static const value_string record_type_str[] = {
103         {0x00, "Full Status"},
104         {0x01, "Link Integrity Verification Only"},
105         {0x02, "Single PVC"},
106         { 0,       NULL }
107         };
108
109 static const value_string pvc_status_new_str[] = {
110         {0x00, "PVC already present"},
111         {0x01, "PVC is new"},
112         { 0,       NULL }
113         };
114
115 static const value_string pvc_status_act_str[] = {
116         {0x00, "PVC is Inactive"},
117         {0x01, "PVC is Acive"},
118         { 0,       NULL }
119         };
120
121 static void
122 dissect_lmi_report_type(tvbuff_t *tvb, int offset, proto_tree *tree)
123 {
124         proto_tree_add_uint(tree, hf_lmi_rcd_type, tvb, offset, 1, tvb_get_guint8( tvb, offset));
125 }
126
127 static void
128 dissect_lmi_link_int(tvbuff_t *tvb, int offset, proto_tree *tree)
129 {
130         proto_tree_add_uint(tree, hf_lmi_send_seq, tvb, offset, 1, tvb_get_guint8( tvb, offset));
131         ++offset;
132         proto_tree_add_uint(tree, hf_lmi_recv_seq, tvb, offset, 0, tvb_get_guint8( tvb, offset));
133
134 }
135
136 static void
137 dissect_lmi_pvc_status(tvbuff_t *tvb, int offset, proto_tree *tree)
138 {
139         proto_tree_add_uint(tree, hf_lmi_dlci_high, tvb, offset, 1, tvb_get_guint8( tvb, offset));
140         ++offset;
141         proto_tree_add_uint(tree, hf_lmi_dlci_low, tvb, offset, 1, tvb_get_guint8( tvb, offset));
142         ++offset;
143         proto_tree_add_uint(tree, hf_lmi_new, tvb, offset, 1, tvb_get_guint8( tvb, offset));
144         proto_tree_add_uint(tree, hf_lmi_act, tvb, offset, 1, tvb_get_guint8( tvb, offset));
145 }
146
147 static void
148 dissect_lmi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
149 {
150         proto_tree      *lmi_tree, *lmi_subtree;
151         proto_item      *ti;
152         int             offset = 2, len;
153         guint8          ele_id;
154
155         if (check_col(pinfo->fd, COL_PROTOCOL))
156                 col_set_str(pinfo->fd, COL_PROTOCOL, "LMI");
157
158         if (tree) {
159                 ti = proto_tree_add_item(tree, proto_lmi, tvb, 0, 3, FALSE);
160                 lmi_tree = proto_item_add_subtree(ti, ett_lmi_ele);
161
162                 proto_tree_add_uint(lmi_tree, hf_lmi_call_ref, tvb, 0, 1, tvb_get_guint8( tvb, 0));
163                 proto_tree_add_uint(lmi_tree, hf_lmi_msg_type,  tvb, 1, 1,  tvb_get_guint8( tvb, 1));
164
165         /* Display the LMI elements */
166                 while( offset < tvb_length( tvb)){
167                         ele_id = tvb_get_guint8( tvb, offset);
168                         len =  tvb_get_guint8( tvb, offset + 1);
169
170                         ti = proto_tree_add_uint(lmi_tree, hf_lmi_inf_ele, tvb, offset, len + 2, 
171                                 tvb_get_guint8( tvb, offset));
172
173                         lmi_subtree = proto_item_add_subtree(ti, ett_lmi_ele);
174
175                         proto_tree_add_uint(lmi_subtree, hf_lmi_inf_ele, tvb, offset, 1,
176                                 tvb_get_guint8( tvb, offset));
177                         ++offset;
178                         len =  tvb_get_guint8( tvb, offset);
179                         proto_tree_add_uint(lmi_subtree, hf_lmi_inf_len, tvb, offset, 1, len);
180                         ++offset;
181                         if (( ele_id == 1) || (ele_id == 51))   
182                                 dissect_lmi_report_type( tvb, offset, lmi_subtree);
183                         else if (( ele_id == 3) || (ele_id == 53))      
184                                 dissect_lmi_link_int( tvb, offset, lmi_subtree);
185                         else if (( ele_id == 7) || (ele_id == 57))      
186                                 dissect_lmi_pvc_status( tvb, offset, lmi_subtree);
187                         offset += len;
188                 }       
189         }
190         else {
191                 lmi_tree = NULL;
192         }
193 }
194
195
196 void
197 proto_register_lmi(void)
198 {
199     static hf_register_info hf[] = {
200         { &hf_lmi_call_ref,
201           { "Call reference", "lmi.cmd", FT_UINT8, BASE_HEX, NULL, 0, 
202                 "Call Reference" }},
203
204         { &hf_lmi_msg_type,
205           { "Message Type", "lmi.msg_type", FT_UINT8, BASE_HEX, VALS(msg_type_str), 0, 
206                 "Message Type" }},
207
208         { &hf_lmi_inf_ele,
209           { "Information Element", "lmi.inf_ele", FT_UINT8, BASE_DEC, VALS(element_type_str), 0,
210                 "Information Element" }},
211         { &hf_lmi_inf_ele,
212           { "Type", "lmi.inf_ele_type", FT_UINT8, BASE_DEC, VALS(element_type_str), 0,
213                 "Information Element Type" }},
214         { &hf_lmi_inf_len,
215           { "Length", "lmi.inf_ele_len", FT_UINT8, BASE_DEC, NULL, 0,
216                 "Information Element Length" }},
217
218         { &hf_lmi_rcd_type,
219           { "Record Type", "lmi.ele_rcd_type", FT_UINT8, BASE_DEC, VALS(record_type_str), 0,
220                 "Record Type" }},
221         { &hf_lmi_send_seq,
222           { "Send Seq", "lmi.send_seq", FT_UINT8, BASE_DEC, NULL, 0,
223                 "Send Sequence" }},
224         { &hf_lmi_recv_seq,
225           { "Recv Seq", "lmi.recv_seq", FT_UINT8, BASE_DEC, NULL, 0,
226                 "Receive Sequence" }},
227         { &hf_lmi_dlci_high,
228           { "DLCI High", "lmi.dlci_hi", FT_UINT8, BASE_DEC, NULL, 0x3f,
229                 "DLCI High bits" }},
230         { &hf_lmi_dlci_low,
231           { "DLCI Low", "lmi.dlci_low", FT_UINT8, BASE_DEC, NULL, 0x78,
232                 "DLCI Low bits" }},
233         { &hf_lmi_new,
234           { "DLCI New", "lmi.dlci_new", FT_UINT8, BASE_DEC, VALS(pvc_status_new_str), 0x08,
235                 "DLCI New Flag" }},
236         { &hf_lmi_act,
237           { "DLCI Active","lmi.dlci_act", FT_UINT8, BASE_DEC, VALS(pvc_status_act_str), 0x02,
238                 "DLCI Active Flag" }},
239     };
240     static gint *ett[] = {
241         &ett_lmi,
242         &ett_lmi_ele,
243     };
244     proto_lmi = proto_register_protocol ("Local Management Interface", "LMI", "lmi");
245     proto_register_field_array (proto_lmi, hf, array_length(hf));
246     proto_register_subtree_array(ett, array_length(ett));
247
248 }
249
250 void
251 proto_reg_handoff_lmi(void)
252 {
253         dissector_add("fr.ietf", NLPID_LMI, dissect_lmi, proto_lmi);
254 }