+ }
+ }
+ else if ((this_fragmentation->fragment[start_index].length) &&
+ (!(this_fragmentation->fragment[start_index].flags & MP_BEGIN)))
+ {
+ uint32_t f_seq = this_fragmentation->start_seq;
+ end_index = start_index;
+ // Find the Begin sequence
+ while (this_fragmentation->fragment[end_index].length)
+ {
+ if (f_seq == this_fragmentation->fragment[end_index].seq)
+ {
+ if (this_fragmentation->fragment[end_index].flags & MP_BEGIN)
+ 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: (FIND2) seq_num:%d frag_index:%d flags:%d is LOST\n",
+ this_fragmentation->fragment[end_index].seq, end_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;
+ break;
+ }
+ end_index = (end_index +1) & MAXFRAGNUM_MASK;
+ f_seq++;
+ }
+
+ // Set new Start sequence
+ this_fragmentation->start_index = end_index;
+ this_fragmentation->start_seq = f_seq;
+ // recalculate the fragment offset from the new begin seq in the bundle
+ frag_offset = (int) (seq_num - f_seq);
+ }
+
+ // discard this fragment if the packet comes before the start sequence
+ if (frag_offset < 0)
+ {
+ // this packet comes before the next
+ LOG(3, s, t, "MPPP: packet comes before the next, seq:%d, begin_seq:%d, size frag:%d\n", seq_num, this_fragmentation->start_seq, l);
+ return;
+ }
+
+ // discard if frag_offset is bigger that the fragmentation buffer size
+ if (frag_offset >= MAXFRAGNUM)
+ {
+ // frag_offset is bigger that the fragmentation buffer size
+ LOG(3, s, t, "MPPP: Index out of range, seq:%d, begin_seq:%d, size frag:%d\n", seq_num, this_fragmentation->start_seq, l);
+ return;
+ }
+
+ //caculate received fragment's index in the fragment array
+ frag_index = (frag_offset + this_fragmentation->start_index) & MAXFRAGNUM_MASK;
+
+ {
+ // insert the frame in it's place
+ fragmentt *this_frag = &this_fragmentation->fragment[frag_index];
+
+ if (this_frag->length > 0)
+ // This fragment is lost, It was around the buffer and it was never completed the packet.
+ LOG(3, this_frag->sid, this_frag->tid, "MPPP: (INSERT) seq_num:%d frag_index:%d flags:%d is LOST\n",
+ this_frag->seq, frag_index, this_frag->flags);
+
+ this_frag->length = l;
+ this_frag->sid = s;
+ this_frag->flags = flags;
+ this_frag->seq = seq_num;
+ memcpy(this_frag->data, p, l);
+
+ LOG(4, s, t, "MPPP: seq_num:%d frag_index:%d INSERTED flags: %02X\n", seq_num, frag_index, flags);