- if (!error)
- {
- frag[b].re_frame_len = cur_len;
- // Process the resassembled frame
- LOG(4, s, t, "MPPP: Process the reassembled frame, len=%d\n",cur_len);
- processmpframe(s, t, frag[b].reassembled_frame, frag[b].re_frame_len, 1);
- // Set reassembled frame length to zero after processing it
- frag[b].re_frame_len = 0;
- memset(frag[b].reassembled_frame, 0, sizeof(frag[b].reassembled_frame));
- }
+ // Set new Start sequence
+ this_fragmentation->start_index = begin_index;
+ this_fragmentation->start_seq = Mmin;
+ M_offset = 0;
+ // recalculate the fragment offset from the new begin seq in the bundle
+ frag_offset = (int) (seq_num - Mmin);
+ }
+
+ // 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: (COMES BEFORE) the next, seq:%d, begin_seq:%d, size_frag:%d, flags:%02X is LOST\n", seq_num, this_fragmentation->start_seq, l, flags);
+ 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\n", seq_num, this_fragmentation->start_seq);
+ 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:%02X is LOST\n",
+ this_frag->seq, frag_index, this_frag->flags);
+
+ this_frag->length = l;
+ this_frag->sid = s;
+ this_frag->tid = t;
+ this_frag->flags = flags;
+ this_frag->seq = seq_num;
+ this_frag->jitteravg = sess_local[s].jitteravg;
+ 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);
+
+ //next frag index
+ frag_index_next = (frag_index + 1) & MAXFRAGNUM_MASK;
+ //previous frag index
+ frag_index_prev = (frag_index - 1) & MAXFRAGNUM_MASK;
+ // next seq
+ seq_num_next = seq_num + 1;
+ // previous seq
+ seq_num_prev = seq_num - 1;
+
+ // Clean the buffer and log the lost fragments
+ if ((frag_index_next != this_fragmentation->start_index) && this_fragmentation->fragment[frag_index_next].length)
+ {
+ // check if the next frag is a lost fragment
+ if (this_fragmentation->fragment[frag_index_next].seq != seq_num_next)
+ {
+ // This fragment is lost, It was around the buffer and it was never completed the packet.
+ LOG(3, this_fragmentation->fragment[frag_index_next].sid, this_fragmentation->fragment[frag_index_next].tid,
+ "MPPP: (NEXT) seq_num:%d frag_index:%d flags:%02X is LOST\n",
+ this_fragmentation->fragment[frag_index_next].seq, frag_index_next,
+ this_fragmentation->fragment[frag_index_next].flags);
+ // this frag is lost
+ this_fragmentation->fragment[frag_index_next].length = 0;
+ this_fragmentation->fragment[frag_index_next].flags = 0;
+
+ if (begin_frame && (!end_frame)) return; // assembling frame failed