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.2 2000/11/04 07:38:19 guy 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 { 6, "Negative Ack" },
99 static const value_string vals_transmission_trailer[] = {
100 { 0, "Not last packet" },
101 { 1, "Last packet of message" },
102 { 2, "Last packet of group" },
103 { 3, "Re-assembly not supported" },
106 static const value_string vals_version[] = {
113 static const value_string vals_abort_type[] = {
118 static const value_string vals_abort_reason_provider[] = {
120 { 0x01, "Protocol Error" },
121 { 0x02, "Invalid TID" },
122 { 0x03, "Not Implemented Class 2" },
123 { 0x04, "Not Implemented SAR" },
124 { 0x05, "Not Implemented User Acknowledgement" },
125 { 0x06, "WTP Version Zero" },
126 { 0x07, "Capacity Temporarily Exceeded" },
127 { 0x08, "No Response" },
128 { 0x09, "Message Too Large" }
131 /* File scoped variables for the protocol and registered fields */
132 static int proto_wtp = HF_EMPTY;
134 /* These fields used by fixed part of header */
135 static int hf_wtp_header_fixed_part = HF_EMPTY;
136 static int hf_wtp_header_flag_continue = HF_EMPTY;
137 static int hf_wtp_header_pdu_type = HF_EMPTY;
138 static int hf_wtp_header_flag_Trailer = HF_EMPTY;
139 static int hf_wtp_header_flag_RID = HF_EMPTY;
140 static int hf_wtp_header_flag_TID = HF_EMPTY;
141 static int hf_wtp_header_flag_TID_response = HF_EMPTY;
143 /* These fields used by Invoke packets */
144 static int hf_wtp_header_Inv_version = HF_EMPTY;
145 static int hf_wtp_header_Inv_flag_TIDNew = HF_EMPTY;
146 static int hf_wtp_header_Inv_flag_UP = HF_EMPTY;
147 static int hf_wtp_header_Inv_Reserved = HF_EMPTY;
148 static int hf_wtp_header_Inv_TransactionClass = HF_EMPTY;
151 static int hf_wtp_header_variable_part = HF_EMPTY;
152 static int hf_wtp_data = HF_EMPTY;
154 static int hf_wtp_header_Ack_flag_TVETOK = HF_EMPTY;
155 static int hf_wtp_header_Abort_type = HF_EMPTY;
156 static int hf_wtp_header_Abort_reason_provider = HF_EMPTY;
157 static int hf_wtp_header_Abort_reason_user = HF_EMPTY;
158 static int hf_wtp_header_sequence_number = HF_EMPTY;
159 static int hf_wtp_header_missing_packets = HF_EMPTY;
161 /* Initialize the subtree pointers */
162 static gint ett_wtp = ETT_EMPTY;
163 static gint ett_header = ETT_EMPTY;
166 static char transaction_class(unsigned char octet);
167 static char pdu_type(unsigned char octet);
168 static char retransmission_indicator(unsigned char octet);
169 void dissect_wtp(tvbuff_t *, packet_info *, proto_tree *);
172 dissect_wtp_no_tvbuff(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
174 packet_info *pinfo = π
175 tvbuff_t *tvb = tvb_create_from_top(offset);
176 dissect_wtp (tvb, pinfo, tree);
179 /* Code to actually dissect the packets */
181 dissect_wtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
183 frame_data *fdata = pinfo->fd;
186 int offCur = 0; /* current offset from start of WTP data */
188 /* bytes at offset 0 - 3 */
190 unsigned char b0 = pd[offset + 0];
191 unsigned char b3 = pd[offset + 3];
193 unsigned char b0 = tvb_get_guint8 (tvb, offCur + 0);
195 /* continuation flag */
196 unsigned char fCon = b0 & 0x80;
197 unsigned char fRID = retransmission_indicator( b0 );
201 /* Set up structures we will need to add the protocol subtree and manage it */
203 proto_tree *wtp_tree;
204 proto_tree *wtp_header_fixed;
206 char pdut = pdu_type( b0 );
207 char clsTransaction = ' ';
209 int numMissing = 0; /* Number of missing packets in a negative ack */
211 tvbuff_t *wsp_tvb = NULL;
213 /* Make entries in Protocol column and Info column of summary display */
216 fprintf( stderr, "dissect_wtp: (Entering) Frame data at %p\n", fdata );
217 fprintf( stderr, "dissect_wtp: tvb length is %d\n", tvb_reported_length( tvb ) );
219 /* Display protocol type depending on the port */
220 if (check_col(fdata, COL_PROTOCOL))
222 switch ( pinfo->match_port )
224 case UDP_PORT_WTP_WSP:
225 col_add_fstr(fdata, COL_PROTOCOL, "WTP+WSP" );
227 case UDP_PORT_WTLS_WTP_WSP:
228 col_add_fstr(fdata, COL_PROTOCOL, "WTLS+WTP+WSP" );
235 /* Develop the string to put in the Info column */
236 cchInfo = snprintf( szInfo, sizeof( szInfo ), "WTP %s", vals_pdu_type[ ( int )pdut ].strptr );
240 clsTransaction = transaction_class( tvb_get_guint8 (tvb, offCur + 3) );
241 snprintf( szInfo + cchInfo, sizeof( szInfo ) - cchInfo, " Class %d", clsTransaction );
244 case SEGMENTED_INVOKE:
245 case SEGMENTED_RESULT:
255 /* Varible number of missing packets */
256 numMissing = tvb_get_guint8 (tvb, offCur + 3);
257 cbHeader = numMissing + 4;
265 strcat( szInfo, " R" );
269 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );
272 /* This field shows up as the "Info" column in the display; you should make
273 it, if possible, summarize what's in the packet, so that a user looking
274 at the list of packets can tell what type of packet it is.
275 "col_add_fstr()" can be used instead of "col_add_str()"; it takes
276 "printf()"-like arguments. */
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. */
286 /* NOTE: The offset and length values in the previous call to
287 "proto_tree_add_item()" define what data bytes to highlight in the hex
288 display window when the line in the protocol tree display
289 corresponding to that item is selected.
291 END_OF_FRAME is a handy way to highlight all data from the offset to
292 the end of the packet. */
294 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );
296 ti = proto_tree_add_item(tree, proto_wtp, tvb, offCur, cbHeader, bo_little_endian);
298 fprintf( stderr, "dissect_wtp: (7) Returned from proto_tree_add_item\n" );
300 wtp_tree = proto_item_add_subtree(ti, ett_wtp);
302 /* Code to process the packet goes here */
305 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );
306 fprintf( stderr, "dissect_wtp: offCur = %d\n", offCur );
307 fprintf( stderr, "dissect_wtp: About to call proto_tree_add_item with %p %d %p %d %d %d\n",
308 wtp_tree, hf_wtp_header_fixed_part, tvb, offCur, cbHeader, bo_little_endian );
309 ti = proto_tree_add_item( wtp_tree, hf_wtp_header_fixed_part, tvb, offCur, cbHeader, bo_little_endian );
310 fprintf( stderr, "dissect_wtp: (6) Returned from proto_tree_add_item\n" );
312 wtp_header_fixed = proto_item_add_subtree(
317 /* Add common items: only CON and PDU Type */
318 ti = proto_tree_add_item(
319 wtp_header_fixed, /* tree */
320 hf_wtp_header_flag_continue, /* id */
322 offCur, /* start of high light */
323 1, /* length of high light */
326 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_pdu_type, tvb, offCur, 1, bo_little_endian );
330 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
331 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
332 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
333 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
335 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_version , tvb, offCur + 3, 1, bo_little_endian );
336 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_flag_TIDNew, tvb, offCur + 3, 1, bo_little_endian );
337 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_flag_UP, tvb, offCur + 3, 1, bo_little_endian );
338 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_Reserved, tvb, offCur + 3, 1, bo_little_endian );
339 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_TransactionClass, tvb, offCur + 3, 1, bo_little_endian );
343 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
344 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
345 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
346 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
350 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Ack_flag_TVETOK, tvb, offCur, 1, bo_big_endian );
352 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, 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 );
358 abortType = tvb_get_guint8 (tvb, offCur) & 0x07;
359 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_type , tvb, offCur , 1, bo_little_endian );
360 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
361 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
363 if (abortType == PROVIDER)
365 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_reason_provider , tvb, offCur + 3 , 1, bo_little_endian );
367 else if (abortType == USER)
369 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_reason_user , tvb, offCur + 3 , 1, bo_little_endian );
373 case SEGMENTED_INVOKE:
374 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
375 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
376 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
377 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
379 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + 3, 1, bo_little_endian );
382 case SEGMENTED_RESULT:
383 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
384 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
385 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
386 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
388 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + 3, 1, bo_little_endian );
392 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
393 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
394 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
396 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_missing_packets , tvb, offCur + 3, 1, bo_little_endian );
397 /* Iterate through missing packets */
398 for (i=0; i<numMissing; i++)
400 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + i, 1, bo_little_endian );
409 /* There is a variable part if the Con flag is set */
410 ti = proto_tree_add_bytes_format(
412 hf_wtp_header_variable_part, /* id */
414 offCur + 4, /* start */
416 "What should go here!", /* value */
417 "Header (Variable part) %02X %02X %02X %02X" , /* format */
421 /* There is no variable part */
422 }; /* End of variable part of header */
426 fprintf( stderr, "dissect_wtp: (4) tree was %p\n", tree );
430 /* Any remaining data ought to be WSP data, so hand off to the WSP dissector */
431 if (tvb_reported_length (tvb) > cbHeader)
433 wsp_tvb = tvb_new_subset(tvb, cbHeader, -1, tvb_reported_length (tvb)-cbHeader);
434 dissect_wsp( wsp_tvb, pinfo, tree);
438 fprintf( stderr, "dissect_wtp: (leaving) fdata->cinfo is %p\n", fdata->cinfo );
442 static char pdu_type(unsigned char octet)
444 char ch = (octet >> 3) & 0x0F;
445 /* Note pdu type must not be 0x00 */
449 static char transaction_class(unsigned char octet)
451 char ch = (octet >> 0) & 0x03; /* ......XX */
455 static char retransmission_indicator(unsigned char octet)
457 char ch = (octet >> 0) & 0x01; /* ......,X */
461 /* Register the protocol with Ethereal */
463 proto_register_wtp(void)
466 /* Setup list of header fields */
467 static hf_register_info hf[] = {
468 { &hf_wtp_header_fixed_part,
470 "wtp.header_fixed_part",
471 FT_BYTES, BASE_HEX, NULL, 0x0,
472 "Fixed part of the header"
475 { &hf_wtp_header_flag_continue,
478 FT_BOOLEAN, 8, TFS( &continue_truth ), 0x80,
482 { &hf_wtp_header_pdu_type,
485 FT_UINT8, BASE_HEX, VALS( vals_pdu_type ), 0x78,
489 { &hf_wtp_header_flag_Trailer,
492 FT_UINT8, BASE_HEX, VALS( vals_transmission_trailer ), 0x06,
496 { &hf_wtp_header_flag_RID,
497 { "Re-transmission Indicator",
499 FT_BOOLEAN, 8, TFS( &RID_truth ), 0x01,
500 "Re-transmission Indicator"
503 { &hf_wtp_header_flag_TID_response,
506 FT_BOOLEAN, 16, TFS( &tid_response_truth ), 0x8000,
510 { &hf_wtp_header_flag_TID,
513 FT_UINT16, BASE_HEX, NULL, 0x7FFF,
517 { &hf_wtp_header_Inv_version,
519 "wtp.header.version",
520 FT_UINT8, BASE_HEX, VALS( vals_version ), 0xC0,
524 { &hf_wtp_header_Inv_flag_TIDNew,
527 FT_BOOLEAN, 8, TFS( &TIDNew_truth ), 0x20,
531 { &hf_wtp_header_Inv_flag_UP,
534 FT_BOOLEAN, 8, TFS( &UP_truth ), 0x10,
538 { &hf_wtp_header_Inv_Reserved,
541 FT_UINT8, BASE_HEX, NULL, 0x0C,
545 { &hf_wtp_header_Inv_TransactionClass,
546 { "Transaction Class",
547 "wtp.inv.transaction-class",
548 FT_UINT8, BASE_HEX, NULL, 0x03,
552 { &hf_wtp_header_Ack_flag_TVETOK,
555 FT_BOOLEAN, 8, TFS( &TVETOK_truth ), 0x04,
559 { &hf_wtp_header_Abort_type,
562 FT_UINT8, BASE_HEX, VALS ( vals_abort_type ), 0x07,
566 { &hf_wtp_header_Abort_reason_provider,
568 "wtp.abort.reason.provider",
569 FT_UINT8, BASE_HEX, VALS ( vals_abort_reason_provider ), 0x00,
573 /* Assume WSP is the user and use its reason codes */
574 { &hf_wtp_header_Abort_reason_user,
576 "wtp.abort.reason.user",
577 FT_UINT8, BASE_HEX, VALS ( vals_wsp_reason_codes ), 0x00,
581 { &hf_wtp_header_sequence_number,
582 { "Packet Sequence Number",
583 "wtp.header.sequence",
584 FT_UINT8, BASE_HEX, NULL, 0x00,
585 "Packet Sequence Number"
588 { &hf_wtp_header_missing_packets,
590 "wtp.header.missing_packets",
591 FT_UINT8, BASE_HEX, NULL, 0x00,
595 { &hf_wtp_header_variable_part,
596 { "Header: Variable part",
597 "wtp.header_variable_part",
598 FT_BYTES, BASE_HEX, NULL, 0x0,
599 "Variable part of the header"
605 FT_BYTES, BASE_HEX, NULL, 0x0,
611 /* Setup protocol subtree array */
612 static gint *ett[] = {
617 /* Register the protocol name and description */
618 proto_wtp = proto_register_protocol(
619 "Wireless Transaction Protocol", /* protocol name for use by ethereal */
620 "wap-wsp-wtp" /* Abbreviated protocol name, should Match IANA
621 < URL:http://www.isi.edu/in-notes/iana/assignments/port-numbers/ >
625 /* Required function calls to register the header fields and subtrees used */
626 proto_register_field_array(proto_wtp, hf, array_length(hf));
627 proto_register_subtree_array(ett, array_length(ett));
631 proto_reg_handoff_wtp(void)
633 dissector_add("udp.port", UDP_PORT_WTP_WSP, dissect_wtp);
634 /* dissector_add("udp.port", UDP_PORT_WTLS_WTP_WSP, dissect_wsp); */