Add editor modelines; Adjust whitespace as needed.
[metze/wireshark/wip.git] / epan / dissectors / packet-teimanagement.c
1 /* packet-teimanagement.c
2  * Routines for LAPD TEI Management frame disassembly
3  * Rolf Fiedler <rolf.fiedler@innoventif.com>
4  * based on code by Gilbert Ramirez <gram@alumni.rice.edu>
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #include <glib.h>
28 #include <epan/packet.h>
29 #include <epan/lapd_sapi.h>
30
31 /* ISDN/LAPD references:
32  *
33  * http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/isdn.htm
34  * http://www.ece.wpi.edu/courses/ee535/hwk11cd95/agrebe/agrebe.html
35  * http://www.acacia-net.com/Clarinet/Protocol/q9213o84.htm
36  */
37
38 void proto_reg_handoff_teimanagement(void);
39 void proto_register_teimanagement(void);
40
41 static int proto_tei=-1;
42
43 static int lm_entity_id=-1;
44 static int lm_reference=-1;
45 static int lm_message=-1;
46 static int lm_action=-1;
47 static int lm_extend =-1;
48 static gint lm_subtree=-1;
49
50 #define TEI_ID_REQUEST    0x01
51 #define TEI_ID_ASSIGNED   0x02
52 #define TEI_ID_DENIED     0x03
53 #define TEI_ID_CHECK_REQ  0x04
54 #define TEI_ID_CHECK_RESP 0x05
55 #define TEI_ID_REMOVE     0x06
56 #define TEI_ID_VERIFY     0x07
57
58 static const value_string tei_msg_vals[]={
59     { TEI_ID_REQUEST,    "Identity Request"},
60     { TEI_ID_ASSIGNED,   "Identity Assigned"},
61     { TEI_ID_DENIED,     "Identity Denied"},
62     { TEI_ID_CHECK_REQ,  "Identity Check Request"},
63     { TEI_ID_CHECK_RESP, "Identity Check Response"},
64     { TEI_ID_REMOVE,     "Identity Remove"},
65     { TEI_ID_VERIFY,     "Identity Verify"},
66     { 0, NULL}
67 };
68
69 static void
70 dissect_teimanagement(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
71 {
72     proto_tree *tei_tree = NULL;
73     proto_item *tei_ti;
74     guint8 message;
75
76     col_set_str(pinfo->cinfo, COL_PROTOCOL, "TEI");
77     col_clear(pinfo->cinfo, COL_INFO);
78
79     if (tree) {
80         tei_ti = proto_tree_add_item(tree, proto_tei, tvb, 0, 5, ENC_NA);
81         tei_tree = proto_item_add_subtree(tei_ti, lm_subtree);
82
83         proto_tree_add_item(tei_tree, lm_entity_id, tvb, 0, 1, ENC_BIG_ENDIAN);
84         proto_tree_add_item(tei_tree, lm_reference,  tvb, 1, 2, ENC_BIG_ENDIAN);
85     }
86
87     message = tvb_get_guint8(tvb, 3);
88         col_add_str(pinfo->cinfo, COL_INFO,
89             val_to_str(message, tei_msg_vals, "Unknown message type (0x%04x)"));
90     if (tree) {
91         proto_tree_add_uint(tei_tree, lm_message, tvb, 3, 1, message);
92         proto_tree_add_item(tei_tree, lm_action, tvb, 4, 1, ENC_BIG_ENDIAN);
93         proto_tree_add_item(tei_tree, lm_extend, tvb, 4, 1, ENC_BIG_ENDIAN);
94     }
95 }
96
97 void
98 proto_register_teimanagement(void)
99 {
100     static gint *subtree[]={
101         &lm_subtree
102     };
103
104     static hf_register_info hf[] = {
105         { &lm_entity_id,
106           { "Entity", "tei.entity", FT_UINT8, BASE_HEX, NULL, 0x0,
107                 "Layer Management Entity Identifier", HFILL }},
108
109         { &lm_reference,
110           { "Reference", "tei.reference", FT_UINT16, BASE_DEC, NULL, 0x0,
111                 "Reference Number", HFILL }},
112
113         { &lm_message,
114           { "Msg", "tei.msg", FT_UINT8, BASE_DEC, VALS(tei_msg_vals), 0x0,
115                 "Message Type", HFILL }},
116
117         { &lm_action,
118           { "Action", "tei.action", FT_UINT8, BASE_DEC, NULL, 0xfe,
119                 "Action Indicator", HFILL }},
120
121         { &lm_extend,
122           { "Extend", "tei.extend", FT_UINT8, BASE_DEC, NULL, 0x01,
123                 "Extension Indicator", HFILL }}
124     };
125
126     proto_tei = proto_register_protocol("TEI Management Procedure, Channel D (LAPD)",
127                                          "TEI_MANAGEMENT", "tei_management");
128     proto_register_field_array (proto_tei, hf, array_length(hf));
129     proto_register_subtree_array(subtree, array_length(subtree));
130 }
131
132 void
133 proto_reg_handoff_teimanagement(void)
134 {
135     dissector_handle_t teimanagement_handle;
136
137     teimanagement_handle = create_dissector_handle(dissect_teimanagement,
138         proto_tei);
139     dissector_add_uint("lapd.sapi", LAPD_SAPI_L2, teimanagement_handle);
140 }
141
142 /*
143  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
144  *
145  * Local variables:
146  * c-basic-offset: 4
147  * tab-width: 8
148  * indent-tabs-mode: nil
149  * End:
150  *
151  * vi: set shiftwidth=4 tabstop=8 expandtab:
152  * :indentSize=4:tabSize=8:noTabs=true:
153  */