rrc_common.c 6.23 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 21
 * 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
 */

22
/*! \file rrc_common.c
23
 * \brief rrc common procedures for eNB and UE
24 25
 * \author Navid Nikaein and Raymond Knopp
 * \date 2011 - 2014
26 27
 * \version 1.0
 * \company Eurecom
28
 * \email:  navid.nikaein@eurecom.fr and raymond.knopp@eurecom.fr
29
 */
30 31 32 33 34

#include "defs.h"
#include "extern.h"
#include "LAYER2/MAC/extern.h"
#include "COMMON/openair_defs.h"
35
#include "COMMON/platform_types.h"
36 37 38 39
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#include "LAYER2/RLC/rlc.h"
#include "COMMON/mac_rrc_primitives.h"
#include "UTIL/LOG/log.h"
40
#include "asn1_msg.h"
41
#include "pdcp.h"
42
#include "UTIL/LOG/vcd_signal_dumper.h"
43
#include "rrc_eNB_UE_context.h"
44
#include "common/ran_context.h"
45

46
#ifdef LOCALIZATION
47 48 49
#include <sys/time.h>
#endif

50
#define DEBUG_RRC 1
51
extern RAN_CONTEXT_t RC;
52 53
extern UE_MAC_INST *UE_mac_inst;

54 55
extern mui_t rrc_eNB_mui;

56 57 58 59 60 61
//-----------------------------------------------------------------------------
int
rrc_init_global_param(
  void
)
//-----------------------------------------------------------------------------
62
{
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

  //#ifdef USER_MODE
  //  Rrc_xface = (RRC_XFACE*)malloc16(sizeof(RRC_XFACE));
  //#endif //USRE_MODE

  //  Rrc_xface->openair_rrc_top_init = openair_rrc_top_init;
  //  Rrc_xface->openair_rrc_eNB_init = openair_rrc_eNB_init;
  //  Rrc_xface->openair_rrc_UE_init  = openair_rrc_ue_init;
  //  Rrc_xface->mac_rrc_data_ind     = mac_rrc_data_ind;
  //Rrc_xface->mac_rrc_data_req     = mac_rrc_data_req;
  // Rrc_xface->rrc_data_indP        = (void *)rlcrrc_data_ind;
  //  Rrc_xface->rrc_rx_tx            = rrc_rx_tx;
  //  Rrc_xface->mac_rrc_meas_ind     = mac_rrc_meas_ind;
  //  Rrc_xface->get_rrc_status       = get_rrc_status;

  //Rrc_xface->rrc_get_status = ...

  //  Mac_rlc_xface->mac_out_of_sync_ind=mac_out_of_sync_ind;

#ifndef NO_RRM
  //  Rrc_xface->fn_rrc=fn_rrc;
#endif
  //  LOG_D(RRC, "[RRC]INIT_GLOBAL_PARAM: Mac_rlc_xface %p, rrc_rlc_register %p,rlcrrc_data_ind%p\n",Mac_rlc_xface,Mac_rlc_xface->rrc_rlc_register_rrc,rlcrrc_data_ind);
  /*
87 88 89 90 91 92
   if((Mac_rlc_xface==NULL) || (Mac_rlc_xface->rrc_rlc_register_rrc==NULL) ||
   (rlcrrc_data_ind==NULL)) {
   LOG_E(RRC,"Data structured is not initialized \n");
   return -1;
   }
   */
93
  rrc_rlc_register_rrc (rrc_data_ind, NULL); //register with rlc
94 95 96 97 98 99 100 101 102 103 104

  DCCH_LCHAN_DESC.transport_block_size = 4;
  DCCH_LCHAN_DESC.max_transport_blocks = 16;
  DCCH_LCHAN_DESC.Delay_class = 1;
  DTCH_DL_LCHAN_DESC.transport_block_size = 52;
  DTCH_DL_LCHAN_DESC.max_transport_blocks = 20;
  DTCH_DL_LCHAN_DESC.Delay_class = 1;
  DTCH_UL_LCHAN_DESC.transport_block_size = 52;
  DTCH_UL_LCHAN_DESC.max_transport_blocks = 20;
  DTCH_UL_LCHAN_DESC.Delay_class = 1;

Lionel Gauthier's avatar
Lionel Gauthier committed
105
  Rlc_info_um.rlc_mode = RLC_MODE_UM;
106 107 108
  Rlc_info_um.rlc.rlc_um_info.timer_reordering = 5;
  Rlc_info_um.rlc.rlc_um_info.sn_field_length = 10;
  Rlc_info_um.rlc.rlc_um_info.is_mXch = 0;
109 110
  //Rlc_info_um.rlc.rlc_um_info.sdu_discard_mode=16;

Lionel Gauthier's avatar
Lionel Gauthier committed
111
  Rlc_info_am_config.rlc_mode = RLC_MODE_AM;
112
  Rlc_info_am_config.rlc.rlc_am_info.max_retx_threshold = 50;
113 114 115 116 117
  Rlc_info_am_config.rlc.rlc_am_info.poll_pdu = 8;
  Rlc_info_am_config.rlc.rlc_am_info.poll_byte = 1000;
  Rlc_info_am_config.rlc.rlc_am_info.t_poll_retransmit = 15;
  Rlc_info_am_config.rlc.rlc_am_info.t_reordering = 50;
  Rlc_info_am_config.rlc.rlc_am_info.t_status_prohibit = 10;
118

119
  return 0;
120 121
}

122 123 124 125 126 127 128 129
//-----------------------------------------------------------------------------
void
rrc_config_buffer(
  SRB_INFO* Srb_info,
  uint8_t Lchan_type,
  uint8_t Role
)
//-----------------------------------------------------------------------------
130
{
131 132 133 134 135

  Srb_info->Rx_buffer.payload_size = 0;
  Srb_info->Tx_buffer.payload_size = 0;
}

136

137 138 139 140 141 142 143 144
//-----------------------------------------------------------------------------
long
binary_search_int(
  int elements[],
  long numElem,
  int value
)
//-----------------------------------------------------------------------------
145
{
winckel's avatar
winckel committed
146
  long first, last, middle, search = -1;
147 148 149
  first = 0;
  last = numElem-1;
  middle = (first+last)/2;
150

151
  if(value < elements[0]) {
152
    return first;
153
  }
154

155
  if(value > elements[last]) {
156
    return last;
157
  }
158

159
  while (first <= last) {
160
    if (elements[middle] < value) {
161
      first = middle+1;
162
    } else if (elements[middle] == value) {
163 164
      search = middle+1;
      break;
165
    } else {
166
      last = middle -1;
167
    }
168

169 170
    middle = (first+last)/2;
  }
171

172
  if (first > last) {
173
    LOG_E(RRC,"Error in binary search!");
174
  }
175

176 177 178 179 180 181 182
  return search;
}

/* This is a binary search routine which operates on an array of floating
   point numbers and returns the index of the range the value lies in
   Used for RSRP and RSRQ measurement mapping. Can potentially be used for other things
*/
183 184 185 186 187 188 189 190
//-----------------------------------------------------------------------------
long
binary_search_float(
  float elements[],
  long numElem,
  float value
)
//-----------------------------------------------------------------------------
191
{
winckel's avatar
winckel committed
192
  long first, last, middle;
193 194 195
  first = 0;
  last = numElem-1;
  middle = (first+last)/2;
196

197
  if(value <= elements[0]) {
198
    return first;
199
  }
200

201
  if(value >= elements[last]) {
202
    return last;
203
  }
204

205
  while (last - first > 1) {
206
    if (elements[middle] > value) {
207
      last = middle;
208
    } else {
209
      first = middle;
210
    }
211

212 213
    middle = (first+last)/2;
  }
214

215
  if (first < 0 || first >= numElem) {
216
    LOG_E(RRC,"\n Error in binary search float!");
217
  }
218

219 220 221
  return first;
}