pdcp_fifo.c 43.1 KB
Newer Older
1
/*******************************************************************************
gauthier's avatar
gauthier committed
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

gauthier's avatar
gauthier committed
5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


gauthier's avatar
gauthier committed
11 12 13 14
    OpenAirInterface is distributed in the hope that 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.
15

gauthier's avatar
gauthier committed
16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
   see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
gauthier's avatar
gauthier committed
22 23 24 25
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

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

/*! \file pdcp_fifo.c
gauthier's avatar
gauthier committed
31 32 33 34 35 36 37
 * \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
 */
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

#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"
63
#include "NAS/DRIVER/LITE/constant.h"
64 65 66 67
#include "SIMULATION/ETH_TRANSPORT/extern.h"
#include "UTIL/OCG/OCG.h"
#include "UTIL/OCG/OCG_extern.h"
#include "UTIL/LOG/log.h"
68
#include "UTIL/OTG/otg_tx.h"
69
#include "UTIL/FIFO/pad_list.h"
70 71
#include "platform_constants.h"

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

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

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

#define MAX_PAYLOAD 1600

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

94
extern Packet_OTG_List_t *otg_pdcp_buffer;
95

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

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

//-----------------------------------------------------------------------------
103
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)
104 105 106
{
  //-----------------------------------------------------------------------------

gauthier's avatar
gauthier committed
107 108 109
  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
110 111
  uint8_t          cont             = 1;
#if defined(LINK_PDCP_TO_GTPV1U)
112
  //MessageDef      *message_p        = NULL;
gauthier's avatar
gauthier committed
113
#endif
114

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

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

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

gauthier's avatar
gauthier committed
125 126
#if defined(LINK_PDCP_TO_GTPV1U)
      if (enb_flagP) {
127
          LOG_I(PDCP,"Sending to GTPV1U %d bytes\n", ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
gauthier's avatar
gauthier committed
128 129 130 131 132 133 134 135
          /*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,
136 137
              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
138 139 140 141 142 143 144 145 146 147 148 149
              &(((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) */
150
#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
151 152 153
      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);
154
#endif //PDCP_DEBUG
gauthier's avatar
gauthier committed
155
      cont = 0;
156

gauthier's avatar
gauthier committed
157 158 159 160
      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);
          }
161 162

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

#else
#ifdef NAS_NETLINK
#ifdef LINUX
170
          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
171 172
              pdcp_output_header_bytes_to_write);
          nas_nlh_tx->nlmsg_len = pdcp_output_header_bytes_to_write;
173 174 175
#endif //LINUX
#endif //NAS_NETLINK

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

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

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

gauthier's avatar
gauthier committed
188 189
              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;
190 191

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

#ifdef NAS_NETLINK
#ifdef LINUX
gauthier's avatar
gauthier committed
197 198 199 200 201 202 203 204
                  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;
                  }
205 206
#endif // LINUX
#endif //NAS_NETLINK
gauthier's avatar
gauthier committed
207
                  bytes_wrote= pdcp_output_sdu_bytes_to_write;
208 209 210
#endif // NAS_FIFO

#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
211 212 213 214 215
                  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);
216
#endif //PDCP_DEBUG
gauthier's avatar
gauthier committed
217 218 219 220 221 222 223 224
                  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,
225
                              ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
gauthier's avatar
gauthier committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
                              ((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");
              }
242
          }
gauthier's avatar
gauthier committed
243 244
      } else {
          // continue writing sdu
245
#ifdef NAS_FIFO
gauthier's avatar
gauthier committed
246
          bytes_wrote = rtf_put (PDCP2NAS_FIFO,
247
              (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
248
              pdcp_output_sdu_bytes_to_write);
249
#else  // NAS_FIFO
gauthier's avatar
gauthier committed
250
          bytes_wrote = pdcp_output_sdu_bytes_to_write;
251 252
#endif  // NAS_FIFO

gauthier's avatar
gauthier committed
253 254 255 256 257 258 259 260 261 262 263 264 265
          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");
              }
          }
266 267 268 269
      }
  }
#ifdef NAS_FIFO
  if ((pdcp_nb_sdu_sent)) {
gauthier's avatar
gauthier committed
270
      if ((pdcp_2_nas_irq > 0)) {
271
#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
272 273
          LOG_I(PDCP, "Frame %d : Trigger NAS RX interrupt\n",
              frameP);
274 275
#endif //PDCP_DEBUG

gauthier's avatar
gauthier committed
276 277 278 279 280 281
          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);
      }
282 283 284 285 286 287 288 289 290 291 292 293
  }
#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
 */
294
int pdcp_fifo_read_input_sdus_remaining_bytes (frame_t frameP, eNB_flag_t enb_flagP)
295 296
{
  //-----------------------------------------------------------------------------
297
  sdu_size_t             bytes_read = 0;
gauthier's avatar
gauthier committed
298 299 300 301 302 303
  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;
304 305 306

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

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

gauthier's avatar
gauthier committed
314 315
          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;
316

gauthier's avatar
gauthier committed
317 318 319
          if (pdcp_input_sdu_remaining_size_to_read != 0) {
              return 0;
          } else {
320
#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
321 322 323 324 325
              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);
326
#endif //PDCP_DEBUG
gauthier's avatar
gauthier committed
327
              pdcp_input_sdu_size_read = 0;
328
#ifdef IDROMEL_NEMO
gauthier's avatar
gauthier committed
329
              pdcp_read_header_g.inst = 0;
330 331
#endif

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

              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,
358
                      (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
359 360 361 362 363 364 365 366
                      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) {
367 368 369 370 371 372 373 374 375 376 377 378
                      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
379 380 381
                      AssertFatal (result == TRUE, "PDCP data request failed!\n");
                  }

382
              } 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
383 384
                  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,
385
                      (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
386 387 388 389 390 391 392 393 394 395 396 397
                          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,
398
                          enb_flagP,
399
                          SRB_FLAG_NO,
gauthier's avatar
gauthier committed
400 401 402 403 404
                          rb_id,
                          RLC_MUI_UNDEFINED,
                          RLC_SDU_CONFIRM_NO,
                          pdcp_input_header.data_size,
                          pdcp_input_sdu_buffer,
405
                          PDCP_TRANSMISSION_MODE_TRANSPARENT);
gauthier's avatar
gauthier committed
406 407 408
                      AssertFatal (result == TRUE, "PDCP data request failed!\n");
                  }

409
              } else if (enb_flagP) {
gauthier's avatar
gauthier committed
410 411 412 413
                  // 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);
414
                      pdcp_p = &pdcp_array_drb_eNB[enb_inst][ue_inst][DEFAULT_RAB_ID-1];
gauthier's avatar
gauthier committed
415 416 417
                      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,
418
                              (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
419 420 421 422 423 424 425 426 427 428
                              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,
429
                              enb_flagP,
430
                              SRB_FLAG_NO,
gauthier's avatar
gauthier committed
431 432 433 434 435
                              DEFAULT_RAB_ID,
                              RLC_MUI_UNDEFINED,
                              RLC_SDU_CONFIRM_NO,
                              pdcp_input_header.data_size,
                              pdcp_input_sdu_buffer,
436
                              PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
437 438 439 440 441 442 443
                          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,
444
                      (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
445 446 447 448 449 450 451 452 453 454
                      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,
455
                      enb_flagP,
456
                      SRB_FLAG_NO,
gauthier's avatar
gauthier committed
457 458 459 460 461
                      DEFAULT_RAB_ID,
                      RLC_MUI_UNDEFINED,
                      RLC_SDU_CONFIRM_NO,
                      pdcp_input_header.data_size,
                      pdcp_input_sdu_buffer,
462
                      PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
463 464 465 466 467 468 469 470
                  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;
471 472 473 474 475 476
      }
  }
  return 1;
}

//-----------------------------------------------------------------------------
477
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)
478 479
{
#ifdef NAS_NETLINK
480
# if defined(ENABLE_PDCP_NETLINK_FIFO)
gauthier's avatar
gauthier committed
481 482 483
  module_id_t                    ue_id     = 0;
  rb_id_t                        rab_id    = 0;
  pdcp_t                        *pdcp      = NULL;
484
  pdcp_transmission_mode_t       pdcp_mode = PDCP_TRANSMISSION_MODE_UNKNOWN;
gauthier's avatar
gauthier committed
485 486
  struct pdcp_netlink_element_s *data      = NULL;

487
  while (pdcp_netlink_dequeue_element(enb_mod_idP, ue_mod_idP, enb_flagP, &data) != 0) {
gauthier's avatar
gauthier committed
488
      DevAssert(data != NULL);
489
      if (enb_flagP == 0) {
490 491
          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
492
      } else {
493 494 495
          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
496
      }
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
      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);
      }
520
      AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
gauthier's avatar
gauthier committed
521 522 523 524 525 526

      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,
527
                  (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
528 529 530 531 532 533
                      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);
534
#ifdef 	OAI_NW_DRIVER_TYPE_ETHERNET
535 536 537 538
              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)
539
                PDCP_TRANSMISSION_MODE_TRANSPARENT;
540 541 542 543 544 545 546 547
#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
548 549
                  LOG_W(PDCP,"unknown IP traffic type \n");
              }
550
#else // NASMESH driver does not curreenlty support multicast traffic
551
              pdcp_mode = PDCP_TRANSMISSION_MODE_DATA;
552
#endif
gauthier's avatar
gauthier committed
553 554 555
              pdcp_data_req(enb_mod_idP,
                  ue_mod_idP,
                  frameP,
556
                  enb_flagP,
557 558
                  SRB_FLAG_NO,
                  rab_id % maxDRB,
gauthier's avatar
gauthier committed
559 560 561 562 563 564
                  RLC_MUI_UNDEFINED,
                  RLC_SDU_CONFIRM_NO,
                  data->pdcp_read_header.data_size,
                  data->data,
                  pdcp_mode);
          } else {
565 566
              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
567
          }
568
      } else if (enb_flagP) {
gauthier's avatar
gauthier committed
569 570 571 572
          /* 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
           */
573 574
          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++) {
575
              pdcp = &pdcp_array_drb_eNB[enb_mod_idP][ue_id][DEFAULT_RAB_ID-1];
gauthier's avatar
gauthier committed
576
              if (pdcp->instanciated_instance) {
577
                  LOG_D(PDCP, "eNB Try Forcing send on DEFAULT_RAB_ID UE %d\n", ue_id);
gauthier's avatar
gauthier committed
578 579 580 581
                  pdcp_data_req(
                      enb_mod_idP,
                      ue_id,
                      frameP,
582
                      enb_flagP,
583
                      SRB_FLAG_NO,
gauthier's avatar
gauthier committed
584 585 586 587 588
                      DEFAULT_RAB_ID,
                      RLC_MUI_UNDEFINED,
                      RLC_SDU_CONFIRM_NO,
                      data->pdcp_read_header.data_size,
                      data->data,
589
                      PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
590 591 592 593 594 595 596 597
              }
          }
      } else {
          LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
          pdcp_data_req(
              enb_mod_idP,
              ue_mod_idP,
              frameP,
598
              enb_flagP,
599
              SRB_FLAG_NO,
gauthier's avatar
gauthier committed
600 601 602 603 604
              DEFAULT_RAB_ID,
              RLC_MUI_UNDEFINED,
              RLC_SDU_CONFIRM_NO,
              data->pdcp_read_header.data_size,
              data->data,
605
              PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
606 607 608 609 610 611 612
      }
      free(data->data);
      free(data);
      data = NULL;
  }
  return 0;
# else /* ENABLE_PDCP_NETLINK_FIFO*/
613 614
  int              len = 1;
  rb_id_t          rab_id  = 0;
615
  while (len > 0) {
gauthier's avatar
gauthier committed
616 617 618 619 620 621 622 623
      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)) {
624

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

gauthier's avatar
gauthier committed
630 631 632 633 634 635 636 637 638
              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);
639
                  } else {
gauthier's avatar
gauthier committed
640 641 642 643 644 645
                      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()
646
#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
647 648
                  LOG_I(PDCP, "[PDCP][FIFO] Something in socket, length %d \n",
                      nas_nlh_rx->nlmsg_len - sizeof(struct nlmsghdr));
649
#endif
gauthier's avatar
gauthier committed
650 651
                  //memcpy(pdcp_read_payload, (unsigned char *)NLMSG_DATA(nas_nlh_rx), nas_nlh_rx->nlmsg_len - sizeof(struct nlmsghdr));

652
#ifdef OAI_EMU
gauthier's avatar
gauthier committed
653 654
                  // overwrite function input parameters, because only one netlink socket for all instances
                  if (pdcp_read_header_g.inst < oai_emulation.info.nb_enb_local) {
655
                      enb_flagP  = 1;
656
                      ue_mod_idP  = pdcp_read_header_g.rb_id / maxDRB + oai_emulation.info.first_ue_local;
gauthier's avatar
gauthier committed
657
                      enb_mod_idP = pdcp_read_header_g.inst  +  oai_emulation.info.first_enb_local;
658
                      rab_id    = pdcp_read_header_g.rb_id % maxDRB;
gauthier's avatar
gauthier committed
659
                  } else {
660
                      enb_flagP  = 0;
gauthier's avatar
gauthier committed
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
                      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);
681
                  AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
gauthier's avatar
gauthier committed
682 683 684 685 686
                  /*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;
687 688 689 690 691 692 693 694 695 696
#warning "TO DO CORRCT VALUES FOR ue mod id, enb mod id"
                  if (enb_flagP) {
		    ue_mod_idP  = 0;
		    enb_mod_idP = 0;
		    rab_id      = pdcp_read_header_g.rb_id % maxDRB;
		  } else {
		    ue_mod_idP  = 0;
		    enb_mod_idP = 0;
		    rab_id      = pdcp_read_header_g.rb_id % maxDRB;
		  }
gauthier's avatar
gauthier committed
697 698
#endif

699
                  if (enb_flagP) {
gauthier's avatar
gauthier committed
700
                      if (rab_id != 0) {
701 702
                          rab_id = rab_id % maxDRB;
                          if (pdcp_array_drb_eNB[enb_mod_idP][ue_mod_idP][rab_id-1].instanciated_instance) {
703
#ifdef PDCP_DEBUG
gauthier's avatar
gauthier committed
704 705 706 707 708 709
                              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);
710 711
#endif

gauthier's avatar
gauthier committed
712 713 714 715 716 717 718 719 720
                              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);

721
                              pdcp_data_req(enb_mod_idP,ue_mod_idP,frameP, enb_flagP,SRB_FLAG_NO,
gauthier's avatar
gauthier committed
722 723 724 725 726
                                  rab_id,
                                  RLC_MUI_UNDEFINED,
                                  RLC_SDU_CONFIRM_NO,
                                  pdcp_read_header_g.data_size,
                                  (unsigned char *)NLMSG_DATA(nas_nlh_rx),
727
                                  PDCP_TRANSMISSION_MODE_DATA);
728
                          } else {
gauthier's avatar
gauthier committed
729 730 731 732 733 734 735 736
                              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);
737
                          }
gauthier's avatar
gauthier committed
738
                      } else  { // rb_id =0, thus interpreated as broadcast and transported as multiple unicast
739
                          // is a broadcast packet, we have to send this packet on all default RABS of all connected UEs
gauthier's avatar
gauthier committed
740
#warning CODE TO BE REVIEWED, ONLY WORK FOR SIMPLE TOPOLOGY CASES
741
                          for (ue_mod_idP = 0; ue_mod_idP < NB_UE_INST; ue_mod_idP++) {
742
                              if (pdcp_array_drb_eNB[enb_mod_idP][ue_mod_idP][rab_id-1].instanciated_instance == TRUE) {
gauthier's avatar
gauthier committed
743 744 745 746 747 748 749 750 751 752 753 754
                                  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,
755
                                      enb_flagP,
756
                                      SRB_FLAG_NO,
gauthier's avatar
gauthier committed
757 758 759 760 761
                                      DEFAULT_RAB_ID,
                                      RLC_MUI_UNDEFINED,
                                      RLC_SDU_CONFIRM_NO,
                                      pdcp_read_header_g.data_size,
                                      (unsigned char *)NLMSG_DATA(nas_nlh_rx),
762
                                      PDCP_TRANSMISSION_MODE_DATA);
763 764
                              }
                          }
gauthier's avatar
gauthier committed
765 766 767
                      }
                  } else {
                      if (rab_id != 0) {
768
                          if (pdcp_array_drb_ue[ue_mod_idP][rab_id-1].instanciated_instance) {
gauthier's avatar
gauthier committed
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
#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
786

gauthier's avatar
gauthier committed
787 788 789 790
                              pdcp_data_req(
                                  enb_mod_idP,
                                  ue_mod_idP,
                                  frameP,
791
                                  enb_flagP,
792
                                  SRB_FLAG_NO,
gauthier's avatar
gauthier committed
793 794 795 796 797
                                  rab_id,
                                  RLC_MUI_UNDEFINED,
                                  RLC_SDU_CONFIRM_NO,
                                  pdcp_read_header_g.data_size,
                                  (unsigned char *)NLMSG_DATA(nas_nlh_rx),
798
                                  PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
                          } 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,
823
                              enb_flagP,
824
                              SRB_FLAG_NO,
gauthier's avatar
gauthier committed
825 826 827 828 829
                              DEFAULT_RAB_ID,
                              RLC_MUI_UNDEFINED,
                              RLC_SDU_CONFIRM_NO,
                              pdcp_read_header_g.data_size,
                              (unsigned char *)NLMSG_DATA(nas_nlh_rx),
830
                              PDCP_TRANSMISSION_MODE_DATA);
831 832
                      }
                  }
gauthier's avatar
gauthier committed
833

834 835
              }
          }
gauthier's avatar
gauthier committed
836
      }
837
  }
838
  return len;
839
# endif
840 841 842 843 844 845
#else // neither NAS_NETLINK nor NAS_FIFO
  return 0;
#endif // NAS_NETLINK
}


846 847 848 849 850
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;
nikaeinn's avatar
nikaeinn committed
851 852
  signed long          pkt_size=0;
  static unsigned int  pkt_cnt_enb=0, pkt_cnt_ue=0;
853 854 855
  uint8_t              pdcp_mode, is_ue=0;
  Packet_otg_elt_t    *otg_pkt_info=NULL;
  int                  result;
856

gauthier's avatar
gauthier committed
857
  src_id = enb_mod_idP;
858

859 860 861
  // 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 ){
862
      module_id = (enb_flagP == 1) ?  enb_mod_idP : ue_mod_idP+NB_eNB_INST;
863
      //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
864 865 866 867 868 869 870 871 872 873 874 875 876
      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
877
          // 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
878
          otg_pkt = (unsigned char*) (otg_pkt_info->otg_pkt).sdu_buffer;
gauthier's avatar
gauthier committed
879 880 881
          pkt_size = (otg_pkt_info->otg_pkt).sdu_buffer_size;
          if (otg_pkt != NULL) {
              if (is_ue == 0 ) {
nikaeinn's avatar
nikaeinn committed
882
		/*rlc_util_print_hex_octets(PDCP,
883
                                            otg_pkt,
884
                                            pkt_size);
nikaeinn's avatar
nikaeinn committed
885
		*/
gauthier's avatar
gauthier committed
886 887
                  //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",
nikaeinn's avatar
nikaeinn committed
888 889
                      enb_mod_idP, frameP, pkt_cnt_enb++, module_id, rb_id, module_id, dst_id, pkt_size, pdcp_mode);
                  result = 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_mode);
gauthier's avatar
gauthier committed
890 891 892 893
                  AssertFatal (result == TRUE, "PDCP data request failed!\n");
              }
              else {
                  //rb_id= eNB_index * MAX_NUM_RB + DTCH;
894 895


nikaeinn's avatar
nikaeinn committed
896 897 898
                  LOG_D(OTG,"[UE %d] Frame %d: sending packet %d from module %d on rab id %d (src %d, dst %d) pkt size %d\n",
			ue_mod_idP, frameP, pkt_cnt_ue++, src_id, rb_id, src_id, dst_id, pkt_size);
                  result = pdcp_data_req( dst_id,
899 900 901
                                          ue_mod_idP,
                                          frameP,
                                          enb_flagP,
902
                                          SRB_FLAG_NO,
903 904 905 906 907 908
                                          rb_id,
                                          RLC_MUI_UNDEFINED,
                                          RLC_SDU_CONFIRM_NO,
                                          pkt_size,
                                          otg_pkt,
                                          PDCP_TRANSMISSION_MODE_DATA);
gauthier's avatar
gauthier committed
909 910 911 912 913
                  AssertFatal (result == TRUE, "PDCP data request failed!\n");
              }
              free(otg_pkt);
              otg_pkt = NULL;
          }
914
          // } //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
915

916 917 918
      }
  }
#else
919
  if ((otg_enabled==1) && (enb_flagP == 1)) { // generate DL traffic
gauthier's avatar
gauthier committed
920 921 922
      unsigned int ctime=0;
      ctime = frameP * 100;

923 924
      /*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
925
      for (dst_id = 0; dst_id<NUMBER_OF_UE_MAX; dst_id++) {
926
          if (mac_get_rrc_status(enb_mod_idP, enb_flagP, dst_id ) > 2) {
gauthier's avatar
gauthier committed
927 928
              otg_pkt=packet_gen(src_id, dst_id, 0, ctime, &pkt_size);
              if (otg_pkt != NULL){
929 930
                  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
931 932 933 934
                  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 {
935 936
      LOG_I(OTG,"nothing generated (src %d, dst %d)\n",src_id, dst_id);
      }*/
gauthier's avatar
gauthier committed
937 938
          }
          /*else {
939
    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 ));
940
    }*/
gauthier's avatar
gauthier committed
941
      }
942 943 944
  }
#endif
}