f1ap_cu_interface_management.c 47 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
/*
 * 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_cu_interface_management.c
 * \brief f1ap interface management for CU
 * \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"
34 35
#include "f1ap_encoder.h"
#include "f1ap_decoder.h"
36 37
#include "f1ap_itti_messaging.h"
#include "f1ap_cu_interface_management.h"
38 39

extern f1ap_setup_req_t *f1ap_du_data_from_du;
Xue Song's avatar
Xue Song committed
40
extern RAN_CONTEXT_t RC;
41

42
int CU_send_RESET(instance_t instance, F1AP_Reset_t *Reset) {
43 44 45
  AssertFatal(1==0,"Not implemented yet\n");
}

46 47 48 49
int CU_handle_RESET_ACKKNOWLEDGE(instance_t instance,
                                  uint32_t assoc_id,
                                  uint32_t stream,
                                  F1AP_F1AP_PDU_t *pdu) {
50 51 52
  AssertFatal(1==0,"Not implemented yet\n");
}

53 54 55 56
int CU_handle_RESET(instance_t instance,
                     uint32_t assoc_id,
                     uint32_t stream,
                     F1AP_F1AP_PDU_t *pdu) {
57 58 59
  AssertFatal(1==0,"Not implemented yet\n");
}

60
int CU_send_RESET_ACKNOWLEDGE(instance_t instance, F1AP_ResetAcknowledge_t *ResetAcknowledge) {
61 62 63 64 65 66 67
  AssertFatal(1==0,"Not implemented yet\n");
}


/*
    Error Indication
*/
68 69 70 71
int CU_handle_ERROR_INDICATION(instance_t instance,
                                uint32_t assoc_id,
                                uint32_t stream,
                                F1AP_F1AP_PDU_t *pdu) {
72 73 74
  AssertFatal(1==0,"Not implemented yet\n");
}

75
int CU_send_ERROR_INDICATION(instance_t instance, F1AP_ErrorIndication_t *ErrorIndication) {
76 77 78 79 80 81 82
  AssertFatal(1==0,"Not implemented yet\n");
}


/*
    F1 Setup
*/
83
int CU_handle_F1_SETUP_REQUEST(instance_t instance,
84 85 86
                               uint32_t assoc_id,
                               uint32_t stream,
                               F1AP_F1AP_PDU_t *pdu)
87
{
88
  LOG_D(F1AP, "CU_handle_F1_SETUP_REQUEST\n");
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
  
  MessageDef                         *message_p;
  F1AP_F1SetupRequest_t              *container;
  F1AP_F1SetupRequestIEs_t           *ie;
  int i = 0;
   

  DevAssert(pdu != NULL);

  container = &pdu->choice.initiatingMessage->value.choice.F1SetupRequest;

  /* F1 Setup Request == Non UE-related procedure -> stream 0 */
  if (stream != 0) {
    LOG_W(F1AP, "[SCTP %d] Received f1 setup request on stream != 0 (%d)\n",
              assoc_id, stream);
  }

106 107 108 109 110
  if(RC.nrrrc) {
    message_p = itti_alloc_new_message(TASK_CU_F1, 0, F1AP_SETUP_REQ);
  } else {
    message_p = itti_alloc_new_message(TASK_RRC_ENB, 0, F1AP_SETUP_REQ);
  }
Xue Song's avatar
Xue Song committed
111

112 113 114 115 116 117 118 119
  /* assoc_id */
  F1AP_SETUP_REQ(message_p).assoc_id = assoc_id;
  
  /* gNB_DU_id */
  // this function exits if the ie is mandatory
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_F1SetupRequestIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_gNB_DU_ID, true);
  asn_INTEGER2ulong(&ie->value.choice.GNB_DU_ID, &F1AP_SETUP_REQ(message_p).gNB_DU_id);
120
  LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).gNB_DU_id %lu \n", F1AP_SETUP_REQ(message_p).gNB_DU_id);
121 122 123 124 125 126 127 128 129

  /* gNB_DU_name */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_F1SetupRequestIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_Name, true);
  F1AP_SETUP_REQ(message_p).gNB_DU_name = calloc(ie->value.choice.GNB_DU_Name.size + 1, sizeof(char));
  memcpy(F1AP_SETUP_REQ(message_p).gNB_DU_name, ie->value.choice.GNB_DU_Name.buf,
         ie->value.choice.GNB_DU_Name.size);
  /* Convert the mme name to a printable string */
  F1AP_SETUP_REQ(message_p).gNB_DU_name[ie->value.choice.GNB_DU_Name.size] = '\0';
130
  LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).gNB_DU_name %s \n", F1AP_SETUP_REQ(message_p).gNB_DU_name);
131 132 133 134 135

  /* GNB_DU_Served_Cells_List */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_F1SetupRequestIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_Served_Cells_List, true);
  F1AP_SETUP_REQ(message_p).num_cells_available = ie->value.choice.GNB_DU_Served_Cells_List.list.count;
136 137
  LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).num_cells_available %d \n",
        F1AP_SETUP_REQ(message_p).num_cells_available);
138 139 140 141

  int num_cells_available = F1AP_SETUP_REQ(message_p).num_cells_available;

  for (i=0; i<num_cells_available; i++) {
142
    F1AP_GNB_DU_Served_Cells_Item_t *served_cells_item_p;
143

144
    served_cells_item_p = &(((F1AP_GNB_DU_Served_Cells_ItemIEs_t *)ie->value.choice.GNB_DU_Served_Cells_List.list.array[i])->value.choice.GNB_DU_Served_Cells_Item);
145 146
    
    /* tac */
147 148
    if (served_cells_item_p->served_Cell_Information.fiveGS_TAC) {
      OCTET_STRING_TO_INT16(served_cells_item_p->served_Cell_Information.fiveGS_TAC, F1AP_SETUP_REQ(message_p).tac[i]);
rmagueta's avatar
rmagueta committed
149
      LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).tac[%d] %d \n", i, F1AP_SETUP_REQ(message_p).tac[i]);
Xue Song's avatar
Xue Song committed
150
    }
151
    /* - nRCGI */
152
    TBCD_TO_MCC_MNC(&(served_cells_item_p->served_Cell_Information.nRCGI.pLMN_Identity), F1AP_SETUP_REQ(message_p).mcc[i],
153 154 155
                    F1AP_SETUP_REQ(message_p).mnc[i],
                    F1AP_SETUP_REQ(message_p).mnc_digit_length[i]);
    
156 157
    
    // NR cellID
158
    BIT_STRING_TO_NR_CELL_IDENTITY(&served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity,
159
				   F1AP_SETUP_REQ(message_p).nr_cellid[i]);
rmagueta's avatar
rmagueta committed
160
    LOG_D(F1AP, "[SCTP %d] Received nRCGI: MCC %d, MNC %d, CELL_ID %llu\n", assoc_id,
161 162 163 164
          F1AP_SETUP_REQ(message_p).mcc[i],
          F1AP_SETUP_REQ(message_p).mnc[i],
          (long long unsigned int)F1AP_SETUP_REQ(message_p).nr_cellid[i]);
    LOG_D(F1AP, "nr_cellId : %x %x %x %x %x\n",
165 166 167 168 169
          served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity.buf[0],
          served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity.buf[1],
          served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity.buf[2],
          served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity.buf[3],
          served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity.buf[4]);
170
    /* - nRPCI */
171
    F1AP_SETUP_REQ(message_p).nr_pci[i] = served_cells_item_p->served_Cell_Information.nRPCI;
rmagueta's avatar
rmagueta committed
172
    LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).nr_pci[%d] %d \n",
173
          i, F1AP_SETUP_REQ(message_p).nr_pci[i]);
174 175 176
  
    // System Information
    /* mib */
177 178 179
    F1AP_SETUP_REQ(message_p).mib[i] = calloc(served_cells_item_p->gNB_DU_System_Information->mIB_message.size + 1, sizeof(char));
    memcpy(F1AP_SETUP_REQ(message_p).mib[i], served_cells_item_p->gNB_DU_System_Information->mIB_message.buf,
           served_cells_item_p->gNB_DU_System_Information->mIB_message.size);
180
    /* Convert the mme name to a printable string */
181 182
    F1AP_SETUP_REQ(message_p).mib[i][served_cells_item_p->gNB_DU_System_Information->mIB_message.size] = '\0';
    F1AP_SETUP_REQ(message_p).mib_length[i] = served_cells_item_p->gNB_DU_System_Information->mIB_message.size;
183 184
    LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).mib[%d] %s , len = %d \n",
          i, F1AP_SETUP_REQ(message_p).mib[i], F1AP_SETUP_REQ(message_p).mib_length[i]);
185 186

    /* sib1 */
187 188 189
    F1AP_SETUP_REQ(message_p).sib1[i] = calloc(served_cells_item_p->gNB_DU_System_Information->sIB1_message.size + 1, sizeof(char));
    memcpy(F1AP_SETUP_REQ(message_p).sib1[i], served_cells_item_p->gNB_DU_System_Information->sIB1_message.buf,
           served_cells_item_p->gNB_DU_System_Information->sIB1_message.size);
190
    /* Convert the mme name to a printable string */
191 192
    F1AP_SETUP_REQ(message_p).sib1[i][served_cells_item_p->gNB_DU_System_Information->sIB1_message.size] = '\0';
    F1AP_SETUP_REQ(message_p).sib1_length[i] = served_cells_item_p->gNB_DU_System_Information->sIB1_message.size;
193 194
    LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).sib1[%d] %s , len = %d \n",
          i, F1AP_SETUP_REQ(message_p).sib1[i], F1AP_SETUP_REQ(message_p).sib1_length[i]);
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
  }

  
  *f1ap_du_data_from_du = F1AP_SETUP_REQ(message_p);
  // char *measurement_timing_information[F1AP_MAX_NB_CELLS];
  // uint8_t ranac[F1AP_MAX_NB_CELLS];

  // int fdd_flag = f1ap_setup_req->fdd_flag;

  // union {
  //   struct {
  //     uint32_t ul_nr_arfcn;
  //     uint8_t ul_scs;
  //     uint8_t ul_nrb;

  //     uint32_t dl_nr_arfcn;
  //     uint8_t dl_scs;
  //     uint8_t dl_nrb;

  //     uint32_t sul_active;
  //     uint32_t sul_nr_arfcn;
  //     uint8_t sul_scs;
  //     uint8_t sul_nrb;

  //     uint8_t num_frequency_bands;
  //     uint16_t nr_band[32];
  //     uint8_t num_sul_frequency_bands;
  //     uint16_t nr_sul_band[32];
  //   } fdd;
  //   struct {

  //     uint32_t nr_arfcn;
  //     uint8_t scs;
  //     uint8_t nrb;

  //     uint32_t sul_active;
  //     uint32_t sul_nr_arfcn;
  //     uint8_t sul_scs;
  //     uint8_t sul_nrb;

  //     uint8_t num_frequency_bands;
  //     uint16_t nr_band[32];
  //     uint8_t num_sul_frequency_bands;
  //     uint16_t nr_sul_band[32];

  //   } tdd;
  // } nr_mode_info[F1AP_MAX_NB_CELLS];
Bing-Kai Hong's avatar
Bing-Kai Hong committed
242 243 244 245 246 247 248 249 250 251

  MSC_LOG_TX_MESSAGE(
  MSC_F1AP_CU,
  MSC_RRC_ENB,
  0,
  0,
  MSC_AS_TIME_FMT" CU_handle_F1_SETUP_REQUEST",
  0,0//MSC_AS_TIME_ARGS(ctxt_pP),
  );

252
  if (num_cells_available > 0) {
253
    if (RC.nrrrc && RC.nrrrc[0]->node_type == ngran_gNB_CU) {
Xue Song's avatar
Xue Song committed
254 255 256 257
      itti_send_msg_to_task(TASK_RRC_GNB, GNB_MODULE_ID_TO_INSTANCE(instance), message_p);
    } else {
      itti_send_msg_to_task(TASK_RRC_ENB, ENB_MODULE_ID_TO_INSTANCE(instance), message_p);
    }
258 259
  } else {
    CU_send_F1_SETUP_FAILURE(instance);
260
    if (RC.nrrrc && RC.nrrrc[0]->node_type == ngran_gNB_CU) {
Xue Song's avatar
Xue Song committed
261 262 263 264
      itti_free(TASK_RRC_GNB,message_p);
    } else {
      itti_free(TASK_RRC_ENB,message_p);
    }
265
    return -1;
266
  }
267
  return 0;
268 269
}

270
int CU_send_F1_SETUP_RESPONSE(instance_t instance,
271
                               f1ap_setup_resp_t *f1ap_setup_resp) {
272 273 274 275
  
  module_id_t enb_mod_idP;
  module_id_t cu_mod_idP;

276 277 278
  // This should be fixed
  enb_mod_idP = (module_id_t)0;
  cu_mod_idP  = (module_id_t)0;
279 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 310 311 312 313 314 315 316 317 318 319 320 321

  F1AP_F1AP_PDU_t           pdu;
  F1AP_F1SetupResponse_t    *out;
  F1AP_F1SetupResponseIEs_t *ie;

  uint8_t  *buffer;
  uint32_t  len;
  int       i = 0;

  /* Create */
  /* 0. Message Type */
  memset(&pdu, 0, sizeof(pdu));
  pdu.present = F1AP_F1AP_PDU_PR_successfulOutcome;
  pdu.choice.successfulOutcome = (F1AP_SuccessfulOutcome_t *)calloc(1, sizeof(F1AP_SuccessfulOutcome_t));
  pdu.choice.successfulOutcome->procedureCode = F1AP_ProcedureCode_id_F1Setup;
  pdu.choice.successfulOutcome->criticality   = F1AP_Criticality_reject;
  pdu.choice.successfulOutcome->value.present = F1AP_SuccessfulOutcome__value_PR_F1SetupResponse;
  out = &pdu.choice.successfulOutcome->value.choice.F1SetupResponse;
  
  /* mandatory */
  /* c1. Transaction ID (integer value)*/
  ie = (F1AP_F1SetupResponseIEs_t *)calloc(1, sizeof(F1AP_F1SetupResponseIEs_t));
  ie->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
  ie->criticality               = F1AP_Criticality_reject;
  ie->value.present             = F1AP_F1SetupResponseIEs__value_PR_TransactionID;
  ie->value.choice.TransactionID = F1AP_get_next_transaction_identifier(enb_mod_idP, cu_mod_idP);
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
  /* optional */
  /* c2. GNB_CU_Name */
  if (f1ap_setup_resp->gNB_CU_name != NULL) {
    ie = (F1AP_F1SetupResponseIEs_t *)calloc(1, sizeof(F1AP_F1SetupResponseIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_gNB_CU_Name;
    ie->criticality               = F1AP_Criticality_ignore;
    ie->value.present             = F1AP_F1SetupResponseIEs__value_PR_GNB_CU_Name;
    OCTET_STRING_fromBuf(&ie->value.choice.GNB_CU_Name, f1ap_setup_resp->gNB_CU_name,
                         strlen(f1ap_setup_resp->gNB_CU_name));
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
  }

  /* mandatory */
  /* c3. cells to be Activated list */
  int num_cells_to_activate = f1ap_setup_resp->num_cells_to_activate;
rmagueta's avatar
rmagueta committed
322
  LOG_D(F1AP, "num_cells_to_activate = %d \n", num_cells_to_activate);
323 324 325 326 327
  if (num_cells_to_activate >0) {
    ie = (F1AP_F1SetupResponseIEs_t *)calloc(1, sizeof(F1AP_F1SetupResponseIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List;
    ie->criticality               = F1AP_Criticality_reject;
    ie->value.present             = F1AP_F1SetupResponseIEs__value_PR_Cells_to_be_Activated_List;
328

329
    for (i=0; i<num_cells_to_activate; i++) {
330

rmagueta's avatar
rmagueta committed
331
      LOG_D(F1AP, "[c3] (cell %d) mcc = %d, mnc = %d, mnc_digit_length = %d, nr_cellid = %lu\n",
rmagueta's avatar
rmagueta committed
332 333 334 335 336
            i,
            f1ap_setup_resp->cells_to_activate[i].mcc,
            f1ap_setup_resp->cells_to_activate[i].mnc,
            f1ap_setup_resp->cells_to_activate[i].mnc_digit_length,
            f1ap_setup_resp->cells_to_activate[i].nr_cellid);
337

338 339 340 341 342
      F1AP_Cells_to_be_Activated_List_ItemIEs_t *cells_to_be_activated_list_item_ies;
      cells_to_be_activated_list_item_ies = (F1AP_Cells_to_be_Activated_List_ItemIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Activated_List_ItemIEs_t));
      cells_to_be_activated_list_item_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
      cells_to_be_activated_list_item_ies->criticality = F1AP_Criticality_reject;
      cells_to_be_activated_list_item_ies->value.present = F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item;
343

344 345 346
      /* 3.1 cells to be Activated list item */
      F1AP_Cells_to_be_Activated_List_Item_t cells_to_be_activated_list_item;
      memset((void *)&cells_to_be_activated_list_item, 0, sizeof(F1AP_Cells_to_be_Activated_List_Item_t));
347

348 349 350 351 352 353 354
      /* - nRCGI */
      F1AP_NRCGI_t nRCGI;
      memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
      MCC_MNC_TO_PLMNID(f1ap_setup_resp->cells_to_activate[i].mcc, f1ap_setup_resp->cells_to_activate[i].mnc, f1ap_setup_resp->cells_to_activate[i].mnc_digit_length,
			&nRCGI.pLMN_Identity);
      NR_CELL_ID_TO_BIT_STRING(f1ap_setup_resp->cells_to_activate[i].nr_cellid, &nRCGI.nRCellIdentity);
      cells_to_be_activated_list_item.nRCGI = nRCGI;
355

356 357 358
      /* optional */
      /* - nRPCI */
      if (1) {
359 360
        cells_to_be_activated_list_item.nRPCI = (F1AP_NRPCI_t *)calloc(1, sizeof(F1AP_NRPCI_t));
        *cells_to_be_activated_list_item.nRPCI = f1ap_setup_resp->cells_to_activate[i].nrpci;  // int 0..1007
361
      }
362

363 364 365
      /* optional */
      /* - gNB-CU System Information */
      if (1) {
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
      /* 3.1.2 gNB-CUSystem Information */
      F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *cells_to_be_activated_list_itemExtIEs;
      cells_to_be_activated_list_itemExtIEs = (F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Activated_List_ItemExtIEs_t));
      cells_to_be_activated_list_itemExtIEs->id                     = F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation;
      cells_to_be_activated_list_itemExtIEs->criticality            = F1AP_Criticality_reject;
      cells_to_be_activated_list_itemExtIEs->extensionValue.present = F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation;

      F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation = (F1AP_GNB_CUSystemInformation_t *)calloc(1, sizeof(F1AP_GNB_CUSystemInformation_t));
      //LOG_I(F1AP, "%s() SI %d size %d: ", __func__, i, f1ap_setup_resp->SI_container_length[i][0]);
      //for (int n = 0; n < f1ap_setup_resp->SI_container_length[i][0]; n++)
      //  printf("%02x ", f1ap_setup_resp->SI_container[i][0][n]);
          //printf("\n");

          // for (int sIBtype=2;sIBtype<33;sIBtype++) { //21 ? 33 ?
      for (int sIBtype=2;sIBtype<21;sIBtype++) {
        if (f1ap_setup_resp->cells_to_activate[i].SI_container[sIBtype]!=NULL) {
          AssertFatal(sIBtype < 6 || sIBtype == 9, "Illegal SI type %d\n",sIBtype);
          F1AP_SibtypetobeupdatedListItem_t *sib_item = calloc(1,sizeof(*sib_item));
          memset((void*)sib_item,0,sizeof(*sib_item));
          sib_item->sIBtype = sIBtype;
          OCTET_STRING_fromBuf(&sib_item->sIBmessage,
             (const char*)f1ap_setup_resp->cells_to_activate[i].SI_container[sIBtype],
             f1ap_setup_resp->cells_to_activate[i].SI_container_length[sIBtype]);

rmagueta's avatar
rmagueta committed
390
          LOG_D(F1AP, "f1ap_setup_resp->SI_container_length[%d][%d] = %d \n", i,sIBtype,f1ap_setup_resp->cells_to_activate[i].SI_container_length[sIBtype]);
391 392 393 394 395 396 397 398 399 400 401 402 403
          ASN_SEQUENCE_ADD(&gNB_CUSystemInformation->sibtypetobeupdatedlist.list,sib_item);
        }
      }
      cells_to_be_activated_list_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation = *gNB_CUSystemInformation;

      F1AP_ProtocolExtensionContainer_154P112_t p_154P112_t;
      memset((void *)&p_154P112_t, 0, sizeof(F1AP_ProtocolExtensionContainer_154P112_t));

      ASN_SEQUENCE_ADD(&p_154P112_t.list, cells_to_be_activated_list_itemExtIEs);
      cells_to_be_activated_list_item.iE_Extensions = (struct F1AP_ProtocolExtensionContainer*)&p_154P112_t;

      free(gNB_CUSystemInformation);
      gNB_CUSystemInformation = NULL;
Xue Song's avatar
Xue Song committed
404
      }
405 406
      /* ADD */
      cells_to_be_activated_list_item_ies->value.choice.Cells_to_be_Activated_List_Item = cells_to_be_activated_list_item;
407
      ASN_SEQUENCE_ADD(&ie->value.choice.Cells_to_be_Activated_List.list, cells_to_be_activated_list_item_ies);
408 409
    }
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
410 411 412 413
  }

  /* encode */
  if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
Xue Song's avatar
Xue Song committed
414
    LOG_E(F1AP, "Failed to encode F1 setup response\n");
415
    return -1;
416 417 418 419
  }

  cu_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data_from_du->assoc_id, buffer, len, 0);

420
  return 0;
421 422
}

423
int CU_send_F1_SETUP_FAILURE(instance_t instance) {
424
  LOG_D(F1AP, "CU_send_F1_SETUP_FAILURE\n");
425 426 427 428
  
  module_id_t enb_mod_idP;
  module_id_t cu_mod_idP;

429 430 431
  // This should be fixed
  enb_mod_idP = (module_id_t)0;
  cu_mod_idP  = (module_id_t)0;
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 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

  F1AP_F1AP_PDU_t           pdu;
  F1AP_F1SetupFailure_t    *out;
  F1AP_F1SetupFailureIEs_t *ie;

  uint8_t  *buffer;
  uint32_t  len;

  /* Create */
  /* 0. Message Type */
  memset(&pdu, 0, sizeof(pdu));
  pdu.present = F1AP_F1AP_PDU_PR_unsuccessfulOutcome;
  pdu.choice.unsuccessfulOutcome = (F1AP_UnsuccessfulOutcome_t *)calloc(1, sizeof(F1AP_UnsuccessfulOutcome_t));
  pdu.choice.unsuccessfulOutcome->procedureCode = F1AP_ProcedureCode_id_F1Setup;
  pdu.choice.unsuccessfulOutcome->criticality   = F1AP_Criticality_reject;
  pdu.choice.unsuccessfulOutcome->value.present = F1AP_UnsuccessfulOutcome__value_PR_F1SetupFailure;
  out = &pdu.choice.unsuccessfulOutcome->value.choice.F1SetupFailure;

  /* mandatory */
  /* c1. Transaction ID (integer value)*/
  ie = (F1AP_F1SetupFailureIEs_t *)calloc(1, sizeof(F1AP_F1SetupFailureIEs_t));
  ie->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
  ie->criticality               = F1AP_Criticality_reject;
  ie->value.present             = F1AP_F1SetupFailureIEs__value_PR_TransactionID;
  ie->value.choice.TransactionID = F1AP_get_next_transaction_identifier(enb_mod_idP, cu_mod_idP);
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

  /* mandatory */
  /* c2. Cause */
  ie = (F1AP_F1SetupFailureIEs_t *)calloc(1, sizeof(F1AP_F1SetupFailureIEs_t));
  ie->id                        = F1AP_ProtocolIE_ID_id_Cause;
  ie->criticality               = F1AP_Criticality_ignore;
  ie->value.present             = F1AP_F1SetupFailureIEs__value_PR_Cause;
  ie->value.choice.Cause.present = F1AP_Cause_PR_radioNetwork;
  ie->value.choice.Cause.choice.radioNetwork = F1AP_CauseRadioNetwork_unspecified;
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

  /* optional */
  /* c3. TimeToWait */
  if (0) {
    ie = (F1AP_F1SetupFailureIEs_t *)calloc(1, sizeof(F1AP_F1SetupFailureIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_TimeToWait;
    ie->criticality               = F1AP_Criticality_ignore;
    ie->value.present             = F1AP_F1SetupFailureIEs__value_PR_TimeToWait;
    ie->value.choice.TimeToWait = F1AP_TimeToWait_v10s;
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
  }

  /* optional */
  /* c4. CriticalityDiagnostics*/
  if (0) {
    ie = (F1AP_F1SetupFailureIEs_t *)calloc(1, sizeof(F1AP_F1SetupFailureIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
    ie->criticality               = F1AP_Criticality_ignore;
    ie->value.present             = F1AP_F1SetupFailureIEs__value_PR_CriticalityDiagnostics;
    ie->value.choice.CriticalityDiagnostics.procedureCode = (F1AP_ProcedureCode_t *)calloc(1, sizeof(F1AP_ProcedureCode_t));
    *ie->value.choice.CriticalityDiagnostics.procedureCode = F1AP_ProcedureCode_id_UEContextSetup;
    ie->value.choice.CriticalityDiagnostics.triggeringMessage = (F1AP_TriggeringMessage_t *)calloc(1, sizeof(F1AP_TriggeringMessage_t));
    *ie->value.choice.CriticalityDiagnostics.triggeringMessage = F1AP_TriggeringMessage_initiating_message;
    ie->value.choice.CriticalityDiagnostics.procedureCriticality = (F1AP_Criticality_t *)calloc(1, sizeof(F1AP_Criticality_t));
    *ie->value.choice.CriticalityDiagnostics.procedureCriticality = F1AP_Criticality_reject;
    ie->value.choice.CriticalityDiagnostics.transactionID = (F1AP_TransactionID_t *)calloc(1, sizeof(F1AP_TransactionID_t));
    *ie->value.choice.CriticalityDiagnostics.transactionID = 0;
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
  }

  /* encode */
  if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
Xue Song's avatar
Xue Song committed
500
    LOG_E(F1AP, "Failed to encode F1 setup failure\n");
501
    return -1;
502 503 504
  }

  cu_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data_from_du->assoc_id, buffer, len, 0);
505 506

  return 0;
507 508 509 510 511 512 513 514
}



/*
    gNB-DU Configuration Update
*/

515 516 517 518
int CU_handle_gNB_DU_CONFIGURATION_UPDATE(instance_t instance,
                                           uint32_t assoc_id,
                                           uint32_t stream,
                                           F1AP_F1AP_PDU_t *pdu) {
519 520 521
  AssertFatal(1==0,"Not implemented yet\n");
}

522
int CU_send_gNB_DU_CONFIGURATION_FAILURE(instance_t instance,
523
                    F1AP_GNBDUConfigurationUpdateFailure_t *GNBDUConfigurationUpdateFailure) {
524 525 526
  AssertFatal(1==0,"Not implemented yet\n");
}

527
int CU_send_gNB_DU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
528
                    F1AP_GNBDUConfigurationUpdateAcknowledge_t *GNBDUConfigurationUpdateAcknowledge) {
529 530 531 532 533 534 535 536 537 538
  AssertFatal(1==0,"Not implemented yet\n");
}



/*
    gNB-CU Configuration Update
*/

//void CU_send_gNB_CU_CONFIGURATION_UPDATE(F1AP_GNBCUConfigurationUpdate_t *GNBCUConfigurationUpdate) {
539
int CU_send_gNB_CU_CONFIGURATION_UPDATE(instance_t instance, f1ap_gnb_cu_configuration_update_t *f1ap_gnb_cu_configuration_update) {
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
  F1AP_F1AP_PDU_t                    pdu;
  F1AP_GNBCUConfigurationUpdate_t    *out;
  F1AP_GNBCUConfigurationUpdateIEs_t *ie;

  uint8_t  *buffer;
  uint32_t  len;
  int       i = 0;


  /* Create */
  /* 0. Message Type */
  memset(&pdu, 0, sizeof(pdu));
  pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_gNBCUConfigurationUpdate;
555
  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_ignore;
556 557 558 559 560 561 562 563 564
  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_GNBCUConfigurationUpdate;
  out = &pdu.choice.initiatingMessage->value.choice.GNBCUConfigurationUpdate;

  /* mandatory */
  /* c1. Transaction ID (integer value) */
  ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
  ie->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
  ie->criticality               = F1AP_Criticality_reject;
  ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_TransactionID;
565
  ie->value.choice.TransactionID = F1AP_get_next_transaction_identifier(instance, 0);
566 567 568 569
  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);



570
  // mandatory
571
  // c2. Cells_to_be_Activated_List
572 573 574 575 576
  if (f1ap_gnb_cu_configuration_update->num_cells_to_activate > 0) {
    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List;
    ie->criticality               = F1AP_Criticality_reject;
    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Activated_List;
577

578
    for (i=0; i<f1ap_gnb_cu_configuration_update->num_cells_to_activate; i++) {
579

rmagueta's avatar
rmagueta committed
580
      LOG_D(F1AP, "[c2] (cell %d) mcc = %d, mnc = %d, mnc_digit_length = %d, nr_cellid = %lu\n",
rmagueta's avatar
rmagueta committed
581 582 583 584 585
            i,
            f1ap_gnb_cu_configuration_update->cells_to_activate[i].mcc,
            f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc,
            f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc_digit_length,
            f1ap_gnb_cu_configuration_update->cells_to_activate[i].nr_cellid);
586

587 588 589 590 591
      F1AP_Cells_to_be_Activated_List_ItemIEs_t *cells_to_be_activated_list_item_ies;
      cells_to_be_activated_list_item_ies = (F1AP_Cells_to_be_Activated_List_ItemIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Activated_List_ItemIEs_t));
      cells_to_be_activated_list_item_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
      cells_to_be_activated_list_item_ies->criticality = F1AP_Criticality_reject;
      cells_to_be_activated_list_item_ies->value.present = F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item;
592

593 594 595
      // 2.1 cells to be Activated list item
      F1AP_Cells_to_be_Activated_List_Item_t cells_to_be_activated_list_item;
      memset((void *)&cells_to_be_activated_list_item, 0, sizeof(F1AP_Cells_to_be_Activated_List_Item_t));
596 597

      // - nRCGI
598 599
      F1AP_NRCGI_t nRCGI;
      memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
600 601
      MCC_MNC_TO_PLMNID(f1ap_gnb_cu_configuration_update->cells_to_activate[i].mcc,
			f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc,
602 603
			f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc_digit_length,
			&nRCGI.pLMN_Identity);
604
      NR_CELL_ID_TO_BIT_STRING(f1ap_gnb_cu_configuration_update->cells_to_activate[i].nr_cellid,
605 606
			       &nRCGI.nRCellIdentity);
      cells_to_be_activated_list_item.nRCGI = nRCGI;
607

608
      if(RC.nrrrc) {
609

610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
        // optional
        // -nRPCI
        cells_to_be_activated_list_item.nRPCI = (F1AP_NRPCI_t *)calloc(1, sizeof(F1AP_NRPCI_t));
        *cells_to_be_activated_list_item.nRPCI = f1ap_gnb_cu_configuration_update->cells_to_activate[i].nrpci;  // int 0..1007

        // optional
        // 3.1.2 gNB-CUSystem Information
        F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *cells_to_be_activated_list_itemExtIEs;
        cells_to_be_activated_list_itemExtIEs = (F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Activated_List_ItemExtIEs_t));
        cells_to_be_activated_list_itemExtIEs->id                     = F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation;
        cells_to_be_activated_list_itemExtIEs->criticality            = F1AP_Criticality_reject;
        cells_to_be_activated_list_itemExtIEs->extensionValue.present = F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation;

        if (f1ap_gnb_cu_configuration_update->cells_to_activate[i].num_SI > 0) {
          F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation = (F1AP_GNB_CUSystemInformation_t *)calloc(1, sizeof(F1AP_GNB_CUSystemInformation_t));
          //LOG_I(F1AP, "%s() SI %d size %d: ", __func__, i, f1ap_setup_resp->SI_container_length[i][0]);
          //for (int n = 0; n < f1ap_setup_resp->SI_container_length[i][0]; n++)
          //  printf("%02x ", f1ap_setup_resp->SI_container[i][0][n]);
          //printf("\n");
629

630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
          // for (int sIBtype=2;sIBtype<33;sIBtype++) { //21 ? 33 ?
          for (int sIBtype=2;sIBtype<21;sIBtype++) {
            if (f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container[sIBtype]!=NULL) {
              AssertFatal(sIBtype < 6 || sIBtype == 9, "Illegal SI type %d\n",sIBtype);
              F1AP_SibtypetobeupdatedListItem_t *sib_item = calloc(1,sizeof(*sib_item));
              memset((void*)sib_item,0,sizeof(*sib_item));
              sib_item->sIBtype = sIBtype;
              OCTET_STRING_fromBuf(&sib_item->sIBmessage,
                                   (const char*)f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container[sIBtype],
                                   f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container_length[sIBtype]);

              LOG_D(F1AP, "f1ap_setup_resp->SI_container_length[%d][%d] = %d \n", i,sIBtype,f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container_length[sIBtype]);
              ASN_SEQUENCE_ADD(&gNB_CUSystemInformation->sibtypetobeupdatedlist.list,sib_item);
            }
          }
          cells_to_be_activated_list_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation = *gNB_CUSystemInformation;


          F1AP_ProtocolExtensionContainer_154P112_t p_154P112_t;
          memset((void *)&p_154P112_t, 0, sizeof(F1AP_ProtocolExtensionContainer_154P112_t));

          ASN_SEQUENCE_ADD(&p_154P112_t.list,
                           cells_to_be_activated_list_itemExtIEs);
          cells_to_be_activated_list_item.iE_Extensions = (struct F1AP_ProtocolExtensionContainer*)&p_154P112_t;

          free(gNB_CUSystemInformation);
          gNB_CUSystemInformation = NULL;
        }
658
      }
659 660 661 662 663

      // ADD
      cells_to_be_activated_list_item_ies->value.choice.Cells_to_be_Activated_List_Item = cells_to_be_activated_list_item;
      ASN_SEQUENCE_ADD(&ie->value.choice.Cells_to_be_Activated_List.list,
		       cells_to_be_activated_list_item_ies);
664
    }
665
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
666

667
  }
668 669


670
  if(!RC.nrrrc) {
671

672 673 674 675 676 677
    /* mandatory */
    /* c3. Cells_to_be_Deactivated_List */
    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Deactivated_List;
    ie->criticality               = F1AP_Criticality_reject;
    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Deactivated_List;
678

679 680 681
    for (i=0;
         i<1;
         i++) {
682

683 684 685 686 687
      F1AP_Cells_to_be_Deactivated_List_ItemIEs_t *cells_to_be_deactivated_list_item_ies;
      cells_to_be_deactivated_list_item_ies = (F1AP_Cells_to_be_Deactivated_List_ItemIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Deactivated_List_ItemIEs_t));
      cells_to_be_deactivated_list_item_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
      cells_to_be_deactivated_list_item_ies->criticality = F1AP_Criticality_reject;
      cells_to_be_deactivated_list_item_ies->value.present = F1AP_Cells_to_be_Deactivated_List_ItemIEs__value_PR_Cells_to_be_Deactivated_List_Item;
688

689 690 691
      // 3.1 cells to be Deactivated list item
      F1AP_Cells_to_be_Deactivated_List_Item_t cells_to_be_deactivated_list_item;
      memset((void *)&cells_to_be_deactivated_list_item, 0, sizeof(F1AP_Cells_to_be_Deactivated_List_Item_t));
692 693


694 695 696 697 698 699 700 701 702 703 704 705 706 707
      F1AP_NRCGI_t nRCGI;
      memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
      MCC_MNC_TO_PLMNID(f1ap_gnb_cu_configuration_update->cells_to_activate[i].mcc,
                        f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc,
                        f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc_digit_length,
                        &nRCGI.pLMN_Identity);
      NR_CELL_ID_TO_BIT_STRING(f1ap_gnb_cu_configuration_update->cells_to_activate[i].nr_cellid, &nRCGI.nRCellIdentity);
      cells_to_be_deactivated_list_item.nRCGI = nRCGI;

      cells_to_be_deactivated_list_item_ies->value.choice.Cells_to_be_Deactivated_List_Item = cells_to_be_deactivated_list_item;
      ASN_SEQUENCE_ADD(&ie->value.choice.Cells_to_be_Deactivated_List.list,
                       cells_to_be_deactivated_list_item_ies);
    }
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
708 709


710 711 712 713 714 715
    /* mandatory */
    /* c4. GNB_CU_TNL_Association_To_Add_List */
    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Add_List;
    ie->criticality               = F1AP_Criticality_reject;
    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_GNB_CU_TNL_Association_To_Add_List;
716

717 718 719
    for (i=0;
         i<1;
         i++) {
720

721 722 723 724 725
      F1AP_GNB_CU_TNL_Association_To_Add_ItemIEs_t *gnb_cu_tnl_association_to_add_item_ies;
      gnb_cu_tnl_association_to_add_item_ies = (F1AP_GNB_CU_TNL_Association_To_Add_ItemIEs_t *)calloc(1, sizeof(F1AP_GNB_CU_TNL_Association_To_Add_ItemIEs_t));
      gnb_cu_tnl_association_to_add_item_ies->id = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Add_Item;
      gnb_cu_tnl_association_to_add_item_ies->criticality = F1AP_Criticality_reject;
      gnb_cu_tnl_association_to_add_item_ies->value.present = F1AP_GNB_CU_TNL_Association_To_Add_ItemIEs__value_PR_GNB_CU_TNL_Association_To_Add_Item;
726

727 728 729
      // 4.1 GNB_CU_TNL_Association_To_Add_Item
      F1AP_GNB_CU_TNL_Association_To_Add_Item_t gnb_cu_tnl_association_to_add_item;
      memset((void *)&gnb_cu_tnl_association_to_add_item, 0, sizeof(F1AP_GNB_CU_TNL_Association_To_Add_Item_t));
730

731

732 733 734 735 736
      // 4.1.1 tNLAssociationTransportLayerAddress
      F1AP_CP_TransportLayerAddress_t transportLayerAddress;
      memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
      transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address;
      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address);
737

738 739 740 741
      // memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
      // transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address_and_port;
      // transportLayerAddress.choice.endpoint_IP_address_and_port = (F1AP_Endpoint_IP_address_and_port_t *)calloc(1, sizeof(F1AP_Endpoint_IP_address_and_port_t));
      // TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address_and_port.endpoint_IP_address);
742

743
      gnb_cu_tnl_association_to_add_item.tNLAssociationTransportLayerAddress = transportLayerAddress;
744

745 746
      // 4.1.2 tNLAssociationUsage
      gnb_cu_tnl_association_to_add_item.tNLAssociationUsage = F1AP_TNLAssociationUsage_non_ue;
747

748 749


750 751 752 753 754
      gnb_cu_tnl_association_to_add_item_ies->value.choice.GNB_CU_TNL_Association_To_Add_Item = gnb_cu_tnl_association_to_add_item;
      ASN_SEQUENCE_ADD(&ie->value.choice.GNB_CU_TNL_Association_To_Add_List.list,
                       gnb_cu_tnl_association_to_add_item_ies);
    }
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
755 756


757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
    /* mandatory */
    /* c5. GNB_CU_TNL_Association_To_Remove_List */
    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Remove_List;
    ie->criticality               = F1AP_Criticality_reject;
    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_GNB_CU_TNL_Association_To_Remove_List;
    for (i=0;
         i<1;
         i++) {

      F1AP_GNB_CU_TNL_Association_To_Remove_ItemIEs_t *gnb_cu_tnl_association_to_remove_item_ies;
      gnb_cu_tnl_association_to_remove_item_ies = (F1AP_GNB_CU_TNL_Association_To_Remove_ItemIEs_t *)calloc(1, sizeof(F1AP_GNB_CU_TNL_Association_To_Remove_ItemIEs_t));
      gnb_cu_tnl_association_to_remove_item_ies->id = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Remove_Item;
      gnb_cu_tnl_association_to_remove_item_ies->criticality = F1AP_Criticality_reject;
      gnb_cu_tnl_association_to_remove_item_ies->value.present = F1AP_GNB_CU_TNL_Association_To_Remove_ItemIEs__value_PR_GNB_CU_TNL_Association_To_Remove_Item;
772

773 774 775
      // 4.1 GNB_CU_TNL_Association_To_Remove_Item
      F1AP_GNB_CU_TNL_Association_To_Remove_Item_t gnb_cu_tnl_association_to_remove_item;
      memset((void *)&gnb_cu_tnl_association_to_remove_item, 0, sizeof(F1AP_GNB_CU_TNL_Association_To_Remove_Item_t));
776 777


778 779 780 781 782
      // 4.1.1 tNLAssociationTransportLayerAddress
      F1AP_CP_TransportLayerAddress_t transportLayerAddress;
      memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
      transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address;
      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address);
783

784 785 786 787
      // memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
      // transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address_and_port;
      // transportLayerAddress.choice.endpoint_IP_address_and_port = (F1AP_Endpoint_IP_address_and_port_t *)calloc(1, sizeof(F1AP_Endpoint_IP_address_and_port_t));
      // TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address_and_port.endpoint_IP_address);
788

789 790 791 792 793 794 795 796 797
      gnb_cu_tnl_association_to_remove_item.tNLAssociationTransportLayerAddress = transportLayerAddress;



      gnb_cu_tnl_association_to_remove_item_ies->value.choice.GNB_CU_TNL_Association_To_Remove_Item = gnb_cu_tnl_association_to_remove_item;
      ASN_SEQUENCE_ADD(&ie->value.choice.GNB_CU_TNL_Association_To_Remove_List.list,
                       gnb_cu_tnl_association_to_remove_item_ies);
    }
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
798

799

800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913
    /* mandatory */
    /* c6. GNB_CU_TNL_Association_To_Update_List */
    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Update_List;
    ie->criticality               = F1AP_Criticality_reject;
    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_GNB_CU_TNL_Association_To_Update_List;
    for (i=0;
         i<1;
         i++) {

      F1AP_GNB_CU_TNL_Association_To_Update_ItemIEs_t *gnb_cu_tnl_association_to_update_item_ies;
      gnb_cu_tnl_association_to_update_item_ies = (F1AP_GNB_CU_TNL_Association_To_Update_ItemIEs_t *)calloc(1, sizeof(F1AP_GNB_CU_TNL_Association_To_Update_ItemIEs_t));
      gnb_cu_tnl_association_to_update_item_ies->id = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Update_Item;
      gnb_cu_tnl_association_to_update_item_ies->criticality = F1AP_Criticality_reject;
      gnb_cu_tnl_association_to_update_item_ies->value.present = F1AP_GNB_CU_TNL_Association_To_Update_ItemIEs__value_PR_GNB_CU_TNL_Association_To_Update_Item;

      // 4.1 GNB_CU_TNL_Association_To_Update_Item
      F1AP_GNB_CU_TNL_Association_To_Update_Item_t gnb_cu_tnl_association_to_update_item;
      memset((void *)&gnb_cu_tnl_association_to_update_item, 0, sizeof(F1AP_GNB_CU_TNL_Association_To_Update_Item_t));


      // 4.1.1 tNLAssociationTransportLayerAddress
      F1AP_CP_TransportLayerAddress_t transportLayerAddress;
      memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
      transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address;
      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address);

      // memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
      // transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address_and_port;
      // transportLayerAddress.choice.endpoint_IP_address_and_port = (F1AP_Endpoint_IP_address_and_port_t *)calloc(1, sizeof(F1AP_Endpoint_IP_address_and_port_t));
      // TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address_and_port.endpoint_IP_address);

      gnb_cu_tnl_association_to_update_item.tNLAssociationTransportLayerAddress = transportLayerAddress;


      // 4.1.2 tNLAssociationUsage
      if (1) {
        gnb_cu_tnl_association_to_update_item.tNLAssociationUsage = (F1AP_TNLAssociationUsage_t *)calloc(1, sizeof(F1AP_TNLAssociationUsage_t));
        *gnb_cu_tnl_association_to_update_item.tNLAssociationUsage = F1AP_TNLAssociationUsage_non_ue;
      }


      gnb_cu_tnl_association_to_update_item_ies->value.choice.GNB_CU_TNL_Association_To_Update_Item = gnb_cu_tnl_association_to_update_item;
      ASN_SEQUENCE_ADD(&ie->value.choice.GNB_CU_TNL_Association_To_Update_List.list,
                       gnb_cu_tnl_association_to_update_item_ies);
    }
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);


    /* mandatory */
    /* c7. Cells_to_be_Barred_List */
    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Barred_List;
    ie->criticality               = F1AP_Criticality_reject;
    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Barred_List;
    for (i=0;
         i<1;
         i++) {

      F1AP_Cells_to_be_Barred_ItemIEs_t *cells_to_be_barred_item_ies;
      cells_to_be_barred_item_ies = (F1AP_Cells_to_be_Barred_ItemIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Barred_ItemIEs_t));
      cells_to_be_barred_item_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
      cells_to_be_barred_item_ies->criticality = F1AP_Criticality_reject;
      cells_to_be_barred_item_ies->value.present = F1AP_Cells_to_be_Barred_ItemIEs__value_PR_Cells_to_be_Barred_Item;

      // 7.1 cells to be Deactivated list item
      F1AP_Cells_to_be_Barred_Item_t cells_to_be_barred_item;
      memset((void *)&cells_to_be_barred_item, 0, sizeof(F1AP_Cells_to_be_Barred_Item_t));

      // - nRCGI
      F1AP_NRCGI_t nRCGI;
      memset(&nRCGI,0,sizeof(F1AP_NRCGI_t));
      MCC_MNC_TO_PLMNID(f1ap_gnb_cu_configuration_update->cells_to_activate[i].mcc,
                        f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc,
                        f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc_digit_length,
                        &nRCGI.pLMN_Identity);
      NR_CELL_ID_TO_BIT_STRING(f1ap_gnb_cu_configuration_update->cells_to_activate[i].nr_cellid, &nRCGI.nRCellIdentity);
      cells_to_be_barred_item.nRCGI = nRCGI;

      // 7.2 cellBarred
      cells_to_be_barred_item.cellBarred = F1AP_CellBarred_not_barred;

      cells_to_be_barred_item_ies->value.choice.Cells_to_be_Barred_Item = cells_to_be_barred_item;
      ASN_SEQUENCE_ADD(&ie->value.choice.Cells_to_be_Barred_List.list,
                       cells_to_be_barred_item_ies);
    }
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);


    /* mandatory */
    /* c8. Protected_EUTRA_Resources_List */
    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
    ie->id                        = F1AP_ProtocolIE_ID_id_Protected_EUTRA_Resources_List;
    ie->criticality               = F1AP_Criticality_reject;
    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Protected_EUTRA_Resources_List;

    for (i=0;
         i<1;
         i++) {


      F1AP_Protected_EUTRA_Resources_ItemIEs_t *protected_eutra_resources_item_ies;

      // 8.1 SpectrumSharingGroupID
      protected_eutra_resources_item_ies = (F1AP_Protected_EUTRA_Resources_ItemIEs_t *)calloc(1, sizeof(F1AP_Protected_EUTRA_Resources_ItemIEs_t));
      protected_eutra_resources_item_ies->id = F1AP_ProtocolIE_ID_id_Protected_EUTRA_Resources_List;
      protected_eutra_resources_item_ies->criticality = F1AP_Criticality_reject;
      protected_eutra_resources_item_ies->value.present = F1AP_Protected_EUTRA_Resources_ItemIEs__value_PR_Protected_EUTRA_Resources_Item;
      ((F1AP_Protected_EUTRA_Resources_Item_t*)&protected_eutra_resources_item_ies->value.choice.Protected_EUTRA_Resources_Item)->spectrumSharingGroupID = 123L;
      memset(&protected_eutra_resources_item_ies->value.choice.Protected_EUTRA_Resources_Item,0,
             sizeof(F1AP_Protected_EUTRA_Resources_Item_t));
      ASN_SEQUENCE_ADD(&ie->value.choice.Protected_EUTRA_Resources_List.list, protected_eutra_resources_item_ies);

      /*
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
       F1AP_Served_EUTRA_Cells_Information_t served_eutra_cells_information;
       memset((void *)&served_eutra_cells_information, 0, sizeof(F1AP_Served_EUTRA_Cells_Information_t));

       F1AP_EUTRA_Mode_Info_t eUTRA_Mode_Info;
       memset((void *)&eUTRA_Mode_Info, 0, sizeof(F1AP_EUTRA_Mode_Info_t));

       // eUTRAFDD
       eUTRA_Mode_Info.present = F1AP_EUTRA_Mode_Info_PR_eUTRAFDD;
       F1AP_EUTRA_FDD_Info_t *eutra_fdd_info;
       eutra_fdd_info = (F1AP_EUTRA_FDD_Info_t *)calloc(1, sizeof(F1AP_EUTRA_FDD_Info_t));
       eutra_fdd_info->uL_offsetToPointA = 123L;
       eutra_fdd_info->dL_offsetToPointA = 456L;
       eUTRA_Mode_Info.choice.eUTRAFDD = eutra_fdd_info;

       // eUTRATDD
       // eUTRA_Mode_Info.present = F1AP_EUTRA_Mode_Info_PR_eUTRATDD;
       // F1AP_EUTRA_TDD_Info_t *eutra_tdd_info;
       // eutra_tdd_info = (F1AP_EUTRA_TDD_Info_t *)calloc(1, sizeof(F1AP_EUTRA_TDD_Info_t));
       // eutra_tdd_info->uL_offsetToPointA = 123L;
       // eutra_tdd_info->dL_offsetToPointA = 456L;
       // eUTRA_Mode_Info.choice.eUTRATDD = eutra_tdd_info;

       served_eutra_cells_information.eUTRA_Mode_Info = eUTRA_Mode_Info;

       OCTET_STRING_fromBuf(&served_eutra_cells_information.protectedEUTRAResourceIndication, "asdsa1d32sa1d31asd31as",
                       strlen("asdsa1d32sa1d31asd31as"));

       ASN_SEQUENCE_ADD(&protected_eutra_resources_item_ies->value.choice.ListofEUTRACellsinGNBDUCoordination.list, &served_eutra_cells_information);

       ASN_SEQUENCE_ADD(&ie->value.choice.Protected_EUTRA_Resources_List.list, protected_eutra_resources_item_ies);
944 945 946
      */
    }
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
947 948 949 950 951
  }


  /* encode */
  if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
Xue Song's avatar
Xue Song committed
952
    LOG_E(F1AP, "Failed to encode F1 gNB-CU CONFIGURATION UPDATE\n");
953
    return -1;
954
  }
955

rmagueta's avatar
rmagueta committed
956 957 958 959
  LOG_D(F1AP, "F1AP gNB-CU CONFIGURATION UPDATE\n");
  //for (int i=0;i<len;i++) printf("%02x ",buffer[i]);
  //printf("\n");

960
  cu_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data_from_du->assoc_id, buffer, len, 0);
961
  return 0;
962 963
}

964 965 966 967
int CU_handle_gNB_CU_CONFIGURATION_UPDATE_FAILURE(instance_t instance,
                                                   uint32_t assoc_id,
                                                   uint32_t stream,
                                                   F1AP_F1AP_PDU_t *pdu) {
968 969 970
  AssertFatal(1==0,"Not implemented yet\n");
}

971 972 973 974
int CU_handle_gNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
                                                       uint32_t assoc_id,
                                                       uint32_t stream,
                                                       F1AP_F1AP_PDU_t *pdu) {
rmagueta's avatar
rmagueta committed
975
  LOG_D(F1AP,"Cell Configuration ok (assoc_id %d)\n",assoc_id);
976
  return(0);
977
}
978

979

980 981 982 983
int CU_handle_gNB_DU_RESOURCE_COORDINATION_REQUEST(instance_t instance,
                                                    uint32_t assoc_id,
                                                    uint32_t stream,
                                                    F1AP_F1AP_PDU_t *pdu) {
984 985 986
  AssertFatal(0, "Not implemented yet\n");
}

987
int CU_send_gNB_DU_RESOURCE_COORDINATION_RESPONSE(instance_t instance,
988 989 990
                    F1AP_GNBDUResourceCoordinationResponse_t *GNBDUResourceCoordinationResponse) {
  AssertFatal(0, "Not implemented yet\n");
}