This is our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Hi,

Iam struggling withe reassembly for 1 week.

could you see what is wrong in my code?

            guint8 flag,pf,stype,sflag,flag_sel,num_sel,i;

            guint16 ns,nr;

            guint32 rem_length;

            guint8 save_fragmented;

            const guint32 mte_seqid=0;

            const void *data = NULL;

            gboolean more_frags=TRUE;

            proto_item *frag_tree_item;

           flag = (tvb_get_guint8(next_tvb, offset_payload) & 0x80) >>7 ;   // Bit 8  to check i pdu /s pdu or sseg pdu

                                if (flag == 0x00){ // flag "0" is for i-pdu

                                poll = (tvb_get_guint8(next_tvb, offset_payload) & 0x40) >>6 ; // Bit 7 pf
                                ns = (tvb_get_ntohs(next_tvb, offset_payload) & 0x3ff0) >>4 ; // 10 Bits are ns
                                offset_payload +=1;
                                nr= (tvb_get_ntohs(next_tvb, offset_payload) & 0x0ffc) >>2 ; // 10 bits are nr
                                offset_payload +=1;
                                stype = (tvb_get_guint8(next_tvb, offset_payload) & 0x03) ; // 2 bits LSB are Stype
                                offset_payload -=2;

            FT_connPDU_item = proto_tree_add_text(tree, next_tvb, offset_payload, sdu_length, "BCnPDU (Formatted) : Information, I flag = 0x%02x, Pf = 0x%02x, Ns = 0x%02x, Nr = 0x%02x ", iflag,pf,ns,nr );

            FT_connPDU_tree = proto_item_add_subtree(FT_connPDU_item, ett_FT_BCnPDU);

            proto_tree_add_text(FT_connPDU_tree, next_tvb, offset_payload, 1, " sdu_length: %d", sdu_length);

            proto_tree_add_text(FT_connPDU_tree, next_tvb, offset_payload, 1, "flag : 0x%02x (%s)", iflag,val_to_str(iflag,true_false_vals,"%s"));

           proto_tree_add_text(FT_connPDU_tree, next_tvb, offset_payload, 1, "Pf : 0x%02x (%d)", pf,pf);

          proto_tree_add_text(FT_connPDU_tree, next_tvb, offset_payload, 2, "Ns : 0x%02x (%d)", ns,ns);

          offset_payload +=1;
          sdu_length-=1;

           proto_tree_add_text(FT_connPDU_tree, next_tvb, offset_payload, 2, "Nr : 0x%02x (%d)", nr,nr);

         offset_payload +=1;

         sdu_length-=1;

         proto_tree_add_text(FT_connPDU_tree, next_tvb, offset_payload, 1, "BConnSegType : 0x%02x (%s)", stype,val_to_str(stype,BCn_Seg_Type_vals,"%s"));

        offset_payload +=1;

       sdu_length-=1;

       switch (stype){

  case 0x00: // Continuation of Message

                                        sdu_length+=1;
rem_length = (guint32) sdu_length;

                                        proto_tree_add_text(FT_connPDU_tree, next_tvb, offset_payload, rem_length , "PDU data : %d", rem_length);

offset_payload +=rem_length;
                                        sdu_length-=rem_length;

                                        proto_tree_add_text(FT_connPDU_tree, next_tvb, offset_payload, 1 , "sdu_length: %d", sdu_length);

                                        save_fragmented = pinfo->fragmented;
                                        pinfo->fragmented = TRUE;

      mte_frag_msg = fragment_add_seq_next(&mte_reassembly_table,next_tvb, offset_payload, pinfo, mte_seqid, NULL, rem_length, more_frags);
                                        pinfo->fragmented = save_fragmented;
                                            col_set_str(pinfo->cinfo, COL_INFO, " mte segment of a reassembled PDU");

                                                if (sdu_length>0){

                                        SIG_PDU(next_tvb, pinfo, tree);

                                                    }

break;

       case 0x01: // Beginning of Message

                                            BCnPDU_stype_item = proto_tree_add_text(FT_connPDU_tree, next_tvb, offset_payload, 1, "%s",val_to_str(stype,BCn_Seg_Type_vals,"%s"));
                                            BCnPDU_stype_tree = proto_item_add_subtree(BCnPDU_stype_item, ett_BCnPDU_stype);

                                            BCnPDU_bom_item = proto_tree_add_text(BCnPDU_stype_tree, next_tvb, offset_payload, 1, "MACSAPFLAGS");
                                            BCnPDU_bom_tree = proto_item_add_subtree(BCnPDU_bom_item, ett_BCnPDU_bom);

                                            temp_val = (tvb_get_guint8(next_tvb, offset_payload) & 0x80) >>7 ; // Bit 8 - Flow Control
                                            proto_tree_add_text(BCnPDU_bom_tree, next_tvb, offset_payload, 1, "Flow Control : 0x%02x (%s)", temp_val,val_to_str(temp_val, true_false_vals,"%s"));
                                            temp_val = (tvb_get_guint8(next_tvb, offset_payload) & 0x40) >>6 ; // Bit 7 - Reserved l
                                            proto_tree_add_text(BCnPDU_bom_tree, next_tvb, offset_payload, 1, "Reserved l : 0x%02x (%d)", temp_val,temp_val);
                                            temp_val = (tvb_get_guint8(next_tvb, offset_payload) & 0x20) >>5 ; // Bit 6 - Expedited
                                            proto_tree_add_text(BCnPDU_bom_tree, next_tvb, offset_payload, 1, "Expedited : 0x%02x (%s)", temp_val,val_to_str(temp_val, true_false_vals,"%s"));
                                            temp_val = (tvb_get_guint8(next_tvb, offset_payload) & 0x10) >>4 ; // Bit 5 - OAM PDU Flag
                                            proto_tree_add_text(BCnPDU_bom_tree, next_tvb, offset_payload, 1, "OAM PDU Flag : 0x%02x (%s)", temp_val,val_to_str(temp_val, true_false_vals,"%s"));
                                            temp_val = (tvb_get_guint8(next_tvb, offset_payload) & 0x08) >>3 ; // Bit 4 - Reserved 2
                                            proto_tree_add_text(BCnPDU_bom_tree, next_tvb, offset_payload, 1, "Reserved 2 : 0x%02x (%d)", temp_val,temp_val);
                                            pl_val = (tvb_get_ntohs(next_tvb, offset_payload) & 0x07ff); // PDU Length - 11 Bits 
                                        proto_tree_add_text(BCnPDU_bom_tree, next_tvb, offset_payload, 2, "PDU Length : 0x%02x (%d)", pl_val,pl_val);
                                            pl_val = (guint32)pl_val;
                                            fragment_set_tot_len(&mte_reassembly_table, pinfo,mte_seqid, NULL, pl_val);
                                            offset_payload+=2;
                                            sdu_length+=2;
                                        proto_tree_add_text(BCnPDU_bom_tree, next_tvb, offset_payload, 1, " sdu_length: %d", sdu_length);
                                            rem_length= (guint32) tvb_length_remaining(next_tvb, offset_payload);
                                            rem_length-=2;
                                        if (rem_length >= pl_val){
                                        rem_length-=2;
                                    proto_tree_add_text(BCnPDU_bom_tree, next_tvb, offset_payload, rem_length, "PDU data  : %d ", rem_length);
                                            offset_payload+=sdu_length;
                                                } else {
                                                                                    proto_tree_add_text(BCnPDU_bom_tree, next_tvb, offset_payload, rem_length, "PDU data  : %d ", rem_length);
                                            offset_payload+=rem_length;
    }

                                            save_fragmented = pinfo->fragmented;
                                        pinfo->fragmented = TRUE;

                                        mte_frag_msg = fragment_add_seq_next(&mte_reassembly_table, next_tvb, offset_payload, pinfo, mte_seqid, NULL, rem_length, more_frags);

 pinfo->fragmented = save_fragmented;

                                        col_set_str(pinfo->cinfo, COL_INFO, " mte segment of a reassembled PDU ");

                                        pinfo->fragmented = save_fragmented;

                                        break;

 case 0x02: // End of Message

                                        sdu_length+=2;
                                        more_frags=FALSE;

                                        rem_length = (guint32) sdu_length;
                                        rem_length-=2;

                                        proto_tree_add_text(FT_connPDU_tree, next_tvb, offset_payload, rem_length , "PDU data : %d", rem_length);                                   offset_payload +=rem_length;
                                    disable_CRC=1;                              save_fragmented = pinfo->fragmented;                        
     pinfo->fragmented = TRUE;      
                                        mte_frag_msg = fragment_add_seq_next(&mte_reassembly_table,next_tvb, offset_payload, pinfo, mte_seqid, NULL, rem_length, more_frags);                               mte_frag_msg = fragment_get_reassembled_id(&mte_reassembly_table, pinfo, mte_seqid);

    //mte_tvb = tvb_new_chain(next_tvb, mte_frag_msg->tvb_data);
                                        mte_tvb = process_reassembled_data(next_tvb, offset_payload, pinfo, "mte Reassembled PDU", mte_frag_msg, &mte_frag_items, NULL, tree );

if (mte_tvb) { /* Reassembled */
                                                try_tvb=mte_tvb;
         col_append_str(pinfo->cinfo, COL_INFO,"(Message reassembled) ");
    add_new_data_source(pinfo, try_tvb, "Reassembled mte");
                                                show_fragment_tree(mte_frag_msg, &mte_frag_items,tree, pinfo, try_tvb, &frag_tree_item);        
                                                    } else { /* Not last packet of reassembled message */

               col_append_str(pinfo->cinfo, COL_INFO,"(Message fragment) ");
                                                                }

                                                      pinfo->fragmented = save_fragmented;

                    if (mte_tvb){
        SIG_PDU(mte_tvb, pinfo, tree);
               } else {
                                            SIG_PDU(next_tvb, pinfo, tree);                 offset_payload+=sdu_length;

                                                                break;

asked 02 Dec '14, 22:26

umar's gravatar image

umar
26222427
accept rate: 0%

edited 02 Dec '14, 23:08

Some one please help!!

(02 Dec '14, 22:26) umar

Some one please help!!

(04 Dec '14, 00:23) umar
Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×78
×29
×3

question asked: 02 Dec '14, 22:26

question was seen: 2,141 times

last updated: 04 Dec '14, 00:23

p​o​w​e​r​e​d by O​S​Q​A