Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-t38.c
bloba5e9801f4854676d9355db6b4bcf6b981a395a03
1 /* Do not modify this file. Changes will be overwritten. */
2 /* Generated automatically by the ASN.1 to Wireshark dissector compiler */
3 /* packet-t38.c */
4 /* asn2wrs.py -q -L -p t38 -c ./t38.cnf -s ./packet-t38-template -D . -O ../.. T38_2002.asn */
6 /* packet-t38.c
7 * Routines for T.38 packet dissection
8 * 2003 Hans Viens
9 * 2004 Alejandro Vaquero, add support Conversations for SDP
10 * 2006 Alejandro Vaquero, add T30 reassemble and dissection
12 * Wireshark - Network traffic analyzer
13 * By Gerald Combs <gerald@wireshark.org>
14 * Copyright 1998 Gerald Combs
16 * SPDX-License-Identifier: GPL-2.0-or-later
20 /* Depending on what ASN.1 specification is used you may have to change
21 * the preference setting regarding Pre-Corrigendum ASN.1 specification:
22 * http://www.itu.int/ITU-T/asn1/database/itu-t/t/t38/1998/T38.html (Pre-Corrigendum=true)
23 * http://www.itu.int/ITU-T/asn1/database/itu-t/t/t38/2003/T38(1998).html (Pre-Corrigendum=true)
25 * http://www.itu.int/ITU-T/asn1/database/itu-t/t/t38/2003/T38(2002).html (Pre-Corrigendum=false)
26 * http://www.itu.int/ITU-T/asn1/database/itu-t/t/t38/2002/t38.html (Pre-Corrigendum=false)
27 * http://www.itu.int/ITU-T/asn1/database/itu-t/t/t38/2002-Amd1/T38.html (Pre-Corrigendum=false)
30 /* TO DO:
31 * - TCP desegmentation is currently not supported for T.38 IFP directly over TCP.
32 * - H.245 dissectors should be updated to start conversations for T.38 similar to RTP.
33 * - Sometimes the last octet is not high-lighted when selecting something in the tree. Bug in PER dissector?
34 * - Add support for RTP payload audio/t38 (draft-jones-avt-audio-t38-03.txt), i.e. T38 in RTP packets.
38 #include "config.h"
40 #include <epan/packet.h>
41 #include <epan/reassemble.h>
42 #include <epan/conversation.h>
43 #include <epan/tap.h>
44 #include <epan/expert.h>
45 #include <epan/strutil.h>
46 #include <epan/prefs.h>
47 #include <epan/ipproto.h>
48 #include <epan/asn1.h>
49 #include <epan/proto_data.h>
50 #include <wsutil/array.h>
52 #include "packet-t38.h"
53 #include "packet-per.h"
54 #include "packet-tpkt.h"
55 #include "packet-acdr.h"
57 void proto_register_t38(void);
59 static int t38_tap;
61 /* dissect using the Pre Corrigendum T.38 ASN.1 specification (1998) */
62 static bool use_pre_corrigendum_asn1_specification = true;
64 /* dissect packets that looks like RTP version 2 packets as RTP */
65 /* instead of as T.38. This may result in that some T.38 UPTL */
66 /* packets with sequence number values higher than 32767 may be */
67 /* shown as RTP packets. */
68 static bool dissect_possible_rtpv2_packets_as_rtp;
71 /* Reassembly of T.38 PDUs over TPKT over TCP */
72 static bool t38_tpkt_reassembly = true;
74 /* Preference setting whether TPKT header is used when sending T.38 over TCP.
75 * The default setting is Maybe where the dissector will look on the first
76 * bytes to try to determine whether TPKT header is used or not. This may not
77 * work so well in some cases. You may want to change the setting to Always or
78 * Newer.
80 #define T38_TPKT_NEVER 0 /* Assume that there is never a TPKT header */
81 #define T38_TPKT_ALWAYS 1 /* Assume that there is always a TPKT header */
82 #define T38_TPKT_MAYBE 2 /* Assume TPKT if first octets are 03-00-xx-xx */
83 static int t38_tpkt_usage = T38_TPKT_MAYBE;
85 static const enum_val_t t38_tpkt_options[] = {
86 {"never", "Never", T38_TPKT_NEVER},
87 {"always", "Always", T38_TPKT_ALWAYS},
88 {"maybe", "Maybe", T38_TPKT_MAYBE},
89 {NULL, NULL, -1}
94 /* T38 */
95 static dissector_handle_t t38_udp_handle;
96 static dissector_handle_t t38_tcp_handle;
97 static dissector_handle_t t38_tcp_pdu_handle;
98 static dissector_handle_t rtp_handle;
99 static dissector_handle_t t30_hdlc_handle;
100 static dissector_handle_t data_handle;
102 static int32_t Type_of_msg_value;
103 static uint32_t Data_Field_field_type_value;
104 static uint32_t Data_value;
105 static uint32_t T30ind_value;
106 static uint32_t Data_Field_item_num;
108 static int proto_t38;
109 static int proto_acdr;
110 static int hf_t38_IFPPacket_PDU; /* IFPPacket */
111 static int hf_t38_UDPTLPacket_PDU; /* UDPTLPacket */
112 static int hf_t38_type_of_msg; /* Type_of_msg */
113 static int hf_t38_data_field; /* Data_Field */
114 static int hf_t38_t30_indicator; /* T30_indicator */
115 static int hf_t38_t30_data; /* T30_data */
116 static int hf_t38_Data_Field_item; /* Data_Field_item */
117 static int hf_t38_field_type; /* T_field_type */
118 static int hf_t38_field_data; /* T_field_data */
119 static int hf_t38_seq_number; /* T_seq_number */
120 static int hf_t38_primary_ifp_packet; /* T_primary_ifp_packet */
121 static int hf_t38_error_recovery; /* T_error_recovery */
122 static int hf_t38_secondary_ifp_packets; /* T_secondary_ifp_packets */
123 static int hf_t38_secondary_ifp_packets_item; /* OpenType_IFPPacket */
124 static int hf_t38_fec_info; /* T_fec_info */
125 static int hf_t38_fec_npackets; /* INTEGER */
126 static int hf_t38_fec_data; /* T_fec_data */
127 static int hf_t38_fec_data_item; /* OCTET_STRING */
129 /* T38 setup fields */
130 static int hf_t38_setup;
131 static int hf_t38_setup_frame;
132 static int hf_t38_setup_method;
134 /* T38 Data reassemble fields */
135 static int hf_t38_fragments;
136 static int hf_t38_fragment;
137 static int hf_t38_fragment_overlap;
138 static int hf_t38_fragment_overlap_conflicts;
139 static int hf_t38_fragment_multiple_tails;
140 static int hf_t38_fragment_too_long_fragment;
141 static int hf_t38_fragment_error;
142 static int hf_t38_fragment_count;
143 static int hf_t38_reassembled_in;
144 static int hf_t38_reassembled_length;
146 static int ett_t38;
147 static int ett_t38_IFPPacket;
148 static int ett_t38_Type_of_msg;
149 static int ett_t38_Data_Field;
150 static int ett_t38_Data_Field_item;
151 static int ett_t38_UDPTLPacket;
152 static int ett_t38_T_error_recovery;
153 static int ett_t38_T_secondary_ifp_packets;
154 static int ett_t38_T_fec_info;
155 static int ett_t38_T_fec_data;
156 static int ett_t38_setup;
158 static int ett_data_fragment;
159 static int ett_data_fragments;
161 static expert_field ei_t38_malformed;
163 static bool primary_part = true;
164 static uint32_t seq_number;
166 /* Tables for reassembly of Data fragments. */
167 static reassembly_table data_reassembly_table;
169 static const fragment_items data_frag_items = {
170 /* Fragment subtrees */
171 &ett_data_fragment,
172 &ett_data_fragments,
173 /* Fragment fields */
174 &hf_t38_fragments,
175 &hf_t38_fragment,
176 &hf_t38_fragment_overlap,
177 &hf_t38_fragment_overlap_conflicts,
178 &hf_t38_fragment_multiple_tails,
179 &hf_t38_fragment_too_long_fragment,
180 &hf_t38_fragment_error,
181 &hf_t38_fragment_count,
182 /* Reassembled in field */
183 &hf_t38_reassembled_in,
184 /* Reassembled length field */
185 &hf_t38_reassembled_length,
186 /* Reassembled data field */
187 NULL,
188 /* Tag */
189 "Data fragments"
192 typedef struct _fragment_key {
193 address src;
194 address dst;
195 uint32_t id;
196 } fragment_key;
198 static conversation_t *p_conv;
199 static t38_conv *p_t38_conv;
200 static t38_conv *p_t38_packet_conv;
201 static t38_conv_info *p_t38_conv_info;
202 static t38_conv_info *p_t38_packet_conv_info;
204 /* RTP Version is the first 2 bits of the first octet in the UDP payload*/
205 #define RTP_VERSION(octet) ((octet) >> 6)
207 void proto_reg_handoff_t38(void);
209 static void show_setup_info(tvbuff_t *tvb, proto_tree *tree, t38_conv *p_t38_conv);
210 /* Preferences bool to control whether or not setup info should be shown */
211 static bool global_t38_show_setup_info = true;
213 /* Can tap up to 4 T38 packets within same packet */
214 /* We only tap the primary part, not the redundancy */
215 #define MAX_T38_MESSAGES_IN_PACKET 4
216 static t38_packet_info t38_info_arr[MAX_T38_MESSAGES_IN_PACKET];
217 static int t38_info_current=0;
218 static t38_packet_info *t38_info;
221 /* Set up an T38 conversation */
222 void t38_add_address(packet_info *pinfo,
223 address *addr, int port,
224 int other_port,
225 const char *setup_method, uint32_t setup_frame_number)
227 address null_addr;
228 conversation_t* p_conversation;
229 t38_conv* p_conversation_data = NULL;
232 * If this isn't the first time this packet has been processed,
233 * we've already done this work, so we don't need to do it
234 * again.
236 if ((pinfo->fd->visited) || (t38_udp_handle == NULL))
238 return;
241 clear_address(&null_addr);
244 * Check if the ip address and port combination is not
245 * already registered as a conversation.
247 p_conversation = find_conversation( setup_frame_number, addr, &null_addr, CONVERSATION_UDP, port, other_port,
248 NO_ADDR_B | (!other_port ? NO_PORT_B : 0));
251 * If not, create a new conversation.
253 if ( !p_conversation || p_conversation->setup_frame != setup_frame_number) {
254 p_conversation = conversation_new( setup_frame_number, addr, &null_addr, CONVERSATION_UDP,
255 (uint32_t)port, (uint32_t)other_port,
256 NO_ADDR2 | (!other_port ? NO_PORT2 : 0));
259 /* Set dissector */
260 conversation_set_dissector(p_conversation, t38_udp_handle);
263 * Check if the conversation has data associated with it.
265 p_conversation_data = (t38_conv*)conversation_get_proto_data(p_conversation, proto_t38);
268 * If not, add a new data item.
270 if ( ! p_conversation_data ) {
271 /* Create conversation data */
272 p_conversation_data = wmem_new(wmem_file_scope(), t38_conv);
274 conversation_add_proto_data(p_conversation, proto_t38, p_conversation_data);
278 * Update the conversation data.
280 (void) g_strlcpy(p_conversation_data->setup_method, setup_method, MAX_T38_SETUP_METHOD_SIZE);
281 p_conversation_data->setup_frame_number = setup_frame_number;
282 p_conversation_data->src_t38_info.reass_ID = 0;
283 p_conversation_data->src_t38_info.reass_start_seqnum = -1;
284 p_conversation_data->src_t38_info.reass_start_data_field = 0;
285 p_conversation_data->src_t38_info.reass_data_type = 0;
286 p_conversation_data->src_t38_info.last_seqnum = -1;
287 p_conversation_data->src_t38_info.packet_lost = 0;
288 p_conversation_data->src_t38_info.burst_lost = 0;
289 p_conversation_data->src_t38_info.time_first_t4_data = 0;
290 p_conversation_data->src_t38_info.additional_hdlc_data_field_counter = 0;
291 p_conversation_data->src_t38_info.seqnum_prev_data_field = -1;
292 p_conversation_data->src_t38_info.next = NULL;
294 p_conversation_data->dst_t38_info.reass_ID = 0;
295 p_conversation_data->dst_t38_info.reass_start_seqnum = -1;
296 p_conversation_data->dst_t38_info.reass_start_data_field = 0;
297 p_conversation_data->dst_t38_info.reass_data_type = 0;
298 p_conversation_data->dst_t38_info.last_seqnum = -1;
299 p_conversation_data->dst_t38_info.packet_lost = 0;
300 p_conversation_data->dst_t38_info.burst_lost = 0;
301 p_conversation_data->dst_t38_info.time_first_t4_data = 0;
302 p_conversation_data->dst_t38_info.additional_hdlc_data_field_counter = 0;
303 p_conversation_data->dst_t38_info.seqnum_prev_data_field = -1;
304 p_conversation_data->dst_t38_info.next = NULL;
308 static fragment_head *
309 force_reassemble_seq(reassembly_table *table, packet_info *pinfo, uint32_t id)
311 fragment_head *fd_head;
312 fragment_item *fd_i;
313 fragment_item *last_fd;
314 uint32_t dfpos, size, packet_lost, burst_lost, seq_num;
315 uint8_t *data;
317 fd_head = fragment_get(table, pinfo, id, NULL);
319 /* have we already seen this frame ?*/
320 if (pinfo->fd->visited) {
321 if (fd_head != NULL && fd_head->flags & FD_DEFRAGMENTED) {
322 return fd_head;
323 } else {
324 return NULL;
328 if (fd_head==NULL){
329 /* we must have it to continue */
330 return NULL;
333 /* check for packet lost and count the burst of packet lost */
334 packet_lost = 0;
335 burst_lost = 0;
336 seq_num = 0;
337 for(fd_i=fd_head->next;fd_i;fd_i=fd_i->next) {
338 if (seq_num != fd_i->offset) {
339 packet_lost += fd_i->offset - seq_num;
340 if ( (fd_i->offset - seq_num) > burst_lost ) {
341 burst_lost = fd_i->offset - seq_num;
344 seq_num = fd_i->offset + 1;
347 /* we have received an entire packet, defragment it and
348 * free all fragments
350 size=0;
351 last_fd=NULL;
352 for(fd_i=fd_head->next;fd_i;fd_i=fd_i->next) {
353 if(!last_fd || last_fd->offset!=fd_i->offset){
354 size+=fd_i->len;
356 last_fd=fd_i;
359 data = (uint8_t *) g_malloc(size);
360 fd_head->tvb_data = tvb_new_real_data(data, size, size);
361 tvb_set_free_cb(fd_head->tvb_data, g_free);
362 fd_head->len = size; /* record size for caller */
364 /* add all data fragments */
365 dfpos = 0;
366 last_fd=NULL;
367 for (fd_i=fd_head->next;fd_i && fd_i->len + dfpos <= size;fd_i=fd_i->next) {
368 if (fd_i->len) {
369 if(!last_fd || last_fd->offset!=fd_i->offset){
370 tvb_memcpy(fd_i->tvb_data, data+dfpos, 0, fd_i->len);
371 dfpos += fd_i->len;
372 } else {
373 /* duplicate/retransmission/overlap */
374 fd_i->flags |= FD_OVERLAP;
375 fd_head->flags |= FD_OVERLAP;
376 if( (last_fd->len!=fd_i->len)
377 || tvb_memeql(last_fd->tvb_data, 0, tvb_get_ptr(fd_i->tvb_data, 0, last_fd->len), last_fd->len) ){
378 fd_i->flags |= FD_OVERLAPCONFLICT;
379 fd_head->flags |= FD_OVERLAPCONFLICT;
383 last_fd=fd_i;
386 /* we have defragmented the pdu, now free all fragments*/
387 for (fd_i=fd_head->next;fd_i;fd_i=fd_i->next) {
388 if(fd_i->tvb_data){
389 tvb_free(fd_i->tvb_data);
390 fd_i->tvb_data=NULL;
394 /* mark this packet as defragmented */
395 fd_head->flags |= FD_DEFRAGMENTED;
396 fd_head->reassembled_in=pinfo->num;
398 col_append_fstr(pinfo->cinfo, COL_INFO, " (t4-data Reassembled: %d pack lost, %d pack burst lost)", packet_lost, burst_lost);
400 p_t38_packet_conv_info->packet_lost = packet_lost;
401 p_t38_packet_conv_info->burst_lost = burst_lost;
403 return fd_head;
406 /* T38 Routines */
408 const value_string t38_T30_indicator_vals[] = {
409 { 0, "no-signal" },
410 { 1, "cng" },
411 { 2, "ced" },
412 { 3, "v21-preamble" },
413 { 4, "v27-2400-training" },
414 { 5, "v27-4800-training" },
415 { 6, "v29-7200-training" },
416 { 7, "v29-9600-training" },
417 { 8, "v17-7200-short-training" },
418 { 9, "v17-7200-long-training" },
419 { 10, "v17-9600-short-training" },
420 { 11, "v17-9600-long-training" },
421 { 12, "v17-12000-short-training" },
422 { 13, "v17-12000-long-training" },
423 { 14, "v17-14400-short-training" },
424 { 15, "v17-14400-long-training" },
425 { 16, "v8-ansam" },
426 { 17, "v8-signal" },
427 { 18, "v34-cntl-channel-1200" },
428 { 19, "v34-pri-channel" },
429 { 20, "v34-CC-retrain" },
430 { 21, "v33-12000-training" },
431 { 22, "v33-14400-training" },
432 { 0, NULL }
436 static int
437 dissect_t38_T30_indicator(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
438 offset = dissect_per_enumerated(tvb, offset, actx, tree, hf_index,
439 16, &T30ind_value, true, 7, NULL);
441 if (primary_part){
442 col_append_fstr(actx->pinfo->cinfo, COL_INFO, " t30ind: %s",
443 val_to_str_const(T30ind_value,t38_T30_indicator_vals,"<unknown>"));
446 /* info for tap */
447 if (primary_part)
448 t38_info->t30ind_value = T30ind_value;
449 return offset;
453 const value_string t38_T30_data_vals[] = {
454 { 0, "v21" },
455 { 1, "v27-2400" },
456 { 2, "v27-4800" },
457 { 3, "v29-7200" },
458 { 4, "v29-9600" },
459 { 5, "v17-7200" },
460 { 6, "v17-9600" },
461 { 7, "v17-12000" },
462 { 8, "v17-14400" },
463 { 9, "v8" },
464 { 10, "v34-pri-rate" },
465 { 11, "v34-CC-1200" },
466 { 12, "v34-pri-ch" },
467 { 13, "v33-12000" },
468 { 14, "v33-14400" },
469 { 0, NULL }
473 static int
474 dissect_t38_T30_data(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
475 offset = dissect_per_enumerated(tvb, offset, actx, tree, hf_index,
476 9, &Data_value, true, 6, NULL);
478 if (primary_part){
479 col_append_fstr(actx->pinfo->cinfo, COL_INFO, " data:%s:",
480 val_to_str_const(Data_value,t38_T30_data_vals,"<unknown>"));
484 /* info for tap */
485 if (primary_part)
486 t38_info->data_value = Data_value;
487 return offset;
491 static const value_string t38_Type_of_msg_vals[] = {
492 { 0, "t30-indicator" },
493 { 1, "t30-data" },
494 { 0, NULL }
497 static const per_choice_t Type_of_msg_choice[] = {
498 { 0, &hf_t38_t30_indicator , ASN1_NO_EXTENSIONS , dissect_t38_T30_indicator },
499 { 1, &hf_t38_t30_data , ASN1_NO_EXTENSIONS , dissect_t38_T30_data },
500 { 0, NULL, 0, NULL }
503 static int
504 dissect_t38_Type_of_msg(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
505 offset = dissect_per_choice(tvb, offset, actx, tree, hf_index,
506 ett_t38_Type_of_msg, Type_of_msg_choice,
507 &Type_of_msg_value);
509 /* info for tap */
510 if (primary_part)
511 t38_info->type_msg = Type_of_msg_value;
512 return offset;
516 static const value_string t38_T_field_type_vals[] = {
517 { 0, "hdlc-data" },
518 { 1, "hdlc-sig-end" },
519 { 2, "hdlc-fcs-OK" },
520 { 3, "hdlc-fcs-BAD" },
521 { 4, "hdlc-fcs-OK-sig-end" },
522 { 5, "hdlc-fcs-BAD-sig-end" },
523 { 6, "t4-non-ecm-data" },
524 { 7, "t4-non-ecm-sig-end" },
525 { 8, "cm-message" },
526 { 9, "jm-message" },
527 { 10, "ci-message" },
528 { 11, "v34rate" },
529 { 0, NULL }
533 static int
534 dissect_t38_T_field_type(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
535 offset = dissect_per_enumerated(tvb, offset, actx, tree, hf_index,
536 8, &Data_Field_field_type_value, (use_pre_corrigendum_asn1_specification)?false:true, (use_pre_corrigendum_asn1_specification)?0:4, NULL);
538 if (primary_part){
539 col_append_fstr(actx->pinfo->cinfo, COL_INFO, " %s",
540 val_to_str_const(Data_Field_field_type_value,t38_T_field_type_vals,"<unknown>"));
543 if (primary_part) {
544 if (Data_Field_field_type_value == 2 || Data_Field_field_type_value == 4 || Data_Field_field_type_value == 7) {/* hdlc-fcs-OK or hdlc-fcs-OK-sig-end or t4-non-ecm-sig-end*/
545 fragment_head *frag_msg = NULL;
546 tvbuff_t* new_tvb = NULL;
547 bool save_fragmented = actx->pinfo->fragmented;
549 actx->pinfo->fragmented = true;
551 /* if reass_start_seqnum=-1 it means we have received the end of the fragmente, without received any fragment data */
552 if (p_t38_packet_conv_info->reass_start_seqnum != -1) {
553 uint32_t frag_seq_num;
554 if (seq_number == (uint32_t)p_t38_packet_conv_info->reass_start_seqnum) {
555 frag_seq_num = (uint32_t)p_t38_packet_conv_info->additional_hdlc_data_field_counter + Data_Field_item_num - p_t38_packet_conv_info->reass_start_data_field;
556 } else {
557 frag_seq_num = seq_number - (uint32_t)p_t38_packet_conv_info->reass_start_seqnum + (uint32_t)p_t38_packet_conv_info->additional_hdlc_data_field_counter + Data_Field_item_num;
559 frag_msg = fragment_add_seq(&data_reassembly_table, /* reassembly table */
560 tvb, offset, actx->pinfo,
561 p_t38_packet_conv_info->reass_ID, /* ID for fragments belonging together */
562 NULL,
563 frag_seq_num, /* fragment sequence number */
564 /*0,*/
565 0, /* fragment length */
566 false, /* More fragments */
568 if ( Data_Field_field_type_value == 7 ) {
569 /* if there was packet lost or other errors during the defrag then frag_msg is NULL. This could also means
570 * there are out of order packets (e.g, got the tail frame t4-non-ecm-sig-end before the last fragment),
571 * but we will assume there was packet lost instead, which is more usual. So, we are going to reassemble the packet
572 * and get some stat, like packet lost and burst number of packet lost
574 if (!frag_msg) {
575 force_reassemble_seq(&data_reassembly_table, /* reassembly table */
576 actx->pinfo,
577 p_t38_packet_conv_info->reass_ID /* ID for fragments belonging together */
579 } else {
580 col_append_str(actx->pinfo->cinfo, COL_INFO, " (t4-data Reassembled: No packet lost)");
582 snprintf(t38_info->desc_comment, MAX_T38_DESC, "No packet lost");
586 if (p_t38_packet_conv_info->packet_lost) {
587 snprintf(t38_info->desc_comment, MAX_T38_DESC, " Pack lost: %d, Pack burst lost: %d", p_t38_packet_conv_info->packet_lost, p_t38_packet_conv_info->burst_lost);
588 } else {
589 snprintf(t38_info->desc_comment, MAX_T38_DESC, "No packet lost");
592 process_reassembled_data(tvb, offset, actx->pinfo,
593 "Reassembled T38", frag_msg, &data_frag_items, NULL, tree);
595 /* Now reset fragmentation information in pinfo */
596 actx->pinfo->fragmented = save_fragmented;
598 t38_info->time_first_t4_data = p_t38_packet_conv_info->time_first_t4_data;
599 t38_info->frame_num_first_t4_data = p_t38_packet_conv_info->reass_ID; /* The reass_ID is the Frame number of the first t4 fragment */
601 } else {
602 new_tvb = process_reassembled_data(tvb, offset, actx->pinfo,
603 "Reassembled T38", frag_msg, &data_frag_items, NULL, tree);
605 /* Now reset fragmentation information in pinfo */
606 actx->pinfo->fragmented = save_fragmented;
608 if (new_tvb) call_dissector_with_data((t30_hdlc_handle) ? t30_hdlc_handle : data_handle, new_tvb, actx->pinfo, tree, t38_info);
610 } else {
611 /* If this is the same sequence number as the previous packet
612 * (i.e., a retransmission), we don't expect to have any
613 * fragment data (we reassembled it in the previous packet).
615 if (p_t38_packet_conv && ((int32_t) seq_number != p_t38_packet_conv_info->last_seqnum)) {
616 proto_tree_add_expert_format(tree, actx->pinfo, &ei_t38_malformed, tvb, offset, tvb_reported_length_remaining(tvb, offset),
617 "[RECEIVED END OF FRAGMENT W/OUT ANY FRAGMENT DATA]");
618 col_append_str(actx->pinfo->cinfo, COL_INFO, " [Malformed?]");
620 actx->pinfo->fragmented = save_fragmented;
624 /* reset the reassemble ID and the start seq number if it is not HDLC data */
625 if ( p_t38_conv && ( ((Data_Field_field_type_value >0) && (Data_Field_field_type_value <6)) || (Data_Field_field_type_value == 7) ) ){
626 p_t38_conv_info->reass_ID = 0;
627 p_t38_conv_info->reass_start_seqnum = -1;
628 p_t38_conv_info->additional_hdlc_data_field_counter = 0;
629 p_t38_conv_info->seqnum_prev_data_field = -1;
631 if (p_t38_packet_conv_info->next == NULL) {
632 p_t38_packet_conv_info->next = wmem_new(wmem_file_scope(), t38_conv_info);
633 p_t38_packet_conv_info = p_t38_packet_conv_info->next;
634 memcpy(p_t38_packet_conv_info, p_t38_conv_info, sizeof(t38_conv_info));
638 t38_info->Data_Field_field_type_value = Data_Field_field_type_value;
640 return offset;
645 static int
646 dissect_t38_T_field_data(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
647 tvbuff_t *value_tvb = NULL;
648 uint32_t value_len;
650 offset = dissect_per_octet_string(tvb, offset, actx, tree, hf_index,
651 1, 65535, false, &value_tvb);
653 value_len = tvb_reported_length(value_tvb);
656 if (primary_part){
657 if(value_len < 8){
658 col_append_fstr(actx->pinfo->cinfo, COL_INFO, "[%s]",
659 tvb_bytes_to_str(actx->pinfo->pool, value_tvb,0,value_len));
661 else {
662 col_append_fstr(actx->pinfo->cinfo, COL_INFO, "[%s...]",
663 tvb_bytes_to_str(actx->pinfo->pool, value_tvb,0,7));
667 if (primary_part) {
668 fragment_head *frag_msg = NULL;
670 /* HDLC Data or t4-non-ecm-data */
671 if (Data_Field_field_type_value == 0 || Data_Field_field_type_value == 6) { /* 0=HDLC Data or 6=t4-non-ecm-data*/
672 bool save_fragmented = actx->pinfo->fragmented;
674 actx->pinfo->fragmented = true;
676 /* if we have not reassembled this packet and it is the first fragment, reset the reassemble ID and the start seq number*/
677 if (p_t38_packet_conv && p_t38_conv && (p_t38_packet_conv_info->reass_start_seqnum == -1)) {
678 /* we use the first fragment's frame_number as fragment ID because the protocol doesn't provide it */
679 /* XXX: We'd be better off assigning our own IDs using a one-up
680 * counter, if it's possible for more than one reassembly to
681 * begin in the same frame.
683 p_t38_conv_info->reass_ID = actx->pinfo->num;
684 p_t38_conv_info->reass_start_seqnum = seq_number;
685 p_t38_conv_info->time_first_t4_data = nstime_to_sec(&actx->pinfo->rel_ts);
686 p_t38_conv_info->additional_hdlc_data_field_counter = 0;
687 p_t38_packet_conv_info->reass_ID = p_t38_conv_info->reass_ID;
688 p_t38_packet_conv_info->reass_start_seqnum = p_t38_conv_info->reass_start_seqnum;
689 p_t38_packet_conv_info->reass_start_data_field = Data_Field_item_num;
690 p_t38_packet_conv_info->seqnum_prev_data_field = p_t38_conv_info->seqnum_prev_data_field;
691 p_t38_packet_conv_info->additional_hdlc_data_field_counter = p_t38_conv_info->additional_hdlc_data_field_counter;
692 p_t38_packet_conv_info->time_first_t4_data = p_t38_conv_info->time_first_t4_data;
694 if (seq_number == (uint32_t)p_t38_packet_conv_info->seqnum_prev_data_field){
695 if(p_t38_conv){
696 p_t38_conv_info->additional_hdlc_data_field_counter++;
699 uint32_t frag_seq_num;
700 if (seq_number == (uint32_t)p_t38_packet_conv_info->reass_start_seqnum) {
701 frag_seq_num = (uint32_t)p_t38_packet_conv_info->additional_hdlc_data_field_counter + Data_Field_item_num - (uint32_t)p_t38_packet_conv_info->reass_start_data_field;
702 } else {
703 frag_seq_num = seq_number - (uint32_t)p_t38_packet_conv_info->reass_start_seqnum + (uint32_t)p_t38_packet_conv_info->additional_hdlc_data_field_counter + Data_Field_item_num;
705 frag_msg = fragment_add_seq(&data_reassembly_table,
706 value_tvb, 0,
707 actx->pinfo,
708 p_t38_packet_conv_info->reass_ID, /* ID for fragments belonging together */
709 NULL,
710 frag_seq_num, /* fragment sequence number */
711 value_len, /* fragment length */
712 true, /* More fragments */
714 p_t38_packet_conv_info->seqnum_prev_data_field = (int32_t)seq_number;
715 process_reassembled_data(tvb, offset, actx->pinfo,
716 "Reassembled T38", frag_msg, &data_frag_items, NULL, tree);
718 if (!frag_msg) { /* Not last packet of reassembled */
719 if (Data_Field_field_type_value == 0) {
720 col_append_fstr(actx->pinfo->cinfo, COL_INFO," (HDLC fragment %u)", frag_seq_num);
721 } else {
722 col_append_fstr(actx->pinfo->cinfo, COL_INFO," (t4-data fragment %u)", seq_number - (uint32_t)p_t38_packet_conv_info->reass_start_seqnum);
726 /* Now reset fragmentation information in pinfo */
727 actx->pinfo->fragmented = save_fragmented;
730 return offset;
734 static const per_sequence_t Data_Field_item_sequence[] = {
735 { &hf_t38_field_type , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_t38_T_field_type },
736 { &hf_t38_field_data , ASN1_NO_EXTENSIONS , ASN1_OPTIONAL , dissect_t38_T_field_data },
737 { NULL, 0, 0, NULL }
740 static int
741 dissect_t38_Data_Field_item(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
742 offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
743 ett_t38_Data_Field_item, Data_Field_item_sequence);
745 if (primary_part) Data_Field_item_num++;
746 return offset;
750 static const per_sequence_t Data_Field_sequence_of[1] = {
751 { &hf_t38_Data_Field_item , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_t38_Data_Field_item },
754 static int
755 dissect_t38_Data_Field(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
756 offset = dissect_per_sequence_of(tvb, offset, actx, tree, hf_index,
757 ett_t38_Data_Field, Data_Field_sequence_of);
759 return offset;
763 static const per_sequence_t IFPPacket_sequence[] = {
764 { &hf_t38_type_of_msg , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_t38_Type_of_msg },
765 { &hf_t38_data_field , ASN1_NO_EXTENSIONS , ASN1_OPTIONAL , dissect_t38_Data_Field },
766 { NULL, 0, 0, NULL }
769 static int
770 dissect_t38_IFPPacket(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
771 offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
772 ett_t38_IFPPacket, IFPPacket_sequence);
774 return offset;
779 static int
780 dissect_t38_T_seq_number(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
781 offset = dissect_per_constrained_integer(tvb, offset, actx, tree, hf_index,
782 0U, 65535U, &seq_number, false);
784 /* info for tap */
785 if (primary_part)
786 t38_info->seq_num = seq_number;
788 col_append_fstr(actx->pinfo->cinfo, COL_INFO, "Seq=%05u ",seq_number);
789 return offset;
794 static int
795 dissect_t38_T_primary_ifp_packet(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
796 primary_part = true;
797 offset = dissect_per_open_type(tvb, offset, actx, tree, hf_index, dissect_t38_IFPPacket);
799 /* if is a valid t38 packet, add to tap */
800 /* Note that t4-non-ecm-sig-end without first_t4_data is not valid */
801 if (p_t38_packet_conv && (!actx->pinfo->flags.in_error_pkt) && ((int32_t) seq_number != p_t38_packet_conv_info->last_seqnum) &&
802 !(t38_info->type_msg == 1 && t38_info->Data_Field_field_type_value == 7 && t38_info->frame_num_first_t4_data == 0))
803 tap_queue_packet(t38_tap, actx->pinfo, t38_info);
805 if (p_t38_conv) p_t38_conv_info->last_seqnum = (int32_t) seq_number;
806 return offset;
811 static int
812 dissect_t38_OpenType_IFPPacket(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
813 offset = dissect_per_open_type(tvb, offset, actx, tree, hf_index, dissect_t38_IFPPacket);
815 return offset;
819 static const per_sequence_t T_secondary_ifp_packets_sequence_of[1] = {
820 { &hf_t38_secondary_ifp_packets_item, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_t38_OpenType_IFPPacket },
823 static int
824 dissect_t38_T_secondary_ifp_packets(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
825 offset = dissect_per_sequence_of(tvb, offset, actx, tree, hf_index,
826 ett_t38_T_secondary_ifp_packets, T_secondary_ifp_packets_sequence_of);
828 return offset;
833 static int
834 dissect_t38_INTEGER(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
835 offset = dissect_per_integer(tvb, offset, actx, tree, hf_index, NULL);
837 return offset;
842 static int
843 dissect_t38_OCTET_STRING(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
844 offset = dissect_per_octet_string(tvb, offset, actx, tree, hf_index,
845 NO_BOUND, NO_BOUND, false, NULL);
847 return offset;
851 static const per_sequence_t T_fec_data_sequence_of[1] = {
852 { &hf_t38_fec_data_item , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_t38_OCTET_STRING },
855 static int
856 dissect_t38_T_fec_data(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
857 offset = dissect_per_sequence_of(tvb, offset, actx, tree, hf_index,
858 ett_t38_T_fec_data, T_fec_data_sequence_of);
860 return offset;
864 static const per_sequence_t T_fec_info_sequence[] = {
865 { &hf_t38_fec_npackets , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_t38_INTEGER },
866 { &hf_t38_fec_data , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_t38_T_fec_data },
867 { NULL, 0, 0, NULL }
870 static int
871 dissect_t38_T_fec_info(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
872 offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
873 ett_t38_T_fec_info, T_fec_info_sequence);
875 return offset;
879 static const value_string t38_T_error_recovery_vals[] = {
880 { 0, "secondary-ifp-packets" },
881 { 1, "fec-info" },
882 { 0, NULL }
885 static const per_choice_t T_error_recovery_choice[] = {
886 { 0, &hf_t38_secondary_ifp_packets, ASN1_NO_EXTENSIONS , dissect_t38_T_secondary_ifp_packets },
887 { 1, &hf_t38_fec_info , ASN1_NO_EXTENSIONS , dissect_t38_T_fec_info },
888 { 0, NULL, 0, NULL }
891 static int
892 dissect_t38_T_error_recovery(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
893 primary_part = false;
894 offset = dissect_per_choice(tvb, offset, actx, tree, hf_index,
895 ett_t38_T_error_recovery, T_error_recovery_choice,
896 NULL);
898 primary_part = true;
899 return offset;
903 static const per_sequence_t UDPTLPacket_sequence[] = {
904 { &hf_t38_seq_number , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_t38_T_seq_number },
905 { &hf_t38_primary_ifp_packet, ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_t38_T_primary_ifp_packet },
906 { &hf_t38_error_recovery , ASN1_NO_EXTENSIONS , ASN1_NOT_OPTIONAL, dissect_t38_T_error_recovery },
907 { NULL, 0, 0, NULL }
910 static int
911 dissect_t38_UDPTLPacket(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
912 /* Initialize to something else than data type */
913 Data_Field_field_type_value = 1;
914 offset = dissect_per_sequence(tvb, offset, actx, tree, hf_index,
915 ett_t38_UDPTLPacket, UDPTLPacket_sequence);
917 return offset;
920 /*--- PDUs ---*/
922 static int dissect_IFPPacket_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
923 int offset = 0;
924 asn1_ctx_t asn1_ctx;
925 asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, true, pinfo);
926 offset = dissect_t38_IFPPacket(tvb, offset, &asn1_ctx, tree, hf_t38_IFPPacket_PDU);
927 offset += 7; offset >>= 3;
928 return offset;
930 static int dissect_UDPTLPacket_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
931 int offset = 0;
932 asn1_ctx_t asn1_ctx;
933 asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, true, pinfo);
934 offset = dissect_t38_UDPTLPacket(tvb, offset, &asn1_ctx, tree, hf_t38_UDPTLPacket_PDU);
935 offset += 7; offset >>= 3;
936 return offset;
940 /* initialize the tap t38_info and the conversation */
941 static void
942 init_t38_info_conv(packet_info *pinfo)
944 /* tap info */
945 t38_info_current++;
946 if (t38_info_current==MAX_T38_MESSAGES_IN_PACKET) {
947 t38_info_current=0;
949 t38_info = &t38_info_arr[t38_info_current];
951 t38_info->seq_num = 0;
952 t38_info->type_msg = 0;
953 t38_info->data_value = 0;
954 t38_info->t30ind_value =0;
955 t38_info->setup_frame_number = 0;
956 t38_info->Data_Field_field_type_value = 0;
957 t38_info->desc[0] = '\0';
958 t38_info->desc_comment[0] = '\0';
959 t38_info->time_first_t4_data = 0;
960 t38_info->frame_num_first_t4_data = 0;
964 p_t38_packet_conv hold the conversation info in each of the packets.
965 p_t38_conv hold the conversation info used to reassemble the HDLC packets, and also the Setup info (e.g SDP)
966 If we already have p_t38_packet_conv in the packet, it means we already reassembled the HDLC packets, so we don't
967 need to use p_t38_conv
969 p_t38_packet_conv = NULL;
970 p_t38_conv = NULL;
972 /* Use existing packet info if available */
973 p_t38_packet_conv = (t38_conv *)p_get_proto_data(wmem_file_scope(), pinfo, proto_t38, 0);
976 /* find the conversation used for Reassemble and Setup Info */
977 p_conv = find_conversation(pinfo->num, &pinfo->net_dst, &pinfo->net_src,
978 conversation_pt_to_conversation_type(pinfo->ptype),
979 pinfo->destport, pinfo->srcport, NO_ADDR_B | NO_PORT_B);
981 /* create a conv if it doesn't exist */
982 if (!p_conv) {
983 p_conv = conversation_new(pinfo->num, &pinfo->net_src, &pinfo->net_dst,
984 conversation_pt_to_conversation_type(pinfo->ptype), pinfo->srcport, pinfo->destport, NO_ADDR2 | NO_PORT2);
986 /* Set dissector */
987 conversation_set_dissector(p_conv, t38_udp_handle);
990 p_t38_conv = (t38_conv *)conversation_get_proto_data(p_conv, proto_t38);
992 /* create the conversation if it doesn't exist */
993 if (!p_t38_conv) {
994 p_t38_conv = wmem_new(wmem_file_scope(), t38_conv);
995 p_t38_conv->setup_method[0] = '\0';
996 p_t38_conv->setup_frame_number = 0;
998 p_t38_conv->src_t38_info.reass_ID = 0;
999 p_t38_conv->src_t38_info.reass_start_seqnum = -1;
1000 p_t38_conv->src_t38_info.reass_start_data_field = 0;
1001 p_t38_conv->src_t38_info.reass_data_type = 0;
1002 p_t38_conv->src_t38_info.last_seqnum = -1;
1003 p_t38_conv->src_t38_info.packet_lost = 0;
1004 p_t38_conv->src_t38_info.burst_lost = 0;
1005 p_t38_conv->src_t38_info.time_first_t4_data = 0;
1006 p_t38_conv->src_t38_info.additional_hdlc_data_field_counter = 0;
1007 p_t38_conv->src_t38_info.seqnum_prev_data_field = -1;
1008 p_t38_conv->src_t38_info.next = NULL;
1010 p_t38_conv->dst_t38_info.reass_ID = 0;
1011 p_t38_conv->dst_t38_info.reass_start_seqnum = -1;
1012 p_t38_conv->dst_t38_info.reass_start_data_field = 0;
1013 p_t38_conv->dst_t38_info.reass_data_type = 0;
1014 p_t38_conv->dst_t38_info.last_seqnum = -1;
1015 p_t38_conv->dst_t38_info.packet_lost = 0;
1016 p_t38_conv->dst_t38_info.burst_lost = 0;
1017 p_t38_conv->dst_t38_info.time_first_t4_data = 0;
1018 p_t38_conv->dst_t38_info.additional_hdlc_data_field_counter = 0;
1019 p_t38_conv->dst_t38_info.seqnum_prev_data_field = -1;
1020 p_t38_conv->dst_t38_info.next = NULL;
1022 conversation_add_proto_data(p_conv, proto_t38, p_t38_conv);
1025 if (!p_t38_packet_conv) {
1026 /* copy the t38 conversation info to the packet t38 conversation */
1027 p_t38_packet_conv = wmem_new(wmem_file_scope(), t38_conv);
1028 (void) g_strlcpy(p_t38_packet_conv->setup_method, p_t38_conv->setup_method, MAX_T38_SETUP_METHOD_SIZE);
1029 p_t38_packet_conv->setup_frame_number = p_t38_conv->setup_frame_number;
1031 memcpy(&(p_t38_packet_conv->src_t38_info), &(p_t38_conv->src_t38_info), sizeof(t38_conv_info));
1032 memcpy(&(p_t38_packet_conv->dst_t38_info), &(p_t38_conv->dst_t38_info), sizeof(t38_conv_info));
1034 p_add_proto_data(wmem_file_scope(), pinfo, proto_t38, 0, p_t38_packet_conv);
1037 if (addresses_equal(conversation_key_addr1(p_conv->key_ptr), &pinfo->net_src)) {
1038 p_t38_conv_info = &(p_t38_conv->src_t38_info);
1039 p_t38_packet_conv_info = &(p_t38_packet_conv->src_t38_info);
1040 } else {
1041 p_t38_conv_info = &(p_t38_conv->dst_t38_info);
1042 p_t38_packet_conv_info = &(p_t38_packet_conv->dst_t38_info);
1045 /* update t38_info */
1046 t38_info->setup_frame_number = p_t38_packet_conv->setup_frame_number;
1049 /* Entry point for dissection */
1050 static int
1051 dissect_t38_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1053 uint8_t octet1;
1054 proto_item *it;
1055 proto_tree *tr;
1056 uint32_t offset=0;
1059 * XXX - heuristic to check for misidentified packets.
1061 if (dissect_possible_rtpv2_packets_as_rtp){
1062 octet1 = tvb_get_uint8(tvb, offset);
1063 if (RTP_VERSION(octet1) == 2){
1064 return call_dissector(rtp_handle,tvb,pinfo,tree);
1068 col_set_str(pinfo->cinfo, COL_PROTOCOL, "T.38");
1069 col_clear(pinfo->cinfo, COL_INFO);
1071 primary_part = true;
1073 /* This indicate the item number in the primary part of the T38 message, it is used for the reassemble of T30 packets */
1074 Data_Field_item_num = 0;
1076 it=proto_tree_add_protocol_format(tree, proto_t38, tvb, 0, -1, "ITU-T Recommendation T.38");
1077 tr=proto_item_add_subtree(it, ett_t38);
1079 /* init tap and conv info */
1080 init_t38_info_conv(pinfo);
1082 /* Show Conversation setup info if exists*/
1083 if (global_t38_show_setup_info) {
1084 show_setup_info(tvb, tr, p_t38_packet_conv);
1087 col_append_str(pinfo->cinfo, COL_INFO, "UDP: UDPTLPacket ");
1089 offset = dissect_UDPTLPacket_PDU(tvb, pinfo, tr, NULL);
1091 if (tvb_reported_length_remaining(tvb,offset)>0){
1092 proto_tree_add_expert_format(tr, pinfo, &ei_t38_malformed, tvb, offset, tvb_reported_length_remaining(tvb, offset),
1093 "[MALFORMED PACKET or wrong preference settings]");
1094 col_append_str(pinfo->cinfo, COL_INFO, " [Malformed?]");
1096 return tvb_captured_length(tvb);
1099 static int
1100 dissect_t38_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1102 proto_item *it;
1103 proto_tree *tr;
1104 uint32_t offset=0;
1105 tvbuff_t *next_tvb;
1106 uint16_t ifp_packet_number=1;
1108 col_set_str(pinfo->cinfo, COL_PROTOCOL, "T.38");
1109 col_clear(pinfo->cinfo, COL_INFO);
1111 primary_part = true;
1113 /* This indicate the item number in the primary part of the T38 message, it is used for the reassemble of T30 packets */
1114 Data_Field_item_num = 0;
1116 it=proto_tree_add_protocol_format(tree, proto_t38, tvb, 0, -1, "ITU-T Recommendation T.38");
1117 tr=proto_item_add_subtree(it, ett_t38);
1119 /* init tap and conv info */
1120 init_t38_info_conv(pinfo);
1122 /* Show Conversation setup info if exists*/
1123 if (global_t38_show_setup_info) {
1124 show_setup_info(tvb, tr, p_t38_packet_conv);
1127 col_append_str(pinfo->cinfo, COL_INFO, "TCP: IFPPacket");
1129 while(tvb_reported_length_remaining(tvb,offset)>0)
1131 next_tvb = tvb_new_subset_remaining(tvb, offset);
1132 offset += dissect_IFPPacket_PDU(next_tvb, pinfo, tr, NULL);
1133 ifp_packet_number++;
1135 if(tvb_reported_length_remaining(tvb,offset)>0){
1136 if(t38_tpkt_usage == T38_TPKT_ALWAYS){
1137 proto_tree_add_expert_format(tr, pinfo, &ei_t38_malformed, tvb, offset, tvb_reported_length_remaining(tvb, offset),
1138 "[MALFORMED PACKET or wrong preference settings]");
1139 col_append_str(pinfo->cinfo, COL_INFO, " [Malformed?]");
1140 break;
1141 }else {
1142 col_append_fstr(pinfo->cinfo, COL_INFO, " IFPPacket#%u",ifp_packet_number);
1147 return tvb_captured_length(tvb);
1150 static int
1151 dissect_t38_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1153 primary_part = true;
1155 if(t38_tpkt_usage == T38_TPKT_ALWAYS){
1156 dissect_tpkt_encap(tvb,pinfo,tree,t38_tpkt_reassembly,t38_tcp_pdu_handle);
1158 else if((t38_tpkt_usage == T38_TPKT_NEVER) || (is_tpkt(tvb,1) == -1)){
1159 dissect_t38_tcp_pdu(tvb, pinfo, tree, data);
1161 else {
1162 dissect_tpkt_encap(tvb,pinfo,tree,t38_tpkt_reassembly,t38_tcp_pdu_handle);
1164 return tvb_captured_length(tvb);
1167 /* Look for conversation info and display any setup info found */
1168 void
1169 show_setup_info(tvbuff_t *tvb, proto_tree *tree, t38_conv *p_t38_conversation)
1171 proto_tree *t38_setup_tree;
1172 proto_item *ti;
1174 if (!p_t38_conversation || p_t38_conversation->setup_frame_number == 0) {
1175 /* there is no Setup info */
1176 return;
1179 ti = proto_tree_add_string_format(tree, hf_t38_setup, tvb, 0, 0,
1181 "Stream setup by %s (frame %u)",
1182 p_t38_conversation->setup_method,
1183 p_t38_conversation->setup_frame_number);
1184 proto_item_set_generated(ti);
1185 t38_setup_tree = proto_item_add_subtree(ti, ett_t38_setup);
1186 if (t38_setup_tree)
1188 /* Add details into subtree */
1189 proto_item* item = proto_tree_add_uint(t38_setup_tree, hf_t38_setup_frame,
1190 tvb, 0, 0, p_t38_conversation->setup_frame_number);
1191 proto_item_set_generated(item);
1192 item = proto_tree_add_string(t38_setup_tree, hf_t38_setup_method,
1193 tvb, 0, 0, p_t38_conversation->setup_method);
1194 proto_item_set_generated(item);
1198 /* This function tries to understand if the payload is sitting on top of AC DR */
1199 static bool
1200 dissect_t38_acdr_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
1202 unsigned acdr_prot = GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_acdr, 0));
1203 if (acdr_prot == ACDR_T38)
1204 return dissect_t38_udp(tvb, pinfo, tree, data);
1205 return false;
1209 /* Wireshark Protocol Registration */
1210 void
1211 proto_register_t38(void)
1213 static hf_register_info hf[] =
1215 { &hf_t38_IFPPacket_PDU,
1216 { "IFPPacket", "t38.IFPPacket_element",
1217 FT_NONE, BASE_NONE, NULL, 0,
1218 NULL, HFILL }},
1219 { &hf_t38_UDPTLPacket_PDU,
1220 { "UDPTLPacket", "t38.UDPTLPacket_element",
1221 FT_NONE, BASE_NONE, NULL, 0,
1222 NULL, HFILL }},
1223 { &hf_t38_type_of_msg,
1224 { "type-of-msg", "t38.type_of_msg",
1225 FT_UINT32, BASE_DEC, VALS(t38_Type_of_msg_vals), 0,
1226 NULL, HFILL }},
1227 { &hf_t38_data_field,
1228 { "data-field", "t38.data_field",
1229 FT_UINT32, BASE_DEC, NULL, 0,
1230 NULL, HFILL }},
1231 { &hf_t38_t30_indicator,
1232 { "t30-indicator", "t38.t30_indicator",
1233 FT_UINT32, BASE_DEC, VALS(t38_T30_indicator_vals), 0,
1234 NULL, HFILL }},
1235 { &hf_t38_t30_data,
1236 { "t30-data", "t38.t30_data",
1237 FT_UINT32, BASE_DEC, VALS(t38_T30_data_vals), 0,
1238 NULL, HFILL }},
1239 { &hf_t38_Data_Field_item,
1240 { "Data-Field item", "t38.Data_Field_item_element",
1241 FT_NONE, BASE_NONE, NULL, 0,
1242 NULL, HFILL }},
1243 { &hf_t38_field_type,
1244 { "field-type", "t38.field_type",
1245 FT_UINT32, BASE_DEC, VALS(t38_T_field_type_vals), 0,
1246 NULL, HFILL }},
1247 { &hf_t38_field_data,
1248 { "field-data", "t38.field_data",
1249 FT_BYTES, BASE_NONE, NULL, 0,
1250 NULL, HFILL }},
1251 { &hf_t38_seq_number,
1252 { "seq-number", "t38.seq_number",
1253 FT_UINT32, BASE_DEC, NULL, 0,
1254 NULL, HFILL }},
1255 { &hf_t38_primary_ifp_packet,
1256 { "primary-ifp-packet", "t38.primary_ifp_packet_element",
1257 FT_NONE, BASE_NONE, NULL, 0,
1258 NULL, HFILL }},
1259 { &hf_t38_error_recovery,
1260 { "error-recovery", "t38.error_recovery",
1261 FT_UINT32, BASE_DEC, VALS(t38_T_error_recovery_vals), 0,
1262 NULL, HFILL }},
1263 { &hf_t38_secondary_ifp_packets,
1264 { "secondary-ifp-packets", "t38.secondary_ifp_packets",
1265 FT_UINT32, BASE_DEC, NULL, 0,
1266 NULL, HFILL }},
1267 { &hf_t38_secondary_ifp_packets_item,
1268 { "secondary-ifp-packets item", "t38.secondary_ifp_packets_item_element",
1269 FT_NONE, BASE_NONE, NULL, 0,
1270 "OpenType_IFPPacket", HFILL }},
1271 { &hf_t38_fec_info,
1272 { "fec-info", "t38.fec_info_element",
1273 FT_NONE, BASE_NONE, NULL, 0,
1274 NULL, HFILL }},
1275 { &hf_t38_fec_npackets,
1276 { "fec-npackets", "t38.fec_npackets",
1277 FT_INT32, BASE_DEC, NULL, 0,
1278 "INTEGER", HFILL }},
1279 { &hf_t38_fec_data,
1280 { "fec-data", "t38.fec_data",
1281 FT_UINT32, BASE_DEC, NULL, 0,
1282 NULL, HFILL }},
1283 { &hf_t38_fec_data_item,
1284 { "fec-data item", "t38.fec_data_item",
1285 FT_BYTES, BASE_NONE, NULL, 0,
1286 "OCTET_STRING", HFILL }},
1287 { &hf_t38_setup,
1288 { "Stream setup", "t38.setup", FT_STRING, BASE_NONE,
1289 NULL, 0x0, "Stream setup, method and frame number", HFILL }},
1290 { &hf_t38_setup_frame,
1291 { "Stream frame", "t38.setup-frame", FT_FRAMENUM, BASE_NONE,
1292 NULL, 0x0, "Frame that set up this stream", HFILL }},
1293 { &hf_t38_setup_method,
1294 { "Stream Method", "t38.setup-method", FT_STRING, BASE_NONE,
1295 NULL, 0x0, "Method used to set up this stream", HFILL }},
1296 {&hf_t38_fragments,
1297 {"Message fragments", "t38.fragments",
1298 FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } },
1299 {&hf_t38_fragment,
1300 {"Message fragment", "t38.fragment",
1301 FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } },
1302 {&hf_t38_fragment_overlap,
1303 {"Message fragment overlap", "t38.fragment.overlap",
1304 FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL } },
1305 {&hf_t38_fragment_overlap_conflicts,
1306 {"Message fragment overlapping with conflicting data",
1307 "t38.fragment.overlap.conflicts",
1308 FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL } },
1309 {&hf_t38_fragment_multiple_tails,
1310 {"Message has multiple tail fragments",
1311 "t38.fragment.multiple_tails",
1312 FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL } },
1313 {&hf_t38_fragment_too_long_fragment,
1314 {"Message fragment too long", "t38.fragment.too_long_fragment",
1315 FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL } },
1316 {&hf_t38_fragment_error,
1317 {"Message defragmentation error", "t38.fragment.error",
1318 FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } },
1319 {&hf_t38_fragment_count,
1320 {"Message fragment count", "t38.fragment.count",
1321 FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL } },
1322 {&hf_t38_reassembled_in,
1323 {"Reassembled in", "t38.reassembled.in",
1324 FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } },
1325 {&hf_t38_reassembled_length,
1326 {"Reassembled T38 length", "t38.reassembled.length",
1327 FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL } },
1330 static int *ett[] =
1332 &ett_t38,
1333 &ett_t38_IFPPacket,
1334 &ett_t38_Type_of_msg,
1335 &ett_t38_Data_Field,
1336 &ett_t38_Data_Field_item,
1337 &ett_t38_UDPTLPacket,
1338 &ett_t38_T_error_recovery,
1339 &ett_t38_T_secondary_ifp_packets,
1340 &ett_t38_T_fec_info,
1341 &ett_t38_T_fec_data,
1342 &ett_t38_setup,
1343 &ett_data_fragment,
1344 &ett_data_fragments
1347 static ei_register_info ei[] = {
1348 { &ei_t38_malformed, { "t38.malformed", PI_MALFORMED, PI_ERROR, "Malformed packet", EXPFILL }},
1351 module_t *t38_module;
1352 expert_module_t* expert_t38;
1354 proto_t38 = proto_register_protocol("T.38", "T.38", "t38");
1355 proto_register_field_array(proto_t38, hf, array_length(hf));
1356 proto_register_subtree_array(ett, array_length(ett));
1357 expert_t38 = expert_register_protocol(proto_t38);
1358 expert_register_field_array(expert_t38, ei, array_length(ei));
1359 t38_udp_handle=register_dissector("t38_udp", dissect_t38_udp, proto_t38);
1360 t38_tcp_handle=register_dissector("t38_tcp", dissect_t38_tcp, proto_t38);
1361 t38_tcp_pdu_handle=register_dissector("t38_tcp_pdu", dissect_t38_tcp_pdu, proto_t38);
1363 /* Register reassemble tables for HDLC */
1364 reassembly_table_register(&data_reassembly_table,
1365 &addresses_reassembly_table_functions);
1367 t38_tap = register_tap("t38");
1369 t38_module = prefs_register_protocol(proto_t38, NULL);
1370 prefs_register_bool_preference(t38_module, "use_pre_corrigendum_asn1_specification",
1371 "Use the Pre-Corrigendum ASN.1 specification",
1372 "Whether the T.38 dissector should decode using the Pre-Corrigendum T.38 "
1373 "ASN.1 specification (1998).",
1374 &use_pre_corrigendum_asn1_specification);
1375 prefs_register_bool_preference(t38_module, "dissect_possible_rtpv2_packets_as_rtp",
1376 "Dissect possible RTP version 2 packets with RTP dissector",
1377 "Whether a UDP packet that looks like RTP version 2 packet will "
1378 "be dissected as RTP packet or T.38 packet. If enabled there is a risk that T.38 UDPTL "
1379 "packets with sequence number higher than 32767 may be dissected as RTP.",
1380 &dissect_possible_rtpv2_packets_as_rtp);
1381 prefs_register_bool_preference(t38_module, "reassembly",
1382 "Reassemble T.38 PDUs over TPKT over TCP",
1383 "Whether the dissector should reassemble T.38 PDUs spanning multiple TCP segments "
1384 "when TPKT is used over TCP. "
1385 "To use this option, you must also enable \"Allow subdissectors to reassemble "
1386 "TCP streams\" in the TCP protocol settings.",
1387 &t38_tpkt_reassembly);
1388 prefs_register_enum_preference(t38_module, "tpkt_usage",
1389 "TPKT used over TCP",
1390 "Whether T.38 is used with TPKT for TCP",
1391 (int *)&t38_tpkt_usage,t38_tpkt_options,false);
1393 prefs_register_bool_preference(t38_module, "show_setup_info",
1394 "Show stream setup information",
1395 "Where available, show which protocol and frame caused "
1396 "this T.38 stream to be created",
1397 &global_t38_show_setup_info);
1401 void
1402 proto_reg_handoff_t38(void)
1404 rtp_handle = find_dissector_add_dependency("rtp", proto_t38);
1405 t30_hdlc_handle = find_dissector_add_dependency("t30.hdlc", proto_t38);
1406 proto_acdr = proto_get_id_by_filter_name("acdr");
1407 data_handle = find_dissector("data");
1408 dissector_add_for_decode_as("tcp.port", t38_tcp_handle);
1409 dissector_add_for_decode_as("udp.port", t38_udp_handle);
1410 heur_dissector_add("udp", dissect_t38_acdr_heur, "T38 over AC DR", "t38_acdr", proto_t38, HEURISTIC_ENABLE);
1411 dissector_add_uint("acdr.media_type", ACDR_T38, t38_udp_handle);