- 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;
- }
-
- if (seq_num-offset < 0 || seq_num-offset > MAXFRAGNUM)
- {
- LOG(2, s, t, "ERROR: Index out of range fn(last):%d, bundle:%d\n",fn,b);
- return;
- }
- /////////////////////////////////////////////////////
- cur_len = 4; // This is set to 4 to leave 4 bytes for function processipin
- for (fn = bundle[b].seq_num_m - offset; fn < seq_num - offset; fn++)
- {
- if (!frag[b].fragment[fn].length)
- {
- LOG(4, s, t, "MPPP: Found lost fragment while reassembling frame %d in (%d,%d)\n",fn, bundle[b].seq_num_m-offset, seq_num-offset);
- error = 1;
- break;
- }
-
- if (cur_len + frag[b].fragment[fn].length > MAXETHER)
- {
- LOG(2, s, t, "MPPP: ERROR: very long frame after assembling %d\n", frag[b].fragment[fn].length+cur_len);
- error = 1;
- break;
- }
-
- memcpy(frag[b].reassembled_frame+cur_len, frag[b].fragment[fn].data, frag[b].fragment[fn].length);
- cur_len += frag[b].fragment[fn].length;
- frag[b].fragment[fn].length = 0; // Indicates that this fragment has been consumed
- // This is usefull for compression
- memset(frag[b].fragment[fn].data, 0, sizeof(frag[b].fragment[fn].data));
- }
-
- 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));
- }