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