1 /* packet-wtp.c (c) 2000 Neil Hunter
2 * Base on original work by Ben Fowler
4 * Routines to dissect WTP component of WAP traffic.
6 * $Id: packet-wtp.c,v 1.8 2001/01/03 16:41:08 gram Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Didier Jorand
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
42 #ifdef NEED_SNPRINTF_H
48 # include "snprintf.h"
54 #include "packet-wap.h"
55 #include "packet-wtp.h"
56 #include "packet-wsp.h"
58 static const true_false_string continue_truth = {
63 static const true_false_string RID_truth = {
68 static const true_false_string TIDNew_truth = {
73 static const true_false_string tid_response_truth = {
78 static const true_false_string UP_truth = {
79 "User Acknowledgement required" ,
80 "User Acknowledgement optional"
83 static const true_false_string TVETOK_truth = {
88 static const value_string vals_pdu_type[] = {
94 { 5, "Segmented Invoke" },
95 { 6, "Segmented Result" },
96 { 7, "Negative Ack" },
100 static const value_string vals_transmission_trailer[] = {
101 { 0, "Not last packet" },
102 { 1, "Last packet of message" },
103 { 2, "Last packet of group" },
104 { 3, "Re-assembly not supported" },
108 static const value_string vals_version[] = {
116 static const value_string vals_abort_type[] = {
122 static const value_string vals_abort_reason_provider[] = {
124 { 0x01, "Protocol Error" },
125 { 0x02, "Invalid TID" },
126 { 0x03, "Not Implemented Class 2" },
127 { 0x04, "Not Implemented SAR" },
128 { 0x05, "Not Implemented User Acknowledgement" },
129 { 0x06, "WTP Version Zero" },
130 { 0x07, "Capacity Temporarily Exceeded" },
131 { 0x08, "No Response" },
132 { 0x09, "Message Too Large" },
136 /* File scoped variables for the protocol and registered fields */
137 static int proto_wtp = HF_EMPTY;
139 /* These fields used by fixed part of header */
140 static int hf_wtp_header_fixed_part = HF_EMPTY;
141 static int hf_wtp_header_flag_continue = HF_EMPTY;
142 static int hf_wtp_header_pdu_type = HF_EMPTY;
143 static int hf_wtp_header_flag_Trailer = HF_EMPTY;
144 static int hf_wtp_header_flag_RID = HF_EMPTY;
145 static int hf_wtp_header_flag_TID = HF_EMPTY;
146 static int hf_wtp_header_flag_TID_response = HF_EMPTY;
148 /* These fields used by Invoke packets */
149 static int hf_wtp_header_Inv_version = HF_EMPTY;
150 static int hf_wtp_header_Inv_flag_TIDNew = HF_EMPTY;
151 static int hf_wtp_header_Inv_flag_UP = HF_EMPTY;
152 static int hf_wtp_header_Inv_Reserved = HF_EMPTY;
153 static int hf_wtp_header_Inv_TransactionClass = HF_EMPTY;
156 static int hf_wtp_header_variable_part = HF_EMPTY;
157 static int hf_wtp_data = HF_EMPTY;
159 static int hf_wtp_header_Ack_flag_TVETOK = HF_EMPTY;
160 static int hf_wtp_header_Abort_type = HF_EMPTY;
161 static int hf_wtp_header_Abort_reason_provider = HF_EMPTY;
162 static int hf_wtp_header_Abort_reason_user = HF_EMPTY;
163 static int hf_wtp_header_sequence_number = HF_EMPTY;
164 static int hf_wtp_header_missing_packets = HF_EMPTY;
166 /* Initialize the subtree pointers */
167 static gint ett_wtp = ETT_EMPTY;
168 static gint ett_header = ETT_EMPTY;
170 static dissector_handle_t wsp_handle;
173 static char transaction_class(unsigned char octet);
174 static char pdu_type(unsigned char octet);
175 static char retransmission_indicator(unsigned char octet);
177 /* Code to actually dissect the packets */
179 dissect_wtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
181 frame_data *fdata = pinfo->fd;
184 int offCur = 0; /* current offset from start of WTP data */
186 /* bytes at offset 0 - 3 */
188 unsigned char b0 = pd[offset + 0];
189 unsigned char b3 = pd[offset + 3];
191 unsigned char b0 = tvb_get_guint8 (tvb, offCur + 0);
193 /* continuation flag */
194 unsigned char fCon = b0 & 0x80;
195 unsigned char fRID = retransmission_indicator( b0 );
199 /* Set up structures we will need to add the protocol subtree and manage it */
201 proto_tree *wtp_tree;
202 proto_tree *wtp_header_fixed;
204 char pdut = pdu_type( b0 );
205 char clsTransaction = ' ';
207 int numMissing = 0; /* Number of missing packets in a negative ack */
209 tvbuff_t *wsp_tvb = NULL;
211 CHECK_DISPLAY_AS_DATA(proto_wtp, tvb, pinfo, tree);
213 pinfo->current_proto = "WTP";
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" );
237 /* Develop the string to put in the Info column */
238 cchInfo = snprintf( szInfo, sizeof( szInfo ), "WTP %s", vals_pdu_type[ ( int )pdut ].strptr );
242 clsTransaction = transaction_class( tvb_get_guint8 (tvb, offCur + 3) );
243 snprintf( szInfo + cchInfo, sizeof( szInfo ) - cchInfo, " Class %d", clsTransaction );
246 case SEGMENTED_INVOKE:
247 case SEGMENTED_RESULT:
257 /* Varible number of missing packets */
258 numMissing = tvb_get_guint8 (tvb, offCur + 3);
259 cbHeader = numMissing + 4;
267 strcat( szInfo, " R" );
271 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );
274 /* This field shows up as the "Info" column in the display; you should make
275 it, if possible, summarize what's in the packet, so that a user looking
276 at the list of packets can tell what type of packet it is. */
277 if (check_col(fdata, COL_INFO)) {
279 fprintf( stderr, "dissect_wtp: (6) About to set info_col header to %s\n", szInfo );
281 col_add_str(fdata, COL_INFO, szInfo );
283 /* In the interest of speed, if "tree" is NULL, don't do any work not
284 necessary to generate protocol tree items. */
287 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );
289 ti = proto_tree_add_item(tree, proto_wtp, tvb, offCur, cbHeader, bo_little_endian);
291 fprintf( stderr, "dissect_wtp: (7) Returned from proto_tree_add_item\n" );
293 wtp_tree = proto_item_add_subtree(ti, ett_wtp);
295 /* Code to process the packet goes here */
298 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );
299 fprintf( stderr, "dissect_wtp: offCur = %d\n", offCur );
300 fprintf( stderr, "dissect_wtp: About to call proto_tree_add_item with %p %d %p %d %d %d\n",
301 wtp_tree, hf_wtp_header_fixed_part, tvb, offCur, cbHeader, bo_little_endian );
302 ti = proto_tree_add_item( wtp_tree, hf_wtp_header_fixed_part, tvb, offCur, cbHeader, bo_little_endian );
303 fprintf( stderr, "dissect_wtp: (6) Returned from proto_tree_add_item\n" );
305 wtp_header_fixed = proto_item_add_subtree(
310 /* Add common items: only CON and PDU Type */
311 ti = proto_tree_add_item(
312 wtp_header_fixed, /* tree */
313 hf_wtp_header_flag_continue, /* id */
315 offCur, /* start of high light */
316 1, /* length of high light */
319 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_pdu_type, tvb, offCur, 1, bo_little_endian );
323 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
324 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
325 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
326 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
328 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_version , tvb, offCur + 3, 1, bo_little_endian );
329 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_flag_TIDNew, tvb, offCur + 3, 1, bo_little_endian );
330 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_flag_UP, tvb, offCur + 3, 1, bo_little_endian );
331 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_Reserved, tvb, offCur + 3, 1, bo_little_endian );
332 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_TransactionClass, tvb, offCur + 3, 1, bo_little_endian );
336 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
337 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
338 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
339 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
343 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Ack_flag_TVETOK, tvb, offCur, 1, bo_big_endian );
345 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
346 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
347 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
351 abortType = tvb_get_guint8 (tvb, offCur) & 0x07;
352 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_type , tvb, offCur , 1, bo_little_endian );
353 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
354 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
356 if (abortType == PROVIDER)
358 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_reason_provider , tvb, offCur + 3 , 1, bo_little_endian );
360 else if (abortType == USER)
362 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_reason_user , tvb, offCur + 3 , 1, bo_little_endian );
366 case SEGMENTED_INVOKE:
367 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
368 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
369 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
370 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
372 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + 3, 1, bo_little_endian );
375 case SEGMENTED_RESULT:
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 );
385 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
386 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
387 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
389 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_missing_packets , tvb, offCur + 3, 1, bo_little_endian );
390 /* Iterate through missing packets */
391 for (i=0; i<numMissing; i++)
393 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + i, 1, bo_little_endian );
402 /* There is a variable part if the Con flag is set */
403 ti = proto_tree_add_bytes_format(
405 hf_wtp_header_variable_part, /* id */
407 offCur + 4, /* start */
409 "What should go here!", /* value */
410 "Header (Variable part) %02X %02X %02X %02X" , /* format */
414 /* There is no variable part */
415 }; /* End of variable part of header */
419 fprintf( stderr, "dissect_wtp: (4) tree was %p\n", tree );
423 /* Any remaining data ought to be WSP data, so hand off to the WSP dissector */
424 if (tvb_reported_length (tvb) > cbHeader)
426 wsp_tvb = tvb_new_subset(tvb, cbHeader, -1, tvb_reported_length (tvb)-cbHeader);
427 call_dissector(wsp_handle, wsp_tvb, pinfo, tree);
431 fprintf( stderr, "dissect_wtp: (leaving) fdata->cinfo is %p\n", fdata->cinfo );
435 static char pdu_type(unsigned char octet)
437 char ch = (octet >> 3) & 0x0F;
438 /* Note pdu type must not be 0x00 */
442 static char transaction_class(unsigned char octet)
444 char ch = (octet >> 0) & 0x03; /* ......XX */
448 static char retransmission_indicator(unsigned char octet)
450 char ch = (octet >> 0) & 0x01; /* ......,X */
454 /* Register the protocol with Ethereal */
456 proto_register_wtp(void)
459 /* Setup list of header fields */
460 static hf_register_info hf[] = {
461 { &hf_wtp_header_fixed_part,
463 "wtp.header_fixed_part",
464 FT_BYTES, BASE_HEX, NULL, 0x0,
465 "Fixed part of the header"
468 { &hf_wtp_header_flag_continue,
471 FT_BOOLEAN, 8, TFS( &continue_truth ), 0x80,
475 { &hf_wtp_header_pdu_type,
478 FT_UINT8, BASE_HEX, VALS( vals_pdu_type ), 0x78,
482 { &hf_wtp_header_flag_Trailer,
485 FT_UINT8, BASE_HEX, VALS( vals_transmission_trailer ), 0x06,
489 { &hf_wtp_header_flag_RID,
490 { "Re-transmission Indicator",
492 FT_BOOLEAN, 8, TFS( &RID_truth ), 0x01,
493 "Re-transmission Indicator"
496 { &hf_wtp_header_flag_TID_response,
499 FT_BOOLEAN, 16, TFS( &tid_response_truth ), 0x8000,
503 { &hf_wtp_header_flag_TID,
506 FT_UINT16, BASE_HEX, NULL, 0x7FFF,
510 { &hf_wtp_header_Inv_version,
512 "wtp.header.version",
513 FT_UINT8, BASE_HEX, VALS( vals_version ), 0xC0,
517 { &hf_wtp_header_Inv_flag_TIDNew,
520 FT_BOOLEAN, 8, TFS( &TIDNew_truth ), 0x20,
524 { &hf_wtp_header_Inv_flag_UP,
527 FT_BOOLEAN, 8, TFS( &UP_truth ), 0x10,
531 { &hf_wtp_header_Inv_Reserved,
534 FT_UINT8, BASE_HEX, NULL, 0x0C,
538 { &hf_wtp_header_Inv_TransactionClass,
539 { "Transaction Class",
540 "wtp.inv.transaction-class",
541 FT_UINT8, BASE_HEX, NULL, 0x03,
545 { &hf_wtp_header_Ack_flag_TVETOK,
548 FT_BOOLEAN, 8, TFS( &TVETOK_truth ), 0x04,
552 { &hf_wtp_header_Abort_type,
555 FT_UINT8, BASE_HEX, VALS ( vals_abort_type ), 0x07,
559 { &hf_wtp_header_Abort_reason_provider,
561 "wtp.abort.reason.provider",
562 FT_UINT8, BASE_HEX, VALS ( vals_abort_reason_provider ), 0x00,
566 /* Assume WSP is the user and use its reason codes */
567 { &hf_wtp_header_Abort_reason_user,
569 "wtp.abort.reason.user",
570 FT_UINT8, BASE_HEX, VALS ( vals_wsp_reason_codes ), 0x00,
574 { &hf_wtp_header_sequence_number,
575 { "Packet Sequence Number",
576 "wtp.header.sequence",
577 FT_UINT8, BASE_HEX, NULL, 0x00,
578 "Packet Sequence Number"
581 { &hf_wtp_header_missing_packets,
583 "wtp.header.missing_packets",
584 FT_UINT8, BASE_HEX, NULL, 0x00,
588 { &hf_wtp_header_variable_part,
589 { "Header: Variable part",
590 "wtp.header_variable_part",
591 FT_BYTES, BASE_HEX, NULL, 0x0,
592 "Variable part of the header"
598 FT_BYTES, BASE_HEX, NULL, 0x0,
604 /* Setup protocol subtree array */
605 static gint *ett[] = {
610 /* Register the protocol name and description */
611 proto_wtp = proto_register_protocol(
612 "Wireless Transaction Protocol", /* protocol name for use by ethereal */
613 "WTP", /* short version of name */
614 "wap-wsp-wtp" /* Abbreviated protocol name, should Match IANA
615 < URL:http://www.isi.edu/in-notes/iana/assignments/port-numbers/ >
619 /* Required function calls to register the header fields and subtrees used */
620 proto_register_field_array(proto_wtp, hf, array_length(hf));
621 proto_register_subtree_array(ett, array_length(ett));
625 proto_reg_handoff_wtp(void)
628 * Get a handle for the IP WSP dissector.
630 wsp_handle = find_dissector("wsp");
632 dissector_add("udp.port", UDP_PORT_WTP_WSP, dissect_wtp);
633 /* dissector_add("udp.port", UDP_PORT_WTLS_WTP_WSP, dissect_wsp); */