From Tim Potter: dissect some of the LSA RPCs stub data.
[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.23 2001/12/10 00:25:41 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
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_sub_pdu_size                   = HF_EMPTY;
152 static int hf_wtp_header_flag_continue                  = HF_EMPTY;
153 static int hf_wtp_header_pdu_type                               = HF_EMPTY;
154 static int hf_wtp_header_flag_Trailer                   = HF_EMPTY;
155 static int hf_wtp_header_flag_RID                               = HF_EMPTY;
156 static int hf_wtp_header_flag_TID                               = HF_EMPTY;
157 static int hf_wtp_header_flag_TID_response              = HF_EMPTY;
158
159 /* These fields used by Invoke packets */
160 static int hf_wtp_header_Inv_version                    = HF_EMPTY;
161 static int hf_wtp_header_Inv_flag_TIDNew                = HF_EMPTY;
162 static int hf_wtp_header_Inv_flag_UP                    = HF_EMPTY;
163 static int hf_wtp_header_Inv_Reserved                   = HF_EMPTY;
164 static int hf_wtp_header_Inv_TransactionClass   = HF_EMPTY;
165
166
167 static int hf_wtp_header_variable_part                  = HF_EMPTY;
168 static int hf_wtp_data                                                  = HF_EMPTY;
169
170 static int hf_wtp_header_Ack_flag_TVETOK                = HF_EMPTY;
171 static int hf_wtp_header_Abort_type                             = HF_EMPTY;
172 static int hf_wtp_header_Abort_reason_provider  = HF_EMPTY;
173 static int hf_wtp_header_Abort_reason_user              = HF_EMPTY;
174 static int hf_wtp_header_sequence_number                = HF_EMPTY;
175 static int hf_wtp_header_missing_packets                = HF_EMPTY;
176
177 /* Initialize the subtree pointers */
178 static gint ett_wtp                                                     = ETT_EMPTY;
179 static gint ett_header                                                  = ETT_EMPTY;
180
181 /* Handle for WSP dissector */
182 static dissector_handle_t wsp_handle;
183
184 /* Declarations */
185 static char transaction_class(unsigned char octet);
186 static char pdu_type(unsigned char octet);
187 static char retransmission_indicator(unsigned char octet);
188
189 /* Code to actually dissect the packets */
190 static void
191 dissect_wtp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
192 {
193         char szInfo[ 50 ];
194         int offCur                      = 0; /* current offset from start of WTP data */
195
196         /* bytes at offset 0 - 3 */
197         /*
198         unsigned char  b0 = pd[offset + 0];
199         unsigned char  b3 = pd[offset + 3];
200         */
201         unsigned char  b0;
202
203         /* continuation flag */
204         unsigned char   fCon;
205         unsigned char   fRID;
206         guint           cbHeader        = 0;
207         guint           vHeader         = 0;
208         int             abortType       = 0;
209
210 /* Set up structures we will need to add the protocol subtree and manage it */
211         proto_item *ti;
212         proto_tree *wtp_tree = NULL;
213         proto_tree *wtp_header_fixed;
214         
215         char pdut;
216         char clsTransaction             = ' ';
217         int cchInfo;
218         int numMissing = 0;             /* Number of missing packets in a negative ack */
219         int i;
220         tvbuff_t *wsp_tvb = NULL;
221
222         b0 = tvb_get_guint8 (tvb, offCur + 0);
223         /* Discover Concatenated PDUs */
224         if (b0 == 0) {
225                 if (tree) {
226                         wtp_tree = proto_tree_add_item(tree, proto_wtp, tvb, offCur, 1, bo_little_endian);
227                 }
228                 offCur = 1;
229                 i = 1;
230                 while (offCur < (int) tvb_reported_length (tvb)) {
231                         b0 = tvb_get_guint8 (tvb, offCur + 0);
232                         if (b0 & 0x80) {
233                                 vHeader = 2;
234                                 cbHeader = ((b0 & 0x7f) << 8) |
235                                                         tvb_get_guint8 (tvb, offCur + 1);
236                         } else {
237                                 vHeader = 1;
238                                 cbHeader = b0;
239                         }
240                     if (tree) {
241                                 proto_tree_add_item(wtp_tree, hf_wtp_header_sub_pdu_size, tvb, offCur, vHeader, bo_big_endian);
242                         }
243                         if (i > 1 && check_col(pinfo->cinfo, COL_INFO)) {
244                                 col_append_str (pinfo->cinfo, COL_INFO, ", ");
245                         }
246                         wsp_tvb = tvb_new_subset(tvb,
247                                 offCur + vHeader, -1, cbHeader);
248                         dissect_wtp_common (wsp_tvb, pinfo, wtp_tree);
249                         offCur += vHeader + cbHeader;
250                         i++;
251                 }
252                 return;
253         }
254         fCon = b0 & 0x80;
255         fRID = retransmission_indicator( b0 );
256         pdut = pdu_type( b0 );
257
258         /* Develop the string to put in the Info column */
259         cchInfo = snprintf( szInfo, sizeof( szInfo ), "WTP %s",
260             val_to_str(pdut, vals_pdu_type, "Unknown PDU type 0x%x"));
261
262         switch( pdut ) {
263                 case INVOKE:
264                         clsTransaction = transaction_class( tvb_get_guint8 (tvb, offCur + 3) );
265                         snprintf( szInfo + cchInfo, sizeof( szInfo ) - cchInfo, " Class %d", clsTransaction  );
266
267                 case ABORT:
268                 case SEGMENTED_INVOKE:
269                 case SEGMENTED_RESULT:
270                         cbHeader = 4;
271                         break;
272
273                 case RESULT:
274                 case ACK:
275                         cbHeader = 3;
276                         break;
277
278                 case NEGATIVE_ACK:
279                         /* Varible number of missing packets */
280                         numMissing = tvb_get_guint8 (tvb, offCur + 3);
281                         cbHeader = numMissing + 4;
282                         break;
283
284                 default:
285                         break;
286         };
287
288         if( fRID ) {
289                 strcat( szInfo, " R" );
290         };
291         if( fCon ) {
292                 unsigned char   tCon;
293                 unsigned char   tByte;
294
295                 do {
296                         tByte = tvb_get_guint8(tvb, offCur + cbHeader + vHeader);
297                         tCon = tByte & 0x80;
298                         if (tByte & 0x04)
299                                 vHeader = vHeader + tvb_get_guint8(tvb,
300                                         offCur + cbHeader + vHeader + 1) + 2;
301                         else
302                                 vHeader = vHeader + (tByte & 0x03) + 1;
303                 } while (tCon);
304         }
305
306 #ifdef DEBUG
307         fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );  
308 #endif
309
310 /* This field shows up as the "Info" column in the display; you should make
311    it, if possible, summarize what's in the packet, so that a user looking
312    at the list of packets can tell what type of packet it is. */
313         if (check_col(pinfo->cinfo, COL_INFO) &&
314                 tvb_reported_length (tvb) <= cbHeader + vHeader) {
315 #ifdef DEBUG
316                 fprintf( stderr, "dissect_wtp: (6) About to set info_col header to %s\n", szInfo );
317 #endif
318                 col_append_str(pinfo->cinfo, COL_INFO, szInfo );
319         };
320 /* In the interest of speed, if "tree" is NULL, don't do any work not
321    necessary to generate protocol tree items. */
322         if (tree) {
323 #ifdef DEBUG
324                 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );  
325 #endif
326                 ti = proto_tree_add_item(tree, proto_wtp, tvb, offCur, cbHeader + vHeader, bo_little_endian);
327 #ifdef DEBUG
328                 fprintf( stderr, "dissect_wtp: (7) Returned from proto_tree_add_item\n" );  
329 #endif
330                 wtp_tree = proto_item_add_subtree(ti, ett_wtp);
331
332 /* Code to process the packet goes here */
333                 {
334 #ifdef DEBUG
335                         fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );  
336                         fprintf( stderr, "dissect_wtp: offCur = %d\n", offCur );  
337                         fprintf( stderr, "dissect_wtp: About to call proto_tree_add_item with %p %d %p %d %d %d\n", 
338                                         wtp_tree, hf_wtp_header_fixed_part, tvb, offCur, cbHeader, bo_little_endian ); 
339                         ti = proto_tree_add_item( wtp_tree, hf_wtp_header_fixed_part, tvb, offCur, cbHeader, bo_little_endian );
340                         fprintf( stderr, "dissect_wtp: (6) Returned from proto_tree_add_item\n" );  
341 #endif
342                         wtp_header_fixed = proto_item_add_subtree(
343                                         ti, 
344                                         ett_header 
345                                 );
346
347                         /* Add common items: only CON and PDU Type */
348                         ti = proto_tree_add_item(
349                                         wtp_header_fixed,               /* tree */
350                                         hf_wtp_header_flag_continue,    /* id */
351                                         tvb, 
352                                         offCur,                         /* start of high light */
353                                         1,                              /* length of high light */
354                                         b0                              /* value */
355                              );
356                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_pdu_type, tvb, offCur, 1, bo_little_endian );
357
358                         switch( pdut ) {
359                                 case INVOKE:
360                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
361                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, 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 );
364
365                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_version , tvb, offCur + 3, 1, bo_little_endian );
366                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_flag_TIDNew, tvb, offCur + 3, 1, bo_little_endian );
367                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_flag_UP, tvb, offCur + 3, 1, bo_little_endian );
368                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_Reserved, tvb, offCur + 3, 1, bo_little_endian );
369                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Inv_TransactionClass, tvb, offCur + 3, 1, bo_little_endian );
370                                         break;
371
372                                 case RESULT:
373                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
374                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
375                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
376                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
377                                         break;
378
379                                 case ACK:
380                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Ack_flag_TVETOK, tvb, offCur, 1, bo_big_endian );
381
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                                         break;
386
387                                 case ABORT:
388                                         abortType = tvb_get_guint8 (tvb, offCur) & 0x07;
389                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_type , tvb, offCur , 1, bo_little_endian );
390                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
391                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
392
393                                         if (abortType == PROVIDER)
394                                         {
395                                                 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_reason_provider , tvb, offCur + 3 , 1, bo_little_endian );
396                                         }
397                                         else if (abortType == USER)
398                                         {
399                                                 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_Abort_reason_user , tvb, offCur + 3 , 1, bo_little_endian );
400                                         }
401                                         break;
402
403                                 case SEGMENTED_INVOKE:
404                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
405                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
406                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
407                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
408
409                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + 3, 1, bo_little_endian );
410                                         break;
411
412                                 case SEGMENTED_RESULT:
413                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_Trailer, tvb, offCur, 1, bo_little_endian );
414                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
415                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
416                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
417
418                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + 3, 1, bo_little_endian );
419                                         break;
420
421                                 case NEGATIVE_ACK:
422                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_RID, tvb, offCur, 1, bo_little_endian );
423                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID_response, tvb, offCur + 1, 2, bo_big_endian );
424                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_flag_TID, tvb, offCur + 1, 2, bo_big_endian );
425
426                                         ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_missing_packets , tvb, offCur + 3, 1, bo_little_endian );
427                                         /* Iterate through missing packets */
428                                         for (i=0; i<numMissing; i++)
429                                         {
430                                                 ti = proto_tree_add_item( wtp_header_fixed, hf_wtp_header_sequence_number , tvb, offCur + i, 1, bo_little_endian );
431                                         }
432                                         break;
433
434                                 default:
435                                         break;
436                         };
437
438                         if( fCon ) {
439                                 /* There is a variable part if the Con flag is set */ 
440                                 ti = proto_tree_add_bytes_format(
441                                                 wtp_tree,                       /* tree */
442                                                 hf_wtp_header_variable_part,    /* id */
443                                                 tvb, 
444                                                 offCur + cbHeader,              /* start */
445                                                 vHeader,                        /* length */
446                                                 "What should go here!",         /* value */
447                                                 "Header (Variable part) %02X %02X %02X %02X"  ,                 /* format */
448                                                 0, 1, 2, 3
449                                     );
450                         } else {
451                                 /* There is no variable part */
452                         }; /* End of variable part of header */
453                 }
454         } else {
455 #ifdef DEBUG
456                 fprintf( stderr, "dissect_wtp: (4) tree was %p\n", tree ); 
457 #endif
458         }
459
460         /* Any remaining data ought to be WSP data,
461          * so hand off to the WSP dissector */
462         if (tvb_reported_length (tvb) > cbHeader + vHeader)
463         {
464                 wsp_tvb = tvb_new_subset(tvb, cbHeader + vHeader, -1,
465                         tvb_reported_length (tvb)-cbHeader-vHeader);
466                 call_dissector(wsp_handle, wsp_tvb, pinfo, tree);
467         }
468 }
469
470 /*
471  * Called directly from UDP.
472  * Put "WTP+WSP" into the "Protocol" column.
473  */
474 static void
475 dissect_wtp_fromudp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
476 {
477         if (check_col(pinfo->cinfo, COL_PROTOCOL))
478                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "WTP+WSP" );
479         if (check_col(pinfo->cinfo, COL_INFO)) {
480                 col_clear(pinfo->cinfo, COL_INFO);
481         }
482
483         dissect_wtp_common(tvb, pinfo, tree);
484 }
485
486 /*
487  * Called from a higher-level WAP dissector, presumably WTLS.
488  * Put "WTLS+WSP+WTP" to the "Protocol" column.
489  *
490  * XXX - is this supposed to be called from WTLS?  If so, we're not
491  * calling it....
492  *
493  * XXX - can this be called from any other dissector?
494  */
495 static void
496 dissect_wtp_fromwap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
497 {
498         if (check_col(pinfo->cinfo, COL_PROTOCOL))
499                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "WTLS+WTP+WSP" );
500         if (check_col(pinfo->cinfo, COL_INFO)) {
501                 col_clear(pinfo->cinfo, COL_INFO);
502         }
503
504         dissect_wtp_common(tvb, pinfo, tree);
505 }
506
507 static char pdu_type(unsigned char octet)
508 {
509         char ch = (octet >> 3) & 0x0F;
510         /* Note pdu type must not be 0x00 */
511         return ch;
512 };
513
514 static char transaction_class(unsigned char octet)
515 {
516         char ch = (octet >> 0) & 0x03; /* ......XX */
517         return ch;
518 };
519
520 static char retransmission_indicator(unsigned char octet)
521 {
522         switch ( pdu_type(octet) ) {
523                 case INVOKE:
524                 case RESULT:
525                 case ACK:
526                 case SEGMENTED_INVOKE:
527                 case SEGMENTED_RESULT:
528                 case NEGATIVE_ACK:
529                         return (octet >> 0) & 0x01; /* ......,X */
530                 default:
531                         return 0;
532         }
533 };
534
535 /* Register the protocol with Ethereal */
536 void
537 proto_register_wtp(void)
538 {                 
539
540 /* Setup list of header fields */
541         static hf_register_info hf[] = {
542                 { &hf_wtp_header_fixed_part,
543                         {       "Header",           
544                                 "wtp.header_fixed_part",
545                                 FT_BYTES, BASE_HEX, NULL, 0x0,          
546                                 "Fixed part of the header", HFILL
547                         }
548                 },
549                 { &hf_wtp_header_sub_pdu_size,
550                         {       "Sub PDU size",           
551                                 "wtp.sub_pdu_size",
552                                 FT_BYTES, BASE_HEX, NULL, 0x0,
553                                 "Size of Sub-PDU", HFILL
554                         }
555                 },
556                 { &hf_wtp_header_flag_continue,
557                         {       "Continue Flag",           
558                                 "wtp.continue_flag",
559                                 FT_BOOLEAN, 8, TFS( &continue_truth ), 0x80,          
560                                 "Continue Flag", HFILL
561                         }
562                 },
563                 { &hf_wtp_header_pdu_type,
564                         {       "PDU Type",           
565                                 "wtp.pdu_type",
566                                  FT_UINT8, BASE_HEX, VALS( vals_pdu_type ), 0x78,
567                                 "PDU Type", HFILL
568                         }
569                 },
570                 { &hf_wtp_header_flag_Trailer,
571                         {       "Trailer Flags",           
572                                 "wtp.trailer_flags",
573                                  FT_UINT8, BASE_HEX, VALS( vals_transaction_trailer ), 0x06,
574                                 "Trailer Flags", HFILL
575                         }
576                 },
577                 { &hf_wtp_header_flag_RID,
578                         {       "Re-transmission Indicator",           
579                                 "wtp.RID",
580                                  FT_BOOLEAN, 8, TFS( &RID_truth ), 0x01,
581                                 "Re-transmission Indicator", HFILL
582                         }
583                 },
584                 { &hf_wtp_header_flag_TID_response,
585                         {       "TID Response",           
586                                 "wtp.TID.response",
587                                 FT_BOOLEAN, 16, TFS( &tid_response_truth ), 0x8000,
588                                 "TID Response", HFILL
589                         }
590                 },
591                 { &hf_wtp_header_flag_TID,
592                         {       "Transaction ID",           
593                                 "wtp.TID",
594                                  FT_UINT16, BASE_HEX, NULL, 0x7FFF,
595                                 "Transaction ID", HFILL
596                         }
597                 },
598                 { &hf_wtp_header_Inv_version,
599                         {       "Version",           
600                                 "wtp.header.version",
601                                  FT_UINT8, BASE_HEX, VALS( vals_version ), 0xC0,
602                                 "Version", HFILL
603                         }
604                 },
605                 { &hf_wtp_header_Inv_flag_TIDNew,
606                         {       "TIDNew",           
607                                 "wtp.header.TIDNew",
608                                  FT_BOOLEAN, 8, TFS( &TIDNew_truth ), 0x20,
609                                 "TIDNew", HFILL
610                         }
611                 },
612                 { &hf_wtp_header_Inv_flag_UP,
613                         {       "U/P flag",           
614                                 "wtp.header.UP",
615                                  FT_BOOLEAN, 8, TFS( &UP_truth ), 0x10,
616                                 "U/P Flag", HFILL
617                         }
618                 },
619                 { &hf_wtp_header_Inv_Reserved,
620                         {       "Reserved",           
621                                 "wtp.inv.reserved",
622                                  FT_UINT8, BASE_HEX, NULL, 0x0C,
623                                 "Reserved", HFILL
624                         }
625                 },
626                 { &hf_wtp_header_Inv_TransactionClass,
627                         {       "Transaction Class",           
628                                 "wtp.inv.transaction_class",
629                                  FT_UINT8, BASE_HEX, VALS( vals_transaction_classes ), 0x03,
630                                 "Transaction Class", HFILL
631                         }
632                 },
633                 { &hf_wtp_header_Ack_flag_TVETOK,
634                         {       "Tve/Tok flag",           
635                                 "wtp.ack.tvetok",
636                                  FT_BOOLEAN, 8, TFS( &TVETOK_truth ), 0x04,
637                                 "Tve/Tok flag", HFILL
638                         }
639                 },
640                 { &hf_wtp_header_Abort_type,
641                         {       "Abort Type",           
642                                 "wtp.abort.type",
643                                  FT_UINT8, BASE_HEX, VALS ( vals_abort_type ), 0x07,
644                                 "Abort Type", HFILL
645                         }
646                 },
647                 { &hf_wtp_header_Abort_reason_provider,
648                         {       "Abort Reason",           
649                                 "wtp.abort.reason.provider",
650                                  FT_UINT8, BASE_HEX, VALS ( vals_abort_reason_provider ), 0x00,
651                                 "Abort Reason", HFILL
652                         }
653                 },
654                 /* Assume WSP is the user and use its reason codes */
655                 { &hf_wtp_header_Abort_reason_user,
656                         {       "Abort Reason",           
657                                 "wtp.abort.reason.user",
658                                  FT_UINT8, BASE_HEX, VALS ( vals_wsp_reason_codes ), 0x00,
659                                 "Abort Reason", HFILL
660                         }
661                 },
662                 { &hf_wtp_header_sequence_number,
663                         {       "Packet Sequence Number",           
664                                 "wtp.header.sequence",
665                                  FT_UINT8, BASE_HEX, NULL, 0x00,
666                                 "Packet Sequence Number", HFILL
667                         }
668                 },
669                 { &hf_wtp_header_missing_packets,
670                         {       "Missing Packets",           
671                                 "wtp.header.missing_packets",
672                                  FT_UINT8, BASE_HEX, NULL, 0x00,
673                                 "Missing Packets", HFILL
674                         }
675                 },
676                 { &hf_wtp_header_variable_part,
677                         {       "Header: Variable part",           
678                                 "wtp.header_variable_part",
679                                 FT_BYTES, BASE_HEX, NULL, 0x0,          
680                                 "Variable part of the header", HFILL
681                         }
682                 },
683                 { &hf_wtp_data,
684                         {       "Data",           
685                                 "wtp.header_data",
686                                 FT_BYTES, BASE_HEX, NULL, 0x0,          
687                                 "Data", HFILL
688                         }
689                 },
690         };
691         
692 /* Setup protocol subtree array */
693         static gint *ett[] = {
694                 &ett_wtp,
695                 &ett_header,
696         };
697
698 /* Register the protocol name and description */
699         proto_wtp = proto_register_protocol(
700                 "Wireless Transaction Protocol",   /* protocol name for use by ethereal */ 
701                 "WTP",                             /* short version of name */
702                 "wap-wsp-wtp"                      /* Abbreviated protocol name, should Match IANA 
703                                                     < URL:http://www.isi.edu/in-notes/iana/assignments/port-numbers/ >
704                                                   */
705         );
706
707 /* Required function calls to register the header fields and subtrees used */
708         proto_register_field_array(proto_wtp, hf, array_length(hf));
709         proto_register_subtree_array(ett, array_length(ett));
710
711         register_dissector("wtp", dissect_wtp_fromwap, proto_wtp);
712         register_dissector("wtp-udp", dissect_wtp_fromudp, proto_wtp);
713 };
714
715 void
716 proto_reg_handoff_wtp(void)
717 {
718         dissector_handle_t wtp_fromudp_handle;
719
720         /*
721          * Get a handle for the connection-oriented WSP dissector - if WTP
722          * PDUs have data, it is WSP.
723          */
724         wsp_handle = find_dissector("wsp-co");
725
726         wtp_fromudp_handle = find_dissector("wtp-udp");
727         dissector_add("udp.port", UDP_PORT_WTP_WSP, wtp_fromudp_handle);
728 }