config.c 26.5 KB
Newer Older
1
/*******************************************************************************
nikaeinn's avatar
nikaeinn committed
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

nikaeinn's avatar
nikaeinn committed
5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


nikaeinn's avatar
nikaeinn committed
11 12 13 14
    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
15

nikaeinn's avatar
nikaeinn committed
16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
    see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
nikaeinn's avatar
nikaeinn committed
22 23 24 25
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

nikaeinn's avatar
nikaeinn committed
28
*******************************************************************************/
29
/*! \file config.c
nikaeinn's avatar
nikaeinn committed
30
 * \brief UE and eNB configuration performed by RRC or as a consequence of RRC procedures
31 32
 * \author  Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
gauthier's avatar
gauthier committed
33 34 35
 * \version 0.1
 * \email: navid.nikaein@eurecom.fr
 * @ingroup _mac
36

gauthier's avatar
gauthier committed
37
 */
38

39 40 41 42 43 44 45 46 47
#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"
48
#include "proto.h"
49 50 51 52 53 54 55 56 57
#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
58 59

/* sec 5.9, 36.321: MAC Reset Procedure */
gauthier's avatar
gauthier committed
60
void ue_mac_reset(module_id_t module_idP,uint8_t eNB_index) {
gauthier's avatar
gauthier committed
61

62
  //Resetting Bj
gauthier's avatar
gauthier committed
63 64 65
  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;
knopp's avatar
 
knopp committed
66
  
67
  //Stopping all timers
gauthier's avatar
gauthier committed
68

69
  //timeAlignmentTimer expires
gauthier's avatar
gauthier committed
70

71
  // PHY changes for UE MAC reset
72
  mac_xface->phy_reset_ue(module_idP,0,eNB_index);
gauthier's avatar
gauthier committed
73

74 75
  // notify RRC to relase PUCCH/SRS
  // cancel all pending SRs
gauthier's avatar
gauthier committed
76 77
  UE_mac_inst[module_idP].scheduling_info.SR_pending=0;
  UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0;
knopp's avatar
 
knopp committed
78
  
79
  // stop ongoing RACH procedure
gauthier's avatar
gauthier committed
80

81
  // discard explicitly signaled ra_PreambleIndex and ra_RACH_MaskIndex, if any
gauthier's avatar
gauthier committed
82 83 84
  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
85

gauthier's avatar
gauthier committed
86 87
  ue_init_mac(module_idP); //This will hopefully do the rest of the MAC reset procedure

88 89
}

gauthier's avatar
gauthier committed
90
int rrc_mac_config_req(module_id_t Mod_id, eNB_flag_t eNB_flagP,uint8_t UE_id,uint8_t eNB_index,
knopp's avatar
 
knopp committed
91 92
		       RadioResourceConfigCommonSIB_t  *radioResourceConfigCommon,
		       struct PhysicalConfigDedicated  *physicalConfigDedicated,
93
#ifdef Rel10
knopp's avatar
 
knopp committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
		       SCellToAddMod_r10_t *sCellToAddMod_r10,
		       //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
#endif
		       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
#ifdef Rel10
		       ,uint8_t                              MBMS_Flag,
		       MBSFN_AreaInfoList_r9_t         *mbsfn_AreaInfoList,
		       PMCH_InfoList_r9_t              *pmch_InfoList
114 115
#endif 
#ifdef CBA
knopp's avatar
 
knopp committed
116 117
		       ,uint8_t                              num_active_cba_groups,
		       uint16_t                              cba_rnti
118
#endif
gauthier's avatar
gauthier committed
119
) {
120

121
  int i,CC_id=0;
122 123 124

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_MAC_CONFIG, VCD_FUNCTION_IN);

gauthier's avatar
gauthier committed
125 126 127 128
  if (eNB_flagP==0) {
      LOG_I(MAC,"[CONFIG][UE %d] Configuring MAC/PHY from eNB %d\n",Mod_id,eNB_index);
      if (tdd_Config != NULL)
        UE_mac_inst[Mod_id].tdd_Config = tdd_Config;
129
  }else {
gauthier's avatar
gauthier committed
130 131 132
      if (physicalConfigDedicated == NULL){
          LOG_I(MAC,"[CONFIG][eNB %d] Configuring MAC/PHY\n",Mod_id);
      } else{
knopp's avatar
 
knopp committed
133
          LOG_I(MAC,"[CONFIG][eNB %d] Configuring MAC/PHY for UE %d (%x)\n",Mod_id,UE_id,UE_RNTI(Mod_id,UE_id));
gauthier's avatar
gauthier committed
134
      }
135
  }
gauthier's avatar
gauthier committed
136

137 138
  if (tdd_Config && SIwindowsize && SIperiod) {
      if (eNB_flagP == ENB_FLAG_YES)
knopp's avatar
 
knopp committed
139
        mac_xface->phy_config_sib1_eNB(Mod_id,0,tdd_Config,*SIwindowsize,*SIperiod);
gauthier's avatar
gauthier committed
140
      else
knopp's avatar
 
knopp committed
141
        mac_xface->phy_config_sib1_ue(Mod_id,0,eNB_index,tdd_Config,*SIwindowsize,*SIperiod);
142 143
  } 

144
  if (radioResourceConfigCommon!=NULL) {
gauthier's avatar
gauthier committed
145 146 147 148 149 150 151 152 153 154
      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);
knopp's avatar
 
knopp committed
155
          mac_xface->phy_config_sib2_eNB(Mod_id,0,radioResourceConfigCommon,ul_CarrierFreq,ul_Bandwidth,additionalSpectrumEmission,mbsfn_SubframeConfigList);
gauthier's avatar
gauthier committed
156 157 158
      }
      else {
          UE_mac_inst[Mod_id].radioResourceConfigCommon = radioResourceConfigCommon;
knopp's avatar
 
knopp committed
159
          mac_xface->phy_config_sib2_ue(Mod_id,0,eNB_index,radioResourceConfigCommon,ul_CarrierFreq,ul_Bandwidth,additionalSpectrumEmission,mbsfn_SubframeConfigList);
gauthier's avatar
gauthier committed
160
      }
161 162 163
  }
  // SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters->logicalChannelGroup
  if (logicalChannelConfig!= NULL) {
gauthier's avatar
gauthier committed
164 165 166 167 168 169 170 171 172 173 174
      if (eNB_flagP==0){
          LOG_I(MAC,"[CONFIG][UE %d] Applying RRC logicalChannelConfig from eNB%d\n",Mod_id,eNB_index);
          UE_mac_inst[Mod_id].logicalChannelConfig[logicalChannelIdentity]=logicalChannelConfig;
          UE_mac_inst[Mod_id].scheduling_info.Bj[logicalChannelIdentity]=0; // initilize the bucket for this lcid
          if (logicalChannelConfig->ul_SpecificParameters) {
              UE_mac_inst[Mod_id].scheduling_info.bucket_size[logicalChannelIdentity]=logicalChannelConfig->ul_SpecificParameters->prioritisedBitRate *
                  logicalChannelConfig->ul_SpecificParameters->bucketSizeDuration; // set the max bucket size
              UE_mac_inst[Mod_id].scheduling_info.LCGID[logicalChannelIdentity]=*logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup;
              LOG_D(MAC,"[CONFIG][UE %d] LCID %d is attached to the LCGID %d\n",Mod_id,logicalChannelIdentity,*logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup);
          } else {
              LOG_E(MAC,"[CONFIG][UE %d] LCID %d NULL ul_SpecificParameters\n",Mod_id,logicalChannelIdentity);
gauthier's avatar
gauthier committed
175
              mac_xface->macphy_exit("NULL ul_SpecificParameters");
gauthier's avatar
gauthier committed
176
          }
177 178 179 180
      }
  }

  if (mac_MainConfig != NULL){
gauthier's avatar
gauthier committed
181 182 183 184 185 186 187
      if (eNB_flagP==0){
          LOG_I(MAC,"[CONFIG][UE%d] Applying RRC macMainConfig from eNB%d\n",Mod_id,eNB_index);
          UE_mac_inst[Mod_id].macConfig=mac_MainConfig;
          UE_mac_inst[Mod_id].measGapConfig=measGapConfig;
          if (mac_MainConfig->ul_SCH_Config) {

              if (mac_MainConfig->ul_SCH_Config->periodicBSR_Timer)
gauthier's avatar
gauthier committed
188
                UE_mac_inst[Mod_id].scheduling_info.periodicBSR_Timer = (uint16_t) *mac_MainConfig->ul_SCH_Config->periodicBSR_Timer;
gauthier's avatar
gauthier committed
189
              else
gauthier's avatar
gauthier committed
190
                UE_mac_inst[Mod_id].scheduling_info.periodicBSR_Timer = (uint16_t) MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity;
gauthier's avatar
gauthier committed
191 192

              if (mac_MainConfig->ul_SCH_Config->maxHARQ_Tx)
gauthier's avatar
gauthier committed
193
                UE_mac_inst[Mod_id].scheduling_info.maxHARQ_Tx     = (uint16_t) *mac_MainConfig->ul_SCH_Config->maxHARQ_Tx;
gauthier's avatar
gauthier committed
194
              else
gauthier's avatar
gauthier committed
195
                UE_mac_inst[Mod_id].scheduling_info.maxHARQ_Tx     = (uint16_t) MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
gauthier's avatar
gauthier committed
196
              if (mac_MainConfig->ul_SCH_Config->retxBSR_Timer)
gauthier's avatar
gauthier committed
197
                UE_mac_inst[Mod_id].scheduling_info.retxBSR_Timer     = (uint16_t) mac_MainConfig->ul_SCH_Config->retxBSR_Timer;
gauthier's avatar
gauthier committed
198
              else
gauthier's avatar
gauthier committed
199
                UE_mac_inst[Mod_id].scheduling_info.retxBSR_Timer     = (uint16_t)MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf2560;
gauthier's avatar
gauthier committed
200
          }
201
#ifdef Rel10   
gauthier's avatar
gauthier committed
202
          if (mac_MainConfig->sr_ProhibitTimer_r9)
gauthier's avatar
gauthier committed
203
            UE_mac_inst[Mod_id].scheduling_info.sr_ProhibitTimer  = (uint16_t) *mac_MainConfig->sr_ProhibitTimer_r9;
gauthier's avatar
gauthier committed
204
          else
gauthier's avatar
gauthier committed
205
            UE_mac_inst[Mod_id].scheduling_info.sr_ProhibitTimer  = (uint16_t) 0;
206
#endif
gauthier's avatar
gauthier committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
          UE_mac_inst[Mod_id].scheduling_info.periodicBSR_SF  = get_sf_periodicBSRTimer(UE_mac_inst[Mod_id].scheduling_info.periodicBSR_Timer);
          UE_mac_inst[Mod_id].scheduling_info.retxBSR_SF     = get_sf_retxBSRTimer(UE_mac_inst[Mod_id].scheduling_info.retxBSR_Timer);

          UE_mac_inst[Mod_id].scheduling_info.drx_config     = mac_MainConfig->drx_Config;
          UE_mac_inst[Mod_id].scheduling_info.phr_config     = mac_MainConfig->phr_Config;
          if (mac_MainConfig->phr_Config){
              UE_mac_inst[Mod_id].PHR_state = mac_MainConfig->phr_Config->present;
              UE_mac_inst[Mod_id].PHR_reconfigured = 1;
              UE_mac_inst[Mod_id].scheduling_info.periodicPHR_Timer = mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer;
              UE_mac_inst[Mod_id].scheduling_info.prohibitPHR_Timer = mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer;
              UE_mac_inst[Mod_id].scheduling_info.PathlossChange = mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange;
          } else {
              UE_mac_inst[Mod_id].PHR_reconfigured = 0;
              UE_mac_inst[Mod_id].PHR_state = MAC_MainConfig__phr_Config_PR_setup;
              UE_mac_inst[Mod_id].scheduling_info.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20;
              UE_mac_inst[Mod_id].scheduling_info.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20;
              UE_mac_inst[Mod_id].scheduling_info.PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;
          }
          UE_mac_inst[Mod_id].scheduling_info.periodicPHR_SF =  get_sf_perioidicPHR_Timer(UE_mac_inst[Mod_id].scheduling_info.periodicPHR_Timer);
          UE_mac_inst[Mod_id].scheduling_info.prohibitPHR_SF =  get_sf_prohibitPHR_Timer(UE_mac_inst[Mod_id].scheduling_info.prohibitPHR_Timer);
          UE_mac_inst[Mod_id].scheduling_info.PathlossChange_db =  get_db_dl_PathlossChange(UE_mac_inst[Mod_id].scheduling_info.PathlossChange);
          LOG_D(MAC,"[UE %d] config PHR (%d): periodic %d (SF) prohibit %d (SF)  pathlosschange %d (db) \n",
229 230
              Mod_id,
              (mac_MainConfig->phr_Config)?mac_MainConfig->phr_Config->present:-1,
gauthier's avatar
gauthier committed
231 232 233 234
              UE_mac_inst[Mod_id].scheduling_info.periodicPHR_SF,
              UE_mac_inst[Mod_id].scheduling_info.prohibitPHR_SF,
              UE_mac_inst[Mod_id].scheduling_info.PathlossChange_db);
      }
235 236 237
  }

  if (physicalConfigDedicated != NULL) {
gauthier's avatar
gauthier committed
238
      if (eNB_flagP==1){
knopp's avatar
 
knopp committed
239
	mac_xface->phy_config_dedicated_eNB(Mod_id,0,UE_RNTI(Mod_id,UE_id),physicalConfigDedicated);
gauthier's avatar
gauthier committed
240
      }else{
knopp's avatar
 
knopp committed
241 242
	mac_xface->phy_config_dedicated_ue(Mod_id,0,eNB_index,physicalConfigDedicated);
	UE_mac_inst[Mod_id].physicalConfigDedicated=physicalConfigDedicated; // for SR proc
gauthier's avatar
gauthier committed
243
      }
244
  }
knopp's avatar
 
knopp committed
245 246 247
#ifdef Rel10
  if (sCellToAddMod_r10 != NULL) {
    
248
    if (eNB_flagP==1){
knopp's avatar
 
knopp committed
249 250 251
      mac_xface->phy_config_dedicated_scell_eNB(Mod_id,UE_RNTI(Mod_id,UE_id),sCellToAddMod_r10,1);
    }
    else {
252
#warning "phy_config_dedicated_scell_ue is empty"
knopp's avatar
 
knopp committed
253 254 255 256 257
      mac_xface->phy_config_dedicated_scell_ue(Mod_id,eNB_index,sCellToAddMod_r10,1);
      UE_mac_inst[Mod_id].physicalConfigDedicatedSCell_r10 = sCellToAddMod_r10->radioResourceConfigDedicatedSCell_r10->physicalConfigDedicatedSCell_r10; // using SCell index 0
    }
  }
#endif
258

gauthier's avatar
gauthier committed
259 260 261 262 263 264 265 266 267
  if (eNB_flagP == 0) {
      if (measObj!= NULL) {
          if (measObj[0]!= NULL){
              UE_mac_inst[Mod_id].n_adj_cells = measObj[0]->measObject.choice.measObjectEUTRA.cellsToAddModList->list.count;
              LOG_I(MAC,"Number of adjacent cells %d\n",UE_mac_inst[Mod_id].n_adj_cells);
              for (i=0;i<UE_mac_inst[Mod_id].n_adj_cells;i++) {
                  UE_mac_inst[Mod_id].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_id].adj_cell_id[i]);
              }
knopp's avatar
 
knopp committed
268
              mac_xface->phy_config_meas_ue(Mod_id,0,eNB_index,UE_mac_inst[Mod_id].n_adj_cells,UE_mac_inst[Mod_id].adj_cell_id);
gauthier's avatar
gauthier committed
269 270
          }
          /*
271 272 273 274 275 276 277
    if (quantityConfig != NULL) {
    	if (quantityConfig[0] != NULL) {
    		UE_mac_inst[Mod_id].quantityConfig = quantityConfig[0];
    		LOG_I(MAC,"UE %d configured filterCoeff.",UE_mac_inst[Mod_id].crnti);
    		mac_xface->phy_config_meas_ue
    	}
    }
gauthier's avatar
gauthier committed
278
           */
279
      }
gauthier's avatar
gauthier committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
  }
  if (eNB_flagP==0) {
      if(mobilityControlInfo != NULL) {

          LOG_D(MAC,"[UE%d] MAC Reset procedure triggered by RRC eNB %d \n",Mod_id,eNB_index);
          ue_mac_reset(Mod_id,eNB_index);

          if(mobilityControlInfo->radioResourceConfigCommon.rach_ConfigCommon) {
              memcpy((void *)&UE_mac_inst[Mod_id].radioResourceConfigCommon->rach_ConfigCommon,
                  (void *)mobilityControlInfo->radioResourceConfigCommon.rach_ConfigCommon,
                  sizeof(RACH_ConfigCommon_t));
          }

          memcpy((void *)&UE_mac_inst[Mod_id].radioResourceConfigCommon->prach_Config.prach_ConfigInfo,
              (void *)mobilityControlInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
              sizeof(PRACH_ConfigInfo_t));
          UE_mac_inst[Mod_id].radioResourceConfigCommon->prach_Config.rootSequenceIndex = mobilityControlInfo->radioResourceConfigCommon.prach_Config.rootSequenceIndex;

          if(mobilityControlInfo->radioResourceConfigCommon.pdsch_ConfigCommon) {
              memcpy((void *)&UE_mac_inst[Mod_id].radioResourceConfigCommon->pdsch_ConfigCommon,
                  (void *)mobilityControlInfo->radioResourceConfigCommon.pdsch_ConfigCommon,
                  sizeof(PDSCH_ConfigCommon_t));
          }
          // not a pointer: mobilityControlInfo->radioResourceConfigCommon.pusch_ConfigCommon
          memcpy((void *)&UE_mac_inst[Mod_id].radioResourceConfigCommon->pusch_ConfigCommon,
              (void *)&mobilityControlInfo->radioResourceConfigCommon.pusch_ConfigCommon,
              sizeof(PUSCH_ConfigCommon_t));

          if(mobilityControlInfo->radioResourceConfigCommon.phich_Config) {
              /* memcpy((void *)&UE_mac_inst[Mod_id].radioResourceConfigCommon->phich_Config,
310 311
	   (void *)mobilityControlInfo->radioResourceConfigCommon.phich_Config,
	   sizeof(PHICH_Config_t)); */
gauthier's avatar
gauthier committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
          }
          if(mobilityControlInfo->radioResourceConfigCommon.pucch_ConfigCommon) {
              memcpy((void *)&UE_mac_inst[Mod_id].radioResourceConfigCommon->pucch_ConfigCommon,
                  (void *)mobilityControlInfo->radioResourceConfigCommon.pucch_ConfigCommon,
                  sizeof(PUCCH_ConfigCommon_t));
          }
          if(mobilityControlInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon) {
              memcpy((void *)&UE_mac_inst[Mod_id].radioResourceConfigCommon->soundingRS_UL_ConfigCommon,
                  (void *)mobilityControlInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
                  sizeof(SoundingRS_UL_ConfigCommon_t));
          }
          if(mobilityControlInfo->radioResourceConfigCommon.uplinkPowerControlCommon) {
              memcpy((void *)&UE_mac_inst[Mod_id].radioResourceConfigCommon->uplinkPowerControlCommon,
                  (void *)mobilityControlInfo->radioResourceConfigCommon.uplinkPowerControlCommon,
                  sizeof(UplinkPowerControlCommon_t));
          }
          //configure antennaInfoCommon somewhere here..
          if(mobilityControlInfo->radioResourceConfigCommon.p_Max) {
              //to be configured
          }
          if(mobilityControlInfo->radioResourceConfigCommon.tdd_Config) {
              UE_mac_inst[Mod_id].tdd_Config = mobilityControlInfo->radioResourceConfigCommon.tdd_Config;
          }
          if(mobilityControlInfo->radioResourceConfigCommon.ul_CyclicPrefixLength) {
              memcpy((void *)&UE_mac_inst[Mod_id].radioResourceConfigCommon->ul_CyclicPrefixLength,
                  (void *)mobilityControlInfo->radioResourceConfigCommon.ul_CyclicPrefixLength,
                  sizeof(UL_CyclicPrefixLength_t));
          }
          // store the previous rnti in case of failure, and set thenew rnti
          UE_mac_inst[Mod_id].crnti_before_ho = UE_mac_inst[Mod_id].crnti;
          UE_mac_inst[Mod_id].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_id, UE_mac_inst[Mod_id].crnti, eNB_index);
          UE_mac_inst[Mod_id].rach_ConfigDedicated = malloc(sizeof(*mobilityControlInfo->rach_ConfigDedicated));
          if (mobilityControlInfo->rach_ConfigDedicated){
              memcpy((void*)UE_mac_inst[Mod_id].rach_ConfigDedicated,
                  (void*)mobilityControlInfo->rach_ConfigDedicated,
                  sizeof(*mobilityControlInfo->rach_ConfigDedicated));
          }
350
          mac_xface->phy_config_afterHO_ue(Mod_id,0,eNB_index,mobilityControlInfo,0);
351 352
      }
  }
gauthier's avatar
gauthier committed
353

354
  if (mbsfn_SubframeConfigList != NULL) {
gauthier's avatar
gauthier committed
355 356
      if (eNB_flagP == 1) {
          LOG_I(MAC,"[eNB %d][CONFIG] Received %d subframe allocation pattern for MBSFN\n", Mod_id, mbsfn_SubframeConfigList->list.count);
knopp's avatar
 
knopp committed
357
          eNB_mac_inst[Mod_id].common_channels[0].num_sf_allocation_pattern= mbsfn_SubframeConfigList->list.count;
gauthier's avatar
gauthier committed
358
          for (i=0; i<mbsfn_SubframeConfigList->list.count; i++) {
knopp's avatar
 
knopp committed
359
              eNB_mac_inst[Mod_id].common_channels[0].mbsfn_SubframeConfig[i] = mbsfn_SubframeConfigList->list.array[i];
gauthier's avatar
gauthier committed
360
              LOG_I(MAC, "[eNB %d][CONFIG] MBSFN_SubframeConfig[%d] pattern is  %x\n", Mod_id, i,
knopp's avatar
 
knopp committed
361
                  eNB_mac_inst[Mod_id].common_channels[0].mbsfn_SubframeConfig[i]->subframeAllocation.choice.oneFrame.buf[0]);
gauthier's avatar
gauthier committed
362
          }
363
#ifdef Rel10
knopp's avatar
 
knopp committed
364
          eNB_mac_inst[Mod_id].common_channels[0].MBMS_flag = MBMS_Flag;
365 366
#endif
      }
gauthier's avatar
gauthier committed
367 368 369 370 371 372 373 374 375 376
      else { // UE
          LOG_I(MAC,"[UE %d][CONFIG] Received %d subframe allocation pattern for MBSFN\n", Mod_id, mbsfn_SubframeConfigList->list.count);
          UE_mac_inst[Mod_id].num_sf_allocation_pattern= mbsfn_SubframeConfigList->list.count;
          for (i=0; i<mbsfn_SubframeConfigList->list.count; i++) {
              LOG_I(MAC, "[UE %d] Configuring MBSFN_SubframeConfig %d from received SIB2 \n", Mod_id, i);
              UE_mac_inst[Mod_id].mbsfn_SubframeConfig[i] = mbsfn_SubframeConfigList->list.array[i];
              //	LOG_I("[UE %d] MBSFN_SubframeConfig[%d] pattern is  %ld\n", Mod_id,
              //    UE_mac_inst[Mod_id].mbsfn_SubframeConfig[i]->subframeAllocation.choice.oneFrame.buf[0]);
          }
      }
377 378 379 380
  }

#ifdef Rel10
  if (mbsfn_AreaInfoList != NULL) {
gauthier's avatar
gauthier committed
381 382 383
      if (eNB_flagP == 1) {
          // One eNB could be part of multiple mbsfn syc area, this could change over time so reset each time
          LOG_I(MAC,"[eNB %d][CONFIG] Received %d MBSFN Area Info\n", Mod_id, mbsfn_AreaInfoList->list.count);
knopp's avatar
 
knopp committed
384
          eNB_mac_inst[Mod_id].common_channels[0].num_active_mbsfn_area = mbsfn_AreaInfoList->list.count;
gauthier's avatar
gauthier committed
385
          for (i =0; i< mbsfn_AreaInfoList->list.count; i++) {
knopp's avatar
 
knopp committed
386
              eNB_mac_inst[Mod_id].common_channels[0].mbsfn_AreaInfo[i] = mbsfn_AreaInfoList->list.array[i];
gauthier's avatar
gauthier committed
387
              LOG_I(MAC,"[eNB %d][CONFIG] MBSFN_AreaInfo[%d]: MCCH Repetition Period = %ld\n", Mod_id,i,
knopp's avatar
 
knopp committed
388 389
                  eNB_mac_inst[Mod_id].common_channels[0].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
              mac_xface->phy_config_sib13_eNB(Mod_id,0,i,eNB_mac_inst[Mod_id].common_channels[0].mbsfn_AreaInfo[i]->mbsfn_AreaId_r9);
gauthier's avatar
gauthier committed
390
          }
391
      }
gauthier's avatar
gauthier committed
392 393 394 395 396 397 398
      else {  // UE
          LOG_I(MAC,"[UE %d][CONFIG] Received %d MBSFN Area Info\n", Mod_id, mbsfn_AreaInfoList->list.count);
          UE_mac_inst[Mod_id].num_active_mbsfn_area = mbsfn_AreaInfoList->list.count;
          for (i =0; i< mbsfn_AreaInfoList->list.count; i++) {
              UE_mac_inst[Mod_id].mbsfn_AreaInfo[i] = mbsfn_AreaInfoList->list.array[i];
              LOG_I(MAC,"[UE %d] MBSFN_AreaInfo[%d]: MCCH Repetition Period = %ld\n",Mod_id, i,
                  UE_mac_inst[Mod_id].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
knopp's avatar
 
knopp committed
399
              mac_xface->phy_config_sib13_ue(Mod_id,0,eNB_index,i,UE_mac_inst[Mod_id].mbsfn_AreaInfo[i]->mbsfn_AreaId_r9);
gauthier's avatar
gauthier committed
400
          }
401 402 403
      }
  }

gauthier's avatar
gauthier committed
404

405
  if (pmch_InfoList != NULL) {
406

gauthier's avatar
gauthier committed
407
      //    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));
408

gauthier's avatar
gauthier committed
409
      if (eNB_flagP == 1) {
410

gauthier's avatar
gauthier committed
411
          LOG_I(MAC, "[CONFIG] Number of PMCH in this MBSFN Area %d\n", pmch_InfoList->list.count);
412

gauthier's avatar
gauthier committed
413
          for (i =0; i< pmch_InfoList->list.count; i++) {
knopp's avatar
 
knopp committed
414
              eNB_mac_inst[Mod_id].common_channels[0].pmch_Config[i] = &pmch_InfoList->list.array[i]->pmch_Config_r9;
415

gauthier's avatar
gauthier committed
416
              LOG_I(MAC, "[CONFIG] PMCH[%d]: This PMCH stop at subframe  %ldth\n", i,
knopp's avatar
 
knopp committed
417
                  eNB_mac_inst[Mod_id].common_channels[0].pmch_Config[i]->sf_AllocEnd_r9);
gauthier's avatar
gauthier committed
418
              LOG_I(MAC, "[CONFIG] PMCH[%d]: mch_Scheduling_Period = %ld\n", i,
knopp's avatar
 
knopp committed
419
                  eNB_mac_inst[Mod_id].common_channels[0].pmch_Config[i]->mch_SchedulingPeriod_r9);
gauthier's avatar
gauthier committed
420
              LOG_I(MAC, "[CONFIG] PMCH[%d]: dataMCS = %ld\n", i,
knopp's avatar
 
knopp committed
421
                  eNB_mac_inst[Mod_id].common_channels[0].pmch_Config[i]->dataMCS_r9);
422

gauthier's avatar
gauthier committed
423
              // MBMS session info list in each MCH
knopp's avatar
 
knopp committed
424
              eNB_mac_inst[Mod_id].common_channels[0].mbms_SessionList[i] = &pmch_InfoList->list.array[i]->mbms_SessionInfoList_r9;
425
              LOG_I(MAC, "PMCH[%d] Number of session (MTCH) is: %d\n",i, eNB_mac_inst[Mod_id].common_channels[0].mbms_SessionList[i]->list.count);
gauthier's avatar
gauthier committed
426
          }
427
      }
gauthier's avatar
gauthier committed
428 429 430 431 432 433 434 435
      else { // UE
          LOG_I(MAC, "[UE %d] Configuring PMCH_config from MCCH MESSAGE \n",Mod_id);
          for (i =0; i< pmch_InfoList->list.count; i++) {
              UE_mac_inst[Mod_id].pmch_Config[i] = &pmch_InfoList->list.array[i]->pmch_Config_r9;
              LOG_I(MAC, "[UE %d] PMCH[%d]: MCH_Scheduling_Period = %ld\n", Mod_id, i,
                  UE_mac_inst[Mod_id].pmch_Config[i]->mch_SchedulingPeriod_r9);
          }
          UE_mac_inst[Mod_id].mcch_status = 1;
436 437
      }
  }
gauthier's avatar
gauthier committed
438

439 440
#endif
#ifdef CBA
gauthier's avatar
gauthier committed
441 442 443 444 445
  if (eNB_flagP == 0){
      if (cba_rnti) {
          UE_mac_inst[Mod_id].cba_rnti[num_active_cba_groups-1] = cba_rnti;
          LOG_D(MAC,"[UE %d] configure CBA group %d RNTI %x for eNB %d (total active cba group %d)\n",
              Mod_id,Mod_id%num_active_cba_groups, cba_rnti,eNB_index,num_active_cba_groups);
446
          mac_xface->phy_config_cba_rnti(Mod_id,CC_id,eNB_flagP,eNB_index,cba_rnti,num_active_cba_groups-1, num_active_cba_groups);
gauthier's avatar
gauthier committed
447
      }
448
  }else {
gauthier's avatar
gauthier committed
449 450 451
      if (cba_rnti) {
          LOG_D(MAC,"[eNB %d] configure CBA RNTI for UE  %d (total active cba groups %d)\n",
              Mod_id, UE_id, num_active_cba_groups);
452
          eNB_mac_inst[Mod_id].common_channels[CC_id].num_active_cba_groups=num_active_cba_groups;
gauthier's avatar
gauthier committed
453
          for (i=0; i < num_active_cba_groups; i ++){
454 455
              if (eNB_mac_inst[Mod_id].common_channels[CC_id].cba_rnti[i] != cba_rnti + i)
                eNB_mac_inst[Mod_id].common_channels[CC_id].cba_rnti[i] = cba_rnti + i;
gauthier's avatar
gauthier committed
456 457 458
              //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){
459
		mac_xface->phy_config_cba_rnti(Mod_id,CC_id,eNB_flagP,UE_id,cba_rnti + i,i,num_active_cba_groups );
gauthier's avatar
gauthier committed
460
                  LOG_D(MAC,"[eNB %d] configure CBA groups %d with RNTI %x for UE  %d (total active cba groups %d)\n",
461
                      Mod_id, i, eNB_mac_inst[Mod_id].common_channels[CC_id].cba_rnti[i],UE_id, num_active_cba_groups);
gauthier's avatar
gauthier committed
462 463
              }
          }
464 465 466 467 468 469 470 471
      }
  }

#endif
  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_MAC_CONFIG, VCD_FUNCTION_OUT);

  return(0);
}
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
#ifdef LOCALIZATION
double
rrc_get_estimated_ue_distance(module_id_t Mod_id, const frame_t frameP,  uint8_t UE_id, int CC_id, uint8_t loc_type){
    // localization types:
    // 0: power based
    // 1: time based
    LTE_eNB_UE_stats     *eNB_UE_stats     = NULL;
    UE_list_t            *UE_list = &eNB_mac_inst[Mod_id].UE_list;
    int                   pCCid;
    
    uint16_t rnti;
    
  //for (UE_id=UE_list->head;UE_id>=0;UE_id=UE_list->next[UE_id]) {
    pCCid = UE_PCCID(Mod_id,UE_id);
    rnti = UE_list->UE_template[pCCid][UE_id].rnti;
    if(rnti == 0)
        return -1;
    eNB_UE_stats = mac_xface->get_eNB_UE_stats(Mod_id,pCCid,rnti);
    switch (loc_type) {
      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;
    }
//    LOG_D(LOCALIZE, "DEBUG ME, dist = %d\n", &eNB_mac_inst[Mod_id].UE_list.UE_template[CC_id][UE_id].distance.power_based);      
  
}

#endif