config.c 27.8 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 config.c
23
 * \brief UE and eNB configuration performed by RRC or as a consequence of RRC procedures
24 25
 * \author  Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
26 27 28
 * \version 0.1
 * \email: navid.nikaein@eurecom.fr
 * @ingroup _mac
29

30
 */
31

32 33 34 35 36 37 38 39 40
#include "COMMON/platform_types.h"
#include "COMMON/platform_constants.h"
#include "SystemInformationBlockType2.h"
//#include "RadioResourceConfigCommonSIB.h"
#include "RadioResourceConfigDedicated.h"
#include "MeasGapConfig.h"
#include "MeasObjectToAddModList.h"
#include "TDD-Config.h"
#include "defs.h"
41
#include "proto.h"
42 43 44 45 46 47 48 49 50
#include "extern.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#ifdef Rel10
#include "MBSFN-AreaInfoList-r9.h"
#include "MBSFN-AreaInfo-r9.h"
#include "MBSFN-SubframeConfigList.h"
#include "PMCH-InfoList-r9.h"
#endif
51 52

/* sec 5.9, 36.321: MAC Reset Procedure */
53 54
void ue_mac_reset(module_id_t module_idP,uint8_t eNB_index)
{
55

56
  //Resetting Bj
57 58 59
  UE_mac_inst[module_idP].scheduling_info.Bj[0] = 0;
  UE_mac_inst[module_idP].scheduling_info.Bj[1] = 0;
  UE_mac_inst[module_idP].scheduling_info.Bj[2] = 0;
60

61
  //Stopping all timers
62

63
  //timeAlignmentTimer expires
64

65
  // PHY changes for UE MAC reset
66
  mac_xface->phy_reset_ue(module_idP,0,eNB_index);
67

68 69
  // notify RRC to relase PUCCH/SRS
  // cancel all pending SRs
70 71
  UE_mac_inst[module_idP].scheduling_info.SR_pending=0;
  UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0;
fnabet's avatar
fnabet committed
72
  UE_mac_inst[module_idP].BSR_reporting_active=0;
73

74
  // stop ongoing RACH procedure
75

76
  // discard explicitly signaled ra_PreambleIndex and ra_RACH_MaskIndex, if any
77 78 79
  UE_mac_inst[module_idP].RA_prach_resources.ra_PreambleIndex  = 0; // check!
  UE_mac_inst[module_idP].RA_prach_resources.ra_RACH_MaskIndex = 0;

knopp's avatar
knopp committed
80

81 82
  ue_init_mac(module_idP); //This will hopefully do the rest of the MAC reset procedure

83 84
}

85 86
int
rrc_mac_config_req(
87 88
  module_id_t                      Mod_idP,
  int                              CC_idP,
89 90 91
  eNB_flag_t                       eNB_flagP,
  rnti_t                           rntiP,
  uint8_t                          eNB_index,
92 93
                       RadioResourceConfigCommonSIB_t  *radioResourceConfigCommon,
                       struct PhysicalConfigDedicated  *physicalConfigDedicated,
94
#ifdef Rel10
95 96
                       SCellToAddMod_r10_t *sCellToAddMod_r10,
                       //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
knopp's avatar
knopp committed
97
#endif
98 99 100 101 102 103 104 105 106 107 108 109 110
                       MeasObjectToAddMod_t           **measObj,
                       MAC_MainConfig_t                *mac_MainConfig,
                       long                             logicalChannelIdentity,
                       LogicalChannelConfig_t          *logicalChannelConfig,
                       MeasGapConfig_t                 *measGapConfig,
                       TDD_Config_t                    *tdd_Config,
                       MobilityControlInfo_t           *mobilityControlInfo,
                       uint8_t                              *SIwindowsize,
                       uint16_t                             *SIperiod,
                       ARFCN_ValueEUTRA_t              *ul_CarrierFreq,
                       long                            *ul_Bandwidth,
                       AdditionalSpectrumEmission_t    *additionalSpectrumEmission,
                       struct MBSFN_SubframeConfigList *mbsfn_SubframeConfigList
knopp's avatar
knopp committed
111
#ifdef Rel10
112 113 114 115
                       ,uint8_t                              MBMS_Flag,
                       MBSFN_AreaInfoList_r9_t         *mbsfn_AreaInfoList,
                       PMCH_InfoList_r9_t              *pmch_InfoList
#endif
116
#ifdef CBA
117 118
                       ,uint8_t                              num_active_cba_groups,
                       uint16_t                              cba_rnti
119
#endif
120 121
                      )
{
122

123
  int i;
124

125
  int UE_id = -1;
126 127 128
  eNB_MAC_INST *eNB = &eNB_mac_inst[Mod_idP];
  UE_list_t *UE_list= &eNB->UE_list;

gauthier's avatar
gauthier committed
129
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_MAC_CONFIG, VCD_FUNCTION_IN);
130

131
  if (eNB_flagP==0) {
132
    LOG_I(MAC,"[CONFIG][UE %d] Configuring MAC/PHY from eNB %d\n",Mod_idP,eNB_index);
133

134
    if (tdd_Config != NULL) {
135
      UE_mac_inst[Mod_idP].tdd_Config = tdd_Config;
136
    }
137
  } else {
138
    UE_id = find_UE_id(Mod_idP, rntiP);
139
    if (physicalConfigDedicated == NULL) {
140
      LOG_I(MAC,"[CONFIG][eNB %d/%d] Configuring MAC/PHY\n", Mod_idP, CC_idP);
141
    } else {
142
      LOG_I(MAC,"[CONFIG][eNB %d/%d] Configuring MAC/PHY for UE %d (%x)\n", Mod_idP, CC_idP, UE_id, UE_RNTI(Mod_idP, UE_id));
143
    }
144
  }
145

146
  if (tdd_Config && SIwindowsize && SIperiod) {
147
    if (eNB_flagP == ENB_FLAG_YES) {
148
      mac_xface->phy_config_sib1_eNB(Mod_idP, CC_idP, tdd_Config, *SIwindowsize, *SIperiod);
149
    } else {
150
      mac_xface->phy_config_sib1_ue(Mod_idP,0,eNB_index,tdd_Config,*SIwindowsize,*SIperiod);
151
    }
152
  }
153

154
  if (radioResourceConfigCommon!=NULL) {
155 156 157 158 159 160 161 162 163 164
    if (eNB_flagP==1) {
      LOG_I(MAC,"[CONFIG]SIB2/3 Contents (partial)\n");
      LOG_I(MAC,"[CONFIG]pusch_config_common.n_SB = %ld\n",radioResourceConfigCommon->pusch_ConfigCommon.pusch_ConfigBasic.n_SB);
      LOG_I(MAC,"[CONFIG]pusch_config_common.hoppingMode = %ld\n",radioResourceConfigCommon->pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode);
      LOG_I(MAC,"[CONFIG]pusch_config_common.pusch_HoppingOffset = %ld\n",  radioResourceConfigCommon->pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset);
      LOG_I(MAC,"[CONFIG]pusch_config_common.enable64QAM = %d\n",radioResourceConfigCommon->pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM);
      LOG_I(MAC,"[CONFIG]pusch_config_common.groupHoppingEnabled = %d\n",radioResourceConfigCommon->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
      LOG_I(MAC,"[CONFIG]pusch_config_common.groupAssignmentPUSCH = %ld\n",radioResourceConfigCommon->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
      LOG_I(MAC,"[CONFIG]pusch_config_common.sequenceHoppingEnabled = %d\n",radioResourceConfigCommon->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
      LOG_I(MAC,"[CONFIG]pusch_config_common.cyclicShift  = %ld\n",radioResourceConfigCommon->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift);
165
      mac_xface->phy_config_sib2_eNB(Mod_idP, CC_idP, radioResourceConfigCommon, ul_CarrierFreq, ul_Bandwidth, additionalSpectrumEmission, mbsfn_SubframeConfigList);
166
    } else {
167 168
      UE_mac_inst[Mod_idP].radioResourceConfigCommon = radioResourceConfigCommon;
      mac_xface->phy_config_sib2_ue(Mod_idP,0,eNB_index,radioResourceConfigCommon,ul_CarrierFreq,ul_Bandwidth,additionalSpectrumEmission,mbsfn_SubframeConfigList);
169
    }
170
  }
171

172 173
  // SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters->logicalChannelGroup
  if (logicalChannelConfig!= NULL) {
174
    if (eNB_flagP==0) {
175 176 177
      LOG_I(MAC,"[CONFIG][UE %d] Applying RRC logicalChannelConfig from eNB%d\n",Mod_idP,eNB_index);
      UE_mac_inst[Mod_idP].logicalChannelConfig[logicalChannelIdentity]=logicalChannelConfig;
      UE_mac_inst[Mod_idP].scheduling_info.Bj[logicalChannelIdentity]=0; // initilize the bucket for this lcid
178 179

      if (logicalChannelConfig->ul_SpecificParameters) {
180
        UE_mac_inst[Mod_idP].scheduling_info.bucket_size[logicalChannelIdentity]=logicalChannelConfig->ul_SpecificParameters->prioritisedBitRate *
181
            logicalChannelConfig->ul_SpecificParameters->bucketSizeDuration; // set the max bucket size
182 183
        UE_mac_inst[Mod_idP].scheduling_info.LCGID[logicalChannelIdentity]=*logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup;
        LOG_D(MAC,"[CONFIG][UE %d] LCID %d is attached to the LCGID %d\n",Mod_idP,logicalChannelIdentity,*logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup);
184
      } else {
185
        LOG_E(MAC,"[CONFIG][UE %d] LCID %d NULL ul_SpecificParameters\n",Mod_idP,logicalChannelIdentity);
186
        mac_xface->macphy_exit("NULL ul_SpecificParameters");
187
      }
188
    }
189 190 191 192 193 194
    else {
      if (logicalChannelConfig)
	UE_list->UE_template[CC_idP][UE_id].lcgidmap[logicalChannelIdentity] = *logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup;
      else
	UE_list->UE_template[CC_idP][UE_id].lcgidmap[logicalChannelIdentity] = 0;
    }
195 196
  }

197 198
  if (mac_MainConfig != NULL) {
    if (eNB_flagP==0) {
199 200 201
      LOG_I(MAC,"[CONFIG][UE%d] Applying RRC macMainConfig from eNB%d\n",Mod_idP,eNB_index);
      UE_mac_inst[Mod_idP].macConfig=mac_MainConfig;
      UE_mac_inst[Mod_idP].measGapConfig=measGapConfig;
202 203 204

      if (mac_MainConfig->ul_SCH_Config) {

205
        if (mac_MainConfig->ul_SCH_Config->periodicBSR_Timer) {
206
          UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_Timer = (uint16_t) *mac_MainConfig->ul_SCH_Config->periodicBSR_Timer;
207
        } else {
208
          UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_Timer = (uint16_t) MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity;
209
        }
210

211
        if (mac_MainConfig->ul_SCH_Config->maxHARQ_Tx) {
212
          UE_mac_inst[Mod_idP].scheduling_info.maxHARQ_Tx     = (uint16_t) *mac_MainConfig->ul_SCH_Config->maxHARQ_Tx;
213
        } else {
214
          UE_mac_inst[Mod_idP].scheduling_info.maxHARQ_Tx     = (uint16_t) MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
215
        }
216

217
        if (mac_MainConfig->ul_SCH_Config->retxBSR_Timer) {
218
          UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer     = (uint16_t) mac_MainConfig->ul_SCH_Config->retxBSR_Timer;
219
        } else {
220
          UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer     = (uint16_t)MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf2560;
221
      }
222
      }
223 224 225

#ifdef Rel10

226
      if (mac_MainConfig->ext1 && mac_MainConfig->ext1->sr_ProhibitTimer_r9) {
227
        UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer  = (uint16_t) *mac_MainConfig->ext1->sr_ProhibitTimer_r9;
228
      } else {
fnabet's avatar
fnabet committed
229
        UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer  = 0;
230
      }
231

fnabet's avatar
fnabet committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
      if (mac_MainConfig->ext2 && mac_MainConfig->ext2->mac_MainConfig_v1020) {
        if (mac_MainConfig->ext2->mac_MainConfig_v1020->extendedBSR_Sizes_r10) {
          UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t) *mac_MainConfig->ext2->mac_MainConfig_v1020->extendedBSR_Sizes_r10;
        } else {
          UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t)0;
        }
        if (mac_MainConfig->ext2->mac_MainConfig_v1020->extendedPHR_r10) {
          UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t) *mac_MainConfig->ext2->mac_MainConfig_v1020->extendedPHR_r10;
        } else {
          UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t)0;
        }
      } else {
        UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t)0;
        UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t)0;
      }
247
#endif
248 249
      UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_SF  = get_sf_periodicBSRTimer(UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_Timer);
      UE_mac_inst[Mod_idP].scheduling_info.retxBSR_SF     = get_sf_retxBSRTimer(UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer);
fnabet's avatar
fnabet committed
250
      UE_mac_inst[Mod_idP].BSR_reporting_active = 0;
251

fnabet's avatar
fnabet committed
252 253 254 255 256
      LOG_D(MAC,"[UE %d]: periodic BSR %d (SF), retx BSR %d (SF)\n",
            Mod_idP,
            UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_SF,
            UE_mac_inst[Mod_idP].scheduling_info.retxBSR_SF);
      
257 258
      UE_mac_inst[Mod_idP].scheduling_info.drx_config     = mac_MainConfig->drx_Config;
      UE_mac_inst[Mod_idP].scheduling_info.phr_config     = mac_MainConfig->phr_Config;
259 260

      if (mac_MainConfig->phr_Config) {
261 262 263 264 265
        UE_mac_inst[Mod_idP].PHR_state = mac_MainConfig->phr_Config->present;
        UE_mac_inst[Mod_idP].PHR_reconfigured = 1;
        UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_Timer = mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer;
        UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_Timer = mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer;
        UE_mac_inst[Mod_idP].scheduling_info.PathlossChange = mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange;
266
      } else {
267 268 269 270 271
        UE_mac_inst[Mod_idP].PHR_reconfigured = 0;
        UE_mac_inst[Mod_idP].PHR_state = MAC_MainConfig__phr_Config_PR_setup;
        UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20;
        UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20;
        UE_mac_inst[Mod_idP].scheduling_info.PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;
272
      }
273

274 275 276
      UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_SF =  get_sf_perioidicPHR_Timer(UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_Timer);
      UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_SF =  get_sf_prohibitPHR_Timer(UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_Timer);
      UE_mac_inst[Mod_idP].scheduling_info.PathlossChange_db =  get_db_dl_PathlossChange(UE_mac_inst[Mod_idP].scheduling_info.PathlossChange);
fnabet's avatar
fnabet committed
277
      UE_mac_inst[Mod_idP].PHR_reporting_active = 0;
278
      LOG_D(MAC,"[UE %d] config PHR (%d): periodic %d (SF) prohibit %d (SF)  pathlosschange %d (db) \n",
279
            Mod_idP,
280
            (mac_MainConfig->phr_Config)?mac_MainConfig->phr_Config->present:-1,
281 282 283
            UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_SF,
            UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_SF,
            UE_mac_inst[Mod_idP].scheduling_info.PathlossChange_db);
284
    }
285 286 287
  }

  if (physicalConfigDedicated != NULL) {
288
    if (eNB_flagP==1) {
289
      mac_xface->phy_config_dedicated_eNB(Mod_idP, CC_idP, UE_RNTI(Mod_idP, UE_id), physicalConfigDedicated);
290
    } else {
291 292
      mac_xface->phy_config_dedicated_ue(Mod_idP,0,eNB_index,physicalConfigDedicated);
      UE_mac_inst[Mod_idP].physicalConfigDedicated=physicalConfigDedicated; // for SR proc
293
    }
294
  }
295

knopp's avatar
knopp committed
296
#ifdef Rel10
297

knopp's avatar
knopp committed
298
  if (sCellToAddMod_r10 != NULL) {
299 300

    if (eNB_flagP==1) {
301
      mac_xface->phy_config_dedicated_scell_eNB(Mod_idP,UE_RNTI(Mod_idP,UE_id),sCellToAddMod_r10,1);
302
    } else {
303 304

	//#warning "phy_config_dedicated_scell_ue is empty"
305 306
      mac_xface->phy_config_dedicated_scell_ue(Mod_idP,eNB_index,sCellToAddMod_r10,1);
      UE_mac_inst[Mod_idP].physicalConfigDedicatedSCell_r10 = sCellToAddMod_r10->radioResourceConfigDedicatedSCell_r10->physicalConfigDedicatedSCell_r10; // using SCell index 0
knopp's avatar
knopp committed
307 308
    }
  }
309

knopp's avatar
knopp committed
310
#endif
311

312
  if (eNB_flagP == 0) {
313 314
    if (measObj!= NULL) {
      if (measObj[0]!= NULL) {
315 316
        UE_mac_inst[Mod_idP].n_adj_cells = measObj[0]->measObject.choice.measObjectEUTRA.cellsToAddModList->list.count;
        LOG_I(MAC,"Number of adjacent cells %d\n",UE_mac_inst[Mod_idP].n_adj_cells);
317

318 319 320
        for (i=0; i<UE_mac_inst[Mod_idP].n_adj_cells; i++) {
          UE_mac_inst[Mod_idP].adj_cell_id[i] = measObj[0]->measObject.choice.measObjectEUTRA.cellsToAddModList->list.array[i]->physCellId;
          LOG_I(MAC,"Cell %d : Nid_cell %d\n",i,UE_mac_inst[Mod_idP].adj_cell_id[i]);
321 322
        }

323
        mac_xface->phy_config_meas_ue(Mod_idP,0,eNB_index,UE_mac_inst[Mod_idP].n_adj_cells,UE_mac_inst[Mod_idP].adj_cell_id);
324
      }
325 326 327 328

      /*
      if (quantityConfig != NULL) {
      if (quantityConfig[0] != NULL) {
329 330
      UE_mac_inst[Mod_idP].quantityConfig = quantityConfig[0];
      LOG_I(MAC,"UE %d configured filterCoeff.",UE_mac_inst[Mod_idP].crnti);
331 332 333 334 335
      mac_xface->phy_config_meas_ue
      }
      }
       */
    }
336
  }
337

338
  if (eNB_flagP==0) {
339 340
    if(mobilityControlInfo != NULL) {

341 342
      LOG_D(MAC,"[UE%d] MAC Reset procedure triggered by RRC eNB %d \n",Mod_idP,eNB_index);
      ue_mac_reset(Mod_idP,eNB_index);
343 344

      if(mobilityControlInfo->radioResourceConfigCommon.rach_ConfigCommon) {
345
        memcpy((void *)&UE_mac_inst[Mod_idP].radioResourceConfigCommon->rach_ConfigCommon,
346 347 348 349
               (void *)mobilityControlInfo->radioResourceConfigCommon.rach_ConfigCommon,
               sizeof(RACH_ConfigCommon_t));
      }

350
      memcpy((void *)&UE_mac_inst[Mod_idP].radioResourceConfigCommon->prach_Config.prach_ConfigInfo,
351 352
             (void *)mobilityControlInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
             sizeof(PRACH_ConfigInfo_t));
353
      UE_mac_inst[Mod_idP].radioResourceConfigCommon->prach_Config.rootSequenceIndex = mobilityControlInfo->radioResourceConfigCommon.prach_Config.rootSequenceIndex;
354 355

      if(mobilityControlInfo->radioResourceConfigCommon.pdsch_ConfigCommon) {
356
        memcpy((void *)&UE_mac_inst[Mod_idP].radioResourceConfigCommon->pdsch_ConfigCommon,
357 358 359 360 361
               (void *)mobilityControlInfo->radioResourceConfigCommon.pdsch_ConfigCommon,
               sizeof(PDSCH_ConfigCommon_t));
      }

      // not a pointer: mobilityControlInfo->radioResourceConfigCommon.pusch_ConfigCommon
362
      memcpy((void *)&UE_mac_inst[Mod_idP].radioResourceConfigCommon->pusch_ConfigCommon,
363 364 365 366
             (void *)&mobilityControlInfo->radioResourceConfigCommon.pusch_ConfigCommon,
             sizeof(PUSCH_ConfigCommon_t));

      if(mobilityControlInfo->radioResourceConfigCommon.phich_Config) {
367
        /* memcpy((void *)&UE_mac_inst[Mod_idP].radioResourceConfigCommon->phich_Config,
368 369 370 371 372
        (void *)mobilityControlInfo->radioResourceConfigCommon.phich_Config,
        sizeof(PHICH_Config_t)); */
      }

      if(mobilityControlInfo->radioResourceConfigCommon.pucch_ConfigCommon) {
373
        memcpy((void *)&UE_mac_inst[Mod_idP].radioResourceConfigCommon->pucch_ConfigCommon,
374 375 376 377 378
               (void *)mobilityControlInfo->radioResourceConfigCommon.pucch_ConfigCommon,
               sizeof(PUCCH_ConfigCommon_t));
      }

      if(mobilityControlInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon) {
379
        memcpy((void *)&UE_mac_inst[Mod_idP].radioResourceConfigCommon->soundingRS_UL_ConfigCommon,
380 381 382 383 384
               (void *)mobilityControlInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
               sizeof(SoundingRS_UL_ConfigCommon_t));
      }

      if(mobilityControlInfo->radioResourceConfigCommon.uplinkPowerControlCommon) {
385
        memcpy((void *)&UE_mac_inst[Mod_idP].radioResourceConfigCommon->uplinkPowerControlCommon,
386 387 388 389 390 391 392 393 394 395
               (void *)mobilityControlInfo->radioResourceConfigCommon.uplinkPowerControlCommon,
               sizeof(UplinkPowerControlCommon_t));
      }

      //configure antennaInfoCommon somewhere here..
      if(mobilityControlInfo->radioResourceConfigCommon.p_Max) {
        //to be configured
      }

      if(mobilityControlInfo->radioResourceConfigCommon.tdd_Config) {
396
        UE_mac_inst[Mod_idP].tdd_Config = mobilityControlInfo->radioResourceConfigCommon.tdd_Config;
397
      }
398 399

      if(mobilityControlInfo->radioResourceConfigCommon.ul_CyclicPrefixLength) {
400
        memcpy((void *)&UE_mac_inst[Mod_idP].radioResourceConfigCommon->ul_CyclicPrefixLength,
401 402 403 404 405
               (void *)mobilityControlInfo->radioResourceConfigCommon.ul_CyclicPrefixLength,
               sizeof(UL_CyclicPrefixLength_t));
      }

      // store the previous rnti in case of failure, and set thenew rnti
406 407 408 409
      UE_mac_inst[Mod_idP].crnti_before_ho = UE_mac_inst[Mod_idP].crnti;
      UE_mac_inst[Mod_idP].crnti = ((mobilityControlInfo->newUE_Identity.buf[0])|(mobilityControlInfo->newUE_Identity.buf[1]<<8));
      LOG_I(MAC,"[UE %d] Received new identity %x from %d\n", Mod_idP, UE_mac_inst[Mod_idP].crnti, eNB_index);
      UE_mac_inst[Mod_idP].rach_ConfigDedicated = malloc(sizeof(*mobilityControlInfo->rach_ConfigDedicated));
410 411

      if (mobilityControlInfo->rach_ConfigDedicated) {
412
        memcpy((void*)UE_mac_inst[Mod_idP].rach_ConfigDedicated,
413 414 415 416
               (void*)mobilityControlInfo->rach_ConfigDedicated,
               sizeof(*mobilityControlInfo->rach_ConfigDedicated));
      }

417
      mac_xface->phy_config_afterHO_ue(Mod_idP,0,eNB_index,mobilityControlInfo,0);
418
    }
419
  }
420

421
  if (mbsfn_SubframeConfigList != NULL) {
422
    if (eNB_flagP == 1) {
423 424
      LOG_I(MAC,"[eNB %d][CONFIG] Received %d subframe allocation pattern for MBSFN\n", Mod_idP, mbsfn_SubframeConfigList->list.count);
      eNB_mac_inst[Mod_idP].common_channels[0].num_sf_allocation_pattern= mbsfn_SubframeConfigList->list.count;
425 426

      for (i=0; i<mbsfn_SubframeConfigList->list.count; i++) {
427 428 429
        eNB_mac_inst[Mod_idP].common_channels[0].mbsfn_SubframeConfig[i] = mbsfn_SubframeConfigList->list.array[i];
        LOG_I(MAC, "[eNB %d][CONFIG] MBSFN_SubframeConfig[%d] pattern is  %x\n", Mod_idP, i,
              eNB_mac_inst[Mod_idP].common_channels[0].mbsfn_SubframeConfig[i]->subframeAllocation.choice.oneFrame.buf[0]);
430 431
      }

432
#ifdef Rel10
433
      eNB_mac_inst[Mod_idP].common_channels[0].MBMS_flag = MBMS_Flag;
434
#endif
435
    } else { // UE
436 437
      LOG_I(MAC,"[UE %d][CONFIG] Received %d subframe allocation pattern for MBSFN\n", Mod_idP, mbsfn_SubframeConfigList->list.count);
      UE_mac_inst[Mod_idP].num_sf_allocation_pattern= mbsfn_SubframeConfigList->list.count;
438 439

      for (i=0; i<mbsfn_SubframeConfigList->list.count; i++) {
440 441 442 443
        LOG_I(MAC, "[UE %d] Configuring MBSFN_SubframeConfig %d from received SIB2 \n", Mod_idP, i);
        UE_mac_inst[Mod_idP].mbsfn_SubframeConfig[i] = mbsfn_SubframeConfigList->list.array[i];
        //  LOG_I("[UE %d] MBSFN_SubframeConfig[%d] pattern is  %ld\n", Mod_idP,
        //    UE_mac_inst[Mod_idP].mbsfn_SubframeConfig[i]->subframeAllocation.choice.oneFrame.buf[0]);
444
      }
445
    }
446 447 448
  }

#ifdef Rel10
449

450
  if (mbsfn_AreaInfoList != NULL) {
451 452
    if (eNB_flagP == 1) {
      // One eNB could be part of multiple mbsfn syc area, this could change over time so reset each time
453 454
      LOG_I(MAC,"[eNB %d][CONFIG] Received %d MBSFN Area Info\n", Mod_idP, mbsfn_AreaInfoList->list.count);
      eNB_mac_inst[Mod_idP].common_channels[0].num_active_mbsfn_area = mbsfn_AreaInfoList->list.count;
455 456

      for (i =0; i< mbsfn_AreaInfoList->list.count; i++) {
457 458 459 460
        eNB_mac_inst[Mod_idP].common_channels[0].mbsfn_AreaInfo[i] = mbsfn_AreaInfoList->list.array[i];
        LOG_I(MAC,"[eNB %d][CONFIG] MBSFN_AreaInfo[%d]: MCCH Repetition Period = %ld\n", Mod_idP,i,
              eNB_mac_inst[Mod_idP].common_channels[0].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
        mac_xface->phy_config_sib13_eNB(Mod_idP,0,i,eNB_mac_inst[Mod_idP].common_channels[0].mbsfn_AreaInfo[i]->mbsfn_AreaId_r9);
461
      }
462
    } else { // UE
463 464
      LOG_I(MAC,"[UE %d][CONFIG] Received %d MBSFN Area Info\n", Mod_idP, mbsfn_AreaInfoList->list.count);
      UE_mac_inst[Mod_idP].num_active_mbsfn_area = mbsfn_AreaInfoList->list.count;
465 466

      for (i =0; i< mbsfn_AreaInfoList->list.count; i++) {
467 468 469 470
        UE_mac_inst[Mod_idP].mbsfn_AreaInfo[i] = mbsfn_AreaInfoList->list.array[i];
        LOG_I(MAC,"[UE %d] MBSFN_AreaInfo[%d]: MCCH Repetition Period = %ld\n",Mod_idP, i,
              UE_mac_inst[Mod_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
        mac_xface->phy_config_sib13_ue(Mod_idP,0,eNB_index,i,UE_mac_inst[Mod_idP].mbsfn_AreaInfo[i]->mbsfn_AreaId_r9);
471
      }
472
    }
473 474
  }

475

476
  if (pmch_InfoList != NULL) {
477

478
    //    LOG_I(MAC,"DUY: lcid when entering rrc_mac config_req is %02d\n",(pmch_InfoList->list.array[0]->mbms_SessionInfoList_r9.list.array[0]->logicalChannelIdentity_r9));
479

480
    if (eNB_flagP == 1) {
481

482
      LOG_I(MAC, "[CONFIG] Number of PMCH in this MBSFN Area %d\n", pmch_InfoList->list.count);
483

484
      for (i =0; i< pmch_InfoList->list.count; i++) {
485
        eNB_mac_inst[Mod_idP].common_channels[0].pmch_Config[i] = &pmch_InfoList->list.array[i]->pmch_Config_r9;
486

nikaeinn's avatar
nikaeinn committed
487
        LOG_I(MAC, "[CONFIG] PMCH[%d]: This PMCH stop (sf_AllocEnd_r9) at subframe  %ldth\n", i,
488
              eNB_mac_inst[Mod_idP].common_channels[0].pmch_Config[i]->sf_AllocEnd_r9);
489
        LOG_I(MAC, "[CONFIG] PMCH[%d]: mch_Scheduling_Period = %ld\n", i,
490
              eNB_mac_inst[Mod_idP].common_channels[0].pmch_Config[i]->mch_SchedulingPeriod_r9);
491
        LOG_I(MAC, "[CONFIG] PMCH[%d]: dataMCS = %ld\n", i,
492
              eNB_mac_inst[Mod_idP].common_channels[0].pmch_Config[i]->dataMCS_r9);
493

494
        // MBMS session info list in each MCH
495 496
        eNB_mac_inst[Mod_idP].common_channels[0].mbms_SessionList[i] = &pmch_InfoList->list.array[i]->mbms_SessionInfoList_r9;
        LOG_I(MAC, "PMCH[%d] Number of session (MTCH) is: %d\n",i, eNB_mac_inst[Mod_idP].common_channels[0].mbms_SessionList[i]->list.count);
497
      }
498
    } else { // UE
499
      LOG_I(MAC, "[UE %d] Configuring PMCH_config from MCCH MESSAGE \n",Mod_idP);
500 501

      for (i =0; i< pmch_InfoList->list.count; i++) {
502 503 504
        UE_mac_inst[Mod_idP].pmch_Config[i] = &pmch_InfoList->list.array[i]->pmch_Config_r9;
        LOG_I(MAC, "[UE %d] PMCH[%d]: MCH_Scheduling_Period = %ld\n", Mod_idP, i,
              UE_mac_inst[Mod_idP].pmch_Config[i]->mch_SchedulingPeriod_r9);
505
      }
506

507
      UE_mac_inst[Mod_idP].mcch_status = 1;
508
    }
509
  }
510

511 512
#endif
#ifdef CBA
513 514 515

  if (eNB_flagP == 0) {
    if (cba_rnti) {
516
      UE_mac_inst[Mod_idP].cba_rnti[num_active_cba_groups-1] = cba_rnti;
517
      LOG_D(MAC,"[UE %d] configure CBA group %d RNTI %x for eNB %d (total active cba group %d)\n",
518 519
            Mod_idP,Mod_idP%num_active_cba_groups, cba_rnti,eNB_index,num_active_cba_groups);
      mac_xface->phy_config_cba_rnti(Mod_idP,CC_idP,eNB_flagP,eNB_index,cba_rnti,num_active_cba_groups-1, num_active_cba_groups);
520 521 522 523
    }
  } else {
    if (cba_rnti) {
      LOG_D(MAC,"[eNB %d] configure CBA RNTI for UE  %d (total active cba groups %d)\n",
524 525
            Mod_idP, UE_id, num_active_cba_groups);
      eNB_mac_inst[Mod_idP].common_channels[CC_idP].num_active_cba_groups=num_active_cba_groups;
526 527

      for (i=0; i < num_active_cba_groups; i ++) {
528 529
        if (eNB_mac_inst[Mod_idP].common_channels[CC_idP].cba_rnti[i] != cba_rnti + i) {
          eNB_mac_inst[Mod_idP].common_channels[CC_idP].cba_rnti[i] = cba_rnti + i;
530
        }
531 532 533 534

        //only configure UE ids up to num_active_cba_groups
        //we use them as candidates for the transmission of dci format0)
        if (UE_id%num_active_cba_groups == i) {
535
          mac_xface->phy_config_cba_rnti(Mod_idP,CC_idP,eNB_flagP,UE_id,cba_rnti + i,i,num_active_cba_groups );
536
          LOG_D(MAC,"[eNB %d] configure CBA groups %d with RNTI %x for UE  %d (total active cba groups %d)\n",
537
                Mod_idP, i, eNB_mac_inst[Mod_idP].common_channels[CC_idP].cba_rnti[i],UE_id, num_active_cba_groups);
538
        }
539
      }
540
    }
541 542 543
  }

#endif
gauthier's avatar
gauthier committed
544
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_MAC_CONFIG, VCD_FUNCTION_OUT);
545 546 547

  return(0);
}
548
#ifdef LOCALIZATION
549
//------------------------------------------------------------------------------
550
double
551 552 553 554 555 556
rrc_get_estimated_ue_distance(
  const protocol_ctxt_t* const ctxt_pP,
  const int         CC_idP,
  const uint8_t     loc_typeP
)
//------------------------------------------------------------------------------
557 558 559 560 561
{
  // localization types:
  // 0: power based
  // 1: time based
  LTE_eNB_UE_stats     *eNB_UE_stats     = NULL;
562
  UE_list_t*            UE_list = &eNB_mac_inst[ctxt_pP->module_id].UE_list;
563
  int                   pCCid;
564
  int                   UE_id;
565

566
  if(ctxt_pP->rnti == NOT_A_RNTI) {
567
    return -1;
568
  }
569

570 571 572
  UE_id = find_UE_id(ctxt_pP->module_id,ctxt_pP->rnti);
  pCCid = UE_PCCID(ctxt_pP->module_id,UE_id);
  eNB_UE_stats = mac_xface->get_eNB_UE_stats(ctxt_pP->module_id,pCCid,ctxt_pP->rnti);
573

574
  switch (loc_typeP) {
575 576 577 578 579 580 581 582 583 584 585 586
  case 0:
    return eNB_UE_stats->distance.power_based;
    break;

  case 1:
    return eNB_UE_stats->distance.time_based;
    break;

  default:
    return  eNB_UE_stats->distance.power_based;
  }

587
  //    LOG_D(LOCALIZE, "DEBUG ME, dist = %d\n", &eNB_mac_inst[ctxt_pP->module_id].UE_list.UE_template[CC_idP][UE_id].distance.power_based);
588

589 590
}

591
#endif