pdcp_fifo.c 35.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

#define PDCP_FIFO_C
#define PDCP_DEBUG 1

#ifndef OAI_EMU
extern int otg_enabled;
#endif

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

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

#include "../MAC/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
55
#include "NETWORK_DRIVER/LITE/constant.h"
56 57 58 59
#include "SIMULATION/ETH_TRANSPORT/extern.h"
#include "UTIL/OCG/OCG.h"
#include "UTIL/OCG/OCG_extern.h"
#include "UTIL/LOG/log.h"
60
#include "UTIL/OTG/otg_tx.h"
61
#include "UTIL/FIFO/pad_list.h"
62
#include "UTIL/LOG/vcd_signal_dumper.h"
63
#include "platform_constants.h"
gauthier's avatar
msc  
gauthier committed
64
#include "msc.h"
65

66
#include "assertions.h"
67

68
#ifdef PDCP_USE_NETLINK
69 70
#include <sys/socket.h>
#include <linux/netlink.h>
71
#include "NETWORK_DRIVER/UE_IP/constant.h"
72

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

gauthier's avatar
gauthier committed
83
unsigned char pdcp_read_state_g = 0;
84 85
#endif

86
extern Packet_OTG_List_t *otg_pdcp_buffer;
87

88
#if defined(LINK_ENB_PDCP_TO_GTPV1U)
89
#  include "gtpv1u_eNB_task.h"
gauthier's avatar
gauthier committed
90 91
#endif

gauthier's avatar
gauthier committed
92
pdcp_data_req_header_t pdcp_read_header_g;
93 94

//-----------------------------------------------------------------------------
95
int pdcp_fifo_flush_sdus(const protocol_ctxt_t* const  ctxt_pP)
96 97 98
{
  //-----------------------------------------------------------------------------

gauthier's avatar
gauthier committed
99 100 101
  mem_block_t     *sdu_p            = list_get_head (&pdcp_sdu_list);
  int              bytes_wrote      = 0;
  int              pdcp_nb_sdu_sent = 0;
gauthier's avatar
gauthier committed
102
  uint8_t          cont             = 1;
103
#if defined(LINK_ENB_PDCP_TO_GTPV1U)
104
  //MessageDef      *message_p        = NULL;
gauthier's avatar
gauthier committed
105
#endif
106

107
#if defined(PDCP_USE_NETLINK) && defined(LINUX)
108 109 110
  int ret = 0;
#endif

111
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH, 1 );
gauthier's avatar
gauthier committed
112
  while (sdu_p && cont) {
113

gauthier's avatar
gauthier committed
114
#if ! defined(OAI_EMU)
115
    ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
116 117
#endif

118
#if defined(LINK_ENB_PDCP_TO_GTPV1U)
gauthier's avatar
gauthier committed
119

120 121 122 123
    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(
124 125
        ctxt_pP->module_id, //gtpv1u_data_t *gtpv1u_data_p,
        ctxt_pP->rnti,//rb_id/maxDRB, TO DO UE ID
126 127 128 129 130 131 132 133 134 135 136 137 138
        ((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);

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

gauthier's avatar
gauthier committed
139
#endif /* defined(ENABLE_USE_MME) */
140
#ifdef PDCP_DEBUG
141
    LOG_D(PDCP, "PDCP->IP TTI %d INST %d: Preparing %d Bytes of data from rab %d to Nas_mesh\n",
142
          ctxt_pP->frame, ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
gauthier's avatar
gauthier committed
143
          ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size, ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
144
#endif //PDCP_DEBUG
145
    cont = 0;
146

147 148 149 150
    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);
      }
151

152 153
#ifdef PDCP_USE_RT_FIFO
      bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO,
154 155
                             &(((uint8_t *) sdu->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
                             pdcp_output_header_bytes_to_write);
156 157

#else
158
#ifdef PDCP_USE_NETLINK
159
#ifdef LINUX
160 161 162
      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;
163
#endif //LINUX
164
#endif //PDCP_USE_NETLINK
165

166
      bytes_wrote = pdcp_output_header_bytes_to_write;
167
#endif //PDCP_USE_RT_FIFO
168 169

#ifdef PDCP_DEBUG
170
      LOG_D(PDCP, "Frame %d Sent %d Bytes of header to Nas_mesh\n",
171 172
            ctxt_pP->frame,
            bytes_wrote);
173 174
#endif //PDCP_DEBUG

175 176
      if (bytes_wrote > 0) {
        pdcp_output_header_bytes_to_write = pdcp_output_header_bytes_to_write - bytes_wrote;
177

178 179
        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;
180

181 182
#ifdef PDCP_USE_RT_FIFO
          bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO, &(sdu->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
183 184
#else

185
#ifdef PDCP_USE_NETLINK
186
#ifdef LINUX
187 188
          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;
189 190
          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 );
191
          ret = sendmsg(nas_sock_fd,&nas_msg_tx,0);
192 193
          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 );
194 195

          if (ret<0) {
196
            LOG_E(PDCP, "[PDCP_FIFOS] sendmsg returns %d (errno: %d)\n", ret, errno);
gauthier's avatar
msc  
gauthier committed
197 198 199 200 201 202 203 204 205 206
      	    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);
           mac_xface->macphy_exit("sendmsg failed for nas_sock_fd\n");
207
            break;
gauthier's avatar
msc  
gauthier committed
208 209 210 211 212 213 214 215 216 217
          } 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);
218 219
          }

220
#endif // LINUX
221
#endif //PDCP_USE_NETLINK
222
          bytes_wrote= pdcp_output_sdu_bytes_to_write;
223
#endif // PDCP_USE_RT_FIFO
224 225

#ifdef PDCP_DEBUG
226 227 228 229 230
          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);
231
#endif //PDCP_DEBUG
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

          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);
              cont = 1;
              pdcp_nb_sdu_sent += 1;
              sdu_p = list_get_head (&pdcp_sdu_list);
            }
          } else {
            LOG_W(PDCP, "RADIO->IP SEND SDU CONGESTION!\n");
254
          }
255 256 257 258 259 260
        } else {
          LOG_W(PDCP, "RADIO->IP SEND SDU CONGESTION!\n");
        }
      }
    } else {
      // continue writing sdu
261 262
#ifdef PDCP_USE_RT_FIFO
      bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO,
263 264
                             (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);
265
#else  // PDCP_USE_RT_FIFO
266
      bytes_wrote = pdcp_output_sdu_bytes_to_write;
267
#endif  // PDCP_USE_RT_FIFO
268

269 270 271 272 273 274 275 276 277 278 279 280
      if (bytes_wrote > 0) {
        pdcp_output_sdu_bytes_to_write -= bytes_wrote;

        if (!pdcp_output_sdu_bytes_to_write) {     // OK finish with this SDU
          //PRINT_RB_SEND_OUTPUT_SDU ("[PDCP] RADIO->IP SEND SDU\n");
          list_remove_head (&pdcp_sdu_list);
          free_mem_block (sdu_p);
          cont = 1;
          pdcp_nb_sdu_sent += 1;
          sdu_p = list_get_head (&pdcp_sdu_list);
          // LOG_D(PDCP, "rb sent a sdu from rab\n");
        }
281
      }
282
    }
283
  }
284
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH, 0 );
285

286
#ifdef PDCP_USE_RT_FIFO
287

288
  if ((pdcp_nb_sdu_sent)) {
289
    if ((pdcp_2_nas_irq > 0)) {
290
#ifdef PDCP_DEBUG
291
      LOG_D(PDCP, "Frame %d : Trigger NAS RX interrupt\n",
292
            ctxt_pP->frame);
293
#endif //PDCP_DEBUG
294
      rt_pend_linux_srq (pdcp_2_nas_irq);
295

296 297 298 299 300
    } 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);
    }
301
  }
302

303
#endif  //PDCP_USE_RT_FIFO
304 305 306 307 308

  return pdcp_nb_sdu_sent;
}

//-----------------------------------------------------------------------------
309
int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
310
{
311
#ifdef PDCP_USE_NETLINK
312
  protocol_ctxt_t                ctxt_cpy = *ctxt_pP;
313 314 315 316
  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;
Cedric Roux's avatar
Cedric Roux committed
317 318
  /* avoid gcc warnings */
  (void)data_p;
gauthier's avatar
gauthier committed
319
  module_id_t                    ue_id     = 0;
320
  pdcp_t*                        pdcp_p    = NULL;
321
# if defined(PDCP_USE_NETLINK_QUEUES)
gauthier's avatar
gauthier committed
322
  rb_id_t                        rab_id    = 0;
323

324
  pdcp_transmission_mode_t       pdcp_mode = PDCP_TRANSMISSION_MODE_UNKNOWN;
gauthier's avatar
gauthier committed
325

gauthier's avatar
gauthier committed
326

327
  while (pdcp_netlink_dequeue_element(ctxt_pP, &data_p) != 0) {
328
    DevAssert(data_p != NULL);
329 330 331 332 333 334 335 336 337 338 339 340 341
    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;
342 343
    }

344
    CHECK_CTXT_ARGS(&ctxt_cpy);
345 346 347 348 349

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

    if (rab_id != 0) {
        LOG_D(PDCP, "[FRAME %05d][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ "
350
            "/ %d Bytes --->][PDCP][MOD %u][RB %u]\n",
351 352
              ctxt_cpy.frame,
              (ctxt_cpy.enb_flag) ? "eNB" : "UE",
353 354 355 356
            data_p->pdcp_read_header.inst,
            data_p->pdcp_read_header.rb_id,
            data_p->pdcp_read_header.data_size,
            ctxt_cpy.module_id,
357 358 359
              rab_id);
#ifdef  OAI_NW_DRIVER_TYPE_ETHERNET

360 361 362
      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 */ ) {
363
#if defined (Rel10)
364
          PDCP_TRANSMISSION_MODE_TRANSPARENT;
365
#else
366
          pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
367
#endif
368 369
      } 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*/ ) {
370 371 372 373 374 375
          pdcp_mode=  PDCP_TRANSMISSION_MODE_DATA;
        } else {
          pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
          LOG_W(PDCP,"unknown IP traffic type \n");
        }

376
#else // OAI_NW_DRIVER_TYPE_ETHERNET NASMESH driver does not curreenlty support multicast traffic
377
        pdcp_mode = PDCP_TRANSMISSION_MODE_DATA;
378
#endif
379
      pdcp_data_req(&ctxt_cpy,
380
                      SRB_FLAG_NO,
381
                      rab_id % maxDRB,
gauthier's avatar
gauthier committed
382 383
                      RLC_MUI_UNDEFINED,
                      RLC_SDU_CONFIRM_NO,
384 385
                    data_p->pdcp_read_header.data_size,
                    data_p->data,
386 387 388 389 390 391 392 393 394
                      pdcp_mode);
    } 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++) {
395
        if (pdcp_module_id_to_rnti[ctxt_cpy.module_id][ue_id] != NOT_A_RNTI) {
396
          LOG_D(PDCP, "eNB Try Forcing send on DEFAULT_RAB_ID UE %d\n", ue_id);
397 398
          ctxt.module_id     = ctxt_cpy.module_id;
          ctxt.rnti          = ctxt_cpy.pdcp_module_id_to_rnti[ctxt_cpy.module_id][ue_id];
399 400 401
          ctxt.frame         = ctxt_cpy.frame;
          ctxt.enb_flag      = ctxt_cpy.enb_flag;

gauthier's avatar
gauthier committed
402
          pdcp_data_req(
403 404 405 406 407
            &ctxt,
            SRB_FLAG_NO,
            DEFAULT_RAB_ID,
            RLC_MUI_UNDEFINED,
            RLC_SDU_CONFIRM_NO,
408 409
            data_p->pdcp_read_header.data_size,
            data_p->data,
410 411
            PDCP_TRANSMISSION_MODE_DATA);
        }
gauthier's avatar
gauthier committed
412
      }
413 414 415 416 417 418 419 420
    } 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,
421 422
        data_p->pdcp_read_header.data_size,
        data_p->data,
423 424 425
        PDCP_TRANSMISSION_MODE_DATA);
    }

426 427 428
    free(data_p->data);
    free(data_p);
    data_p = NULL;
gauthier's avatar
gauthier committed
429
  }
430

gauthier's avatar
gauthier committed
431
  return 0;
432
# else /* PDCP_USE_NETLINK_QUEUES*/
433
  int              len = 1;
434
  int  msg_len;
435
  rb_id_t          rab_id  = 0;
436 437 438
  int rlc_data_req_flag = 3;
 
  while ((len > 0) && (rlc_data_req_flag !=0))  {
439 440
    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 );
441
    len = recvmsg(nas_sock_fd, &nas_msg_rx, 0);
442
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 );
443 444 445

    if (len<=0) {
      // nothing in pdcp NAS socket
446
      //LOG_D(PDCP, "[PDCP][NETLINK] Nothing in socket, length %d \n", len);
447
    } else {
448 449
    
      msg_len = len;
450
      for (nas_nlh_rx = (struct nlmsghdr *) nl_rx_buf;
451 452
           NLMSG_OK (nas_nlh_rx, msg_len);
           nas_nlh_rx = NLMSG_NEXT (nas_nlh_rx, msg_len)) {
453 454

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

        if (nas_nlh_rx->nlmsg_type == NLMSG_ERROR) {
460
          LOG_D(PDCP, "[PDCP][NETLINK] RX NLMSG_ERROR\n");
461 462 463 464 465 466
        }

        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));
467
            LOG_D(PDCP, "[PDCP][NETLINK] RX pdcp_data_req_header_t inst %u, rb_id %u data_size %d\n",
468 469
                  pdcp_read_header_g.inst, pdcp_read_header_g.rb_id, pdcp_read_header_g.data_size);
          } else {
470
            LOG_E(PDCP, "[PDCP][NETLINK] WRONG size %d should be sizeof (pdcp_data_req_header_t) + sizeof(struct nlmsghdr)\n",
471 472 473 474 475
                  nas_nlh_rx->nlmsg_len);
          }
        } else {
          pdcp_read_state_g = 0;
          // print_active_requests()
476
#ifdef PDCP_DEBUG
477
          LOG_D(PDCP, "[PDCP][NETLINK] Something in socket, length %d \n",
478
                nas_nlh_rx->nlmsg_len - sizeof(struct nlmsghdr));
479
#endif
gauthier's avatar
gauthier committed
480

481
#ifdef OAI_EMU
482 483 484 485 486

          // 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;
487 488
            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];
489 490 491 492
            rab_id    = pdcp_read_header_g.rb_id % maxDRB;
          } else {
            ctxt.frame         = ctxt_cpy.frame;
            ctxt.enb_flag      = ENB_FLAG_NO;
493 494
            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];
nikaeinn's avatar
nikaeinn committed
495
            rab_id    = pdcp_read_header_g.rb_id % maxDRB;
496 497
          }

498
          CHECK_CTXT_ARGS(&ctxt);
499 500 501 502
          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) ? \
                  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;*/
503
#else // OAI_EMU
504
          pdcp_read_header_g.inst = 0;
Cedric Roux's avatar
Cedric Roux committed
505
//#warning "TO DO CORRCT VALUES FOR ue mod id, enb mod id"
506
          ctxt.frame         = ctxt_cpy.frame;
507
          ctxt.enb_flag      = ctxt_cpy.enb_flag;
508

509
#ifdef PDCP_DEBUG
510
          LOG_I(PDCP, "[PDCP][NETLINK] pdcp_read_header_g.rb_id = %d\n", pdcp_read_header_g.rb_id);
511 512
#endif

513
          if (ctxt_cpy.enb_flag) {
514
            ctxt.module_id = 0;
515
            rab_id      = pdcp_read_header_g.rb_id % maxDRB;
516
            ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index];
517
          } else {
518
            ctxt.module_id = 0;
519
            rab_id      = pdcp_read_header_g.rb_id % maxDRB;
520
            ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
521
          }
522

523

gauthier's avatar
gauthier committed
524 525
#endif

526 527 528
          if (ctxt.enb_flag) {
            if (rab_id != 0) {
              rab_id = rab_id % maxDRB;
529 530
              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);
531

532
              if (h_rc == HASH_TABLE_OK) {
533
#ifdef PDCP_DEBUG
534 535 536 537 538 539
                LOG_D(PDCP, "[FRAME %5u][eNB][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %d) 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);
540 541
#endif

gauthier's avatar
msc  
gauthier committed
542 543 544 545 546
          	    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,
gauthier's avatar
gauthier committed
547
          	      MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
gauthier's avatar
msc  
gauthier committed
548 549 550 551 552
          	      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);
553
                LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u]UE %u][RB %u]\n",
554 555 556 557
                      ctxt_cpy.frame,
                      pdcp_read_header_g.inst,
                      pdcp_read_header_g.rb_id,
                      pdcp_read_header_g.data_size,
558 559
                      ctxt.module_id,
                      ctxt.rnti,
560 561 562 563 564 565 566 567 568 569 570
                      rab_id);

                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);
              } else {
571
                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",
572 573 574 575
                      ctxt.frame,
                      pdcp_read_header_g.inst,
                      pdcp_read_header_g.rb_id,
                      pdcp_read_header_g.data_size,
576 577
                      ctxt.module_id,
                      ctxt.rnti,
578 579 580 581
                      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
Cedric Roux's avatar
Cedric Roux committed
582
//#warning CODE TO BE REVIEWED, ONLY WORK FOR SIMPLE TOPOLOGY CASES
583 584 585 586
              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",
587 588 589 590
                        ctxt.frame,
                        pdcp_read_header_g.inst,
                        pdcp_read_header_g.rb_id,
                        pdcp_read_header_g.data_size,
591 592
                        ctxt.module_id,
                        ctxt.rnti,
593 594 595 596 597 598 599 600 601 602 603 604 605
                        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),
                    PDCP_TRANSMISSION_MODE_DATA);
                }
              }
            }
606
          } else { // enb_flag
607
            if (rab_id != 0) {
608 609 610 611 612
              if (rab_id == UE_IP_DEFAULT_RAB_ID) {
                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);
613
              } else {
614 615 616 617 618 619
                rab_id = rab_id % maxDRB;
                LOG_D(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);
              }
620 621

              if (h_rc == HASH_TABLE_OK) {
622
                rab_id = pdcp_p->rb_id;
gauthier's avatar
gauthier committed
623
#ifdef PDCP_DEBUG
624 625 626 627 628 629
                LOG_D(PDCP, "[FRAME %5u][UE][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %d) 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);
630

631
                LOG_D(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB %u]\n",
632 633 634 635
                      ctxt.frame,
                      pdcp_read_header_g.inst,
                      pdcp_read_header_g.rb_id,
                      pdcp_read_header_g.data_size,
636 637
                      ctxt.module_id,
                      ctxt.rnti,
638 639
                      rab_id);
#endif
gauthier's avatar
msc  
gauthier committed
640 641 642 643 644
          	    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,
gauthier's avatar
gauthier committed
645
          	      MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
gauthier's avatar
msc  
gauthier committed
646 647 648 649 650
          	      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);
gauthier's avatar
gauthier committed
651

652 653 654 655 656 657 658 659 660 661
                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);
              } else {
gauthier's avatar
msc  
gauthier committed
662 663 664 665 666
            	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,
gauthier's avatar
gauthier committed
667
                  MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
gauthier's avatar
msc  
gauthier committed
668 669 670 671 672
                  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);
673 674
                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",
675 676 677 678
                      ctxt.frame,
                      pdcp_read_header_g.inst,
                      pdcp_read_header_g.rb_id,
                      pdcp_read_header_g.data_size,
679 680 681 682
                      ctxt.module_id,
                      ctxt.rnti,
                      rab_id,
                      key);
683
              }
684 685
            }  else {
              LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
686
              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",
687 688 689 690
                    ctxt.frame,
                    pdcp_read_header_g.inst,
                    pdcp_read_header_g.rb_id,
                    pdcp_read_header_g.data_size,
691 692
                    ctxt.module_id,
                    ctxt.rnti,
693
                    DEFAULT_RAB_ID);
gauthier's avatar
msc  
gauthier committed
694 695 696 697
          	  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,
gauthier's avatar
gauthier committed
698
                MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u default rab %u size %u",
gauthier's avatar
msc  
gauthier committed
699 700 701 702 703 704
                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);

705 706 707 708 709 710 711 712 713 714
              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);
            }
715
          }
716 717

        }
gauthier's avatar
gauthier committed
718
      }
719
    }
720
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 0 );
721
  }
722

723
  return len;
724
# endif
725
#else // neither PDCP_USE_NETLINK nor PDCP_USE_RT_FIFO
726
  return 0;
727
#endif // PDCP_USE_NETLINK
728 729 730
}


731 732
void pdcp_fifo_read_input_sdus_from_otg (const protocol_ctxt_t* const  ctxt_pP) {

733 734 735
  unsigned char       *otg_pkt=NULL;
  module_id_t          dst_id; // dst for otg
  rb_id_t              rb_id;
736
  unsigned int         pkt_size=0;
737
#if defined(USER_MODE) && defined(OAI_EMU)
738
  module_id_t          src_id;
739
  static unsigned int  pkt_cnt_enb=0, pkt_cnt_ue=0;
740

741 742
  Packet_otg_elt_t    *otg_pkt_info=NULL;
  int                  result;
743 744 745 746 747
  uint8_t              pdcp_mode, is_ue=0;
#endif
  protocol_ctxt_t      ctxt;
  // we need to add conditions to avoid transmitting data when the UE is not RRC connected.
#if defined(USER_MODE) && defined(OAI_EMU)
748

749
  if (oai_emulation.info.otg_enabled ==1 ) {
750 751 752 753 754 755 756 757 758
    // 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);
759
      //otg_pkt_info = pkt_list_remove_head(&(otg_pdcp_buffer[module_id]));
760 761
      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
762 763 764 765 766 767 768 769 770 771 772 773
      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 ) {
774 775 776 777 778 779
          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,
780 781
            ctxt_pP->subframe,
	    src_id);
782

783
          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",
784 785 786 787 788 789 790
                ctxt.module_id,
                ctxt.frame,
                pkt_cnt_enb++,
                src_id,
                rb_id,
                src_id,
                dst_id,
791
		oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id],
792 793
                pkt_size,
                pdcp_mode);
794 795 796 797 798 799 800 801
          result = pdcp_data_req(&ctxt,
                                 SRB_FLAG_NO,
                                 rb_id,
                                 RLC_MUI_UNDEFINED,
                                 RLC_SDU_CONFIRM_NO,
                                 pkt_size,
                                 otg_pkt,
                                 pdcp_mode);
802 803 804
          if (result != TRUE) {
            LOG_W(OTG,"PDCP data request failed!\n");
          }
805 806 807 808
        } else {
          //rb_id= eNB_index * MAX_NUM_RB + DTCH;


809
          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",
810 811 812 813 814
                ctxt_pP->module_id,
                ctxt_pP->frame,
                pkt_cnt_ue++,
                ctxt_pP->module_id,
                rb_id,
815 816
                src_id,
		pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id], // [src_id]
817 818 819 820
                dst_id,
                pkt_size);
          PROTOCOL_CTXT_SET_BY_MODULE_ID(
            &ctxt,
821
            ctxt_pP->module_id, //src_id,
822
            ENB_FLAG_NO,
823
            pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id],// [src_id]
824
            ctxt_pP->frame,
825 826
            ctxt_pP->subframe,
	    dst_id);
827 828 829 830 831 832 833 834 835

          result = pdcp_data_req( &ctxt,
                                  SRB_FLAG_NO,
                                  rb_id,
                                  RLC_MUI_UNDEFINED,
                                  RLC_SDU_CONFIRM_NO,
                                  pkt_size,
                                  otg_pkt,
                                  PDCP_TRANSMISSION_MODE_DATA);
836 837 838
          if (result != TRUE) {
            LOG_W(OTG,"PDCP data request failed!\n");
          }
839 840 841 842
        }

        free(otg_pkt);
        otg_pkt = NULL;
843
      }
844 845 846 847

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

    }
848
  }
849

850
#else
851

852
  if ((otg_enabled==1) && (ctxt_pP->enb_flag == ENB_FLAG_YES)) { // generate DL traffic
853 854 855 856 857
    unsigned int ctime=0;
    ctime = ctxt_pP->frame * 100;

    /*if  ((mac_get_rrc_status(eNB_index, ctxt_pP->enb_flag, 0 ) > 2) &&
    (mac_get_rrc_status(eNB_index, ctxt_pP->enb_flag, 1 ) > 2)) { */
858 859 860 861 862 863
    PROTOCOL_CTXT_SET_BY_MODULE_ID(
      &ctxt,
      ctxt_pP->module_id,
      ctxt_pP->enb_flag,
      NOT_A_RNTI,
      ctxt_pP->frame,
864 865
      ctxt_pP->subframe,
      ctxt_pP->module_id);
866 867

    for (dst_id = 0; dst_id<NUMBER_OF_UE_MAX; dst_id++) {
868 869 870 871
      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*/) {
872
        unsigned int temp = 0;
873 874 875 876 877 878
          otg_pkt=packet_gen(
                    ENB_MODULE_ID_TO_INSTANCE(ctxt.module_id),
                    UE_MODULE_ID_TO_INSTANCE(dst_id),
                    0,
                    ctime,
                    &temp);
879 880 881 882 883 884 885 886 887 888 889 890
        pkt_size = temp;

        if (otg_pkt != NULL) {
          rb_id = dst_id * maxDRB + DTCH;
          pdcp_data_req(&ctxt,
                        SRB_FLAG_NO,
                        rb_id,
                        RLC_MUI_UNDEFINED,
                        RLC_SDU_CONFIRM_NO,
                        pkt_size,
                        otg_pkt,
                        PDCP_TRANSMISSION_MODE_DATA);
891 892 893 894 895
            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);
          }
896
        }
gauthier's avatar
gauthier committed
897
      }
898
    }
899
  }
900

901 902
#endif
}