For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / epan / dissectors / packet-h223.c
index 658f2c12db62e031e8d86197093c92011db3eeac..e1c64ed928d89a5b957d853060f19cd1850653ad 100644 (file)
@@ -54,7 +54,6 @@
 
 /* Wireshark ID of the H.223 protocol */
 static int proto_h223 = -1;
-static int proto_h223_bitswapped = -1;
 
 /* The following hf_* variables are used to hold the Wireshark IDs of
  * our header fields; they are filled out when we call
@@ -79,6 +78,7 @@ static int hf_h223_mux_fragment_overlap_conflict = -1;
 static int hf_h223_mux_fragment_multiple_tails = -1;
 static int hf_h223_mux_fragment_too_long_fragment = -1;
 static int hf_h223_mux_fragment_error = -1;
+static int hf_h223_mux_fragment_count = -1;
 static int hf_h223_mux_reassembled_in = -1;
 static int hf_h223_mux_reassembled_length = -1;
 
@@ -89,6 +89,7 @@ static int hf_h223_al_fragment_overlap_conflict = -1;
 static int hf_h223_al_fragment_multiple_tails = -1;
 static int hf_h223_al_fragment_too_long_fragment = -1;
 static int hf_h223_al_fragment_error = -1;
+static int hf_h223_al_fragment_count = -1;
 static int hf_h223_al_reassembled_in = -1;
 static int hf_h223_al_reassembled_length = -1;
 
@@ -134,6 +135,7 @@ static const fragment_items h223_mux_frag_items _U_ = {
     &hf_h223_mux_fragment_multiple_tails,
     &hf_h223_mux_fragment_too_long_fragment,
     &hf_h223_mux_fragment_error,
+    &hf_h223_mux_fragment_count,
     &hf_h223_mux_reassembled_in,
     &hf_h223_mux_reassembled_length,
     "fragments"
@@ -149,6 +151,7 @@ static const fragment_items h223_al_frag_items = {
     &hf_h223_al_fragment_multiple_tails,
     &hf_h223_al_fragment_too_long_fragment,
     &hf_h223_al_fragment_error,
+    &hf_h223_al_fragment_count,
     &hf_h223_al_reassembled_in,
     &hf_h223_al_reassembled_length,
     "fragments"
@@ -176,7 +179,8 @@ static GHashTable *circuit_chain_hashtable = NULL;
 static guint circuit_chain_count = 1;
 
 /* Hash Functions */
-static gint circuit_chain_equal(gconstpointer v, gconstpointer w)
+static gint
+circuit_chain_equal(gconstpointer v, gconstpointer w)
 {
     const circuit_chain_key *v1 = (const circuit_chain_key *)v;
     const circuit_chain_key *v2 = (const circuit_chain_key *)w;
@@ -186,15 +190,16 @@ static gint circuit_chain_equal(gconstpointer v, gconstpointer w)
     return result;
 }
 
-static guint circuit_chain_hash (gconstpointer v)
+static guint
+circuit_chain_hash (gconstpointer v)
 {
     const circuit_chain_key *key = (const circuit_chain_key *)v;
     guint hash_val = ((guint32)(unsigned long)(key->call))^(((guint32)key->vc) << 16);
     return hash_val;
 }
 
-static guint32 circuit_chain_lookup(const h223_call_info* call_info,
-                                    guint32 child_vc)
+static guint32
+circuit_chain_lookup(const h223_call_info* call_info, guint32 child_vc)
 {
     circuit_chain_key key, *new_key;
     guint32 circuit_id;
@@ -210,7 +215,8 @@ static guint32 circuit_chain_lookup(const h223_call_info* call_info,
     return circuit_id;
 }
 
-static void circuit_chain_init(void)
+static void
+circuit_chain_init(void)
 {
     if (circuit_chain_hashtable)
         g_hash_table_destroy(circuit_chain_hashtable);
@@ -275,14 +281,15 @@ typedef struct {
     h223_call_info          *call_info;
 } h223_vc_info;
 
-static void add_h223_mux_element(h223_call_direction_data *direct, guint8 mc, h223_mux_element *me, guint32 framenum)
+static void
+add_h223_mux_element(h223_call_direction_data *direct, guint8 mc, h223_mux_element *me, guint32 framenum)
 {
     h223_mux_element_listitem *li;
     h223_mux_element_listitem **old_li_ptr;
     h223_mux_element_listitem *old_li;
-    
+
     DISSECTOR_ASSERT(mc < 16);
-    
+
     li = se_alloc(sizeof(h223_mux_element_listitem));
     old_li_ptr = &(direct->mux_table[mc]);
     old_li = *old_li_ptr;
@@ -307,14 +314,15 @@ static void add_h223_mux_element(h223_call_direction_data *direct, guint8 mc, h2
     li->me = me;
 }
 
-static h223_mux_element* find_h223_mux_element(h223_call_direction_data* direct, guint8 mc, guint32 framenum, guint32 pkt_offset)
+static h223_mux_element*
+find_h223_mux_element(h223_call_direction_data* direct, guint8 mc, guint32 framenum, guint32 pkt_offset)
 {
     h223_mux_element_listitem* li;
-    
+
     DISSECTOR_ASSERT(mc < 16);
-    
+
     li = direct->mux_table[mc];
-    
+
     while( li && li->next && li->next->first_frame < framenum )
         li = li->next;
     while( li && li->next && li->next->first_frame == framenum && li->next->pdu_offset < pkt_offset )
@@ -326,7 +334,8 @@ static h223_mux_element* find_h223_mux_element(h223_call_direction_data* direct,
     }
 }
 
-static void add_h223_lc_params(h223_vc_info* vc_info, int direction, h223_lc_params *lc_params, guint32 framenum )
+static void
+add_h223_lc_params(h223_vc_info* vc_info, int direction, h223_lc_params *lc_params, guint32 framenum )
 {
     h223_lc_params_listitem *li = se_alloc(sizeof(h223_lc_params_listitem));
     h223_lc_params_listitem **old_li_ptr = &(vc_info->lc_params[direction ? 0 : 1]);
@@ -353,7 +362,8 @@ static void add_h223_lc_params(h223_vc_info* vc_info, int direction, h223_lc_par
     li->lc_params = lc_params;
 }
 
-static h223_lc_params* find_h223_lc_params(h223_vc_info* vc_info, int direction, guint32 framenum)
+static h223_lc_params*
+find_h223_lc_params(h223_vc_info* vc_info, int direction, guint32 framenum)
 {
     h223_lc_params_listitem* li = vc_info->lc_params[direction? 0 : 1];
     while( li && li->next && li->next->first_frame <= framenum )
@@ -364,7 +374,8 @@ static h223_lc_params* find_h223_lc_params(h223_vc_info* vc_info, int direction,
         return NULL;
 }
 
-static void init_direction_data(h223_call_direction_data *direct)
+static void
+init_direction_data(h223_call_direction_data *direct)
 {
     int i;
     h223_mux_element *mc0_element;
@@ -381,7 +392,8 @@ static void init_direction_data(h223_call_direction_data *direct)
     mc0_element->next = NULL;
 }
 
-static h223_vc_info* h223_vc_info_new( h223_call_info* call_info )
+static h223_vc_info*
+h223_vc_info_new( h223_call_info* call_info )
 {
     h223_vc_info *vc_info = se_alloc(sizeof(h223_vc_info));
     vc_info->lc_params[0] = vc_info->lc_params[1] = NULL;
@@ -389,7 +401,8 @@ static h223_vc_info* h223_vc_info_new( h223_call_info* call_info )
     return vc_info;
 }
 
-static void init_logical_channel( guint32 start_frame, h223_call_info* call_info, int vc, int direction, h223_lc_params* params )
+static void
+init_logical_channel( guint32 start_frame, h223_call_info* call_info, int vc, int direction, h223_lc_params* params )
 {
     guint32 circuit_id = circuit_chain_lookup(call_info, vc);
     circuit_t *subcircuit;
@@ -410,7 +423,8 @@ static void init_logical_channel( guint32 start_frame, h223_call_info* call_info
 }
 
 /* create a brand-new h223_call_info structure */
-static h223_call_info *create_call_info( guint32 start_frame )
+static h223_call_info *
+create_call_info( guint32 start_frame )
 {
     h223_call_info *datax;
     h223_lc_params *vc0_params;
@@ -420,7 +434,7 @@ static h223_call_info *create_call_info( guint32 start_frame )
     /* initialise the call info */
     init_direction_data(&datax -> direction_data[0]);
     init_direction_data(&datax -> direction_data[1]);
-        
+
     /* FIXME shouldn't this be figured out dynamically? */
     datax -> h223_level = 2;
 
@@ -435,7 +449,8 @@ static h223_call_info *create_call_info( guint32 start_frame )
 }
 
 /* find or create call_info struct for calls over circuits (eg, IAX) */
-static h223_call_info *find_or_create_call_info_circ(packet_info * pinfo)
+static h223_call_info *
+find_or_create_call_info_circ(packet_info * pinfo)
 {
     h223_call_info *datax;
     circuit_t *circ = NULL;
@@ -446,7 +461,7 @@ static h223_call_info *find_or_create_call_info_circ(packet_info * pinfo)
         return NULL;
 
     datax = (h223_call_info *)circuit_get_proto_data(circ, proto_h223);
-    
+
     if( datax == NULL ) {
         datax = create_call_info(pinfo->fd->num);
 
@@ -456,16 +471,17 @@ static h223_call_info *find_or_create_call_info_circ(packet_info * pinfo)
 #endif
         circuit_add_proto_data(circ, proto_h223, datax);
     }
-    
+
     /* work out what direction we're really going in */
     if( pinfo->p2p_dir < 0 || pinfo->p2p_dir > 1)
         pinfo->p2p_dir = P2P_DIR_SENT;
-    
+
     return datax;
 }
 
 /* find or create call_info struct for calls over conversations (eg, RTP) */
-static h223_call_info *find_or_create_call_info_conv(packet_info * pinfo)
+static h223_call_info *
+find_or_create_call_info_conv(packet_info * pinfo)
 {
     h223_call_info *datax;
     conversation_t *conv;
@@ -484,7 +500,7 @@ static h223_call_info *find_or_create_call_info_conv(packet_info * pinfo)
 
     if(datax == NULL && pinfo->ptype == PT_UDP ) {
         conversation_t *conv2;
-        
+
         /* RTP tracks the two sides of the conversation totally separately;
          * this messes us up totally.
          *
@@ -523,7 +539,7 @@ static h223_call_info *find_or_create_call_info_conv(packet_info * pinfo)
                 pinfo->dst.data[0], pinfo->dst.data[1], pinfo->dst.data[2], pinfo->dst.data[3],
                 pinfo->destport);
 #endif
-            
+
         conversation_add_proto_data(conv, proto_h223, datax);
         /* add the source details so we can distinguish directions
          * in future */
@@ -535,13 +551,14 @@ static h223_call_info *find_or_create_call_info_conv(packet_info * pinfo)
     if( ADDRESSES_EQUAL( &(pinfo->src), &(datax->srcaddress))
         && pinfo->srcport == datax->srcport )
         pinfo->p2p_dir = P2P_DIR_SENT;
-    else 
+    else
         pinfo->p2p_dir = P2P_DIR_RECV;
 
     return datax;
 }
 
-static h223_call_info *find_or_create_call_info ( packet_info * pinfo )
+static h223_call_info *
+find_or_create_call_info ( packet_info * pinfo )
 {
     h223_call_info *datax;
 
@@ -552,7 +569,8 @@ static h223_call_info *find_or_create_call_info ( packet_info * pinfo )
 }
 
 /* called from the h245 dissector to handle a MultiplexEntrySend message */
-static void h223_set_mc( packet_info* pinfo, guint8 mc, h223_mux_element* me )
+static void
+h223_set_mc( packet_info* pinfo, guint8 mc, h223_mux_element* me )
 {
     circuit_t *circ = find_circuit( pinfo->ctype, pinfo->circuit_id, pinfo->fd->num );
     h223_vc_info* vc_info;
@@ -566,7 +584,8 @@ static void h223_set_mc( packet_info* pinfo, guint8 mc, h223_mux_element* me )
 }
 
 /* called from the h245 dissector to handle an OpenLogicalChannelAck message */
-static void h223_add_lc( packet_info* pinfo, guint16 lc, h223_lc_params* params )
+static void
+h223_add_lc( packet_info* pinfo, guint16 lc, h223_lc_params* params )
 {
     circuit_t *circ = find_circuit( pinfo->ctype, pinfo->circuit_id, pinfo->fd->num );
     h223_vc_info* vc_info;
@@ -613,11 +632,10 @@ static guint8 h223_al2_crc8bit( tvbuff_t *tvb ) {
     return crc;
 }
 
-static void dissect_mux_al_pdu( tvbuff_t *tvb,
-                                packet_info *pinfo,
-                                proto_tree *vc_tree,
-/*                                circuit_t* vc_circuit, */
-                                h223_lc_params* lc_params )
+static void
+dissect_mux_al_pdu( tvbuff_t *tvb, packet_info *pinfo, proto_tree *vc_tree,
+/*                  circuit_t* vc_circuit, */
+                    h223_lc_params* lc_params )
 {
     proto_tree *al_tree = NULL;
     proto_item *al_item, *hidden_item;
@@ -644,9 +662,9 @@ static void dissect_mux_al_pdu( tvbuff_t *tvb,
                 PROTO_ITEM_SET_HIDDEN(hidden_item);
             }
             next_tvb = tvb;
-            al_subitem = proto_tree_add_item(al_tree, hf_h223_al_payload, next_tvb, 0, -1, FALSE);
+            al_subitem = proto_tree_add_item(al_tree, hf_h223_al_payload, next_tvb, 0, -1, ENC_NA);
             break;
-        
+
         case al2WithSequenceNumbers:
             al2_sequenced = TRUE;
             /* fall-through */
@@ -663,15 +681,15 @@ static void dissect_mux_al_pdu( tvbuff_t *tvb,
             /* check minimum payload length */
             if(len < (al2_sequenced?2U:1U))
                 THROW(BoundsError);
-        
+
             data_start = 0;
             if( al2_sequenced ) {
-                proto_tree_add_item(al_tree, hf_h223_al2_seqno, tvb, 0, 1, TRUE);
+                proto_tree_add_item(al_tree, hf_h223_al2_seqno, tvb, 0, 1, ENC_LITTLE_ENDIAN);
                 data_start++;
             }
 
             next_tvb = tvb_new_subset( tvb, data_start, len-1-data_start, len-1-data_start );
-            al_subitem = proto_tree_add_item(al_tree, hf_h223_al_payload, next_tvb, 0, -1, FALSE);
+            al_subitem = proto_tree_add_item(al_tree, hf_h223_al_payload, next_tvb, 0, -1, ENC_NA);
 
             calc_checksum = h223_al2_crc8bit(tvb);
             real_checksum = tvb_get_guint8(tvb, len - 1);
@@ -719,12 +737,11 @@ static void dissect_mux_al_pdu( tvbuff_t *tvb,
  * end_of_mux_sdu true if this is a segmentable VC and this is the last
  *              fragment in an SDU
  */
-static void dissect_mux_sdu_fragment(tvbuff_t *volatile next_tvb,
-                                    packet_info *pinfo,
-                                    guint32 pkt_offset,
-                                    proto_tree *pdu_tree,
-                                    h223_call_info* call_info,
-                                    guint16 vc, gboolean end_of_mux_sdu)
+static void
+dissect_mux_sdu_fragment(tvbuff_t *volatile next_tvb, packet_info *pinfo,
+                         guint32 pkt_offset, proto_tree *pdu_tree,
+                         h223_call_info* call_info, guint16 vc,
+                         gboolean end_of_mux_sdu)
 {
     /* update the circuit details before passing to a subdissector */
     guint32 orig_circuit = pinfo->circuit_id;
@@ -754,12 +771,12 @@ static void dissect_mux_sdu_fragment(tvbuff_t *volatile next_tvb,
             }
         }
 
-        
+
         if( lc_params != NULL ) {
                 if( lc_params->segmentable && lc_params->al_type != al1NotFramed ) {
                     stream_t *substream;
                     stream_pdu_fragment_t *frag;
-                
+
                     substream = find_stream_circ(subcircuit,pinfo->p2p_dir);
                     if(substream == NULL )
                         substream = stream_new_circ(subcircuit,pinfo->p2p_dir);
@@ -780,7 +797,7 @@ static void dissect_mux_sdu_fragment(tvbuff_t *volatile next_tvb,
                     }
 
                     next_tvb = stream_process_reassembled(
-                        next_tvb, 0, pinfo, 
+                        next_tvb, 0, pinfo,
                         "Reassembled H.223 AL-PDU",
                         frag, &h223_al_frag_items,
                         NULL, vc_tree);
@@ -805,7 +822,8 @@ static void dissect_mux_sdu_fragment(tvbuff_t *volatile next_tvb,
     ENDTRY;
 }
 
-static guint32 mux_element_sublist_size( h223_mux_element* me )
+static guint32
+mux_element_sublist_size( h223_mux_element* me )
 {
     h223_mux_element *current_me = me;
     guint32 length = 0;
@@ -836,9 +854,12 @@ static guint32 mux_element_sublist_size( h223_mux_element* me )
  * offset       offset within tvb to start work
  * endOfMuxSdu  true if the end-of-sdu flag was set
  */
-static guint32 dissect_mux_payload_by_me_list( tvbuff_t *tvb, packet_info *pinfo, guint32 pkt_offset,
-                                               proto_tree *pdu_tree,
-                                               h223_call_info* call_info, h223_mux_element* me, guint32 offset, gboolean endOfMuxSdu )
+static guint32
+dissect_mux_payload_by_me_list( tvbuff_t *tvb, packet_info *pinfo,
+                                guint32 pkt_offset, proto_tree *pdu_tree,
+                                h223_call_info* call_info,
+                                h223_mux_element *me, guint32 offset,
+                                gboolean endOfMuxSdu )
 {
     guint32 len = tvb_reported_length(tvb);
     guint32 frag_len;
@@ -885,10 +906,11 @@ static guint32 dissect_mux_payload_by_me_list( tvbuff_t *tvb, packet_info *pinfo
  * call_info    data structure for h223 call
  * mc           multiplex code for this PDU
  * endOfMuxSdu  true if the end-of-sdu flag was set
- */ 
-static void dissect_mux_payload( tvbuff_t *tvb, packet_info *pinfo, guint32 pkt_offset,
-                                 proto_tree *pdu_tree,
-                                 h223_call_info* call_info, guint8 mc, gboolean endOfMuxSdu )
+ */
+static void
+dissect_mux_payload( tvbuff_t *tvb, packet_info *pinfo, guint32 pkt_offset,
+                     proto_tree *pdu_tree, h223_call_info *call_info,
+                     guint8 mc, gboolean endOfMuxSdu )
 {
     guint32 len = tvb_reported_length(tvb);
 
@@ -899,9 +921,9 @@ static void dissect_mux_payload( tvbuff_t *tvb, packet_info *pinfo, guint32 pkt_
     } else {
         /* no entry found in mux-table. ignore packet and dissect as data */
         proto_tree *vc_tree = NULL;
-            
+
         if(pdu_tree) {
-            proto_item *vc_item = proto_tree_add_item(pdu_tree, hf_h223_mux_deact, tvb, 0, len, FALSE);
+            proto_item *vc_item = proto_tree_add_item(pdu_tree, hf_h223_mux_deact, tvb, 0, len, ENC_NA);
             vc_tree = proto_item_add_subtree(vc_item, ett_h223_mux_deact);
         }
         call_dissector(data_handle,tvb,pinfo,vc_tree);
@@ -920,10 +942,9 @@ static void dissect_mux_payload( tvbuff_t *tvb, packet_info *pinfo, guint32 pkt_
  * call_info    h223 info structure for this h223 call
  * pdu_no       index of this pdu within the call
  */
-static void dissect_mux_pdu( tvbuff_t *tvb, packet_info * pinfo,
-                             guint32 pkt_offset,
-                             proto_tree *h223_tree,
-                             h223_call_info *call_info)
+static void
+dissect_mux_pdu( tvbuff_t *tvb, packet_info *pinfo, guint32 pkt_offset,
+                 proto_tree *h223_tree, h223_call_info *call_info)
 {
     guint32 offset = 0;
     /* actual (as opposed to reported) payload len */
@@ -943,7 +964,7 @@ static void dissect_mux_pdu( tvbuff_t *tvb, packet_info * pinfo,
     g_debug("%u: dissecting complete H.223 MUX-PDU, pkt_offset %u, len %u",
             pinfo->fd->num, pkt_offset, tvb_reported_length(tvb));
 #endif
-    
+
     switch(call_info->h223_level) {
         case 0: case 1:
             raw_hdr = tvb_get_guint8(tvb,0);
@@ -964,7 +985,7 @@ static void dissect_mux_pdu( tvbuff_t *tvb, packet_info * pinfo,
 
             if(errors != -1) {
                 correct_hdr = raw_hdr ^ (guint32)errors;
-    
+
                 mc = (guint8)(correct_hdr & 0xf);
                 mpl = (guint8)((correct_hdr >> 4) & 0xff);
 
@@ -983,23 +1004,22 @@ static void dissect_mux_pdu( tvbuff_t *tvb, packet_info * pinfo,
         case 3:
             /* XXX not implemented */
         default:
-            len=0;
             DISSECTOR_ASSERT_NOT_REACHED();
     }
 
-    
+
     if( h223_tree ) {
         if( mpl == 0 ) {
-            pdu_item = proto_tree_add_item (h223_tree, hf_h223_mux_stuffing_pdu, tvb, 0, -1, FALSE);
+            pdu_item = proto_tree_add_item (h223_tree, hf_h223_mux_stuffing_pdu, tvb, 0, -1, ENC_NA);
             pdu_tree = proto_item_add_subtree (pdu_item, ett_h223_mux_stuffing_pdu);
         } else {
-            pdu_item = proto_tree_add_item (h223_tree, hf_h223_mux_pdu, tvb, 0, -1, FALSE);
+            pdu_item = proto_tree_add_item (h223_tree, hf_h223_mux_pdu, tvb, 0, -1, ENC_NA);
             pdu_tree = proto_item_add_subtree (pdu_item, ett_h223_mux_pdu);
         }
     }
 
     if( pdu_tree ) {
-        proto_item *item = proto_tree_add_item (pdu_tree, hf_h223_mux_header, tvb, 0, offset, FALSE);
+        proto_item *item = proto_tree_add_item (pdu_tree, hf_h223_mux_header, tvb, 0, offset, ENC_NA);
         proto_tree *hdr_tree = proto_item_add_subtree (item, ett_h223_mux_header);
 
         switch(call_info->h223_level) {
@@ -1055,17 +1075,17 @@ static void dissect_mux_pdu( tvbuff_t *tvb, packet_info * pinfo,
         proto_tree *vc_tree = NULL;
 
         if( pdu_tree ) {
-            proto_item *vc_item = proto_tree_add_item(pdu_tree, hf_h223_mux_extra, next_tvb, 0, len, FALSE);
+            proto_item *vc_item = proto_tree_add_item(pdu_tree, hf_h223_mux_extra, next_tvb, 0, len, ENC_NA);
             vc_tree = proto_item_add_subtree(vc_item, ett_h223_mux_deact);
         }
         call_dissector(data_handle,next_tvb,pinfo,vc_tree);
 
         offset += len;
-    } 
+    }
 
     /* add the closing HDLC flag */
     if( pdu_tree )
-        proto_tree_add_item(pdu_tree,hf_h223_mux_hdlc2,tvb,offset,2,FALSE);
+        proto_tree_add_item(pdu_tree,hf_h223_mux_hdlc2,tvb,offset,2,ENC_BIG_ENDIAN);
 }
 
 
@@ -1075,21 +1095,20 @@ static void dissect_mux_pdu( tvbuff_t *tvb, packet_info * pinfo,
  */
 
 /* attempt to parse the header of a mux pdu */
-static gboolean attempt_mux_level0_header_parse(guint32 nbytes, guint32 hdr, guint32 *minlen)
+static gboolean
+attempt_mux_level0_header_parse(guint32 nbytes _U_, guint32 hdr _U_, guint32 *minlen _U_)
 {
     /* level 0 isn't byte-aligned, so is a complete pain to implement */
     DISSECTOR_ASSERT_NOT_REACHED();
-    nbytes = nbytes;
-    hdr=hdr;
-    minlen=minlen;
     return FALSE;
 }
 
-static gboolean attempt_mux_level1_header_parse(guint32 nbytes, guint32 hdr, guint32 *minlen)
+static gboolean
+attempt_mux_level1_header_parse(guint32 nbytes, guint32 hdr, guint32 *minlen)
 {
     /* this is untested */
     DISSECTOR_ASSERT_NOT_REACHED();
-    
+
     if(nbytes < 2)
         return FALSE;
 
@@ -1103,10 +1122,11 @@ static gboolean attempt_mux_level1_header_parse(guint32 nbytes, guint32 hdr, gui
     return TRUE;
 }
 
-static gboolean attempt_mux_level2_3_header_parse(guint32 nbytes, guint32 hdr, guint32 *minlen)
+static gboolean
+attempt_mux_level2_3_header_parse(guint32 nbytes, guint32 hdr, guint32 *minlen)
 {
     gint32 errors;
-    
+
     if(nbytes < 3)
         return FALSE;
 
@@ -1118,7 +1138,7 @@ static gboolean attempt_mux_level2_3_header_parse(guint32 nbytes, guint32 hdr, g
         ((hdr & 0xFF0000) >> 16) |
         (hdr & 0x00FF00) |
         ((hdr & 0x0000FF) << 16);
-    
+
     errors = golay_errors(hdr);
     if(errors != -1) {
         hdr ^= errors;
@@ -1135,7 +1155,8 @@ static gboolean (* const attempt_mux_header_parse[])(guint32 nbytes, guint32 hea
     attempt_mux_level2_3_header_parse
 };
 
-static gboolean h223_mux_check_hdlc(int h223_level, guint32 nbytes, guint32 tail_buf)
+static gboolean
+h223_mux_check_hdlc(int h223_level, guint32 nbytes, guint32 tail_buf)
 {
     guint32 masked;
 
@@ -1165,9 +1186,10 @@ static gboolean h223_mux_check_hdlc(int h223_level, guint32 nbytes, guint32 tail
  * extra bytes needed, or zero if we don't know yet
  */
 
-static gint dissect_mux_pdu_fragment( tvbuff_t *tvb, guint32 start_offset, packet_info * pinfo,
-                                      proto_tree *h223_tree,
-                                      h223_call_info *call_info)
+static gint
+dissect_mux_pdu_fragment( tvbuff_t *tvb, guint32 start_offset,
+                          packet_info *pinfo, proto_tree *h223_tree,
+                          h223_call_info *call_info)
 {
     tvbuff_t *volatile next_tvb;
     volatile guint32 offset = start_offset;
@@ -1176,16 +1198,17 @@ static gint dissect_mux_pdu_fragment( tvbuff_t *tvb, guint32 start_offset, packe
     gboolean header_parsed = FALSE;
     guint32 header_buf = 0, tail_buf = 0;
     guint32 pdu_minlen = 0;
-    
+    void *pd_save;
+
 
 #ifdef DEBUG_H223_FRAGMENTATION
     g_debug("%d: dissecting H.223 PDU, start_offset %u, %u bytes left",
             pinfo->fd->num,start_offset, tvb_reported_length_remaining( tvb, start_offset ));
 #endif
-    
+
     while( more_frags && offset < tvb_reported_length( tvb )) {
         guint8 byte = tvb_get_guint8(tvb, offset++);
-        
+
         /* read a byte into the header buf, if necessary */
         if((offset-start_offset) <= 4) {
             header_buf <<= 8;
@@ -1236,15 +1259,22 @@ static gint dissect_mux_pdu_fragment( tvbuff_t *tvb, guint32 start_offset, packe
     /* we catch boundserrors on the pdu so that errors on an
      * individual pdu don't screw up the whole of the rest of the
      * stream */
+    pd_save = pinfo->private_data;
     TRY {
         dissect_mux_pdu( next_tvb, pinfo, start_offset, h223_tree, call_info);
     }
 
     CATCH2(BoundsError,ReportedBoundsError) {
-        col_append_str(pinfo->cinfo, COL_INFO,
-                           "[Malformed Packet]");
+        /*  Restore the private_data structure in case one of the
+         *  called dissectors modified it (and, due to the exception,
+         *  was unable to restore it).
+         */
+        pinfo->private_data = pd_save;
+
+        col_append_str(pinfo->cinfo, COL_INFO, "[Malformed Packet]");
         proto_tree_add_protocol_format(h223_tree, proto_malformed,
-                                       tvb, 0, 0, "[Malformed Packet: %s]", pinfo->current_proto);
+                                       tvb, 0, 0, "[Malformed Packet: %s]",
+                                       pinfo->current_proto);
     }
 
     ENDTRY;
@@ -1262,7 +1292,8 @@ static gint dissect_mux_pdu_fragment( tvbuff_t *tvb, guint32 start_offset, packe
  * Updates desegment_offset and desegment_len if the end of the data didn't
  * line up with the end of a pdu.
  */
-static void dissect_h223 (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
+static void
+dissect_h223 (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
     proto_tree *h223_tree = NULL;
     proto_item *h223_item = NULL;
@@ -1279,7 +1310,7 @@ static void dissect_h223 (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree
 
     /* add the 'h223' tree to the main tree */
     if (tree) {
-        h223_item = proto_tree_add_item (tree, proto_h223, tvb, 0, -1, FALSE);
+        h223_item = proto_tree_add_item (tree, proto_h223, tvb, 0, -1, ENC_NA);
         h223_tree = proto_item_add_subtree (h223_item, ett_h223);
     }
 
@@ -1325,7 +1356,8 @@ static void dissect_h223 (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree
  * This dissector swaps the ordering of the bits in each byte before using the
  * normal entry point.
  */
-static void dissect_h223_bitswapped (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
+static void
+dissect_h223_bitswapped (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
     tvbuff_t *reversed_tvb;
     guint8 *datax;
@@ -1349,13 +1381,14 @@ static void dissect_h223_bitswapped (tvbuff_t * tvb, packet_info * pinfo, proto_
 
     /* Add the reversed data to the data source list. */
     add_new_data_source(pinfo, reversed_tvb, "Bit-swapped H.223 frame" );
-    
+
     dissect_h223(reversed_tvb,pinfo,tree);
 }
 
 /******************************************************************************/
 
-static void h223_init_protocol (void)
+static void
+h223_init_protocol (void)
 {
     circuit_chain_init();
 }
@@ -1364,12 +1397,12 @@ static void h223_init_protocol (void)
 void proto_register_h223 (void)
 {
     /* A header field is something you can search/filter on.
-     * 
+     *
      * We create a structure to register our fields. It consists of an
      * array of hf_register_info structures, each of which are of the format
      * {&(field id), {name, abbrev, type, display, strings, bitmask, blurb, HFILL}}.
      */
-   
+
     static hf_register_info hf[] = {
         { &hf_h223_non_h223_data,
           { "Non-H.223 data", "h223.non-h223", FT_NONE, BASE_NONE, NULL, 0x0,
@@ -1390,7 +1423,7 @@ void proto_register_h223 (void)
         { &hf_h223_mux_rawhdr,
           { "Raw value", "h223.mux.rawhdr", FT_UINT24, BASE_HEX, NULL, 0x0,
             "Raw header bytes", HFILL }},
-        
+
         { &hf_h223_mux_correctedhdr,
           { "Corrected value", "h223.mux.correctedhdr", FT_UINT24, BASE_HEX, NULL, 0x0,
             "Corrected header bytes", HFILL }},
@@ -1409,12 +1442,12 @@ void proto_register_h223 (void)
 
         { &hf_h223_mux_vc,
           { "H.223 virtual circuit", "h223.mux.vc", FT_UINT16, BASE_DEC, NULL, 0x0,
-            "H.223 Virtual Circuit", HFILL }},
-        
+            NULL, HFILL }},
+
         { &hf_h223_mux_extra,
           { "Extraneous data", "h223.mux.extra", FT_NONE, BASE_NONE, NULL, 0x0,
             "data beyond mpl", HFILL }},
-        
+
         { &hf_h223_mux_hdlc2,
           { "HDLC flag", "h223.mux.hdlc", FT_UINT16, BASE_HEX, NULL, 0x0,
             "framing flag", HFILL }},
@@ -1423,74 +1456,82 @@ void proto_register_h223 (void)
         { &hf_h223_mux_fragment_overlap,
           { "Fragment overlap", "h223.mux.fragment.overlap", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
             "Fragment overlaps with other fragments", HFILL }},
-        
+
         { &hf_h223_mux_fragment_overlap_conflict,
           { "Conflicting data in fragment overlap",     "h223.mux.fragment.overlap.conflict", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
             "Overlapping fragments contained conflicting data", HFILL }},
-        
+
         { &hf_h223_mux_fragment_multiple_tails,
           { "Multiple tail fragments found",    "h223.mux.fragment.multipletails", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
             "Several tails were found when defragmenting the packet", HFILL }},
-        
+
         { &hf_h223_mux_fragment_too_long_fragment,
           { "Fragment too long",        "h223.mux.fragment.toolongfragment", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
             "Fragment contained data past end of packet", HFILL }},
-        
+
         { &hf_h223_mux_fragment_error,
           { "Defragmentation error", "h223.mux.fragment.error", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
             "Defragmentation error due to illegal fragments", HFILL }},
-        
+
+        { &hf_h223_mux_fragment_count,
+          { "Fragment count", "h223.mux.fragment.count", FT_UINT32, BASE_DEC, NULL, 0x0,
+            NULL, HFILL }},
+
         { &hf_h223_mux_fragment,
           { "H.223 MUX-PDU Fragment", "h223.mux.fragment", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
             NULL, HFILL }},
-        
+
         { &hf_h223_mux_fragments,
           { "H.223 MUX-PDU Fragments", "h223.mux.fragments", FT_NONE, BASE_NONE, NULL, 0x0,
             NULL, HFILL }},
-        
+
         { &hf_h223_mux_reassembled_in,
           { "MUX-PDU fragment, reassembled in frame", "h223.mux.reassembled_in", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
             "This H.223 MUX-PDU packet is reassembled in this frame", HFILL }},
 
         { &hf_h223_mux_reassembled_length,
-          { "Reassembled length", "h223.mux.reassembled.length", FT_UINT32, BASE_DEC, NULL, 0x0,
+          { "Reassembled H.223 MUX-PDU length", "h223.mux.reassembled.length", FT_UINT32, BASE_DEC, NULL, 0x0,
             "The total length of the reassembled payload", HFILL }},
 
         /* fields for h.223-al fragments */
         { &hf_h223_al_fragment_overlap,
           { "Fragment overlap", "h223.al.fragment.overlap", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
             "Fragment overlaps with other fragments", HFILL }},
-        
+
         { &hf_h223_al_fragment_overlap_conflict,
           { "Conflicting data in fragment overlap",     "h223.al.fragment.overlap.conflict", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
             "Overlapping fragments contained conflicting data", HFILL }},
-        
+
         { &hf_h223_al_fragment_multiple_tails,
           { "Multiple tail fragments found",    "h223.al.fragment.multipletails", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
             "Several tails were found when defragmenting the packet", HFILL }},
-        
+
         { &hf_h223_al_fragment_too_long_fragment,
           { "Fragment too long",        "h223.al.fragment.toolongfragment", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
             "Fragment contained data past end of packet", HFILL }},
-        
+
         { &hf_h223_al_fragment_error,
           { "Defragmentation error", "h223.al.fragment.error", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
             "Defragmentation error due to illegal fragments", HFILL }},
-        
+
+        { &hf_h223_al_fragment_count,
+          { "Fragment count", "h223.al.fragment.count", FT_UINT32, BASE_DEC, NULL, 0x0,
+            NULL, HFILL }},
+
         { &hf_h223_al_fragment,
           { "H.223 AL-PDU Fragment", "h223.al.fragment", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
             NULL, HFILL }},
-        
+
         { &hf_h223_al_fragments,
           { "H.223 AL-PDU Fragments", "h223.al.fragments", FT_NONE, BASE_NONE, NULL, 0x0,
             NULL, HFILL }},
-        
+
         { &hf_h223_al_reassembled_in,
           { "AL-PDU fragment, reassembled in frame", "h223.al.reassembled_in", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
             "This H.223 AL-PDU packet is reassembled in this frame", HFILL }},
 
         { &hf_h223_al_reassembled_length,
-          { "Reassembled length", "h223.al.reassembled.length", FT_UINT32, BASE_DEC, NULL, 0x0,
+          { "Reassembled H.223 AL-PDU length", "h223.al.reassembled.length", FT_UINT32, BASE_DEC, NULL, 0x0,
             "The total length of the reassembled payload", HFILL }},
 
         /* h223-als */
@@ -1553,14 +1594,12 @@ void proto_register_h223 (void)
 
     proto_h223 =
         proto_register_protocol ("ITU-T Recommendation H.223", "H.223", "h223");
-    proto_h223_bitswapped =
-        proto_register_protocol ("Bitswapped ITU-T Recommendation H.223", "H.223 (Bitswapped)", "h223_bitswapped");
 
     proto_register_field_array (proto_h223, hf, array_length (hf));
     proto_register_subtree_array (ett, array_length (ett));
     register_dissector("h223", dissect_h223, proto_h223);
-    register_dissector("h223_bitswapped", dissect_h223_bitswapped, proto_h223_bitswapped);
-        
+    register_dissector("h223_bitswapped", dissect_h223_bitswapped, proto_h223);
+
     /* register our init routine to be called at the start of a capture,
        to clear out our hash tables etc */
     register_init_routine(&h223_init_protocol);
@@ -1579,7 +1618,7 @@ void proto_reg_handoff_h223(void)
     dissector_add_handle("tcp.port", h223);
     dissector_add_handle("tcp.port", h223_bitswapped);
     dissector_add_string("rtp_dyn_payload_type","CLEARMODE", h223_bitswapped);
-    dissector_add("iax2.dataformat", AST_DATAFORMAT_H223_H245, h223_bitswapped);
+    dissector_add_uint("iax2.dataformat", AST_DATAFORMAT_H223_H245, h223_bitswapped);
 }
 
 /*
@@ -1587,10 +1626,10 @@ void proto_reg_handoff_h223(void)
  *
  * Local Variables:
  * c-basic-offset: 4
- * tab-width: 4
+ * tab-width: 8
  * indent-tabs-mode: nil
  * End:
  *
- * ex: set shiftwidth=4 tabstop=4 expandtab
- * :indentSize=4:tabSize=4:noTabs=true:
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
  */