3 * Dissector for the Skinny Client Control Protocol
4 * (The "D-Channel"-Protocol for Cisco Systems' IP-Phones)
5 * Copyright 2001, Joerg Mayer (email: see AUTHORS file)
7 * This file is based on packet-aim.c, which is
8 * Copyright 2000, Ralf Hoelzer <ralf@well.com>
10 * $Id: packet-skinny.c,v 1.6 2001/12/03 03:59:39 guy Exp $
12 * Ethereal - Network traffic analyzer
13 * By Gerald Combs <gerald@ethereal.com>
14 * Copyright 1998 Gerald Combs
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 /* This implementation is based on a draft version of the 3.0
45 * #ifdef HAVE_SYS_TYPES_H
46 * # include <sys/types.h>
49 * #ifdef HAVE_NETINET_IN_H
50 * # include <netinet/in.h>
53 * #include <glib.h> // already in packet.h -> tvbuff.h
55 * #ifdef NEED_SNPRINTF_H
56 * # include "snprintf.h"
62 * #include "strutil.h"
65 #define TCP_PORT_SKINNY 2000
67 /* I will probably need this again when I change things
68 * to function pointers, but let me use the existing
69 * infrastructure for now
77 static const value_string message_id[] = {
79 /* Station -> Callmanager */
80 {0x0000, "KeepAliveMessage"},
81 {0x0001, "RegisterMessage"},
82 {0x0002, "IpPortMessage"},
83 {0x0003, "KeypadButtonMessage"},
84 {0x0004, "EnblocCallMessage"},
85 {0x0005, "StimulusMessage"},
86 {0x0006, "OffHookMessage"},
87 {0x0007, "OnHookMessage"},
88 {0x0008, "HookFlashMessage"},
89 {0x0009, "ForwardStatReqMessage"},
90 {0x000A, "SpeedDialStatReqMessage"},
91 {0x000B, "LineStatReqMessage"},
92 {0x000C, "ConfigStatReqMessage"},
93 {0x000D, "TimeDateReqMessage"},
94 {0x000E, "ButtonTemplateReqMessage"},
95 {0x000F, "VersionReqMessage"},
96 {0x0010, "CapabilitiesResMessage"},
97 {0x0011, "MediaPortListMessage"},
98 {0x0012, "ServerReqMessage"},
99 {0x0020, "AlarmMessage"},
100 {0x0021, "MulticastMediaReceptionAck"},
101 {0x0022, "OpenReceiveChannelAck"},
102 {0x0023, "ConnectionStatisticsRes"},
103 {0x0024, "OffHookWithCgpnMessage"},
104 {0x0025, "SoftKeySetReqMessage"},
105 {0x0026, "SoftKeyEventMessage"},
106 {0x0027, "UnregisterMessage"},
107 {0x0028, "SoftKeyEventMessage"},
108 {0x0029, "RegisterTokenReq"},
110 /* Callmanager -> Station */
111 /* 0x0000, 0x0003? */
112 {0x0081, "RegisterAckMessage"},
113 {0x0082, "StartToneMessage"},
114 {0x0083, "StopToneMessage"},
115 {0x0085, "SetRingerMessage"},
116 {0x0086, "SetLampMessage"},
117 {0x0087, "SetHkFDetectMessage"},
118 {0x0088, "SetSpeakerModeMessage"},
119 {0x0089, "SetMicroModeMessage"},
120 {0x008A, "StartMediaTransmission"},
121 {0x008B, "StopMediaTransmission"},
122 {0x008C, "StartMediaReception"},
123 {0x008D, "StopMediaReception"},
124 {0x008F, "CallInfoMessage"},
125 {0x0090, "ForwardStatMessage"},
126 {0x0091, "SpeedDialStatMessage"},
127 {0x0092, "LineStatMessage"},
128 {0x0093, "ConfigStatMessage"},
129 {0x0094, "DefineTimeDate"},
130 {0x0095, "StartSessionTransmission"},
131 {0x0096, "StopSessionTransmission"},
132 {0x0097, "ButtonTemplateMessage"},
133 {0x0098, "VersionMessage"},
134 {0x0099, "DisplayTextMessage"},
135 {0x009A, "ClearDisplay"},
136 {0x009B, "CapabilitiesReqMessage"},
137 {0x009C, "EnunciatorCommandMessage"},
138 {0x009D, "RegisterRejectMessage"},
139 {0x009E, "ServerResMessage"},
141 {0x0100, "KeepAliveAckMessage"},
142 {0x0101, "StartMulticastMediaReception"},
143 {0x0102, "StartMulticastMediaTransmission"},
144 {0x0103, "StopMulticastMediaReception"},
145 {0x0104, "StopMulticastMediaTransmission"},
146 {0x0105, "OpenReceiveChannel"},
147 {0x0106, "CloseReceiveChannel"},
148 {0x0107, "ConnectionStatisticsReq"},
149 {0x0108, "SoftKeyTemplateResMessage"},
150 {0x0109, "SoftKeySetResMessage"},
151 {0x0110, "SelectSoftKeysMessage"},
152 {0x0111, "CallStateMessage"},
153 {0x0112, "DisplayPromptStatusMessage"},
154 {0x0113, "ClearPromptStatusMessage"},
155 {0x0114, "DisplayNotifyMessage"},
156 {0x0115, "ClearNotifyMessage"},
157 {0x0116, "ActivateCallPlaneMessage"},
158 {0x0117, "DeactivateCallPlaneMessage"},
159 {0x0118, "UnregisterAckMessage"},
160 {0x0119, "BackSpaceReqMessage"},
161 {0x011A, "RegisterTokenAck"},
162 {0x011B, "RegisterTokenReject"},
164 {0 , NULL} /* needed for value_string automagic */
167 static void dissect_skinny(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
169 /* Initialize the protocol and registered fields */
170 static int proto_skinny = -1;
171 static int hf_skinny_data_length = -1;
172 static int hf_skinny_reserved = -1;
173 static int hf_skinny_messageid = -1;
175 /* Initialize the subtree pointers */
176 static gint ett_skinny = -1;
178 static dissector_handle_t data_handle;
180 /* Code to actually dissect the packets */
181 static void dissect_skinny(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
183 /* The general structure of a packet: {IP-Header|TCP-Header|n*SKINNY}
184 * SKINNY-Packet: {Header(Size, Reserved)|Data(MessageID, Message-Data)}
188 guint32 hdr_data_length;
189 guint32 hdr_reserved;
190 guint32 data_messageid;
191 gchar *messageid_str;
194 /* Set up structures we will need to add the protocol subtree and manage it */
196 proto_tree *skinny_tree = NULL;
198 /* check, if this is really an SKINNY packet, they start with a length + 0 */
200 /* get relevant header information */
201 hdr_data_length = tvb_get_letohl(tvb, 0);
202 hdr_reserved = tvb_get_letohl(tvb, 4);
203 data_messageid = tvb_get_letohl(tvb, 8);
204 data_size = MIN(8+hdr_data_length, tvb_length(tvb)) - 0xC;
206 /* hdr_data_length > 1024 is just a heuristic. Better values/checks welcome */
207 if (hdr_data_length < 4 || hdr_data_length > 1024 || hdr_reserved != 0) {
208 /* Not an SKINNY packet, just happened to use the same port */
209 call_dissector(data_handle,tvb, pinfo, tree);
213 /* Make entries in Protocol column and Info column on summary display */
214 if (check_col(pinfo->fd, COL_PROTOCOL))
215 col_set_str(pinfo->fd, COL_PROTOCOL, "SKINNY");
217 if (check_col(pinfo->fd, COL_INFO))
218 col_add_str(pinfo->fd, COL_INFO, "Skinny Client Control Protocol");
220 /* In the interest of speed, if "tree" is NULL, don't do any work not
221 * necessary to generate protocol tree items. */
223 ti = proto_tree_add_item(tree, proto_skinny, tvb, 0,
224 data_size + 0xC, FALSE);
225 skinny_tree = proto_item_add_subtree(ti, ett_skinny);
226 proto_tree_add_uint(skinny_tree, hf_skinny_data_length, tvb,
227 0, 4, hdr_data_length);
228 proto_tree_add_uint(skinny_tree, hf_skinny_reserved, tvb,
231 messageid_str = val_to_str(data_messageid, message_id, "0x%08X (Unknown)");
232 if (check_col(pinfo->fd, COL_INFO)) {
233 col_add_str(pinfo->fd, COL_INFO, messageid_str);
236 proto_tree_add_uint(skinny_tree, hf_skinny_messageid, tvb,
237 8, 4, data_messageid /* FIXME: add messageid_str */ );
239 proto_tree_add_protocol_format(skinny_tree, proto_skinny, tvb,
241 data_size, "Data (%d byte%s)", data_size,
242 plurality(data_size, "", "s"));
246 /*FIXME: call dissect_skinny recursively until all data is used up */
249 /* Register the protocol with Ethereal */
251 proto_register_skinny(void)
254 /* Setup list of header fields */
255 static hf_register_info hf[] = {
256 { &hf_skinny_data_length,
257 { "Data Length", "skinny.data_length",
258 FT_UINT32, BASE_HEX, NULL, 0x0,
259 "Number of bytes in the data portion.",
262 { &hf_skinny_reserved,
263 { "Reserved", "skinny.reserved",
264 FT_UINT32, BASE_HEX, NULL, 0x0,
265 "Reserved for furture(?) use.",
268 /* FIXME: Enable use of message name ??? */
269 { &hf_skinny_messageid,
270 { "Message ID", "skinny.messageid",
271 FT_UINT32, BASE_HEX, VALS(message_id), 0x0,
272 "The function requested/done with this message.",
277 /* Setup protocol subtree array */
278 static gint *ett[] = {
282 /* Register the protocol name and description */
283 proto_skinny = proto_register_protocol("Skinny Client Control Protocol",
286 /* Required function calls to register the header fields and subtrees used */
287 proto_register_field_array(proto_skinny, hf, array_length(hf));
288 proto_register_subtree_array(ett, array_length(ett));
292 proto_reg_handoff_skinny(void)
294 dissector_handle_t skinny_handle;
296 data_handle = find_dissector("data");
297 skinny_handle = create_dissector_handle(dissect_skinny, proto_skinny);
298 dissector_add("tcp.port", TCP_PORT_SKINNY, skinny_handle);