+ if (b_seq == this_fragmentation->fragment[begin_index].seq)
+ {
+ if (this_fragmentation->fragment[begin_index].flags & MP_BEGIN)
+ {
+ int isfoundE = 0;
+ // Adjust the new start sequence and start index
+ this_fragmentation->start_index = begin_index;
+ this_fragmentation->start_seq = b_seq;
+ // Begin Sequence found, now try to found the End Sequence to complete the frame
+ end_index = begin_index;
+ while (b_seq < Mmin)
+ {
+ if (this_fragmentation->fragment[end_index].length)
+ {
+ if (b_seq == this_fragmentation->fragment[end_index].seq)
+ {
+ if (this_fragmentation->fragment[end_index].flags & MP_END)
+ {
+ // The End sequence was found and the frame is complete
+ isfoundE = 1;
+ break;
+ }
+ }
+ else
+ {
+ // This fragment is lost, it was never completed the packet.
+ LOG(3, this_fragmentation->fragment[end_index].sid, this_fragmentation->fragment[end_index].tid,
+ "MPPP: (FIND END) seq_num:%d frag_index:%d flags:%02X is LOST\n",
+ this_fragmentation->fragment[end_index].seq, begin_index,
+ this_fragmentation->fragment[end_index].flags);
+ // this frag is lost
+ this_fragmentation->fragment[end_index].length = 0;
+ this_fragmentation->fragment[end_index].flags = 0;
+ // This frame is not complete find the next Begin
+ break;
+ }
+ }
+ else
+ {
+ // This frame is not complete find the next Begin if exist
+ break;
+ }
+ end_index = (end_index +1) & MAXFRAGNUM_MASK;
+ b_seq++;
+ }
+
+ if (isfoundE)
+ // The End sequence was found and the frame is complete
+ break;
+ else
+ // find the next Begin
+ begin_index = end_index;
+ }
+ }
+ else
+ {
+ // This fragment is lost, it was never completed the packet.
+ LOG(3, this_fragmentation->fragment[begin_index].sid, this_fragmentation->fragment[begin_index].tid,
+ "MPPP: (FIND BEGIN) seq_num:%d frag_index:%d flags:%02X is LOST\n",
+ this_fragmentation->fragment[begin_index].seq, begin_index,
+ this_fragmentation->fragment[begin_index].flags);
+ // this frag is lost
+ this_fragmentation->fragment[begin_index].length = 0;
+ this_fragmentation->fragment[begin_index].flags = 0;
+ }
+ }
+ begin_index = (begin_index +1) & MAXFRAGNUM_MASK;
+ b_seq++;
+ }
+
+assembling_frame:
+ // try to assemble the frame that has the received fragment as a member
+ // get the beginning of this frame
+ begin_index = end_index = this_fragmentation->start_index;
+ if (this_fragmentation->fragment[begin_index].length)
+ {
+ if (!(this_fragmentation->fragment[begin_index].flags & MP_BEGIN))
+ {
+ LOG(3, this_fragmentation->fragment[begin_index].sid, this_fragmentation->fragment[begin_index].tid,
+ "MPPP: (NOT BEGIN) seq_num:%d frag_index:%d flags:%02X\n",
+ this_fragmentation->fragment[begin_index].seq, begin_index,
+ this_fragmentation->fragment[begin_index].flags);
+ // should occur only after an "M_Offset out of range"
+ // The start sequence must be a begin sequence
+ this_fragmentation->start_index = (begin_index +1) & MAXFRAGNUM_MASK;
+ this_fragmentation->start_seq++;
+ return; // assembling frame failed