pdcp_fifo.c 59.2 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
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
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
26
 * \version 0.5
27
 * \email navid.nikaein@eurecom.fr
28 29 30
 * \warning This component can be runned only in user-space
 * @ingroup pdcp
 */
31 32

#define PDCP_FIFO_C
33 34
#define PDCP_DEBUG 1
#define DEBUG_PDCP_FIFO_FLUSH_SDU
35 36 37 38 39 40

extern int otg_enabled;

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

41
#include <pthread.h>
42 43 44 45 46 47 48
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define rtf_put write
#define rtf_get read

49
#include "../MAC/mac_extern.h"
50
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
51
#include "NETWORK_DRIVER/LITE/constant.h"
52
//#include "SIMULATION/ETH_TRANSPORT/extern.h"
53 54
#include "UTIL/OCG/OCG.h"
#include "UTIL/OCG/OCG_extern.h"
55
#include "common/utils/LOG/log.h"
56
#include "UTIL/OTG/otg_tx.h"
57
#include "UTIL/FIFO/pad_list.h"
58
#include "common/utils/LOG/vcd_signal_dumper.h"
59
#include "platform_constants.h"
Lionel Gauthier's avatar
msc  
Lionel Gauthier committed
60
#include "msc.h"
61
#include "pdcp.h"
62

63
#include "assertions.h"
64

65
#ifdef PDCP_USE_NETLINK
66 67
#include <sys/socket.h>
#include <linux/netlink.h>
68
#include "NETWORK_DRIVER/UE_IP/constant.h"
69

70
extern char nl_rx_buf[NL_MAX_PAYLOAD];
71
extern struct sockaddr_nl nas_src_addr, nas_dest_addr;
72 73 74 75
extern struct nlmsghdr *nas_nlh_tx;
extern struct nlmsghdr *nas_nlh_rx;
extern struct iovec nas_iov_tx;
extern struct iovec nas_iov_rx;
76
#ifdef UE_NAS_USE_TUN
77
extern int nas_sock_fd[MAX_MOBILES_PER_ENB];
78
#else
79
extern int nas_sock_fd;
80
#endif
81 82
extern struct msghdr nas_msg_tx;
extern struct msghdr nas_msg_rx;
83

84
unsigned char pdcp_read_state_g = 0;
85 86 87 88
extern uint8_t nfapi_mode;
#ifdef UESIM_EXPANSION
extern uint16_t inst_pdcp_list[NUMBER_OF_UE_MAX];
#endif
89 90
#endif

91
extern Packet_OTG_List_t *otg_pdcp_buffer;
92
#if defined(LINK_ENB_PDCP_TO_GTPV1U)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
93
#  include "gtpv1u_eNB_task.h"
Cedric Roux's avatar
Cedric Roux committed
94
#  include "gtpv1u_eNB_defs.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
95 96
#endif

97 98
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);

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
/* 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

114
pdcp_data_req_header_t pdcp_read_header_g;
115 116

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

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

125 126
#ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
#define THREAD_NAME_LEN 16
127 128 129 130 131 132 133
   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");
   }
134 135 136
#undef THREAD_NAME_LEN
#endif

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

#endif

157 158 159 160
   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;
161
#if defined(LINK_ENB_PDCP_TO_GTPV1U)
162
   //MessageDef      *message_p        = NULL;
163 164
#endif

165
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH, 1 );
166
   while (sdu_p && cont) { //&& sdu_p!=0x01 && sdu_p!=0x02 && sdu_p!=0x100000000 && sdu_p!=0x200000000
167

168
#ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
169 170 171 172
      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);
173
#else
174
      // Raphael: was suppressed by Raymond --> should be suppressed?
175 176
      // value of sdu_p->data->inst is set in pdcp_data_ind
      // it's necessary to set 1 in case of UE with S1.
177 178 179
      //if (ctxt_pP->enb_flag){
      //  ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
      //}
180
#endif
181

182
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
183
      //TTN (29/05/18) OIP1 for UE-eNB, OIP0 for UE-UE (incoming packets)
184
      //for the  moment, based on rb_id, we distinguish between the traffic from eNB and from other UE
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
185

186
      //traffic from other UE
matzakos's avatar
matzakos committed
187
      if ( ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id >= 4) {
188 189
         ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
      } else
190
#endif
191 192 193
      { //traffic from eNB
         ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 1;
      }
194

195
#if defined(LINK_ENB_PDCP_TO_GTPV1U)
Lionel Gauthier's avatar
Lionel Gauthier committed
196

197 198 199 200 201
      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,
202
               ctxt_pP->rnti,//rb_id/LTE_maxDRB, TO DO UE ID
203 204 205 206 207 208 209 210 211 212 213 214 215
               ((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
      }
216

Lionel Gauthier's avatar
Lionel Gauthier committed
217
#endif /* defined(ENABLE_USE_MME) */
218
#ifdef PDCP_DEBUG
219
      LOG_D(PDCP, "PDCP->IP TTI %d INST %d: Preparing %d Bytes of data from rab %d to Nas_mesh\n",
220 221
            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);
222
#endif //PDCP_DEBUG
223 224 225
      cont = 0;

//TTN - for D2D (PC5S)
226
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
227 228
      sidelink_pc5s_element *sl_pc5s_msg_recv = NULL;
      char send_buf[BUFSIZE];
229
      int rb_id = ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id;
230

231
      if (rb_id >= MAX_NUM_LCID_DATA) { //hardcoded for PC5-Signaling
232
      //if ((rb_id == 28) | (rb_id == 29) | (rb_id == 30))
233 234 235 236

#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));
237 238 239 240 241 242
         LOG_I(PDCP,"Received PC5S message, header traffic_type: %d)\n", sl_pc5s_msg_recv->pc5s_header.traffic_type);
         LOG_I(PDCP,"Received PC5S message, header rb_id: %d)\n", sl_pc5s_msg_recv->pc5s_header.rb_id);
         LOG_I(PDCP,"Received PC5S message, header data_size: %d)\n", sl_pc5s_msg_recv->pc5s_header.data_size);
         LOG_I(PDCP,"Received PC5S message, header inst: %d)\n", sl_pc5s_msg_recv->pc5s_header.inst);
         LOG_I(PDCP,"Received PC5-S message, sourceL2Id: 0x%08x\n)\n", sl_pc5s_msg_recv->pc5s_header.sourceL2Id);
         LOG_I(PDCP,"Received PC5-S message, destinationL1Id: 0x%08x\n)\n", sl_pc5s_msg_recv->pc5s_header.destinationL2Id);
243
         free(sl_pc5s_msg_recv);
244 245 246 247
#endif
         memset(send_buf, 0, BUFSIZE);
         memcpy((void *)send_buf, (void*)(sdu_p->data+sizeof(pdcp_data_ind_header_t)), sizeof(sidelink_pc5s_element));

248 249
         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);
250 251 252 253
         if (n < 0) {
            LOG_E(PDCP, "ERROR: Failed to send to ProSe App\n");
            exit(EXIT_FAILURE);
         }
254
      }
255 256 257 258 259 260
#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);
         }
261

262
#ifdef PDCP_USE_RT_FIFO
263 264 265
         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);
266 267

#else
268
#ifdef PDCP_USE_NETLINK
269
#ifdef LINUX
270 271 272
         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;
273
#endif //LINUX
274
#endif //PDCP_USE_NETLINK
275

276
         bytes_wrote = pdcp_output_header_bytes_to_write;
277
#endif //PDCP_USE_RT_FIFO
278 279

#ifdef PDCP_DEBUG
280
         LOG_D(PDCP, "Frame %d Sent %d Bytes of header to Nas_mesh\n",
281 282
               ctxt_pP->frame,
               bytes_wrote);
283 284
#endif //PDCP_DEBUG

285 286
         if (bytes_wrote > 0) {
            pdcp_output_header_bytes_to_write = pdcp_output_header_bytes_to_write - bytes_wrote;
287

288 289 290
            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!");
291

292
#ifdef PDCP_USE_RT_FIFO
293
               bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO, &(sdu->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
294 295
#else

296
#ifdef PDCP_USE_NETLINK
297
#ifdef LINUX
298
              // LOG_I(PDCP, "Panos-D: pdcp_fifo_flush_sdus() in PDCP_USE_NETLINK 2 \n");
299 300
          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;
301 302
          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 );
303 304 305
#ifdef UE_NAS_USE_TUN
          ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
#else
306
          ret = sendmsg(nas_sock_fd,&nas_msg_tx,0);
307
#endif
308 309
          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 );
310 311

          if (ret<0) {
312
            LOG_E(PDCP, "[PDCP_FIFOS] sendmsg returns %d (errno: %d)\n", ret, errno);
Lionel Gauthier's avatar
msc  
Lionel Gauthier committed
313 314 315 316 317 318 319 320 321
      	    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);
322
	    AssertFatal(1==0,"sendmsg failed for nas_sock_fd\n");
323
            break;
Lionel Gauthier's avatar
msc  
Lionel Gauthier committed
324 325 326 327 328 329 330 331 332 333
          } 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);
334 335
          }

336
#endif // LINUX
337
#endif //PDCP_USE_NETLINK
338
               bytes_wrote= pdcp_output_sdu_bytes_to_write;
339
#endif // PDCP_USE_RT_FIFO
340 341

#ifdef PDCP_DEBUG
342
               LOG_I(PDCP, "PDCP->IP Frame %d INST %d: Sent %d Bytes of data from rab %d to higher layers\n",
343 344 345 346
                     ctxt_pP->frame,
                     ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
                     bytes_wrote,
                     ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
347
#endif //PDCP_DEBUG
348

349 350 351 352 353
               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);
354
                     LOG_D(PDCP,
355 356 357 358 359 360 361 362 363
                           "[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__);
364

365 366 367 368 369 370 371 372 373 374
                     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");
               }
375
            } else {
376
               LOG_W(PDCP, "3: RADIO->IP SEND SDU CONGESTION!\n");
377
            }
378 379 380
         } else {
            LOG_D(PDCP, "4 skip free_mem_block: bytes_wrote = %d\n", bytes_wrote);
         }
381
      } else {
382
         // continue writing sdu
383
#ifdef PDCP_USE_RT_FIFO
384 385 386
         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);
387
#else  // PDCP_USE_RT_FIFO
388
         bytes_wrote = pdcp_output_sdu_bytes_to_write;
389
#endif  // PDCP_USE_RT_FIFO
390
         LOG_D(PDCP, "THINH 2 bytes_wrote = %d\n", bytes_wrote);
391

392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
         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);
         }
409
      }
410 411
   }
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH, 0 );
412

413
#ifdef PDCP_USE_RT_FIFO
414

415 416
   if ((pdcp_nb_sdu_sent)) {
      if ((pdcp_2_nas_irq > 0)) {
417
#ifdef PDCP_DEBUG
418 419
         LOG_D(PDCP, "Frame %d : Trigger NAS RX interrupt\n",
               ctxt_pP->frame);
420
#endif //PDCP_DEBUG
421
         rt_pend_linux_srq (pdcp_2_nas_irq);
422

423 424 425 426 427 428
      } 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);
      }
   }
429

430
#endif  //PDCP_USE_RT_FIFO
431

432
#ifdef PDCP_SDU_FLUSH_LOCK
433
   if (pthread_mutex_unlock(&mtex)) exit_fun("PDCP_SDU_FLUSH_LOCK unlock error!");
434 435
#endif

436
   return pdcp_nb_sdu_sent;
437 438 439
}

//-----------------------------------------------------------------------------
440
int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
441
{
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
#ifdef UE_NAS_USE_TUN
  protocol_ctxt_t ctxt = *ctxt_pP;
  hash_key_t key = HASHTABLE_NOT_A_KEY_VALUE;
  hashtable_rc_t h_rc;
  pdcp_t* pdcp_p = NULL;
  int len;
  rb_id_t rab_id = DEFAULT_RAB_ID;

  do {
    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 = read(nas_sock_fd[ctxt_pP->module_id], &nl_rx_buf, NL_MAX_PAYLOAD);
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 );

    if (len<=0) continue;
    LOG_D(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);
    if (h_rc == HASH_TABLE_OK) {
      LOG_D(PDCP, "[FRAME %5u][UE][NETLINK][IP->PDCP] INST %d: Received socket with length %d on Rab %d \n",
            ctxt.frame, ctxt.instance, len, rab_id);

      LOG_D(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB %u]\n",
            ctxt.frame, ctxt.instance, rab_id, len, ctxt.module_id,
            ctxt.rnti, 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 rab %u size %u",
                         MSC_AS_TIME_ARGS(ctxt_pP),
                         ctxt.instance, rab_id, rab_id, len);

      pdcp_data_req(&ctxt, SRB_FLAG_NO, rab_id, RLC_MUI_UNDEFINED,
476
                    RLC_SDU_CONFIRM_NO, len, (unsigned char *)nl_rx_buf,
477
                    PDCP_TRANSMISSION_MODE_DATA
478
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
479 480 481
                    , NULL, NULL
#endif
                   );
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
    } 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),
      ctxt.instance, rab_id, rab_id, len);
      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, ctxt.instance, rab_id, len, ctxt.module_id,
            ctxt.rnti, rab_id, key);
    }
  } while (len > 0);
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 0 );
  return len;

#else /* UE_NAS_USE_TUN */

502
#ifdef PDCP_USE_NETLINK
503 504 505 506 507 508 509 510 511 512 513
   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)
514
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
515 516
   int prose_addr_len;
   char send_buf[BUFSIZE], receive_buf[BUFSIZE];
517
   //int optval;
518 519 520
   int bytes_received;
   sidelink_pc5s_element *sl_pc5s_msg_recv = NULL;
   sidelink_pc5s_element *sl_pc5s_msg_send = NULL;
521 522 523
   //uint32_t sourceL2Id;
   //uint32_t groupL2Id;
   //module_id_t         module_id = 0;
524
   pc5s_header_t *pc5s_header;
525
#endif
526

527 528 529 530 531 532 533 534
# 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);
535
      rab_id = data_p->pdcp_read_header.rb_id % LTE_maxDRB; //Panos: maxDRB
536 537 538 539 540 541 542 543 544 545 546 547 548
      // 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;
      }
549

550
      CHECK_CTXT_ARGS(&ctxt_cpy);
Lionel Gauthier's avatar
Lionel Gauthier committed
551

552
      AssertFatal (rab_id    < LTE_maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, LTE_maxDRB);
553

554
      if (rab_id != 0) {
Raymond Knopp's avatar
Raymond Knopp committed
555
         LOG_D(PDCP, "[FRAME %05d][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ "
556 557 558 559 560 561 562 563
               "/ %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);
564 565
#ifdef  OAI_NW_DRIVER_TYPE_ETHERNET

566 567 568
         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 */ ) {
569
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
570
            PDCP_TRANSMISSION_MODE_TRANSPARENT;
571
#else
572
            pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
573
#endif
574 575 576 577 578 579 580
         } 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");
         }
581

582
#else // OAI_NW_DRIVER_TYPE_ETHERNET NASMESH driver does not curreenlty support multicast traffic
583
         pdcp_mode = PDCP_TRANSMISSION_MODE_DATA;
584
#endif
585 586
         pdcp_data_req(&ctxt_cpy,
               SRB_FLAG_NO,
587
               rab_id % LTE_maxDRB,
588 589 590 591
               RLC_MUI_UNDEFINED,
               RLC_SDU_CONFIRM_NO,
               data_p->pdcp_read_header.data_size,
               data_p->data,
592
               pdcp_mode
593
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
594 595 596
               ,NULL, NULL
#endif
               );
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
      } 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,
620
                     PDCP_TRANSMISSION_MODE_DATA
621
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
622 623 624
                     ,NULL, NULL
#endif
                     );
625 626 627 628 629 630 631 632 633 634 635 636
            }
         }
      } 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,
637
               PDCP_TRANSMISSION_MODE_DATA
638
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
639 640 641
               ,NULL, NULL
#endif
               );
642
      }
643

644 645 646 647
      free(data_p->data);
      free(data_p);
      data_p = NULL;
   }
648

649
   return 0;
650
# else /* PDCP_USE_NETLINK_QUEUES*/
651 652 653 654 655 656 657
   int              len = 1;
   int  msg_len;
   rb_id_t          rab_id  = 0;
   int rlc_data_req_flag = 3;


//TTN for D2D (PC5S)
658
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
659
   prose_addr_len = sizeof(prose_pdcp_addr);
660 661 662
   // receive a message from ProSe App
   memset(receive_buf, 0, BUFSIZE);
   bytes_received = recvfrom(pdcp_pc5_sockfd, receive_buf, BUFSIZE, 0,
663
         (struct sockaddr *) &prose_pdcp_addr, (socklen_t *)&prose_addr_len);
664 665 666 667 668
   //  if (bytes_received < 0){
   //    LOG_E(RRC, "ERROR: Failed to receive from ProSe App\n");
   //    exit(EXIT_FAILURE);
   // }
   if (bytes_received > 0) {
669 670
      pc5s_header = calloc(1, sizeof(pc5s_header_t));
      memcpy((void *)pc5s_header, (void *)receive_buf, sizeof(pc5s_header_t));
671

672
      if (pc5s_header->traffic_type == TRAFFIC_PC5S_SESSION_INIT){
673
         //send reply to ProSe app
674
         LOG_D(PDCP,"Received a request to open PDCP socket and establish a new PDCP session ... send response to ProSe App \n");
675 676
         memset(send_buf, 0, BUFSIZE);
         sl_pc5s_msg_send = calloc(1, sizeof(sidelink_pc5s_element));
677
         sl_pc5s_msg_send->pc5s_header.traffic_type = TRAFFIC_PC5S_SESSION_INIT;
678 679 680
         sl_pc5s_msg_send->pc5sPrimitive.status = 1;

         memcpy((void *)send_buf, (void *)sl_pc5s_msg_send, sizeof(sidelink_pc5s_element));
681 682
         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);
683 684 685 686
         if (bytes_sent < 0) {
            LOG_E(PDCP, "ERROR: Failed to send to ProSe App\n");
            exit(EXIT_FAILURE);
         }
687
      } else if (pc5s_header->traffic_type == TRAFFIC_PC5S_SIGNALLING) { //if containing PC5-S message -> send to other UE
688
         LOG_I(PDCP,"Received PC5-S message ... send to the other UE\n");
689
#ifdef PDCP_DEBUG
690 691 692 693 694 695
         LOG_I(PDCP,"Received PC5-S message, traffic_type: %d)\n", pc5s_header->traffic_type);
         LOG_I(PDCP,"Received PC5-S message, rbid: %d)\n", pc5s_header->rb_id);
         LOG_I(PDCP,"Received PC5-S message, data_size: %d)\n", pc5s_header->data_size);
         LOG_I(PDCP,"Received PC5-S message, inst: %d)\n", pc5s_header->inst);
         LOG_I(PDCP,"Received PC5-S message,sourceL2Id: 0x%08x\n)\n", pc5s_header->sourceL2Id);
         LOG_I(PDCP,"Received PC5-S message,destinationL1Id: 0x%08x\n)\n", pc5s_header->destinationL2Id);
696

697
#endif
698

699
#ifdef OAI_EMU
700

701
         // overwrite function input parameters, because only one netlink socket for all instances
702
         if (pc5s_header->inst < oai_emulation.info.nb_enb_local) {
703 704
            ctxt.frame         = ctxt_cpy.frame;
            ctxt.enb_flag      = ENB_FLAG_YES;
705
            ctxt.module_id     = pc5s_header.inst  +  oai_emulation.info.first_enb_local;
706 707
            ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pc5s_header->rb_id / LTE_maxDRB + oai_emulation.info.first_ue_local];
            rab_id    = pc5s_header->rb_id % LTE_maxDRB;
708
         } else {
709 710
            ctxt.frame         = ctxt_cpy.frame;
            ctxt.enb_flag      = ENB_FLAG_NO;
711
            ctxt.module_id     = pc5s_header->inst - oai_emulation.info.nb_enb_local + oai_emulation.info.first_ue_local;
712
            ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
713
            rab_id    = pc5s_header->rb_id % LTE_maxDRB;
714 715 716
         }

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

728
         LOG_I(PDCP, "[PDCP] pc5s_header->rb_id = %d\n", pc5s_header->rb_id);
729 730 731

         if (ctxt_cpy.enb_flag) {
            ctxt.module_id = 0;
732
            rab_id      = pc5s_header->rb_id % LTE_maxDRB;
733 734 735
            ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index];
         } else {
            ctxt.module_id = 0;
736
            rab_id      = pc5s_header->rb_id % LTE_maxDRB;
737
            ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
738 739 740 741 742 743 744
         }
#endif

         //UE
         if (!ctxt.enb_flag) {
            if (rab_id != 0) {
               if (rab_id == UE_IP_DEFAULT_RAB_ID) {
745
                  LOG_D(PDCP, "PDCP_COLL_KEY_DEFAULT_DRB_VALUE(module_id=%d, rnti=%x, enb_flag=%d)\n",
746 747 748
                        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);
749
                  LOG_D(PDCP,"request key %x : (%d,%x,%d,%d)\n",
750 751
                        (uint8_t)key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
               } else {
752
                  rab_id = rab_id % LTE_maxDRB;
753 754 755 756 757
                  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",
758
                		  (uint8_t)key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
759 760 761 762 763
               }

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

770
                  LOG_D(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB %u]\n",
771
                        ctxt.frame,
772 773 774
                        pc5s_header->inst,
                        pc5s_header->rb_id,
                        pc5s_header->data_size,
775 776 777 778 779 780 781 782 783 784 785
                        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),
786 787
                                    pc5s_header->inst,
                                    pc5s_header->rb_id,
788
                                    rab_id,
789
                                    pc5s_header->data_size);
790

791 792 793
                  /*LOG_I(PDCP, "In pdcp_fifo_read_input_sdus() before calling pdcp_data_req() 1 \n");
                  list_display_memory_head_tail(&pdcp_sdu_list);*/

794 795 796 797 798 799
                  pdcp_data_req(
                        &ctxt,
                        SRB_FLAG_NO,
                        rab_id,
                        RLC_MUI_UNDEFINED,
                        RLC_SDU_CONFIRM_NO,
800
                        pc5s_header->data_size,
801
                        (unsigned char *)receive_buf,
802
                        PDCP_TRANSMISSION_MODE_DATA
803
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
804 805
                        ,&pc5s_header->sourceL2Id
                        ,&pc5s_header->destinationL2Id
806 807
#endif
                        );
808 809 810
                  /*LOG_I(PDCP, "In pdcp_fifo_read_input_sdus() after calling pdcp_data_req 1() \n");
                  list_display_memory_head_tail(&pdcp_sdu_list);*/

811 812 813 814 815 816 817 818
               } 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),
819 820
                                    pc5s_header->inst,
                                    pc5s_header->rb_id,
821
                                    rab_id,
822
                                    pc5s_header->data_size);
823 824 825
                  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,
826 827 828
                        pc5s_header->inst,
                        pc5s_header->rb_id,
                        pc5s_header->data_size,
829 830 831 832 833 834 835 836 837
                        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,
838 839 840
                     pc5s_header->inst,
                     pc5s_header->rb_id,
                     pc5s_header->data_size,
841 842 843 844 845 846 847 848 849
                     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),
850 851
                                 pc5s_header->inst,
                                 pc5s_header->rb_id,
852
                                 DEFAULT_RAB_ID,
853
                                 pc5s_header->data_size);
854 855 856 857 858 859
               pdcp_data_req (
                     &ctxt,
                     SRB_FLAG_NO,
                     DEFAULT_RAB_ID,
                     RLC_MUI_UNDEFINED,
                     RLC_SDU_CONFIRM_NO,
860
                     pc5s_header->data_size,
861
                     (unsigned char *)receive_buf,
862
                     PDCP_TRANSMISSION_MODE_DATA
863
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
864 865
                     ,&pc5s_header->sourceL2Id
                     ,&pc5s_header->destinationL2Id
866 867
#endif
                     );
868 869 870 871 872 873 874
            }
         }
          free (sl_pc5s_msg_recv);
          free (sl_pc5s_msg_send);
      }
   }

875
#endif /*end PC5S*/
876 877 878 879 880 881 882 883
   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
884
         //LOG_D(PDCP, "[PDCP][NETLINK] Nothing in socket, length %d \n", len);
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
      } 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));
905 906
                  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 );
907 908 909 910 911 912 913 914 915 916 917 918 919
               } 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
920

921 922 923 924 925 926

               // 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;
927 928
                  ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pdcp_read_header_g.rb_id / LTE_maxDRB + oai_emulation.info.first_ue_local];
                  rab_id    = pdcp_read_header_g.rb_id % LTE_maxDRB;
929 930 931 932 933
               } 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];
934
                  rab_id    = pdcp_read_header_g.rb_id % LTE_maxDRB;
935 936 937
               }

               CHECK_CTXT_ARGS(&ctxt);
938
               AssertFatal (rab_id    < LTE_maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, LTE_maxDRB);
939
               /*LGpdcp_read_header.inst = (pdcp_read_header_g.inst >= oai_emulation.info.nb_enb_local) ? \
940 941
                  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;*/
942
#else // OAI_EMU
943 944 945 946 947
               /* 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;
948

949
#ifdef PDCP_DEBUG
950
               LOG_D(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);
951
#endif
952
          if (ctxt_cpy.enb_flag) {
953
            ctxt.module_id = 0;
954 955
            rab_id      = pdcp_read_header_g.rb_id % LTE_maxDRB;
            ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_read_header_g.rb_id / LTE_maxDRB];
956
          } else {
957 958 959 960
            if (nfapi_mode == 3) {
#ifdef UESIM_EXPANSION
              ctxt.module_id = inst_pdcp_list[pdcp_read_header_g.inst];
#else
961
              ctxt.module_id = pdcp_read_header_g.inst;
962 963 964 965
#endif
            } else {
              ctxt.module_id = 0;
            }
966
            rab_id      = pdcp_read_header_g.rb_id % LTE_maxDRB;
967
            ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
968
          }
969 970 971

#endif

972 973
          if (ctxt.enb_flag) {
            if (rab_id != 0) {
974
              rab_id = rab_id % LTE_maxDRB;
975 976
              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);
977

978
                     if (h_rc == HASH_TABLE_OK) {
979
#ifdef PDCP_DEBUG
980 981 982 983 984 985
                        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);
986 987
#endif

988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
                        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,
1009 1010 1011 1012 1013 1014
                              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),
1015
                              PDCP_TRANSMISSION_MODE_DATA
1016
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
1017 1018 1019
                              ,NULL, NULL
#endif
                              );
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
                     } 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),
1052
                                 PDCP_TRANSMISSION_MODE_DATA
1053
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
1054 1055 1056
                                ,NULL, NULL
#endif
                                );
1057 1058 1059 1060 1061 1062
                        }
                     }
                  }
               } else { // enb_flag
                  if (rab_id != 0) {
                     if (rab_id == UE_IP_DEFAULT_RAB_ID) {
Raymond Knopp's avatar
Raymond Knopp committed
1063
                        LOG_D(PDCP, "PDCP_COLL_KEY_DEFAULT_DRB_VALUE(module_id=%d, rnti=%x, enb_flag=%d)\n",
1064 1065 1066
                              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);
1067 1068 1069
                        LOG_D(PDCP,"request key %x : (%d,%x,%d,%d)\n",
                        		(uint8_t)key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
                     } else {
1070
                        rab_id = rab_id % LTE_maxDRB;
Raymond Knopp's avatar
Raymond Knopp committed
1071
                        LOG_D(PDCP, "PDCP_COLL_KEY_VALUE(module_id=%d, rnti=%x, enb_flag=%d, rab_id=%d, SRB_FLAG=%d)\n",
1072 1073 1074
                              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);
Raymond Knopp's avatar
Raymond Knopp committed
1075
                        LOG_D(PDCP,"request key %x : (%d,%x,%d,%d)\n",
1076
                        		(uint8_t)key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
1077 1078 1079 1080
                     }

                     if (h_rc == HASH_TABLE_OK) {
                        rab_id = pdcp_p->rb_id;
1081
#ifdef PDCP_DEBUG
1082
                        LOG_D(PDCP, "[FRAME %5u][UE][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %zu) on Rab %d \n",
1083 1084 1085 1086 1087 1088
                              ctxt.frame,
                              pdcp_read_header_g.inst,
                              len,
                              nas_nlh_rx->nlmsg_len-sizeof(struct nlmsghdr),
                              pdcp_read_header_g.rb_id);

1089
                        LOG_D(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB %u]\n",
1090 1091 1092 1093 1094 1095 1096
                              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);
1097
#endif
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
                        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);
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
                        if(nfapi_mode == 3){
                        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),
                              PDCP_TRANSMISSION_MODE_DATA
1119
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
1120 1121
                              ,NULL
                              ,NULL
1122
#endif
1123 1124
                              );
                        }else{
1125
                        	//TTN - for traffic from OIP1 (to eNB), sourceL2/DestL2 should be set to NULL
1126
                        	LOG_D(PDCP, "[THINH] source L2 Id: 0x%08x, destL2 0x%08x \n",pdcp_read_header_g.sourceL2Id, pdcp_read_header_g.destinationL2Id);
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
                        	if (pdcp_read_header_g.inst == 0 ){ //INST == 0 (OIP0)
                        		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),
                        				PDCP_TRANSMISSION_MODE_DATA
                        				#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
1137 1138
                        				,&pdcp_read_header_g.sourceL2Id //NULL
                        				,&pdcp_read_header_g.destinationL2Id //NULL
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
                        				#endif
                        				);
                        	} else {  //INST == 1 (OIP1)
                        		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),
                        				PDCP_TRANSMISSION_MODE_DATA
                        				#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                        				,NULL
                        				,NULL
                        				#endif
                        				);
                        	}
1157
                        }
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
                     } 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);
1201
                     if(nfapi_mode == 3){
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
                    	 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),
                    			 PDCP_TRANSMISSION_MODE_DATA
                    			 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                    			 ,NULL
                    			 ,NULL
                    			 #endif
                    			 );
1216
                     }else{
1217 1218
                    	 //TTN - for traffic from OIP1 (to eNB), sourceL2/DestL2 should be set to NULL
                    	 if (pdcp_read_header_g.inst == 0){  //INST == 0 (OIP0)
1219
                    		 LOG_D(PDCP, "[THINH] source L2 Id: 0x%08x, destL2 0x%08x \n",pdcp_read_header_g.sourceL2Id, pdcp_read_header_g.destinationL2Id);
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
                    		 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),
                    				 PDCP_TRANSMISSION_MODE_DATA
                    				 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                    				 ,&pdcp_read_header_g.sourceL2Id
                    				 ,&pdcp_read_header_g.destinationL2Id
                    				 #endif
                    				 );
                    	 }  else { //INST == 1 (OIP1)
                    		 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),
                    				 PDCP_TRANSMISSION_MODE_DATA
                    				 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                    				 ,NULL
                    				 ,NULL
                    				 #endif
                    				 );
                    	 }
1250
                     }
1251 1252
                  }
               }
1253

1254 1255
            }
         }
1256
      }
1257 1258 1259
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 0 );
   }

1260

1261
   return len;
1262
# endif
1263
#else // neither PDCP_USE_NETLINK nor PDCP_USE_RT_FIFO
1264
   return 0;
1265
#endif // PDCP_USE_NETLINK
1266
#endif /* #else UE_NAS_USE_TUN */
1267 1268 1269
}


1270 1271
void pdcp_fifo_read_input_sdus_from_otg (const protocol_ctxt_t* const  ctxt_pP) {

1272

1273
  module_id_t          dst_id; // dst for otg
1274 1275 1276
  protocol_ctxt_t      ctxt;
  // we need to add conditions to avoid transmitting data when the UE is not RRC connected.
  if ((otg_enabled==1) && (ctxt_pP->enb_flag == ENB_FLAG_YES)) { // generate DL traffic
1277

1278 1279 1280 1281 1282 1283
    PROTOCOL_CTXT_SET_BY_MODULE_ID(
      &ctxt,
      ctxt_pP->module_id,
      ctxt_pP->enb_flag,
      NOT_A_RNTI,
      ctxt_pP->frame,
1284 1285
      ctxt_pP->subframe,
      ctxt_pP->module_id);
1286

1287
    for (dst_id = 0; dst_id<MAX_MOBILES_PER_ENB; dst_id++) {
1288
      ctxt.rnti = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id];
1289
    }
1290
  }
1291 1292 1293
}

//TTN for D2D (PC5S)
1294
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
1295

1296
void
1297
pdcp_pc5_socket_init() {
1298 1299
	//pthread_attr_t     attr;
   //struct sched_param sched_param;
1300
   int optval; // flag value for setsockopt
1301
   //int n; // message byte size
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 1329

   //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