prach_procedures.c 9.1 KB
Newer Older
Raymond Knopp's avatar
Raymond Knopp committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*
 * 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.1  (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
 */

/*! \file phy_procedures_lte_eNB.c
 * \brief Implementation of eNB procedures from 36.213 LTE specifications
 * \author R. Knopp, F. Kaltenberger, N. Nikaein, X. Foukas
 * \date 2011
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,navid.nikaein@eurecom.fr, x.foukas@sms.ed.ac.uk
 * \note
 * \warning
 */

33 34 35
#include "PHY/defs_eNB.h"
#include "PHY/phy_extern.h"
#include "SCHED/sched_eNB.h"
Raymond Knopp's avatar
Raymond Knopp committed
36 37
#include "nfapi_interface.h"
#include "fapi_l1.h"
oai's avatar
oai committed
38
#include "nfapi_pnf.h"
39
#include "common/utils/LOG/log.h"
frtabu's avatar
frtabu committed
40
#include "nfapi/oai_integration/vendor_ext.h"
41
#include "common/utils/LOG/vcd_signal_dumper.h"
Raymond Knopp's avatar
Raymond Knopp committed
42 43 44 45 46 47 48 49


#include "assertions.h"
#include "msc.h"

#include <time.h>

#if defined(ENABLE_ITTI)
frtabu's avatar
frtabu committed
50
  #include "intertask_interface.h"
Raymond Knopp's avatar
Raymond Knopp committed
51 52 53
#endif


Cedric Roux's avatar
Cedric Roux committed
54 55
extern int oai_nfapi_rach_ind(nfapi_rach_indication_t *rach_ind);

56
void prach_procedures(PHY_VARS_eNB *eNB
57
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
frtabu's avatar
frtabu committed
58 59
  ,
  int br_flag
Raymond Knopp's avatar
Raymond Knopp committed
60
#endif
frtabu's avatar
frtabu committed
61
                     ) {
62
  uint16_t max_preamble[4],max_preamble_energy[4],max_preamble_delay[4],avg_preamble_energy[4];
Raymond Knopp's avatar
Raymond Knopp committed
63 64
  uint16_t i;
  int frame,subframe;
65
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
frtabu's avatar
frtabu committed
66

Raymond Knopp's avatar
Raymond Knopp committed
67 68 69 70 71 72
  if (br_flag==1) {
    subframe = eNB->proc.subframe_prach_br;
    frame = eNB->proc.frame_prach_br;
    pthread_mutex_lock(&eNB->UL_INFO_mutex);
    eNB->UL_INFO.rach_ind_br.rach_indication_body.number_of_preambles=0;
    pthread_mutex_unlock(&eNB->UL_INFO_mutex);
frtabu's avatar
frtabu committed
73
  } else
Raymond Knopp's avatar
Raymond Knopp committed
74
#endif
frtabu's avatar
frtabu committed
75 76 77 78 79 80 81 82
  {
    pthread_mutex_lock(&eNB->UL_INFO_mutex);
    eNB->UL_INFO.rach_ind.rach_indication_body.number_of_preambles=0;
    pthread_mutex_unlock(&eNB->UL_INFO_mutex);
    subframe = eNB->proc.subframe_prach;
    frame = eNB->proc.frame_prach;
  }

Raymond Knopp's avatar
Raymond Knopp committed
83 84 85 86 87
  RU_t *ru;
  int aa=0;
  int ru_aa;
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,1);

frtabu's avatar
frtabu committed
88
  for (i=0; i<eNB->num_RU; i++) {
Raymond Knopp's avatar
Raymond Knopp committed
89
    ru=eNB->RU_list[i];
frtabu's avatar
frtabu committed
90 91

    for (ru_aa=0,aa=0; ru_aa<ru->nb_rx; ru_aa++,aa++) {
Raymond Knopp's avatar
Raymond Knopp committed
92
      eNB->prach_vars.rxsigF[0][aa] = eNB->RU_list[i]->prach_rxsigF[ru_aa];
93
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Raymond Knopp's avatar
Raymond Knopp committed
94 95 96
      int ce_level;

      if (br_flag==1)
frtabu's avatar
frtabu committed
97 98
        for (ce_level=0; ce_level<4; ce_level++) eNB->prach_vars_br.rxsigF[ce_level][aa] = eNB->RU_list[i]->prach_rxsigF_br[ce_level][ru_aa];

Raymond Knopp's avatar
Raymond Knopp committed
99 100 101 102
#endif
    }
  }

103
  // run PRACH detection for CE-level 0 only for now when br_flag is set
Raymond Knopp's avatar
Raymond Knopp committed
104
  rx_prach(eNB,
frtabu's avatar
frtabu committed
105 106 107 108
           eNB->RU_list[0],
           &max_preamble[0],
           &max_preamble_energy[0],
           &max_preamble_delay[0],
109
	   &avg_preamble_energy[0],
frtabu's avatar
frtabu committed
110 111
           frame,
           0
112
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
frtabu's avatar
frtabu committed
113
           ,br_flag
Raymond Knopp's avatar
Raymond Knopp committed
114
#endif
frtabu's avatar
frtabu committed
115
          );
116
  LOG_D(PHY,"[RAPROC] Frame %d, subframe %d : BR %d  Most likely preamble %d, energy %d dB delay %d (prach_energy counter %d), threshold %d, I0 %d\n",
nepes's avatar
nepes committed
117
        frame,subframe,br_flag,
Raymond Knopp's avatar
Raymond Knopp committed
118 119 120
        max_preamble[0],
        max_preamble_energy[0]/10,
        max_preamble_delay[0],
121 122 123
        eNB->prach_energy_counter,
	eNB->measurements.prach_I0+eNB->prach_DTX_threshold,
	eNB->measurements.prach_I0);
124
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
frtabu's avatar
frtabu committed
125

Raymond Knopp's avatar
Raymond Knopp committed
126
  if (br_flag==1) {
127 128
    int             prach_mask;
    prach_mask = is_prach_subframe (&eNB->frame_parms, eNB->proc.frame_prach_br, eNB->proc.subframe_prach_br);
129
    eNB->UL_INFO.rach_ind_br.rach_indication_body.preamble_list = eNB->preamble_list_br;
130 131
    int             ind = 0;
    int             ce_level = 0;
frtabu's avatar
frtabu committed
132
    /* Save for later, it doesn't work
133 134 135 136 137 138 139 140 141 142
       for (int ind=0,ce_level=0;ce_level<4;ce_level++) {

       if ((eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[ce_level]==1)&&
       (prach_mask&(1<<(1+ce_level)) > 0) && // prach is active and CE level has finished its repetitions
       (eNB->prach_vars_br.repetition_number[ce_level]==
       eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[ce_level])) {

    */

    if (eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[0] == 1) {
143
      if ((eNB->prach_energy_counter == 100) && (max_preamble_energy[0] > eNB->measurements.prach_I0 + eNB->prach_DTX_threshold_emtc[0])) {
144
        eNB->UL_INFO.rach_ind_br.rach_indication_body.number_of_preambles++;
145 146 147 148 149 150 151 152 153 154 155 156
        eNB->preamble_list_br[ind].preamble_rel8.timing_advance = max_preamble_delay[ind];      //
        eNB->preamble_list_br[ind].preamble_rel8.preamble = max_preamble[ind];
        // note: fid is implicitly 0 here, this is the rule for eMTC RA-RNTI from 36.321, Section 5.1.4
        eNB->preamble_list_br[ind].preamble_rel8.rnti = 1 + subframe + (60*(eNB->prach_vars_br.first_frame[ce_level] % 40));
        eNB->preamble_list_br[ind].instance_length = 0; //don't know exactly what this is
        eNB->preamble_list_br[ind].preamble_rel13.rach_resource_type = 1 + ce_level;    // CE Level
        LOG_I (PHY, "Filling NFAPI indication for RACH %d CELevel %d (mask %x) : TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
               ind,
               ce_level,
               prach_mask,
               eNB->preamble_list_br[ind].preamble_rel8.timing_advance,
               eNB->preamble_list_br[ind].preamble_rel8.preamble, eNB->preamble_list_br[ind].preamble_rel8.rnti, eNB->preamble_list_br[ind].preamble_rel13.rach_resource_type);
Raymond Knopp's avatar
Raymond Knopp committed
157
      }
158
    }
Raymond Knopp's avatar
Raymond Knopp committed
159

frtabu's avatar
frtabu committed
160 161 162 163 164 165 166 167 168
    /*
    ind++;
    }
    } */// ce_level
  } else
#endif
  {
    if ((eNB->prach_energy_counter == 100) &&
        (max_preamble_energy[0] > eNB->measurements.prach_I0+eNB->prach_DTX_threshold)) {
169
      LOG_D(PHY,"[eNB %d/%d][RAPROC] Frame %d, subframe %d Initiating RA procedure with preamble %d, energy %d.%d dB, delay %d\n",
frtabu's avatar
frtabu committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
            eNB->Mod_id,
            eNB->CC_id,
            frame,
            subframe,
            max_preamble[0],
            max_preamble_energy[0]/10,
            max_preamble_energy[0]%10,
            max_preamble_delay[0]);
      T(T_ENB_PHY_INITIATE_RA_PROCEDURE, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe),
        T_INT(max_preamble[0]), T_INT(max_preamble_energy[0]), T_INT(max_preamble_delay[0]));
      pthread_mutex_lock(&eNB->UL_INFO_mutex);
      eNB->UL_INFO.rach_ind.rach_indication_body.number_of_preambles  = 1;
      eNB->UL_INFO.rach_ind.rach_indication_body.preamble_list        = &eNB->preamble_list[0];
      eNB->UL_INFO.rach_ind.rach_indication_body.tl.tag               = NFAPI_RACH_INDICATION_BODY_TAG;
      eNB->UL_INFO.rach_ind.header.message_id                         = NFAPI_RACH_INDICATION;
      eNB->UL_INFO.rach_ind.sfn_sf                                    = frame<<4 | subframe;
      eNB->preamble_list[0].preamble_rel8.tl.tag                = NFAPI_PREAMBLE_REL8_TAG;
      eNB->preamble_list[0].preamble_rel8.timing_advance        = max_preamble_delay[0];
      eNB->preamble_list[0].preamble_rel8.preamble              = max_preamble[0];
      eNB->preamble_list[0].preamble_rel8.rnti                  = 1+subframe;  // note: fid is implicitly 0 here
      eNB->preamble_list[0].preamble_rel13.rach_resource_type   = 0;
      eNB->preamble_list[0].instance_length                     = 0; //don't know exactly what this is

      if (NFAPI_MODE==NFAPI_MODE_PNF) {  // If NFAPI PNF then we need to send the message to the VNF
        LOG_D(PHY,"Filling NFAPI indication for RACH : SFN_SF:%d TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
              NFAPI_SFNSF2DEC(eNB->UL_INFO.rach_ind.sfn_sf),
              eNB->preamble_list[0].preamble_rel8.timing_advance,
              eNB->preamble_list[0].preamble_rel8.preamble,
              eNB->preamble_list[0].preamble_rel8.rnti,
              eNB->preamble_list[0].preamble_rel13.rach_resource_type);
        oai_nfapi_rach_ind(&eNB->UL_INFO.rach_ind);
        eNB->UL_INFO.rach_ind.rach_indication_body.number_of_preambles = 0;
Raymond Knopp's avatar
Raymond Knopp committed
202
      }
frtabu's avatar
frtabu committed
203 204 205 206

      pthread_mutex_unlock(&eNB->UL_INFO_mutex);
    } // max_preamble_energy > prach_I0 + 100
    else {
207
      eNB->measurements.prach_I0 = ((eNB->measurements.prach_I0*900)>>10) + ((avg_preamble_energy[0]*124)>>10);
frtabu's avatar
frtabu committed
208 209 210 211 212 213

      if (frame==0) LOG_I(PHY,"prach_I0 = %d.%d dB\n",eNB->measurements.prach_I0/10,eNB->measurements.prach_I0%10);

      if (eNB->prach_energy_counter < 100) eNB->prach_energy_counter++;
    }
  } // else br_flag
Raymond Knopp's avatar
Raymond Knopp committed
214 215 216

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,0);
}