pdcp.h 20.8 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 LAYER2/PDCP_v10.1.0/pdcp.h
Lionel Gauthier's avatar
Lionel Gauthier committed
23
* \brief pdcp interface with RLC, RRC
24 25 26 27 28
* \author  Lionel GAUTHIER and Navid Nikaein
* \date 2009-2012
* \version 1.0
*/

frtabu's avatar
frtabu committed
29
/** @defgroup _pdcp PDCP
30 31 32 33
* @ingroup _oai2
* @{
*/

34 35 36 37
#ifndef __PDCP_H__
#    define __PDCP_H__
//-----------------------------------------------------------------------------
#ifndef NON_ACCESS_STRATUM
38 39
  #include "UTIL/MEM/mem_block.h"
  #include "UTIL/LISTS/list.h"
40 41
#endif //NON_ACCESS_STRATUM
//-----------------------------------------------------------------------------
42
#include "RRC/LTE/rrc_defs.h"
43
#include "COMMON/platform_constants.h"
44
#include "COMMON/platform_types.h"
45 46 47 48 49
#include "LTE_DRB-ToAddMod.h"
#include "LTE_DRB-ToAddModList.h"
#include "LTE_SRB-ToAddMod.h"
#include "LTE_SRB-ToAddModList.h"
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
50 51
  #include "LTE_MBMS-SessionInfoList-r9.h"
  #include "LTE_PMCH-InfoList-r9.h"
52 53
#endif

frtabu's avatar
frtabu committed
54 55 56 57 58 59 60 61 62 63 64
typedef rlc_op_status_t  (*send_rlc_data_req_func_t)(const protocol_ctxt_t *const,
    const srb_flag_t, const MBMS_flag_t,
    const rb_id_t, const mui_t,
    confirm_t, sdu_size_t, mem_block_t *,const uint32_t *const, const uint32_t *const);
typedef boolean_t (*pdcp_data_ind_func_t)( const protocol_ctxt_t *, const srb_flag_t,
    const MBMS_flag_t, const rb_id_t, const sdu_size_t,
    mem_block_t *,const uint32_t *const, const uint32_t *const);
/* maximum number of tun interfaces that will be created to emulates UEs */
/* UEs beyond that will be multiplexed on the same tun   */
#define MAX_NUMBER_NETIF           16

65 66 67 68
#define PDCP_USE_NETLINK_BIT            (1<< 11)
#define LINK_ENB_PDCP_TO_IP_DRIVER_BIT  (1<< 13)
#define LINK_ENB_PDCP_TO_GTPV1U_BIT     (1<< 14)
#define UE_NAS_USE_TUN_BIT              (1<< 15)
69
#define ENB_NAS_USE_TUN_BIT             (1<< 16)
70 71
typedef struct {
  uint64_t optmask;
frtabu's avatar
frtabu committed
72 73
  send_rlc_data_req_func_t send_rlc_data_req_func;
  pdcp_data_ind_func_t pdcp_data_ind_func;
74 75
} pdcp_params_t;

frtabu's avatar
frtabu committed
76 77


78 79 80 81
#define PDCP_USE_NETLINK            ( get_pdcp_optmask() & PDCP_USE_NETLINK_BIT)
#define LINK_ENB_PDCP_TO_IP_DRIVER  ( get_pdcp_optmask() & LINK_ENB_PDCP_TO_IP_DRIVER_BIT)
#define LINK_ENB_PDCP_TO_GTPV1U     ( get_pdcp_optmask() & LINK_ENB_PDCP_TO_GTPV1U_BIT)
#define UE_NAS_USE_TUN              ( get_pdcp_optmask() & UE_NAS_USE_TUN_BIT)
82
#define ENB_NAS_USE_TUN             ( get_pdcp_optmask() & ENB_NAS_USE_TUN_BIT)
83
uint64_t get_pdcp_optmask(void);
84

Lionel Gauthier's avatar
Lionel Gauthier committed
85 86
extern pthread_t       pdcp_thread;
extern pthread_attr_t  pdcp_thread_attr;
87
extern pthread_mutex_t pdcp_mutex;
Lionel Gauthier's avatar
Lionel Gauthier committed
88 89
extern pthread_cond_t  pdcp_cond;
extern int             pdcp_instance_cnt;
90

91 92 93
#define PROTOCOL_PDCP_CTXT_FMT PROTOCOL_CTXT_FMT"[%s %02u] "

#define PROTOCOL_PDCP_CTXT_ARGS(CTXT_Pp, pDCP_Pp) PROTOCOL_CTXT_ARGS(CTXT_Pp),\
frtabu's avatar
frtabu committed
94 95
  (pDCP_Pp->is_srb) ? "SRB" : "DRB",\
  pDCP_Pp->rb_id
96
int init_pdcp_thread(void);
97 98
void cleanup_pdcp_thread(void);

99 100 101 102 103 104 105 106 107 108 109 110 111
uint32_t Pdcp_stats_tx_window_ms[MAX_eNB][MAX_MOBILES_PER_ENB];
uint32_t Pdcp_stats_tx_bytes[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx_bytes_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx_bytes_tmp_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx_tmp_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx_sn[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx_throughput_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx_aiat[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx_aiat_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx_aiat_tmp_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_tx_iat[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
112

113 114 115 116 117 118 119 120 121 122 123 124 125 126
uint32_t Pdcp_stats_rx_window_ms[MAX_eNB][MAX_MOBILES_PER_ENB];
uint32_t Pdcp_stats_rx[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_tmp_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_bytes[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_bytes_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_bytes_tmp_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_sn[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_goodput_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_aiat[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_aiat_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_aiat_tmp_w[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_iat[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
uint32_t Pdcp_stats_rx_outoforder[MAX_eNB][MAX_MOBILES_PER_ENB][NB_RB_MAX];
127

128
void pdcp_update_perioidical_stats(const protocol_ctxt_t *const  ctxt_pP);
Navid Nikaein's avatar
Navid Nikaein committed
129

130 131

/*Packet Probing for agent PDCP*/
132 133
//uint64_t *pdcp_packet_counter;
//uint64_t *pdcp_size_packet;
134 135
typedef struct pdcp_enb_s {
  // used for eNB stats generation
136 137
  uint16_t uid[MAX_MOBILES_PER_ENB];
  rnti_t rnti[MAX_MOBILES_PER_ENB];
138
  uint16_t num_ues;
frtabu's avatar
frtabu committed
139

140 141 142
  uint64_t sfn;
  frame_t  frame;
  sub_frame_t subframe;
frtabu's avatar
frtabu committed
143 144

} pdcp_enb_t;
145

146
pdcp_enb_t pdcp_enb[MAX_NUM_CCs];
147

148
typedef struct pdcp_stats_s {
149 150 151
  time_stats_t pdcp_run;
  time_stats_t data_req;
  time_stats_t data_ind;
152
  time_stats_t apply_security; //
153
  time_stats_t validate_security;
154
  time_stats_t pdcp_ip;
155
  time_stats_t ip_pdcp; // separte thread
156
} pdcp_stats_t; // common to eNB and UE
157 158


159 160
typedef struct pdcp_s {
  //boolean_t     instanciated_instance;
161
  uint16_t       header_compression_profile;
162

163 164 165
  /* SR: added this flag to distinguish UE/eNB instance as pdcp_run for virtual
   * mode can receive data on NETLINK for eNB while eNB_flag = 0 and for UE when eNB_flag = 1
   */
Lionel Gauthier's avatar
Lionel Gauthier committed
166
  boolean_t is_ue;
167
  boolean_t is_srb;
168

frtabu's avatar
frtabu committed
169
  /* Configured security algorithms */
170 171
  uint8_t cipheringAlgorithm;
  uint8_t integrityProtAlgorithm;
172

173 174 175 176 177
  /* User-Plane encryption key
   * Control-Plane RRC encryption key
   * Control-Plane RRC integrity key
   * These keys are configured by RRC layer
   */
178 179 180
  uint8_t *kUPenc;
  uint8_t *kRRCint;
  uint8_t *kRRCenc;
181

182
  uint8_t security_activated;
183

Lionel Gauthier's avatar
Lionel Gauthier committed
184
  rlc_mode_t rlc_mode;
185 186
  uint8_t status_report;
  uint8_t seq_num_size;
187

Lionel Gauthier's avatar
Lionel Gauthier committed
188
  logical_chan_id_t lcid;
189
  rb_id_t           rb_id;
190 191 192 193 194
  /*
   * Sequence number state variables
   *
   * TX and RX window
   */
Lionel Gauthier's avatar
Lionel Gauthier committed
195 196
  pdcp_sn_t next_pdcp_tx_sn;
  pdcp_sn_t next_pdcp_rx_sn;
197
  pdcp_sn_t maximum_pdcp_rx_sn;
198 199 200
  /*
   * TX and RX Hyper Frame Numbers
   */
Lionel Gauthier's avatar
Lionel Gauthier committed
201 202
  pdcp_hfn_t tx_hfn;
  pdcp_hfn_t rx_hfn;
203

204 205 206
  /*
   * SN of the last PDCP SDU delivered to upper layers
   */
Lionel Gauthier's avatar
Lionel Gauthier committed
207
  pdcp_sn_t  last_submitted_pdcp_rx_sn;
208 209 210 211 212 213

  /*
   * Following array is used as a bitmap holding missing sequence
   * numbers to generate a PDCP Control PDU for PDCP status
   * report (see 6.2.6)
   */
214
  uint8_t missing_pdu_bitmap[512];
215 216 217 218 219
  /*
   * This is intentionally signed since we need a 'NULL' value
   * which is not also a valid sequence number
   */
  short int first_missing_pdu;
220

221 222
} pdcp_t;

223
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
224
typedef struct pdcp_mbms_s {
Lionel Gauthier's avatar
Lionel Gauthier committed
225 226
  boolean_t instanciated_instance;
  rb_id_t   rb_id;
227
} pdcp_mbms_t;
Lionel Gauthier's avatar
Lionel Gauthier committed
228
#endif
229 230 231 232 233 234 235 236 237
/*
 * Following symbolic constant alters the behaviour of PDCP
 * and makes it linked to PDCP test code under targets/TEST/PDCP/
 *
 * For the version at SVN repository this should be UNDEFINED!
 * XXX And later this should be configured through the Makefile
 * under targets/TEST/PDCP/
 */

238
/*! \fn boolean_t pdcp_data_req(const protocol_ctxt_t* const  , srb_flag_t , rb_id_t , mui_t , confirm_t ,sdu_size_t , unsigned char* , pdcp_transmission_mode_t )
239
* \brief This functions handles data transfer requests coming either from RRC or from IP
240 241
* \param[in] ctxt_pP        Running context.
* \param[in] rab_id         Radio Bearer ID
242
* \param[in] muiP
243 244
* \param[in] confirmP
* \param[in] sdu_buffer_size Size of incoming SDU in bytes
245 246
* \param[in] sdu_buffer      Buffer carrying SDU
* \param[in] mode            flag to indicate whether the userplane data belong to the control plane or data plane or transparent
247 248 249 250
* \return TRUE on success, FALSE otherwise
* \note None
* @ingroup _pdcp
*/
251
boolean_t pdcp_data_req(
252
  protocol_ctxt_t  *ctxt_pP,
frtabu's avatar
frtabu committed
253 254 255 256 257
  const srb_flag_t srb_flagP,
  const rb_id_t rb_id,
  const mui_t muiP,
  const confirm_t confirmP, \
  const sdu_size_t sdu_buffer_size,
258
  unsigned char *const sdu_buffer,
frtabu's avatar
frtabu committed
259
  const pdcp_transmission_mode_t mode
260
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
261 262
  ,const uint32_t *const sourceL2Id
  ,const uint32_t *const destinationL2Id
263
#endif
264
);
265

266
/*! \fn boolean_t pdcp_data_ind(const protocol_ctxt_t* const, srb_flag_t, MBMS_flag_t, rb_id_t, sdu_size_t, mem_block_t*, boolean_t)
267
* \brief This functions handles data transfer indications coming from RLC
268
* \param[in] ctxt_pP        Running context.
269
* \param[in] Shows if rb is SRB
270 271 272 273 274 275 276 277 278
* \param[in] Tells if MBMS traffic
* \param[in] rab_id Radio Bearer ID
* \param[in] sdu_buffer_size Size of incoming SDU in bytes
* \param[in] sdu_buffer Buffer carrying SDU
* \param[in] is_data_plane flag to indicate whether the userplane data belong to the control plane or data plane
* \return TRUE on success, FALSE otherwise
* \note None
* @ingroup _pdcp
*/
279
boolean_t pdcp_data_ind(
280
  const protocol_ctxt_t *const  ctxt_pP,
frtabu's avatar
frtabu committed
281 282 283 284
  const srb_flag_t srb_flagP,
  const MBMS_flag_t MBMS_flagP,
  const rb_id_t rb_id,
  const sdu_size_t sdu_buffer_size,
285
  mem_block_t *const sdu_buffer);
286

287
/*! \fn void rrc_pdcp_config_req(const protocol_ctxt_t* const ,uint32_t,rb_id_t,uint8_t)
288
* \brief This functions initializes relevant PDCP entity
289
* \param[in] ctxt_pP        Running context.
Lionel Gauthier's avatar
Lionel Gauthier committed
290 291 292
* \param[in] actionP flag for action: add, remove , modify
* \param[in] rb_idP Radio Bearer ID of relevant PDCP entity
* \param[in] security_modeP Radio Bearer ID of relevant PDCP entity
293 294 295
* \return none
* \note None
* @ingroup _pdcp
296
*/
297
void rrc_pdcp_config_req (
298
  const protocol_ctxt_t *const  ctxt_pP,
frtabu's avatar
frtabu committed
299 300 301 302
  const srb_flag_t  srb_flagP,
  const uint32_t    actionP,
  const rb_id_t     rb_idP,
  const uint8_t     security_modeP);
303

304
/*! \fn bool rrc_pdcp_config_asn1_req (const protocol_ctxt_t* const , SRB_ToAddModList_t* srb2add_list, DRB_ToAddModList_t* drb2add_list, DRB_ToReleaseList_t*  drb2release_list)
305
* \brief  Function for RRC to configure a Radio Bearer.
306
* \param[in]  ctxt_pP           Running context.
307 308 309 310
* \param[in]  index             index of UE or eNB depending on the eNB_flag
* \param[in]  srb2add_list      SRB configuration list to be created.
* \param[in]  drb2add_list      DRB configuration list to be created.
* \param[in]  drb2release_list  DRB configuration list to be released.
311 312 313 314
* \param[in]  security_mode     Security algorithm to apply for integrity/ciphering
* \param[in]  kRRCenc           RRC encryption key
* \param[in]  kRRCint           RRC integrity key
* \param[in]  kUPenc            User-Plane encryption key
315
* \param[in]  defaultDRB        Default DRB ID
316 317
* \return     A status about the processing, OK or error code.
*/
318
boolean_t rrc_pdcp_config_asn1_req (
319
  const protocol_ctxt_t *const  ctxt_pP,
frtabu's avatar
frtabu committed
320 321 322 323 324 325 326
  LTE_SRB_ToAddModList_t  *const srb2add_list,
  LTE_DRB_ToAddModList_t  *const drb2add_list,
  LTE_DRB_ToReleaseList_t *const drb2release_list,
  const uint8_t                   security_modeP,
  uint8_t                  *const kRRCenc,
  uint8_t                  *const kRRCint,
  uint8_t                  *const kUPenc
327
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
frtabu's avatar
frtabu committed
328
  ,LTE_PMCH_InfoList_r9_t  *pmch_InfoList_r9
329
#endif
frtabu's avatar
frtabu committed
330
  ,rb_id_t                 *const defaultDRB
331
);
332

333
/*! \fn boolean_t pdcp_config_req_asn1 (const protocol_ctxt_t* const ctxt_pP, srb_flag_t srb_flagP, uint32_t  action, rb_id_t rb_id, uint8_t rb_sn, uint8_t rb_report, uint16_t header_compression_profile, uint8_t security_mode)
334
* \brief  Function for RRC to configure a Radio Bearer.
335
* \param[in]  ctxt_pP           Running context.
Lionel Gauthier's avatar
Lionel Gauthier committed
336 337 338
* \param[in]  pdcp_pP            Pointer on PDCP structure.
* \param[in]  enb_mod_idP        Virtualized enb module identifier, Not used if eNB_flagP = 0.
* \param[in]  ue_mod_idP         Virtualized ue module identifier.
339 340
* \param[in]  frame              Frame index.
* \param[in]  eNB_flag           Flag to indicate eNB (1) or UE (0)
341
* \param[in]  srb_flagP          Flag to indicate SRB (1) or DRB (0)
342 343 344 345 346 347
* \param[in]  action             add, remove, modify a RB
* \param[in]  rb_id              radio bearer id
* \param[in]  rb_sn              sequence number for this radio bearer
* \param[in]  drb_report         set a pdcp report for this drb
* \param[in]  header_compression set the rohc profile
* \param[in]  security_mode      set the integrity and ciphering algs
348 349 350
* \param[in]  kRRCenc            RRC encryption key
* \param[in]  kRRCint            RRC integrity key
* \param[in]  kUPenc             User-Plane encryption key
351 352
* \return     A status about the processing, OK or error code.
*/
353
boolean_t pdcp_config_req_asn1 (
354
  const protocol_ctxt_t *const  ctxt_pP,
frtabu's avatar
frtabu committed
355 356 357 358 359 360 361 362 363 364 365 366 367 368
  pdcp_t         *const pdcp_pP,
  const srb_flag_t       srb_flagP,
  const rlc_mode_t       rlc_mode,
  const uint32_t         action,
  const uint16_t         lc_id,
  const uint16_t         mch_id,
  const rb_id_t          rb_id,
  const uint8_t          rb_sn,
  const uint8_t          rb_report,
  const uint16_t         header_compression_profile,
  const uint8_t          security_mode,
  uint8_t         *const kRRCenc,
  uint8_t         *const kRRCint,
  uint8_t         *const kUPenc);
Raymond Knopp's avatar
 
Raymond Knopp committed
369

370 371 372 373 374
/*! \fn void pdcp_add_UE(const protocol_ctxt_t* const  ctxt_pP)
* \brief  Function (for RRC) to add a new UE in PDCP module
* \param[in]  ctxt_pP           Running context.
* \return     A status about the processing, OK or error code.
*/
375
void pdcp_add_UE(const protocol_ctxt_t *const  ctxt_pP);
frtabu's avatar
frtabu committed
376

377
/*! \fn boolean_t pdcp_remove_UE(const protocol_ctxt_t* const  ctxt_pP)
frtabu's avatar
frtabu committed
378
* \brief  Function for RRC to remove UE from PDCP module hashtable
379
* \param[in]  ctxt_pP           Running context.
Raymond Knopp's avatar
 
Raymond Knopp committed
380 381
* \return     A status about the processing, OK or error code.
*/
382
boolean_t pdcp_remove_UE(
383
  const protocol_ctxt_t *const  ctxt_pP);
Raymond Knopp's avatar
 
Raymond Knopp committed
384

385
/*! \fn void rrc_pdcp_config_release( const protocol_ctxt_t* const, rb_id_t)
386
* \brief This functions is unused
387
* \param[in]  ctxt_pP           Running context.
388 389 390 391 392
* \param[in] rab_id Radio Bearer ID of relevant PDCP entity
* \return none
* \note None
* @ingroup _pdcp
*/
393
//void rrc_pdcp_config_release ( const protocol_ctxt_t* const  ctxt_pP, rb_id_t);
394

395
/*! \fn void pdcp_run(const protocol_ctxt_t* const  ctxt_pP)
396
* \brief Runs PDCP entity to let it handle incoming/outgoing SDUs
397
* \param[in]  ctxt_pP           Running context.
398 399 400 401
* \return none
* \note None
* @ingroup _pdcp
*/
402
void pdcp_run            (
403
  const protocol_ctxt_t *const  ctxt_pP);
404
uint64_t pdcp_module_init     (uint64_t pdcp_optmask);
405 406 407
void pdcp_module_cleanup (void);
void pdcp_layer_init     (void);
void pdcp_layer_cleanup  (void);
408 409
#define PDCP2NW_DRIVER_FIFO 21
#define NW_DRIVER2PDCP_FIFO 22
410

411 412 413 414
int pdcp_fifo_flush_sdus                      ( const protocol_ctxt_t *const  ctxt_pP);
int pdcp_fifo_read_input_sdus_remaining_bytes ( const protocol_ctxt_t *const  ctxt_pP);
int pdcp_fifo_read_input_sdus                 ( const protocol_ctxt_t *const  ctxt_pP);
void pdcp_fifo_read_input_sdus_from_otg       ( const protocol_ctxt_t *const  ctxt_pP);
415 416
void pdcp_set_rlc_data_req_func(send_rlc_data_req_func_t send_rlc_data_req);
void pdcp_set_pdcp_data_ind_func(pdcp_data_ind_func_t pdcp_data_ind);
frtabu's avatar
frtabu committed
417
pdcp_data_ind_func_t get_pdcp_data_ind_func(void);
418 419 420 421 422
//-----------------------------------------------------------------------------

/*
 * Following two types are utilized between NAS driver and PDCP
 */
423 424 425


typedef struct pdcp_data_req_header_s {
426
  rb_id_t             rb_id;
427
  sdu_size_t          data_size;
428
  signed int          inst;
429
  ip_traffic_type_t   traffic_type;
430
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
431 432 433
  uint32_t sourceL2Id;
  uint32_t destinationL2Id;
#endif
434
} pdcp_data_req_header_t;
435 436

typedef struct pdcp_data_ind_header_s {
437
  rb_id_t             rb_id;
438
  sdu_size_t          data_size;
439
  signed int          inst;
440
  ip_traffic_type_t   dummy_traffic_type;
441
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
442 443 444
  uint32_t sourceL2Id;
  uint32_t destinationL2Id;
#endif
445 446
} pdcp_data_ind_header_t;

447
struct pdcp_netlink_element_s {
448
  pdcp_data_req_header_t pdcp_read_header;
449

450 451
  /* Data part of the message */
  uint8_t *data;
452 453
};

454
//TTN for D2D (PC5S)
455
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
456 457 458 459 460 461 462 463 464
#define PDCP_SOCKET_PORT_NO 9999 //temporary value
#define PC5_SIGNALLING_PAYLOAD_SIZE   100  //should be updated with a correct value
int pdcp_pc5_sockfd;
struct sockaddr_in prose_ctrl_addr;
struct sockaddr_in prose_pdcp_addr;
struct sockaddr_in pdcp_sin;
void pdcp_pc5_socket_init(void);

typedef struct  {
frtabu's avatar
frtabu committed
465 466 467 468 469 470
  rb_id_t             rb_id;
  sdu_size_t          data_size;
  signed int          inst;
  ip_traffic_type_t   traffic_type;
  uint32_t sourceL2Id;
  uint32_t destinationL2Id;
471 472 473 474
} __attribute__((__packed__)) pc5s_header_t;

//new PC5S-message
typedef struct  {
frtabu's avatar
frtabu committed
475
  unsigned char bytes[PC5_SIGNALLING_PAYLOAD_SIZE];
476 477 478 479
}  __attribute__((__packed__)) PC5SignallingMessage ;

//example of PC5-S messages
typedef struct {
frtabu's avatar
frtabu committed
480 481 482 483 484
  pc5s_header_t pc5s_header;
  union {
    uint8_t status;
    PC5SignallingMessage pc5_signalling_message;
  } pc5sPrimitive;
485 486 487 488 489
} __attribute__((__packed__)) sidelink_pc5s_element;


#endif

490 491 492 493 494 495 496 497
/*
 * PDCP limit values
 */
#define PDCP_MAX_SDU_SIZE 8188 // octets, see 4.3.1 Services provided to upper layers
#define PDCP_MAX_SN_5BIT  31   // 2^5-1
#define PDCP_MAX_SN_7BIT  127  // 2^7-1
#define PDCP_MAX_SN_12BIT 4095 // 2^12-1

498 499
/*
 * Reordering_Window: half of the PDCP SN space
500
 */
501 502 503 504
#define REORDERING_WINDOW_SN_5BIT 16
#define REORDERING_WINDOW_SN_7BIT 64
#define REORDERING_WINDOW_SN_12BIT 2048

505 506 507
signed int             pdcp_2_nas_irq;
pdcp_stats_t              UE_pdcp_stats[MAX_MOBILES_PER_ENB];
pdcp_stats_t              eNB_pdcp_stats[NUMBER_OF_eNB_MAX];
508

509 510

// for UE code conly
511 512 513
rnti_t                 pdcp_UE_UE_module_id_to_rnti[MAX_MOBILES_PER_ENB];
rnti_t                 pdcp_eNB_UE_instance_to_rnti[MAX_MOBILES_PER_ENB]; // for noS1 mode
unsigned int           pdcp_eNB_UE_instance_to_rnti_index;
514
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
515 516
  pdcp_mbms_t               pdcp_mbms_array_ue[MAX_MOBILES_PER_ENB][LTE_maxServiceCount][LTE_maxSessionPerPMCH];   // some constants from openair2/RRC/LTE/MESSAGES/asn1_constants.h
  pdcp_mbms_t               pdcp_mbms_array_eNB[NUMBER_OF_eNB_MAX][LTE_maxServiceCount][LTE_maxSessionPerPMCH]; // some constants from openair2/RRC/LTE/MESSAGES/asn1_constants.h
Lionel Gauthier's avatar
Lionel Gauthier committed
517
#endif
518 519 520 521 522 523 524 525 526
sdu_size_t             pdcp_output_sdu_bytes_to_write;
sdu_size_t             pdcp_output_header_bytes_to_write;
list_t                 pdcp_sdu_list;
int                    pdcp_sent_a_sdu;
pdcp_data_req_header_t pdcp_input_header;
unsigned char          pdcp_input_sdu_buffer[MAX_IP_PACKET_SIZE];
sdu_size_t             pdcp_input_index_header;
sdu_size_t             pdcp_input_sdu_size_read;
sdu_size_t             pdcp_input_sdu_remaining_size_to_read;
527

528
#define PDCP_COLL_KEY_VALUE(mODULE_iD, rNTI, iS_eNB, rB_iD, iS_sRB) \
frtabu's avatar
frtabu committed
529 530 531 532 533 534
  ((hash_key_t)mODULE_iD          | \
   (((hash_key_t)(rNTI))   << 8)  | \
   (((hash_key_t)(iS_eNB)) << 24) | \
   (((hash_key_t)(rB_iD))  << 25) | \
   (((hash_key_t)(iS_sRB)) << 33) | \
   (((hash_key_t)(0x55))   << 34))
535 536 537 538 539

// hash key to the same PDCP as indexed by PDCP_COLL_KEY_VALUE(... rB_iD, iS_sRB=0) where rB_iD
// is the default DRB ID. The hidden code 0x55 indicates the key is indexed by (rB_iD,is_sRB)
// whereas the hidden code 0xaa indicates the key is for default DRB only
#define PDCP_COLL_KEY_DEFAULT_DRB_VALUE(mODULE_iD, rNTI, iS_eNB) \
frtabu's avatar
frtabu committed
540 541 542 543 544 545
  ((hash_key_t)mODULE_iD          | \
   (((hash_key_t)(rNTI))   << 8)  | \
   (((hash_key_t)(iS_eNB)) << 24) | \
   (((hash_key_t)(0xff))   << 25) | \
   (((hash_key_t)(0x00))   << 33) | \
   (((hash_key_t)(0xaa))   << 34))
546 547 548 549

// service id max val is maxServiceCount = 16 (asn1_constants.h)

#define PDCP_COLL_KEY_MBMS_VALUE(mODULE_iD, rNTI, iS_eNB, sERVICE_ID, sESSION_ID) \
frtabu's avatar
frtabu committed
550 551 552 553 554 555
  ((hash_key_t)mODULE_iD              | \
   (((hash_key_t)(rNTI))       << 8)  | \
   (((hash_key_t)(iS_eNB))     << 24) | \
   (((hash_key_t)(sERVICE_ID)) << 32) | \
   (((hash_key_t)(sESSION_ID)) << 37) | \
   (((hash_key_t)(0x0000000000000001))  << 63))
556

557
extern hash_table_t  *pdcp_coll_p;
558 559

#endif
560
/*@}*/