- uint32_t fn = bundle[b].seq_num_m - offset;
- uint16_t cur_len;
- bundle[b].pending_frag = 0;
- // Check for array indexes
- if (fn < 0 || fn > MAXFRAGNUM)
- {
- LOG(2, s, t, "ERROR: Index out of range fn:%d, bundle:%d\n",fn,b);
- return;
- }
+ uint32_t s_seq = sess_local[(this_bundle->members[i])].last_seq;
+ if (s_seq < min)
+ min = s_seq;
+ }
+ this_fragmentation->M = min;
+ }
+
+ LOG(4, s, t, "MPPP: Setting M to %d\n", this_fragmentation->M);
+ //calculate M's offset from the begin seq in the bundle
+ M_offset = (this_fragmentation->M + this_bundle->max_seq - this_fragmentation->start_seq) & (this_bundle->max_seq-1);
+
+ //caculate M's index in the fragment array
+ M_index = (M_offset + this_fragmentation->start_index) & MAXFRAGNUM_MASK;
+
+ //caculate received fragment's index in the fragment array
+ frag_index = (frag_offset + this_fragmentation->start_index) & MAXFRAGNUM_MASK;
+
+ //frame with a single fragment
+ if (begin_frame && end_frame)
+ {
+ // process and reset fragmentation
+ LOG(4, s, t, "MPPP: Both bits are set (Begin and End).\n");
+ this_fragmentation->fragment[frag_index].length = l;
+ this_fragmentation->fragment[frag_index].sid = s;
+ this_fragmentation->fragment[frag_index].flags = flags;
+ this_fragmentation->fragment[frag_index].seq = seq_num;
+ this_fragmentation->re_frame_begin_index = frag_index;
+ this_fragmentation->re_frame_end_index = frag_index;
+ processmpframe(s, t, p, l, 0);
+ this_fragmentation->fragment[frag_index].length = 0;
+ this_fragmentation->fragment[frag_index].flags = 0;
+ end_index = frag_index;
+ }
+ else
+ {
+ // insert the frame in it's place
+ fragmentt *this_frag = &this_fragmentation->fragment[frag_index];
+ this_frag->length = l;
+ this_frag->sid = s;
+ this_frag->flags = flags;
+ this_frag->seq = seq_num;
+ memcpy(this_frag->data, p, l);
+
+ // try to assemble the frame that has the received fragment as a member
+ // get the beginning of this frame
+ begin_index = end_index = frag_index;
+ while (this_fragmentation->fragment[begin_index].length)
+ {
+ if (this_fragmentation->fragment[begin_index].flags & MP_BEGIN)
+ break;
+ begin_index = (begin_index ? (begin_index -1) : (MAXFRAGNUM -1));
+ }