Move the GSM SMS dissection to a dedicated subdissector (currently still within
[obnox/wireshark/wip.git] / packet-qllc.c
1 /* packet-qllc.c
2  * Routines for QLLC protocol - Qualified? LLC
3  * Gilbert Ramirez <gram@alumni.rice.edu>
4  *
5  * $Id: packet-qllc.c,v 1.8 2003/01/06 02:24:57 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 2001 Gerald Combs
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
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32
33 static int proto_qllc = -1;
34 static int hf_qllc_address = -1;
35 static int hf_qllc_control = -1;
36
37 static gint ett_qllc = -1;
38
39 static dissector_handle_t sna_handle;
40
41 #define QSM                 0x93
42 #define QDISC               0x53
43 #define QXID                0xbf
44 #define QTEST               0xf3
45 #define QRR                 0xf1
46 #define QRD                 0x53
47 #define QUA                 0x73
48 #define QDM                 0x1f
49 #define QFRMR               0x97
50 #define QUI                 0x03
51 #define QUI_NO_REPLY        0x13
52 #define QSIM                0x17
53
54 #define QRD_QDISC_VALUE     0x53
55 #define QDISC_TEXT          "QDISC"
56 #define QRD_TEXT            "QRD"
57
58 /* Control Field */
59 static const value_string qllc_control_vals[] = {
60     { QUI,          "QUI" },
61     { QUI_NO_REPLY, "QUI - reply required" },
62     { QSIM,         "QSIM" },
63     { QDM,          "QDM" },
64     { QUA,          "QUA" },
65     { QSM,          "QSM" },
66     { QFRMR,        "QFRMR" },
67     { QXID,         "QXID" },
68     { QRR,          "QRR" },
69     { QTEST,        "QTEST" },
70     { QDISC,        QDISC_TEXT },
71     { QRD,          QRD_TEXT },
72     { 0x00, NULL },
73 };
74
75
76 static void
77 dissect_qllc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
78 {
79     proto_tree  *qllc_tree = NULL;
80     proto_item  *qllc_ti = NULL;
81     gboolean    *q_bit_set = pinfo->private_data;
82     guint8      address, ctrl;
83     gboolean    command = FALSE;
84
85     /*
86      * If the Q bit isn't set, this is just SNA data.
87      */
88     if (!(*q_bit_set)) {
89         call_dissector(sna_handle, tvb, pinfo, tree);
90         return;
91     }
92
93     /* Summary information */
94     if (check_col(pinfo->cinfo, COL_PROTOCOL))
95         col_set_str(pinfo->cinfo, COL_PROTOCOL, "QLLC");
96     if (check_col(pinfo->cinfo, COL_INFO))
97         col_clear(pinfo->cinfo, COL_INFO);
98
99     if (tree) {
100         qllc_ti = proto_tree_add_item(tree, proto_qllc, tvb, 0, -1, FALSE);
101         qllc_tree = proto_item_add_subtree(qllc_ti, ett_qllc);
102     }
103
104     /* Get the address; we need it to determine if this is a
105      * COMMAND or a RESPONSE */
106     address = tvb_get_guint8(tvb, 0);
107     if (tree) {
108         proto_tree_add_item(qllc_tree, hf_qllc_address, tvb, 0, 1, FALSE);
109     }
110
111     /* The address field equals X'FF' in commands (except QRR)
112      * and anything in responses. */
113     ctrl = tvb_get_guint8(tvb, 1);
114     if (ctrl != QRR && address == 0xff) {
115         command = TRUE;
116     }
117
118
119     /* Disambiguate QRD_QDISC_VALUE, based on whether this packet is
120      * a COMMAND or RESPONSE. */
121     if (ctrl == QRD_QDISC_VALUE) {
122         if (command) {
123             if (check_col(pinfo->cinfo, COL_INFO)) {
124                 col_set_str(pinfo->cinfo, COL_INFO, QDISC_TEXT);
125             }
126             if (tree) {
127                 proto_tree_add_text(qllc_tree, tvb,
128                         1, 1, "Control Field: %s (0x%02x)", QDISC_TEXT, ctrl);
129             }
130         }
131         else {
132             if (check_col(pinfo->cinfo, COL_INFO)) {
133                 col_set_str(pinfo->cinfo, COL_INFO, QRD_TEXT);
134             }
135             if (tree) {
136                 proto_tree_add_text(qllc_tree, tvb,
137                         1, 1, "Control Field: %s (0x%02x)", QRD_TEXT, ctrl);
138             }
139         }
140
141         /* Add the field for filtering purposes */
142         if (tree) {
143             proto_tree_add_uint_hidden(qllc_tree, hf_qllc_control, tvb,
144                     1, 1, ctrl);
145         }
146     }
147     else {
148         /* Non-ambiguous control field value */
149         if (check_col(pinfo->cinfo, COL_INFO)) {
150             col_set_str(pinfo->cinfo, COL_INFO,
151                     val_to_str(ctrl, qllc_control_vals,
152                         "Control Field: 0x%02x (unknown)"));
153         }
154         if (tree) {
155             proto_tree_add_uint(qllc_tree, hf_qllc_control, tvb,
156                     1, 1, ctrl);
157         }
158     }
159
160     /* Do we have an I field ? */
161     /* XXX - I field exists for QUI too, but only for subarea nodes.
162      * Need to test for this. */
163     if (ctrl == QXID || ctrl == QTEST || ctrl == QFRMR) {
164         /* yes */
165     }
166 }
167
168 void
169 proto_register_qllc(void)
170 {
171         static hf_register_info hf[] = {
172             { &hf_qllc_address,
173                 { "Address Field",      "qllc.address", FT_UINT8, BASE_HEX, NULL, 0x0,
174                         "", HFILL }},
175
176                 { &hf_qllc_control,
177                 { "Control Field",      "qllc.control", FT_UINT8, BASE_HEX,
178                   VALS(qllc_control_vals), 0x0, "", HFILL }},
179         };
180
181         static gint *ett[] = {
182                 &ett_qllc,
183         };
184
185         proto_qllc = proto_register_protocol("Qualified Logical Link Control",
186             "QLLC", "qllc");
187         proto_register_field_array(proto_qllc, hf, array_length(hf));
188         proto_register_subtree_array(ett, array_length(ett));
189         register_dissector("qllc", dissect_qllc, proto_qllc);
190 }
191
192 void
193 proto_reg_handoff_qllc(void)
194 {
195         sna_handle = find_dissector("sna");
196 }