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