HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-wtp.c
blobda81df4e4627a73c6f09b2fb10755ebb3f2aba9e
1 /* packet-wtp.c
3 * Routines to dissect WTP component of WAP traffic.
5 * $Id$
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.
30 #include "config.h"
32 #ifdef DEBUG
33 #include <stdio.h>
34 #endif
36 #include <glib.h>
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 = {
46 "TPI Present" ,
47 "No TPI"
50 static const true_false_string RID_truth = {
51 "Re-Transmission",
52 "First transmission"
55 static const true_false_string TIDNew_truth = {
56 "TID is new" ,
57 "TID is valid"
60 static const true_false_string tid_response_truth = {
61 "Response" ,
62 "Original"
65 static const true_false_string UP_truth = {
66 "User Acknowledgement required" ,
67 "User Acknowledgement optional"
70 static const true_false_string TVETOK_truth = {
71 "True",
72 "False"
75 static const value_string vals_wtp_pdu_type[] = {
76 { 0, "Not Allowed" },
77 { 1, "Invoke" },
78 { 2, "Result" },
79 { 3, "Ack" },
80 { 4, "Abort" },
81 { 5, "Segmented Invoke" },
82 { 6, "Segmented Result" },
83 { 7, "Negative Ack" },
84 { 0, NULL }
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" },
92 { 0, NULL }
95 static const value_string vals_version[] = {
96 { 0, "Current" },
97 { 1, "Undefined" },
98 { 2, "Undefined" },
99 { 3, "Undefined" },
100 { 0, NULL }
103 static const value_string vals_abort_type[] = {
104 { 0, "Provider" },
105 { 1, "User (WSP)" },
106 { 0, NULL }
109 static const value_string vals_abort_reason_provider[] = {
110 { 0x00, "Unknown" },
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" },
120 { 0x00, NULL }
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" },
127 { 0x00, NULL }
130 static const value_string vals_tpi_type[] = {
131 { 0x00, "Error" },
132 { 0x01, "Info" },
133 { 0x02, "Option" },
134 { 0x03, "Packet sequence number" },
135 { 0x04, "SDU boundary" },
136 { 0x05, "Frame boundary" },
137 { 0x00, NULL }
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" },
147 { 0x00, NULL }
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 = {
206 &ett_wtp_fragment,
207 &ett_wsp_fragments,
208 &hf_wtp_fragments,
209 &hf_wtp_fragment,
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 */
219 NULL,
220 "fragments"
223 /* Handle for WSP dissector */
224 static dissector_handle_t wsp_handle;
227 * reassembly of WSP
229 static reassembly_table wtp_reassembly_table;
231 static void
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)) {
248 case INVOKE:
249 case RESULT:
250 case ACK:
251 case SEGMENTED_INVOKE:
252 case SEGMENTED_RESULT:
253 case NEGATIVE_ACK:
254 return octet & 0x01; /* .......X */
255 default:
256 return 0;
261 * dissect a TPI
263 static void
264 wtp_handle_tpi(proto_tree *tree, tvbuff_t *tvb)
266 int offset = 0;
267 unsigned char tByte;
268 unsigned char tType;
269 unsigned char tLen;
270 proto_tree *subTree = NULL;
271 proto_item *pi;
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++);
277 else
278 tLen = tByte & 0x03;
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);
282 switch (tType) {
283 case 0x00: /* Error*/
284 /* \todo */
285 break;
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);
290 break;
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);
296 break;
297 case 0x03: /* PSN */
298 proto_tree_add_item(subTree, hf_wtp_tpi_psn,
299 tvb, offset, 1, ENC_LITTLE_ENDIAN);
300 break;
301 case 0x04: /* SDU boundary */
302 /* \todo */
303 break;
304 case 0x05: /* Frame boundary */
305 /* \todo */
306 break;
307 default:
308 break;
312 /* Code to actually dissect the packets */
313 static void
314 dissect_wtp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
316 char *szInfo;
317 int offCur = 0; /* current offset from start of WTP data */
318 gint returned_length, str_index = 0;
320 unsigned char b0;
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*/
328 int abortType = 0;
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;
334 char pdut;
335 char clsTransaction = 3;
336 int numMissing = 0; /* Number of missing packets in a negative ack */
337 int i;
338 tvbuff_t *wsp_tvb = NULL;
339 guint8 psn = 0; /* Packet sequence number*/
340 guint16 TID = 0; /* Transaction-Id */
341 int dataOffset;
342 gint dataLen;
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 */
349 if (b0 == 0) {
350 guint c_fieldlen = 0; /* Length of length-field */
351 guint c_pdulen = 0; /* Length of conc. PDU */
353 if (tree) {
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");
359 offCur = 1;
360 i = 1;
361 while (offCur < (int) tvb_reported_length(tvb)) {
362 tvbuff_t *wtp_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);
370 if (b0 & 0x80) {
371 c_fieldlen = 2;
372 c_pdulen = ((b0 & 0x7f) << 8) | tvb_get_guint8(tvb, offCur + 1);
373 } else {
374 c_fieldlen = 1;
375 c_pdulen = b0;
377 if (tree) {
378 proto_tree_add_uint(wtp_tree, hf_wtp_header_sub_pdu_size,
379 tvb, offCur, c_fieldlen, c_pdulen);
381 if (i > 1) {
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;
388 i++;
390 if (tree) {
391 proto_item_append_text(ti, ", PDU count: %u", i);
393 return;
395 /* No concatenation */
396 fCon = b0 & 0x80;
397 fRID = retransmission_indicator(b0);
398 pdut = pdu_type(b0);
400 #ifdef DEBUG
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));
405 #endif
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);
412 switch (pdut) {
413 case INVOKE:
414 fTTR = transmission_trailer(b0);
415 TID = tvb_get_ntohs(tvb, offCur + 1);
416 psn = 0;
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);
421 cbHeader = 4;
422 break;
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);
429 if (psn != 0) {
430 returned_length = g_snprintf(&szInfo[str_index], SZINFO_SIZE-str_index,
431 " (%u)", psn);
432 str_index += MIN(returned_length, SZINFO_SIZE-str_index);
434 cbHeader = 4;
435 break;
437 case ABORT:
438 cbHeader = 4;
439 break;
441 case RESULT:
442 fTTR = transmission_trailer(b0);
443 TID = tvb_get_ntohs(tvb, offCur + 1);
444 psn = 0;
445 cbHeader = 3;
446 break;
448 case ACK:
449 cbHeader = 3;
450 break;
452 case NEGATIVE_ACK:
453 /* Variable number of missing packets */
454 numMissing = tvb_get_guint8(tvb, offCur + 3);
455 cbHeader = numMissing + 4;
456 break;
458 default:
459 break;
461 if (fRID) {
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. */
467 if (tree) {
468 #ifdef DEBUG
469 fprintf(stderr, "dissect_wtp: cbHeader = %d\n", cbHeader);
470 #endif
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);
473 #ifdef DEBUG
474 fprintf(stderr, "dissect_wtp: (7) Returned from proto_tree_add_item\n");
475 #endif
476 wtp_tree = proto_item_add_subtree(ti, ett_wtp);
478 /* Code to process the packet goes here */
479 #ifdef DEBUG
480 fprintf(stderr, "dissect_wtp: cbHeader = %d\n", cbHeader);
481 fprintf(stderr, "dissect_wtp: offCur = %d\n", offCur);
482 #endif
483 /* Add common items: only CON and PDU Type */
484 proto_tree_add_item(
485 wtp_tree, /* tree */
486 hf_wtp_header_flag_continue, /* id */
487 tvb,
488 offCur, /* start of highlight */
489 1, /* length of highlight*/
490 b0 /* value */
492 proto_tree_add_item(wtp_tree, hf_wtp_header_pdu_type, tvb, offCur, 1, ENC_LITTLE_ENDIAN);
494 switch(pdut) {
495 case INVOKE:
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,
507 ", PDU: Invoke (%u)"
508 ", Transaction Class: %s (%u)",
509 INVOKE,
510 val_to_str_const(clsTransaction, vals_transaction_classes, "Undefined"),
511 clsTransaction);
512 break;
514 case RESULT:
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);
520 break;
522 case ACK:
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);
529 break;
531 case ABORT:
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,
541 ", PDU: Abort (%u)"
542 ", Type: Provider (%u)"
543 ", Reason: %s (%u)",
544 ABORT,
545 PROVIDER,
546 val_to_str_const(reason, vals_abort_reason_provider, "Undefined"),
547 reason);
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,
553 ", PDU: Abort (%u)"
554 ", Type: User (%u)"
555 ", Reason: %s (%u)",
556 ABORT,
557 PROVIDER,
558 val_to_str_ext_const(reason, &vals_wsp_reason_codes_ext, "Undefined"),
559 reason);
561 break;
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);
574 break;
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);
587 break;
589 case NEGATIVE_ACK:
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);
604 break;
606 default:
607 break;
609 if (fRID) {
610 proto_item_append_text(ti, ", Retransmission");
612 } else { /* tree is NULL */
613 #ifdef DEBUG
614 fprintf(stderr, "dissect_wtp: (4) tree was %p\n", tree);
615 #endif
617 /* Process the variable part */
618 if (fCon) { /* Now, analyze variable part */
619 guint8 tCon;
620 guint8 tByte;
621 guint tpiLen;
622 tvbuff_t *tmp_tvb;
624 vHeader = 0; /* Start scan all over */
626 do {
627 tByte = tvb_get_guint8(tvb, offCur + cbHeader + vHeader);
628 tCon = tByte & 0x80;
629 if (tByte & 0x04) /* Long TPI */
630 tpiLen = 2 + tvb_get_guint8(tvb, offCur + cbHeader + vHeader + 1);
631 else
632 tpiLen = 1 + (tByte & 0x03);
633 if (tree)
635 tmp_tvb = tvb_new_subset(tvb, offCur + cbHeader + vHeader, tpiLen, tpiLen);
636 wtp_handle_tpi(wtp_tree, tmp_tvb);
638 vHeader += tpiLen;
639 } while (tCon);
640 } else {
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 */
646 if (tree)
647 proto_item_set_len(ti, cbHeader + vHeader);
649 #ifdef DEBUG
650 fprintf( stderr, "dissect_wtp: cbHeader = %d\n", cbHeader );
651 #endif
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
657 * WSP dissector.
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,
717 NULL, wtp_tree);
718 #ifdef DEBUG
719 printf("WTP: Packet %u %s -> %d: wsp_tvb = %p, fd_wtp = %p, frame = %u\n",
720 pinfo->fd->num,
721 fd_wtp ? "Reassembled" : "Not reassembled",
722 fd_wtp ? fd_wtp->reassembled_in : -1,
723 wsp_tvb,
724 fd_wtp
726 #endif
727 if (fd_wtp) {
728 /* Reassembled */
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);
734 } else {
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");
742 } else {
743 /* Not reassembled yet, or not reassembled at all */
744 col_append_fstr(pinfo->cinfo, COL_INFO,
745 "%s (Unreassembled fragment %u)",
746 szInfo, psn);
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);
759 else
761 /* Nothing to hand to subdissector */
762 col_append_str(pinfo->cinfo, COL_INFO, szInfo);
765 else
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.
776 static void
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
790 * calling it....
792 * XXX - can this be called from any other dissector?
794 static void
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 */
804 void
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,
819 NULL, HFILL
822 { &hf_wtp_header_pdu_type,
823 { "PDU Type", "wtp.pdu_type",
824 FT_UINT8, BASE_HEX, VALS( vals_wtp_pdu_type ), 0x78,
825 NULL, HFILL
828 { &hf_wtp_header_flag_Trailer,
829 { "Trailer Flags", "wtp.trailer_flags",
830 FT_UINT8, BASE_HEX, VALS( vals_transaction_trailer ), 0x06,
831 NULL, HFILL
834 { &hf_wtp_header_flag_RID,
835 { "Re-transmission Indicator", "wtp.RID",
836 FT_BOOLEAN, 8, TFS( &RID_truth ), 0x01,
837 NULL, HFILL
840 { &hf_wtp_header_flag_TID_response,
841 { "TID Response", "wtp.TID.response",
842 FT_BOOLEAN, 16, TFS( &tid_response_truth ), 0x8000,
843 NULL, HFILL
846 { &hf_wtp_header_flag_TID,
847 { "Transaction ID", "wtp.TID",
848 FT_UINT16, BASE_HEX, NULL, 0x7FFF,
849 NULL, HFILL
852 { &hf_wtp_header_Inv_version,
853 { "Version", "wtp.header.version",
854 FT_UINT8, BASE_HEX, VALS( vals_version ), 0xC0,
855 NULL, HFILL
858 { &hf_wtp_header_Inv_flag_TIDNew,
859 { "TIDNew", "wtp.header.TIDNew",
860 FT_BOOLEAN, 8, TFS( &TIDNew_truth ), 0x20,
861 NULL, HFILL
864 { &hf_wtp_header_Inv_flag_UP,
865 { "U/P flag", "wtp.header.UP",
866 FT_BOOLEAN, 8, TFS( &UP_truth ), 0x10,
867 NULL, HFILL
870 { &hf_wtp_header_Inv_Reserved,
871 { "Reserved", "wtp.inv.reserved",
872 FT_UINT8, BASE_HEX, NULL, 0x0C,
873 NULL, HFILL
876 { &hf_wtp_header_Inv_TransactionClass,
877 { "Transaction Class", "wtp.inv.transaction_class",
878 FT_UINT8, BASE_HEX, VALS( vals_transaction_classes ), 0x03,
879 NULL, HFILL
882 { &hf_wtp_header_Ack_flag_TVETOK,
883 { "Tve/Tok flag", "wtp.ack.tvetok",
884 FT_BOOLEAN, 8, TFS( &TVETOK_truth ), 0x04,
885 NULL, HFILL
888 { &hf_wtp_header_Abort_type,
889 { "Abort Type", "wtp.abort.type",
890 FT_UINT8, BASE_HEX, VALS ( vals_abort_type ), 0x07,
891 NULL, HFILL
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,
897 NULL, HFILL
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,
904 NULL, HFILL
907 { &hf_wtp_header_sequence_number,
908 { "Packet Sequence Number", "wtp.header.sequence",
909 FT_UINT8, BASE_DEC, NULL, 0x00,
910 NULL, HFILL
913 { &hf_wtp_header_missing_packets,
914 { "Missing Packets", "wtp.header.missing_packets",
915 FT_UINT8, BASE_DEC, NULL, 0x00,
916 NULL, HFILL
919 #if 0
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
926 { &hf_wtp_data,
927 { "Data", "wtp.header_data",
928 FT_BYTES, BASE_NONE, NULL, 0x0,
929 NULL, HFILL
932 #endif
933 { &hf_wtp_tpi_type,
934 { "TPI", "wtp.tpi",
935 FT_UINT8, BASE_HEX, VALS(vals_tpi_type), 0x00,
936 "Identification of the Transport Information Item", HFILL
939 { &hf_wtp_tpi_psn,
940 { "Packet sequence number", "wtp.tpi.psn",
941 FT_UINT8, BASE_DEC, NULL, 0x00,
942 "Sequence number of this packet", HFILL
945 { &hf_wtp_tpi_opt,
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
957 { &hf_wtp_tpi_info,
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,
998 NULL, HFILL
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
1013 { &hf_wtp_fragment,
1014 { "WTP Fragment", "wtp.fragment",
1015 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1016 NULL, HFILL
1019 { &hf_wtp_fragments,
1020 { "WTP Fragments", "wtp.fragments",
1021 FT_NONE, BASE_NONE, NULL, 0x0,
1022 NULL, HFILL
1027 /* Setup protocol subtree array */
1028 static gint *ett[] = {
1029 &ett_wtp,
1030 &ett_wtp_sub_pdu_tree,
1031 &ett_header,
1032 &ett_tpilist,
1033 &ett_wsp_fragments,
1034 &ett_wtp_fragment,
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);
1055 void
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
1075 * Local variables:
1076 * c-basic-offset: 4
1077 * tab-width: 4
1078 * indent-tabs-mode: nil
1079 * End:
1081 * vi: set shiftwidth=4 tabstop=4 expandtab:
1082 * :indentSize=4:tabSize=4:noTabs=true: