eNB_scheduler_RA.c 21 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
 */
Raymond Knopp's avatar
 
Raymond Knopp committed
21

22
/*! \file eNB_scheduler_RA.c
23
 * \brief primitives used for random access
Raymond Knopp's avatar
 
Raymond Knopp committed
24 25 26 27 28 29 30 31 32
 * \author  Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
 * \email: navid.nikaein@eurecom.fr
 * \version 1.0
 * @ingroup _mac

 */

#include "assertions.h"
33
#include "platform_types.h"
Raymond Knopp's avatar
 
Raymond Knopp committed
34 35
#include "PHY/defs.h"
#include "PHY/extern.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
36
#include "msc.h"
Raymond Knopp's avatar
 
Raymond Knopp committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

#include "SCHED/defs.h"
#include "SCHED/extern.h"

#include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/extern.h"

#include "LAYER2/MAC/proto.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"

#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"

//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"

#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif

61
#include "SIMULATION/TOOLS/defs.h" // for taus
Raymond Knopp's avatar
 
Raymond Knopp committed
62

63
#include "T.h"
Raymond Knopp's avatar
Raymond Knopp committed
64

65 66 67 68 69 70 71
// eMTC notes
// Implements MSG2 and MSG4
// fill_rar for eMTC
// new RA_templates for eMTC UEs, CCCH_BR instead of CCCH
// resource allocation for format 1A (4->6 PRBs)
// initiate_ra_proc: add detection of BR/CE UEs

72
void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,unsigned char Msg3_subframe)
73
{
Raymond Knopp's avatar
 
Raymond Knopp committed
74

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  int                             CC_id;
  eNB_MAC_INST                    *eNB = RC.mac[module_idP];
  COMMON_channels_t               *cc  = eNB->common_channels;
  RA_TEMPLATE                     *RA_template;
  uint8_t                         i;
  int16_t                         rrc_sdu_length;
  uint8_t                         lcid;
  uint8_t                         offset;
  int                             UE_id           = -1;
  int16_t                         TBsize          = -1;
  uint16_t                        msg4_padding;
  uint16_t                        msg4_post_padding;
  uint16_t                        msg4_header;
  uint8_t                         *vrb_map;
  int                             first_rb;
  int                             N_RB_DL;
  nfapi_dl_config_request_pdu_t   *dl_config_pdu;
  nfapi_tx_request_pdu_t          *TX_req;
  UE_list_t                       *UE_list=&eNB->UE_list;
  int round;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
95

96
  start_meas(&eNB->schedule_ra);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
97

98
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
99

100

101 102 103 104
    vrb_map       = cc[CC_id].vrb_map;

    dl_config_pdu = &eNB->DL_req[CC_id].dl_config_pdu_list[eNB->DL_req[CC_id].number_pdu]; 
    N_RB_DL       = to_prb(cc[CC_id].mib->message.dl_Bandwidth);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
105

106
    for (i=0; i<NB_RA_PROC_MAX; i++) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
107

108
      RA_template = (RA_TEMPLATE *)&cc[CC_id].RA_template[i];
109 110

      if (RA_template->RA_active == TRUE) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
111

112
        LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d RA %d is active (generate RAR %d, generate_Msg4 %d, wait_ack_Msg4 %d, rnti %x)\n",
113 114 115 116 117 118 119 120 121 122
              module_idP,CC_id,i,RA_template->generate_rar,RA_template->generate_Msg4,RA_template->wait_ack_Msg4, RA_template->rnti);

        if (RA_template->generate_rar == 1) {

          LOG_D(MAC,"[eNB %d] CC_id %d Frame %d, subframeP %d: Generating RAR DCI (proc %d), RA_active %d format 1A (%d,%d))\n",
                module_idP, CC_id, frameP, subframeP,i,
                RA_template->RA_active,
                RA_template->RA_dci_fmt1,
                RA_template->RA_dci_size_bits1);

123 124 125 126 127
          first_rb = 0;
          vrb_map[first_rb] = 1;
          vrb_map[first_rb+1] = 1;
          vrb_map[first_rb+2] = 1;
          vrb_map[first_rb+3] = 1;
128

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
	  memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
	  dl_config_pdu->pdu_type                                                          = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
	  dl_config_pdu->pdu_size                                                          = 2+sizeof(nfapi_dl_config_dci_dl_pdu);
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                             = NFAPI_DL_DCI_FORMAT_1A;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level                      = 4;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                                   = RA_template->RA_rnti;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                              = 2;    // RA-RNTI : see Table 4-10 from SCF082 - nFAPI specifications
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power                     = 6000; // equal to RS power
	  
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                           = 0;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                                    = 1; // no TPC
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1                   = 1;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                                  = 0;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1                   = 0;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = 0;
144

145
	  if (!CCE_allocation_infeasible(module_idP,CC_id,1,subframeP,2,RA_template->RA_rnti)) {
Raymond Knopp's avatar
Raymond Knopp committed
146 147
	    LOG_D(MAC,"Frame %d: Subframe %d : Adding common DCI for RA_RNTI %x\n",
                  frameP,subframeP,RA_template->RA_rnti);
148 149
	    eNB->DL_req[CC_id].number_dci++;
	    eNB->DL_req[CC_id].number_pdu++;
150

151 152
            /* this will be updated when PHY calls set_msg3_subframe */
	    RA_template->Msg3_subframe = -1;
153 154 155 156 157 158 159 160 161 162 163

	    fill_rar(module_idP,CC_id,frameP,cc[CC_id].RAR_pdu.payload,N_RB_DL,7);
	    // DL request
		     
	    TX_req                                                                = &eNB->TX_req[CC_id].tx_pdu_list[eNB->TX_req[CC_id].number_of_pdus]; 
	    TX_req->pdu_length                                                    = 7;  // This should be changed if we have more than 1 preamble 
	    TX_req->pdu_index                                                     = eNB->pdu_index[CC_id]++;
	    TX_req->num_segments                                                  = 1;
	    TX_req->segments[0].segment_length                                    = 7;
	    TX_req->segments[0].segment_data                                      = cc[CC_id].RAR_pdu.payload;
	    eNB->TX_req[CC_id].number_of_pdus++;
164 165
	  }
        } else if (RA_template->generate_Msg4 == 1) {
166 167

          // check for Msg4 Message
168
          UE_id = find_UE_id(module_idP,RA_template->rnti);
169
	  AssertFatal(UE_id>=0,"Can't find UE for t-crnti\n");
170 171 172 173 174

          if (Is_rrc_registered == 1) {

            // Get RRCConnectionSetup for Piggyback
            rrc_sdu_length = mac_rrc_data_req(module_idP,
175
                                              CC_id,
176
                                              frameP,
177 178
                                              CCCH,
                                              1, // 1 transport block
179
                                              &cc[CC_id].CCCH_pdu.payload[0],
180
                                              ENB_FLAG_YES,
181 182 183
                                              module_idP,
                                              0); // not used in this case

184 185
	    AssertFatal(rrc_sdu_length>=0,
			"[MAC][eNB Scheduler] CCCH not allocated\n");
186 187
          }

188 189
          LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: UE_id %d, Is_rrc_registered %d, rrc_sdu_length %d\n",
                module_idP, CC_id, frameP, subframeP,UE_id, Is_rrc_registered,rrc_sdu_length);
190 191

          if (rrc_sdu_length>0) {
192
            LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating Msg4 with RRC Piggyback (RA proc %d, RNTI %x)\n",
193
                  module_idP, CC_id, frameP, subframeP,i,RA_template->rnti);
194

195 196
	    first_rb=0;

197 198 199 200
	    vrb_map[first_rb] = 1;
	    vrb_map[first_rb+1] = 1;
	    vrb_map[first_rb+2] = 1;
	    vrb_map[first_rb+3] = 1;
201 202


203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
	    memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
	    dl_config_pdu->pdu_type                                                          = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
	    dl_config_pdu->pdu_size                                                          = 2+sizeof(nfapi_dl_config_dci_dl_pdu);
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                             = NFAPI_DL_DCI_FORMAT_1A;
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level                      = 4;
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                                   = RA_template->rnti;
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                              = 1;    // C-RNTI : see Table 4-10 from SCF082 - nFAPI specifications
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power                     = 6000; // equal to RS power
	    
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                           = 0;
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                                    = 1; // no TPC
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1                   = 1;
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1                   = 0;
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = 0;

218 219 220
            // Compute MCS for 3 PRB
            msg4_header = 1+6+1;  // CR header, CR CE, SDU header

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242

	    if ((rrc_sdu_length+msg4_header) <= 22) {
	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 4;
	      TBsize = 22;
	    } else if ((rrc_sdu_length+msg4_header) <= 28) {
	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 5;
	      TBsize = 28;
	    } else if ((rrc_sdu_length+msg4_header) <= 32) {
	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 6;
	      TBsize = 32;
	    } else if ((rrc_sdu_length+msg4_header) <= 41) {
	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 7;
	      TBsize = 41;
	    } else if ((rrc_sdu_length+msg4_header) <= 49) {
	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 8;
	      TBsize = 49;
	    } else if ((rrc_sdu_length+msg4_header) <= 57) {
	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 9;
	      TBsize = 57;
	    }

	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding= getRIV(N_RB_DL,first_rb,4);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
243

244
	    if (!CCE_allocation_infeasible(module_idP,CC_id,0,subframeP,2,RA_template->rnti)) {
245 246 247
	      eNB->DL_req[CC_id].number_dci++;
	      eNB->DL_req[CC_id].number_pdu++;
		      
248 249 250 251
	      RA_template->generate_Msg4=0;
	      RA_template->wait_ack_Msg4=1;
	      RA_template->RA_active = FALSE;
	      lcid=0;
252 253 254 255

	      // set HARQ process 0 round to 0 for this UE
	      UE_list->UE_sched_ctrl[UE_id].round[CC_id] = 0;

256 257 258 259 260 261 262 263 264 265 266
	      if ((TBsize - rrc_sdu_length - msg4_header) <= 2) {
		msg4_padding = TBsize - rrc_sdu_length - msg4_header;
		msg4_post_padding = 0;
	      } else {
		msg4_padding = 0;
		msg4_post_padding = TBsize - rrc_sdu_length - msg4_header -1;
	      }
	      
	      LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d subframeP %d Msg4 : TBS %d, sdu_len %d, msg4_header %d, msg4_padding %d, msg4_post_padding %d\n",
		    module_idP,CC_id,frameP,subframeP,TBsize,rrc_sdu_length,msg4_header,msg4_padding,msg4_post_padding);
	      DevAssert( UE_id != UE_INDEX_INVALID ); // FIXME not sure how to gracefully return
267
	      // CHECK THIS: &cc[CC_id].CCCH_pdu.payload[0]
268 269 270 271 272 273 274 275 276 277 278
	      offset = generate_dlsch_header((unsigned char*)eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0],
					     1,                           //num_sdus
					     (unsigned short*)&rrc_sdu_length,             //
					     &lcid,                       // sdu_lcid
					     255,                         // no drx
					     0,                           // no timing advance
					     RA_template->cont_res_id,  // contention res id
					     msg4_padding,                // no padding
					     msg4_post_padding);
	      
	      memcpy((void*)&eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0][(unsigned char)offset],
279
		     &cc[CC_id].CCCH_pdu.payload[0],
280
		     rrc_sdu_length);
281 282 283 284 285 286 287 288 289 290

	    // DL request
	      
	      TX_req                                                                = &eNB->TX_req[CC_id].tx_pdu_list[eNB->TX_req[CC_id].number_of_pdus]; 
	      TX_req->pdu_length                                                    = rrc_sdu_length;
	      TX_req->pdu_index                                                     = eNB->pdu_index[CC_id]++;
	      TX_req->num_segments                                                  = 1;
	      TX_req->segments[0].segment_length                                    = rrc_sdu_length;
	      TX_req->segments[0].segment_data                                      = eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0];
	      eNB->TX_req[CC_id].number_of_pdus++;
291
	      
292 293
              T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP), T_INT(CC_id), T_INT(RA_template->rnti), T_INT(frameP), T_INT(subframeP),
                T_INT(0 /*harq_pid always 0?*/), T_BUFFER(&eNB->UE_list.DLSCH_pdu[CC_id][0][UE_id].payload[0], TBsize));
294
	      
295 296 297
	      if (opt_enabled==1) {
		trace_pdu(1, (uint8_t *)eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0],
			  rrc_sdu_length, UE_id, 3, UE_RNTI(module_idP, UE_id),
298
			  eNB->frame, eNB->subframe,0,0);
299 300 301 302 303 304
		LOG_D(OPT,"[eNB %d][DLSCH] CC_id %d Frame %d trace pdu for rnti %x with size %d\n",
		      module_idP, CC_id, frameP, UE_RNTI(module_idP,UE_id), rrc_sdu_length);
	      }
	      
	    }
	  }
305 306

          //try here
Lionel Gauthier's avatar
 
Lionel Gauthier committed
307
        }
308

309 310
      } else if (RA_template->wait_ack_Msg4==1) {
	// check HARQ status and retransmit if necessary
311
	LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Checking if Msg4 was acknowledged: \tn",
312 313
	      module_idP,CC_id,frameP,subframeP);
	// Get candidate harq_pid from PHY
314 315 316 317 318

	UE_id = find_UE_id(module_idP,RA_template->rnti);
	AssertFatal(UE_id>=0,"Can't find UE for t-crnti\n");
	round = UE_list->UE_sched_ctrl[UE_id].round[CC_id];

319 320 321 322
	if (round>0) {
	  //RA_template->wait_ack_Msg4++;
	  // we have to schedule a retransmission
	  
323
	  first_rb=0;
324 325 326 327
	  vrb_map[first_rb] = 1;
	  vrb_map[first_rb+1] = 1;
	  vrb_map[first_rb+2] = 1;
	  vrb_map[first_rb+3] = 1;
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345

	  memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
	  dl_config_pdu->pdu_type                                                          = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
	  dl_config_pdu->pdu_size                                                          = 2+sizeof(nfapi_dl_config_dci_dl_pdu);
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                             = NFAPI_DL_DCI_FORMAT_1A;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level                      = 4;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                                   = RA_template->rnti;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                              = 1;    // C-RNTI : see Table 4-10 from SCF082 - nFAPI specifications
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power                     = 6000; // equal to RS power
	  
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                           = 0;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                                    = 1; // no TPC
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1                   = 1;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1                   = 0;
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = 0;
	  
	  // Compute MCS for 3 PRB
	  msg4_header = 1+6+1;  // CR header, CR CE, SDU header
346
	  
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
	  
	  if ((rrc_sdu_length+msg4_header) <= 22) {
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 4;
	    TBsize = 22;
	  } else if ((rrc_sdu_length+msg4_header) <= 28) {
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 5;
	    TBsize = 28;
	  } else if ((rrc_sdu_length+msg4_header) <= 32) {
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 6;
	    TBsize = 32;
	  } else if ((rrc_sdu_length+msg4_header) <= 41) {
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 7;
	    TBsize = 41;
	  } else if ((rrc_sdu_length+msg4_header) <= 49) {
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 8;
	    TBsize = 49;
	  } else if ((rrc_sdu_length+msg4_header) <= 57) {
	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 9;
	    TBsize = 57;
366 367
	  }
	  
368 369
	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding= getRIV(N_RB_DL,first_rb,4);
	  
370
	  if (!CCE_allocation_infeasible(module_idP,CC_id,0,subframeP,2,RA_template->rnti)) {
371 372 373 374
	    eNB->DL_req[CC_id].number_dci++;
	    eNB->DL_req[CC_id].number_pdu++;
		  
	    LOG_I(MAC,"msg4 retransmission for rnti %x (round %d) fsf %d/%d\n", RA_template->rnti, round, frameP, subframeP);
375
	  }
376 377
	  else
	    LOG_I(MAC,"msg4 retransmission for rnti %x (round %d) fsf %d/%d CCE allocation failed!\n", RA_template->rnti, round, frameP, subframeP);
378 379 380 381 382 383 384 385
	  LOG_W(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Msg4 not acknowledged, adding ue specific dci (rnti %x) for RA (Msg4 Retransmission)\n",
		module_idP,CC_id,frameP,subframeP,RA_template->rnti);
	} else {
	  LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d : Msg4 acknowledged\n",module_idP,CC_id,frameP,subframeP);
	  RA_template->wait_ack_Msg4=0;
	  RA_template->RA_active=FALSE;
	  UE_id = find_UE_id(module_idP,RA_template->rnti);
	  DevAssert( UE_id != -1 );
386
	  eNB->UE_list.UE_template[UE_PCCID(module_idP,UE_id)][UE_id].configured=TRUE;
387
	}
388
      }
389 390
    } // for i=0 .. N_RA_PROC-1 
  } // CC_id
Raymond Knopp's avatar
 
Raymond Knopp committed
391

392 393
  stop_meas(&eNB->schedule_ra);
}
Lionel Gauthier's avatar
 
Lionel Gauthier committed
394

395
// handles the event of MSG1 reception
396 397
void initiate_ra_proc(module_id_t module_idP, int CC_id,frame_t frameP, uint16_t preamble_index,int16_t timing_offset,uint8_t sect_id,sub_frame_t subframeP,
                      uint8_t f_id)
398 399 400
{

  uint8_t i;
401
  RA_TEMPLATE *RA_template = (RA_TEMPLATE *)&RC.mac[module_idP]->common_channels[CC_id].RA_template[0];
402

403
  LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Initiating RA procedure for preamble index %d\n",module_idP,CC_id,frameP,preamble_index);
404

405 406 407
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_INITIATE_RA_PROC,1);
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_INITIATE_RA_PROC,0);

408
  for (i=0; i<NB_RA_PROC_MAX; i++) {
409 410
    if (RA_template[i].RA_active==FALSE &&
        RA_template[i].wait_ack_Msg4 == 0) {
Cedric Roux's avatar
Cedric Roux committed
411
      int loop = 0;
412 413 414 415 416
      RA_template[i].RA_active=TRUE;
      RA_template[i].generate_rar=1;
      RA_template[i].generate_Msg4=0;
      RA_template[i].wait_ack_Msg4=0;
      RA_template[i].timing_offset=timing_offset;
Cedric Roux's avatar
Cedric Roux committed
417 418 419 420 421 422 423 424 425 426 427 428
      /* TODO: find better procedure to allocate RNTI */
      do {
        RA_template[i].rnti = taus();
        loop++;
      } while (loop != 100 &&
               /* TODO: this is not correct, the rnti may be in use without
                * being in the MAC yet. To be refined.
                */
               !(find_UE_id(module_idP, RA_template[i].rnti) == -1 &&
                 /* 1024 and 60000 arbirarily chosen, not coming from standard */
                 RA_template[i].rnti >= 1024 && RA_template[i].rnti < 60000));
      if (loop == 100) { printf("%s:%d:%s: FATAL ERROR! contact the authors\n", __FILE__, __LINE__, __FUNCTION__); abort(); }
429 430
      RA_template[i].RA_rnti = 1+subframeP+(10*f_id);
      RA_template[i].preamble_index = preamble_index;
431 432
      LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Activating RAR generation for process %d, rnti %x, RA_active %d\n",
            module_idP,CC_id,frameP,i,RA_template[i].rnti,
433 434 435 436 437
            RA_template[i].RA_active);

      return;
    }
  }
Cedric Roux's avatar
Cedric Roux committed
438 439

  LOG_E(MAC,"[eNB %d][RAPROC] FAILURE: CC_id %d Frame %d Initiating RA procedure for preamble index %d\n",module_idP,CC_id,frameP,preamble_index);
440
}
Lionel Gauthier's avatar
 
Lionel Gauthier committed
441

442 443 444
void cancel_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP, rnti_t rnti)
{
  unsigned char i;
445
  RA_TEMPLATE *RA_template = (RA_TEMPLATE *)&RC.mac[module_idP]->common_channels[CC_id].RA_template[0];
446

Lionel Gauthier's avatar
Lionel Gauthier committed
447
  MSC_LOG_EVENT(MSC_PHY_ENB, "RA Cancelling procedure ue %"PRIx16" ", rnti);
448
  LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Cancelling RA procedure for UE rnti %x\n",module_idP,CC_id,frameP,rnti);
449 450 451 452 453 454 455 456 457 458

  for (i=0; i<NB_RA_PROC_MAX; i++) {
    if (rnti == RA_template[i].rnti) {
      RA_template[i].RA_active=FALSE;
      RA_template[i].generate_rar=0;
      RA_template[i].generate_Msg4=0;
      RA_template[i].wait_ack_Msg4=0;
      RA_template[i].timing_offset=0;
      RA_template[i].RRC_timer=20;
      RA_template[i].rnti = 0;
Raymond Knopp's avatar
 
Raymond Knopp committed
459
    }
460
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
461 462
}