3 * Routines to dissect WTP component of WAP traffic.
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * WAP dissector based on original work by Ben Fowler
12 * Updated by Neil Hunter <neil.hunter@energis-squared.com>
13 * WTLS support by Alexandre P. Ferreira (Splice IP)
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38 #include <epan/packet.h>
39 #include <epan/reassemble.h>
40 #include <epan/wmem/wmem.h>
41 #include "packet-wap.h"
42 #include "packet-wtp.h"
43 #include "packet-wsp.h"
45 static const true_false_string continue_truth
= {
50 static const true_false_string RID_truth
= {
55 static const true_false_string TIDNew_truth
= {
60 static const true_false_string tid_response_truth
= {
65 static const true_false_string UP_truth
= {
66 "User Acknowledgement required" ,
67 "User Acknowledgement optional"
70 static const true_false_string TVETOK_truth
= {
75 static const value_string vals_wtp_pdu_type
[] = {
81 { 5, "Segmented Invoke" },
82 { 6, "Segmented Result" },
83 { 7, "Negative Ack" },
87 static const value_string vals_transaction_trailer
[] = {
88 { 0, "Not last packet" },
89 { 1, "Last packet of message" },
90 { 2, "Last packet of group" },
91 { 3, "Re-assembly not supported" },
95 static const value_string vals_version
[] = {
103 static const value_string vals_abort_type
[] = {
109 static const value_string vals_abort_reason_provider
[] = {
111 { 0x01, "Protocol Error" },
112 { 0x02, "Invalid TID" },
113 { 0x03, "Not Implemented Class 2" },
114 { 0x04, "Not Implemented SAR" },
115 { 0x05, "Not Implemented User Acknowledgement" },
116 { 0x06, "WTP Version Zero" },
117 { 0x07, "Capacity Temporarily Exceeded" },
118 { 0x08, "No Response" },
119 { 0x09, "Message Too Large" },
123 static const value_string vals_transaction_classes
[] = {
124 { 0x00, "Unreliable Invoke without Result" },
125 { 0x01, "Reliable Invoke without Result" },
126 { 0x02, "Reliable Invoke with Reliable Result" },
130 static const value_string vals_tpi_type
[] = {
134 { 0x03, "Packet sequence number" },
135 { 0x04, "SDU boundary" },
136 { 0x05, "Frame boundary" },
140 static const value_string vals_tpi_opt
[] = {
141 { 0x01, "Maximum receive unit" },
142 { 0x02, "Total message size" },
143 { 0x03, "Delay transmission timer" },
144 { 0x04, "Maximum group" },
145 { 0x05, "Current TID" },
146 { 0x06, "No cached TID" },
150 /* File scoped variables for the protocol and registered fields */
151 static int proto_wtp
= HF_EMPTY
;
153 /* These fields used by fixed part of header */
154 static int hf_wtp_header_sub_pdu_size
= HF_EMPTY
;
155 static int hf_wtp_header_flag_continue
= HF_EMPTY
;
156 static int hf_wtp_header_pdu_type
= HF_EMPTY
;
157 static int hf_wtp_header_flag_Trailer
= HF_EMPTY
;
158 static int hf_wtp_header_flag_RID
= HF_EMPTY
;
159 static int hf_wtp_header_flag_TID
= HF_EMPTY
;
160 static int hf_wtp_header_flag_TID_response
= HF_EMPTY
;
162 /* These fields used by Invoke packets */
163 static int hf_wtp_header_Inv_version
= HF_EMPTY
;
164 static int hf_wtp_header_Inv_flag_TIDNew
= HF_EMPTY
;
165 static int hf_wtp_header_Inv_flag_UP
= HF_EMPTY
;
166 static int hf_wtp_header_Inv_Reserved
= HF_EMPTY
;
167 static int hf_wtp_header_Inv_TransactionClass
= HF_EMPTY
;
169 /* static int hf_wtp_header_variable_part = HF_EMPTY; */
170 /* static int hf_wtp_data = HF_EMPTY; */
172 static int hf_wtp_tpi_type
= HF_EMPTY
;
173 static int hf_wtp_tpi_psn
= HF_EMPTY
;
174 static int hf_wtp_tpi_opt
= HF_EMPTY
;
175 static int hf_wtp_tpi_optval
= HF_EMPTY
;
176 static int hf_wtp_tpi_info
= HF_EMPTY
;
178 static int hf_wtp_header_Ack_flag_TVETOK
= HF_EMPTY
;
179 static int hf_wtp_header_Abort_type
= HF_EMPTY
;
180 static int hf_wtp_header_Abort_reason_provider
= HF_EMPTY
;
181 static int hf_wtp_header_Abort_reason_user
= HF_EMPTY
;
182 static int hf_wtp_header_sequence_number
= HF_EMPTY
;
183 static int hf_wtp_header_missing_packets
= HF_EMPTY
;
185 /* These fields used when reassembling WTP fragments */
186 static int hf_wtp_fragments
= HF_EMPTY
;
187 static int hf_wtp_fragment
= HF_EMPTY
;
188 static int hf_wtp_fragment_overlap
= HF_EMPTY
;
189 static int hf_wtp_fragment_overlap_conflict
= HF_EMPTY
;
190 static int hf_wtp_fragment_multiple_tails
= HF_EMPTY
;
191 static int hf_wtp_fragment_too_long_fragment
= HF_EMPTY
;
192 static int hf_wtp_fragment_error
= HF_EMPTY
;
193 static int hf_wtp_fragment_count
= HF_EMPTY
;
194 static int hf_wtp_reassembled_in
= HF_EMPTY
;
195 static int hf_wtp_reassembled_length
= HF_EMPTY
;
197 /* Initialize the subtree pointers */
198 static gint ett_wtp
= ETT_EMPTY
;
199 static gint ett_wtp_sub_pdu_tree
= ETT_EMPTY
;
200 static gint ett_header
= ETT_EMPTY
;
201 static gint ett_tpilist
= ETT_EMPTY
;
202 static gint ett_wsp_fragments
= ETT_EMPTY
;
203 static gint ett_wtp_fragment
= ETT_EMPTY
;
205 static const fragment_items wtp_frag_items
= {
210 &hf_wtp_fragment_overlap
,
211 &hf_wtp_fragment_overlap_conflict
,
212 &hf_wtp_fragment_multiple_tails
,
213 &hf_wtp_fragment_too_long_fragment
,
214 &hf_wtp_fragment_error
,
215 &hf_wtp_fragment_count
,
216 &hf_wtp_reassembled_in
,
217 &hf_wtp_reassembled_length
,
218 /* Reassembled data field */
223 /* Handle for WSP dissector */
224 static dissector_handle_t wsp_handle
;
229 static reassembly_table wtp_reassembly_table
;
232 wtp_defragment_init(void)
234 reassembly_table_init(&wtp_reassembly_table
,
235 &addresses_reassembly_table_functions
);
239 * Extract some bitfields
241 #define pdu_type(octet) (((octet) >> 3) & 0x0F) /* Note pdu type must not be 0x00 */
242 #define transaction_class(octet) ((octet) & 0x03) /* ......XX */
243 #define transmission_trailer(octet) (((octet) >> 1) & 0x01) /* ......X. */
245 static char retransmission_indicator(unsigned char octet
)
247 switch (pdu_type(octet
)) {
251 case SEGMENTED_INVOKE
:
252 case SEGMENTED_RESULT
:
254 return octet
& 0x01; /* .......X */
264 wtp_handle_tpi(proto_tree
*tree
, tvbuff_t
*tvb
)
270 proto_tree
*subTree
= NULL
;
273 tByte
= tvb_get_guint8(tvb
, offset
++);
274 tType
= (tByte
& 0x78) >> 3;
275 if (tByte
& 0x04) /* Long TPI */
276 tLen
= tvb_get_guint8(tvb
, offset
++);
279 pi
= proto_tree_add_uint(tree
, hf_wtp_tpi_type
,
280 tvb
, 0, tvb_length(tvb
), tType
);
281 subTree
= proto_item_add_subtree(pi
, ett_tpilist
);
283 case 0x00: /* Error*/
286 case 0x01: /* Info */
287 /* Beware, untested case here */
288 proto_tree_add_item(subTree
, hf_wtp_tpi_info
,
289 tvb
, offset
, tLen
, ENC_NA
);
291 case 0x02: /* Option */
292 proto_tree_add_item(subTree
, hf_wtp_tpi_opt
,
293 tvb
, offset
++, 1, ENC_LITTLE_ENDIAN
);
294 proto_tree_add_item(subTree
, hf_wtp_tpi_optval
,
295 tvb
, offset
, tLen
- 1, ENC_NA
);
298 proto_tree_add_item(subTree
, hf_wtp_tpi_psn
,
299 tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
301 case 0x04: /* SDU boundary */
304 case 0x05: /* Frame boundary */
312 /* Code to actually dissect the packets */
314 dissect_wtp_common(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
317 int offCur
= 0; /* current offset from start of WTP data */
318 gint returned_length
, str_index
= 0;
322 /* continuation flag */
323 unsigned char fCon
; /* Continue flag */
324 unsigned char fRID
; /* Re-transmission indicator*/
325 unsigned char fTTR
= '\0'; /* Transmission trailer */
326 guint cbHeader
= 0; /* Fixed header length */
327 guint vHeader
= 0; /* Variable header length*/
330 /* Set up structures we'll need to add the protocol subtree and manage it */
331 proto_item
*ti
= NULL
;
332 proto_tree
*wtp_tree
= NULL
;
335 char clsTransaction
= 3;
336 int numMissing
= 0; /* Number of missing packets in a negative ack */
338 tvbuff_t
*wsp_tvb
= NULL
;
339 guint8 psn
= 0; /* Packet sequence number*/
340 guint16 TID
= 0; /* Transaction-Id */
344 #define SZINFO_SIZE 256
345 szInfo
=(char *)wmem_alloc(wmem_packet_scope(), SZINFO_SIZE
);
347 b0
= tvb_get_guint8 (tvb
, offCur
+ 0);
348 /* Discover Concatenated PDUs */
350 guint c_fieldlen
= 0; /* Length of length-field */
351 guint c_pdulen
= 0; /* Length of conc. PDU */
354 ti
= proto_tree_add_item(tree
, proto_wtp
,
355 tvb
, offCur
, 1, ENC_NA
);
356 wtp_tree
= proto_item_add_subtree(ti
, ett_wtp_sub_pdu_tree
);
357 proto_item_append_text(ti
, ", PDU concatenation");
361 while (offCur
< (int) tvb_reported_length(tvb
)) {
363 /* The length of an embedded WTP PDU is coded as either:
364 * - a 7-bit value contained in one octet with highest bit == 0.
365 * - a 15-bit value contained in two octets (little endian)
366 * if the 1st octet has its highest bit == 1.
367 * This means that this is NOT encoded as an uintvar-integer!!!
369 b0
= tvb_get_guint8(tvb
, offCur
+ 0);
372 c_pdulen
= ((b0
& 0x7f) << 8) | tvb_get_guint8(tvb
, offCur
+ 1);
378 proto_tree_add_uint(wtp_tree
, hf_wtp_header_sub_pdu_size
,
379 tvb
, offCur
, c_fieldlen
, c_pdulen
);
382 col_append_str(pinfo
->cinfo
, COL_INFO
, ", ");
384 /* Skip the length field for the WTP sub-tvb */
385 wtp_tvb
= tvb_new_subset(tvb
, offCur
+ c_fieldlen
, c_pdulen
, c_pdulen
);
386 dissect_wtp_common(wtp_tvb
, pinfo
, wtp_tree
);
387 offCur
+= c_fieldlen
+ c_pdulen
;
391 proto_item_append_text(ti
, ", PDU count: %u", i
);
395 /* No concatenation */
397 fRID
= retransmission_indicator(b0
);
401 printf("WTP packet %u: tree = %p, pdu = %s (%u) length: %u\n",
402 pinfo
->fd
->num
, tree
,
403 val_to_str(pdut
, vals_wtp_pdu_type
, "Unknown PDU type 0x%x"),
404 pdut
, tvb_length(tvb
));
407 /* Develop the string to put in the Info column */
408 returned_length
= g_snprintf(szInfo
, SZINFO_SIZE
, "WTP %s",
409 val_to_str(pdut
, vals_wtp_pdu_type
, "Unknown PDU type 0x%x"));
410 str_index
+= MIN(returned_length
, SZINFO_SIZE
-str_index
);
414 fTTR
= transmission_trailer(b0
);
415 TID
= tvb_get_ntohs(tvb
, offCur
+ 1);
417 clsTransaction
= transaction_class(tvb_get_guint8(tvb
, offCur
+ 3));
418 returned_length
= g_snprintf(&szInfo
[str_index
], SZINFO_SIZE
-str_index
,
419 " Class %d", clsTransaction
);
420 str_index
+= MIN(returned_length
, SZINFO_SIZE
-str_index
);
424 case SEGMENTED_INVOKE
:
425 case SEGMENTED_RESULT
:
426 fTTR
= transmission_trailer(b0
);
427 TID
= tvb_get_ntohs(tvb
, offCur
+ 1);
428 psn
= tvb_get_guint8(tvb
, offCur
+ 3);
430 returned_length
= g_snprintf(&szInfo
[str_index
], SZINFO_SIZE
-str_index
,
432 str_index
+= MIN(returned_length
, SZINFO_SIZE
-str_index
);
442 fTTR
= transmission_trailer(b0
);
443 TID
= tvb_get_ntohs(tvb
, offCur
+ 1);
453 /* Variable number of missing packets */
454 numMissing
= tvb_get_guint8(tvb
, offCur
+ 3);
455 cbHeader
= numMissing
+ 4;
462 /*returned_length =*/ g_snprintf(&szInfo
[str_index
], SZINFO_SIZE
-str_index
, " R" );
463 /*str_index += MIN(returned_length, SZINFO_SIZE-str_index);*/
465 /* In the interest of speed, if "tree" is NULL, don't do any work not
466 necessary to generate protocol tree items. */
469 fprintf(stderr
, "dissect_wtp: cbHeader = %d\n", cbHeader
);
471 /* NOTE - Length will be set when we process the TPI */
472 ti
= proto_tree_add_item(tree
, proto_wtp
, tvb
, offCur
, 0, ENC_NA
);
474 fprintf(stderr
, "dissect_wtp: (7) Returned from proto_tree_add_item\n");
476 wtp_tree
= proto_item_add_subtree(ti
, ett_wtp
);
478 /* Code to process the packet goes here */
480 fprintf(stderr
, "dissect_wtp: cbHeader = %d\n", cbHeader
);
481 fprintf(stderr
, "dissect_wtp: offCur = %d\n", offCur
);
483 /* Add common items: only CON and PDU Type */
486 hf_wtp_header_flag_continue
, /* id */
488 offCur
, /* start of highlight */
489 1, /* length of highlight*/
492 proto_tree_add_item(wtp_tree
, hf_wtp_header_pdu_type
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
496 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_Trailer
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
497 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_RID
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
498 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID_response
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
499 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
501 proto_tree_add_item(wtp_tree
, hf_wtp_header_Inv_version
, tvb
, offCur
+ 3, 1, ENC_LITTLE_ENDIAN
);
502 proto_tree_add_item(wtp_tree
, hf_wtp_header_Inv_flag_TIDNew
, tvb
, offCur
+ 3, 1, ENC_LITTLE_ENDIAN
);
503 proto_tree_add_item(wtp_tree
, hf_wtp_header_Inv_flag_UP
, tvb
, offCur
+ 3, 1, ENC_LITTLE_ENDIAN
);
504 proto_tree_add_item(wtp_tree
, hf_wtp_header_Inv_Reserved
, tvb
, offCur
+ 3, 1, ENC_LITTLE_ENDIAN
);
505 proto_tree_add_item(wtp_tree
, hf_wtp_header_Inv_TransactionClass
, tvb
, offCur
+ 3, 1, ENC_LITTLE_ENDIAN
);
506 proto_item_append_text(ti
,
508 ", Transaction Class: %s (%u)",
510 val_to_str_const(clsTransaction
, vals_transaction_classes
, "Undefined"),
515 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_Trailer
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
516 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_RID
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
517 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID_response
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
518 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
519 proto_item_append_text(ti
, ", PDU: Result (%u)", RESULT
);
523 proto_tree_add_item(wtp_tree
, hf_wtp_header_Ack_flag_TVETOK
, tvb
, offCur
, 1, ENC_BIG_ENDIAN
);
525 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_RID
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
526 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID_response
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
527 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
528 proto_item_append_text(ti
, ", PDU: ACK (%u)", ACK
);
532 abortType
= tvb_get_guint8 (tvb
, offCur
) & 0x07;
533 proto_tree_add_item(wtp_tree
, hf_wtp_header_Abort_type
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
534 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID_response
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
535 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
537 if (abortType
== PROVIDER
) {
538 guint8 reason
= tvb_get_guint8(tvb
, offCur
+ 3);
539 proto_tree_add_item( wtp_tree
, hf_wtp_header_Abort_reason_provider
, tvb
, offCur
+ 3 , 1, ENC_LITTLE_ENDIAN
);
540 proto_item_append_text(ti
,
542 ", Type: Provider (%u)"
546 val_to_str_const(reason
, vals_abort_reason_provider
, "Undefined"),
549 else if (abortType
== USER
) {
550 guint8 reason
= tvb_get_guint8(tvb
, offCur
+ 3);
551 proto_tree_add_item(wtp_tree
, hf_wtp_header_Abort_reason_user
, tvb
, offCur
+ 3 , 1, ENC_LITTLE_ENDIAN
);
552 proto_item_append_text(ti
,
558 val_to_str_ext_const(reason
, &vals_wsp_reason_codes_ext
, "Undefined"),
563 case SEGMENTED_INVOKE
:
564 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_Trailer
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
565 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_RID
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
566 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID_response
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
567 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
569 proto_tree_add_item(wtp_tree
, hf_wtp_header_sequence_number
, tvb
, offCur
+ 3, 1, ENC_LITTLE_ENDIAN
);
570 proto_item_append_text(ti
,
571 ", PDU: Segmented Invoke (%u)"
572 ", Packet Sequence Number: %u",
573 SEGMENTED_INVOKE
, psn
);
576 case SEGMENTED_RESULT
:
577 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_Trailer
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
578 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_RID
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
579 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID_response
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
580 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
582 proto_tree_add_item(wtp_tree
, hf_wtp_header_sequence_number
, tvb
, offCur
+ 3, 1, ENC_LITTLE_ENDIAN
);
583 proto_item_append_text(ti
,
584 ", PDU: Segmented Result (%u)"
585 ", Packet Sequence Number: %u",
586 SEGMENTED_RESULT
, psn
);
590 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_RID
, tvb
, offCur
, 1, ENC_LITTLE_ENDIAN
);
591 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID_response
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
592 proto_tree_add_item(wtp_tree
, hf_wtp_header_flag_TID
, tvb
, offCur
+ 1, 2, ENC_BIG_ENDIAN
);
594 proto_tree_add_item(wtp_tree
, hf_wtp_header_missing_packets
, tvb
, offCur
+ 3, 1, ENC_LITTLE_ENDIAN
);
595 /* Iterate through missing packets */
596 for (i
= 0; i
< numMissing
; i
++)
598 proto_tree_add_item(wtp_tree
, hf_wtp_header_sequence_number
, tvb
, offCur
+ 4 + i
, 1, ENC_LITTLE_ENDIAN
);
600 proto_item_append_text(ti
,
601 ", PDU: Negative Ack (%u)"
602 ", Missing Packets: %u",
603 NEGATIVE_ACK
, numMissing
);
610 proto_item_append_text(ti
, ", Retransmission");
612 } else { /* tree is NULL */
614 fprintf(stderr
, "dissect_wtp: (4) tree was %p\n", tree
);
617 /* Process the variable part */
618 if (fCon
) { /* Now, analyze variable part */
624 vHeader
= 0; /* Start scan all over */
627 tByte
= tvb_get_guint8(tvb
, offCur
+ cbHeader
+ vHeader
);
629 if (tByte
& 0x04) /* Long TPI */
630 tpiLen
= 2 + tvb_get_guint8(tvb
, offCur
+ cbHeader
+ vHeader
+ 1);
632 tpiLen
= 1 + (tByte
& 0x03);
635 tmp_tvb
= tvb_new_subset(tvb
, offCur
+ cbHeader
+ vHeader
, tpiLen
, tpiLen
);
636 wtp_handle_tpi(wtp_tree
, tmp_tvb
);
641 /* There is no variable part */
642 } /* End of variable part of header */
644 /* Set the length of the WTP protocol part now we know the length of the
645 * fixed and variable WTP headers */
647 proto_item_set_len(ti
, cbHeader
+ vHeader
);
650 fprintf( stderr
, "dissect_wtp: cbHeader = %d\n", cbHeader
);
654 * Any remaining data ought to be WSP data (if not WTP ACK, NACK
655 * or ABORT pdu), so, if we have any remaining data, and it's
656 * not an ACK, NACK, or ABORT PDU, hand it off (defragmented) to the
658 * Note that the last packet of a fragmented WTP message needn't
659 * contain any data, so we allow payloadless packets to be
660 * reassembled. (XXX - does the reassembly code handle this
661 * for packets other than the last packet?)
663 * Try calling a subdissector only if:
664 * - The WTP payload is ressembled in this very packet,
665 * - The WTP payload is not fragmented across packets.
667 dataOffset
= offCur
+ cbHeader
+ vHeader
;
668 dataLen
= tvb_reported_length_remaining(tvb
, dataOffset
);
669 if ((dataLen
>= 0) &&
670 ! ((pdut
==ACK
) || (pdut
==NEGATIVE_ACK
) || (pdut
==ABORT
)))
672 /* Try to reassemble if needed, and hand over to WSP
673 * A fragmented WTP packet is either:
674 * - An INVOKE with fTTR (transmission trailer) not set,
675 * - a SEGMENTED_INVOKE,
676 * - A RESULT with fTTR (transmission trailer) not set,
677 * - a SEGMENTED_RESULT.
679 if ( ( (pdut
== SEGMENTED_INVOKE
) || (pdut
== SEGMENTED_RESULT
)
680 || ( ((pdut
== INVOKE
) || (pdut
== RESULT
)) && (!fTTR
) )
681 ) && tvb_bytes_exist(tvb
, dataOffset
, dataLen
) )
683 /* Try reassembling fragments */
684 fragment_head
*fd_wtp
= NULL
;
685 guint32 reassembled_in
= 0;
686 gboolean save_fragmented
= pinfo
->fragmented
;
688 pinfo
->fragmented
= TRUE
;
689 fd_wtp
= fragment_add_seq(&wtp_reassembly_table
, tvb
, dataOffset
,
690 pinfo
, TID
, NULL
, psn
, dataLen
, !fTTR
, 0);
691 /* XXX - fragment_add_seq() yields NULL unless Wireshark knows
692 * that the packet is part of a reassembled whole. This means
693 * that fd_wtp will be NULL as long as Wireshark did not encounter
694 * (and process) the packet containing the last fragment.
695 * This implies that Wireshark needs two passes over the data for
696 * correct reassembly. At the first pass, a capture containing
697 * three fragments plus a retransmssion of the last fragment
698 * will progressively show:
700 * Packet 1: (Unreassembled fragment 1)
701 * Packet 2: (Unreassembled fragment 2)
702 * Packet 3: (Reassembled WTP)
703 * Packet 4: (WTP payload reassembled in packet 3)
705 * However at subsequent evaluation (e.g., by applying a display
706 * filter) the packet summary will show:
708 * Packet 1: (WTP payload reassembled in packet 3)
709 * Packet 2: (WTP payload reassembled in packet 3)
710 * Packet 3: (Reassembled WTP)
711 * Packet 4: (WTP payload reassembled in packet 3)
713 * This is important to know, and also affects read filters!
715 wsp_tvb
= process_reassembled_data(tvb
, dataOffset
, pinfo
,
716 "Reassembled WTP", fd_wtp
, &wtp_frag_items
,
719 printf("WTP: Packet %u %s -> %d: wsp_tvb = %p, fd_wtp = %p, frame = %u\n",
721 fd_wtp
? "Reassembled" : "Not reassembled",
722 fd_wtp
? fd_wtp
->reassembled_in
: -1,
729 reassembled_in
= fd_wtp
->reassembled_in
;
730 if (pinfo
->fd
->num
== reassembled_in
) {
731 /* Reassembled in this very packet:
732 * We can safely hand the tvb to the WSP dissector */
733 call_dissector(wsp_handle
, wsp_tvb
, pinfo
, tree
);
735 /* Not reassembled in this packet */
736 col_append_fstr(pinfo
->cinfo
, COL_INFO
,
737 "%s (WTP payload reassembled in packet %u)",
738 szInfo
, fd_wtp
->reassembled_in
);
740 proto_tree_add_text(wtp_tree
, tvb
, dataOffset
, -1, "Payload");
743 /* Not reassembled yet, or not reassembled at all */
744 col_append_fstr(pinfo
->cinfo
, COL_INFO
,
745 "%s (Unreassembled fragment %u)",
747 proto_tree_add_text(wtp_tree
, tvb
, dataOffset
, -1, "Payload");
749 /* Now reset fragmentation information in pinfo */
750 pinfo
->fragmented
= save_fragmented
;
752 else if ( ((pdut
== INVOKE
) || (pdut
== RESULT
)) && (fTTR
) )
754 /* Non-fragmented payload */
755 wsp_tvb
= tvb_new_subset_remaining(tvb
, dataOffset
);
756 /* We can safely hand the tvb to the WSP dissector */
757 call_dissector(wsp_handle
, wsp_tvb
, pinfo
, tree
);
761 /* Nothing to hand to subdissector */
762 col_append_str(pinfo
->cinfo
, COL_INFO
, szInfo
);
767 /* Nothing to hand to subdissector */
768 col_append_str(pinfo
->cinfo
, COL_INFO
, szInfo
);
773 * Called directly from UDP.
774 * Put "WTP+WSP" into the "Protocol" column.
777 dissect_wtp_fromudp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
779 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "WTP+WSP");
780 col_clear(pinfo
->cinfo
, COL_INFO
);
782 dissect_wtp_common(tvb
, pinfo
, tree
);
786 * Called from a higher-level WAP dissector, presumably WTLS.
787 * Put "WTLS+WSP+WTP" to the "Protocol" column.
789 * XXX - is this supposed to be called from WTLS? If so, we're not
792 * XXX - can this be called from any other dissector?
795 dissect_wtp_fromwtls(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
797 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "WTLS+WTP+WSP");
798 col_clear(pinfo
->cinfo
, COL_INFO
);
800 dissect_wtp_common(tvb
, pinfo
, tree
);
803 /* Register the protocol with Wireshark */
805 proto_register_wtp(void)
808 /* Setup list of header fields */
809 static hf_register_info hf
[] = {
810 { &hf_wtp_header_sub_pdu_size
,
811 { "Sub PDU size", "wtp.sub_pdu_size",
812 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
813 "Size of Sub-PDU (bytes)", HFILL
816 { &hf_wtp_header_flag_continue
,
817 { "Continue Flag", "wtp.continue_flag",
818 FT_BOOLEAN
, 8, TFS( &continue_truth
), 0x80,
822 { &hf_wtp_header_pdu_type
,
823 { "PDU Type", "wtp.pdu_type",
824 FT_UINT8
, BASE_HEX
, VALS( vals_wtp_pdu_type
), 0x78,
828 { &hf_wtp_header_flag_Trailer
,
829 { "Trailer Flags", "wtp.trailer_flags",
830 FT_UINT8
, BASE_HEX
, VALS( vals_transaction_trailer
), 0x06,
834 { &hf_wtp_header_flag_RID
,
835 { "Re-transmission Indicator", "wtp.RID",
836 FT_BOOLEAN
, 8, TFS( &RID_truth
), 0x01,
840 { &hf_wtp_header_flag_TID_response
,
841 { "TID Response", "wtp.TID.response",
842 FT_BOOLEAN
, 16, TFS( &tid_response_truth
), 0x8000,
846 { &hf_wtp_header_flag_TID
,
847 { "Transaction ID", "wtp.TID",
848 FT_UINT16
, BASE_HEX
, NULL
, 0x7FFF,
852 { &hf_wtp_header_Inv_version
,
853 { "Version", "wtp.header.version",
854 FT_UINT8
, BASE_HEX
, VALS( vals_version
), 0xC0,
858 { &hf_wtp_header_Inv_flag_TIDNew
,
859 { "TIDNew", "wtp.header.TIDNew",
860 FT_BOOLEAN
, 8, TFS( &TIDNew_truth
), 0x20,
864 { &hf_wtp_header_Inv_flag_UP
,
865 { "U/P flag", "wtp.header.UP",
866 FT_BOOLEAN
, 8, TFS( &UP_truth
), 0x10,
870 { &hf_wtp_header_Inv_Reserved
,
871 { "Reserved", "wtp.inv.reserved",
872 FT_UINT8
, BASE_HEX
, NULL
, 0x0C,
876 { &hf_wtp_header_Inv_TransactionClass
,
877 { "Transaction Class", "wtp.inv.transaction_class",
878 FT_UINT8
, BASE_HEX
, VALS( vals_transaction_classes
), 0x03,
882 { &hf_wtp_header_Ack_flag_TVETOK
,
883 { "Tve/Tok flag", "wtp.ack.tvetok",
884 FT_BOOLEAN
, 8, TFS( &TVETOK_truth
), 0x04,
888 { &hf_wtp_header_Abort_type
,
889 { "Abort Type", "wtp.abort.type",
890 FT_UINT8
, BASE_HEX
, VALS ( vals_abort_type
), 0x07,
894 { &hf_wtp_header_Abort_reason_provider
,
895 { "Abort Reason", "wtp.abort.reason.provider",
896 FT_UINT8
, BASE_HEX
, VALS ( vals_abort_reason_provider
), 0x00,
900 /* Assume WSP is the user and use its reason codes */
901 { &hf_wtp_header_Abort_reason_user
,
902 { "Abort Reason", "wtp.abort.reason.user",
903 FT_UINT8
, BASE_HEX
|BASE_EXT_STRING
, &vals_wsp_reason_codes_ext
, 0x00,
907 { &hf_wtp_header_sequence_number
,
908 { "Packet Sequence Number", "wtp.header.sequence",
909 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
913 { &hf_wtp_header_missing_packets
,
914 { "Missing Packets", "wtp.header.missing_packets",
915 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
920 { &hf_wtp_header_variable_part
,
921 { "Header: Variable part", "wtp.header_variable_part",
922 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
923 "Variable part of the header", HFILL
927 { "Data", "wtp.header_data",
928 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
935 FT_UINT8
, BASE_HEX
, VALS(vals_tpi_type
), 0x00,
936 "Identification of the Transport Information Item", HFILL
940 { "Packet sequence number", "wtp.tpi.psn",
941 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
942 "Sequence number of this packet", HFILL
946 { "Option", "wtp.tpi.opt",
947 FT_UINT8
, BASE_HEX
, VALS(vals_tpi_opt
), 0x00,
948 "The given option for this TPI", HFILL
951 { &hf_wtp_tpi_optval
,
952 { "Option Value", "wtp.tpi.opt.val",
953 FT_NONE
, BASE_NONE
, NULL
, 0x00,
954 "The value that is supplied with this option", HFILL
958 { "Information", "wtp.tpi.info",
959 FT_NONE
, BASE_NONE
, NULL
, 0x00,
960 "The information being send by this TPI", HFILL
964 /* Fragment fields */
965 { &hf_wtp_fragment_overlap
,
966 { "Fragment overlap", "wtp.fragment.overlap",
967 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
968 "Fragment overlaps with other fragments", HFILL
971 { &hf_wtp_fragment_overlap_conflict
,
972 { "Conflicting data in fragment overlap", "wtp.fragment.overlap.conflict",
973 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
974 "Overlapping fragments contained conflicting data", HFILL
977 { &hf_wtp_fragment_multiple_tails
,
978 { "Multiple tail fragments found", "wtp.fragment.multipletails",
979 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
980 "Several tails were found when defragmenting the packet", HFILL
983 { &hf_wtp_fragment_too_long_fragment
,
984 { "Fragment too long", "wtp.fragment.toolongfragment",
985 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
986 "Fragment contained data past end of packet", HFILL
989 { &hf_wtp_fragment_error
,
990 { "Defragmentation error", "wtp.fragment.error",
991 FT_FRAMENUM
, BASE_NONE
, NULL
, 0x0,
992 "Defragmentation error due to illegal fragments", HFILL
995 { &hf_wtp_fragment_count
,
996 { "Fragment count", "wtp.fragment.count",
997 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1001 { &hf_wtp_reassembled_in
,
1002 { "Reassembled in", "wtp.reassembled.in",
1003 FT_FRAMENUM
, BASE_NONE
, NULL
, 0x0,
1004 "WTP fragments are reassembled in the given packet", HFILL
1007 { &hf_wtp_reassembled_length
,
1008 { "Reassembled WTP length", "wtp.reassembled.length",
1009 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1010 "The total length of the reassembled payload", HFILL
1014 { "WTP Fragment", "wtp.fragment",
1015 FT_FRAMENUM
, BASE_NONE
, NULL
, 0x0,
1019 { &hf_wtp_fragments
,
1020 { "WTP Fragments", "wtp.fragments",
1021 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1027 /* Setup protocol subtree array */
1028 static gint
*ett
[] = {
1030 &ett_wtp_sub_pdu_tree
,
1037 /* Register the protocol name and description */
1038 proto_wtp
= proto_register_protocol(
1039 "Wireless Transaction Protocol", /* protocol name for use by wireshark */
1040 "WTP", /* short version of name */
1041 "wtp" /* Abbreviated protocol name, should Match IANA
1042 < URL:http://www.iana.org/assignments/port-numbers/ >
1046 /* Required calls to register the header fields and subtrees used */
1047 proto_register_field_array(proto_wtp
, hf
, array_length(hf
));
1048 proto_register_subtree_array(ett
, array_length(ett
));
1050 register_dissector("wtp-wtls", dissect_wtp_fromwtls
, proto_wtp
);
1051 register_dissector("wtp-udp", dissect_wtp_fromudp
, proto_wtp
);
1052 register_init_routine(wtp_defragment_init
);
1056 proto_reg_handoff_wtp(void)
1058 dissector_handle_t wtp_fromudp_handle
;
1061 * Get a handle for the connection-oriented WSP dissector - if WTP
1062 * PDUs have data, it is WSP.
1064 wsp_handle
= find_dissector("wsp-co");
1066 wtp_fromudp_handle
= find_dissector("wtp-udp");
1067 dissector_add_uint("udp.port", UDP_PORT_WTP_WSP
, wtp_fromudp_handle
);
1068 dissector_add_uint("gsm_sms_ud.udh.port", UDP_PORT_WTP_WSP
, wtp_fromudp_handle
);
1069 dissector_add_uint("gsm_sms.udh.port", UDP_PORT_WTP_WSP
, wtp_fromudp_handle
);
1073 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1078 * indent-tabs-mode: nil
1081 * vi: set shiftwidth=4 tabstop=4 expandtab:
1082 * :indentSize=4:tabSize=4:noTabs=true: