rlc_am_rx_list.c 58.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22
23
#define RLC_AM_MODULE 1
#define RLC_AM_RX_LIST_C 1
24
25
26
//-----------------------------------------------------------------------------
#include "platform_types.h"
//-----------------------------------------------------------------------------
27
#include "assertions.h"
28
29
30
31
32
33
#include "list.h"
#include "rlc_am.h"
#include "LAYER2/MAC/extern.h"
#include "UTIL/LOG/log.h"


fnabet's avatar
fnabet committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
boolean_t rlc_am_rx_check_vr_reassemble(
		  const protocol_ctxt_t* const ctxt_pP,
		  const rlc_am_entity_t* const rlc_pP)
{
	mem_block_t*       cursor_p                    = NULL;
	cursor_p = rlc_pP->receiver_buffer.head;
	boolean_t reassemble = FALSE;

	if (cursor_p != NULL) {

		rlc_am_pdu_info_t* pdu_info_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
		rlc_usn_t sn_ref = pdu_info_p->sn;
		if (sn_ref != rlc_pP->vr_r) {
			reassemble = TRUE;
		}

		/* jump up to vrR */
		while ((RLC_AM_DIFF_SN(pdu_info_p->sn,sn_ref) < RLC_AM_DIFF_SN(rlc_pP->vr_r,sn_ref)) && (cursor_p != NULL)) {
			if ((pdu_info_p->rf) && (((rlc_am_rx_pdu_management_t*)(cursor_p->data))->segment_reassembled == RLC_AM_RX_PDU_SEGMENT_REASSEMBLE_NO)) {
				((rlc_am_rx_pdu_management_t*)(cursor_p->data))->segment_reassembled = RLC_AM_RX_PDU_SEGMENT_REASSEMBLE_PENDING;
			}
			cursor_p = cursor_p->next;
			if (cursor_p != NULL) {
				pdu_info_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
			}
		}

		if ((cursor_p != NULL) && (pdu_info_p->sn == rlc_pP->vr_r)) {
			/* case vrR = partially received */
			rlc_am_rx_pdu_management_t * pdu_cursor_mgnt_p = (rlc_am_rx_pdu_management_t *) (cursor_p->data);
			sdu_size_t          next_waited_so = 0;
			AssertFatal(pdu_cursor_mgnt_p->all_segments_received == 0,"AM Rx Check Reassembly vr=%d should be partly received LCID=%d\n",
					rlc_pP->vr_r,rlc_pP->channel_id);
			while ((cursor_p != NULL) && (pdu_info_p->sn == rlc_pP->vr_r) && (pdu_info_p->so == next_waited_so)) {
				if (pdu_cursor_mgnt_p->segment_reassembled == RLC_AM_RX_PDU_SEGMENT_REASSEMBLE_NO) {
					pdu_cursor_mgnt_p->segment_reassembled = RLC_AM_RX_PDU_SEGMENT_REASSEMBLE_PENDING;
					reassemble = TRUE;
				}
				next_waited_so += pdu_info_p->payload_size;
				cursor_p = cursor_p->next;
				if (cursor_p != NULL) {
					pdu_cursor_mgnt_p = (rlc_am_rx_pdu_management_t *) (cursor_p->data);
					pdu_info_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
				}
			}
		}

	}
	return reassemble;
}

mem_block_t * create_new_segment_from_pdu(
		mem_block_t* const tb_pP,
		uint16_t so_offset, /* offset from the data part of the PDU to copy */
		sdu_size_t	data_length_to_copy)
{
	rlc_am_pdu_info_t* pdu_rx_info_p	= &((rlc_am_rx_pdu_management_t*)(tb_pP->data))->pdu_info;
	rlc_am_pdu_info_t* pdu_new_segment_info_p = NULL;
	mem_block_t *	new_segment_p		= NULL;
	int16_t  new_li_list[RLC_AM_MAX_SDU_IN_PDU];
	int16_t header_size = 0;
	uint8_t	num_li = 0;
	boolean_t fi_start, fi_end, lsf;

	/* Init some PDU Segment header fixed parameters */
	fi_start = !((pdu_rx_info_p->fi & 0x2) >> 1);
	fi_end = !(pdu_rx_info_p->fi & 0x1);
	lsf = ((pdu_rx_info_p->lsf == 1) || (pdu_rx_info_p->rf == 0));

	/* Handle NO Li case fist */
	if (pdu_rx_info_p->num_li == 0) {

		header_size = RLC_AM_PDU_SEGMENT_HEADER_MIN_SIZE;

		if (so_offset) {
			fi_start = FALSE;
		}
		if (so_offset + data_length_to_copy != pdu_rx_info_p->payload_size) {
			fi_end = FALSE;
			lsf = FALSE;
		}
	} // end no LI in original segment
	else {

		uint8_t	li_index = 0;
		uint16_t li_sum = 0;
		num_li = pdu_rx_info_p->num_li;

		/* set LSF to false if we know that end of the original segment will not be copied */
		if (so_offset + data_length_to_copy != pdu_rx_info_p->payload_size) {
			lsf = FALSE;
		}

		/* catch the first LI containing so_offset */
		while ((li_index < pdu_rx_info_p->num_li) && (li_sum + pdu_rx_info_p->li_list[li_index] <= so_offset)) {
			li_sum += pdu_rx_info_p->li_list[li_index];
			num_li --;
			li_index ++;
		}

		/* set FI start if so_offset = LI sum and at least one LI have been read  */
		if ((li_index) && (so_offset == li_sum)) {
			fi_start = TRUE;
		}

		/* Fill LI until the end */
		if (num_li) {
			sdu_size_t	remaining_size = data_length_to_copy;
			uint8_t	j = 0;
			new_li_list[0] = li_sum + pdu_rx_info_p->li_list[li_index] - so_offset;
			if (data_length_to_copy <= new_li_list[0]) {
				num_li = 0;
			}
			else {
				remaining_size -= new_li_list[0];
				j++;
				li_index ++;
				while ((li_index < pdu_rx_info_p->num_li) && (remaining_size >= pdu_rx_info_p->li_list[li_index])) {
					remaining_size -= pdu_rx_info_p->li_list[li_index];
					new_li_list[j] = pdu_rx_info_p->li_list[li_index];
					j++;
					li_index ++;
				}

				/* update number of LI in the segment */
				num_li = j;
				/* set FI End if remaining size = 0  */
				if (remaining_size == 0) {
					fi_end = TRUE;
				}
			}
		}

		/* compute header size */
		header_size = RLC_AM_PDU_SEGMENT_HEADER_SIZE(num_li);

	} // end LIs in original segment

	/* Allocate new buffer */
	new_segment_p = get_free_mem_block(sizeof (mac_rlc_max_rx_header_size_t) + header_size + data_length_to_copy, __func__);

	/* Fill PDU  Segment Infos and Header */
	if (new_segment_p != NULL) {
		pdu_new_segment_info_p	= &((rlc_am_rx_pdu_management_t*)(new_segment_p->data))->pdu_info;
		rlc_am_rx_pdu_management_t * pdu_cursor_mgnt_p = (rlc_am_rx_pdu_management_t *) (new_segment_p->data);
		uint8_t   *pdu_segment_header_p        	= &(new_segment_p->data[sizeof (mac_rlc_max_rx_header_size_t)]);

		pdu_cursor_mgnt_p->segment_reassembled	= RLC_AM_RX_PDU_SEGMENT_REASSEMBLE_NO; //to be updated after if SN = vrR

		pdu_new_segment_info_p->d_c 			= pdu_rx_info_p->d_c;
		pdu_new_segment_info_p->sn				= pdu_rx_info_p->sn;
		pdu_new_segment_info_p->p				= pdu_rx_info_p->p;
		pdu_new_segment_info_p->rf				= 1;
		pdu_new_segment_info_p->fi				= (((fi_start ? 0: 1) << 1) | (fi_end ? 0: 1));
		pdu_new_segment_info_p->e				= (num_li ? 1: 0);
		pdu_new_segment_info_p->lsf				= (lsf ? 1: 0);
		pdu_new_segment_info_p->so				= pdu_rx_info_p->so + so_offset;
		pdu_new_segment_info_p->payload			= pdu_segment_header_p + header_size;
		pdu_new_segment_info_p->header_size 	= header_size;
		pdu_new_segment_info_p->payload_size	= data_length_to_copy;
		pdu_new_segment_info_p->hidden_size		= data_length_to_copy;
		for (int i=0; i < num_li; i++) {
			pdu_new_segment_info_p->li_list[i] = new_li_list[i];
			pdu_new_segment_info_p->hidden_size -= new_li_list[i];
		}

		/* Fill Header part in the buffer */
		/* Content is supposed to be init with 0 so with FIStart=FIEnd=TRUE */
		/* copy first two bytes from original: D/C + RF + FI + E+ SN*/
		memset(pdu_segment_header_p, 0, header_size);
		RLC_AM_PDU_SET_D_C(*pdu_segment_header_p);
		RLC_AM_PDU_SET_RF(*pdu_segment_header_p);
		if (pdu_new_segment_info_p->p) {
			RLC_AM_PDU_SET_POLL(*pdu_segment_header_p);
		}
		/* Change FI */
		if (!fi_start)
		{
			// Set to not starting
			(*pdu_segment_header_p) |= (1 << (RLC_AM_PDU_FI_OFFSET + 1));

		}
		if (!fi_end)
		{
			// Set to not starting
			(*pdu_segment_header_p) |= (1 << (RLC_AM_PDU_FI_OFFSET));

		}
		/* E */
		if (pdu_new_segment_info_p->e) {
			RLC_AM_PDU_SET_E(*pdu_segment_header_p);
		}
		/* SN */
		(*pdu_segment_header_p) |= (pdu_new_segment_info_p->sn >> 8) ;
		*(pdu_segment_header_p + 1) = (pdu_new_segment_info_p->sn & 0xFF);

		pdu_segment_header_p += 2;

		/* Last Segment Flag (LSF) */
		if (lsf)
		{
			RLC_AM_PDU_SET_LSF(*pdu_segment_header_p);
		}
		/* Store SO bytes */
		* (pdu_segment_header_p )  		= (pdu_new_segment_info_p->so >> 8) & 0xFF;
		* (pdu_segment_header_p + 1)  	= pdu_new_segment_info_p->so & 0xFF;

		if (num_li) {
			uint16_t index = 0;
			uint16_t temp = 0;
			uint8_t li_bit_offset = 4; /* toggle between 0 and 4 */
			uint8_t li_jump_offset = 1; /* toggle between 1 and 2 */

			/* loop on nb of LIs */
			pdu_segment_header_p += 2;

			while (index < num_li)
			{
				/* Set E bit for next LI if present */
				if (index < num_li - 1)
					RLC_SET_BIT(temp,li_bit_offset + RLC_AM_LI_BITS);
				/* Set LI */
				RLC_AM_PDU_SET_LI(temp,new_li_list[index],li_bit_offset);
				*pdu_segment_header_p = temp >> 8;
				*(pdu_segment_header_p + 1) = temp & 0xFF;
				pdu_segment_header_p += li_jump_offset;
				li_bit_offset ^= 0x4;
				li_jump_offset ^= 0x3;

				temp = ((*pdu_segment_header_p) << 8) | (*(pdu_segment_header_p + 1));
				index ++;
			}
		}

		/* copy data part */
		/* Fill mem_block contexts */
		((struct mac_tb_ind *) (new_segment_p->data))->first_bit = 0;
		((struct mac_tb_ind *) (new_segment_p->data))->data_ptr = (uint8_t*)&new_segment_p->data[sizeof (mac_rlc_max_rx_header_size_t)];
		((struct mac_tb_ind *) (new_segment_p->data))->size = data_length_to_copy + header_size;
		memcpy(pdu_new_segment_info_p->payload,pdu_rx_info_p->payload + so_offset,data_length_to_copy);
	}

	return new_segment_p;
}

rlc_am_rx_pdu_status_t rlc_am_rx_list_handle_pdu_segment(
		const protocol_ctxt_t* const  ctxt_pP,
		rlc_am_entity_t* const rlc_pP,
		mem_block_t* const tb_pP)
{
	  rlc_am_pdu_info_t* pdu_rx_info_p                  = &((rlc_am_rx_pdu_management_t*)(tb_pP->data))->pdu_info;
	  rlc_am_pdu_info_t* pdu_info_cursor_p           = NULL;
	  rlc_am_pdu_info_t* pdu_info_previous_cursor_p  = NULL;
	  mem_block_t*       cursor_p                    = NULL;
	  mem_block_t*       previous_cursor_p           = NULL;
	  mem_block_t*       next_cursor_p           	 = NULL;
	  cursor_p = rlc_pP->receiver_buffer.head;
	  boolean_t prev_segment_found = FALSE;
	  boolean_t next_segment_found = FALSE;
	  uint16_t so_start = 0;
	  uint16_t so_end = 0;
	  uint16_t so_start_segment = pdu_rx_info_p->so;
	  uint16_t so_end_segment = pdu_rx_info_p->so + pdu_rx_info_p->payload_size - 1;

	  /*****************************************************/
	  // 1) Find previous cursor to the PDU to insert
	  /*****************************************************/
	  previous_cursor_p = cursor_p;
	  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
	  pdu_info_previous_cursor_p = pdu_info_cursor_p;
	  while (cursor_p != NULL) {
		  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;

		  // Stop if Cursor SN >= Received SN
		  if (RLC_AM_DIFF_SN(pdu_info_cursor_p->sn,rlc_pP->vr_r) >= RLC_AM_DIFF_SN(pdu_rx_info_p->sn,rlc_pP->vr_r)) {
			  break;
		  }

          previous_cursor_p = cursor_p;
          pdu_info_previous_cursor_p = pdu_info_cursor_p;
          cursor_p = cursor_p->next;
	  }

	  /*****************************************************/
	  // 2) Store the received Segment
	  /*****************************************************/
	  // First case : cursor_p is NULL or its SN is different from the received one, it means the SN is received for the first time
	  // Insert PDU after previous_cursor_p
	  if ((cursor_p == NULL) || (pdu_info_cursor_p->sn != pdu_rx_info_p->sn)) {
323
324
325
326
327
328
329
330
331
332
333
334
335
336
        rlc_usn_t sn_prev = pdu_info_previous_cursor_p->sn;
          if (RLC_AM_DIFF_SN(sn_prev,rlc_pP->vr_r) < RLC_AM_DIFF_SN(pdu_rx_info_p->sn,rlc_pP->vr_r)) {
                LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[PROCESS RX PDU SEGMENT SN=%d] PDU SEGMENT INSERTED AFTER PDU SN=%d\n",
                            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),pdu_rx_info_p->sn,
                            sn_prev);
              list2_insert_after_element(tb_pP, previous_cursor_p, &rlc_pP->receiver_buffer);
          }
          else { /* SN of head of Rx PDU list is higher than received PDU SN */
              LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[PROCESS RX PDU SEGMENT SN=%d] PDU SEGMENT INSERTED BEFORE PDU SN=%d\n",
                            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),pdu_rx_info_p->sn,
                            pdu_info_cursor_p->sn);
              list2_insert_before_element(tb_pP, cursor_p, &rlc_pP->receiver_buffer);
          }

fnabet's avatar
fnabet committed
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
		  return RLC_AM_DATA_PDU_STATUS_OK;
	  }

	  // Filter out SN duplicate
	  rlc_am_rx_pdu_management_t * pdu_cursor_mgnt_p = (rlc_am_rx_pdu_management_t *) (cursor_p->data);

	  if (pdu_cursor_mgnt_p->all_segments_received) {
		  return RLC_AM_DATA_PDU_STATUS_AM_SEGMENT_DUPLICATE;
	  }

	  // Handle the remaining case : some PDU Segments already received for the same SN
	  // Try to insert the PDU according to its SO and SO+datalength of stored ones
	  // First find the segment just before the pdu to insert
	  while ((cursor_p != NULL) && (pdu_info_cursor_p->sn == pdu_rx_info_p->sn)) {
		  if (pdu_rx_info_p->so < pdu_info_cursor_p->so) {
			  prev_segment_found = TRUE;
			  break;
		  }

		  previous_cursor_p = cursor_p;
		  pdu_info_previous_cursor_p = pdu_info_cursor_p;
		  cursor_p = cursor_p->next;
		  if (cursor_p != NULL) {
			  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
		  }
	  }

	  /* if not previously inserted, it will be put after the last segment if it was not LSF*/
	  if ((!prev_segment_found) && (pdu_info_previous_cursor_p->lsf == 0)) {
		  prev_segment_found = TRUE;
		  next_segment_found = TRUE; // no more segment after the PDU
		  next_cursor_p = cursor_p;
		  AssertFatal(previous_cursor_p->next == next_cursor_p,"AM Rx PDU Segment store at the end error, SN=%d \n",pdu_rx_info_p->sn);
	  }
	  else
	  {
		  // the segment is duplicate
		  return RLC_AM_DATA_PDU_STATUS_AM_SEGMENT_DUPLICATE;
	  }



	  // Check that the Segment is not duplicate by scanning stored contiguous segments from previous_cursor_p
	  pdu_info_previous_cursor_p = &((rlc_am_rx_pdu_management_t*)(previous_cursor_p->data))->pdu_info;
	  if ((previous_cursor_p != NULL) && (pdu_info_previous_cursor_p->sn == pdu_rx_info_p->sn)) {
		  so_start = pdu_info_previous_cursor_p->so;
		  so_end = pdu_info_previous_cursor_p->so + pdu_info_previous_cursor_p->payload_size - 1;

		  cursor_p = previous_cursor_p;
		  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
		  cursor_p = cursor_p->next;
		  rlc_am_pdu_info_t* pdu_info_cursor_next_p = NULL;
		  if (cursor_p != NULL) {
			  pdu_info_cursor_next_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
		  }

		  while ((cursor_p != NULL) && (pdu_info_cursor_next_p->sn == pdu_rx_info_p->sn)
				  && (pdu_info_cursor_next_p->so == pdu_info_cursor_p->so + pdu_info_cursor_p->payload_size)) {
			  so_end += pdu_info_cursor_next_p->payload_size;
			  pdu_info_cursor_p = pdu_info_cursor_next_p;
			  cursor_p = cursor_p->next;
			  if (cursor_p != NULL) {
				  pdu_info_cursor_next_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
			  }
		  }

		  /* Now discard the PDU segment if it is within so_start so_end */
		  if ((so_start <= so_start_segment) && (so_end_segment <= so_end)) {
fnabet's avatar
fnabet committed
405
406
			  LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[PROCESS RX PDU SEGMENT]  DISCARD : DUPLICATE SEGMENT SN=%d\n",
			  	              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),pdu_rx_info_p->sn);
fnabet's avatar
fnabet committed
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
			  return RLC_AM_DATA_PDU_STATUS_AM_SEGMENT_DUPLICATE;
		  }
	  }


	  // Now found the segment which will be right after the pdu to insert
	  if (!next_segment_found) {

		  cursor_p = previous_cursor_p->next;
		  next_cursor_p = cursor_p;
		  if (next_cursor_p != NULL) {
			  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(next_cursor_p->data))->pdu_info;
		  }

		  // Discard embedded segments in the received PDU segment
		  while ((next_cursor_p != NULL) && (pdu_info_cursor_p->sn == pdu_rx_info_p->sn) &&
				  (pdu_rx_info_p->so + pdu_rx_info_p->payload_size >= pdu_info_cursor_p->so + pdu_info_cursor_p->payload_size)) {
			  /* Discard the segment */
			  cursor_p = next_cursor_p;
			  next_cursor_p = next_cursor_p->next;
			  list2_remove_element (cursor_p, &rlc_pP->receiver_buffer);
			  free_mem_block(cursor_p, __func__);

			  if (next_cursor_p != NULL) {
				  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(next_cursor_p->data))->pdu_info;
			  }
		  }
	  }

	  /* Now remove duplicate bytes */
	  // remove duplicate at the begining, only valid if the segment is to be inserted after a PDU segment of the same SN
	  pdu_info_previous_cursor_p = &((rlc_am_rx_pdu_management_t*)(previous_cursor_p->data))->pdu_info;
	  if (pdu_info_previous_cursor_p->sn == pdu_rx_info_p->sn) {
		  so_start_segment += (pdu_info_previous_cursor_p->so + pdu_info_previous_cursor_p->payload_size - pdu_rx_info_p->so);
	  }
	  // remove duplicate at the end
	  if (next_cursor_p != NULL) {
		  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(next_cursor_p->data))->pdu_info;

		  if ((pdu_info_cursor_p->sn == pdu_rx_info_p->sn) && (so_end_segment >= pdu_info_cursor_p->so)) {
			  so_end_segment = pdu_info_cursor_p->so - 1;
		  }
	  }

	  AssertFatal((so_start_segment <= so_end_segment) && (pdu_rx_info_p->so <= so_start_segment) &&
			  (so_end_segment <= pdu_rx_info_p->so + pdu_rx_info_p->payload_size - 1),
			  " AM RX PDU Segment Duplicate elimination error OldSOStart=%d OldSOEnd=%d newSOStart=%d newSOEnd =%d SN=%d\n",
			  pdu_rx_info_p->so,pdu_rx_info_p->so + pdu_rx_info_p->payload_size - 1,so_start_segment,so_end_segment,pdu_rx_info_p->sn);

	  /* Last step : Insertion */
	  /* If some duplicate bytes had been removed, build a new PDU segment */
	  if ((pdu_rx_info_p->so != so_start_segment) || (so_end_segment != pdu_rx_info_p->so + pdu_rx_info_p->payload_size - 1)) {

		  mem_block_t* trunc_segment = create_new_segment_from_pdu(tb_pP,so_start_segment - pdu_rx_info_p->so,so_end_segment - so_start_segment + 1);
		  if (trunc_segment != NULL) {
fnabet's avatar
fnabet committed
462
463
464
			  LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[PROCESS RX PDU SEGMENT]  CREATE SEGMENT FROM SEGMENT OFFSET=%d DATA LENGTH=%d SN=%d\n",
			  	              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),so_start_segment - pdu_rx_info_p->so,so_end_segment - so_start_segment + 1,pdu_rx_info_p->sn);

fnabet's avatar
fnabet committed
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
			  list2_insert_after_element(trunc_segment, previous_cursor_p, &rlc_pP->receiver_buffer);
			  /* Free original PDU Segment */
			  free_mem_block(tb_pP, __func__);

			  return RLC_AM_DATA_PDU_STATUS_OK;
		  }
		  else {
			  return RLC_AM_DATA_PDU_STATUS_BUFFER_FULL;
		  }
	  }
	  else
	  {
		  list2_insert_after_element(tb_pP, previous_cursor_p, &rlc_pP->receiver_buffer);
		  return RLC_AM_DATA_PDU_STATUS_OK;
	  }
}

rlc_am_rx_pdu_status_t rlc_am_rx_list_handle_pdu(
		const protocol_ctxt_t* const  ctxt_pP,
		rlc_am_entity_t* const rlc_pP,
		mem_block_t* const tb_pP)
{
	  rlc_am_pdu_info_t* pdu_rx_info_p                  = &((rlc_am_rx_pdu_management_t*)(tb_pP->data))->pdu_info;
	  rlc_am_pdu_info_t* pdu_info_cursor_p           = NULL;
	  mem_block_t*       cursor_p                    = NULL;
	  mem_block_t*       previous_cursor_p           = NULL;
	  cursor_p = rlc_pP->receiver_buffer.head;
	  rlc_am_rx_pdu_status_t pdu_status = RLC_AM_DATA_PDU_STATUS_OK;
	  // it is assumed this pdu is in rx window


	  /*****************************************************/
	  // 1) Find previous cursor to the PDU to insert
	  /*****************************************************/
	  previous_cursor_p = cursor_p;
	  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
	  while (cursor_p != NULL) {
		  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;

		  // Stop if Cursor SN >= Received SN
		  if (RLC_AM_DIFF_SN(pdu_info_cursor_p->sn,rlc_pP->vr_r) >= RLC_AM_DIFF_SN(pdu_rx_info_p->sn,rlc_pP->vr_r)) {
			  break;
		  }

          previous_cursor_p = cursor_p;
          cursor_p = cursor_p->next;
	  }

	  /*****************************************************/
	  // 2) Insert PDU by removing byte duplicate if required
	  /*****************************************************/
	  // First case : cursor_p is NULL, it means the SN is received for the first time
	  // Insert PDU after previous_cursor_p
	  if ((cursor_p == NULL) || (pdu_info_cursor_p->sn != pdu_rx_info_p->sn)) {
519
520
521
522
523
524
525
526
527
528
529
530
531
532
	      rlc_usn_t sn_prev = ((rlc_am_rx_pdu_management_t*)(previous_cursor_p->data))->pdu_info.sn;
	      if (RLC_AM_DIFF_SN(sn_prev,rlc_pP->vr_r) < RLC_AM_DIFF_SN(pdu_rx_info_p->sn,rlc_pP->vr_r)) {
	            LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[PROCESS RX PDU SN=%d] PDU INSERTED AFTER PDU SN=%d\n",
	                        PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),pdu_rx_info_p->sn,
	                        ((rlc_am_rx_pdu_management_t*)(previous_cursor_p->data))->pdu_info.sn);
	          list2_insert_after_element(tb_pP, previous_cursor_p, &rlc_pP->receiver_buffer);
	      }
	      else { /* SN of head of Rx PDU list is higher than received PDU SN */
              LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[PROCESS RX PDU SN=%d] PDU INSERTED BEFORE PDU SN=%d\n",
                            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),pdu_rx_info_p->sn,
                            pdu_info_cursor_p->sn);
	          list2_insert_before_element(tb_pP, cursor_p, &rlc_pP->receiver_buffer);
	      }

fnabet's avatar
fnabet committed
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
		  return pdu_status;
	  }

	  // Filter out SN duplicate
	  // SN of received PDU has already data stored
	  rlc_am_rx_pdu_management_t * pdu_cursor_mgnt_p = (rlc_am_rx_pdu_management_t *) (cursor_p->data);

	  if (pdu_cursor_mgnt_p->all_segments_received) {
		  return RLC_AM_DATA_PDU_STATUS_SN_DUPLICATE;
	  }

	  /* check if the received PDU is equal to vrR */
	  if ((pdu_rx_info_p->sn != rlc_pP->vr_r) || (pdu_info_cursor_p->so != 0)) {
		  /* The full received PDU can replace the allready received PDU Segments. */
		  /* clean them and append this PDU */
		  mem_block_t*       cursor_next_p = cursor_p;
		  while (cursor_next_p) {
			  cursor_p = cursor_next_p;
			  cursor_next_p = cursor_next_p->next;
			  list2_remove_element (cursor_p, &rlc_pP->receiver_buffer);
			  free_mem_block(cursor_p, __func__);
			  if (cursor_next_p != NULL) {
				  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_next_p->data))->pdu_info;
				  if (pdu_info_cursor_p->sn != pdu_rx_info_p->sn) {
					  break;
				  }
			  }
		  }

fnabet's avatar
fnabet committed
562
563
564
	      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[PROCESS RX PDU]  PDU REPLACES STORED PDU SEGMENTS SN=%d\n",
	              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),pdu_rx_info_p->sn);

fnabet's avatar
fnabet committed
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
		  list2_insert_after_element(tb_pP, previous_cursor_p, &rlc_pP->receiver_buffer);
		  return pdu_status;
	  } // End SN != vrR or SO != 0
	  else {
		  /* First update cursor until discontinuity */
		  previous_cursor_p = cursor_p;
		  AssertFatal(pdu_info_cursor_p->rf != 0,"AM Rx PDU Error, stored SN=%d should be a PDU segment\n",pdu_info_cursor_p->sn);
		  AssertFatal(((rlc_am_rx_pdu_management_t *) (cursor_p->data))->all_segments_received == 0,
				  "AM Rx PDU Error, stored SN=%d already fully received\n",pdu_info_cursor_p->sn);
		  sdu_size_t          next_waited_so = 0;
		  while ((cursor_p != NULL) && (pdu_info_cursor_p->sn == pdu_rx_info_p->sn) && (pdu_info_cursor_p->so == next_waited_so)) {
			  next_waited_so += pdu_info_cursor_p->payload_size;
	          previous_cursor_p = cursor_p;
	          cursor_p = cursor_p->next;
	          if (cursor_p != NULL) {
	        	  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
	          }
		  }
		  /* Create a new PDU segment by removing first next_waited_so bytes */
		  mem_block_t* trunc_pdu = create_new_segment_from_pdu(tb_pP,next_waited_so,pdu_rx_info_p->payload_size - next_waited_so);

		  if (trunc_pdu != NULL) {
			  ((rlc_am_rx_pdu_management_t *) (trunc_pdu->data))->segment_reassembled = RLC_AM_RX_PDU_SEGMENT_REASSEMBLE_PENDING;
			  /* Insert PDU Segment */
			  list2_insert_after_element(trunc_pdu, previous_cursor_p, &rlc_pP->receiver_buffer);

fnabet's avatar
fnabet committed
591
592
593
		      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[PROCESS RX PDU]  CREATE PDU SEGMENT FROM PDU OFFSET =%d SN=%d\n",
		              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),next_waited_so,pdu_rx_info_p->sn);

fnabet's avatar
fnabet committed
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
			  /* clean previous stored segments in duplicate */
			  if ((cursor_p != NULL) && (pdu_info_cursor_p->sn == pdu_rx_info_p->sn)) {
				  mem_block_t*       cursor_next_p = cursor_p;
				  while (cursor_next_p) {
					  cursor_p = cursor_next_p;
					  cursor_next_p = cursor_next_p->next;
					  list2_remove_element (cursor_p, &rlc_pP->receiver_buffer);
					  free_mem_block(cursor_p, __func__);
					  if (cursor_next_p != NULL) {
						  pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_next_p->data))->pdu_info;
						  if (pdu_info_cursor_p->sn != pdu_rx_info_p->sn) {
							  break;
						  }
					  }
				  }
			  }

			  /* Free original PDU */
			  free_mem_block(tb_pP, __func__);

			  return pdu_status;
		  }
		  else {
			  return RLC_AM_DATA_PDU_STATUS_BUFFER_FULL;
		  }
	  }
}
621

fnabet's avatar
fnabet committed
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
// returns 0 if success
// returns neg value if failure
//-----------------------------------------------------------------------------
rlc_am_rx_pdu_status_t
rlc_am_rx_list_check_duplicate_insert_pdu(
  const protocol_ctxt_t* const  ctxt_pP,
  rlc_am_entity_t* const rlc_pP,
  mem_block_t* const tb_pP)
{
	  rlc_am_pdu_info_t* pdu_rx_info_p                  = &((rlc_am_rx_pdu_management_t*)(tb_pP->data))->pdu_info;
	  mem_block_t*       cursor_p                    = NULL;
	  cursor_p = rlc_pP->receiver_buffer.head;
	  rlc_am_rx_pdu_status_t pdu_status = RLC_AM_DATA_PDU_STATUS_OK;
	  // it is assumed this pdu is in rx window

	  if (cursor_p == NULL)  {
		    LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (only inserted)\n",
		          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
		          __LINE__,
				  pdu_rx_info_p->sn);
		    list2_add_head(tb_pP, &rlc_pP->receiver_buffer);
		    return pdu_status;
	  }


	  /* Init Reassembly status */
	  ((rlc_am_rx_pdu_management_t*)(tb_pP->data))->segment_reassembled = RLC_AM_RX_PDU_SEGMENT_REASSEMBLE_NO;

	  if (pdu_rx_info_p->rf == 0) { // Case normal PDU received
		  pdu_status = rlc_am_rx_list_handle_pdu(ctxt_pP,rlc_pP,tb_pP);
	  }
	  else {
		  pdu_status = rlc_am_rx_list_handle_pdu_segment(ctxt_pP,rlc_pP,tb_pP);
	  }

	  return pdu_status;
}
#if 0
660
661
662
// returns 0 if success
// returns neg value if failure
//-----------------------------------------------------------------------------
663
664
signed int
rlc_am_rx_list_insert_pdu(
665
666
667
  const protocol_ctxt_t* const  ctxt_pP,
  rlc_am_entity_t* const rlc_pP,
  mem_block_t* const tb_pP)
668
{
669
670
671
672
673
674
675
676
  rlc_am_pdu_info_t* pdu_info_p                  = &((rlc_am_rx_pdu_management_t*)(tb_pP->data))->pdu_info;
  rlc_am_pdu_info_t* pdu_info_cursor_p           = NULL;
  rlc_am_pdu_info_t* pdu_info_previous_cursor_p  = NULL;
  mem_block_t*       cursor_p                    = NULL;
  mem_block_t*       previous_cursor_p           = NULL;
  cursor_p = rlc_pP->receiver_buffer.head;
  // it is assumed this pdu is in rx window

fnabet's avatar
fnabet committed
677
678
679
680
  //TODO : check for duplicate
  // should be rewrite
  /* look for previous SN */

681
682
683
684
685
686
687
688
689
690
691
692
  if (cursor_p) {
    if (rlc_pP->vr_mr < rlc_pP->vr_r) {
      if (pdu_info_p->sn >= rlc_pP->vr_r) {
        pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;

        while ((cursor_p != NULL)  && (pdu_info_cursor_p->sn >= rlc_pP->vr_r)) { // LG added =
          if (pdu_info_p->sn < pdu_info_cursor_p->sn) {
            if (previous_cursor_p != NULL) {
              pdu_info_previous_cursor_p = &((rlc_am_rx_pdu_management_t*)(previous_cursor_p->data))->pdu_info;

              if (pdu_info_previous_cursor_p->sn == pdu_info_p->sn) {
                if (pdu_info_p->rf != pdu_info_previous_cursor_p->rf) {
693
694
                  LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d WRONG RF -> DROPPED (vr(mr) < vr(r) and sn >= vr(r))\n",
                        PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
695
696
697
698
699
                        __LINE__,
                        pdu_info_p->sn);
                  return -2;
                } else if (pdu_info_p->rf == 1) {
                  if ((pdu_info_previous_cursor_p->so + pdu_info_previous_cursor_p->payload_size - 1) >= pdu_info_p->so) {
700
701
                    LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d SO OVERLAP -> DROPPED (vr(mr) < vr(r) and sn >= vr(r))\n",
                          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
gauthier's avatar
gauthier committed
702
703
                          __LINE__,
                          pdu_info_p->sn);
704
705
706
707
708
709
                    return -2;
                  }
                }
              }
            }

710
711
            LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (vr(mr) > vr(r))\n",
                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
712
713
714
715
716
717
718
                  __LINE__,
                  pdu_info_p->sn);
            list2_insert_before_element(tb_pP, cursor_p, &rlc_pP->receiver_buffer);
            return 0;

          } else if (pdu_info_p->sn == pdu_info_cursor_p->sn) {
            if (pdu_info_cursor_p->rf == 0) {
719
720
              LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d DUPLICATE -> DROPPED\n",
                    PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
721
722
723
724
725
726
727
728
729
730
731
732
                    __LINE__,
                    pdu_info_p->sn);
              return -2;
            } else if (pdu_info_p->rf == 1) {
              if ((pdu_info_p->so + pdu_info_p->payload_size - 1) < pdu_info_cursor_p->so) {

                if (previous_cursor_p != NULL) {
                  pdu_info_previous_cursor_p = &((rlc_am_rx_pdu_management_t*)(previous_cursor_p->data))->pdu_info;

                  if (pdu_info_previous_cursor_p->sn == pdu_info_cursor_p->sn) {
                    if ((pdu_info_previous_cursor_p->so + pdu_info_previous_cursor_p->payload_size - 1) < pdu_info_p->so) {

733
734
                      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d SEGMENT OFFSET %05d (vr(mr) < vr(r) and sn >= vr(r))\n",
                            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
735
736
737
738
739
740
                            __LINE__,
                            pdu_info_p->sn,
                            pdu_info_p->so);
                      list2_insert_before_element(tb_pP, cursor_p, &rlc_pP->receiver_buffer);
                      return 0;
                    } else {
741
742
                      LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d OVERLAP PREVIOUS SO DUPLICATE -> DROPPED\n",
                            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
743
744
745
                            __LINE__,
                            pdu_info_p->sn);
                      return -2;
746
                    }
747
                  }
748
                }
749

750
751
                LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d SEGMENT OFFSET %05d (vr(mr) < vr(r) and sn >= vr(r))\n",
                      PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
752
753
754
755
756
757
758
                      __LINE__,
                      pdu_info_p->sn,
                      pdu_info_p->so);
                list2_insert_before_element(tb_pP, cursor_p, &rlc_pP->receiver_buffer);
                return 0;

              } else if (pdu_info_p->so <= pdu_info_cursor_p->so) {
759
760
                LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d OVERLAP SO DUPLICATE -> DROPPED\n",
                      PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
gauthier's avatar
gauthier committed
761
762
                      __LINE__,
                      pdu_info_p->sn);
763
                return -2;
764
765
              }
            } else {
766
767
              LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d DROPPED\n",
                    PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
                    __LINE__,
                    pdu_info_p->sn);
              return -2;
            }
          }

          previous_cursor_p = cursor_p;
          cursor_p = cursor_p->next;

          if (cursor_p != NULL) {
            pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
          }
        }

        if (cursor_p != NULL) {
783
784
          LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (vr(mr) < vr(r) and sn >= vr(r))\n",
                PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
785
786
787
788
789
790
                __LINE__,
                pdu_info_p->sn);
          list2_insert_before_element(tb_pP, cursor_p, &rlc_pP->receiver_buffer);
          return 0;
        } else {
          if (pdu_info_cursor_p->rf == 0) {
791
792
            LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (vr(mr) < vr(r) and vr(h) > vr(r) and sn >= vr(r))\n",
                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
793
794
795
796
797
798
                  __LINE__,
                  pdu_info_p->sn);
            list2_add_tail(tb_pP, &rlc_pP->receiver_buffer);
            return 0;
          } else if ((pdu_info_p->rf == 1) && (pdu_info_cursor_p->rf == 1) && (pdu_info_p->sn == pdu_info_cursor_p->sn)) {
            if ((pdu_info_cursor_p->so + pdu_info_cursor_p->payload_size - 1) < pdu_info_p->so) {
799
800
              LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (vr(mr) < vr(r) and vr(h) > vr(r) and sn >= vr(r))\n",
                    PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
801
802
803
804
805
                    __LINE__,
                    pdu_info_p->sn);
              list2_add_tail(tb_pP, &rlc_pP->receiver_buffer);
              return 0;
            } else {
806
807
              LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d DROPPED\n",
                    PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
808
809
810
811
812
                    __LINE__,
                    pdu_info_p->sn);
              return -2;
            }
          } else if (pdu_info_p->sn != pdu_info_cursor_p->sn) {
813
814
            LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (vr(mr) < vr(r) and vr(h) > vr(r) and sn >= vr(r))\n",
                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
815
816
817
818
819
820
821
                  __LINE__,
                  pdu_info_p->sn);
            list2_add_tail(tb_pP, &rlc_pP->receiver_buffer);
            return 0;
          }
        }

822
823
        LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d DROPPED\n",
              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
              __LINE__,
              pdu_info_p->sn);
        return -2;
      } else { // (pdu_info_p->sn < rlc_pP->vr_r)
        cursor_p = rlc_pP->receiver_buffer.tail;
        pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;

        while ((cursor_p != NULL) && (pdu_info_cursor_p->sn < rlc_pP->vr_r)) {
          //pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
          if (pdu_info_p->sn > pdu_info_cursor_p->sn) {
            if (previous_cursor_p != NULL) {
              pdu_info_previous_cursor_p = &((rlc_am_rx_pdu_management_t*)(previous_cursor_p->data))->pdu_info;

              if (pdu_info_previous_cursor_p->sn == pdu_info_cursor_p->sn) {
                if (pdu_info_p->rf != pdu_info_previous_cursor_p->rf) {
839
840
                  LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d WRONG RF -> DROPPED (vr(mr) < vr(r) and sn >= vr(r))\n",
                        PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
841
842
843
844
                        __LINE__, pdu_info_p->sn);
                  return -2;
                } else if (pdu_info_p->rf == 1) {
                  if ((pdu_info_p->so + pdu_info_p->payload_size - 1) >= pdu_info_previous_cursor_p->so) {
845
846
                    LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d SO OVERLAP -> DROPPED (vr(mr) < vr(r) and sn >= vr(r))\n",
                          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
gauthier's avatar
gauthier committed
847
848
                          __LINE__,
                          pdu_info_p->sn);
849
850
851
852
853
854
                    return -2;
                  }
                }
              }
            }

855
856
            LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (vr(mr) < vr(r))\n",
                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
857
858
859
860
861
862
                  __LINE__,
                  pdu_info_p->sn);
            list2_insert_after_element(tb_pP, cursor_p, &rlc_pP->receiver_buffer);
            return 0;
          } else if (pdu_info_p->sn == pdu_info_cursor_p->sn) {
            if (pdu_info_cursor_p->rf == 0) {
863
864
              LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d DUPLICATE -> DROPPED\n",
                    PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
865
866
867
868
869
870
871
872
873
874
875
876
                    __LINE__,
                    pdu_info_p->sn);
              return -2;
            } else if (pdu_info_p->rf == 1) {
              if ((pdu_info_cursor_p->so + pdu_info_cursor_p->payload_size - 1) < pdu_info_p->so) {

                if (previous_cursor_p != NULL) {
                  pdu_info_previous_cursor_p = &((rlc_am_rx_pdu_management_t*)(previous_cursor_p->data))->pdu_info;

                  if (pdu_info_previous_cursor_p->sn == pdu_info_cursor_p->sn) {
                    if ((pdu_info_p->so + pdu_info_p->payload_size - 1) < pdu_info_previous_cursor_p->so) {

877
878
                      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d SEGMENT OFFSET %05d (vr(mr) < vr(r) and sn < vr(r))\n",
                            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
879
880
881
882
883
884
                            __LINE__,
                            pdu_info_p->sn,
                            pdu_info_p->so);
                      list2_insert_after_element(tb_pP, cursor_p, &rlc_pP->receiver_buffer);
                      return 0;
                    } else {
885
886
                      LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d OVERLAP PREVIOUS SO DUPLICATE -> DROPPED\n",
                            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
887
888
889
                            __LINE__,
                            pdu_info_p->sn);
                      return -2;
890
                    }
891
                  }
892
                }
893

894
895
                LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d SEGMENT OFFSET %05d (vr(mr) < vr(r) and sn < vr(r))\n",
                      PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
896
897
898
899
900
901
902
                      __LINE__,
                      pdu_info_p->sn,
                      pdu_info_p->so);
                list2_insert_after_element(tb_pP, cursor_p, &rlc_pP->receiver_buffer);
                return 0;

              } else if (pdu_info_cursor_p->so <= pdu_info_p->so) {
903
904
                LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d OVERLAP SO DUPLICATE -> DROPPED\n",
                      PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
gauthier's avatar
gauthier committed
905
906
                      __LINE__,
                      pdu_info_p->sn);
907
                return -2;
908
909
              }
            } else {
910
911
              LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d DROPPED\n",
                    PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
912
913
914
                    __LINE__,
                    pdu_info_p->sn);
              return -2;
915
            }
916
          }
917

918
919
920
921
922
923
924
925
926
          previous_cursor_p = cursor_p;
          cursor_p = cursor_p->previous;

          if (cursor_p != NULL) {
            pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;
          }
        }

        if (cursor_p != NULL) {
927
928
          LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (vr(mr) < vr(r) and sn < vr(r))\n",
                PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
929
930
931
932
933
934
                __LINE__,
                pdu_info_p->sn);
          list2_insert_after_element(tb_pP, cursor_p, &rlc_pP->receiver_buffer);
          return 0;
        } else {
          if (pdu_info_cursor_p->rf == 0) {
935
936
            LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (vr(mr) < vr(r) and vr(h) > vr(r) and sn >= vr(r))\n",
                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
937
938
939
940
941
942
                  __LINE__,
                  pdu_info_p->sn);
            list2_add_tail(tb_pP, &rlc_pP->receiver_buffer);
            return 0;
          } else if ((pdu_info_p->rf == 1) && (pdu_info_cursor_p->rf == 1) && (pdu_info_p->sn == pdu_info_cursor_p->sn)) {
            if ((pdu_info_cursor_p->so + pdu_info_cursor_p->payload_size - 1) < pdu_info_p->so) {
943
944
              LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (vr(mr) < vr(r) and vr(h) > vr(r) and sn >= vr(r))\n",
                    PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
945
946
947
948
949
                    __LINE__,
                    pdu_info_p->sn);
              list2_add_tail(tb_pP, &rlc_pP->receiver_buffer);
              return 0;
            } else {
950
951
              LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d DROPPED\n",
                    PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
952
953
954
955
956
                    __LINE__,
                    pdu_info_p->sn);
              return -2;
            }
          } else if (pdu_info_p->sn != pdu_info_cursor_p->sn) {
957
958
            LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d (vr(mr) < vr(r) and vr(h) > vr(r) and sn >= vr(r))\n",
                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
959
960
961
962
963
964
965
                  __LINE__,
                  pdu_info_p->sn);
            list2_add_tail(tb_pP, &rlc_pP->receiver_buffer);
            return 0;
          }
        }

966
967
        LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d DROPPED\n",
              PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
              __LINE__,
              pdu_info_p->sn);
        return -2;
      }
    } else { // (pdu_info_p->vr_mr > rlc_pP->vr_r), > and not >=
      // FAR MORE SIMPLE CASE
      while (cursor_p != NULL) {
        //msg ("[FRAME %05u][%s][RLC_AM][MOD %u/%u][RB %u][INSERT PDU] LINE %d cursor_p %p\n", ctxt_pP->frame, rlc_pP->module_id, rlc_pP->rb_id, __LINE__, cursor_p);
        pdu_info_cursor_p = &((rlc_am_rx_pdu_management_t*)(cursor_p->data))->pdu_info;

        if (pdu_info_p->sn < pdu_info_cursor_p->sn) {

          if (previous_cursor_p != NULL) {
            pdu_info_previous_cursor_p = &((rlc_am_rx_pdu_management_t*)(previous_cursor_p->data))->pdu_info;

            if (pdu_info_previous_cursor_p->sn == pdu_info_p->sn) {
              if (pdu_info_p->rf != pdu_info_previous_cursor_p->rf) {
985
986
                LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d WRONG RF -> DROPPED (vr(mr) > vr(r))\n",
                      PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
987
988
989
990
991
                      __LINE__,
                      pdu_info_p->sn);
                return -2;
              } else if (pdu_info_p->rf == 1) {
                if ((pdu_info_previous_cursor_p->so + pdu_info_previous_cursor_p->payload_size - 1) >= pdu_info_p->so) {
992
993
                  LOG_N(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[INSERT PDU] LINE %d RX PDU SN %04d SO OVERLAP -> DROPPED (vr(mr) > vr(r))\n",
                        PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
994
995
996
                        __LINE__,
                        pdu_info_p->sn);
                  return -2;
997
                }
998
              }
999
            }
1000
          }
For faster browsing, not all history is shown. View entire blame