f1ap_common.c 6.24 KB
Newer Older
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 33 34
/*
 * 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 f1ap_common.c
 * \brief f1ap procedures for both CU and DU
 * \author EURECOM/NTUST
 * \date 2018
 * \version 0.1
 * \company Eurecom
 * \email: navid.nikaein@eurecom.fr, bing-kai.hong@eurecom.fr
 * \note
 * \warning
 */

#include "f1ap_common.h"

35
#if defined(EMIT_ASN_DEBUG_EXTERN)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
int asn_debug = 0;
int asn1_xer_print = 0;

inline void ASN_DEBUG(const char *fmt, ...)
{
  if (asn_debug) {
    int adi = asn_debug_indent;
    va_list ap;
    va_start(ap, fmt);
    fprintf(stderr, "[ASN1]");

    while(adi--) fprintf(stderr, " ");

    vfprintf(stderr, fmt, ap);
    fprintf(stderr, "\n");
    va_end(ap);
  }
}
#endif

56 57 58 59 60 61 62 63
uint8_t F1AP_get_next_transaction_identifier(module_id_t enb_mod_idP, module_id_t cu_mod_idP)
{
  static uint8_t transaction_identifier[NUMBER_OF_eNB_MAX];
  transaction_identifier[enb_mod_idP+cu_mod_idP] =
      (transaction_identifier[enb_mod_idP+cu_mod_idP] + 1) % F1AP_TRANSACTION_IDENTIFIER_NUMBER;
  //LOG_T(F1AP,"generated xid is %d\n",transaction_identifier[enb_mod_idP+cu_mod_idP]);
  return transaction_identifier[enb_mod_idP+cu_mod_idP];
}
64

Robert Schmidt's avatar
Robert Schmidt committed
65
int f1ap_add_ue(f1ap_cudu_inst_t    *f1_inst,
66 67 68
                module_id_t          module_idP,
                int                  CC_idP,
                int                  UE_id,
Robert Schmidt's avatar
Robert Schmidt committed
69 70 71 72 73 74 75
                rnti_t               rntiP) {
  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
    if (f1_inst->f1ap_ue[i].rnti == rntiP) {
      f1_inst->f1ap_ue[i].f1ap_uid = i;
      f1_inst->f1ap_ue[i].mac_uid = UE_id;
      LOG_I(F1AP, "Updating the index of UE with RNTI %x and du_ue_f1ap_id %d\n", f1_inst->f1ap_ue[i].rnti, f1_inst->f1ap_ue[i].du_ue_f1ap_id);
      return i;
76 77
    }
  }
Robert Schmidt's avatar
Robert Schmidt committed
78 79 80 81 82 83 84 85 86
  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
    if (f1_inst->f1ap_ue[i].rnti == 0 ) {
      f1_inst->f1ap_ue[i].rnti = rntiP;
      f1_inst->f1ap_ue[i].f1ap_uid = i;
      f1_inst->f1ap_ue[i].mac_uid = UE_id;
      f1_inst->f1ap_ue[i].du_ue_f1ap_id = rntiP;
      f1_inst->f1ap_ue[i].cu_ue_f1ap_id = rntiP;
      f1_inst->num_ues++;
      LOG_I(F1AP, "Adding a new UE with RNTI %x and cu/du ue_f1ap_id %d\n", f1_inst->f1ap_ue[i].rnti, f1_inst->f1ap_ue[i].du_ue_f1ap_id);
87 88 89 90 91 92 93
      return i;
    }
  }
  return -1;
}


Robert Schmidt's avatar
Robert Schmidt committed
94 95 96 97 98 99
int f1ap_remove_ue(f1ap_cudu_inst_t *f1_inst,
                   rnti_t            rntiP) {
  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
    if (f1_inst->f1ap_ue[i].rnti == rntiP) {
      f1_inst->f1ap_ue[i].rnti = 0;
      break;
100 101
    }
  }
Robert Schmidt's avatar
Robert Schmidt committed
102 103
  f1_inst->num_ues--;
  return 0;
104 105
}

Robert Schmidt's avatar
Robert Schmidt committed
106 107 108 109 110
int f1ap_get_du_ue_f1ap_id(f1ap_cudu_inst_t *f1_inst,
                            rnti_t            rntiP) {
  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
    if (f1_inst->f1ap_ue[i].rnti == rntiP) {
      return f1_inst->f1ap_ue[i].du_ue_f1ap_id;
111
    }
Robert Schmidt's avatar
Robert Schmidt committed
112 113
  }
  return -1;
114 115
}

Robert Schmidt's avatar
Robert Schmidt committed
116 117 118 119 120
int f1ap_get_cu_ue_f1ap_id(f1ap_cudu_inst_t *f1_inst,
                            rnti_t            rntiP) {
  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
    if (f1_inst->f1ap_ue[i].rnti == rntiP) {
      return f1_inst->f1ap_ue[i].cu_ue_f1ap_id;
121
    }
Robert Schmidt's avatar
Robert Schmidt committed
122 123
  }
  return -1;
124 125
}

Robert Schmidt's avatar
Robert Schmidt committed
126 127 128 129 130 131 132 133
int f1ap_get_rnti_by_du_id(f1ap_cudu_inst_t *f1_inst,
                           module_id_t       du_ue_f1ap_id ) {
  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
    if (f1_inst->f1ap_ue[i].du_ue_f1ap_id == du_ue_f1ap_id) {
      return f1_inst->f1ap_ue[i].rnti;
    }
  }
  return -1;
134 135
}

Robert Schmidt's avatar
Robert Schmidt committed
136 137 138 139 140 141 142 143
int f1ap_get_rnti_by_cu_id(f1ap_cudu_inst_t *f1_inst,
                           module_id_t       cu_ue_f1ap_id ) {
  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
    if (f1_inst->f1ap_ue[i].cu_ue_f1ap_id == cu_ue_f1ap_id) {
      return f1_inst->f1ap_ue[i].rnti;
    }
  }
  return -1;
144 145
}

Robert Schmidt's avatar
Robert Schmidt committed
146 147 148 149
int f1ap_get_du_uid(f1ap_cudu_inst_t *f1_inst,
                    module_id_t       du_ue_f1ap_id ) {
  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
    if (f1_inst->f1ap_ue[i].du_ue_f1ap_id == du_ue_f1ap_id) {
150
      return i;
Robert Schmidt's avatar
Robert Schmidt committed
151 152 153
    }
  }
  return -1;
154 155
}

Robert Schmidt's avatar
Robert Schmidt committed
156 157 158 159
int f1ap_get_cu_uid(f1ap_cudu_inst_t *f1_inst,
                    module_id_t       cu_ue_f1ap_id ) {
  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
    if (f1_inst->f1ap_ue[i].cu_ue_f1ap_id == cu_ue_f1ap_id) {
160
      return i;
Robert Schmidt's avatar
Robert Schmidt committed
161 162 163
    }
  }
  return -1;
164 165
}

Robert Schmidt's avatar
Robert Schmidt committed
166 167 168 169
int f1ap_get_uid_by_rnti(f1ap_cudu_inst_t *f1_inst,
                         rnti_t            rntiP ) {
  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
    if (f1_inst->f1ap_ue[i].rnti == rntiP) {
170
      return i;
Robert Schmidt's avatar
Robert Schmidt committed
171 172 173
    }
  }
  return -1;
174 175
}

Robert Schmidt's avatar
Robert Schmidt committed
176 177 178 179
int f1ap_du_add_cu_ue_id(f1ap_cudu_inst_t *f1_inst,
                         module_id_t       du_ue_f1ap_id,
                         module_id_t       cu_ue_f1ap_id) {
  module_id_t f1ap_uid = f1ap_get_du_uid(f1_inst,du_ue_f1ap_id);
180
  if (f1ap_uid < 0 || f1ap_uid >= MAX_MOBILES_PER_ENB) return -1;
Robert Schmidt's avatar
Robert Schmidt committed
181 182 183
  f1_inst->f1ap_ue[f1ap_uid].cu_ue_f1ap_id = cu_ue_f1ap_id;
  LOG_I(F1AP, "Adding cu_ue_f1ap_id %d for UE with RNTI %x\n", cu_ue_f1ap_id, f1_inst->f1ap_ue[f1ap_uid].rnti);
  return 0;
184 185
}

Robert Schmidt's avatar
Robert Schmidt committed
186 187 188 189
int f1ap_cu_add_du_ue_id(f1ap_cudu_inst_t *f1_inst,
                         module_id_t       cu_ue_f1ap_id,
                         module_id_t       du_ue_f1ap_id) {
  module_id_t f1ap_uid = f1ap_get_cu_uid(f1_inst,cu_ue_f1ap_id);
190
  if (f1ap_uid < 0 || f1ap_uid >= MAX_MOBILES_PER_ENB) return -1;
Robert Schmidt's avatar
Robert Schmidt committed
191 192 193 194
  f1_inst->f1ap_ue[f1ap_uid].du_ue_f1ap_id = du_ue_f1ap_id;
  LOG_I(F1AP, "Adding du_ue_f1ap_id %d for UE with RNTI %x\n", du_ue_f1ap_id, f1_inst->f1ap_ue[f1ap_uid].rnti);
  return 0;
}