3 * Routines to dissect WTP component of WAP traffic.
5 * $Id: packet-wtp.c,v 1.14 2001/06/18 02:17:54 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Didier Jorand
11 * WAP dissector based on original work by Ben Fowler
12 * Updated by Neil Hunter <neil.hunter@energis-squared.com>
13 * WTLS support by Alexandre P. Ferreira (Splice IP)
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #ifdef HAVE_SYS_TYPES_H
38 # include <sys/types.h>
41 #ifdef HAVE_NETINET_IN_H
42 # include <netinet/in.h>
45 #ifdef NEED_SNPRINTF_H
51 # include "snprintf.h"
57 #include "packet-wap.h"
58 #include "packet-wtp.h"
59 #include "packet-wsp.h"
61 static const true_false_string continue_truth = {
66 static const true_false_string RID_truth = {
71 static const true_false_string TIDNew_truth = {
76 static const true_false_string tid_response_truth = {
81 static const true_false_string UP_truth = {
82 "User Acknowledgement required" ,
83 "User Acknowledgement optional"
86 static const true_false_string TVETOK_truth = {
91 static const value_string vals_pdu_type[] = {
97 { 5, "Segmented Invoke" },
98 { 6, "Segmented Result" },
99 { 7, "Negative Ack" },
103 static const value_string vals_transmission_trailer[] = {
104 { 0, "Not last packet" },
105 { 1, "Last packet of message" },
106 { 2, "Last packet of group" },
107 { 3, "Re-assembly not supported" },
111 static const value_string vals_version[] = {
119 static const value_string vals_abort_type[] = {
125 static const value_string vals_abort_reason_provider[] = {
127 { 0x01, "Protocol Error" },
128 { 0x02, "Invalid TID" },
129 { 0x03, "Not Implemented Class 2" },
130 { 0x04, "Not Implemented SAR" },
131 { 0x05, "Not Implemented User Acknowledgement" },
132 { 0x06, "WTP Version Zero" },
133 { 0x07, "Capacity Temporarily Exceeded" },
134 { 0x08, "No Response" },
135 { 0x09, "Message Too Large" },
139 /* File scoped variables for the protocol and registered fields */
140 static int proto_wtp = HF_EMPTY;
142 /* These fields used by fixed part of header */
143 static int hf_wtp_header_fixed_part = HF_EMPTY;
144 static int hf_wtp_header_flag_continue = HF_EMPTY;
145 static int hf_wtp_header_pdu_type = HF_EMPTY;
146 static int hf_wtp_header_flag_Trailer = HF_EMPTY;
147 static int hf_wtp_header_flag_RID = HF_EMPTY;
148 static int hf_wtp_header_flag_TID = HF_EMPTY;
149 static int hf_wtp_header_flag_TID_response = HF_EMPTY;
151 /* These fields used by Invoke packets */
152 static int hf_wtp_header_Inv_version = HF_EMPTY;
153 static int hf_wtp_header_Inv_flag_TIDNew = HF_EMPTY;
154 static int hf_wtp_header_Inv_flag_UP = HF_EMPTY;
155 static int hf_wtp_header_Inv_Reserved = HF_EMPTY;
156 static int hf_wtp_header_Inv_TransactionClass = HF_EMPTY;
159 static int hf_wtp_header_variable_part = HF_EMPTY;
160 static int hf_wtp_data = HF_EMPTY;
162 static int hf_wtp_header_Ack_flag_TVETOK = HF_EMPTY;
163 static int hf_wtp_header_Abort_type = HF_EMPTY;
164 static int hf_wtp_header_Abort_reason_provider = HF_EMPTY;
165 static int hf_wtp_header_Abort_reason_user = HF_EMPTY;
166 static int hf_wtp_header_sequence_number = HF_EMPTY;
167 static int hf_wtp_header_missing_packets = HF_EMPTY;
169 /* Initialize the subtree pointers */
170 static gint ett_wtp = ETT_EMPTY;
171 static gint ett_header = ETT_EMPTY;
173 /* Handle for WSP dissector */
174 static dissector_handle_t wsp_handle;
177 static char transaction_class(unsigned char octet);
178 static char pdu_type(unsigned char octet);
179 static char retransmission_indicator(unsigned char octet);
181 /* Code to actually dissect the packets */
183 dissect_wtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
185 frame_data *fdata = pinfo->fd;
188 int offCur = 0; /* current offset from start of WTP data */
190 /* bytes at offset 0 - 3 */
192 unsigned char b0 = pd[offset + 0];
193 unsigned char b3 = pd[offset + 3];
197 /* continuation flag */
203 /* Set up structures we will need to add the protocol subtree and manage it */
205 proto_tree *wtp_tree;
206 proto_tree *wtp_header_fixed;
209 char clsTransaction = ' ';
211 int numMissing = 0; /* Number of missing packets in a negative ack */
213 tvbuff_t *wsp_tvb = NULL;
215 /* Make entries in Protocol column and Info column of summary display */
218 fprintf( stderr, "dissect_wtp: (Entering) Frame data at %p\n", fdata );
219 fprintf( stderr, "dissect_wtp: tvb length is %d\n", tvb_reported_length( tvb ) );
221 /* Display protocol type depending on the port */
222 if (check_col(fdata, COL_PROTOCOL))
224 switch ( pinfo->match_port )
226 case UDP_PORT_WTP_WSP:
227 col_add_fstr(fdata, COL_PROTOCOL, "WTP+WSP" );
229 case UDP_PORT_WTLS_WTP_WSP:
230 col_add_fstr(fdata, COL_PROTOCOL, "WTLS+WTP+WSP" );
236 if (check_col(fdata, COL_INFO)) {
237 col_clear(fdata, COL_INFO);
240 b0 = tvb_get_guint8 (tvb, offCur + 0);
242 fRID = retransmission_indicator( b0 );
243 pdut = pdu_type( b0 );
245 /* Develop the string to put in the Info column */
246 cchInfo = snprintf( szInfo, sizeof( szInfo ), "WTP %s",
247 val_to_str(pdut, vals_pdu_type, "Unknown PDU type 0x%x"));
251 clsTransaction = transaction_class( tvb_get_guint8 (tvb, offCur + 3) );
252 snprintf( szInfo + cchInfo, sizeof( szInfo ) - cchInfo, " Class %d", clsTransaction );
255 case SEGMENTED_INVOKE:
256 case SEGMENTED_RESULT:
266 /* Varible number of missing packets */
267 numMissing = tvb_get_guint8 (tvb, offCur + 3);
268 cbHeader = numMissing + 4;
276 strcat( szInfo, " R" );
280 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );
283 /* This field shows up as the "Info" column in the display; you should make
284 it, if possible, summarize what's in the packet, so that a user looking
285 at the list of packets can tell what type of packet it is. */
286 if (check_col(fdata, COL_INFO)) {
288 fprintf( stderr, "dissect_wtp: (6) About to set info_col header to %s\n", szInfo );
290 col_add_str(fdata, COL_INFO, szInfo );
292 /* In the interest of speed, if "tree" is NULL, don't do any work not
293 necessary to generate protocol tree items. */
296 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );
298 ti = proto_tree_add_item(tree, proto_wtp, tvb, offCur, cbHeader, bo_little_endian);
300 fprintf( stderr, "dissect_wtp: (7) Returned from proto_tree_add_item\n" );
302 wtp_tree = proto_item_add_subtree(ti, ett_wtp);
304 /* Code to process the packet goes here */
307 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );
308 fprintf( stderr, "dissect_wtp: offCur = %d\n", offCur );
309 fprintf( stderr, "dissect_wtp: About to call proto_tree_add_item with %p %d %p %d %d %d\n",
310 wtp_tree, hf_wtp_header_fixed_part, tvb, offCur, cbHeader, bo_little_endian );
311 ti = proto_tree_add_item( wtp_tree, hf_wtp_header_fixed_part, tvb, offCur, cbHeader, bo_little_endian );
312 fprintf( stderr, "dissect_wtp: (6) Returned from proto_tree_add_item\n" );
314 wtp_header_fixed = proto_item_add_subtree(
319 /* Add common items: only CON and PDU Type */
320 ti = proto_tree_add_item(
321 wtp_header_fixed, /* tree */
322 hf_wtp_header_flag_continue, /* id */
324 offCur, /* start of high light */
325 1, /* length of high light */
328 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_pdu_type, tvb, offCur, 1, bo_little_endian );
332 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
333 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
334 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
335 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
337 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_version , tvb, offCur + 3, 1, bo_little_endian );
338 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_flag_TIDNew, tvb, offCur + 3, 1, bo_little_endian );
339 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_flag_UP, tvb, offCur + 3, 1, bo_little_endian );
340 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_Reserved, tvb, offCur + 3, 1, bo_little_endian );
341 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_TransactionClass, tvb, offCur + 3, 1, bo_little_endian );
345 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
346 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
347 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
348 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
352 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Ack_flag_TVETOK, tvb, offCur, 1, bo_big_endian );
354 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
355 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
356 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
360 abortType = tvb_get_guint8 (tvb, offCur) & 0x07;
361 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_type , tvb, offCur , 1, bo_little_endian );
362 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
363 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
365 if (abortType == PROVIDER)
367 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_reason_provider , tvb, offCur + 3 , 1, bo_little_endian );
369 else if (abortType == USER)
371 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_reason_user , tvb, offCur + 3 , 1, bo_little_endian );
375 case SEGMENTED_INVOKE:
376 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
377 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
378 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
379 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
381 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + 3, 1, bo_little_endian );
384 case SEGMENTED_RESULT:
385 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
386 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
387 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
388 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
390 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + 3, 1, bo_little_endian );
394 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
395 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
396 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
398 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_missing_packets , tvb, offCur + 3, 1, bo_little_endian );
399 /* Iterate through missing packets */
400 for (i=0; i<numMissing; i++)
402 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + i, 1, bo_little_endian );
411 /* There is a variable part if the Con flag is set */
412 ti = proto_tree_add_bytes_format(
414 hf_wtp_header_variable_part, /* id */
416 offCur + 4, /* start */
418 "What should go here!", /* value */
419 "Header (Variable part) %02X %02X %02X %02X" , /* format */
423 /* There is no variable part */
424 }; /* End of variable part of header */
428 fprintf( stderr, "dissect_wtp: (4) tree was %p\n", tree );
432 /* Any remaining data ought to be WSP data,
433 * so hand off to the WSP dissector */
434 if (tvb_reported_length (tvb) > cbHeader)
436 wsp_tvb = tvb_new_subset(tvb, cbHeader, -1,
437 tvb_reported_length (tvb)-cbHeader);
438 call_dissector(wsp_handle, wsp_tvb, pinfo, tree);
442 fprintf( stderr, "dissect_wtp: (leaving) fdata->cinfo is %p\n", fdata->cinfo );
446 static char pdu_type(unsigned char octet)
448 char ch = (octet >> 3) & 0x0F;
449 /* Note pdu type must not be 0x00 */
453 static char transaction_class(unsigned char octet)
455 char ch = (octet >> 0) & 0x03; /* ......XX */
459 static char retransmission_indicator(unsigned char octet)
461 switch ( pdu_type(octet) ) {
465 case SEGMENTED_INVOKE:
466 case SEGMENTED_RESULT:
468 return (octet >> 0) & 0x01; /* ......,X */
474 /* Register the protocol with Ethereal */
476 proto_register_wtp(void)
479 /* Setup list of header fields */
480 static hf_register_info hf[] = {
481 { &hf_wtp_header_fixed_part,
483 "wtp.header_fixed_part",
484 FT_BYTES, BASE_HEX, NULL, 0x0,
485 "Fixed part of the header", HFILL
488 { &hf_wtp_header_flag_continue,
491 FT_BOOLEAN, 8, TFS( &continue_truth ), 0x80,
492 "Continue Flag", HFILL
495 { &hf_wtp_header_pdu_type,
498 FT_UINT8, BASE_HEX, VALS( vals_pdu_type ), 0x78,
502 { &hf_wtp_header_flag_Trailer,
505 FT_UINT8, BASE_HEX, VALS( vals_transmission_trailer ), 0x06,
509 { &hf_wtp_header_flag_RID,
510 { "Re-transmission Indicator",
512 FT_BOOLEAN, 8, TFS( &RID_truth ), 0x01,
513 "Re-transmission Indicator", HFILL
516 { &hf_wtp_header_flag_TID_response,
519 FT_BOOLEAN, 16, TFS( &tid_response_truth ), 0x8000,
520 "TID Response", HFILL
523 { &hf_wtp_header_flag_TID,
526 FT_UINT16, BASE_HEX, NULL, 0x7FFF,
527 "Transmission ID", HFILL
530 { &hf_wtp_header_Inv_version,
532 "wtp.header.version",
533 FT_UINT8, BASE_HEX, VALS( vals_version ), 0xC0,
537 { &hf_wtp_header_Inv_flag_TIDNew,
540 FT_BOOLEAN, 8, TFS( &TIDNew_truth ), 0x20,
544 { &hf_wtp_header_Inv_flag_UP,
547 FT_BOOLEAN, 8, TFS( &UP_truth ), 0x10,
551 { &hf_wtp_header_Inv_Reserved,
554 FT_UINT8, BASE_HEX, NULL, 0x0C,
558 { &hf_wtp_header_Inv_TransactionClass,
559 { "Transaction Class",
560 "wtp.inv.transaction_class",
561 FT_UINT8, BASE_HEX, NULL, 0x03,
562 "Transaction Class", HFILL
565 { &hf_wtp_header_Ack_flag_TVETOK,
568 FT_BOOLEAN, 8, TFS( &TVETOK_truth ), 0x04,
569 "Tve/Tok flag", HFILL
572 { &hf_wtp_header_Abort_type,
575 FT_UINT8, BASE_HEX, VALS ( vals_abort_type ), 0x07,
579 { &hf_wtp_header_Abort_reason_provider,
581 "wtp.abort.reason.provider",
582 FT_UINT8, BASE_HEX, VALS ( vals_abort_reason_provider ), 0x00,
583 "Abort Reason", HFILL
586 /* Assume WSP is the user and use its reason codes */
587 { &hf_wtp_header_Abort_reason_user,
589 "wtp.abort.reason.user",
590 FT_UINT8, BASE_HEX, VALS ( vals_wsp_reason_codes ), 0x00,
591 "Abort Reason", HFILL
594 { &hf_wtp_header_sequence_number,
595 { "Packet Sequence Number",
596 "wtp.header.sequence",
597 FT_UINT8, BASE_HEX, NULL, 0x00,
598 "Packet Sequence Number", HFILL
601 { &hf_wtp_header_missing_packets,
603 "wtp.header.missing_packets",
604 FT_UINT8, BASE_HEX, NULL, 0x00,
605 "Missing Packets", HFILL
608 { &hf_wtp_header_variable_part,
609 { "Header: Variable part",
610 "wtp.header_variable_part",
611 FT_BYTES, BASE_HEX, NULL, 0x0,
612 "Variable part of the header", HFILL
618 FT_BYTES, BASE_HEX, NULL, 0x0,
624 /* Setup protocol subtree array */
625 static gint *ett[] = {
630 /* Register the protocol name and description */
631 proto_wtp = proto_register_protocol(
632 "Wireless Transaction Protocol", /* protocol name for use by ethereal */
633 "WTP", /* short version of name */
634 "wap-wsp-wtp" /* Abbreviated protocol name, should Match IANA
635 < URL:http://www.isi.edu/in-notes/iana/assignments/port-numbers/ >
639 /* Required function calls to register the header fields and subtrees used */
640 proto_register_field_array(proto_wtp, hf, array_length(hf));
641 proto_register_subtree_array(ett, array_length(ett));
645 proto_reg_handoff_wtp(void)
648 * Get a handle for the IP WSP dissector - if WTP PDUs have data, it is WSP
650 wsp_handle = find_dissector("wsp");
652 dissector_add("udp.port", UDP_PORT_WTP_WSP, dissect_wtp, proto_wtp);