Fix from Tom Uijldert: scan TPI's to get proper WTP packet length and
[obnox/wireshark/wip.git] / packet-wtp.c
1 /* packet-wtp.c
2  *
3  * Routines to dissect WTP component of WAP traffic.
4  * 
5  * $Id: packet-wtp.c,v 1.19 2001/09/11 14:36:31 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.org>
9  * Copyright 1998 Didier Jorand
10  *
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)
14  *
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.
19  * 
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.
24  * 
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.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <stdio.h>
35 #include <stdlib.h>
36
37 #ifdef HAVE_SYS_TYPES_H
38 # include <sys/types.h>
39 #endif
40
41 #ifdef HAVE_NETINET_IN_H
42 # include <netinet/in.h>
43 #endif
44
45 #ifdef NEED_SNPRINTF_H
46 # ifdef HAVE_STDARG_H
47 #  include <stdarg.h>
48 # else
49 #  include <varargs.h>
50 # endif
51 # include "snprintf.h"
52 #endif
53
54 #include <string.h>
55 #include <glib.h>
56 #include "packet.h"
57 #include "packet-wap.h"
58 #include "packet-wtp.h"
59 #include "packet-wsp.h"
60
61 static const true_false_string continue_truth = { 
62         "TPI Present" ,
63         "No TPI"
64 };
65
66 static const true_false_string RID_truth = { 
67         "Re-Transmission",
68         "First transmission"
69 };
70
71 static const true_false_string TIDNew_truth = { 
72         "TID is new" ,
73         "TID is valid"
74 };
75
76 static const true_false_string tid_response_truth = { 
77         "Response" ,
78         "Original"
79 };
80
81 static const true_false_string UP_truth = { 
82         "User Acknowledgement required" ,
83         "User Acknowledgement optional"
84 };
85
86 static const true_false_string TVETOK_truth = {
87         "True",
88         "False"
89 };
90
91 static const value_string vals_pdu_type[] = {
92         { 0, "Not Allowed" },
93         { 1, "Invoke" },
94         { 2, "Result" },
95         { 3, "Ack" },
96         { 4, "Abort" },
97         { 5, "Segmented Invoke" },
98         { 6, "Segmented Result" },
99         { 7, "Negative Ack" },
100         { 0, NULL }
101 };
102
103 static const value_string vals_transaction_trailer[] = {
104         { 0, "Not last packet" },
105         { 1, "Last packet of message" },
106         { 2, "Last packet of group" },
107         { 3, "Re-assembly not supported" },
108         { 0, NULL }
109 };
110
111 static const value_string vals_version[] = {
112         { 0, "Current" },
113         { 1, "Undefined" },
114         { 2, "Undefined" },
115         { 3, "Undefined" },
116         { 0, NULL }
117 };
118
119 static const value_string vals_abort_type[] = {
120         { 0, "Provider" },
121         { 1, "User (WSP)" },
122         { 0, NULL }
123 };
124
125 static const value_string vals_abort_reason_provider[] = {
126         { 0x00, "Unknown" },
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" },
136         { 0x00, NULL }
137 };
138
139 static const value_string vals_transaction_classes[] = {
140         { 0x00, "Unreliable Invoke without Result" },
141         { 0x01, "Reliable Invoke without Result" },
142         { 0x02, "Reliable Invoke with Reliable Result" },
143         { 0x00, NULL }
144 };
145
146 /* File scoped variables for the protocol and registered fields */
147 static int proto_wtp                                                    = HF_EMPTY;
148
149 /* These fields used by fixed part of header */
150 static int hf_wtp_header_fixed_part                     = HF_EMPTY;
151 static int hf_wtp_header_flag_continue                  = HF_EMPTY;
152 static int hf_wtp_header_pdu_type                               = HF_EMPTY;
153 static int hf_wtp_header_flag_Trailer                   = HF_EMPTY;
154 static int hf_wtp_header_flag_RID                               = HF_EMPTY;
155 static int hf_wtp_header_flag_TID                               = HF_EMPTY;
156 static int hf_wtp_header_flag_TID_response              = HF_EMPTY;
157
158 /* These fields used by Invoke packets */
159 static int hf_wtp_header_Inv_version                    = HF_EMPTY;
160 static int hf_wtp_header_Inv_flag_TIDNew                = HF_EMPTY;
161 static int hf_wtp_header_Inv_flag_UP                    = HF_EMPTY;
162 static int hf_wtp_header_Inv_Reserved                   = HF_EMPTY;
163 static int hf_wtp_header_Inv_TransactionClass   = HF_EMPTY;
164
165
166 static int hf_wtp_header_variable_part                  = HF_EMPTY;
167 static int hf_wtp_data                                                  = HF_EMPTY;
168
169 static int hf_wtp_header_Ack_flag_TVETOK                = HF_EMPTY;
170 static int hf_wtp_header_Abort_type                             = HF_EMPTY;
171 static int hf_wtp_header_Abort_reason_provider  = HF_EMPTY;
172 static int hf_wtp_header_Abort_reason_user              = HF_EMPTY;
173 static int hf_wtp_header_sequence_number                = HF_EMPTY;
174 static int hf_wtp_header_missing_packets                = HF_EMPTY;
175
176 /* Initialize the subtree pointers */
177 static gint ett_wtp                                                     = ETT_EMPTY;
178 static gint ett_header                                                  = ETT_EMPTY;
179
180 /* Handle for WSP dissector */
181 static dissector_handle_t wsp_handle;
182
183 /* Declarations */
184 static char transaction_class(unsigned char octet);
185 static char pdu_type(unsigned char octet);
186 static char retransmission_indicator(unsigned char octet);
187
188 /* Code to actually dissect the packets */
189 static void
190 dissect_wtp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
191 {
192         frame_data *fdata = pinfo->fd;
193
194         char szInfo[ 50 ];
195         int offCur                      = 0; /* current offset from start of WTP data */
196
197         /* bytes at offset 0 - 3 */
198         /*
199         unsigned char  b0 = pd[offset + 0];
200         unsigned char  b3 = pd[offset + 3];
201         */
202         unsigned char  b0;
203
204         /* continuation flag */
205         unsigned char   fCon;
206         unsigned char   fRID;
207         guint           cbHeader        = 0;
208         guint           vHeader         = 0;
209         int             abortType       = 0;
210
211 /* Set up structures we will need to add the protocol subtree and manage it */
212         proto_item *ti;
213         proto_tree *wtp_tree;
214         proto_tree *wtp_header_fixed;
215         
216         char pdut;
217         char clsTransaction             = ' ';
218         int cchInfo;
219         int numMissing = 0;             /* Number of missing packets in a negative ack */
220         int i;
221         tvbuff_t *wsp_tvb = NULL;
222
223 #ifdef DEBUG
224         fprintf( stderr, "dissect_wtp: (Entering) Frame data at %p\n", fdata ); 
225         fprintf( stderr, "dissect_wtp: tvb length is %d\n", tvb_reported_length( tvb ) ); 
226 #endif
227         if (check_col(fdata, COL_INFO)) {
228                 col_clear(fdata, COL_INFO);
229         };
230     
231         b0 = tvb_get_guint8 (tvb, offCur + 0);
232         fCon = b0 & 0x80;
233         fRID = retransmission_indicator( b0 );
234         pdut = pdu_type( b0 );
235
236         /* Develop the string to put in the Info column */
237         cchInfo = snprintf( szInfo, sizeof( szInfo ), "WTP %s",
238             val_to_str(pdut, vals_pdu_type, "Unknown PDU type 0x%x"));
239
240         switch( pdut ) {
241                 case INVOKE:
242                         clsTransaction = transaction_class( tvb_get_guint8 (tvb, offCur + 3) );
243                         snprintf( szInfo + cchInfo, sizeof( szInfo ) - cchInfo, " Class %d", clsTransaction  );
244
245                 case ABORT:
246                 case SEGMENTED_INVOKE:
247                 case SEGMENTED_RESULT:
248                         cbHeader = 4;
249                         break;
250
251                 case RESULT:
252                 case ACK:
253                         cbHeader = 3;
254                         break;
255
256                 case NEGATIVE_ACK:
257                         /* Varible number of missing packets */
258                         numMissing = tvb_get_guint8 (tvb, offCur + 3);
259                         cbHeader = numMissing + 4;
260                         break;
261
262                 default:
263                         break;
264         };
265
266         if( fRID ) {
267                 strcat( szInfo, " R" );
268         };
269         if( fCon ) {
270                 unsigned char   tCon;
271                 unsigned char   tByte;
272
273                 do {
274                         tByte = tvb_get_guint8(tvb, offCur + cbHeader + vHeader);
275                         tCon = tByte & 0x80;
276                         if (tByte & 0x04)
277                                 vHeader = vHeader + tvb_get_guint8(tvb,
278                                         offCur + cbHeader + vHeader + 1) + 2;
279                         else
280                                 vHeader = vHeader + (tByte & 0x03) + 1;
281                 } while (tCon);
282         }
283
284 #ifdef DEBUG
285         fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );  
286 #endif
287
288 /* This field shows up as the "Info" column in the display; you should make
289    it, if possible, summarize what's in the packet, so that a user looking
290    at the list of packets can tell what type of packet it is. */
291         if (check_col(fdata, COL_INFO)) {
292 #ifdef DEBUG
293                 fprintf( stderr, "dissect_wtp: (6) About to set info_col header to %s\n", szInfo );
294 #endif
295                 col_add_str(fdata, COL_INFO, szInfo );
296         };
297 /* In the interest of speed, if "tree" is NULL, don't do any work not
298    necessary to generate protocol tree items. */
299         if (tree) {
300 #ifdef DEBUG
301                 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );  
302 #endif
303                 ti = proto_tree_add_item(tree, proto_wtp, tvb, offCur, cbHeader + vHeader, bo_little_endian);
304 #ifdef DEBUG
305                 fprintf( stderr, "dissect_wtp: (7) Returned from proto_tree_add_item\n" );  
306 #endif
307                 wtp_tree = proto_item_add_subtree(ti, ett_wtp);
308
309 /* Code to process the packet goes here */
310                 {
311 #ifdef DEBUG
312                         fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );  
313                         fprintf( stderr, "dissect_wtp: offCur = %d\n", offCur );  
314                         fprintf( stderr, "dissect_wtp: About to call proto_tree_add_item with %p %d %p %d %d %d\n", 
315                                         wtp_tree, hf_wtp_header_fixed_part, tvb, offCur, cbHeader, bo_little_endian ); 
316                         ti = proto_tree_add_item( wtp_tree, hf_wtp_header_fixed_part, tvb, offCur, cbHeader, bo_little_endian );
317                         fprintf( stderr, "dissect_wtp: (6) Returned from proto_tree_add_item\n" );  
318 #endif
319                         wtp_header_fixed = proto_item_add_subtree(
320                                         ti, 
321                                         ett_header 
322                                 );
323
324                         /* Add common items: only CON and PDU Type */
325                         ti = proto_tree_add_item(
326                                         wtp_header_fixed,               /* tree */
327                                         hf_wtp_header_flag_continue,    /* id */
328                                         tvb, 
329                                         offCur,                         /* start of high light */
330                                         1,                              /* length of high light */
331                                         b0                              /* value */
332                              );
333                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_pdu_type, tvb, offCur, 1, bo_little_endian );
334
335                         switch( pdut ) {
336                                 case INVOKE:
337                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
338                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
339                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
340                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
341
342                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_version , tvb, offCur + 3, 1, bo_little_endian );
343                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_flag_TIDNew, tvb, offCur + 3, 1, bo_little_endian );
344                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_flag_UP, tvb, offCur + 3, 1, bo_little_endian );
345                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_Reserved, tvb, offCur + 3, 1, bo_little_endian );
346                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_TransactionClass, tvb, offCur + 3, 1, bo_little_endian );
347                                         break;
348
349                                 case RESULT:
350                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
351                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
352                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
353                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
354                                         break;
355
356                                 case ACK:
357                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Ack_flag_TVETOK, tvb, offCur, 1, bo_big_endian );
358
359                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, 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 );
362                                         break;
363
364                                 case ABORT:
365                                         abortType = tvb_get_guint8 (tvb, offCur) & 0x07;
366                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_type , tvb, offCur , 1, bo_little_endian );
367                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
368                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
369
370                                         if (abortType == PROVIDER)
371                                         {
372                                                 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_reason_provider , tvb, offCur + 3 , 1, bo_little_endian );
373                                         }
374                                         else if (abortType == USER)
375                                         {
376                                                 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_reason_user , tvb, offCur + 3 , 1, bo_little_endian );
377                                         }
378                                         break;
379
380                                 case SEGMENTED_INVOKE:
381                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
382                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
383                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
384                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
385
386                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + 3, 1, bo_little_endian );
387                                         break;
388
389                                 case SEGMENTED_RESULT:
390                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
391                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
392                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
393                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
394
395                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + 3, 1, bo_little_endian );
396                                         break;
397
398                                 case NEGATIVE_ACK:
399                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
400                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
401                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
402
403                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_missing_packets , tvb, offCur + 3, 1, bo_little_endian );
404                                         /* Iterate through missing packets */
405                                         for (i=0; i<numMissing; i++)
406                                         {
407                                                 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + i, 1, bo_little_endian );
408                                         }
409                                         break;
410
411                                 default:
412                                         break;
413                         };
414
415                         if( fCon ) {
416                                 /* There is a variable part if the Con flag is set */ 
417                                 ti = proto_tree_add_bytes_format(
418                                                 wtp_tree,                       /* tree */
419                                                 hf_wtp_header_variable_part,    /* id */
420                                                 tvb, 
421                                                 offCur + cbHeader,              /* start */
422                                                 vHeader,                        /* length */
423                                                 "What should go here!",         /* value */
424                                                 "Header (Variable part) %02X %02X %02X %02X"  ,                 /* format */
425                                                 0, 1, 2, 3
426                                     );
427                         } else {
428                                 /* There is no variable part */
429                         }; /* End of variable part of header */
430                 }
431         } else {
432 #ifdef DEBUG
433                 fprintf( stderr, "dissect_wtp: (4) tree was %p\n", tree ); 
434 #endif
435         }
436
437         /* Any remaining data ought to be WSP data,
438          * so hand off to the WSP dissector */
439         if (tvb_reported_length (tvb) > cbHeader + vHeader)
440         {
441                 wsp_tvb = tvb_new_subset(tvb, cbHeader + vHeader, -1,
442                         tvb_reported_length (tvb)-cbHeader-vHeader);
443                 call_dissector(wsp_handle, wsp_tvb, pinfo, tree);
444         }
445
446 #ifdef DEBUG
447         fprintf( stderr, "dissect_wtp: (leaving) fdata->cinfo is %p\n", fdata->cinfo ); 
448 #endif
449 }
450
451 /*
452  * Called directly from UDP.
453  * Put "WTP+WSP" into the "Protocol" column.
454  */
455 void
456 dissect_wtp_fromudp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
457 {
458         if (check_col(pinfo->fd, COL_PROTOCOL))
459                 col_set_str(pinfo->fd, COL_PROTOCOL, "WTP+WSP" );
460
461         dissect_wtp_common(tvb, pinfo, tree);
462 }
463
464 /*
465  * Called from a higher-level WAP dissector, presumably WTLS.
466  * Put "WTLS+WSP+WTP" to the "Protocol" column.
467  *
468  * XXX - is this supposed to be called from WTLS?  If so, we're not
469  * calling it....
470  *
471  * XXX - can this be called from any other dissector?
472  */
473 static void
474 dissect_wtp_fromwap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
475 {
476         if (check_col(pinfo->fd, COL_PROTOCOL))
477                 col_set_str(pinfo->fd, COL_PROTOCOL, "WTLS+WTP+WSP" );
478
479         dissect_wtp_common(tvb, pinfo, tree);
480 }
481
482 static char pdu_type(unsigned char octet)
483 {
484         char ch = (octet >> 3) & 0x0F;
485         /* Note pdu type must not be 0x00 */
486         return ch;
487 };
488
489 static char transaction_class(unsigned char octet)
490 {
491         char ch = (octet >> 0) & 0x03; /* ......XX */
492         return ch;
493 };
494
495 static char retransmission_indicator(unsigned char octet)
496 {
497         switch ( pdu_type(octet) ) {
498                 case INVOKE:
499                 case RESULT:
500                 case ACK:
501                 case SEGMENTED_INVOKE:
502                 case SEGMENTED_RESULT:
503                 case NEGATIVE_ACK:
504                         return (octet >> 0) & 0x01; /* ......,X */
505                 default:
506                         return 0;
507         }
508 };
509
510 /* Register the protocol with Ethereal */
511 void
512 proto_register_wtp(void)
513 {                 
514
515 /* Setup list of header fields */
516         static hf_register_info hf[] = {
517                 { &hf_wtp_header_fixed_part,
518                         {       "Header",           
519                                 "wtp.header_fixed_part",
520                                 FT_BYTES, BASE_HEX, NULL, 0x0,          
521                                 "Fixed part of the header", HFILL
522                         }
523                 },
524                 { &hf_wtp_header_flag_continue,
525                         {       "Continue Flag",           
526                                 "wtp.continue_flag",
527                                 FT_BOOLEAN, 8, TFS( &continue_truth ), 0x80,          
528                                 "Continue Flag", HFILL
529                         }
530                 },
531                 { &hf_wtp_header_pdu_type,
532                         {       "PDU Type",           
533                                 "wtp.pdu_type",
534                                  FT_UINT8, BASE_HEX, VALS( vals_pdu_type ), 0x78,
535                                 "PDU Type", HFILL
536                         }
537                 },
538                 { &hf_wtp_header_flag_Trailer,
539                         {       "Trailer Flags",           
540                                 "wtp.trailer_flags",
541                                  FT_UINT8, BASE_HEX, VALS( vals_transaction_trailer ), 0x06,
542                                 "Trailer Flags", HFILL
543                         }
544                 },
545                 { &hf_wtp_header_flag_RID,
546                         {       "Re-transmission Indicator",           
547                                 "wtp.RID",
548                                  FT_BOOLEAN, 8, TFS( &RID_truth ), 0x01,
549                                 "Re-transmission Indicator", HFILL
550                         }
551                 },
552                 { &hf_wtp_header_flag_TID_response,
553                         {       "TID Response",           
554                                 "wtp.TID.response",
555                                 FT_BOOLEAN, 16, TFS( &tid_response_truth ), 0x8000,
556                                 "TID Response", HFILL
557                         }
558                 },
559                 { &hf_wtp_header_flag_TID,
560                         {       "Transaction ID",           
561                                 "wtp.TID",
562                                  FT_UINT16, BASE_HEX, NULL, 0x7FFF,
563                                 "Transaction ID", HFILL
564                         }
565                 },
566                 { &hf_wtp_header_Inv_version,
567                         {       "Version",           
568                                 "wtp.header.version",
569                                  FT_UINT8, BASE_HEX, VALS( vals_version ), 0xC0,
570                                 "Version", HFILL
571                         }
572                 },
573                 { &hf_wtp_header_Inv_flag_TIDNew,
574                         {       "TIDNew",           
575                                 "wtp.header.TIDNew",
576                                  FT_BOOLEAN, 8, TFS( &TIDNew_truth ), 0x20,
577                                 "TIDNew", HFILL
578                         }
579                 },
580                 { &hf_wtp_header_Inv_flag_UP,
581                         {       "U/P flag",           
582                                 "wtp.header.UP",
583                                  FT_BOOLEAN, 8, TFS( &UP_truth ), 0x10,
584                                 "U/P Flag", HFILL
585                         }
586                 },
587                 { &hf_wtp_header_Inv_Reserved,
588                         {       "Reserved",           
589                                 "wtp.inv.reserved",
590                                  FT_UINT8, BASE_HEX, NULL, 0x0C,
591                                 "Reserved", HFILL
592                         }
593                 },
594                 { &hf_wtp_header_Inv_TransactionClass,
595                         {       "Transaction Class",           
596                                 "wtp.inv.transaction_class",
597                                  FT_UINT8, BASE_HEX, VALS( vals_transaction_classes ), 0x03,
598                                 "Transaction Class", HFILL
599                         }
600                 },
601                 { &hf_wtp_header_Ack_flag_TVETOK,
602                         {       "Tve/Tok flag",           
603                                 "wtp.ack.tvetok",
604                                  FT_BOOLEAN, 8, TFS( &TVETOK_truth ), 0x04,
605                                 "Tve/Tok flag", HFILL
606                         }
607                 },
608                 { &hf_wtp_header_Abort_type,
609                         {       "Abort Type",           
610                                 "wtp.abort.type",
611                                  FT_UINT8, BASE_HEX, VALS ( vals_abort_type ), 0x07,
612                                 "Abort Type", HFILL
613                         }
614                 },
615                 { &hf_wtp_header_Abort_reason_provider,
616                         {       "Abort Reason",           
617                                 "wtp.abort.reason.provider",
618                                  FT_UINT8, BASE_HEX, VALS ( vals_abort_reason_provider ), 0x00,
619                                 "Abort Reason", HFILL
620                         }
621                 },
622                 /* Assume WSP is the user and use its reason codes */
623                 { &hf_wtp_header_Abort_reason_user,
624                         {       "Abort Reason",           
625                                 "wtp.abort.reason.user",
626                                  FT_UINT8, BASE_HEX, VALS ( vals_wsp_reason_codes ), 0x00,
627                                 "Abort Reason", HFILL
628                         }
629                 },
630                 { &hf_wtp_header_sequence_number,
631                         {       "Packet Sequence Number",           
632                                 "wtp.header.sequence",
633                                  FT_UINT8, BASE_HEX, NULL, 0x00,
634                                 "Packet Sequence Number", HFILL
635                         }
636                 },
637                 { &hf_wtp_header_missing_packets,
638                         {       "Missing Packets",           
639                                 "wtp.header.missing_packets",
640                                  FT_UINT8, BASE_HEX, NULL, 0x00,
641                                 "Missing Packets", HFILL
642                         }
643                 },
644                 { &hf_wtp_header_variable_part,
645                         {       "Header: Variable part",           
646                                 "wtp.header_variable_part",
647                                 FT_BYTES, BASE_HEX, NULL, 0x0,          
648                                 "Variable part of the header", HFILL
649                         }
650                 },
651                 { &hf_wtp_data,
652                         {       "Data",           
653                                 "wtp.header_data",
654                                 FT_BYTES, BASE_HEX, NULL, 0x0,          
655                                 "Data", HFILL
656                         }
657                 },
658         };
659         
660 /* Setup protocol subtree array */
661         static gint *ett[] = {
662                 &ett_wtp,
663                 &ett_header,
664         };
665
666 /* Register the protocol name and description */
667         proto_wtp = proto_register_protocol(
668                 "Wireless Transaction Protocol",   /* protocol name for use by ethereal */ 
669                 "WTP",                             /* short version of name */
670                 "wap-wsp-wtp"                      /* Abbreviated protocol name, should Match IANA 
671                                                     < URL:http://www.isi.edu/in-notes/iana/assignments/port-numbers/ >
672                                                   */
673         );
674
675 /* Required function calls to register the header fields and subtrees used */
676         proto_register_field_array(proto_wtp, hf, array_length(hf));
677         proto_register_subtree_array(ett, array_length(ett));
678
679         register_dissector("wtp", dissect_wtp_fromwap, proto_wtp);
680 };
681
682 void
683 proto_reg_handoff_wtp(void)
684 {
685         /*
686          * Get a handle for the connection-oriented WSP dissector - if WTP
687          * PDUs have data, it is WSP.
688          */
689         wsp_handle = find_dissector("wsp-co");
690
691         dissector_add("udp.port", UDP_PORT_WTP_WSP, dissect_wtp_fromudp,
692             proto_wtp);
693 }