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

/*! \file pdcp_fifo.c
gauthier's avatar
gauthier committed
23
 * \brief pdcp interface with linux IP interface, have a look at http://man7.org/linux/man-pages/man7/netlink.7.html for netlink
24 25
 * \author  Navid Nikaein and Lionel GAUTHIER
 * \date 2009 - 2016
gauthier's avatar
gauthier committed
26
 * \version 0.5
27
 * \email navid.nikaein@eurecom.fr
gauthier's avatar
gauthier committed
28 29 30
 * \warning This component can be runned only in user-space
 * @ingroup pdcp
 */
31 32 33

#define PDCP_FIFO_C
#define PDCP_DEBUG 1
34
//#define DEBUG_PDCP_FIFO_FLUSH_SDU
35 36 37 38 39 40 41 42 43

#ifndef OAI_EMU
extern int otg_enabled;
#endif

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

#ifdef USER_MODE
44
#include <pthread.h>
45 46 47 48 49 50 51 52 53 54 55 56
#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"
57
#include "NETWORK_DRIVER/LITE/constant.h"
58 59 60 61
#include "SIMULATION/ETH_TRANSPORT/extern.h"
#include "UTIL/OCG/OCG.h"
#include "UTIL/OCG/OCG_extern.h"
#include "UTIL/LOG/log.h"
62
#include "UTIL/OTG/otg_tx.h"
63
#include "UTIL/FIFO/pad_list.h"
64
#include "UTIL/LOG/vcd_signal_dumper.h"
65
#include "platform_constants.h"
gauthier's avatar
msc  
gauthier committed
66
#include "msc.h"
67
#include "pdcp.h"
68

69
#include "assertions.h"
70

71
#ifdef PDCP_USE_NETLINK
72 73
#include <sys/socket.h>
#include <linux/netlink.h>
74
#include "NETWORK_DRIVER/UE_IP/constant.h"
75

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

gauthier's avatar
gauthier committed
86
unsigned char pdcp_read_state_g = 0;
87 88
#endif

89
extern Packet_OTG_List_t *otg_pdcp_buffer;
90

91
#if defined(LINK_ENB_PDCP_TO_GTPV1U)
92
#  include "gtpv1u_eNB_task.h"
Cedric Roux's avatar
Cedric Roux committed
93
#  include "gtpv1u_eNB_defs.h"
gauthier's avatar
gauthier committed
94 95
#endif

96 97
extern int gtpv1u_new_data_req( uint8_t  enb_module_idP, rnti_t   ue_rntiP, uint8_t  rab_idP, uint8_t *buffer_pP, uint32_t buf_lenP, uint32_t buf_offsetP);

98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
/* Prevent de-queueing the same PDCP SDU from the queue twice
 * by multiple threads. This has happened in TDD when thread-odd
 * is flushing a PDCP SDU after UE_RX() processing; whereas
 * thread-even is at a special-subframe, skips the UE_RX() process
 * and goes straight to the PDCP SDU flushing. The 2nd flushing
 * dequeues the same SDU again causing unexpected behavior.
 *
 * comment out the MACRO below to disable this protection
 */
#define PDCP_SDU_FLUSH_LOCK

#ifdef PDCP_SDU_FLUSH_LOCK
static pthread_mutex_t mtex = PTHREAD_MUTEX_INITIALIZER;
#endif

gauthier's avatar
gauthier committed
113
pdcp_data_req_header_t pdcp_read_header_g;
114 115

//-----------------------------------------------------------------------------
116
int pdcp_fifo_flush_sdus(const protocol_ctxt_t* const  ctxt_pP)
117
{
118
   //-----------------------------------------------------------------------------
119

120 121 122
   //#if defined(PDCP_USE_NETLINK) && defined(LINUX)
   int ret = 0;
   //#endif
123

124 125
#ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
#define THREAD_NAME_LEN 16
126 127 128 129 130 131 132
   static char threadname[THREAD_NAME_LEN];
   ret = pthread_getname_np(pthread_self(), threadname, THREAD_NAME_LEN);
   if (ret != 0)
   {
      perror("pthread_getname_np : ");
      exit_fun("Error getting thread name");
   }
133 134 135
#undef THREAD_NAME_LEN
#endif

136
#ifdef PDCP_SDU_FLUSH_LOCK
137 138
   ret = pthread_mutex_trylock(&mtex);
   if (ret == EBUSY) {
139
#ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
140 141
      LOG_W(PDCP, "[%s] at SFN/SF=%d/%d wait for PDCP FIFO to be unlocked\n",
            threadname, ctxt_pP->frame, ctxt_pP->subframe);
142
#endif
143 144 145
      if (pthread_mutex_lock(&mtex)) {
         exit_fun("PDCP_SDU_FLUSH_LOCK lock error!");
      }
146
#ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
147 148
      LOG_I(PDCP, "[%s] at SFN/SF=%d/%d PDCP FIFO is unlocked\n",
            threadname, ctxt_pP->frame, ctxt_pP->subframe);
149
#endif
150 151 152
   } else if (ret != 0) {
      exit_fun("PDCP_SDU_FLUSH_LOCK trylock error!");
   }
153 154 155

#endif

156 157 158 159
   mem_block_t     *sdu_p            = list_get_head (&pdcp_sdu_list);
   int              bytes_wrote      = 0;
   int              pdcp_nb_sdu_sent = 0;
   uint8_t          cont             = 1;
160
#if defined(LINK_ENB_PDCP_TO_GTPV1U)
161
   //MessageDef      *message_p        = NULL;
162 163
#endif

164 165
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH, 1 );
   while (sdu_p && cont) {
166

167
#ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
168 169 170 171
      LOG_D(PDCP, "[%s] SFN/SF=%d/%d inst=%d size=%d\n",
            threadname, ctxt_pP->frame, ctxt_pP->subframe,
            ((pdcp_data_ind_header_t*) sdu_p->data)->inst,
            ((pdcp_data_ind_header_t *) sdu_p->data)->data_size);
172
#else
173
      ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
174
#endif
175

176
#if defined(LINK_ENB_PDCP_TO_GTPV1U)
gauthier's avatar
gauthier committed
177

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
      if (ctxt_pP->enb_flag) {
         AssertFatal(0, "Now execution should not go here");
         LOG_D(PDCP,"Sending to GTPV1U %d bytes\n", ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
         gtpv1u_new_data_req(
               ctxt_pP->module_id, //gtpv1u_data_t *gtpv1u_data_p,
               ctxt_pP->rnti,//rb_id/maxDRB, TO DO UE ID
               ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id + 4,
               &(((uint8_t *) sdu_p->data)[sizeof (pdcp_data_ind_header_t)]),
               ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size,
               0);

         list_remove_head (&pdcp_sdu_list);
         free_mem_block (sdu_p, __func__);
         cont = 1;
         pdcp_nb_sdu_sent += 1;
         sdu_p = list_get_head (&pdcp_sdu_list);
         LOG_D(OTG,"After  GTPV1U\n");
         continue; // loop again
      }
197

gauthier's avatar
gauthier committed
198
#endif /* defined(ENABLE_USE_MME) */
199
#ifdef PDCP_DEBUG
200 201 202
      LOG_D(PDCP, "PDCP->IP TTI %d INST %d: Preparing %d Bytes of data from rab %d to Nas_mesh\n",
            ctxt_pP->frame, ((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);
203
#endif //PDCP_DEBUG
204 205 206 207 208 209
      cont = 0;

//TTN - for D2D (PC5S)
#ifdef Rel14
      sidelink_pc5s_element *sl_pc5s_msg_recv = NULL;
      char send_buf[BUFSIZE];
210
      int rb_id = ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id;
211

212 213
      if (rb_id == 10) { //hardcoded for PC5-Signaling
      //if ((rb_id == 28) | (rb_id == 29) | (rb_id == 30))
214 215 216 217

#ifdef PDCP_DEBUG
         sl_pc5s_msg_recv = calloc(1, sizeof(sidelink_pc5s_element));
         memcpy((void*)sl_pc5s_msg_recv, (void*)(sdu_p->data+sizeof(pdcp_data_ind_header_t)), sizeof(sidelink_pc5s_element));
218
         LOG_D(PDCP,"Received PC5S message, header traffic_type: %d)\n", sl_pc5s_msg_recv->pdcp_data_header.traffic_type);
219 220 221
         LOG_D(PDCP,"Received PC5S message, header rb_id: %d)\n", sl_pc5s_msg_recv->pdcp_data_header.rb_id);
         LOG_D(PDCP,"Received PC5S message, header data_size: %d)\n", sl_pc5s_msg_recv->pdcp_data_header.data_size);
         LOG_D(PDCP,"Received PC5S message, header inst: %d)\n", sl_pc5s_msg_recv->pdcp_data_header.inst);
222 223 224
         LOG_D(PDCP,"Received PC5-S message, sourceL2Id: 0x%08x\n)\n", sl_pc5s_msg_recv->pdcp_data_header.sourceL2Id);
         LOG_D(PDCP,"Received PC5-S message, destinationL1Id: 0x%08x\n)\n", sl_pc5s_msg_recv->pdcp_data_header.destinationL2Id);
         free(sl_pc5s_msg_recv);
225 226 227 228
#endif
         memset(send_buf, 0, BUFSIZE);
         memcpy((void *)send_buf, (void*)(sdu_p->data+sizeof(pdcp_data_ind_header_t)), sizeof(sidelink_pc5s_element));

229 230
         int prose_addr_len = sizeof(prose_pdcp_addr);
         int n = sendto(pdcp_pc5_sockfd, (char *)send_buf, sizeof(sidelink_pc5s_element), 0, (struct sockaddr *)&prose_pdcp_addr, prose_addr_len);
231 232 233 234
         if (n < 0) {
            LOG_E(PDCP, "ERROR: Failed to send to ProSe App\n");
            exit(EXIT_FAILURE);
         }
235
      }
236 237 238 239 240 241
#endif

      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);
         }
242

243
#ifdef PDCP_USE_RT_FIFO
244 245 246
         bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO,
               &(((uint8_t *) sdu->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
               pdcp_output_header_bytes_to_write);
247 248

#else
249
#ifdef PDCP_USE_NETLINK
250
#ifdef LINUX
251 252 253
         memcpy(NLMSG_DATA(nas_nlh_tx), &(((uint8_t *) sdu_p->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
               pdcp_output_header_bytes_to_write);
         nas_nlh_tx->nlmsg_len = pdcp_output_header_bytes_to_write;
254
#endif //LINUX
255
#endif //PDCP_USE_NETLINK
256

257
         bytes_wrote = pdcp_output_header_bytes_to_write;
258
#endif //PDCP_USE_RT_FIFO
259 260

#ifdef PDCP_DEBUG
261 262 263
         LOG_D(PDCP, "Frame %d Sent %d Bytes of header to Nas_mesh\n",
               ctxt_pP->frame,
               bytes_wrote);
264 265
#endif //PDCP_DEBUG

266 267
         if (bytes_wrote > 0) {
            pdcp_output_header_bytes_to_write = pdcp_output_header_bytes_to_write - bytes_wrote;
268

269 270 271
            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;
               AssertFatal(pdcp_output_sdu_bytes_to_write >= 0, "invalid data_size!");
272

273
#ifdef PDCP_USE_RT_FIFO
274
               bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO, &(sdu->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
275 276
#else

277
#ifdef PDCP_USE_NETLINK
278
#ifdef LINUX
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
               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;
               VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_UE_PDCP_FLUSH_SIZE, pdcp_output_sdu_bytes_to_write);
               VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH_BUFFER, 1 );
               ret = sendmsg(nas_sock_fd,&nas_msg_tx,0);
               VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH_BUFFER, 0 );
               VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_UE_PDCP_FLUSH_ERR, ret );

               if (ret<0) {
                  LOG_E(PDCP, "[PDCP_FIFOS] sendmsg returns %d (errno: %d)\n", ret, errno);
                  MSC_LOG_TX_MESSAGE_FAILED(
                        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
                                    NULL,
                                    0,
                                    MSC_AS_TIME_FMT" DATA-IND RNTI %"PRIx16" rb %u size %u",
                                    MSC_AS_TIME_ARGS(ctxt_pP),
                                    ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
                                    ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
                  AssertFatal(1==0,"sendmsg failed for nas_sock_fd\n");
                  break;
               } else {
                  MSC_LOG_TX_MESSAGE(
                        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
                                    NULL,
                                    0,
                                    MSC_AS_TIME_FMT" DATA-IND RNTI %"PRIx16" rb %u size %u",
                                    MSC_AS_TIME_ARGS(ctxt_pP),
                                    ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
                                    ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
               }
311

312
#endif // LINUX
313
#endif //PDCP_USE_NETLINK
314
               bytes_wrote= pdcp_output_sdu_bytes_to_write;
315
#endif // PDCP_USE_RT_FIFO
316 317

#ifdef PDCP_DEBUG
318 319 320 321 322
               LOG_D(PDCP, "PDCP->IP Frame %d INST %d: Sent %d Bytes of data from rab %d to higher layers\n",
                     ctxt_pP->frame,
                     ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
                     bytes_wrote,
                     ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
323
#endif //PDCP_DEBUG
324

325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
               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",
                           ctxt_pP->frame,
                           ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
                           ((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, __func__);
                     cont = 1;
                     pdcp_nb_sdu_sent += 1;
                     sdu_p = list_get_head (&pdcp_sdu_list);
                  } else {
                     LOG_D(PDCP, "1 skip free_mem_block: pdcp_output_sdu_bytes_to_write = %d\n", pdcp_output_sdu_bytes_to_write);
                     AssertFatal(pdcp_output_sdu_bytes_to_write > 0, "pdcp_output_sdu_bytes_to_write cannot be negative!");
                  }
               } else {
                  LOG_W(PDCP, "2: RADIO->IP SEND SDU CONGESTION!\n");
               }
350
            } else {
351
               LOG_W(PDCP, "3: RADIO->IP SEND SDU CONGESTION!\n");
352
            }
353 354 355
         } else {
            LOG_D(PDCP, "4 skip free_mem_block: bytes_wrote = %d\n", bytes_wrote);
         }
356
      } else {
357
         // continue writing sdu
358
#ifdef PDCP_USE_RT_FIFO
359 360 361
         bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO,
               (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])),
               pdcp_output_sdu_bytes_to_write);
362
#else  // PDCP_USE_RT_FIFO
363
         bytes_wrote = pdcp_output_sdu_bytes_to_write;
364
#endif  // PDCP_USE_RT_FIFO
365
         LOG_D(PDCP, "THINH 2 bytes_wrote = %d\n", bytes_wrote);
366

367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
         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, __func__);
               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");
            } else {
               LOG_D(PDCP, "5 skip free_mem_block: pdcp_output_sdu_bytes_to_write = %d\n", pdcp_output_sdu_bytes_to_write);
            }
         } else {
            LOG_D(PDCP, "6 skip free_mem_block: bytes_wrote = %d\n", bytes_wrote);
         }
384
      }
385 386
   }
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH, 0 );
387

388
#ifdef PDCP_USE_RT_FIFO
389

390 391
   if ((pdcp_nb_sdu_sent)) {
      if ((pdcp_2_nas_irq > 0)) {
392
#ifdef PDCP_DEBUG
393 394
         LOG_D(PDCP, "Frame %d : Trigger NAS RX interrupt\n",
               ctxt_pP->frame);
395
#endif //PDCP_DEBUG
396
         rt_pend_linux_srq (pdcp_2_nas_irq);
397

398 399 400 401 402 403
      } else {
         LOG_E(PDCP, "Frame %d: ERROR IF IP STACK WANTED : NOTIF PACKET(S) pdcp_2_nas_irq not initialized : %d\n",
               ctxt_pP->frame,
               pdcp_2_nas_irq);
      }
   }
404

405
#endif  //PDCP_USE_RT_FIFO
406

407
#ifdef PDCP_SDU_FLUSH_LOCK
408
   if (pthread_mutex_unlock(&mtex)) exit_fun("PDCP_SDU_FLUSH_LOCK unlock error!");
409 410
#endif

411
   return pdcp_nb_sdu_sent;
412 413 414
}

//-----------------------------------------------------------------------------
415
int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
416
{
417
#ifdef PDCP_USE_NETLINK
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
   protocol_ctxt_t                ctxt_cpy = *ctxt_pP;
   protocol_ctxt_t                ctxt;
   hash_key_t                     key       = HASHTABLE_NOT_A_KEY_VALUE;
   hashtable_rc_t                 h_rc;
   struct pdcp_netlink_element_s* data_p    = NULL;
   /* avoid gcc warnings */
   (void)data_p;
   module_id_t                    ue_id     = 0;
   pdcp_t*                        pdcp_p    = NULL;

//TTN for D2D (PC5S)
#ifdef Rel14
   int prose_addr_len;
   char send_buf[BUFSIZE], receive_buf[BUFSIZE];
   int optval;
   int bytes_received;
   sidelink_pc5s_element *sl_pc5s_msg_recv = NULL;
   sidelink_pc5s_element *sl_pc5s_msg_send = NULL;
   uint32_t sourceL2Id;
   uint32_t groupL2Id;
   module_id_t         module_id = 0;
   pdcp_data_header_t *pdcp_data_header;
#endif
441

442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
# if defined(PDCP_USE_NETLINK_QUEUES)
   rb_id_t                        rab_id    = 0;

   pdcp_transmission_mode_t       pdcp_mode = PDCP_TRANSMISSION_MODE_UNKNOWN;


   while (pdcp_netlink_dequeue_element(ctxt_pP, &data_p) != 0) {
      DevAssert(data_p != NULL);
      rab_id = data_p->pdcp_read_header.rb_id % maxDRB;
      // ctxt_pP->rnti is NOT_A_RNTI
      ctxt_cpy.rnti = pdcp_module_id_to_rnti[ctxt_cpy.module_id][data_p->pdcp_read_header.inst];
      key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_cpy.rnti, ctxt_pP->enb_flag, rab_id, SRB_FLAG_NO);
      h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);

      if (h_rc != HASH_TABLE_OK) {
         LOG_W(PDCP, PROTOCOL_CTXT_FMT" Dropped IP PACKET cause no PDCP instanciated\n",
               PROTOCOL_CTXT_ARGS(ctxt_pP));
         free(data_p->data);
         free(data_p);
         data_p = NULL;
         continue;
      }
gauthier's avatar
gauthier committed
464

465
      CHECK_CTXT_ARGS(&ctxt_cpy);
gauthier's avatar
gauthier committed
466

467
      AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
468

469 470 471 472 473 474 475 476 477 478
      if (rab_id != 0) {
         LOG_I(PDCP, "[FRAME %05d][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ "
               "/ %d Bytes --->][PDCP][MOD %u][RB %u]\n",
               ctxt_cpy.frame,
               (ctxt_cpy.enb_flag) ? "eNB" : "UE",
                     data_p->pdcp_read_header.inst,
                     data_p->pdcp_read_header.rb_id,
                     data_p->pdcp_read_header.data_size,
                     ctxt_cpy.module_id,
                     rab_id);
479 480
#ifdef  OAI_NW_DRIVER_TYPE_ETHERNET

481 482 483
         if ((data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV6_TYPE_MULTICAST) /*TRAFFIC_IPV6_TYPE_MULTICAST */ ||
               (data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_MULTICAST) /*TRAFFIC_IPV4_TYPE_MULTICAST */ ||
               (data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_BROADCAST) /*TRAFFIC_IPV4_TYPE_BROADCAST */ ) {
Cedric Roux's avatar
Cedric Roux committed
484
#if defined(Rel10) || defined(Rel14)
485
            PDCP_TRANSMISSION_MODE_TRANSPARENT;
486
#else
487
            pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
488
#endif
489 490 491 492 493 494 495
         } else if ((data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV6_TYPE_UNICAST) /* TRAFFIC_IPV6_TYPE_UNICAST */ ||
               (data_p->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;
            LOG_W(PDCP,"unknown IP traffic type \n");
         }
496

497
#else // OAI_NW_DRIVER_TYPE_ETHERNET NASMESH driver does not curreenlty support multicast traffic
498
         pdcp_mode = PDCP_TRANSMISSION_MODE_DATA;
499
#endif
500 501 502 503 504 505 506
         pdcp_data_req(&ctxt_cpy,
               SRB_FLAG_NO,
               rab_id % maxDRB,
               RLC_MUI_UNDEFINED,
               RLC_SDU_CONFIRM_NO,
               data_p->pdcp_read_header.data_size,
               data_p->data,
507 508 509 510 511
               pdcp_mode
#ifdef Rel14
               ,NULL, NULL
#endif
               );
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
      } else if (ctxt_cpy.enb_flag) {
         /* 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
          */
         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++) {
            if (pdcp_module_id_to_rnti[ctxt_cpy.module_id][ue_id] != NOT_A_RNTI) {
               LOG_D(PDCP, "eNB Try Forcing send on DEFAULT_RAB_ID UE %d\n", ue_id);
               ctxt.module_id     = ctxt_cpy.module_id;
               ctxt.rnti          = ctxt_cpy.pdcp_module_id_to_rnti[ctxt_cpy.module_id][ue_id];
               ctxt.frame         = ctxt_cpy.frame;
               ctxt.enb_flag      = ctxt_cpy.enb_flag;

               pdcp_data_req(
                     &ctxt,
                     SRB_FLAG_NO,
                     DEFAULT_RAB_ID,
                     RLC_MUI_UNDEFINED,
                     RLC_SDU_CONFIRM_NO,
                     data_p->pdcp_read_header.data_size,
                     data_p->data,
535 536 537 538 539
                     PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
                     ,NULL, NULL
#endif
                     );
540 541 542 543 544 545 546 547 548 549 550 551
            }
         }
      } else {
         LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
         pdcp_data_req(
               &ctxt_cpy,
               SRB_FLAG_NO,
               DEFAULT_RAB_ID,
               RLC_MUI_UNDEFINED,
               RLC_SDU_CONFIRM_NO,
               data_p->pdcp_read_header.data_size,
               data_p->data,
552 553 554 555 556
               PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
               ,NULL, NULL
#endif
               );
557
      }
558

559 560 561 562
      free(data_p->data);
      free(data_p);
      data_p = NULL;
   }
563

564
   return 0;
565
# else /* PDCP_USE_NETLINK_QUEUES*/
566 567 568 569 570 571 572 573
   int              len = 1;
   int  msg_len;
   rb_id_t          rab_id  = 0;
   int rlc_data_req_flag = 3;


//TTN for D2D (PC5S)
#ifdef Rel14
574
   prose_addr_len = sizeof(prose_pdcp_addr);
575 576 577
   // receive a message from ProSe App
   memset(receive_buf, 0, BUFSIZE);
   bytes_received = recvfrom(pdcp_pc5_sockfd, receive_buf, BUFSIZE, 0,
578
         (struct sockaddr *) &prose_pdcp_addr, &prose_addr_len);
579 580 581 582 583 584 585 586
   //  if (bytes_received < 0){
   //    LOG_E(RRC, "ERROR: Failed to receive from ProSe App\n");
   //    exit(EXIT_FAILURE);
   // }
   if (bytes_received > 0) {
      pdcp_data_header = calloc(1, sizeof(pdcp_data_header_t));
      memcpy((void *)pdcp_data_header, (void *)receive_buf, sizeof(pdcp_data_header_t));

587
      if (pdcp_data_header->traffic_type == TRAFFIC_PC5S_SESSION_INIT){
588
         //send reply to ProSe app
589
         LOG_D(PDCP,"Received a request to open PDCP socket and establish a new PDCP session ... send response to ProSe App \n");
590 591
         memset(send_buf, 0, BUFSIZE);
         sl_pc5s_msg_send = calloc(1, sizeof(sidelink_pc5s_element));
592
         sl_pc5s_msg_send->pdcp_data_header.traffic_type = TRAFFIC_PC5S_SESSION_INIT;
593 594 595
         sl_pc5s_msg_send->pc5sPrimitive.status = 1;

         memcpy((void *)send_buf, (void *)sl_pc5s_msg_send, sizeof(sidelink_pc5s_element));
596 597
         int prose_addr_len = sizeof(prose_pdcp_addr);
         int bytes_sent = sendto(pdcp_pc5_sockfd, (char *)send_buf, sizeof(sidelink_pc5s_element), 0, (struct sockaddr *)&prose_pdcp_addr, prose_addr_len);
598 599 600 601
         if (bytes_sent < 0) {
            LOG_E(PDCP, "ERROR: Failed to send to ProSe App\n");
            exit(EXIT_FAILURE);
         }
602 603
      } else if (pdcp_data_header->traffic_type == TRAFFIC_PC5S_SIGNALLING) { //if containing PC5-S message -> send to other UE
         LOG_D(PDCP,"Received PC5-S message ... send to the other UE\n");
604
#ifdef PDCP_DEBUG
605 606 607 608 609 610
         LOG_D(PDCP,"Received PC5-S message, traffic_type: %d)\n", pdcp_data_header->traffic_type);
         LOG_D(PDCP,"Received PC5-S message, rbid: %d)\n", pdcp_data_header->rb_id);
         LOG_D(PDCP,"Received PC5-S message, data_size: %d)\n", pdcp_data_header->data_size);
         LOG_D(PDCP,"Received PC5-S message, inst: %d)\n", pdcp_data_header->inst);
         LOG_D(PDCP,"Received PC5-S message,sourceL2Id: 0x%08x\n)\n", pdcp_data_header->sourceL2Id);
         LOG_D(PDCP,"Received PC5-S message,destinationL1Id: 0x%08x\n)\n", pdcp_data_header->destinationL2Id);
611

612
#endif
gauthier's avatar
gauthier committed
613

614
#ifdef OAI_EMU
615

616 617
         // overwrite function input parameters, because only one netlink socket for all instances
         if (pdcp_data_header->inst < oai_emulation.info.nb_enb_local) {
618 619
            ctxt.frame         = ctxt_cpy.frame;
            ctxt.enb_flag      = ENB_FLAG_YES;
620 621 622 623
            ctxt.module_id     = pdcp_data_header.inst  +  oai_emulation.info.first_enb_local;
            ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pdcp_data_header->rb_id / maxDRB + oai_emulation.info.first_ue_local];
            rab_id    = pdcp_data_header->rb_id % maxDRB;
         } else {
624 625
            ctxt.frame         = ctxt_cpy.frame;
            ctxt.enb_flag      = ENB_FLAG_NO;
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
            ctxt.module_id     = pdcp_data_header->inst - oai_emulation.info.nb_enb_local + oai_emulation.info.first_ue_local;
            ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
            rab_id    = pdcp_data_header->rb_id % maxDRB;
         }

         CHECK_CTXT_ARGS(&ctxt);
         AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
         /*LGpdcp_read_header.inst = (pdcp_data_header.inst >= oai_emulation.info.nb_enb_local) ? \
                  pdcp_data_header.inst - oai_emulation.info.nb_enb_local+ NB_eNB_INST + oai_emulation.info.first_ue_local :
                  pdcp_data_header.inst +  oai_emulation.info.first_enb_local;*/
#else // OAI_EMU
         /* TODO: do we have to reset to 0 or not? not for a scenario with 1 UE at least */
         //          pdcp_data_header.inst = 0;
         //#warning "TO DO CORRCT VALUES FOR ue mod id, enb mod id"
         ctxt.frame         = ctxt_cpy.frame;
         ctxt.enb_flag      = ctxt_cpy.enb_flag;

         LOG_I(PDCP, "[PDCP] pdcp_data_header->rb_id = %d\n", pdcp_data_header->rb_id);

         if (ctxt_cpy.enb_flag) {
            ctxt.module_id = 0;
            rab_id      = pdcp_data_header->rb_id % maxDRB;
            ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index];
         } else {
            ctxt.module_id = 0;
            rab_id      = pdcp_data_header->rb_id % maxDRB;
652
            ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
         }
#endif

         //UE
         if (!ctxt.enb_flag) {
            if (rab_id != 0) {
               if (rab_id == UE_IP_DEFAULT_RAB_ID) {
                  LOG_I(PDCP, "PDCP_COLL_KEY_DEFAULT_DRB_VALUE(module_id=%d, rnti=%x, enb_flag=%d)\n",
                        ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
                  key = PDCP_COLL_KEY_DEFAULT_DRB_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
                  h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
                  LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
                        key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
               } else {
                  rab_id = rab_id % maxDRB;
                  LOG_I(PDCP, "PDCP_COLL_KEY_VALUE(module_id=%d, rnti=%x, enb_flag=%d, rab_id=%d, SRB_FLAG=%d)\n",
                        ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
                  key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
                  h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
                  LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
                        key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
               }

               if (h_rc == HASH_TABLE_OK) {
                  rab_id = pdcp_p->rb_id;
#ifdef PDCP_DEBUG
                  LOG_I(PDCP, "[FRAME %5u][UE][NETLINK][IP->PDCP] INST %d: Received socket with length %d  on Rab %d \n",
                        ctxt.frame,
                        pdcp_data_header->inst,
                        bytes_received,
                        pdcp_data_header->rb_id);

                  LOG_I(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB %u]\n",
                        ctxt.frame,
                        pdcp_data_header->inst,
                        pdcp_data_header->rb_id,
                        pdcp_data_header->data_size,
                        ctxt.module_id,
                        ctxt.rnti,
                        rab_id);
#endif
                  MSC_LOG_RX_MESSAGE(
                        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
                                    NULL,
                                    0,
                                    MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
                                    MSC_AS_TIME_ARGS(ctxt_pP),
                                    pdcp_data_header.inst,
                                    pdcp_data_header.rb_id,
                                    rab_id,
                                    pdcp_data_header.data_size);

                  pdcp_data_req(
                        &ctxt,
                        SRB_FLAG_NO,
                        rab_id,
                        RLC_MUI_UNDEFINED,
                        RLC_SDU_CONFIRM_NO,
                        pdcp_data_header->data_size,
                        (unsigned char *)receive_buf,
714 715 716 717 718 719
                        PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
                        ,&pdcp_data_header->sourceL2Id
                        ,&pdcp_data_header->destinationL2Id
#endif
                        );
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
               } else {
                  MSC_LOG_RX_DISCARDED_MESSAGE(
                        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
                                    NULL,
                                    0,
                                    MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
                                    MSC_AS_TIME_ARGS(ctxt_pP),
                                    pdcp_data_header.inst,
                                    pdcp_data_header.rb_id,
                                    rab_id,
                                    pdcp_data_header.data_size);
                  LOG_D(PDCP,
                        "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes ---X][PDCP][MOD %u][UE %u][RB %u] NON INSTANCIATED INSTANCE key 0x%"PRIx64", DROPPED\n",
                        ctxt.frame,
                        pdcp_data_header->inst,
                        pdcp_data_header->rb_id,
                        pdcp_data_header->data_size,
                        ctxt.module_id,
                        ctxt.rnti,
                        rab_id,
                        key);
               }
            }  else { //if (rab_id == 0)
               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][UE %u][RB DEFAULT_RAB_ID %u]\n",
                     ctxt.frame,
                     pdcp_data_header->inst,
                     pdcp_data_header->rb_id,
                     pdcp_data_header->data_size,
                     ctxt.module_id,
                     ctxt.rnti,
                     DEFAULT_RAB_ID);
               MSC_LOG_RX_MESSAGE(
                     (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
                           (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
                                 NULL,0,
                                 MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u default rab %u size %u",
                                 MSC_AS_TIME_ARGS(ctxt_pP),
                                 pdcp_data_header->inst,
                                 pdcp_data_header->rb_id,
                                 DEFAULT_RAB_ID,
                                 pdcp_data_header->data_size);

               pdcp_data_req (
                     &ctxt,
                     SRB_FLAG_NO,
                     DEFAULT_RAB_ID,
                     RLC_MUI_UNDEFINED,
                     RLC_SDU_CONFIRM_NO,
                     pdcp_data_header->data_size,
                     (unsigned char *)receive_buf,
772 773 774 775 776 777
                     PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
                     ,&pdcp_data_header->sourceL2Id
                     ,&pdcp_data_header->destinationL2Id
#endif
                     );
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
            }
         }
          free (sl_pc5s_msg_recv);
          free (sl_pc5s_msg_send);
      }
   }

#endif

   while ((len > 0) && (rlc_data_req_flag !=0))  {
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 1 );
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 1 );
      len = recvmsg(nas_sock_fd, &nas_msg_rx, 0);
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 );

      if (len<=0) {
         // nothing in pdcp NAS socket
         //LOG_D(PDCP, "[PDCP][NETLINK] Nothing in socket, length %d \n", len);
      } else {

         msg_len = len;
         for (nas_nlh_rx = (struct nlmsghdr *) nl_rx_buf;
               NLMSG_OK (nas_nlh_rx, msg_len);
               nas_nlh_rx = NLMSG_NEXT (nas_nlh_rx, msg_len)) {

            if (nas_nlh_rx->nlmsg_type == NLMSG_DONE) {
               LOG_D(PDCP, "[PDCP][NETLINK] RX NLMSG_DONE\n");
               //return;
            }

            if (nas_nlh_rx->nlmsg_type == NLMSG_ERROR) {
               LOG_D(PDCP, "[PDCP][NETLINK] 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));
816 817
                  LOG_D(PDCP, "[PDCP][NETLINK] RX pdcp_data_req_header_t inst %u, rb_id %u data_size %d, source L2Id 0x%08x, destination L2Id 0x%08x\n",
                        pdcp_read_header_g.inst, pdcp_read_header_g.rb_id, pdcp_read_header_g.data_size,pdcp_read_header_g.sourceL2Id, pdcp_read_header_g.destinationL2Id );
818 819 820 821 822 823 824 825 826 827 828 829 830
               } else {
                  LOG_E(PDCP, "[PDCP][NETLINK] 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()
#ifdef PDCP_DEBUG
               LOG_D(PDCP, "[PDCP][NETLINK] Something in socket, length %zu\n",
                     nas_nlh_rx->nlmsg_len - sizeof(struct nlmsghdr));
#endif

#ifdef OAI_EMU
831

832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850

               // overwrite function input parameters, because only one netlink socket for all instances
               if (pdcp_read_header_g.inst < oai_emulation.info.nb_enb_local) {
                  ctxt.frame         = ctxt_cpy.frame;
                  ctxt.enb_flag      = ENB_FLAG_YES;
                  ctxt.module_id     = pdcp_read_header_g.inst  +  oai_emulation.info.first_enb_local;
                  ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pdcp_read_header_g.rb_id / maxDRB + oai_emulation.info.first_ue_local];
                  rab_id    = pdcp_read_header_g.rb_id % maxDRB;
               } else {
                  ctxt.frame         = ctxt_cpy.frame;
                  ctxt.enb_flag      = ENB_FLAG_NO;
                  ctxt.module_id     = pdcp_read_header_g.inst - oai_emulation.info.nb_enb_local + oai_emulation.info.first_ue_local;
                  ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
                  rab_id    = pdcp_read_header_g.rb_id % maxDRB;
               }

               CHECK_CTXT_ARGS(&ctxt);
               AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
               /*LGpdcp_read_header.inst = (pdcp_read_header_g.inst >= oai_emulation.info.nb_enb_local) ? \
851 852
                  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;*/
853
#else // OAI_EMU
854 855 856 857 858
               /* TODO: do we have to reset to 0 or not? not for a scenario with 1 UE at least */
               //          pdcp_read_header_g.inst = 0;
               //#warning "TO DO CORRCT VALUES FOR ue mod id, enb mod id"
               ctxt.frame         = ctxt_cpy.frame;
               ctxt.enb_flag      = ctxt_cpy.enb_flag;
859

860
#ifdef PDCP_DEBUG
861
               LOG_I(PDCP, "[PDCP][NETLINK] pdcp_read_header_g.rb_id = %d, source L2Id = 0x%08x, destination L2Id = 0x%08x \n", pdcp_read_header_g.rb_id, pdcp_read_header_g.sourceL2Id, pdcp_read_header_g.destinationL2Id);
862 863
#endif

864 865 866 867 868 869 870 871 872
               if (ctxt_cpy.enb_flag) {
                  ctxt.module_id = 0;
                  rab_id      = pdcp_read_header_g.rb_id % maxDRB;
                  ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index];
               } else {
                  ctxt.module_id = 0;
                  rab_id      = pdcp_read_header_g.rb_id % maxDRB;
                  ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
               }
873

874

gauthier's avatar
gauthier committed
875 876
#endif

877 878 879 880 881
               if (ctxt.enb_flag) {
                  if (rab_id != 0) {
                     rab_id = rab_id % maxDRB;
                     key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
                     h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
882

883
                     if (h_rc == HASH_TABLE_OK) {
884
#ifdef PDCP_DEBUG
885 886 887 888 889 890
                        LOG_D(PDCP, "[FRAME %5u][eNB][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %zu) on Rab %d \n",
                              ctxt.frame,
                              pdcp_read_header_g.inst,
                              len,
                              nas_nlh_rx->nlmsg_len-sizeof(struct nlmsghdr),
                              pdcp_read_header_g.rb_id);
891 892
#endif

893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913
                        MSC_LOG_RX_MESSAGE(
                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
                                    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
                                          NULL,
                                          0,
                                          MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
                                          MSC_AS_TIME_ARGS(ctxt_pP),
                                          pdcp_read_header_g.inst,
                                          pdcp_read_header_g.rb_id,
                                          rab_id,
                                          pdcp_read_header_g.data_size);
                        LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u]UE %u][RB %u]\n",
                              ctxt_cpy.frame,
                              pdcp_read_header_g.inst,
                              pdcp_read_header_g.rb_id,
                              pdcp_read_header_g.data_size,
                              ctxt.module_id,
                              ctxt.rnti,
                              rab_id);

                        pdcp_data_req(&ctxt,
914 915 916 917 918 919
                              SRB_FLAG_NO,
                              rab_id,
                              RLC_MUI_UNDEFINED,
                              RLC_SDU_CONFIRM_NO,
                              pdcp_read_header_g.data_size,
                              (unsigned char *)NLMSG_DATA(nas_nlh_rx),
920 921 922 923 924
                              PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
                              ,NULL, NULL
#endif
                              );
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
                     } else {
                        LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes ---X][PDCP][MOD %u][UE %u][RB %u] NON INSTANCIATED INSTANCE, DROPPED\n",
                              ctxt.frame,
                              pdcp_read_header_g.inst,
                              pdcp_read_header_g.rb_id,
                              pdcp_read_header_g.data_size,
                              ctxt.module_id,
                              ctxt.rnti,
                              rab_id);
                     }
                  } else  { // 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
                     //#warning CODE TO BE REVIEWED, ONLY WORK FOR SIMPLE TOPOLOGY CASES
                     for (ue_id = 0; ue_id < NB_UE_INST; ue_id++) {
                        if (oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt_cpy.module_id][ue_id] != NOT_A_RNTI) {
                           ctxt.rnti = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt_cpy.module_id][ue_id];
                           LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB DEFAULT_RAB_ID %u]\n",
                                 ctxt.frame,
                                 pdcp_read_header_g.inst,
                                 pdcp_read_header_g.rb_id,
                                 pdcp_read_header_g.data_size,
                                 ctxt.module_id,
                                 ctxt.rnti,
                                 DEFAULT_RAB_ID);
                           pdcp_data_req (
                                 &ctxt,
                                 SRB_FLAG_NO,
                                 DEFAULT_RAB_ID,
                                 RLC_MUI_UNDEFINED,
                                 RLC_SDU_CONFIRM_NO,
                                 pdcp_read_header_g.data_size,
                                 (unsigned char *)NLMSG_DATA(nas_nlh_rx),
957 958 959 960 961
                                 PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
                                ,NULL, NULL
#endif
                                );
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
                        }
                     }
                  }
               } else { // enb_flag
                  if (rab_id != 0) {
                     if (rab_id == UE_IP_DEFAULT_RAB_ID) {
                        LOG_I(PDCP, "PDCP_COLL_KEY_DEFAULT_DRB_VALUE(module_id=%d, rnti=%x, enb_flag=%d)\n",
                              ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
                        key = PDCP_COLL_KEY_DEFAULT_DRB_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
                        h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
                        LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
                              key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
                     } else {
                        rab_id = rab_id % maxDRB;
                        LOG_I(PDCP, "PDCP_COLL_KEY_VALUE(module_id=%d, rnti=%x, enb_flag=%d, rab_id=%d, SRB_FLAG=%d)\n",
                              ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
                        key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
                        h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
                        LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
                              key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
                     }

                     if (h_rc == HASH_TABLE_OK) {
                        rab_id = pdcp_p->rb_id;
gauthier's avatar
gauthier committed
986
#ifdef PDCP_DEBUG
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
                        LOG_I(PDCP, "[FRAME %5u][UE][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %zu) on Rab %d \n",
                              ctxt.frame,
                              pdcp_read_header_g.inst,
                              len,
                              nas_nlh_rx->nlmsg_len-sizeof(struct nlmsghdr),
                              pdcp_read_header_g.rb_id);

                        LOG_I(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB %u]\n",
                              ctxt.frame,
                              pdcp_read_header_g.inst,
                              pdcp_read_header_g.rb_id,
                              pdcp_read_header_g.data_size,
                              ctxt.module_id,
                              ctxt.rnti,
                              rab_id);
1002
#endif
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
                        MSC_LOG_RX_MESSAGE(
                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
                                    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
                                          NULL,
                                          0,
                                          MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
                                          MSC_AS_TIME_ARGS(ctxt_pP),
                                          pdcp_read_header_g.inst,
                                          pdcp_read_header_g.rb_id,
                                          rab_id,
                                          pdcp_read_header_g.data_size);

                        pdcp_data_req(
                              &ctxt,
                              SRB_FLAG_NO,
                              rab_id,
                              RLC_MUI_UNDEFINED,
                              RLC_SDU_CONFIRM_NO,
                              pdcp_read_header_g.data_size,
                              (unsigned char *)NLMSG_DATA(nas_nlh_rx),
1023 1024 1025 1026 1027 1028
                              PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
                              ,&pdcp_read_header_g.sourceL2Id
                              ,&pdcp_read_header_g.destinationL2Id
#endif
                              );
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
                     } else {
                        MSC_LOG_RX_DISCARDED_MESSAGE(
                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
                                    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
                                          NULL,
                                          0,
                                          MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
                                          MSC_AS_TIME_ARGS(ctxt_pP),
                                          pdcp_read_header_g.inst,
                                          pdcp_read_header_g.rb_id,
                                          rab_id,
                                          pdcp_read_header_g.data_size);
                        LOG_D(PDCP,
                              "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes ---X][PDCP][MOD %u][UE %u][RB %u] NON INSTANCIATED INSTANCE key 0x%"PRIx64", DROPPED\n",
                              ctxt.frame,
                              pdcp_read_header_g.inst,
                              pdcp_read_header_g.rb_id,
                              pdcp_read_header_g.data_size,
                              ctxt.module_id,
                              ctxt.rnti,
                              rab_id,
                              key);
                     }
                  }  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][UE %u][RB DEFAULT_RAB_ID %u]\n",
                           ctxt.frame,
                           pdcp_read_header_g.inst,
                           pdcp_read_header_g.rb_id,
                           pdcp_read_header_g.data_size,
                           ctxt.module_id,
                           ctxt.rnti,
                           DEFAULT_RAB_ID);
                     MSC_LOG_RX_MESSAGE(
                           (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
                                 (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
                                       NULL,0,
                                       MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u default rab %u size %u",
                                       MSC_AS_TIME_ARGS(ctxt_pP),
                                       pdcp_read_header_g.inst,
                                       pdcp_read_header_g.rb_id,
                                       DEFAULT_RAB_ID,
                                       pdcp_read_header_g.data_size);

                     pdcp_data_req (
                           &ctxt,
                           SRB_FLAG_NO,
                           DEFAULT_RAB_ID,
                           RLC_MUI_UNDEFINED,
                           RLC_SDU_CONFIRM_NO,
                           pdcp_read_header_g.data_size,
                           (unsigned char *)NLMSG_DATA(nas_nlh_rx),
1081 1082 1083 1084 1085 1086
                           PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
                           ,&pdcp_read_header_g.sourceL2Id
                           ,&pdcp_read_header_g.destinationL2Id
#endif
                           );
1087 1088
                  }
               }
1089

1090 1091
            }
         }
gauthier's avatar
gauthier committed
1092
      }
1093 1094 1095
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 0 );
   }

1096

1097
   return len;
1098
# endif
1099
#else // neither PDCP_USE_NETLINK nor PDCP_USE_RT_FIFO
1100
   return 0;
1101
#endif // PDCP_USE_NETLINK
1102 1103 1104
}


1105 1106
void pdcp_fifo_read_input_sdus_from_otg (const protocol_ctxt_t* const  ctxt_pP) {

1107 1108 1109 1110
   unsigned char       *otg_pkt=NULL;
   module_id_t          dst_id; // dst for otg
   rb_id_t              rb_id;
   unsigned int         pkt_size=0;
1111
#if defined(USER_MODE) && defined(OAI_EMU)
1112 1113
   module_id_t          src_id;
   static unsigned int  pkt_cnt_enb=0, pkt_cnt_ue=0;
1114

1115 1116 1117
   Packet_otg_elt_t    *otg_pkt_info=NULL;
   int                  result;
   uint8_t              pdcp_mode, is_ue=0;
1118
#endif
1119 1120
   protocol_ctxt_t      ctxt;
   // we need to add conditions to avoid transmitting data when the UE is not RRC connected.
1121
#if defined(USER_MODE) && defined(OAI_EMU)
1122

1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
   if (oai_emulation.info.otg_enabled ==1 ) {
      // module_id is source id
      while ((otg_pkt_info = pkt_list_remove_head(&(otg_pdcp_buffer[ctxt_pP->instance]))) != 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",
               ctxt_pP->module_id,
               ctxt_pP->frame,
               otg_pkt_info,
               ctxt_pP->instance,
               pkt_list_get_head(&(otg_pdcp_buffer[ctxt_pP->instance])),
               otg_pdcp_buffer[ctxt_pP->instance].nb_elements);
         //otg_pkt_info = pkt_list_remove_head(&(otg_pdcp_buffer[module_id]));
         dst_id    = (otg_pkt_info->otg_pkt).dst_id; // type is module_id_t
         src_id    = (otg_pkt_info->otg_pkt).module_id; // type is module_id_t
         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
         // if (mac_get_rrc_status(module_id, ctxt_pP->enb_flag, dst_id ) > 2 /*RRC_CONNECTED*/) { // not needed: this test is already done in update_otg_enb
         otg_pkt = (unsigned char*) (otg_pkt_info->otg_pkt).sdu_buffer;
         pkt_size = (otg_pkt_info->otg_pkt).sdu_buffer_size;

         if (otg_pkt != NULL) {
            if (is_ue == 0 ) {
               PROTOCOL_CTXT_SET_BY_MODULE_ID(
                     &ctxt,
                     src_id,
                     ENB_FLAG_YES,
                     oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id],
                     ctxt_pP->frame,
                     ctxt_pP->subframe,
                     src_id);

               LOG_D(OTG,"[eNB %d] Frame %d sending packet %d from module %d on rab id %d (src %d, dst %d/%x) pkt size %d for pdcp mode %d\n",
                     ctxt.module_id,
                     ctxt.frame,
                     pkt_cnt_enb++,
                     src_id,
                     rb_id,
                     src_id,
                     dst_id,
                     oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id],
                     pkt_size,
                     pdcp_mode);
               result = pdcp_data_req(&ctxt,
                     SRB_FLAG_NO,
                     rb_id,
                     RLC_MUI_UNDEFINED,
                     RLC_SDU_CONFIRM_NO,
                     pkt_size,
                     otg_pkt,
1175 1176 1177 1178 1179
                     pdcp_mode
#ifdef Rel14
                     , NULL, NULL
#endif
                     );
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
               if (result != TRUE) {
                  LOG_W(OTG,"PDCP data request failed!\n");
               }
            } else {
               //rb_id= eNB_index * MAX_NUM_RB + DTCH;


               LOG_D(OTG,"[UE %d] Frame %d: sending packet %d from module %d on rab id %d (src %d/%x, dst %d) pkt size %d\n",
                     ctxt_pP->module_id,
                     ctxt_pP->frame,
                     pkt_cnt_ue++,
                     ctxt_pP->module_id,
                     rb_id,
                     src_id,
                     pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id], // [src_id]
                     dst_id,
                     pkt_size);
               PROTOCOL_CTXT_SET_BY_MODULE_ID(
                     &ctxt,
                     ctxt_pP->module_id, //src_id,
                     ENB_FLAG_NO,
                     pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id],// [src_id]
                     ctxt_pP->frame,
                     ctxt_pP->subframe,
                     dst_id);

               result = pdcp_data_req( &ctxt,
                     SRB_FLAG_NO,
                     rb_id,
                     RLC_MUI_UNDEFINED,
                     RLC_SDU_CONFIRM_NO,
                     pkt_size,
                     otg_pkt,
1213 1214 1215 1216 1217
                     PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
                     , NULL, NULL
#endif
                     );
1218 1219 1220 1221 1222 1223 1224 1225
               if (result != TRUE) {
                  LOG_W(OTG,"PDCP data request failed!\n");
               }
            }

            free(otg_pkt);
            otg_pkt = NULL;
         }
1226

1227
         // } //else LOG_D(OTG,"ctxt_pP->frame %d enb %d-> ue %d link not yet established state %d  \n", ctxt_pP->frame, eNB_index,dst_id - NB_eNB_INST, mac_get_rrc_status(module_id, ctxt_pP->enb_flag, dst_id - NB_eNB_INST));
1228

1229 1230
      }
   }
1231

1232
#else
1233

1234 1235 1236
   if ((otg_enabled==1) && (ctxt_pP->enb_flag == ENB_FLAG_YES)) { // generate DL traffic
      unsigned int ctime=0;
      ctime = ctxt_pP->frame * 100;
1237

1238
      /*if  ((mac_get_rrc_status(eNB_index, ctxt_pP->enb_flag, 0 ) > 2) &&
1239
    (mac_get_rrc_status(eNB_index, ctxt_pP->enb_flag, 1 ) > 2)) { */
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
      PROTOCOL_CTXT_SET_BY_MODULE_ID(
            &ctxt,
            ctxt_pP->module_id,
            ctxt_pP->enb_flag,
            NOT_A_RNTI,
            ctxt_pP->frame,
            ctxt_pP->subframe,
            ctxt_pP->module_id);

      for (dst_id = 0; dst_id<NUMBER_OF_UE_MAX; dst_id++) {
         ctxt.rnti = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id];

         if (ctxt.rnti != NOT_A_RNTI) {
            if (mac_eNB_get_rrc_status(ctxt.module_id, ctxt.rnti ) > 2 /*RRC_SI_RECEIVED*/) {
               unsigned int temp = 0;
               otg_pkt=packet_gen(
                     ENB_MODULE_ID_TO_INSTANCE(ctxt.module_id),
                     UE_MODULE_ID_TO_INSTANCE(dst_id),
                     0,
                     ctime,
                     &temp);
               pkt_size = temp;

               if (otg_pkt != NULL) {
                  rb_id = dst_id * maxDRB + DTCH;
                  pdcp_data_req(&ctxt,
1266 1267 1268 1269 1270 1271
                        SRB_FLAG_NO,
                        rb_id,
                        RLC_MUI_UNDEFINED,
                        RLC_SDU_CONFIRM_NO,
                        pkt_size,
                        otg_pkt,
1272 1273 1274 1275 1276
                        PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
                        , NULL, NULL
#endif
                        );
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328
                  LOG_I(OTG,
                        "send packet from module %d on rab id %d (src %d, dst %d) pkt size %d\n",
                        ctxt_pP->module_id, rb_id, ctxt_pP->module_id, dst_id, pkt_size);
                  free(otg_pkt);
               }
            }
         }
      }
   }

#endif
}

//TTN for D2D (PC5S)
#ifdef Rel14

int
pdcp_pc5_socket_init() {
   pthread_attr_t     attr;
   struct sched_param sched_param;
   int optval; // flag value for setsockopt
   int n; // message byte size

   //create PDCP socket
   pdcp_pc5_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
   if (pdcp_pc5_sockfd < 0){
      LOG_E(PDCP,"[pdcp_pc5_socket_init] Error opening socket %d (%d:%s)\n",pdcp_pc5_sockfd,errno, strerror(errno));
      exit(EXIT_FAILURE);
   }

   optval = 1;
   setsockopt(pdcp_pc5_sockfd, SOL_SOCKET, SO_REUSEADDR,
         (const void *)&optval , sizeof(int));

   fcntl(pdcp_pc5_sockfd,F_SETFL,O_NONBLOCK);

   bzero((char *) &pdcp_sin, sizeof(pdcp_sin));
   pdcp_sin.sin_family = AF_INET;
   pdcp_sin.sin_addr.s_addr = htonl(INADDR_ANY);
   pdcp_sin.sin_port = htons(PDCP_SOCKET_PORT_NO);
   // associate the parent socket with a port
   if (bind(pdcp_pc5_sockfd, (struct sockaddr *) &pdcp_sin,
         sizeof(pdcp_sin)) < 0) {
      LOG_E(PDCP,"[pdcp_pc5_socket_init] ERROR: Failed on binding the socket\n");
      exit(1);
   }

}

#endif