2 * Owen Kirby <osk@exegin.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
28 #include <epan/packet.h>
29 #include <epan/prefs.h>
30 #include "packet-tcp.h"
32 /* Default SCOP Port numbers. */
33 #define SCOP_DEFAULT_PORT 17755
34 #define SCOP_DEFAULT_PORT_SECURED 17756
36 /* Structure to contain information from the SCoP packet. */
46 /* Header definitions for use with the TCP transport layer. */
47 #define SCOP_HEADER_LENGTH 4
48 #define SCOP_LENGTH_OFFSET 2
50 /* SCoP Transport Types */
51 #define SCOP_TRANSPORT_UDP 1
52 #define SCOP_TRANSPORT_TCP 2
53 #define SCOP_TRANSPORT_UDP_CCM 129
54 #define SCOP_TRANSPORT_TCP_CCM 130
55 #define SCOP_TRANSPORT_TCP_SSL 131
57 /* Service Identifier Field */
58 #define SCOP_SERVICE_SCOP 0x00
59 #define SCOP_SERVICE_BRIDGE 0x01
60 #define SCOP_SERVICE_GATEWAY 0x02
62 /* SCoP Command Values */
63 #define SCOP_CMD_HELLO 0x00
64 #define SCOP_CMD_HELLO_RESP 0x01
65 #define SCOP_CMD_HELLO_ACK 0x02
66 #define SCOP_CMD_GOODBYE 0x04
67 #define SCOP_CMD_GOODBYE_RESP 0x05
68 #define SCOP_CMD_KEEPALIVE_PING 0x06
69 #define SCOP_CMD_KEEPALIVE_PONG 0x07
71 /* Bridge Command type values. */
72 #define SCOP_BRIDGE_CMD 0x00
73 #define SCOP_BRIDGE_MSG 0x01
75 /* Function declarations */
76 void proto_reg_handoff_scop(void);
78 static void dissect_scop_zip (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
);
79 static void dissect_scop_bridge (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
);
81 static guint
get_scop_length(packet_info
*pinfo _U_
, tvbuff_t
*tvb
, int offset
);
83 /* Initialize protocol and registered fields */
84 static int proto_scop
= -1;
85 static int hf_scop_transport
= -1;
86 static int hf_scop_version
= -1;
87 static int hf_scop_length
= -1;
88 static int hf_scop_service
= -1;
89 static int hf_scop_type
= -1;
90 static int hf_scop_status
= -1;
92 static gint ett_scop
= -1;
94 static const value_string scop_transports
[] = {
95 { SCOP_TRANSPORT_UDP
, "UDP Mode 1" },
96 { SCOP_TRANSPORT_TCP
, "TCP Mode 2" },
97 { SCOP_TRANSPORT_UDP_CCM
, "UDP Mode 1 with CCM* Security" },
98 { SCOP_TRANSPORT_TCP_CCM
, "TCP Mode 2 with CCM* Security" },
99 { SCOP_TRANSPORT_TCP_SSL
, "TCP Mode 3 with SSL/TSL Tunnel" },
103 static const value_string scop_types
[] = {
104 { SCOP_CMD_HELLO
, "Hello" },
105 { SCOP_CMD_HELLO_RESP
, "Hello Response" },
106 { SCOP_CMD_HELLO_ACK
, "Hello Acknowledgment" },
107 { SCOP_CMD_GOODBYE
, "Goodbye" },
108 { SCOP_CMD_GOODBYE_RESP
, "Goodbye Response" },
109 { SCOP_CMD_KEEPALIVE_PING
, "Keep Alive Ping" },
110 { SCOP_CMD_KEEPALIVE_PONG
, "Keep Alive Pong" },
114 static const value_string scop_services
[] = {
115 { SCOP_SERVICE_SCOP
, "SCoP" },
116 { SCOP_SERVICE_BRIDGE
, "Bridge" },
117 { SCOP_SERVICE_GATEWAY
, "Gateway" },
121 static guint32 gPREF_scop_port
= SCOP_DEFAULT_PORT
;
122 static guint32 gPREF_scop_port_secured
= SCOP_DEFAULT_PORT_SECURED
;
124 /* Dissector handle */
125 static dissector_handle_t data_handle
;
126 static dissector_handle_t ieee802154_handle
;
128 /*FUNCTION:------------------------------------------------------
132 * ZigBee SCoP packet dissection routine for Wireshark.
134 * tvbuff_t *tvb - pointer to buffer containing raw packet.
135 * packet_info *pinfo - pointer to packet information fields
136 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
139 *---------------------------------------------------------------
142 dissect_scop(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
145 proto_item
*proto_root
;
146 proto_tree
*scop_tree
;
151 memset(&packet
, 0, sizeof(packet
));
153 /* Set the protocol name. */
154 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "SCoP");
156 /* Clear the info column. */
157 col_clear(pinfo
->cinfo
, COL_INFO
);
159 /* Create the protocol display tree. */
160 proto_root
= proto_tree_add_protocol_format(tree
, proto_scop
, tvb
, 0, tvb_length(tvb
),
162 scop_tree
= proto_item_add_subtree(proto_root
, ett_scop
);
164 /* Extract the SCoP Transport type. */
165 packet
.transport
= tvb_get_guint8(tvb
, offset
);
166 proto_tree_add_uint(scop_tree
, hf_scop_transport
, tvb
, offset
, 1, packet
.transport
);
169 /* Extract the SCoP Version. */
170 packet
.version
= tvb_get_guint8(tvb
, offset
);
171 proto_tree_add_uint(scop_tree
, hf_scop_version
, tvb
, offset
, 1, packet
.version
);
174 /* Extract the SCoP Packet length. */
175 packet
.length
= tvb_get_ntohs(tvb
, offset
);
176 proto_tree_add_uint(scop_tree
, hf_scop_length
, tvb
, offset
, 2, packet
.length
);
179 if ( (packet
.transport
== SCOP_TRANSPORT_UDP_CCM
)
180 || (packet
.transport
== SCOP_TRANSPORT_TCP_CCM
)) {
181 /* Decryption Failed. */
186 /* Extract the service type. */
187 packet
.service
= tvb_get_guint8(next_tvb
, offset
);
188 proto_tree_add_uint(scop_tree
, hf_scop_service
, next_tvb
, offset
, 1, packet
.service
);
191 /* Call the appropriate helper routine to dissect based on the service type. */
192 switch (packet
.service
) {
193 case SCOP_SERVICE_SCOP
:
194 dissect_scop_zip(tvb_new_subset_remaining(next_tvb
, offset
), pinfo
, scop_tree
);
196 case SCOP_SERVICE_BRIDGE
:
197 dissect_scop_bridge(tvb_new_subset_remaining(next_tvb
, offset
), pinfo
, scop_tree
);
199 case SCOP_SERVICE_GATEWAY
:
200 /* Nothing yet defined for the gateway. Fall-Through. */
202 /* Unknown Service Type. */
203 call_dissector(data_handle
, tvb_new_subset_remaining(next_tvb
, offset
), pinfo
, tree
);
207 return tvb_length(tvb
);
208 } /* dissect_scop() */
210 /*FUNCTION:------------------------------------------------------
214 * Returns the length of a SCoP packet. For use with the TCP
217 * packet_info *pinfo - pointer to packet information fields
218 * tvbuff_t *tvb - pointer to buffer containing the packet.
219 * int offset - beginning of packet.
221 * guint - Length of SCoP packet
222 *---------------------------------------------------------------
225 get_scop_length(packet_info
*pinfo _U_
, tvbuff_t
*tvb
, int offset
)
227 /* Byte 0: Protocol Type.
228 * Byte 1: Protocol Version.
229 * Bytes 2-3: Packet Length (network order).
231 return tvb_get_ntohs(tvb
, offset
+ SCOP_LENGTH_OFFSET
);
232 } /* get_scop_length */
234 /*FUNCTION:------------------------------------------------------
238 * ZigBee SCoP packet dissection routine for Wireshark.
239 * for use with TCP ports.
241 * tvbuff_t *tvb - pointer to buffer containing raw packet.
242 * packet_info *pinfo - pointer to packet information fields
243 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
246 *---------------------------------------------------------------
249 dissect_scop_tcp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
251 tcp_dissect_pdus(tvb
, pinfo
, tree
, TRUE
, SCOP_HEADER_LENGTH
, get_scop_length
, dissect_scop
, data
);
252 return tvb_length(tvb
);
253 } /* dissect_scop_tcp */
256 /*FUNCTION:------------------------------------------------------
260 * Intermediate dissector for the SCoP service type.
262 * tvbuff_t *tvb - pointer to buffer containing raw packet.
263 * packet_info *pinfo - pointer to packet information fields
264 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
267 *---------------------------------------------------------------
270 dissect_scop_zip(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
273 guint8 type
= tvb_get_guint8(tvb
, offset
);
276 /* Display the Packet type*/
277 proto_tree_add_uint(tree
, hf_scop_type
, tvb
, offset
, 1, type
);
278 proto_item_append_text(tree
, ", %s", val_to_str_const(type
, scop_types
, "Reserved Type"));
279 col_set_str(pinfo
->cinfo
, COL_INFO
, val_to_str_const(type
, scop_types
, "Reserved Type"));
282 if (type
== SCOP_CMD_HELLO_RESP
) {
283 status
= tvb_get_ntohs(tvb
, 1);
284 proto_tree_add_uint_format_value(tree
, hf_scop_status
, tvb
, offset
, 2, status
, "%s", (status
==0x0000)?"Success":"Failure");
288 /* If there are any bytes left over, pass them to the data dissector. */
289 if (offset
< tvb_length(tvb
)) {
290 tvbuff_t
*payload_tvb
= tvb_new_subset_remaining(tvb
, offset
);
291 proto_tree
*root
= proto_tree_get_root(tree
);
292 call_dissector(data_handle
, payload_tvb
, pinfo
, root
);
294 } /* dissect_scop_zip() */
296 /*FUNCTION:------------------------------------------------------
298 * dissect_scop_bridge
300 * Intermediate dissector for the Bridge service type.
302 * tvbuff_t *tvb - pointer to buffer containing raw packet.
303 * packet_info *pinfo - pointer to packet information fields
304 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
307 *---------------------------------------------------------------
310 dissect_scop_bridge(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
312 call_dissector(ieee802154_handle
, tvb
, pinfo
, proto_tree_get_root(tree
));
313 } /* dissect_scop_bridge() */
315 /*FUNCTION:------------------------------------------------------
317 * proto_register_scop
319 * SCoP protocol registration.
324 *---------------------------------------------------------------
326 void proto_register_scop(void)
328 module_t
*scop_module
;
330 static hf_register_info hf
[] = {
331 { &hf_scop_transport
,
332 { "Transport Type", "scop.transport", FT_UINT8
, BASE_DEC
, VALS(scop_transports
), 0x0,
333 "The type of transport used.", HFILL
}},
336 { "Version", "scop.version", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
337 "The version of the sniffer.", HFILL
}},
340 { "Length", "scop.length", FT_UINT16
, BASE_DEC
, NULL
, 0x0,
344 { "Service Identifier", "scop.service", FT_UINT8
, BASE_DEC
, VALS(scop_services
), 0x0,
348 { "Packet Type", "scop.type", FT_UINT8
, BASE_DEC
, VALS(scop_types
), 0x0,
349 "Service-specific packet type.", HFILL
}},
352 { "Status", "scop.status", FT_UINT16
, BASE_HEX
, NULL
, 0x0,
353 "Status of the SCoP Command.", HFILL
}}
356 static gint
*ett
[] = {
360 /* Register protocol name and description. */
361 proto_scop
= proto_register_protocol("ZigBee SCoP", "SCoP", "scop");
363 /* Register header fields and subtrees. */
364 proto_register_field_array(proto_scop
, hf
, array_length(hf
));
365 proto_register_subtree_array(ett
, array_length(ett
));
367 /* Register preferences module */
368 scop_module
= prefs_register_protocol(proto_scop
, proto_reg_handoff_scop
);
370 /* Register preferences */
371 prefs_register_uint_preference(scop_module
, "port", "SCoP Port",
372 "Set the port for SCoP\n",
373 10, &gPREF_scop_port
);
374 prefs_register_uint_preference(scop_module
, "port_secure", "SCoP Secured Port",
375 "Set the port for secured SCoP\n",
376 10, &gPREF_scop_port_secured
);
378 /* Register dissector with Wireshark. */
379 new_register_dissector("scop.udp", dissect_scop
, proto_scop
);
380 new_register_dissector("scop.tcp", dissect_scop_tcp
, proto_scop
);
381 } /* proto_register_scop() */
383 /*FUNCTION:------------------------------------------------------
385 * proto_reg_handoff_scop
387 * Registers the zigbee dissector with Wireshark.
388 * Will be called every time 'apply' is pressed in the preferences menu.
393 *---------------------------------------------------------------
395 void proto_reg_handoff_scop(void)
397 static gboolean inited
= FALSE
;
398 static guint32 lastPort
;
399 static guint32 lastPort_secured
;
401 static dissector_handle_t scop_udp_handle
;
402 static dissector_handle_t scop_tcp_handle
;
405 scop_udp_handle
= find_dissector("scop.udp");
406 scop_tcp_handle
= find_dissector("scop.tcp");
407 ieee802154_handle
= find_dissector("wpan_nofcs");
408 data_handle
= find_dissector("data");
411 dissector_delete_uint("udp.port", lastPort
, scop_udp_handle
);
412 dissector_delete_uint("tcp.port", lastPort
, scop_tcp_handle
);
413 dissector_delete_uint("udp.port", lastPort_secured
, scop_udp_handle
);
414 dissector_delete_uint("tcp.port", lastPort_secured
, scop_tcp_handle
);
416 dissector_add_uint("udp.port", gPREF_scop_port
, scop_udp_handle
);
417 dissector_add_uint("tcp.port", gPREF_scop_port
, scop_tcp_handle
);
418 dissector_add_uint("udp.port", gPREF_scop_port_secured
, scop_udp_handle
);
419 dissector_add_uint("tcp.port", gPREF_scop_port_secured
, scop_tcp_handle
);
421 lastPort
= gPREF_scop_port
;
422 lastPort_secured
= gPREF_scop_port_secured
;
423 } /* proto_reg_handoff_scop */