pdcp_fifo.c 42.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*******************************************************************************

  Eurecom OpenAirInterface
  Copyright(c) 1999 - 2011 Eurecom

  This program is free software; you can redistribute it and/or modify it
  under the terms and conditions of the GNU General Public License,
  version 2, as published by the Free Software Foundation.

  This program is distributed in the hope it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  The full GNU General Public License is included in this distribution in
  the file called "COPYING".

  Contact Information
  Openair Admin: openair_admin@eurecom.fr
  Openair Tech : openair_tech@eurecom.fr
  Forums       : http://forums.eurecom.fsr/openairinterface
  Address      : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France

gauthier's avatar
gauthier committed
27
 *******************************************************************************/
28 29

/*! \file pdcp_fifo.c
gauthier's avatar
gauthier committed
30 31 32 33 34 35 36
 * \brief pdcp interface with linux IP interface, have a look at http://man7.org/linux/man-pages/man7/netlink.7.html for netlink
 * \author  Lionel GAUTHIER and Navid Nikaein
 * \date 2009
 * \version 0.5
 * \warning This component can be runned only in user-space
 * @ingroup pdcp
 */
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

#define PDCP_FIFO_C
#define PDCP_DEBUG 1
//#define IDROMEL_NEMO 1

#ifndef OAI_EMU
extern int otg_enabled;
#endif

#include "pdcp.h"
#include "pdcp_primitives.h"

#ifdef USER_MODE
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define rtf_put write
#define rtf_get read
#else
#include <rtai_fifos.h>
#endif //USER_MODE

#include "../MAC/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
62
#include "NAS/DRIVER/LITE/constant.h"
63 64 65 66
#include "SIMULATION/ETH_TRANSPORT/extern.h"
#include "UTIL/OCG/OCG.h"
#include "UTIL/OCG/OCG_extern.h"
#include "UTIL/LOG/log.h"
67
#include "UTIL/OTG/otg_tx.h"
68
#include "UTIL/FIFO/pad_list.h"
69 70
#include "platform_constants.h"

71
#include "assertions.h"
72 73 74 75 76

#ifdef NAS_NETLINK
#include <sys/socket.h>
#include <linux/netlink.h>

77
extern char nl_rx_buf[NL_MAX_PAYLOAD];
78
extern struct sockaddr_nl nas_src_addr, nas_dest_addr;
79 80 81 82
extern struct nlmsghdr *nas_nlh_tx;
extern struct nlmsghdr *nas_nlh_rx;
extern struct iovec nas_iov_tx;
extern struct iovec nas_iov_rx;
83
extern int nas_sock_fd;
84 85
extern struct msghdr nas_msg_tx;
extern struct msghdr nas_msg_rx;
86 87 88

#define MAX_PAYLOAD 1600

gauthier's avatar
gauthier committed
89
unsigned char pdcp_read_state_g = 0;
90
//unsigned char pdcp_read_payload[MAX_PAYLOAD];
91 92
#endif

93
extern Packet_OTG_List_t *otg_pdcp_buffer;
94

gauthier's avatar
gauthier committed
95
#if defined(LINK_PDCP_TO_GTPV1U)
96
#  include "gtpv1u_eNB_task.h"
gauthier's avatar
gauthier committed
97 98
#endif

gauthier's avatar
gauthier committed
99
pdcp_data_req_header_t pdcp_read_header_g;
100 101

//-----------------------------------------------------------------------------
102
int pdcp_fifo_flush_sdus(frame_t frameP, eNB_flag_t enb_flagP, module_id_t enb_mod_idP, module_id_t ue_mod_idP)
103 104 105
{
  //-----------------------------------------------------------------------------

gauthier's avatar
gauthier committed
106 107 108
  mem_block_t     *sdu_p            = list_get_head (&pdcp_sdu_list);
  int              bytes_wrote      = 0;
  int              pdcp_nb_sdu_sent = 0;
gauthier's avatar
gauthier committed
109 110
  uint8_t          cont             = 1;
#if defined(LINK_PDCP_TO_GTPV1U)
111
  //MessageDef      *message_p        = NULL;
gauthier's avatar
gauthier committed
112
#endif
113

114 115 116 117
#if defined(NAS_NETLINK) && defined(LINUX)
  int ret = 0;
#endif

gauthier's avatar
gauthier committed
118
  while (sdu_p && cont) {
119

gauthier's avatar
gauthier committed
120
#if ! defined(OAI_EMU)
gauthier's avatar
gauthier committed
121
      ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
122 123
#endif

gauthier's avatar
gauthier committed
124 125 126 127 128 129 130 131 132 133 134
#if defined(LINK_PDCP_TO_GTPV1U)
      if (enb_flagP) {
          LOG_I(PDCP,"Sending to GTPV1U\n");
          /*message_p = itti_alloc_new_message(TASK_PDCP_ENB, GTPV1U_TUNNEL_DATA_REQ);
          GTPV1U_TUNNEL_DATA_REQ(message_p).buffer       = &(((uint8_t *) sdu_p->data)[sizeof (pdcp_data_ind_header_t)]);
          GTPV1U_TUNNEL_DATA_REQ(message_p).length       = ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size;
          GTPV1U_TUNNEL_DATA_REQ(message_p).ue_module_id = ue_mod_idP;
          GTPV1U_TUNNEL_DATA_REQ(message_p).rab_id;      = ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id;
          */
          gtpv1u_new_data_req(
              enb_mod_idP, //gtpv1u_data_t *gtpv1u_data_p,
135 136
              ue_mod_idP,//rb_id/maxDRB, TO DO UE ID
              ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id + 4,
gauthier's avatar
gauthier committed
137 138 139 140 141 142 143 144 145 146 147 148
              &(((uint8_t *) sdu_p->data)[sizeof (pdcp_data_ind_header_t)]),
              ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);

          list_remove_head (&pdcp_sdu_list);
          free_mem_block (sdu_p);
          cont = 1;
          pdcp_nb_sdu_sent += 1;
          sdu_p = list_get_head (&pdcp_sdu_list);
          LOG_I(OTG,"After  GTPV1U\n");
          continue; // loop again
       }
#endif /* defined(ENABLE_USE_MME) */
149
#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
150 151 152
      LOG_I(PDCP, "PDCP->IP TTI %d INST %d: Preparing %d Bytes of data from rab %d to Nas_mesh\n",
          frameP, ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
          ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size, ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
153
#endif //PDCP_DEBUG
gauthier's avatar
gauthier committed
154
      cont = 0;
155

gauthier's avatar
gauthier committed
156 157 158 159
      if (!pdcp_output_sdu_bytes_to_write) {
          if (!pdcp_output_header_bytes_to_write) {
              pdcp_output_header_bytes_to_write = sizeof (pdcp_data_ind_header_t);
          }
160 161

#ifdef NAS_FIFO
gauthier's avatar
gauthier committed
162
          bytes_wrote = rtf_put (PDCP2NAS_FIFO,
163
              &(((uint8_t *) sdu->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
gauthier's avatar
gauthier committed
164
              pdcp_output_header_bytes_to_write);
165 166 167 168

#else
#ifdef NAS_NETLINK
#ifdef LINUX
169
          memcpy(NLMSG_DATA(nas_nlh_tx), &(((uint8_t *) sdu_p->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
gauthier's avatar
gauthier committed
170 171
              pdcp_output_header_bytes_to_write);
          nas_nlh_tx->nlmsg_len = pdcp_output_header_bytes_to_write;
172 173 174
#endif //LINUX
#endif //NAS_NETLINK

gauthier's avatar
gauthier committed
175
          bytes_wrote = pdcp_output_header_bytes_to_write;
176 177 178
#endif //NAS_FIFO

#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
179 180 181
          LOG_I(PDCP, "Frame %d Sent %d Bytes of header to Nas_mesh\n",
              frameP,
              bytes_wrote);
182 183
#endif //PDCP_DEBUG

gauthier's avatar
gauthier committed
184 185
          if (bytes_wrote > 0) {
              pdcp_output_header_bytes_to_write = pdcp_output_header_bytes_to_write - bytes_wrote;
186

gauthier's avatar
gauthier committed
187 188
              if (!pdcp_output_header_bytes_to_write) { // continue with sdu
                  pdcp_output_sdu_bytes_to_write = ((pdcp_data_ind_header_t *) sdu_p->data)->data_size;
189 190

#ifdef NAS_FIFO
gauthier's avatar
gauthier committed
191
                  bytes_wrote = rtf_put (PDCP2NAS_FIFO, &(sdu->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
192 193 194 195
#else

#ifdef NAS_NETLINK
#ifdef LINUX
gauthier's avatar
gauthier committed
196 197 198 199 200 201 202 203
                  memcpy(NLMSG_DATA(nas_nlh_tx)+sizeof(pdcp_data_ind_header_t), &(sdu_p->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
                  nas_nlh_tx->nlmsg_len += pdcp_output_sdu_bytes_to_write;
                  ret = sendmsg(nas_sock_fd,&nas_msg_tx,0);
                  if (ret<0) {
                      LOG_D(PDCP, "[PDCP_FIFOS] sendmsg returns %d (errno: %d)\n", ret, errno);
                      mac_xface->macphy_exit("sendmsg failed for nas_sock_fd\n");
                      break;
                  }
204 205
#endif // LINUX
#endif //NAS_NETLINK
gauthier's avatar
gauthier committed
206
                  bytes_wrote= pdcp_output_sdu_bytes_to_write;
207 208 209
#endif // NAS_FIFO

#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
210 211 212 213 214
                  LOG_I(PDCP, "PDCP->IP Frame %d INST %d: Sent %d Bytes of data from rab %d to Nas_mesh\n",
                      frameP,
                      ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
                      bytes_wrote,
                      ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
215
#endif //PDCP_DEBUG
gauthier's avatar
gauthier committed
216 217 218 219 220 221 222 223
                  if (bytes_wrote > 0) {
                      pdcp_output_sdu_bytes_to_write -= bytes_wrote;

                      if (!pdcp_output_sdu_bytes_to_write) { // OK finish with this SDU
                          // LOG_D(PDCP, "rb sent a sdu qos_sap %d\n", sapiP);
                          LOG_D(PDCP,
                              "[FRAME %05d][xxx][PDCP][MOD xx/xx][RB %u][--- PDCP_DATA_IND / %d Bytes --->][IP][INSTANCE %u][RB %u]\n",
                              frameP,
224
                              ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
gauthier's avatar
gauthier committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
                              ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size,
                              ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
                              ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);

                          list_remove_head (&pdcp_sdu_list);
                          free_mem_block (sdu_p);
                          cont = 1;
                          pdcp_nb_sdu_sent += 1;
                          sdu_p = list_get_head (&pdcp_sdu_list);
                      }
                  } else {
                      LOG_W(PDCP, "RADIO->IP SEND SDU CONGESTION!\n");
                  }
              } else {
                  LOG_W(PDCP, "RADIO->IP SEND SDU CONGESTION!\n");
              }
241
          }
gauthier's avatar
gauthier committed
242 243
      } else {
          // continue writing sdu
244
#ifdef NAS_FIFO
gauthier's avatar
gauthier committed
245
          bytes_wrote = rtf_put (PDCP2NAS_FIFO,
246
              (uint8_t *) (&(sdu_p->data[sizeof (pdcp_data_ind_header_t) + ((pdcp_data_ind_header_t *) sdu_p->data)->data_size - pdcp_output_sdu_bytes_to_write])),
gauthier's avatar
gauthier committed
247
              pdcp_output_sdu_bytes_to_write);
248
#else  // NAS_FIFO
gauthier's avatar
gauthier committed
249
          bytes_wrote = pdcp_output_sdu_bytes_to_write;
250 251
#endif  // NAS_FIFO

gauthier's avatar
gauthier committed
252 253 254 255 256 257 258 259 260 261 262 263 264
          if (bytes_wrote > 0) {
              pdcp_output_sdu_bytes_to_write -= bytes_wrote;

              if (!pdcp_output_sdu_bytes_to_write) {     // OK finish with this SDU
                  //PRINT_RB_SEND_OUTPUT_SDU ("[PDCP] RADIO->IP SEND SDU\n");
                  list_remove_head (&pdcp_sdu_list);
                  free_mem_block (sdu_p);
                  cont = 1;
                  pdcp_nb_sdu_sent += 1;
                  sdu_p = list_get_head (&pdcp_sdu_list);
                  // LOG_D(PDCP, "rb sent a sdu from rab\n");
              }
          }
265 266 267 268
      }
  }
#ifdef NAS_FIFO
  if ((pdcp_nb_sdu_sent)) {
gauthier's avatar
gauthier committed
269
      if ((pdcp_2_nas_irq > 0)) {
270
#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
271 272
          LOG_I(PDCP, "Frame %d : Trigger NAS RX interrupt\n",
              frameP);
273 274
#endif //PDCP_DEBUG

gauthier's avatar
gauthier committed
275 276 277 278 279 280
          rt_pend_linux_srq (pdcp_2_nas_irq);
      } else {
          LOG_E(PDCP, "Frame %d: ERROR IF IP STACK WANTED : NOTIF PACKET(S) pdcp_2_nas_irq not initialized : %d\n",
              frameP,
              pdcp_2_nas_irq);
      }
281 282 283 284 285 286 287 288 289 290 291 292
  }
#endif  //NAS_FIFO

  return pdcp_nb_sdu_sent;
}

//-----------------------------------------------------------------------------
/*
 * returns a positive value if whole bytes that had to be read were read
 * returns zero  value if whole bytes that had to be read were not read at all
 * returns a negative  value if an error was encountered while reading the rt fifo
 */
293
int pdcp_fifo_read_input_sdus_remaining_bytes (frame_t frameP, eNB_flag_t enb_flagP)
294 295
{
  //-----------------------------------------------------------------------------
296
  sdu_size_t             bytes_read = 0;
gauthier's avatar
gauthier committed
297 298 299 300 301 302
  rb_id_t                rab_id     = 0;
  pdcp_t                *pdcp_p     = NULL;
  module_id_t            ue_inst    = 0;
  module_id_t            enb_inst   = 0;
  rb_id_t                rb_id      = 0;
  int                    result     = -1;
303 304 305

  // if remaining bytes to read
  if (pdcp_input_sdu_remaining_size_to_read > 0) {
gauthier's avatar
gauthier committed
306 307 308
      bytes_read = rtf_get (NAS2PDCP_FIFO,
          &(pdcp_input_sdu_buffer[pdcp_input_sdu_size_read]),
          pdcp_input_sdu_remaining_size_to_read);
309

gauthier's avatar
gauthier committed
310 311
      if (bytes_read > 0) {
          LOG_D(PDCP, "[PDCP_FIFOS] Read %d remaining bytes of data from Nas_mesh\n", bytes_read);
312

gauthier's avatar
gauthier committed
313 314
          pdcp_input_sdu_remaining_size_to_read = pdcp_input_sdu_remaining_size_to_read - bytes_read;
          pdcp_input_sdu_size_read = pdcp_input_sdu_size_read + bytes_read;
315

gauthier's avatar
gauthier committed
316 317 318
          if (pdcp_input_sdu_remaining_size_to_read != 0) {
              return 0;
          } else {
319
#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
320 321 322 323 324
              LOG_I(PDCP, "Frame %d: IP->RADIO RECEIVED COMPLETE SDU size %d inst %d rb %d\n",
                  frameP,
                  pdcp_input_sdu_size_read,
                  pdcp_input_header.inst,
                  pdcp_input_header.rb_id);
325
#endif //PDCP_DEBUG
gauthier's avatar
gauthier committed
326
              pdcp_input_sdu_size_read = 0;
327
#ifdef IDROMEL_NEMO
gauthier's avatar
gauthier committed
328
              pdcp_read_header_g.inst = 0;
329 330
#endif

331
              if (enb_flagP == 0) {
gauthier's avatar
gauthier committed
332
                  ue_inst  = pdcp_read_header_g.inst;
333
                  rb_id    = pdcp_read_header_g.rb_id;
gauthier's avatar
gauthier committed
334
                  enb_inst = 0;
335
                  pdcp_p   = &pdcp_array_drb_ue[ue_inst][rb_id-1];
gauthier's avatar
gauthier committed
336
              } else {
337 338
                  ue_inst  = pdcp_read_header_g.rb_id / maxDRB;
                  rb_id    = pdcp_read_header_g.rb_id % maxDRB;
gauthier's avatar
gauthier committed
339
                  enb_inst = pdcp_read_header_g.inst;
340
                  pdcp_p   = &pdcp_array_drb_eNB[enb_inst][ue_inst][rb_id-1];
gauthier's avatar
gauthier committed
341 342 343 344 345 346 347 348 349 350
              }
              AssertFatal (enb_inst < NB_eNB_INST, "eNB module id is too high (%u/%d)!\n",       enb_inst, NB_eNB_INST);
              AssertFatal (ue_inst  >= NB_eNB_INST,
                           "UE module id is too low (%u/%d)!\n",
                           ue_inst,
                           NB_eNB_INST);
              AssertFatal (ue_inst  < (NB_eNB_INST + NB_UE_INST),
                           "UE module id is too high (%u/%d)!\n",
                           ue_inst,
                           NB_eNB_INST + NB_UE_INST);
351
              AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
gauthier's avatar
gauthier committed
352 353 354 355

              if (pdcp_input_header.rb_id != 0) {
                  LOG_D(PDCP, "[FRAME %5u][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u/%u][RB %u]\n",
                      frameP,
356
                      (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
357 358 359 360 361 362 363 364
                      pdcp_read_header_g.inst,
                      pdcp_read_header_g.rb_id,
                      pdcp_read_header_g.data_size,
                      enb_inst,
                      ue_inst,
                      rb_id);

                  if (pdcp_p->instanciated_instance) {
365 366 367 368 369 370 371 372 373 374 375 376
                      result = pdcp_data_req (
                              enb_inst,
                              ue_inst,
                              frameP,
                              enb_flagP,
                              SRB_FLAG_NO,
                              rb_id % maxDRB,
                              RLC_MUI_UNDEFINED,
                              RLC_SDU_CONFIRM_NO,
                              pdcp_input_header.data_size,
                              pdcp_input_sdu_buffer,
                              PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
377 378 379
                      AssertFatal (result == TRUE, "PDCP data request failed!\n");
                  }

380
              } else if ((pdcp_input_header.traffic_type == TRAFFIC_IPV6_TYPE_MULTICAST) || (pdcp_input_header.traffic_type == TRAFFIC_IPV4_TYPE_MULTICAST)) {
gauthier's avatar
gauthier committed
381 382
                  LOG_D(PDCP, "[FRAME %5u][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ on MBMS bearer/ %d Bytes --->][PDCP][MOD %u/%u][RB %u]\n",
                      frameP,
383
                      (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
384 385 386 387 388 389 390 391 392 393 394 395
                          pdcp_read_header_g.inst,
                          pdcp_read_header_g.rb_id,
                          pdcp_read_header_g.data_size,
                          enb_inst,
                          ue_inst,
                          rb_id);

                  if (pdcp_p->instanciated_instance) {
                      result = pdcp_data_req (
                          enb_inst,
                          ue_inst,
                          frameP,
396
                          enb_flagP,
397
                          SRB_FLAG_NO,
gauthier's avatar
gauthier committed
398 399 400 401 402
                          rb_id,
                          RLC_MUI_UNDEFINED,
                          RLC_SDU_CONFIRM_NO,
                          pdcp_input_header.data_size,
                          pdcp_input_sdu_buffer,
403
                          PDCP_TRANSMISSION_MODE_TRANSPARENT);
gauthier's avatar
gauthier committed
404 405 406
                      AssertFatal (result == TRUE, "PDCP data request failed!\n");
                  }

407
              } else if (enb_flagP) {
gauthier's avatar
gauthier committed
408 409 410 411
                  // is a broadcast packet, we have to send this packet on all default RABS of all connected UEs
                  LOG_D(PDCP, "Checking if could sent on default rabs\n");
                  for (ue_inst = 0; ue_inst < NUMBER_OF_UE_MAX; ue_inst++) {
                      LOG_D(PDCP, "Checking if could sent on default rab id %d\n", DEFAULT_RAB_ID);
412
                      pdcp_p = &pdcp_array_drb_eNB[enb_inst][ue_inst][DEFAULT_RAB_ID-1];
gauthier's avatar
gauthier committed
413 414 415
                      if (pdcp_p->instanciated_instance) {
                          LOG_D(PDCP, "[FRAME %5u][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u/%u][RB DEFAULT_RAB_ID %u]\n",
                              frameP,
416
                              (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
417 418 419 420 421 422 423 424 425 426
                              pdcp_read_header_g.inst,
                              pdcp_read_header_g.rb_id,
                              pdcp_read_header_g.data_size,
                              enb_inst,
                              ue_inst,
                              DEFAULT_RAB_ID);
                          result = pdcp_data_req (
                              enb_inst,
                              ue_inst,
                              frameP,
427
                              enb_flagP,
428
                              SRB_FLAG_NO,
gauthier's avatar
gauthier committed
429 430 431 432 433
                              DEFAULT_RAB_ID,
                              RLC_MUI_UNDEFINED,
                              RLC_SDU_CONFIRM_NO,
                              pdcp_input_header.data_size,
                              pdcp_input_sdu_buffer,
434
                              PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
435 436 437 438 439 440 441
                          AssertFatal (result == TRUE, "PDCP data request failed!\n");
                      }
                  }
              } else {
                  LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
                  LOG_D(PDCP, "[FRAME %5u][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u/%u][RB DEFAULT_RAB_ID %u]\n",
                      frameP,
442
                      (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
443 444 445 446 447 448 449 450 451 452
                      pdcp_read_header_g.inst,
                      pdcp_read_header_g.rb_id,
                      pdcp_read_header_g.data_size,
                      enb_inst,
                      ue_inst,
                      DEFAULT_RAB_ID);
                  result = pdcp_data_req (
                      enb_inst,
                      ue_inst,
                      frameP,
453
                      enb_flagP,
454
                      SRB_FLAG_NO,
gauthier's avatar
gauthier committed
455 456 457 458 459
                      DEFAULT_RAB_ID,
                      RLC_MUI_UNDEFINED,
                      RLC_SDU_CONFIRM_NO,
                      pdcp_input_header.data_size,
                      pdcp_input_sdu_buffer,
460
                      PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
461 462 463 464 465 466 467 468
                  AssertFatal (result == TRUE, "PDCP data request failed!\n");
              }
              // not necessary
              //memset(pdcp_input_sdu_buffer, 0, MAX_IP_PACKET_SIZE);
              return 1;
          }
      } else {
          return bytes_read;
469 470 471 472 473 474
      }
  }
  return 1;
}

//-----------------------------------------------------------------------------
475
int pdcp_fifo_read_input_sdus (frame_t frameP, eNB_flag_t enb_flagP, module_id_t ue_mod_idP, module_id_t enb_mod_idP)
476 477
{
#ifdef NAS_NETLINK
478
# if defined(ENABLE_PDCP_NETLINK_FIFO)
gauthier's avatar
gauthier committed
479 480 481
  module_id_t                    ue_id     = 0;
  rb_id_t                        rab_id    = 0;
  pdcp_t                        *pdcp      = NULL;
482
  pdcp_transmission_mode_t       pdcp_mode = PDCP_TRANSMISSION_MODE_UNKNOWN;
gauthier's avatar
gauthier committed
483 484
  struct pdcp_netlink_element_s *data      = NULL;

485
  while (pdcp_netlink_dequeue_element(enb_mod_idP, ue_mod_idP, enb_flagP, &data) != 0) {
gauthier's avatar
gauthier committed
486
      DevAssert(data != NULL);
487
      if (enb_flagP == 0) {
488 489
          rab_id = data->pdcp_read_header.rb_id % maxDRB;
          pdcp = &pdcp_array_drb_ue[ue_mod_idP][rab_id-1];
gauthier's avatar
gauthier committed
490
      } else {
491 492 493
          rab_id = data->pdcp_read_header.rb_id % maxDRB;
          ue_mod_idP = data->pdcp_read_header.rb_id / maxDRB;
          pdcp = &pdcp_array_drb_eNB[enb_mod_idP][ue_mod_idP][rab_id-1];
gauthier's avatar
gauthier committed
494
      }
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
      if (enb_flagP) {
          AssertFatal ((enb_mod_idP >= oai_emulation.info.first_enb_local) && (oai_emulation.info.nb_enb_local > 0),
              "eNB module id is too low (%u/%d)!\n",
              enb_mod_idP,
              oai_emulation.info.first_enb_local);
          AssertFatal ((enb_mod_idP < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local)) && (oai_emulation.info.nb_enb_local > 0),
              "eNB module id is too high (%u/%d)!\n",
              enb_mod_idP,
              oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local);
          AssertFatal (ue_mod_idP  < NB_UE_INST,
              "UE module id is too high (%u/%d)!\n",
              ue_mod_idP,
              oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
      } else {
          AssertFatal (ue_mod_idP  < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local),
              "UE module id is too high (%u/%d)!\n",
              ue_mod_idP,
              oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
          AssertFatal (ue_mod_idP  >= oai_emulation.info.first_ue_local,
              "UE module id is too low (%u/%d)!\n",
              ue_mod_idP,
              oai_emulation.info.first_ue_local);
      }
518
      AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
gauthier's avatar
gauthier committed
519 520 521 522 523 524

      if (rab_id != 0) {
          if (pdcp->instanciated_instance) {
              LOG_D(PDCP, "[FRAME %05d][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ "
                  "/ %d Bytes --->][PDCP][MOD %u/%u][RB %u]\n",
                  frameP,
525
                  (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
526 527 528 529 530 531
                      data->pdcp_read_header.inst,
                      data->pdcp_read_header.rb_id,
                      data->pdcp_read_header.data_size,
                      enb_mod_idP,
                      ue_mod_idP,
                      rab_id);
532
#ifdef 	OAI_NW_DRIVER_TYPE_ETHERNET
533 534 535 536
              if ((data->pdcp_read_header.traffic_type == TRAFFIC_IPV6_TYPE_MULTICAST) /*TRAFFIC_IPV6_TYPE_MULTICAST */ ||
                  (data->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_MULTICAST) /*TRAFFIC_IPV4_TYPE_MULTICAST */ ||
                  (data->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_BROADCAST) /*TRAFFIC_IPV4_TYPE_BROADCAST */ ) {
#if defined (Rel10)
537
                PDCP_TRANSMISSION_MODE_TRANSPARENT;
538 539 540 541 542 543 544 545
#else
                pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
#endif
              } else if ((data->pdcp_read_header.traffic_type == TRAFFIC_IPV6_TYPE_UNICAST) /* TRAFFIC_IPV6_TYPE_UNICAST */ ||
                  (data->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_UNICAST) /*TRAFFIC_IPV4_TYPE_UNICAST*/ ) {
                pdcp_mode=  PDCP_TRANSMISSION_MODE_DATA;
              } else {
                  pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
gauthier's avatar
gauthier committed
546 547
                  LOG_W(PDCP,"unknown IP traffic type \n");
              }
548
#else // NASMESH driver does not curreenlty support multicast traffic
549
              pdcp_mode = PDCP_TRANSMISSION_MODE_DATA;
550
#endif
gauthier's avatar
gauthier committed
551 552 553
              pdcp_data_req(enb_mod_idP,
                  ue_mod_idP,
                  frameP,
554
                  enb_flagP,
555 556
                  SRB_FLAG_NO,
                  rab_id % maxDRB,
gauthier's avatar
gauthier committed
557 558 559 560 561 562
                  RLC_MUI_UNDEFINED,
                  RLC_SDU_CONFIRM_NO,
                  data->pdcp_read_header.data_size,
                  data->data,
                  pdcp_mode);
          } else {
563 564
              LOG_E(PDCP, "Received packet for non-instanciated instance %u with rb_id %u, UE_index %d, enb_flagP %d eNB_index %d\n",
                  data->pdcp_read_header.inst, data->pdcp_read_header.rb_id, ue_mod_idP, enb_flagP,enb_mod_idP);
gauthier's avatar
gauthier committed
565
          }
566
      } else if (enb_flagP) {
gauthier's avatar
gauthier committed
567 568 569 570
          /* rb_id = 0, thus interpreated as broadcast and transported as
           * multiple unicast is a broadcast packet, we have to send this
           * packet on all default RABS of all connected UEs
           */
571 572
          LOG_D(PDCP, "eNB Try Forcing send on DEFAULT_RAB_ID first_ue_local %u nb_ue_local %u\n", oai_emulation.info.first_ue_local, oai_emulation.info.nb_ue_local);
          for (ue_id = 0; ue_id < NB_UE_INST; ue_id++) {
573
              pdcp = &pdcp_array_drb_eNB[enb_mod_idP][ue_id][DEFAULT_RAB_ID-1];
gauthier's avatar
gauthier committed
574
              if (pdcp->instanciated_instance) {
575
                  LOG_D(PDCP, "eNB Try Forcing send on DEFAULT_RAB_ID UE %d\n", ue_id);
gauthier's avatar
gauthier committed
576 577 578 579
                  pdcp_data_req(
                      enb_mod_idP,
                      ue_id,
                      frameP,
580
                      enb_flagP,
581
                      SRB_FLAG_NO,
gauthier's avatar
gauthier committed
582 583 584 585 586
                      DEFAULT_RAB_ID,
                      RLC_MUI_UNDEFINED,
                      RLC_SDU_CONFIRM_NO,
                      data->pdcp_read_header.data_size,
                      data->data,
587
                      PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
588 589 590 591 592 593 594 595
              }
          }
      } else {
          LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
          pdcp_data_req(
              enb_mod_idP,
              ue_mod_idP,
              frameP,
596
              enb_flagP,
597
              SRB_FLAG_NO,
gauthier's avatar
gauthier committed
598 599 600 601 602
              DEFAULT_RAB_ID,
              RLC_MUI_UNDEFINED,
              RLC_SDU_CONFIRM_NO,
              data->pdcp_read_header.data_size,
              data->data,
603
              PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
604 605 606 607 608 609 610
      }
      free(data->data);
      free(data);
      data = NULL;
  }
  return 0;
# else /* ENABLE_PDCP_NETLINK_FIFO*/
611 612
  int              len = 1;
  rb_id_t          rab_id  = 0;
613
  while (len > 0) {
gauthier's avatar
gauthier committed
614 615 616 617 618 619 620 621
      len = recvmsg(nas_sock_fd, &nas_msg_rx, 0);
      if (len<=0) {
          // nothing in pdcp NAS socket
          //LOG_I(PDCP, "[PDCP][NETLINK] Nothing in socket, length %d \n", len);
      } else {
          for (nas_nlh_rx = (struct nlmsghdr *) nl_rx_buf;
              NLMSG_OK (nas_nlh_rx, len);
              nas_nlh_rx = NLMSG_NEXT (nas_nlh_rx, len)) {
622

gauthier's avatar
gauthier committed
623 624 625 626
              if (nas_nlh_rx->nlmsg_type == NLMSG_DONE) {
                  LOG_I(PDCP, "[PDCP][FIFO] RX NLMSG_DONE\n");
                  //return;
              }
627

gauthier's avatar
gauthier committed
628 629 630 631 632 633 634 635 636
              if (nas_nlh_rx->nlmsg_type == NLMSG_ERROR) {
                  LOG_I(PDCP, "[PDCP][FIFO] RX NLMSG_ERROR\n");
              }
              if (pdcp_read_state_g == 0) {
                  if (nas_nlh_rx->nlmsg_len == sizeof (pdcp_data_req_header_t) + sizeof(struct nlmsghdr)) {
                      pdcp_read_state_g = 1;  //get
                      memcpy((void *)&pdcp_read_header_g, (void *)NLMSG_DATA(nas_nlh_rx), sizeof(pdcp_data_req_header_t));
                      LOG_I(PDCP, "[PDCP][FIFO] RX pdcp_data_req_header_t inst %u, rb_id %u data_size %d\n",
                          pdcp_read_header_g.inst, pdcp_read_header_g.rb_id, pdcp_read_header_g.data_size);
637
                  } else {
gauthier's avatar
gauthier committed
638 639 640 641 642 643
                      LOG_E(PDCP, "[PDCP][FIFO] WRONG size %d should be sizeof (pdcp_data_req_header_t) + sizeof(struct nlmsghdr)\n",
                          nas_nlh_rx->nlmsg_len);
                  }
              } else {
                  pdcp_read_state_g = 0;
                  // print_active_requests()
644
#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
645 646
                  LOG_I(PDCP, "[PDCP][FIFO] Something in socket, length %d \n",
                      nas_nlh_rx->nlmsg_len - sizeof(struct nlmsghdr));
647
#endif
gauthier's avatar
gauthier committed
648 649 650 651
                  //memcpy(pdcp_read_payload, (unsigned char *)NLMSG_DATA(nas_nlh_rx), nas_nlh_rx->nlmsg_len - sizeof(struct nlmsghdr));

                  // overwrite function input parameters, because only one netlink socket for all instances
                  if (pdcp_read_header_g.inst < oai_emulation.info.nb_enb_local) {
652
                      enb_flagP  = 1;
653
                      ue_mod_idP  = pdcp_read_header_g.rb_id / maxDRB + oai_emulation.info.first_ue_local;
gauthier's avatar
gauthier committed
654
                      enb_mod_idP = pdcp_read_header_g.inst  +  oai_emulation.info.first_enb_local;
655
                      rab_id    = pdcp_read_header_g.rb_id % maxDRB;
gauthier's avatar
gauthier committed
656
                  } else {
657
                      enb_flagP  = 0;
gauthier's avatar
gauthier committed
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
                      ue_mod_idP  = pdcp_read_header_g.inst - oai_emulation.info.nb_enb_local + oai_emulation.info.first_ue_local;
                      enb_mod_idP = 0;
                      rab_id    = pdcp_read_header_g.rb_id;
                  }
                  AssertFatal (enb_mod_idP >= oai_emulation.info.first_enb_local,
                              "eNB inst is too low (%u/%d)!\n",
                              enb_mod_idP,
                              oai_emulation.info.first_enb_local);
                  AssertFatal (enb_mod_idP < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local),
                              "eNB inst is too high (%u/%d)!\n",
                              enb_mod_idP,
                              oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local);
                  AssertFatal (ue_mod_idP  >= oai_emulation.info.first_ue_local,
                               "UE inst is too low (%u/%d)!\n",
                               ue_mod_idP,
                               oai_emulation.info.first_ue_local);
                  AssertFatal (ue_mod_idP  < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local),
                               "UE inst is too high (%u/%d)!\n",
                               ue_mod_idP,
                               oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
678
                  AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
gauthier's avatar
gauthier committed
679 680 681 682 683 684 685 686
#ifdef OAI_EMU
                  /*LGpdcp_read_header.inst = (pdcp_read_header_g.inst >= oai_emulation.info.nb_enb_local) ? \
                          pdcp_read_header_g.inst - oai_emulation.info.nb_enb_local+ NB_eNB_INST + oai_emulation.info.first_ue_local :
                          pdcp_read_header_g.inst +  oai_emulation.info.first_enb_local;*/
#else
                  pdcp_read_header_g.inst = 0;
#endif

687
                  if (enb_flagP) {
gauthier's avatar
gauthier committed
688
                      if (rab_id != 0) {
689 690
                          rab_id = rab_id % maxDRB;
                          if (pdcp_array_drb_eNB[enb_mod_idP][ue_mod_idP][rab_id-1].instanciated_instance) {
691
#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
692 693 694 695 696 697
                              LOG_I(PDCP, "[FRAME %5u][eNB][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %d) on Rab %d \n",
                                  frameP,
                                  pdcp_read_header_g.inst,
                                  len,
                                  nas_nlh_rx->nlmsg_len-sizeof(struct nlmsghdr),
                                  pdcp_read_header_g.rb_id);
698 699
#endif

gauthier's avatar
gauthier committed
700 701 702 703 704 705 706 707 708
                              LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u/%u][RB %u]\n",
                                  frameP,
                                  pdcp_read_header_g.inst,
                                  pdcp_read_header_g.rb_id,
                                  pdcp_read_header_g.data_size,
                                  enb_mod_idP,
                                  ue_mod_idP,
                                  rab_id);

709
                              pdcp_data_req(enb_mod_idP,ue_mod_idP,frameP, enb_flagP,SRB_FLAG_NO,
gauthier's avatar
gauthier committed
710 711 712 713 714
                                  rab_id,
                                  RLC_MUI_UNDEFINED,
                                  RLC_SDU_CONFIRM_NO,
                                  pdcp_read_header_g.data_size,
                                  (unsigned char *)NLMSG_DATA(nas_nlh_rx),
715
                                  PDCP_TRANSMISSION_MODE_DATA);
716
                          } else {
gauthier's avatar
gauthier committed
717 718 719 720 721 722 723 724
                              LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes ---X][PDCP][MOD %u/%u][RB %u] NON INSTANCIATED INSTANCE, DROPPED\n",
                                  frameP,
                                  pdcp_read_header_g.inst,
                                  pdcp_read_header_g.rb_id,
                                  pdcp_read_header_g.data_size,
                                  enb_mod_idP,
                                  ue_mod_idP,
                                  rab_id);
725
                          }
gauthier's avatar
gauthier committed
726
                      } else  { // rb_id =0, thus interpreated as broadcast and transported as multiple unicast
727
                          // is a broadcast packet, we have to send this packet on all default RABS of all connected UEs
gauthier's avatar
gauthier committed
728
#warning CODE TO BE REVIEWED, ONLY WORK FOR SIMPLE TOPOLOGY CASES
729
                          for (ue_mod_idP = 0; ue_mod_idP < NB_UE_INST; ue_mod_idP++) {
730
                              if (pdcp_array_drb_eNB[enb_mod_idP][ue_mod_idP][rab_id-1].instanciated_instance == TRUE) {
gauthier's avatar
gauthier committed
731 732 733 734 735 736 737 738 739 740 741 742
                                  LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u/%u][RB DEFAULT_RAB_ID %u]\n",
                                      frameP,
                                      pdcp_read_header_g.inst,
                                      pdcp_read_header_g.rb_id,
                                      pdcp_read_header_g.data_size,
                                      enb_mod_idP,
                                      ue_mod_idP,
                                      DEFAULT_RAB_ID);
                                  pdcp_data_req (
                                      enb_mod_idP,
                                      ue_mod_idP,
                                      frameP,
743
                                      enb_flagP,
744
                                      SRB_FLAG_NO,
gauthier's avatar
gauthier committed
745 746 747 748 749
                                      DEFAULT_RAB_ID,
                                      RLC_MUI_UNDEFINED,
                                      RLC_SDU_CONFIRM_NO,
                                      pdcp_read_header_g.data_size,
                                      (unsigned char *)NLMSG_DATA(nas_nlh_rx),
750
                                      PDCP_TRANSMISSION_MODE_DATA);
751 752
                              }
                          }
gauthier's avatar
gauthier committed
753 754 755
                      }
                  } else {
                      if (rab_id != 0) {
756
                          if (pdcp_array_drb_ue[ue_mod_idP][rab_id-1].instanciated_instance) {
gauthier's avatar
gauthier committed
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
#ifdef PDCP_DEBUG
                              LOG_I(PDCP, "[FRAME %5u][UE][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %d) on Rab %d \n",
                                  frameP,
                                  pdcp_read_header_g.inst,
                                  len,
                                  nas_nlh_rx->nlmsg_len-sizeof(struct nlmsghdr),
                                  pdcp_read_header_g.rb_id);

                              LOG_D(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u/%u][RB %u]\n",
                                  frameP,
                                  pdcp_read_header_g.inst,
                                  pdcp_read_header_g.rb_id,
                                  pdcp_read_header_g.data_size,
                                  enb_mod_idP,
                                  ue_mod_idP,
                                  rab_id);
#endif
774

gauthier's avatar
gauthier committed
775 776 777 778
                              pdcp_data_req(
                                  enb_mod_idP,
                                  ue_mod_idP,
                                  frameP,
779
                                  enb_flagP,
780
                                  SRB_FLAG_NO,
gauthier's avatar
gauthier committed
781 782 783 784 785
                                  rab_id,
                                  RLC_MUI_UNDEFINED,
                                  RLC_SDU_CONFIRM_NO,
                                  pdcp_read_header_g.data_size,
                                  (unsigned char *)NLMSG_DATA(nas_nlh_rx),
786
                                  PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
                          } else {
                              LOG_D(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes ---X][PDCP][MOD %u/%u][RB %u] NON INSTANCIATED INSTANCE, DROPPED\n",
                                  frameP,
                                  pdcp_read_header_g.inst,
                                  pdcp_read_header_g.rb_id,
                                  pdcp_read_header_g.data_size,
                                  enb_mod_idP,
                                  ue_mod_idP,
                                  rab_id);
                          }
                      }  else {
                          LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
                          LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u/%u][RB DEFAULT_RAB_ID %u]\n",
                              frameP,
                              pdcp_read_header_g.inst,
                              pdcp_read_header_g.rb_id,
                              pdcp_read_header_g.data_size,
                              enb_mod_idP,
                              ue_mod_idP,
                              DEFAULT_RAB_ID);
                          pdcp_data_req (
                              enb_mod_idP,
                              ue_mod_idP,
                              frameP,
811
                              enb_flagP,
812
                              SRB_FLAG_NO,
gauthier's avatar
gauthier committed
813 814 815 816 817
                              DEFAULT_RAB_ID,
                              RLC_MUI_UNDEFINED,
                              RLC_SDU_CONFIRM_NO,
                              pdcp_read_header_g.data_size,
                              (unsigned char *)NLMSG_DATA(nas_nlh_rx),
818
                              PDCP_TRANSMISSION_MODE_DATA);
819 820
                      }
                  }
gauthier's avatar
gauthier committed
821

822 823
              }
          }
gauthier's avatar
gauthier committed
824
      }
825
  }
826
  return len;
827
# endif
828 829 830 831 832 833
#else // neither NAS_NETLINK nor NAS_FIFO
  return 0;
#endif // NAS_NETLINK
}


834 835 836 837 838
void pdcp_fifo_read_input_sdus_from_otg (frame_t frameP, eNB_flag_t enb_flagP, module_id_t ue_mod_idP, module_id_t enb_mod_idP) {
  unsigned char       *otg_pkt=NULL;
  module_id_t          src_id, module_id; // src for otg
  module_id_t          dst_id; // dst for otg
  rb_id_t              rb_id;
839
  signed long          pkt_size=0, pkt_cnt=0;
840 841 842
  uint8_t              pdcp_mode, is_ue=0;
  Packet_otg_elt_t    *otg_pkt_info=NULL;
  int                  result;
843

gauthier's avatar
gauthier committed
844
  src_id = enb_mod_idP;
845

846 847 848
  // we need to add conditions to avoid transmitting data when the UE is not RRC connected.
#if defined(USER_MODE) && defined(OAI_EMU)
  if (oai_emulation.info.otg_enabled ==1 ){
849 850
      module_id = (enb_flagP == 1) ?  enb_mod_idP : ue_mod_idP;
      //rb_id    = (enb_flagP == 1) ? enb_mod_idP * MAX_NUM_RB + DTCH : (NB_eNB_INST + UE_index -1 ) * MAX_NUM_RB + DTCH ;
gauthier's avatar
gauthier committed
851 852 853 854 855 856 857 858 859 860 861 862 863
      src_id = module_id;
      while ((otg_pkt_info = pkt_list_remove_head(&(otg_pdcp_buffer[module_id]))) != NULL) {
          LOG_I(OTG,"Mod_id %d Frame %d Got a packet (%p), HEAD of otg_pdcp_buffer[%d] is %p and Nb elements is %d\n",
              module_id,frameP, otg_pkt_info, module_id, pkt_list_get_head(&(otg_pdcp_buffer[module_id])), otg_pdcp_buffer[module_id].nb_elements);
          //otg_pkt_info = pkt_list_remove_head(&(otg_pdcp_buffer[module_id]));
          dst_id = (otg_pkt_info->otg_pkt).dst_id;
          module_id = (otg_pkt_info->otg_pkt).module_id;
          rb_id = (otg_pkt_info->otg_pkt).rb_id;
          is_ue = (otg_pkt_info->otg_pkt).is_ue;
          pdcp_mode = (otg_pkt_info->otg_pkt).mode;
          //    LOG_I(PDCP,"pdcp_fifo, pdcp mode is= %d\n",pdcp_mode);

          // generate traffic if the ue is rrc reconfigured state
864
          // if (mac_get_rrc_status(module_id, enb_flagP, dst_id ) > 2 /*RRC_CONNECTED*/) { // not needed: this test is already done in update_otg_enb
865
          otg_pkt = (unsigned char*) (otg_pkt_info->otg_pkt).sdu_buffer;
gauthier's avatar
gauthier committed
866 867 868
          pkt_size = (otg_pkt_info->otg_pkt).sdu_buffer_size;
          if (otg_pkt != NULL) {
              if (is_ue == 0 ) {
869
                  rlc_util_print_hex_octets(PDCP,
870
                                            otg_pkt,
871 872
                                            pkt_size);

gauthier's avatar
gauthier committed
873 874 875
                  //rb_id = (/*NB_eNB_INST +*/ dst_id -1 ) * MAX_NUM_RB + DTCH;
                  LOG_D(OTG,"[eNB %d] Frame %d sending packet %d from module %d on rab id %d (src %d, dst %d) pkt size %d for pdcp mode %d\n",
                      enb_mod_idP, frameP, pkt_cnt++, module_id, rb_id, module_id, dst_id, pkt_size, pdcp_mode);
876
                  result = pdcp_data_req(enb_mod_idP, ue_mod_idP, frameP, enb_flagP, SRB_FLAG_NO, rb_id, RLC_MUI_UNDEFINED, RLC_SDU_CONFIRM_NO, pkt_size, otg_pkt,pdcp_mode);
gauthier's avatar
gauthier committed
877 878 879 880
                  AssertFatal (result == TRUE, "PDCP data request failed!\n");
              }
              else {
                  //rb_id= eNB_index * MAX_NUM_RB + DTCH;
881 882


gauthier's avatar
gauthier committed
883 884
                  LOG_D(OTG,"[UE %d] sending packet from module %d on rab id %d (src %d, dst %d) pkt size %d\n",
                      ue_mod_idP, src_id, rb_id, src_id, dst_id, pkt_size);
885 886 887 888
                  result = pdcp_data_req( enb_mod_idP,
                                          ue_mod_idP,
                                          frameP,
                                          enb_flagP,
889
                                          SRB_FLAG_NO,
890 891 892 893 894 895
                                          rb_id,
                                          RLC_MUI_UNDEFINED,
                                          RLC_SDU_CONFIRM_NO,
                                          pkt_size,
                                          otg_pkt,
                                          PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
896 897 898 899 900
                  AssertFatal (result == TRUE, "PDCP data request failed!\n");
              }
              free(otg_pkt);
              otg_pkt = NULL;
          }
901
          // } //else LOG_D(OTG,"frameP %d enb %d-> ue %d link not yet established state %d  \n", frameP, eNB_index,dst_id - NB_eNB_INST, mac_get_rrc_status(module_id, enb_flagP, dst_id - NB_eNB_INST));
gauthier's avatar
gauthier committed
902

903 904 905
      }
  }
#else
906
  if ((otg_enabled==1) && (enb_flagP == 1)) { // generate DL traffic
gauthier's avatar
gauthier committed
907 908 909
      unsigned int ctime=0;
      ctime = frameP * 100;

910 911
      /*if  ((mac_get_rrc_status(eNB_index, enb_flagP, 0 ) > 2) &&
      (mac_get_rrc_status(eNB_index, enb_flagP, 1 ) > 2)) { */
gauthier's avatar
gauthier committed
912
      for (dst_id = 0; dst_id<NUMBER_OF_UE_MAX; dst_id++) {
913
          if (mac_get_rrc_status(enb_mod_idP, enb_flagP, dst_id ) > 2) {
gauthier's avatar
gauthier committed
914 915
              otg_pkt=packet_gen(src_id, dst_id, 0, ctime, &pkt_size);
              if (otg_pkt != NULL){
916 917
                  rb_id = dst_id * maxDRB + DTCH;
                  pdcp_data_req(enb_mod_idP, dst_id, frameP, enb_flagP, SRB_FLAG_NO, rb_id, RLC_MUI_UNDEFINED, RLC_SDU_CONFIRM_NO,pkt_size, otg_pkt, PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
918 919 920 921
                  LOG_I(OTG,"send packet from module %d on rab id %d (src %d, dst %d) pkt size %d\n", enb_mod_idP, rb_id, src_id, dst_id, pkt_size);
                  free(otg_pkt);
              }
              /*else {
922 923
      LOG_I(OTG,"nothing generated (src %d, dst %d)\n",src_id, dst_id);
      }*/
gauthier's avatar
gauthier committed
924 925
          }
          /*else {
926
    LOG_I(OTG,"rrc_status (src %d, dst %d) = %d\n",src_id, dst_id, mac_get_rrc_status(src_id, enb_flagP, dst_id ));
927
    }*/
gauthier's avatar
gauthier committed
928
      }
929 930 931
  }
#endif
}