ngap_gNB_handlers.c 86.1 KB
Newer Older
zhenghuangkun's avatar
zhenghuangkun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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 ngap_gNB_handlers.c
 * \brief ngap messages handlers for gNB part
zhenghuangkun's avatar
zhenghuangkun committed
24 25 26
 * \author Yoshio INOUE, Masayuki HARADA
 * \email yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com (yoshio.inoue%40fujitsu.com%2cmasayuki.harada%40fujitsu.com)
 * \date 2020
zhenghuangkun's avatar
zhenghuangkun committed
27 28
 * \version 0.1
 */
zhenghuangkun's avatar
zhenghuangkun committed
29
 
zhenghuangkun's avatar
zhenghuangkun committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#include <stdint.h>

#include "intertask_interface.h"

#include "asn1_conversions.h"

#include "ngap_common.h"
// #include "ngap_gNB.h"
#include "ngap_gNB_defs.h"
#include "ngap_gNB_handlers.h"
#include "ngap_gNB_decoder.h"

#include "ngap_gNB_ue_context.h"
#include "ngap_gNB_trace.h"
#include "ngap_gNB_nas_procedures.h"
#include "ngap_gNB_management_procedures.h"

#include "ngap_gNB_default_values.h"

#include "assertions.h"
#include "conversions.h"
#include "msc.h"
52
#include "NGAP_NonDynamic5QIDescriptor.h"
zhenghuangkun's avatar
zhenghuangkun committed
53 54

static
zhenghuangkun's avatar
zhenghuangkun committed
55
int ngap_gNB_handle_ng_setup_response(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
56 57 58
                                      uint32_t               stream,
                                      NGAP_NGAP_PDU_t       *pdu);
static
zhenghuangkun's avatar
zhenghuangkun committed
59
int ngap_gNB_handle_ng_setup_failure(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
                                     uint32_t               stream,
                                     NGAP_NGAP_PDU_t       *pdu);

static
int ngap_gNB_handle_error_indication(uint32_t               assoc_id,
                                     uint32_t               stream,
                                     NGAP_NGAP_PDU_t       *pdu);

static
int ngap_gNB_handle_initial_context_request(uint32_t               assoc_id,
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu);

static
int ngap_gNB_handle_ue_context_release_command(uint32_t               assoc_id,
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu);

static
zhenghuangkun's avatar
zhenghuangkun committed
79
int ngap_gNB_handle_pdusession_setup_request(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
80 81 82 83 84 85 86 87 88
                                        uint32_t               stream,
                                        NGAP_NGAP_PDU_t       *pdu);

static
int ngap_gNB_handle_paging(uint32_t               assoc_id,
                           uint32_t               stream,
                           NGAP_NGAP_PDU_t       *pdu);

static
zhenghuangkun's avatar
zhenghuangkun committed
89
int ngap_gNB_handle_pdusession_modify_request(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
90 91 92 93
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu);

static
zhenghuangkun's avatar
zhenghuangkun committed
94
int ngap_gNB_handle_pdusession_release_command(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
95 96 97 98
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu);

static
zhenghuangkun's avatar
zhenghuangkun committed
99
int ngap_gNB_handle_ng_path_switch_request_ack(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
100 101 102 103
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu);

static
zhenghuangkun's avatar
zhenghuangkun committed
104
int ngap_gNB_handle_ng_path_switch_request_failure(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
105 106 107 108
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu);

static
zhenghuangkun's avatar
zhenghuangkun committed
109
int ngap_gNB_handle_ng_ENDC_pdusession_modification_confirm(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
110 111 112 113
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu);

/* Handlers matrix. Only gNB related procedure present here */
heshanyun's avatar
heshanyun committed
114
ngap_message_decoded_callback ngap_messages_callback[][3] = {
zhenghuangkun's avatar
zhenghuangkun committed
115 116 117 118 119 120 121 122 123 124 125 126
  { 0, 0, 0 }, /* AMFConfigurationUpdate */
  { 0, 0, 0 }, /* AMFStatusIndication */
  { 0, 0, 0 }, /* CellTrafficTrace */
  { ngap_gNB_handle_deactivate_trace, 0, 0 }, /* DeactivateTrace */
  { ngap_gNB_handle_nas_downlink, 0, 0 }, /* DownlinkNASTransport */
  { 0, 0, 0 }, /* DownlinkNonUEAssociatedNRPPaTransport */
  { 0, 0, 0 }, /* DownlinkRANConfigurationTransfer */
  { 0, 0, 0 }, /* DownlinkRANStatusTransfer */
  { 0, 0, 0 }, /* DownlinkUEAssociatedNRPPaTransport */
  { ngap_gNB_handle_error_indication, 0, 0 }, /* ErrorIndication */
  { 0, 0, 0 }, /* HandoverCancel */
  { 0, 0, 0 }, /* HandoverNotification */
zhenghuangkun's avatar
zhenghuangkun committed
127 128 129
  { 0, 0, 0 }, /* HandoverPreparation */
  { 0, 0, 0 }, /* HandoverResourceAllocation */
  { ngap_gNB_handle_initial_context_request, 0, 0 }, /* InitialContextSetup */
zhenghuangkun's avatar
zhenghuangkun committed
130
  { 0, 0, 0 }, /* InitialUEMessage */
zhenghuangkun's avatar
zhenghuangkun committed
131 132 133
  { 0, 0, 0 }, /* LocationReportingControl */
  { 0, 0, 0 }, /* LocationReportingFailureIndication */
  { 0, 0, 0 }, /* LocationReport */
zhenghuangkun's avatar
zhenghuangkun committed
134 135 136
  { 0, 0, 0 }, /* NASNonDeliveryIndication */
  { 0, 0, 0 }, /* NGReset */
  { 0, ngap_gNB_handle_ng_setup_response, ngap_gNB_handle_ng_setup_failure }, /* NGSetup */
zhenghuangkun's avatar
zhenghuangkun committed
137 138
  { 0, 0, 0 }, /* OverloadStart */
  { 0, 0, 0 }, /* OverloadStop */
zhenghuangkun's avatar
zhenghuangkun committed
139 140 141 142 143 144 145
  { ngap_gNB_handle_paging, 0, 0 }, /* Paging */
  { 0, ngap_gNB_handle_ng_path_switch_request_ack, ngap_gNB_handle_ng_path_switch_request_failure }, /* PathSwitchRequest */
  { ngap_gNB_handle_pdusession_modify_request, 0, 0 }, /* PDUSessionResourceModify */
  { 0, ngap_gNB_handle_ng_ENDC_pdusession_modification_confirm, 0 }, /* PDUSessionResourceModifyIndication */
  { ngap_gNB_handle_pdusession_release_command, 0, 0 }, /* PDUSessionResourceRelease */
  { ngap_gNB_handle_pdusession_setup_request, 0, 0 }, /* PDUSessionResourceSetup */
  { 0, 0, 0 }, /* PDUSessionResourceNotify */
zhenghuangkun's avatar
zhenghuangkun committed
146
  { 0, 0, 0 }, /* PrivateMessage */
zhenghuangkun's avatar
zhenghuangkun committed
147 148
  { 0, 0, 0 }, /* PWSCancel */
  { 0, 0, 0 }, /* PWSFailureIndication */
zhenghuangkun's avatar
zhenghuangkun committed
149
  { 0, 0, 0 }, /* PWSRestartIndication */
zhenghuangkun's avatar
zhenghuangkun committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  { 0, 0, 0 }, /* RANConfigurationUpdate */
  { 0, 0, 0 }, /* RerouteNASRequest */
  { 0, 0, 0 }, /* RRCInactiveTransitionReport */
  { 0, 0, 0 }, /* TraceFailureIndication */
  { ngap_gNB_handle_trace_start, 0, 0 }, /* TraceStart */
  { 0, 0, 0 }, /* UEContextModification */
  { ngap_gNB_handle_ue_context_release_command, 0, 0 }, /* UEContextRelease */
  { 0, 0, 0 }, /* UEContextReleaseRequest */
  { 0, 0, 0 }, /* UERadioCapabilityCheck */
  { 0, 0, 0 }, /* UERadioCapabilityInfoIndication */
  { 0, 0, 0 }, /* UETNLABindingRelease */
  { 0, 0, 0 }, /* UplinkNASTransport */
  { 0, 0, 0 }, /* UplinkNonUEAssociatedNRPPaTransport */
  { 0, 0, 0 }, /* UplinkRANConfigurationTransfer */
  { 0, 0, 0 }, /* UplinkRANStatusTransfer */
  { 0, 0, 0 }, /* UplinkUEAssociatedNRPPaTransport */
  { 0, 0, 0 }, /* WriteReplaceWarning */
  { 0, 0, 0 }, /* SecondaryRATDataUsageReport */

zhenghuangkun's avatar
zhenghuangkun committed
169 170 171 172 173 174 175 176 177 178
};
char *ngap_direction2String(int ngap_dir) {
  static char *ngap_direction_String[] = {
    "", /* Nothing */
    "Originating message", /* originating message */
    "Successfull outcome", /* successfull outcome */
    "UnSuccessfull outcome", /* successfull outcome */
  };
  return(ngap_direction_String[ngap_dir]);
}
zhenghuangkun's avatar
zhenghuangkun committed
179
void ngap_handle_ng_setup_message(ngap_gNB_amf_data_t *amf_desc_p, int sctp_shutdown) {
zhenghuangkun's avatar
zhenghuangkun committed
180
  if (sctp_shutdown) {
zhenghuangkun's avatar
zhenghuangkun committed
181
    /* A previously connected AMF has been shutdown */
zhenghuangkun's avatar
zhenghuangkun committed
182

zhenghuangkun's avatar
zhenghuangkun committed
183 184 185
    /* TODO check if it was used by some gNB and send a message to inform these gNB if there is no more associated AMF */
    if (amf_desc_p->state == NGAP_GNB_STATE_CONNECTED) {
      amf_desc_p->state = NGAP_GNB_STATE_DISCONNECTED;
zhenghuangkun's avatar
zhenghuangkun committed
186

zhenghuangkun's avatar
zhenghuangkun committed
187 188 189
      if (amf_desc_p->ngap_gNB_instance->ngap_amf_associated_nb > 0) {
        /* Decrease associated AMF number */
        amf_desc_p->ngap_gNB_instance->ngap_amf_associated_nb --;
zhenghuangkun's avatar
zhenghuangkun committed
190 191
      }

zhenghuangkun's avatar
zhenghuangkun committed
192 193
      /* If there are no more associated AMF, inform gNB app */
      if (amf_desc_p->ngap_gNB_instance->ngap_amf_associated_nb == 0) {
zhenghuangkun's avatar
zhenghuangkun committed
194
        MessageDef                 *message_p;
195
        message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_DEREGISTERED_GNB_IND);
zhenghuangkun's avatar
zhenghuangkun committed
196 197
        NGAP_DEREGISTERED_GNB_IND(message_p).nb_amf = 0;
        itti_send_msg_to_task(TASK_GNB_APP, amf_desc_p->ngap_gNB_instance->instance, message_p);
zhenghuangkun's avatar
zhenghuangkun committed
198 199 200 201
      }
    }
  } else {
    /* Check that at least one setup message is pending */
zhenghuangkun's avatar
zhenghuangkun committed
202 203
    DevCheck(amf_desc_p->ngap_gNB_instance->ngap_amf_pending_nb > 0, amf_desc_p->ngap_gNB_instance->instance,
             amf_desc_p->ngap_gNB_instance->ngap_amf_pending_nb, 0);
zhenghuangkun's avatar
zhenghuangkun committed
204

zhenghuangkun's avatar
zhenghuangkun committed
205
    if (amf_desc_p->ngap_gNB_instance->ngap_amf_pending_nb > 0) {
zhenghuangkun's avatar
zhenghuangkun committed
206
      /* Decrease pending messages number */
zhenghuangkun's avatar
zhenghuangkun committed
207
      amf_desc_p->ngap_gNB_instance->ngap_amf_pending_nb --;
zhenghuangkun's avatar
zhenghuangkun committed
208 209 210
    }

    /* If there are no more pending messages, inform gNB app */
zhenghuangkun's avatar
zhenghuangkun committed
211
    if (amf_desc_p->ngap_gNB_instance->ngap_amf_pending_nb == 0) {
zhenghuangkun's avatar
zhenghuangkun committed
212
      MessageDef                 *message_p;
213
      message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_REGISTER_GNB_CNF);
zhenghuangkun's avatar
zhenghuangkun committed
214 215
      NGAP_REGISTER_GNB_CNF(message_p).nb_amf = amf_desc_p->ngap_gNB_instance->ngap_amf_associated_nb;
      itti_send_msg_to_task(TASK_GNB_APP, amf_desc_p->ngap_gNB_instance->instance, message_p);
zhenghuangkun's avatar
zhenghuangkun committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
    }
  }
}

int ngap_gNB_handle_message(uint32_t assoc_id, int32_t stream,
                            const uint8_t *const data, const uint32_t data_length) {
  NGAP_NGAP_PDU_t pdu;
  int ret;
  DevAssert(data != NULL);
  memset(&pdu, 0, sizeof(pdu));

  if (ngap_gNB_decode_pdu(&pdu, data, data_length) < 0) {
    NGAP_ERROR("Failed to decode PDU\n");
    return -1;
  }

  /* Checking procedure Code and direction of message */
233
  if (pdu.choice.initiatingMessage->procedureCode >= sizeof(ngap_messages_callback) / (3 * sizeof(
zhenghuangkun's avatar
zhenghuangkun committed
234 235 236
        ngap_message_decoded_callback))
      || (pdu.present > NGAP_NGAP_PDU_PR_unsuccessfulOutcome)) {
    NGAP_ERROR("[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n",
237
               assoc_id, pdu.choice.initiatingMessage->procedureCode, pdu.present);
zhenghuangkun's avatar
zhenghuangkun committed
238 239 240 241 242 243 244
    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, &pdu);
    return -1;
  }

  /* No handler present.
   * This can mean not implemented or no procedure for gNB (wrong direction).
   */
245
  if (ngap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1] == NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
246
    NGAP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n",
247
               assoc_id, pdu.choice.initiatingMessage->procedureCode,
zhenghuangkun's avatar
zhenghuangkun committed
248 249 250 251 252 253
               ngap_direction2String(pdu.present - 1));
    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, &pdu);
    return -1;
  }

  /* Calling the right handler */
254
  ret = (*ngap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1])
zhenghuangkun's avatar
zhenghuangkun committed
255 256 257 258 259 260
        (assoc_id, stream, &pdu);
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NGAP_NGAP_PDU, &pdu);
  return ret;
}

static
zhenghuangkun's avatar
zhenghuangkun committed
261
int ngap_gNB_handle_ng_setup_failure(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
262 263
                                     uint32_t               stream,
                                     NGAP_NGAP_PDU_t       *pdu) {
zhenghuangkun's avatar
zhenghuangkun committed
264 265 266
  NGAP_NGSetupFailure_t      *container;
  NGAP_NGSetupFailureIEs_t   *ie;
  ngap_gNB_amf_data_t        *amf_desc_p;
zhenghuangkun's avatar
zhenghuangkun committed
267
  DevAssert(pdu != NULL);
268
  container = &pdu->choice.unsuccessfulOutcome->value.choice.NGSetupFailure;
zhenghuangkun's avatar
zhenghuangkun committed
269 270 271 272 273 274 275

  /* S1 Setup Failure == Non UE-related procedure -> stream 0 */
  if (stream != 0) {
    NGAP_WARN("[SCTP %d] Received s1 setup failure on stream != 0 (%d)\n",
              assoc_id, stream);
  }

zhenghuangkun's avatar
zhenghuangkun committed
276
  if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
277
    NGAP_ERROR("[SCTP %d] Received S1 setup response for non existing "
zhenghuangkun's avatar
zhenghuangkun committed
278
               "AMF context\n", assoc_id);
zhenghuangkun's avatar
zhenghuangkun committed
279 280 281
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
282
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_NGSetupFailureIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
283 284 285 286
                             NGAP_ProtocolIE_ID_id_Cause,true);

  if ((ie->value.choice.Cause.present == NGAP_Cause_PR_misc) &&
      (ie->value.choice.Cause.choice.misc == NGAP_CauseMisc_unspecified)) {
zhenghuangkun's avatar
zhenghuangkun committed
287
    NGAP_WARN("Received NG setup failure for AMF... AMF is not ready\n");
zhenghuangkun's avatar
zhenghuangkun committed
288
  } else {
zhenghuangkun's avatar
zhenghuangkun committed
289
    NGAP_ERROR("Received NG setup failure for AMF... please check your parameters\n");
zhenghuangkun's avatar
zhenghuangkun committed
290 291
  }

zhenghuangkun's avatar
zhenghuangkun committed
292 293
  amf_desc_p->state = NGAP_GNB_STATE_WAITING;
  ngap_handle_ng_setup_message(amf_desc_p, 0);
zhenghuangkun's avatar
zhenghuangkun committed
294 295 296 297
  return 0;
}

static
zhenghuangkun's avatar
zhenghuangkun committed
298
int ngap_gNB_handle_ng_setup_response(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
299 300
                                      uint32_t               stream,
                                      NGAP_NGAP_PDU_t       *pdu) {
zhenghuangkun's avatar
zhenghuangkun committed
301 302 303
  NGAP_NGSetupResponse_t    *container;
  NGAP_NGSetupResponseIEs_t *ie;
  ngap_gNB_amf_data_t       *amf_desc_p;
zhenghuangkun's avatar
zhenghuangkun committed
304 305
  int i;
  DevAssert(pdu != NULL);
306
  container = &pdu->choice.successfulOutcome->value.choice.NGSetupResponse;
zhenghuangkun's avatar
zhenghuangkun committed
307

zhenghuangkun's avatar
zhenghuangkun committed
308
  /* NG Setup Response == Non UE-related procedure -> stream 0 */
zhenghuangkun's avatar
zhenghuangkun committed
309
  if (stream != 0) {
zhenghuangkun's avatar
zhenghuangkun committed
310
    NGAP_ERROR("[SCTP %d] Received ng setup response on stream != 0 (%d)\n",
zhenghuangkun's avatar
zhenghuangkun committed
311 312 313 314
               assoc_id, stream);
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
315 316 317
  if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
    NGAP_ERROR("[SCTP %d] Received NG setup response for non existing "
               "AMF context\n", assoc_id);
zhenghuangkun's avatar
zhenghuangkun committed
318 319 320
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
321 322
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_NGSetupResponseIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_ServedGUAMIList, true);
zhenghuangkun's avatar
zhenghuangkun committed
323

zhenghuangkun's avatar
zhenghuangkun committed
324 325
  /* The list of served guami can contain at most 256 elements.
   * NR related guami is the first element in the list, i.e with an id of 0.
zhenghuangkun's avatar
zhenghuangkun committed
326
   */
zhenghuangkun's avatar
zhenghuangkun committed
327 328 329
  NGAP_DEBUG("servedGUAMIs.list.count %d\n", ie->value.choice.ServedGUAMIList.list.count);
  DevAssert(ie->value.choice.ServedGUAMIList.list.count > 0);
  DevAssert(ie->value.choice.ServedGUAMIList.list.count <= NGAP_maxnoofServedGUAMIs);
zhenghuangkun's avatar
zhenghuangkun committed
330

zhenghuangkun's avatar
zhenghuangkun committed
331 332 333
  for (i = 0; i < ie->value.choice.ServedGUAMIList.list.count; i++) {
    NGAP_ServedGUAMIItem_t  *guami_item_p;
    struct served_guami_s   *new_guami_p;
zhenghuangkun's avatar
zhenghuangkun committed
334

zhenghuangkun's avatar
zhenghuangkun committed
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
    guami_item_p = ie->value.choice.ServedGUAMIList.list.array[i];
    new_guami_p = calloc(1, sizeof(struct served_guami_s));
    STAILQ_INIT(&new_guami_p->served_plmns);
    STAILQ_INIT(&new_guami_p->served_region_ids);
    STAILQ_INIT(&new_guami_p->amf_set_ids);
    STAILQ_INIT(&new_guami_p->amf_pointers);
    
    NGAP_PLMNIdentity_t *plmn_identity_p;
    struct plmn_identity_s *new_plmn_identity_p;
    plmn_identity_p = &guami_item_p->gUAMI.pLMNIdentity;
    new_plmn_identity_p = calloc(1, sizeof(struct plmn_identity_s));
    TBCD_TO_MCC_MNC(plmn_identity_p, new_plmn_identity_p->mcc,
                    new_plmn_identity_p->mnc, new_plmn_identity_p->mnc_digit_length);
    STAILQ_INSERT_TAIL(&new_guami_p->served_plmns, new_plmn_identity_p, next);
    new_guami_p->nb_served_plmns++;
    
    NGAP_AMFRegionID_t        *amf_region_id_p;
    struct served_region_id_s *new_region_id_p;
    amf_region_id_p = &guami_item_p->gUAMI.aMFRegionID;
    new_region_id_p = calloc(1, sizeof(struct served_region_id_s));
    OCTET_STRING_TO_INT8(amf_region_id_p, new_region_id_p->amf_region_id);
    STAILQ_INSERT_TAIL(&new_guami_p->served_region_ids, new_region_id_p, next);
    new_guami_p->nb_region_id++;

    NGAP_AMFSetID_t        *amf_set_id_p;
    struct amf_set_id_s    *new_amf_set_id_p;
    amf_set_id_p = &guami_item_p->gUAMI.aMFSetID;
    new_amf_set_id_p = calloc(1, sizeof(struct amf_set_id_s));
    OCTET_STRING_TO_INT16(amf_set_id_p, new_amf_set_id_p->amf_set_id);
    STAILQ_INSERT_TAIL(&new_guami_p->amf_set_ids, new_amf_set_id_p, next);
    new_guami_p->nb_amf_set_id++;

    NGAP_AMFPointer_t        *amf_pointer_p;
    struct amf_pointer_s     *new_amf_pointer_p;
    amf_pointer_p = &guami_item_p->gUAMI.aMFPointer;
    new_amf_pointer_p = calloc(1, sizeof(struct amf_pointer_s));
    OCTET_STRING_TO_INT8(amf_pointer_p, new_amf_pointer_p->amf_pointer);
    STAILQ_INSERT_TAIL(&new_guami_p->amf_pointers, new_amf_pointer_p, next);
    new_guami_p->nb_amf_pointer++;

    STAILQ_INSERT_TAIL(&amf_desc_p->served_guami, new_guami_p, next);
  }

  /* Set the capacity of this AMF */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_NGSetupResponseIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_RelativeAMFCapacity, true);

  amf_desc_p->relative_amf_capacity = ie->value.choice.RelativeAMFCapacity;

  /* mandatory set the amf name */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_NGSetupResponseIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_AMFName, true);
zhenghuangkun's avatar
zhenghuangkun committed
387

zhenghuangkun's avatar
zhenghuangkun committed
388 389
  if (ie) {
    amf_desc_p->amf_name = calloc(ie->value.choice.AMFName.size + 1, sizeof(char));
heshanyun's avatar
heshanyun committed
390 391
    memcpy(amf_desc_p->amf_name, ie->value.choice.AMFName.buf,
           ie->value.choice.AMFName.size);
zhenghuangkun's avatar
zhenghuangkun committed
392
    /* Convert the amf name to a printable string */
heshanyun's avatar
heshanyun committed
393
    amf_desc_p->amf_name[ie->value.choice.AMFName.size] = '\0';
zhenghuangkun's avatar
zhenghuangkun committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
  }

  
  /* mandatory set the plmn supports */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_NGSetupResponseIEs_t, ie, container,
                               NGAP_ProtocolIE_ID_id_PLMNSupportList, true);

  NGAP_DEBUG("PLMNSupportList.list.count %d\n", ie->value.choice.PLMNSupportList.list.count);
  DevAssert(ie->value.choice.PLMNSupportList.list.count > 0);
  DevAssert(ie->value.choice.PLMNSupportList.list.count <= NGAP_maxnoofPLMNs);

  STAILQ_INIT(&amf_desc_p->plmn_supports);

  for (i = 0; i < ie->value.choice.ServedGUAMIList.list.count; i++) {
    NGAP_PLMNSupportItem_t *plmn_support_item_p;
    struct plmn_support_s  *new_plmn_support_p;
    NGAP_SliceSupportItem_t  *slice_support_item_p;
    struct slice_support_s *new_slice_support_p;

    plmn_support_item_p = ie->value.choice.PLMNSupportList.list.array[i];

    new_plmn_support_p = calloc(1, sizeof(struct plmn_support_s));
    
    TBCD_TO_MCC_MNC(&plmn_support_item_p->pLMNIdentity, new_plmn_support_p->plmn_identity.mcc,
                    new_plmn_support_p->plmn_identity.mnc, new_plmn_support_p->plmn_identity.mnc_digit_length);

    NGAP_DEBUG("PLMNSupportList.list.count %d\n", plmn_support_item_p->sliceSupportList.list.count);
    DevAssert(plmn_support_item_p->sliceSupportList.list.count > 0);
    DevAssert(plmn_support_item_p->sliceSupportList.list.count <= NGAP_maxnoofSliceItems);

    STAILQ_INIT(&new_plmn_support_p->slice_supports);
    for(int j=0; j<plmn_support_item_p->sliceSupportList.list.count; j++) {
      slice_support_item_p = plmn_support_item_p->sliceSupportList.list.array[j];
      
      new_slice_support_p = calloc(1, sizeof(struct slice_support_s));

      OCTET_STRING_TO_INT8(&slice_support_item_p->s_NSSAI.sST, new_slice_support_p->sST);

      if(slice_support_item_p->s_NSSAI.sD != NULL) {
        new_slice_support_p->sD_flag = 1;
434 435 436
        new_slice_support_p->sD[0] = slice_support_item_p->s_NSSAI.sD->buf[0];
        new_slice_support_p->sD[1] = slice_support_item_p->s_NSSAI.sD->buf[1];
        new_slice_support_p->sD[2] = slice_support_item_p->s_NSSAI.sD->buf[2];
zhenghuangkun's avatar
zhenghuangkun committed
437 438
      }
      STAILQ_INSERT_TAIL(&new_plmn_support_p->slice_supports, new_slice_support_p, next);
zhenghuangkun's avatar
zhenghuangkun committed
439 440
    }

zhenghuangkun's avatar
zhenghuangkun committed
441
    STAILQ_INSERT_TAIL(&amf_desc_p->plmn_supports, new_plmn_support_p, next);
zhenghuangkun's avatar
zhenghuangkun committed
442 443
  }

zhenghuangkun's avatar
zhenghuangkun committed
444
  /* The association is now ready as gNB and AMF know parameters of each other.
zhenghuangkun's avatar
zhenghuangkun committed
445 446
   * Mark the association as UP to enable UE contexts creation.
   */
zhenghuangkun's avatar
zhenghuangkun committed
447 448 449
  amf_desc_p->state = NGAP_GNB_STATE_CONNECTED;
  amf_desc_p->ngap_gNB_instance->ngap_amf_associated_nb ++;
  ngap_handle_ng_setup_message(amf_desc_p, 0);
450

zhenghuangkun's avatar
zhenghuangkun committed
451 452 453 454 455 456 457 458
  return 0;
}


static
int ngap_gNB_handle_error_indication(uint32_t         assoc_id,
                                     uint32_t         stream,
                                     NGAP_NGAP_PDU_t *pdu) {
zhenghuangkun's avatar
zhenghuangkun committed
459

zhenghuangkun's avatar
zhenghuangkun committed
460 461
  NGAP_ErrorIndication_t    *container;
  NGAP_ErrorIndicationIEs_t *ie;
zhenghuangkun's avatar
zhenghuangkun committed
462
  ngap_gNB_amf_data_t        *amf_desc_p;
zhenghuangkun's avatar
zhenghuangkun committed
463 464
  uint64_t                 amf_ue_ngap_id;
    
zhenghuangkun's avatar
zhenghuangkun committed
465
  DevAssert(pdu != NULL);
466
  container = &pdu->choice.initiatingMessage->value.choice.ErrorIndication;
zhenghuangkun's avatar
zhenghuangkun committed
467

zhenghuangkun's avatar
zhenghuangkun committed
468
  /* NG Setup Failure == Non UE-related procedure -> stream 0 */
zhenghuangkun's avatar
zhenghuangkun committed
469
  if (stream != 0) {
zhenghuangkun's avatar
zhenghuangkun committed
470
    NGAP_WARN("[SCTP %d] Received ng Error indication on stream != 0 (%d)\n",
zhenghuangkun's avatar
zhenghuangkun committed
471 472 473
              assoc_id, stream);
  }

zhenghuangkun's avatar
zhenghuangkun committed
474
  if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
475
    NGAP_ERROR("[SCTP %d] Received ng Error indication for non existing "
zhenghuangkun's avatar
zhenghuangkun committed
476
               "AMF context\n", assoc_id);
zhenghuangkun's avatar
zhenghuangkun committed
477 478 479 480
    return -1;
  }

  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_ErrorIndicationIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
481
                             NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID, false);
zhenghuangkun's avatar
zhenghuangkun committed
482 483 484

  /* optional */
  if (ie != NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
485 486
    asn_INTEGER2ulong(&(ie->value.choice.AMF_UE_NGAP_ID), &amf_ue_ngap_id);
    NGAP_WARN("Received NG Error indication AMF UE NGAP ID 0x%lx\n", amf_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
487 488 489
  }

  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_ErrorIndicationIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
490
                             NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, false);
zhenghuangkun's avatar
zhenghuangkun committed
491 492 493

  /* optional */
  if (ie != NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
494
    NGAP_WARN("Received NG Error indication gNB UE NGAP ID 0x%lx\n", ie->value.choice.RAN_UE_NGAP_ID);
zhenghuangkun's avatar
zhenghuangkun committed
495 496 497 498 499 500 501 502 503
  }

  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_ErrorIndicationIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_Cause, false);

  /* optional */
  if (ie) {
    switch(ie->value.choice.Cause.present) {
      case NGAP_Cause_PR_NOTHING:
zhenghuangkun's avatar
zhenghuangkun committed
504
        NGAP_WARN("Received NG Error indication cause NOTHING\n");
zhenghuangkun's avatar
zhenghuangkun committed
505 506 507 508 509
        break;

      case NGAP_Cause_PR_radioNetwork:
        switch (ie->value.choice.Cause.choice.radioNetwork) {
          case NGAP_CauseRadioNetwork_unspecified:
zhenghuangkun's avatar
zhenghuangkun committed
510
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_unspecified\n");
zhenghuangkun's avatar
zhenghuangkun committed
511 512
            break;

zhenghuangkun's avatar
zhenghuangkun committed
513 514
          case NGAP_CauseRadioNetwork_txnrelocoverall_expiry:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_txnrelocoverall_expiry\n");
zhenghuangkun's avatar
zhenghuangkun committed
515 516 517
            break;

          case NGAP_CauseRadioNetwork_successful_handover:
zhenghuangkun's avatar
zhenghuangkun committed
518
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_successful_handover\n");
zhenghuangkun's avatar
zhenghuangkun committed
519 520
            break;

zhenghuangkun's avatar
zhenghuangkun committed
521 522 523 524 525 526
          case NGAP_CauseRadioNetwork_release_due_to_ngran_generated_reason:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_release_due_to_ngran_generated_reason\n");
            break;
          
          case NGAP_CauseRadioNetwork_release_due_to_5gc_generated_reason:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_release_due_to_5gc_generated_reason\n");
zhenghuangkun's avatar
zhenghuangkun committed
527 528 529
            break;

          case NGAP_CauseRadioNetwork_handover_cancelled:
zhenghuangkun's avatar
zhenghuangkun committed
530
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_handover_cancelled\n");
zhenghuangkun's avatar
zhenghuangkun committed
531 532 533
            break;

          case NGAP_CauseRadioNetwork_partial_handover:
zhenghuangkun's avatar
zhenghuangkun committed
534
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_partial_handover\n");
zhenghuangkun's avatar
zhenghuangkun committed
535 536
            break;

zhenghuangkun's avatar
zhenghuangkun committed
537 538
          case NGAP_CauseRadioNetwork_ho_failure_in_target_5GC_ngran_node_or_target_system:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_ho_failure_in_target_5GC_ngran_node_or_target_system\n");
zhenghuangkun's avatar
zhenghuangkun committed
539 540 541
            break;

          case NGAP_CauseRadioNetwork_ho_target_not_allowed:
zhenghuangkun's avatar
zhenghuangkun committed
542
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_ho_target_not_allowed\n");
zhenghuangkun's avatar
zhenghuangkun committed
543 544
            break;

zhenghuangkun's avatar
zhenghuangkun committed
545 546
          case NGAP_CauseRadioNetwork_tngrelocoverall_expiry:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_tngrelocoverall_expiry\n");
zhenghuangkun's avatar
zhenghuangkun committed
547 548
            break;

zhenghuangkun's avatar
zhenghuangkun committed
549 550
          case NGAP_CauseRadioNetwork_tngrelocprep_expiry:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_tngrelocprep_expiry\n");
zhenghuangkun's avatar
zhenghuangkun committed
551 552 553
            break;

          case NGAP_CauseRadioNetwork_cell_not_available:
zhenghuangkun's avatar
zhenghuangkun committed
554
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_cell_not_available\n");
zhenghuangkun's avatar
zhenghuangkun committed
555 556 557
            break;

          case NGAP_CauseRadioNetwork_unknown_targetID:
zhenghuangkun's avatar
zhenghuangkun committed
558
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_unknown_targetID\n");
zhenghuangkun's avatar
zhenghuangkun committed
559 560 561
            break;

          case NGAP_CauseRadioNetwork_no_radio_resources_available_in_target_cell:
zhenghuangkun's avatar
zhenghuangkun committed
562
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_no_radio_resources_available_in_target_cell\n");
zhenghuangkun's avatar
zhenghuangkun committed
563 564
            break;

zhenghuangkun's avatar
zhenghuangkun committed
565 566
          case NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID\n");
zhenghuangkun's avatar
zhenghuangkun committed
567 568
            break;

zhenghuangkun's avatar
zhenghuangkun committed
569 570
          case NGAP_CauseRadioNetwork_inconsistent_remote_UE_NGAP_ID:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_inconsistent_remote_UE_NGAP_ID\n");
zhenghuangkun's avatar
zhenghuangkun committed
571 572 573
            break;

          case NGAP_CauseRadioNetwork_handover_desirable_for_radio_reason:
zhenghuangkun's avatar
zhenghuangkun committed
574
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_handover_desirable_for_radio_reason\n");
zhenghuangkun's avatar
zhenghuangkun committed
575 576 577
            break;

          case NGAP_CauseRadioNetwork_time_critical_handover:
zhenghuangkun's avatar
zhenghuangkun committed
578
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_time_critical_handover\n");
zhenghuangkun's avatar
zhenghuangkun committed
579 580 581
            break;

          case NGAP_CauseRadioNetwork_resource_optimisation_handover:
zhenghuangkun's avatar
zhenghuangkun committed
582
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_resource_optimisation_handover\n");
zhenghuangkun's avatar
zhenghuangkun committed
583 584 585
            break;

          case NGAP_CauseRadioNetwork_reduce_load_in_serving_cell:
zhenghuangkun's avatar
zhenghuangkun committed
586
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_reduce_load_in_serving_cell\n");
zhenghuangkun's avatar
zhenghuangkun committed
587 588 589
            break;

          case NGAP_CauseRadioNetwork_user_inactivity:
zhenghuangkun's avatar
zhenghuangkun committed
590
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_user_inactivity\n");
zhenghuangkun's avatar
zhenghuangkun committed
591 592 593
            break;

          case NGAP_CauseRadioNetwork_radio_connection_with_ue_lost:
zhenghuangkun's avatar
zhenghuangkun committed
594
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_radio_connection_with_ue_lost\n");
zhenghuangkun's avatar
zhenghuangkun committed
595 596
            break;

zhenghuangkun's avatar
zhenghuangkun committed
597 598
          case NGAP_CauseRadioNetwork_radio_resources_not_available:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_radio_resources_not_available\n");
zhenghuangkun's avatar
zhenghuangkun committed
599 600
            break;

zhenghuangkun's avatar
zhenghuangkun committed
601 602
          case NGAP_CauseRadioNetwork_invalid_qos_combination:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_invalid_qos_combination\n");
zhenghuangkun's avatar
zhenghuangkun committed
603 604 605
            break;

          case NGAP_CauseRadioNetwork_failure_in_radio_interface_procedure:
zhenghuangkun's avatar
zhenghuangkun committed
606
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_failure_in_radio_interface_procedure\n");
zhenghuangkun's avatar
zhenghuangkun committed
607 608
            break;

zhenghuangkun's avatar
zhenghuangkun committed
609 610
          case NGAP_CauseRadioNetwork_interaction_with_other_procedure:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_interaction_with_other_procedure\n");
zhenghuangkun's avatar
zhenghuangkun committed
611 612
            break;

zhenghuangkun's avatar
zhenghuangkun committed
613 614
          case NGAP_CauseRadioNetwork_unknown_PDU_session_ID:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_unknown_PDU_session_ID\n");
zhenghuangkun's avatar
zhenghuangkun committed
615 616
            break;

zhenghuangkun's avatar
zhenghuangkun committed
617 618
          case NGAP_CauseRadioNetwork_unkown_qos_flow_ID:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_unkown_qos_flow_ID\n");
zhenghuangkun's avatar
zhenghuangkun committed
619 620
            break;

zhenghuangkun's avatar
zhenghuangkun committed
621 622
          case NGAP_CauseRadioNetwork_multiple_PDU_session_ID_instances:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_multiple_PDU_session_ID_instances\n");
zhenghuangkun's avatar
zhenghuangkun committed
623 624
            break;

zhenghuangkun's avatar
zhenghuangkun committed
625 626
          case NGAP_CauseRadioNetwork_multiple_qos_flow_ID_instances:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_multiple_qos_flow_ID_instances\n");
zhenghuangkun's avatar
zhenghuangkun committed
627 628 629
            break;

          case NGAP_CauseRadioNetwork_encryption_and_or_integrity_protection_algorithms_not_supported:
zhenghuangkun's avatar
zhenghuangkun committed
630
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_encryption_and_or_integrity_protection_algorithms_not_supported\n");
zhenghuangkun's avatar
zhenghuangkun committed
631 632
            break;

zhenghuangkun's avatar
zhenghuangkun committed
633
          case NGAP_CauseRadioNetwork_ng_intra_system_handover_triggered:
zhenghuangkun's avatar
zhenghuangkun committed
634
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_ng_intra_system_handover_triggered\n");
zhenghuangkun's avatar
zhenghuangkun committed
635 636
            break;

zhenghuangkun's avatar
zhenghuangkun committed
637
          case NGAP_CauseRadioNetwork_ng_inter_system_handover_triggered:
zhenghuangkun's avatar
zhenghuangkun committed
638 639 640 641 642 643 644 645 646 647 648 649 650
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_ng_inter_system_handover_triggered\n");
            break;

          case NGAP_CauseRadioNetwork_xn_handover_triggered:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_xn_handover_triggered\n");
            break;

          case NGAP_CauseRadioNetwork_not_supported_5QI_value:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_not_supported_5QI_value\n");
            break;

          case NGAP_CauseRadioNetwork_ue_context_transfer:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_ue_context_transfer\n");
zhenghuangkun's avatar
zhenghuangkun committed
651 652
            break;

zhenghuangkun's avatar
zhenghuangkun committed
653 654
          case NGAP_CauseRadioNetwork_ims_voice_eps_fallback_or_rat_fallback_triggered:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_ims_voice_eps_fallback_or_rat_fallback_triggered\n");
zhenghuangkun's avatar
zhenghuangkun committed
655 656
            break;

zhenghuangkun's avatar
zhenghuangkun committed
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
          case NGAP_CauseRadioNetwork_up_integrity_protection_not_possible:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_up_integrity_protection_not_possible\n");
            break;
          case NGAP_CauseRadioNetwork_up_confidentiality_protection_not_possible:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_up_confidentiality_protection_not_possible\n");
            break;

          case NGAP_CauseRadioNetwork_slice_not_supported:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_slice_not_supported\n");
            break;

          case NGAP_CauseRadioNetwork_ue_in_rrc_inactive_state_not_reachable:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_ue_in_rrc_inactive_state_not_reachable\n");
            break;

          case NGAP_CauseRadioNetwork_redirection:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_redirection\n");
zhenghuangkun's avatar
zhenghuangkun committed
674 675
            break;

zhenghuangkun's avatar
zhenghuangkun committed
676 677
          case NGAP_CauseRadioNetwork_resources_not_available_for_the_slice:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_resources_not_available_for_the_slice\n");
zhenghuangkun's avatar
zhenghuangkun committed
678
            break;
zhenghuangkun's avatar
zhenghuangkun committed
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697

          case NGAP_CauseRadioNetwork_ue_max_integrity_protected_data_rate_reason:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_ue_max_integrity_protected_data_rate_reason\n");
            break;

          case NGAP_CauseRadioNetwork_release_due_to_cn_detected_mobility:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_release_due_to_cn_detected_mobility\n");
            break;

          case NGAP_CauseRadioNetwork_n26_interface_not_available:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_n26_interface_not_available\n");
            break;

          case NGAP_CauseRadioNetwork_release_due_to_pre_emption:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_release_due_to_pre_emption\n");
            break;

          case NGAP_CauseRadioNetwork_multiple_location_reporting_reference_ID_instances:
            NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_multiple_location_reporting_reference_ID_instances\n");
zhenghuangkun's avatar
zhenghuangkun committed
698 699 700
            break;

          default:
zhenghuangkun's avatar
zhenghuangkun committed
701
            NGAP_WARN("Received NG Error indication cause radio network case not handled\n");
zhenghuangkun's avatar
zhenghuangkun committed
702 703 704 705 706 707 708
        }

        break;

      case NGAP_Cause_PR_transport:
        switch (ie->value.choice.Cause.choice.transport) {
          case NGAP_CauseTransport_transport_resource_unavailable:
zhenghuangkun's avatar
zhenghuangkun committed
709
            NGAP_WARN("Received NG Error indication NGAP_CauseTransport_transport_resource_unavailable\n");
zhenghuangkun's avatar
zhenghuangkun committed
710 711 712
            break;

          case NGAP_CauseTransport_unspecified:
zhenghuangkun's avatar
zhenghuangkun committed
713
            NGAP_WARN("Received NG Error indication NGAP_CauseTransport_unspecified\n");
zhenghuangkun's avatar
zhenghuangkun committed
714 715 716
            break;

          default:
zhenghuangkun's avatar
zhenghuangkun committed
717
            NGAP_WARN("Received NG Error indication cause transport case not handled\n");
zhenghuangkun's avatar
zhenghuangkun committed
718 719 720 721 722 723 724
        }

        break;

      case NGAP_Cause_PR_nas:
        switch (ie->value.choice.Cause.choice.nas) {
          case NGAP_CauseNas_normal_release:
zhenghuangkun's avatar
zhenghuangkun committed
725
            NGAP_WARN("Received NG Error indication NGAP_CauseNas_normal_release\n");
zhenghuangkun's avatar
zhenghuangkun committed
726 727 728
            break;

          case NGAP_CauseNas_authentication_failure:
zhenghuangkun's avatar
zhenghuangkun committed
729
            NGAP_WARN("Received NG Error indication NGAP_CauseNas_authentication_failure\n");
zhenghuangkun's avatar
zhenghuangkun committed
730 731
            break;

zhenghuangkun's avatar
zhenghuangkun committed
732 733
          case NGAP_CauseNas_deregister:
            NGAP_WARN("Received NG Error indication NGAP_CauseNas_deregister\n");
zhenghuangkun's avatar
zhenghuangkun committed
734 735 736
            break;

          case NGAP_CauseNas_unspecified:
zhenghuangkun's avatar
zhenghuangkun committed
737
            NGAP_WARN("Received NG Error indication NGAP_CauseNas_unspecified\n");
zhenghuangkun's avatar
zhenghuangkun committed
738 739 740
            break;

          default:
zhenghuangkun's avatar
zhenghuangkun committed
741
            NGAP_WARN("Received NG Error indication cause nas case not handled\n");
zhenghuangkun's avatar
zhenghuangkun committed
742 743 744 745 746 747 748
        }

        break;

      case NGAP_Cause_PR_protocol:
        switch (ie->value.choice.Cause.choice.protocol) {
          case NGAP_CauseProtocol_transfer_syntax_error:
zhenghuangkun's avatar
zhenghuangkun committed
749
            NGAP_WARN("Received NG Error indication NGAP_CauseProtocol_transfer_syntax_error\n");
zhenghuangkun's avatar
zhenghuangkun committed
750 751 752
            break;

          case NGAP_CauseProtocol_abstract_syntax_error_reject:
zhenghuangkun's avatar
zhenghuangkun committed
753
            NGAP_WARN("Received NG Error indication NGAP_CauseProtocol_abstract_syntax_error_reject\n");
zhenghuangkun's avatar
zhenghuangkun committed
754 755 756
            break;

          case NGAP_CauseProtocol_abstract_syntax_error_ignore_and_notify:
zhenghuangkun's avatar
zhenghuangkun committed
757
            NGAP_WARN("Received NG Error indication NGAP_CauseProtocol_abstract_syntax_error_ignore_and_notify\n");
zhenghuangkun's avatar
zhenghuangkun committed
758 759 760
            break;

          case NGAP_CauseProtocol_message_not_compatible_with_receiver_state:
zhenghuangkun's avatar
zhenghuangkun committed
761
            NGAP_WARN("Received NG Error indication NGAP_CauseProtocol_message_not_compatible_with_receiver_state\n");
zhenghuangkun's avatar
zhenghuangkun committed
762 763 764
            break;

          case NGAP_CauseProtocol_semantic_error:
zhenghuangkun's avatar
zhenghuangkun committed
765
            NGAP_WARN("Received NG Error indication NGAP_CauseProtocol_semantic_error\n");
zhenghuangkun's avatar
zhenghuangkun committed
766 767 768
            break;

          case NGAP_CauseProtocol_abstract_syntax_error_falsely_constructed_message:
zhenghuangkun's avatar
zhenghuangkun committed
769
            NGAP_WARN("Received NG Error indication NGAP_CauseProtocol_abstract_syntax_error_falsely_constructed_message\n");
zhenghuangkun's avatar
zhenghuangkun committed
770 771 772
            break;

          case NGAP_CauseProtocol_unspecified:
zhenghuangkun's avatar
zhenghuangkun committed
773
            NGAP_WARN("Received NG Error indication NGAP_CauseProtocol_unspecified\n");
zhenghuangkun's avatar
zhenghuangkun committed
774 775 776
            break;

          default:
zhenghuangkun's avatar
zhenghuangkun committed
777
            NGAP_WARN("Received NG Error indication cause protocol case not handled\n");
zhenghuangkun's avatar
zhenghuangkun committed
778 779 780 781 782 783 784
        }

        break;

      case NGAP_Cause_PR_misc:
        switch (ie->value.choice.Cause.choice.protocol) {
          case NGAP_CauseMisc_control_processing_overload:
zhenghuangkun's avatar
zhenghuangkun committed
785
            NGAP_WARN("Received NG Error indication NGAP_CauseMisc_control_processing_overload\n");
zhenghuangkun's avatar
zhenghuangkun committed
786 787 788
            break;

          case NGAP_CauseMisc_not_enough_user_plane_processing_resources:
zhenghuangkun's avatar
zhenghuangkun committed
789
            NGAP_WARN("Received NG Error indication NGAP_CauseMisc_not_enough_user_plane_processing_resources\n");
zhenghuangkun's avatar
zhenghuangkun committed
790 791 792
            break;

          case NGAP_CauseMisc_hardware_failure:
zhenghuangkun's avatar
zhenghuangkun committed
793
            NGAP_WARN("Received NG Error indication NGAP_CauseMisc_hardware_failure\n");
zhenghuangkun's avatar
zhenghuangkun committed
794 795 796
            break;

          case NGAP_CauseMisc_om_intervention:
zhenghuangkun's avatar
zhenghuangkun committed
797
            NGAP_WARN("Received NG Error indication NGAP_CauseMisc_om_intervention\n");
zhenghuangkun's avatar
zhenghuangkun committed
798 799 800
            break;

          case NGAP_CauseMisc_unspecified:
zhenghuangkun's avatar
zhenghuangkun committed
801
            NGAP_WARN("Received NG Error indication NGAP_CauseMisc_unspecified\n");
zhenghuangkun's avatar
zhenghuangkun committed
802 803 804
            break;

          case NGAP_CauseMisc_unknown_PLMN:
zhenghuangkun's avatar
zhenghuangkun committed
805
            NGAP_WARN("Received NG Error indication NGAP_CauseMisc_unknown_PLMN\n");
zhenghuangkun's avatar
zhenghuangkun committed
806 807 808
            break;

          default:
zhenghuangkun's avatar
zhenghuangkun committed
809
            NGAP_WARN("Received NG Error indication cause misc case not handled\n");
zhenghuangkun's avatar
zhenghuangkun committed
810 811 812
        }

        break;
zhenghuangkun's avatar
zhenghuangkun committed
813 814 815 816 817
        
      default:
       NGAP_WARN("Received NG Error indication cause NGAP_Cause_PR_choice_Extensions\n");
       break;
      
zhenghuangkun's avatar
zhenghuangkun committed
818 819 820
    }
  }

zhenghuangkun's avatar
zhenghuangkun committed
821

zhenghuangkun's avatar
zhenghuangkun committed
822 823 824 825 826 827 828
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_ErrorIndicationIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_CriticalityDiagnostics, false);

  if (ie) {
    // TODO continue
  }

zhenghuangkun's avatar
zhenghuangkun committed
829

zhenghuangkun's avatar
zhenghuangkun committed
830 831 832 833 834 835 836 837 838
  // TODO continue
  return 0;
}


static
int ngap_gNB_handle_initial_context_request(uint32_t   assoc_id,
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu) {
839

zhenghuangkun's avatar
zhenghuangkun committed
840
  int i;
zhenghuangkun's avatar
zhenghuangkun committed
841
  ngap_gNB_amf_data_t   *amf_desc_p       = NULL;
zhenghuangkun's avatar
zhenghuangkun committed
842 843 844 845
  ngap_gNB_ue_context_t *ue_desc_p        = NULL;
  MessageDef            *message_p        = NULL;
  NGAP_InitialContextSetupRequest_t    *container;
  NGAP_InitialContextSetupRequestIEs_t *ie;
zhenghuangkun's avatar
zhenghuangkun committed
846
  NGAP_RAN_UE_NGAP_ID_t    ran_ue_ngap_id;
847
  uint64_t                 amf_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
848
  DevAssert(pdu != NULL);
849
  container = &pdu->choice.initiatingMessage->value.choice.InitialContextSetupRequest;
zhenghuangkun's avatar
zhenghuangkun committed
850

zhenghuangkun's avatar
zhenghuangkun committed
851
  if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
852
    NGAP_ERROR("[SCTP %d] Received initial context setup request for non "
zhenghuangkun's avatar
zhenghuangkun committed
853
               "existing AMF context\n", assoc_id);
zhenghuangkun's avatar
zhenghuangkun committed
854 855 856
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
857
  /* id-AMF-UE-NGAP-ID */
zhenghuangkun's avatar
zhenghuangkun committed
858
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
859
                             NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID, true);
zhenghuangkun's avatar
zhenghuangkun committed
860 861

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
862
    asn_INTEGER2ulong(&(ie->value.choice.AMF_UE_NGAP_ID), &amf_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
863 864 865 866
  } else {
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
867
  /* id-RAN-UE-NGAP-ID */
zhenghuangkun's avatar
zhenghuangkun committed
868
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
869
                             NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true);
zhenghuangkun's avatar
zhenghuangkun committed
870 871

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
872
    ran_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID;
zhenghuangkun's avatar
zhenghuangkun committed
873

zhenghuangkun's avatar
zhenghuangkun committed
874 875
    if ((ue_desc_p = ngap_gNB_get_ue_context(amf_desc_p->ngap_gNB_instance,
                     ran_ue_ngap_id)) == NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
876 877
      NGAP_ERROR("[SCTP %d] Received initial context setup request for non "
                 "existing UE context 0x%06lx\n", assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
878
                 ran_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
879 880 881 882 883 884 885
      return -1;
    }
  } else {
    return -1;
  }

  /* Initial context request = UE-related procedure -> stream != 0 */
886 887 888 889 890
  //if (stream == 0) {
  //  NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n",
  //             assoc_id, stream);
  //  return -1;
  //}
zhenghuangkun's avatar
zhenghuangkun committed
891 892

  ue_desc_p->rx_stream = stream;
zhenghuangkun's avatar
zhenghuangkun committed
893
  ue_desc_p->amf_ue_ngap_id = amf_ue_ngap_id;
894
  
895
  message_p        = itti_alloc_new_message(TASK_NGAP, 0, NGAP_INITIAL_CONTEXT_SETUP_REQ);
zhenghuangkun's avatar
zhenghuangkun committed
896 897 898
  NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_initial_id  = ue_desc_p->ue_initial_id;
  ue_desc_p->ue_initial_id = 0;
  NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).gNB_ue_ngap_id = ue_desc_p->gNB_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
899 900
  NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).amf_ue_ngap_id = ue_desc_p->amf_ue_ngap_id;
  /* id-UEAggregateMaximumBitRate */
zhenghuangkun's avatar
zhenghuangkun committed
901
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
902
                             NGAP_ProtocolIE_ID_id_UEAggregateMaximumBitRate, false);
zhenghuangkun's avatar
zhenghuangkun committed
903 904

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
905
    asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitRate.uEAggregateMaximumBitRateUL),
zhenghuangkun's avatar
zhenghuangkun committed
906
                      &(NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_ul));
zhenghuangkun's avatar
zhenghuangkun committed
907
    asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitRate.uEAggregateMaximumBitRateDL),
zhenghuangkun's avatar
zhenghuangkun committed
908 909
                      &(NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_dl));
  } else {
zhenghuangkun's avatar
zhenghuangkun committed
910
    NGAP_ERROR("could not found NGAP_ProtocolIE_ID_id_UEAggregateMaximumBitRate\n");
zhenghuangkun's avatar
zhenghuangkun committed
911 912
  }

zhenghuangkun's avatar
zhenghuangkun committed
913 914

  /* id-GUAMI */
zhenghuangkun's avatar
zhenghuangkun committed
915
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
916
                             NGAP_ProtocolIE_ID_id_GUAMI, true);
zhenghuangkun's avatar
zhenghuangkun committed
917 918

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
919 920 921 922 923 924 925 926 927
    TBCD_TO_MCC_MNC(&ie->value.choice.GUAMI.pLMNIdentity, NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).guami.mcc,
                    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).guami.mnc, NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).guami.mnc_len);
    
    OCTET_STRING_TO_INT8(&ie->value.choice.GUAMI.aMFRegionID, NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).guami.amf_region_id);
    OCTET_STRING_TO_INT16(&ie->value.choice.GUAMI.aMFSetID, NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).guami.amf_set_id);
    OCTET_STRING_TO_INT8(&ie->value.choice.GUAMI.aMFPointer, NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).guami.amf_pointer);
  } else {/* ie != NULL */
    return -1;
  }
zhenghuangkun's avatar
zhenghuangkun committed
928

zhenghuangkun's avatar
zhenghuangkun committed
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtReq, false);

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_of_pdusessions =
      ie->value.choice.PDUSessionResourceSetupListCxtReq.list.count;

    for (i = 0; i < ie->value.choice.PDUSessionResourceSetupListCxtReq.list.count; i++) {
      NGAP_PDUSessionResourceSetupItemCxtReq_t *item_p;
      asn_dec_rval_t                           dec_rval;
      NGAP_PDUSessionResourceSetupRequestTransfer_t *pdusessionTransfer_p = NULL;
      NGAP_PDUSessionResourceSetupRequestTransferIEs_t *pdusessionTransfer_ies = NULL;
        
      item_p = (NGAP_PDUSessionResourceSetupItemCxtReq_t *)ie->value.choice.PDUSessionResourceSetupListCxtReq.list.array[i];
      NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].pdusession_id = item_p->pDUSessionID;
zhenghuangkun's avatar
zhenghuangkun committed
944 945 946

      if (item_p->nAS_PDU != NULL) {
        /* Only copy NAS pdu if present */
zhenghuangkun's avatar
zhenghuangkun committed
947 948
        NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].nas_pdu.length = item_p->nAS_PDU->size;
        NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].nas_pdu.buffer =
zhenghuangkun's avatar
zhenghuangkun committed
949
          malloc(sizeof(uint8_t) * item_p->nAS_PDU->size);
zhenghuangkun's avatar
zhenghuangkun committed
950
        memcpy(NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].nas_pdu.buffer,
zhenghuangkun's avatar
zhenghuangkun committed
951
               item_p->nAS_PDU->buf, item_p->nAS_PDU->size);
zhenghuangkun's avatar
zhenghuangkun committed
952
        NGAP_DEBUG("Received NAS message with the PDUSESSION setup procedure\n");
zhenghuangkun's avatar
zhenghuangkun committed
953
      } else {
zhenghuangkun's avatar
zhenghuangkun committed
954 955 956 957 958
        NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].nas_pdu.length = 0;
        NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].nas_pdu.buffer = NULL;
      }


959
      dec_rval = aper_decode(NULL,
zhenghuangkun's avatar
zhenghuangkun committed
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
                               &asn_DEF_NGAP_PDUSessionResourceSetupRequestTransfer,
                               (void **)&pdusessionTransfer_p,
                               item_p->pDUSessionResourceSetupRequestTransfer.buf,
                               item_p->pDUSessionResourceSetupRequestTransfer.size, 0, 0);

      if(dec_rval.code != RC_OK) {
        NGAP_ERROR("could not decode PDUSessionResourceSetupRequestTransfer\n");
        return -1;
      }

      for(int j=0; j< pdusessionTransfer_p->protocolIEs.list.count; j++) {
        pdusessionTransfer_ies = pdusessionTransfer_p->protocolIEs.list.array[j];
        switch(pdusessionTransfer_ies->id) {
          /* optional PDUSessionAggregateMaximumBitRate */
          case NGAP_ProtocolIE_ID_id_PDUSessionAggregateMaximumBitRate:
            break;
        
          /* mandatory UL-NGU-UP-TNLInformation */
          case NGAP_ProtocolIE_ID_id_UL_NGU_UP_TNLInformation:
            {
              NGAP_GTPTunnel_t  *gTPTunnel_p;
981
              gTPTunnel_p = pdusessionTransfer_ies->value.choice.UPTransportLayerInformation.choice.gTPTunnel;
zhenghuangkun's avatar
zhenghuangkun committed
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
              
              /* Set the transport layer address */
              memcpy(NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].upf_addr.buffer,
                     gTPTunnel_p->transportLayerAddress.buf, gTPTunnel_p->transportLayerAddress.size);
              
              NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].upf_addr.length =
                gTPTunnel_p->transportLayerAddress.size * 8 - gTPTunnel_p->transportLayerAddress.bits_unused;
              
              /* GTP tunnel endpoint ID */
              OCTET_STRING_TO_INT32(&gTPTunnel_p->gTP_TEID, NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].gtp_teid);
            }
            
            break;
            
          /* optional AdditionalUL-NGU-UP-TNLInformation */
          case NGAP_ProtocolIE_ID_id_AdditionalUL_NGU_UP_TNLInformation:
            break;

          /* optional DataForwardingNotPossible */
          case NGAP_ProtocolIE_ID_id_DataForwardingNotPossible:
            break;

          /* mandatory PDUSessionType */
          case NGAP_ProtocolIE_ID_id_PDUSessionType:
            NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].upf_addr.pdu_session_type = (uint8_t)pdusessionTransfer_ies->value.choice.PDUSessionType;
            break;

          /* optional SecurityIndication */
          case NGAP_ProtocolIE_ID_id_SecurityIndication:
            break;

          /* optional NetworkInstance */
          case NGAP_ProtocolIE_ID_id_NetworkInstance:
            break;

          /* mandatory QosFlowSetupRequestList */
          case NGAP_ProtocolIE_ID_id_QosFlowSetupRequestList:
            {
              NGAP_QosFlowSetupRequestItem_t *qosFlowItem_p;
              
zhenghuangkun's avatar
zhenghuangkun committed
1022
              NGAP_DEBUG("QosFlowSetupRequestList.list.count %d\n", pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count);
zhenghuangkun's avatar
zhenghuangkun committed
1023 1024 1025 1026 1027 1028 1029 1030 1031
              DevAssert(pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count > 0);
              DevAssert(pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count <= NGAP_maxnoofQosFlows);

              NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].nb_qos = pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count;
                
              for(int qosIdx = 0; qosIdx < pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count; qosIdx++) {
                qosFlowItem_p = pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.array[qosIdx];
                
                /* Set the QOS informations */
1032
                NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].qos[qosIdx].qfi = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
1033 1034 1035 1036 1037 1038
                if(qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.present == NGAP_QosCharacteristics_PR_nonDynamic5QI){
                  if(qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.choice.nonDynamic5QI != NULL){
                    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].qos[qosIdx].fiveQI =
                        (uint64_t)qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.choice.nonDynamic5QI->fiveQI;
                  }
                }
zhenghuangkun's avatar
zhenghuangkun committed
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
              
                NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].qos[qosIdx].allocation_retention_priority.priority_level =
                  qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.priorityLevelARP;
                NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].qos[qosIdx].allocation_retention_priority.pre_emp_capability =
                  qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.pre_emptionCapability;
                NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).pdusession_param[i].qos[qosIdx].allocation_retention_priority.pre_emp_vulnerability =
                  qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.pre_emptionVulnerability;
              }
            }
          
            break;
            
          /* optional CommonNetworkInstance */
          case NGAP_ProtocolIE_ID_id_CommonNetworkInstance:
            break;
            
          default:
zhenghuangkun's avatar
zhenghuangkun committed
1056
            NGAP_ERROR("could not found protocolIEs id %ld\n", pdusessionTransfer_ies->id);
zhenghuangkun's avatar
zhenghuangkun committed
1057 1058
            return -1;
        }
zhenghuangkun's avatar
zhenghuangkun committed
1059 1060 1061
      }

    } /* for i... */
zhenghuangkun's avatar
zhenghuangkun committed
1062 1063 1064 1065 1066 1067 1068 1069
  } else {/* ie != NULL */
    NGAP_ERROR("could not found NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtReq\n");
  }
  
  /* id-AllowedNSSAI */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
                               NGAP_ProtocolIE_ID_id_AllowedNSSAI, true);
  
1070
  //if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
1071 1072
    NGAP_AllowedNSSAI_Item_t *allow_nssai_item_p = NULL;
  
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
    NGAP_WARN("AllowedNSSAI.list.count %d\n", ie != NULL ? ie->value.choice.AllowedNSSAI.list.count : 2);
    //NGAP_DEBUG("AllowedNSSAI.list.count %d\n", ie->value.choice.AllowedNSSAI.list.count);
    //DevAssert(ie->value.choice.AllowedNSSAI.list.count > 0);
    //DevAssert(ie->value.choice.AllowedNSSAI.list.count <= NGAP_maxnoofAllowedS_NSSAIs);

    if (ie == NULL) {
    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_allowed_nssais = 2;

    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[0].sST = 01;

    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[0].sD_flag = 1;
    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[0].sD[0] = 01;
    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[0].sD[1] = 02;
    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[0].sD[2] = 03;

    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[1].sST = 01;
 
    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[1].sD_flag = 1;
    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[1].sD[0] = 00;//11;
    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[1].sD[1] = 00;//22;
    	NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[1].sD[2] = 01;//33;
    } else {
zhenghuangkun's avatar
zhenghuangkun committed
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104

    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_allowed_nssais = ie->value.choice.AllowedNSSAI.list.count;
    
    for(i = 0; i < ie->value.choice.AllowedNSSAI.list.count; i++) {
      allow_nssai_item_p = ie->value.choice.AllowedNSSAI.list.array[i];
      
      OCTET_STRING_TO_INT8(&allow_nssai_item_p->s_NSSAI.sST, NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[i].sST);

      if(allow_nssai_item_p->s_NSSAI.sD != NULL) {
        NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[i].sD_flag = 1;
1105 1106 1107
        NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[i].sD[0] = allow_nssai_item_p->s_NSSAI.sD->buf[0];
        NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[i].sD[1] = allow_nssai_item_p->s_NSSAI.sD->buf[1];
        NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[i].sD[2] = allow_nssai_item_p->s_NSSAI.sD->buf[2];
zhenghuangkun's avatar
zhenghuangkun committed
1108 1109
      }
    }
1110 1111 1112 1113
   }
  //} else {/* ie != NULL */
  //  return -1;
  //}
zhenghuangkun's avatar
zhenghuangkun committed
1114 1115 1116 1117 1118 1119

  /* id-UESecurityCapabilities */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_UESecurityCapabilities, true);

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
1120 1121 1122 1123 1124 1125 1126 1127
    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.nRencryption_algorithms =
      BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.nRencryptionAlgorithms);
    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.nRintegrity_algorithms =
      BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.nRintegrityProtectionAlgorithms);
    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.eUTRAencryption_algorithms =
      BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.eUTRAencryptionAlgorithms);
    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.eUTRAintegrity_algorithms =
      BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.eUTRAintegrityProtectionAlgorithms);
zhenghuangkun's avatar
zhenghuangkun committed
1128 1129 1130 1131 1132
    /* id-SecurityKey : Copy the security key */
  } else {/* ie != NULL */
    return -1;
  }

1133
  /* id-MobilityRestrictionList */
zhenghuangkun's avatar
zhenghuangkun committed
1134 1135 1136 1137 1138 1139
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_SecurityKey, true);

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
    memcpy(&NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_key,
           ie->value.choice.SecurityKey.buf, ie->value.choice.SecurityKey.size);
1140
    
zhenghuangkun's avatar
zhenghuangkun committed
1141 1142 1143
  } else {/* ie != NULL */
    return -1;
  }
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176

  /* id-NAS-PDU */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
                               NGAP_ProtocolIE_ID_id_MobilityRestrictionList, false);
  
  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
    NGAP_MobilityRestrictionList_t *mobility_rest_list_p = NULL;
    mobility_rest_list_p = &ie->value.choice.MobilityRestrictionList;

    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).mobility_restriction_flag   = 1;
    TBCD_TO_MCC_MNC(&mobility_rest_list_p->servingPLMN, 
                    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).mobility_restriction.serving_plmn.mcc,
                    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).mobility_restriction.serving_plmn.mnc, 
                    NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).mobility_restriction.serving_plmn.mnc_digit_length);
  } 


  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_InitialContextSetupRequestIEs_t, ie, container,
                                 NGAP_ProtocolIE_ID_id_NAS_PDU, false);
    
  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
    if(ie->value.choice.NAS_PDU.size > 0) {
      NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).nas_pdu_flag   = 1;
      NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).nas_pdu.length = ie->value.choice.NAS_PDU.size;
      NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).nas_pdu.buffer = malloc(sizeof(uint8_t) * ie->value.choice.NAS_PDU.size);
      memcpy(NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).nas_pdu.buffer,
             ie->value.choice.NAS_PDU.buf, ie->value.choice.NAS_PDU.size);
    }
      
  } 

  itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);

zhenghuangkun's avatar
zhenghuangkun committed
1177 1178 1179 1180 1181 1182 1183 1184
  return 0;
}


static
int ngap_gNB_handle_ue_context_release_command(uint32_t   assoc_id,
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu) {
1185

zhenghuangkun's avatar
zhenghuangkun committed
1186
  ngap_gNB_amf_data_t   *amf_desc_p       = NULL;
zhenghuangkun's avatar
zhenghuangkun committed
1187 1188
  ngap_gNB_ue_context_t *ue_desc_p        = NULL;
  MessageDef            *message_p        = NULL;
1189 1190
  uint64_t                            amf_ue_ngap_id;
  NGAP_RAN_UE_NGAP_ID_t               gnb_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
1191 1192 1193
  NGAP_UEContextReleaseCommand_t     *container;
  NGAP_UEContextReleaseCommand_IEs_t *ie;
  DevAssert(pdu != NULL);
1194
  container = &pdu->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
zhenghuangkun's avatar
zhenghuangkun committed
1195

zhenghuangkun's avatar
zhenghuangkun committed
1196
  if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
1197
    NGAP_ERROR("[SCTP %d] Received UE context release command for non "
zhenghuangkun's avatar
zhenghuangkun committed
1198
               "existing AMF context\n", assoc_id);
zhenghuangkun's avatar
zhenghuangkun committed
1199 1200 1201 1202 1203 1204 1205 1206 1207
    return -1;
  }

  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_UEContextReleaseCommand_IEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_UE_NGAP_IDs, true);

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
    switch (ie->value.choice.UE_NGAP_IDs.present) {
      case NGAP_UE_NGAP_IDs_PR_uE_NGAP_ID_pair:
1208 1209
        gnb_ue_ngap_id = ie->value.choice.UE_NGAP_IDs.choice.uE_NGAP_ID_pair->rAN_UE_NGAP_ID;
        asn_INTEGER2ulong(&(ie->value.choice.UE_NGAP_IDs.choice.uE_NGAP_ID_pair->aMF_UE_NGAP_ID), &amf_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
1210 1211
        MSC_LOG_RX_MESSAGE(
          MSC_NGAP_GNB,
zhenghuangkun's avatar
zhenghuangkun committed
1212
          MSC_NGAP_AMF,
zhenghuangkun's avatar
zhenghuangkun committed
1213
          NULL,0,
zhenghuangkun's avatar
zhenghuangkun committed
1214
          "0 UEContextRelease/%s gNB_ue_ngap_id "NGAP_UE_ID_FMT" amf_ue_ngap_id "NGAP_UE_ID_FMT" len %u",
zhenghuangkun's avatar
zhenghuangkun committed
1215
          ngap_direction2String(pdu->present - 1),
1216
          gnb_ue_ngap_id,
zhenghuangkun's avatar
zhenghuangkun committed
1217
          amf_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
1218

zhenghuangkun's avatar
zhenghuangkun committed
1219
        if ((ue_desc_p = ngap_gNB_get_ue_context(amf_desc_p->ngap_gNB_instance,
1220
                         gnb_ue_ngap_id)) == NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
1221 1222 1223
          NGAP_ERROR("[SCTP %d] Received UE context release command for non "
                     "existing UE context 0x%06lx\n",
                     assoc_id,
1224
                     gnb_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
1225 1226 1227 1228 1229 1230 1231
          return -1;
        } else {
          MSC_LOG_TX_MESSAGE(
            MSC_NGAP_GNB,
            MSC_RRC_GNB,
            NULL,0,
            "0 NGAP_UE_CONTEXT_RELEASE_COMMAND/%d gNB_ue_ngap_id "NGAP_UE_ID_FMT" ",
1232
            gnb_ue_ngap_id);
1233
          message_p    = itti_alloc_new_message(TASK_NGAP, 0, NGAP_UE_CONTEXT_RELEASE_COMMAND);
zhenghuangkun's avatar
zhenghuangkun committed
1234

zhenghuangkun's avatar
zhenghuangkun committed
1235 1236
          if (ue_desc_p->amf_ue_ngap_id == 0) { // case of Detach Request and switch off from RRC_IDLE mode
            ue_desc_p->amf_ue_ngap_id = amf_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
1237 1238
          }

1239
          NGAP_UE_CONTEXT_RELEASE_COMMAND(message_p).gNB_ue_ngap_id = gnb_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
1240 1241 1242 1243 1244 1245
          itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
          return 0;
        }

        break;

1246
      //#warning "TODO mapping amf_ue_ngap_id  gnb_ue_ngap_id?"
zhenghuangkun's avatar
zhenghuangkun committed
1247

1248 1249 1250
      case NGAP_UE_NGAP_IDs_PR_aMF_UE_NGAP_ID:
        asn_INTEGER2ulong(&(ie->value.choice.UE_NGAP_IDs.choice.aMF_UE_NGAP_ID), &amf_ue_ngap_id);
        NGAP_ERROR("TO DO mapping amf_ue_ngap_id  gnb_ue_ngap_id");
zhenghuangkun's avatar
zhenghuangkun committed
1251
        (void)amf_ue_ngap_id; /* TODO: remove - it's to remove gcc warning about unused var */
zhenghuangkun's avatar
zhenghuangkun committed
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264

      case NGAP_UE_NGAP_IDs_PR_NOTHING:
      default:
        NGAP_ERROR("NGAP_UE_CONTEXT_RELEASE_COMMAND not processed, missing info elements");
        return -1;
    }
  } else {
    return -1;
  }

  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_UEContextReleaseCommand_IEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_Cause, true);
  /* TBD */
1265

heshanyun's avatar
heshanyun committed
1266
  return 0;
zhenghuangkun's avatar
zhenghuangkun committed
1267 1268 1269
}

static
zhenghuangkun's avatar
zhenghuangkun committed
1270
int ngap_gNB_handle_pdusession_setup_request(uint32_t         assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
1271 1272
                                        uint32_t         stream,
                                        NGAP_NGAP_PDU_t *pdu) {
yincong's avatar
yincong committed
1273 1274 1275
//  NGAP_AMF_UE_NGAP_ID_t       amf_ue_ngap_id;
  uint64_t                      amf_ue_ngap_id;
  NGAP_RAN_UE_NGAP_ID_t         ran_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
1276
  ngap_gNB_amf_data_t          *amf_desc_p       = NULL;
zhenghuangkun's avatar
zhenghuangkun committed
1277 1278
  ngap_gNB_ue_context_t        *ue_desc_p        = NULL;
  MessageDef                   *message_p        = NULL;
yincong's avatar
yincong committed
1279 1280
  NGAP_PDUSessionResourceSetupRequest_t     *container;
  NGAP_PDUSessionResourceSetupRequestIEs_t  *ie;
zhenghuangkun's avatar
zhenghuangkun committed
1281
  DevAssert(pdu != NULL);
1282
  container = &pdu->choice.initiatingMessage->value.choice.PDUSessionResourceSetupRequest;
zhenghuangkun's avatar
zhenghuangkun committed
1283

zhenghuangkun's avatar
zhenghuangkun committed
1284
  if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
yincong's avatar
yincong committed
1285
    NGAP_ERROR("[SCTP %d] Received pdu session resource setup request for non "
zhenghuangkun's avatar
zhenghuangkun committed
1286
               "existing AMF context\n", assoc_id);
zhenghuangkun's avatar
zhenghuangkun committed
1287 1288 1289
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
1290
  /* id-AMF-UE-NGAP-ID */
yincong's avatar
yincong committed
1291
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceSetupRequestIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
1292
                             NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID, true);
zhenghuangkun's avatar
zhenghuangkun committed
1293 1294

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
1295
     asn_INTEGER2ulong(&(ie->value.choice.AMF_UE_NGAP_ID), &amf_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
1296 1297 1298 1299 1300
  } else {
    return -1;
  }

  /* id-gNB-UE-NGAP-ID */
yincong's avatar
yincong committed
1301
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceSetupRequestIEs_t, ie, container,
1302
                         NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true);
zhenghuangkun's avatar
zhenghuangkun committed
1303 1304

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
yincong's avatar
yincong committed
1305
    ran_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID;
zhenghuangkun's avatar
zhenghuangkun committed
1306 1307 1308 1309
  } else {
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
1310
  if ((ue_desc_p = ngap_gNB_get_ue_context(amf_desc_p->ngap_gNB_instance,
yincong's avatar
yincong committed
1311 1312
                   ran_ue_ngap_id)) == NULL) {
    NGAP_ERROR("[SCTP %d] Received pdu session resource setup request for non "
zhenghuangkun's avatar
zhenghuangkun committed
1313
               "existing UE context 0x%06lx\n", assoc_id,
yincong's avatar
yincong committed
1314
               ran_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
1315 1316 1317 1318
    return -1;
  }

  /* Initial context request = UE-related procedure -> stream != 0 */
1319 1320 1321 1322 1323
  // if (stream == 0) {
  //   NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n",
  //              assoc_id, stream);
  //   return -1;
  // }
zhenghuangkun's avatar
zhenghuangkun committed
1324 1325 1326

  ue_desc_p->rx_stream = stream;

zhenghuangkun's avatar
zhenghuangkun committed
1327
  if ( ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) {
1328
    NGAP_WARN("UE context amf_ue_ngap_id is different form that of the message (%lu != %lu)",
1329
              (uint64_t)ue_desc_p->amf_ue_ngap_id, amf_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
1330 1331
  }

1332
  message_p        = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PDUSESSION_SETUP_REQ);
yincong's avatar
yincong committed
1333 1334
  NGAP_PDUSESSION_SETUP_REQ(message_p).ue_initial_id   = ue_desc_p->ue_initial_id;
  ue_desc_p->ue_initial_id = 0;
1335 1336
  NGAP_PDUSESSION_SETUP_REQ(message_p).gNB_ue_ngap_id = ue_desc_p->gNB_ue_ngap_id;
  NGAP_PDUSESSION_SETUP_REQ(message_p).amf_ue_ngap_id = ue_desc_p->amf_ue_ngap_id;
yincong's avatar
yincong committed
1337 1338

  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceSetupRequestIEs_t, ie, container,
1339
                         NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListSUReq, true);
zhenghuangkun's avatar
zhenghuangkun committed
1340 1341

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
1342
    NGAP_PDUSESSION_SETUP_REQ(message_p).nb_pdusessions_tosetup =
yincong's avatar
yincong committed
1343
      ie->value.choice.PDUSessionResourceSetupListSUReq.list.count;
zhenghuangkun's avatar
zhenghuangkun committed
1344

yincong's avatar
yincong committed
1345
    for (int i = 0; i < ie->value.choice.PDUSessionResourceSetupListSUReq.list.count; i++) {
1346 1347 1348 1349
      NGAP_PDUSessionResourceSetupItemSUReq_t          *item_p;
      asn_dec_rval_t                                   dec_rval;
      NGAP_PDUSessionResourceSetupRequestTransfer_t    *pdusessionTransfer_p   = NULL;
      NGAP_PDUSessionResourceSetupRequestTransferIEs_t *pdusessionTransfer_ies = NULL;
yincong's avatar
yincong committed
1350

1351 1352
      item_p = (NGAP_PDUSessionResourceSetupItemSUReq_t *)ie->value.choice.PDUSessionResourceSetupListSUReq.list.array[i];
      NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].pdusession_id = item_p->pDUSessionID;
yincong's avatar
yincong committed
1353 1354


1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
      // check for the NAS PDU
      if (item_p->pDUSessionNAS_PDU->size > 0 ) {
        NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].nas_pdu.length = item_p->pDUSessionNAS_PDU->size;
        NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->pDUSessionNAS_PDU->size);
        memcpy(NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].nas_pdu.buffer,
               item_p->pDUSessionNAS_PDU->buf, item_p->pDUSessionNAS_PDU->size);
        // NGAP_INFO("received a NAS PDU with size %d (%02x.%02x)\n",NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].nas_pdu.length, item_p->nAS_PDU.buf[0], item_p->nAS_PDU.buf[1]);
      } else {
        NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].nas_pdu.length = 0;
        NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].nas_pdu.buffer = NULL;
        NGAP_WARN("NAS PDU is not provided, generate a PDUSESSION_SETUP Failure (TBD) back to AMF \n");
      }
yincong's avatar
yincong committed
1367

1368
      dec_rval = aper_decode(NULL,
1369 1370 1371 1372
                               &asn_DEF_NGAP_PDUSessionResourceSetupRequestTransfer,
                               (void **)&pdusessionTransfer_p,
                               item_p->pDUSessionResourceSetupRequestTransfer.buf,
                               item_p->pDUSessionResourceSetupRequestTransfer.size, 0, 0);
yincong's avatar
yincong committed
1373

1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
      if(dec_rval.code != RC_OK) {
        NGAP_ERROR("could not decode PDUSessionResourceSetupRequestTransfer\n");
        return -1;
      }

      for(int j=0; j< pdusessionTransfer_p->protocolIEs.list.count; j++) {
        pdusessionTransfer_ies = pdusessionTransfer_p->protocolIEs.list.array[j];

        switch(pdusessionTransfer_ies->id) {
          /* optional PDUSessionAggregateMaximumBitRate */
          case NGAP_ProtocolIE_ID_id_PDUSessionAggregateMaximumBitRate:
            break;

          /* mandatory UL-NGU-UP-TNLInformation */
          case NGAP_ProtocolIE_ID_id_UL_NGU_UP_TNLInformation:
          {
          	NGAP_GTPTunnel_t  *gTPTunnel_p;
1391
              gTPTunnel_p = pdusessionTransfer_ies->value.choice.UPTransportLayerInformation.choice.gTPTunnel;
1392 1393 1394 1395 1396 1397 1398 1399
              /* The transport layer address for the IP packets */
              OCTET_STRING_TO_INT32(&gTPTunnel_p->gTP_TEID, NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].gtp_teid);
              NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].upf_addr.length =
              		gTPTunnel_p->transportLayerAddress.size * 8 - gTPTunnel_p->transportLayerAddress.bits_unused;
              memcpy(NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].upf_addr.buffer ,
              		gTPTunnel_p->transportLayerAddress.buf, gTPTunnel_p->transportLayerAddress.size);
          }
            break;
yincong's avatar
yincong committed
1400

1401 1402 1403
          /* optional AdditionalUL-NGU-UP-TNLInformation */
          case NGAP_ProtocolIE_ID_id_AdditionalUL_NGU_UP_TNLInformation:
            break;
yincong's avatar
yincong committed
1404

1405 1406 1407
          /* optional DataForwardingNotPossible */
          case NGAP_ProtocolIE_ID_id_DataForwardingNotPossible:
            break;
yincong's avatar
yincong committed
1408

1409 1410 1411 1412
          /* mandatory PDUSessionType */
          case NGAP_ProtocolIE_ID_id_PDUSessionType:
            NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].upf_addr.pdu_session_type = (uint8_t)pdusessionTransfer_ies->value.choice.PDUSessionType;
            break;
yincong's avatar
yincong committed
1413

1414 1415 1416
          /* optional SecurityIndication */
          case NGAP_ProtocolIE_ID_id_SecurityIndication:
            break;
yincong's avatar
yincong committed
1417

1418 1419 1420
          /* optional NetworkInstance */
          case NGAP_ProtocolIE_ID_id_NetworkInstance:
            break;
yincong's avatar
yincong committed
1421

1422 1423 1424 1425
          /* mandatory QosFlowSetupRequestList */
          case NGAP_ProtocolIE_ID_id_QosFlowSetupRequestList:
          {
            NGAP_QosFlowSetupRequestItem_t *qosFlowItem_p;
yincong's avatar
yincong committed
1426

1427 1428 1429
            NGAP_DEBUG("servedGUAMIs.list.count %d\n", pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count);
            DevAssert(pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count > 0);
            DevAssert(pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count <= NGAP_maxnoofQosFlows);
yincong's avatar
yincong committed
1430

1431
            NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].nb_qos = pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count;
yincong's avatar
yincong committed
1432

1433 1434
            for(int qosIdx = 0; qosIdx < pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.count; qosIdx++){
              qosFlowItem_p = pdusessionTransfer_ies->value.choice.QosFlowSetupRequestList.list.array[qosIdx];
yincong's avatar
yincong committed
1435

1436
              /* Set the QOS informations */
1437 1438 1439 1440 1441 1442 1443
              NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].qos[qosIdx].qfi = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
              if(qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.present == NGAP_QosCharacteristics_PR_nonDynamic5QI){
                if(qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.choice.nonDynamic5QI != NULL){
                  NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].qos[qosIdx].fiveQI = 
                    (uint64_t)qosFlowItem_p->qosFlowLevelQosParameters.qosCharacteristics.choice.nonDynamic5QI->fiveQI;
                }
              }
1444 1445 1446 1447 1448 1449
              NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].qos[qosIdx].allocation_retention_priority.priority_level =
                qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.priorityLevelARP;
              NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].qos[qosIdx].allocation_retention_priority.pre_emp_capability =
                qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.pre_emptionCapability;
              NGAP_PDUSESSION_SETUP_REQ(message_p).pdusession_setup_params[i].qos[qosIdx].allocation_retention_priority.pre_emp_vulnerability =
                qosFlowItem_p->qosFlowLevelQosParameters.allocationAndRetentionPriority.pre_emptionVulnerability;
yincong's avatar
yincong committed
1450
            }
1451 1452
          }
          break;
yincong's avatar
yincong committed
1453

1454 1455 1456
          /* optional CommonNetworkInstance */
          case NGAP_ProtocolIE_ID_id_CommonNetworkInstance:
            break;
yincong's avatar
yincong committed
1457

1458 1459 1460 1461 1462
          default:
            NGAP_ERROR("could not found protocolIEs id %ld\n", pdusessionTransfer_ies->id);
            return -1;
        }
      }/* for j... */
yincong's avatar
yincong committed
1463
    } /* for i... */
zhenghuangkun's avatar
zhenghuangkun committed
1464
    itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
yincong's avatar
yincong committed
1465
  }else {/* ie == NULL */
1466 1467
    NGAP_ERROR("could not found NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListSUReq\n");
    return -1;
zhenghuangkun's avatar
zhenghuangkun committed
1468 1469 1470 1471
  }
  return 0;
}

yincong's avatar
yincong committed
1472

zhenghuangkun's avatar
zhenghuangkun committed
1473 1474 1475 1476
static
int ngap_gNB_handle_paging(uint32_t               assoc_id,
                           uint32_t               stream,
                           NGAP_NGAP_PDU_t       *pdu) {
zhenghuangkun's avatar
zhenghuangkun committed
1477

zhenghuangkun's avatar
zhenghuangkun committed
1478
  ngap_gNB_amf_data_t   *amf_desc_p        = NULL;
zhenghuangkun's avatar
zhenghuangkun committed
1479 1480 1481 1482 1483
  ngap_gNB_instance_t   *ngap_gNB_instance = NULL;
  MessageDef            *message_p         = NULL;
  NGAP_Paging_t         *container;
  NGAP_PagingIEs_t      *ie;
  DevAssert(pdu != NULL);
1484
  container = &pdu->choice.initiatingMessage->value.choice.Paging;
zhenghuangkun's avatar
zhenghuangkun committed
1485 1486
  // received Paging Message from AMF
  NGAP_DEBUG("[SCTP %d] Received Paging Message From AMF\n",assoc_id);
zhenghuangkun's avatar
zhenghuangkun committed
1487 1488 1489 1490 1491 1492 1493 1494

  /* Paging procedure -> stream != 0 */
  if (stream == 0) {
    LOG_W(NGAP,"[SCTP %d] Received Paging procedure on stream (%d)\n",
          assoc_id, stream);
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
1495
  if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
1496
    NGAP_ERROR("[SCTP %d] Received Paging for non "
zhenghuangkun's avatar
zhenghuangkun committed
1497
               "existing AMF context\n", assoc_id);
zhenghuangkun's avatar
zhenghuangkun committed
1498 1499 1500
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
1501
  ngap_gNB_instance = amf_desc_p->ngap_gNB_instance;
zhenghuangkun's avatar
zhenghuangkun committed
1502 1503

  if (ngap_gNB_instance == NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
1504
    NGAP_ERROR("[SCTP %d] Received Paging for non existing AMF context : ngap_gNB_instance is NULL\n",
zhenghuangkun's avatar
zhenghuangkun committed
1505 1506 1507 1508
               assoc_id);
    return -1;
  }

1509
  message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PAGING_IND);
zhenghuangkun's avatar
zhenghuangkun committed
1510 1511 1512
  /* convert NGAP_PagingIEs_t to ngap_paging_ind_t */
  /* id-UEIdentityIndexValue : convert UE Identity Index value */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PagingIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
1513
                             NGAP_ProtocolIE_ID_id_UEPagingIdentity, true);
zhenghuangkun's avatar
zhenghuangkun committed
1514 1515

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
1516 1517 1518
    OCTET_STRING_TO_INT16(&ie->value.choice.UEPagingIdentity.choice.fiveG_S_TMSI->aMFSetID, NGAP_PAGING_IND(message_p).ue_paging_identity.s_tmsi.amf_set_id);
    OCTET_STRING_TO_INT8(&ie->value.choice.UEPagingIdentity.choice.fiveG_S_TMSI->aMFPointer, NGAP_PAGING_IND(message_p).ue_paging_identity.s_tmsi.amf_pointer);
    OCTET_STRING_TO_INT32(&ie->value.choice.UEPagingIdentity.choice.fiveG_S_TMSI->fiveG_TMSI, NGAP_PAGING_IND(message_p).ue_paging_identity.s_tmsi.m_tmsi);
zhenghuangkun's avatar
zhenghuangkun committed
1519 1520 1521 1522 1523 1524

    NGAP_DEBUG("[SCTP %d] Received Paging Identity amf_set_id %d, amf_pointer %d, m_tmsi %d\n",
               assoc_id,
               NGAP_PAGING_IND(message_p).ue_paging_identity.s_tmsi.amf_set_id,
               NGAP_PAGING_IND(message_p).ue_paging_identity.s_tmsi.amf_pointer,
               NGAP_PAGING_IND(message_p).ue_paging_identity.s_tmsi.m_tmsi);
zhenghuangkun's avatar
zhenghuangkun committed
1525 1526 1527 1528 1529
  } else {
    return -1;
  }


zhenghuangkun's avatar
zhenghuangkun committed
1530
  NGAP_PAGING_IND(message_p).paging_drx = NGAP_PAGING_DRX_256;
zhenghuangkun's avatar
zhenghuangkun committed
1531 1532
  /* id-pagingDRX */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PagingIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
1533
                             NGAP_ProtocolIE_ID_id_PagingDRX, false);
zhenghuangkun's avatar
zhenghuangkun committed
1534 1535 1536 1537 1538

  /* optional */
  if (ie) {
    NGAP_PAGING_IND(message_p).paging_drx = ie->value.choice.PagingDRX;
  } else {
zhenghuangkun's avatar
zhenghuangkun committed
1539
    NGAP_PAGING_IND(message_p).paging_drx = NGAP_PAGING_DRX_256;
zhenghuangkun's avatar
zhenghuangkun committed
1540 1541 1542 1543 1544 1545 1546
  }

  memset (&NGAP_PAGING_IND(message_p).plmn_identity[0], 0, sizeof(plmn_identity_t)*256);
  memset (&NGAP_PAGING_IND(message_p).tac[0], 0, sizeof(int16_t)*256);
  NGAP_PAGING_IND(message_p).tai_size = 0;
  /* id-TAIList */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PagingIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
1547
                             NGAP_ProtocolIE_ID_id_TAIListForPaging, true);
zhenghuangkun's avatar
zhenghuangkun committed
1548 1549

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
1550
    NGAP_INFO("[SCTP %d] Received Paging taiList For Paging: count %d\n", assoc_id, ie->value.choice.TAIListForPaging.list.count);
zhenghuangkun's avatar
zhenghuangkun committed
1551

zhenghuangkun's avatar
zhenghuangkun committed
1552 1553 1554 1555
    for (int i = 0; i < ie->value.choice.TAIListForPaging.list.count; i++) {
      NGAP_TAIListForPagingItem_t *item_p;
      item_p = (NGAP_TAIListForPagingItem_t *)ie->value.choice.TAIListForPaging.list.array[i];
      TBCD_TO_MCC_MNC(&(item_p->tAI.pLMNIdentity), NGAP_PAGING_IND(message_p).plmn_identity[i].mcc,
zhenghuangkun's avatar
zhenghuangkun committed
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569
                      NGAP_PAGING_IND(message_p).plmn_identity[i].mnc,
                      NGAP_PAGING_IND(message_p).plmn_identity[i].mnc_digit_length);
      OCTET_STRING_TO_INT16(&(item_p->tAI.tAC), NGAP_PAGING_IND(message_p).tac[i]);
      NGAP_PAGING_IND(message_p).tai_size++;
      NGAP_DEBUG("[SCTP %d] Received Paging: MCC %d, MNC %d, TAC %d\n", assoc_id,
                 NGAP_PAGING_IND(message_p).plmn_identity[i].mcc,
                 NGAP_PAGING_IND(message_p).plmn_identity[i].mnc,
                 NGAP_PAGING_IND(message_p).tac[i]);
    }
  } else {
    return -1;
  }

  //paging parameter values
zhenghuangkun's avatar
zhenghuangkun committed
1570 1571 1572 1573
  NGAP_DEBUG("[SCTP %d] Received Paging parameters: Paging Identity amf_set_id %d amf_pointer %d m_tmsi %d paging_drx %d paging_priority %d\n",assoc_id,
             NGAP_PAGING_IND(message_p).ue_paging_identity.s_tmsi.amf_set_id,
             NGAP_PAGING_IND(message_p).ue_paging_identity.s_tmsi.amf_pointer,
             NGAP_PAGING_IND(message_p).ue_paging_identity.s_tmsi.m_tmsi,
zhenghuangkun's avatar
zhenghuangkun committed
1574 1575 1576
             NGAP_PAGING_IND(message_p).paging_drx, NGAP_PAGING_IND(message_p).paging_priority);
  /* send message to RRC */
  itti_send_msg_to_task(TASK_RRC_GNB, ngap_gNB_instance->instance, message_p);
zhenghuangkun's avatar
zhenghuangkun committed
1577

zhenghuangkun's avatar
zhenghuangkun committed
1578 1579 1580 1581
  return 0;
}

static
zhenghuangkun's avatar
zhenghuangkun committed
1582
int ngap_gNB_handle_pdusession_modify_request(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
1583 1584
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu) {
zhenghuangkun's avatar
zhenghuangkun committed
1585

zhenghuangkun's avatar
zhenghuangkun committed
1586 1587
  int i, nb_of_pdusessions_failed;
  ngap_gNB_amf_data_t           *amf_desc_p       = NULL;
zhenghuangkun's avatar
zhenghuangkun committed
1588 1589
  ngap_gNB_ue_context_t         *ue_desc_p        = NULL;
  MessageDef                    *message_p        = NULL;
zhenghuangkun's avatar
zhenghuangkun committed
1590 1591 1592 1593
  NGAP_PDUSessionResourceModifyRequest_t     *container;
  NGAP_PDUSessionResourceModifyRequestIEs_t  *ie;
  NGAP_RAN_UE_NGAP_ID_t         gnb_ue_ngap_id;
  uint64_t                      amf_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
1594
  DevAssert(pdu != NULL);
1595
  container = &pdu->choice.initiatingMessage->value.choice.PDUSessionResourceModifyRequest;
zhenghuangkun's avatar
zhenghuangkun committed
1596

zhenghuangkun's avatar
zhenghuangkun committed
1597
  if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
1598
    NGAP_ERROR("[SCTP %d] Received PDUSession Resource modify request for non "
zhenghuangkun's avatar
zhenghuangkun committed
1599
               "existing AMF context\n", assoc_id);
zhenghuangkun's avatar
zhenghuangkun committed
1600 1601 1602
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
1603
  /* id-AMF-UE-NGAP-ID */
zhenghuangkun's avatar
zhenghuangkun committed
1604
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceModifyRequestIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
1605
                             NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID, true);
zhenghuangkun's avatar
zhenghuangkun committed
1606 1607

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
1608
    asn_INTEGER2ulong(&(ie->value.choice.AMF_UE_NGAP_ID), &amf_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
1609 1610 1611 1612
  } else {
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
1613 1614 1615
  /* id-RAN-UE-NGAP-ID */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceModifyRequestIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true);
zhenghuangkun's avatar
zhenghuangkun committed
1616 1617

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
1618
    gnb_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID;
zhenghuangkun's avatar
zhenghuangkun committed
1619 1620 1621 1622
  } else {
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
1623
  if ((ue_desc_p = ngap_gNB_get_ue_context(amf_desc_p->ngap_gNB_instance,
zhenghuangkun's avatar
zhenghuangkun committed
1624 1625 1626 1627
                   gnb_ue_ngap_id)) == NULL) {
    NGAP_ERROR("[SCTP %d] Received PDUSession Resource modify request for non "
               "existing UE context 0x%08lx\n", assoc_id,
               gnb_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
1628 1629 1630
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
1631
  /* PDUSession Resource modify request = UE-related procedure -> stream != 0 */
zhenghuangkun's avatar
zhenghuangkun committed
1632 1633 1634 1635 1636 1637 1638 1639
  if (stream == 0) {
    NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n",
               assoc_id, stream);
    return -1;
  }

  ue_desc_p->rx_stream = stream;

zhenghuangkun's avatar
zhenghuangkun committed
1640
  if (ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) {
zhenghuangkun's avatar
zhenghuangkun committed
1641 1642
    NGAP_WARN("UE context amf_ue_ngap_id is different form that of the message (%ld != %ld)",
              (uint64_t)ue_desc_p->amf_ue_ngap_id, amf_ue_ngap_id);
1643
    message_p = itti_alloc_new_message (TASK_RRC_GNB, 0, NGAP_PDUSESSION_MODIFY_RESP);
zhenghuangkun's avatar
zhenghuangkun committed
1644 1645 1646
    NGAP_PDUSESSION_MODIFY_RESP (message_p).gNB_ue_ngap_id = gnb_ue_ngap_id;
    NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceModifyRequestIEs_t, ie, container,
                               NGAP_ProtocolIE_ID_id_PDUSessionResourceModifyListModReq, true);
zhenghuangkun's avatar
zhenghuangkun committed
1647 1648

    if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
1649 1650 1651 1652 1653
      for(nb_of_pdusessions_failed = 0; nb_of_pdusessions_failed < ie->value.choice.PDUSessionResourceModifyListModReq.list.count; nb_of_pdusessions_failed++) {
        NGAP_PDUSessionResourceModifyItemModReq_t *item_p;
        item_p = (NGAP_PDUSessionResourceModifyItemModReq_t *)ie->value.choice.PDUSessionResourceModifyListModReq.list.array[nb_of_pdusessions_failed];
        
        NGAP_PDUSESSION_MODIFY_RESP(message_p).pdusessions_failed[nb_of_pdusessions_failed].pdusession_id = item_p->pDUSessionID;
zhenghuangkun's avatar
zhenghuangkun committed
1654
        NGAP_PDUSESSION_MODIFY_RESP(message_p).pdusessions_failed[nb_of_pdusessions_failed].cause = NGAP_Cause_PR_radioNetwork;
zhenghuangkun's avatar
zhenghuangkun committed
1655
        NGAP_PDUSESSION_MODIFY_RESP(message_p).pdusessions_failed[nb_of_pdusessions_failed].cause_value = NGAP_CauseRadioNetwork_unknown_local_UE_NGAP_ID;
zhenghuangkun's avatar
zhenghuangkun committed
1656 1657 1658 1659 1660
      }
    } else {
      return -1;
    }

zhenghuangkun's avatar
zhenghuangkun committed
1661 1662 1663
    NGAP_PDUSESSION_MODIFY_RESP(message_p).nb_of_pdusessions_failed = nb_of_pdusessions_failed;
    ngap_gNB_pdusession_modify_resp(amf_desc_p->ngap_gNB_instance->instance,
                               &NGAP_PDUSESSION_MODIFY_RESP(message_p));
zhenghuangkun's avatar
zhenghuangkun committed
1664 1665 1666 1667 1668
    itti_free(TASK_RRC_GNB,message_p);
    message_p = NULL;
    return -1;
  }

1669
  message_p        = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PDUSESSION_MODIFY_REQ);
zhenghuangkun's avatar
zhenghuangkun committed
1670 1671
  NGAP_PDUSESSION_MODIFY_REQ(message_p).ue_initial_id  = ue_desc_p->ue_initial_id;
  NGAP_PDUSESSION_MODIFY_REQ(message_p).amf_ue_ngap_id  = amf_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
1672 1673 1674 1675
  NGAP_PDUSESSION_MODIFY_REQ(message_p).gNB_ue_ngap_id  = gnb_ue_ngap_id;
  /* id-PDUSessionResourceModifyListModReq */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceModifyRequestIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_PDUSessionResourceModifyListModReq, true);
zhenghuangkun's avatar
zhenghuangkun committed
1676 1677

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
zhenghuangkun's avatar
zhenghuangkun committed
1678
    NGAP_PDUSESSION_MODIFY_REQ(message_p).nb_pdusessions_tomodify =
zhenghuangkun's avatar
zhenghuangkun committed
1679
      ie->value.choice.PDUSessionResourceModifyListModReq.list.count;
zhenghuangkun's avatar
zhenghuangkun committed
1680

zhenghuangkun's avatar
zhenghuangkun committed
1681 1682 1683 1684 1685 1686 1687 1688 1689
    for (i = 0; i < ie->value.choice.PDUSessionResourceModifyListModReq.list.count; i++) {
      NGAP_PDUSessionResourceModifyItemModReq_t         *item_p;
      asn_dec_rval_t                                    dec_rval;
      NGAP_PDUSessionResourceModifyRequestTransfer_t    *pdusessionTransfer_p = NULL;
      NGAP_PDUSessionResourceModifyRequestTransferIEs_t *pdusessionTransfer_ies = NULL;
        
      item_p = (NGAP_PDUSessionResourceModifyItemModReq_t *)ie->value.choice.PDUSessionResourceModifyListModReq.list.array[i];
    
      NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].pdusession_id = item_p->pDUSessionID;
zhenghuangkun's avatar
zhenghuangkun committed
1690 1691

      // check for the NAS PDU
zhenghuangkun's avatar
zhenghuangkun committed
1692 1693 1694
      if (item_p->nAS_PDU != NULL && item_p->nAS_PDU->size > 0 ) {
        NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].nas_pdu.length = item_p->nAS_PDU->size;
        NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU->size);
zhenghuangkun's avatar
zhenghuangkun committed
1695
        memcpy(NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].nas_pdu.buffer,
zhenghuangkun's avatar
zhenghuangkun committed
1696
               item_p->nAS_PDU->buf, item_p->nAS_PDU->size);
zhenghuangkun's avatar
zhenghuangkun committed
1697
      } else {
zhenghuangkun's avatar
zhenghuangkun committed
1698 1699
        NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].nas_pdu.length = 0;
        NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].nas_pdu.buffer = NULL;
zhenghuangkun's avatar
zhenghuangkun committed
1700 1701 1702
        continue;
      }

1703
      dec_rval = aper_decode(NULL,
zhenghuangkun's avatar
zhenghuangkun committed
1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
                             &asn_DEF_NGAP_PDUSessionResourceModifyRequestTransfer,
                             (void **)&pdusessionTransfer_p,
                             item_p->pDUSessionResourceModifyRequestTransfer.buf,
                             item_p->pDUSessionResourceModifyRequestTransfer.size, 0, 0);

      if(dec_rval.code != RC_OK) {
        NGAP_ERROR("could not decode PDUSessionResourceModifyRequestTransfer\n");
        return -1;
      }

      for(int j=0; j< pdusessionTransfer_p->protocolIEs.list.count; j++) {
        pdusessionTransfer_ies = pdusessionTransfer_p->protocolIEs.list.array[j];
        switch(pdusessionTransfer_ies->id) {
          /* optional PDUSessionAggregateMaximumBitRate */
          case NGAP_ProtocolIE_ID_id_PDUSessionAggregateMaximumBitRate:
            break;
        
          /* optional UL-NGU-UP-TNLModifyList */
          case NGAP_ProtocolIE_ID_id_UL_NGU_UP_TNLModifyList:
            break;
            
          /* optional NetworkInstance */
          case NGAP_ProtocolIE_ID_id_NetworkInstance:
            break;

          /* optional QosFlowAddOrModifyRequestList */
          case NGAP_ProtocolIE_ID_id_QosFlowAddOrModifyRequestList:
            {
              NGAP_QosFlowAddOrModifyRequestItem_t *qosFlowItem_p;
              
              NGAP_DEBUG("QosFlowAddOrModifyRequestList.list.count %d\n", pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.count);
              DevAssert(pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.count > 0);
              DevAssert(pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.count <= NGAP_maxnoofQosFlows);

              NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].nb_qos = pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.count;
                
              for(int qosIdx = 0; qosIdx < pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.count; qosIdx++) {
                qosFlowItem_p = pdusessionTransfer_ies->value.choice.QosFlowAddOrModifyRequestList.list.array[qosIdx];
                
                /* Set the QOS informations */
1744
                NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].qos[qosIdx].qfi = (uint8_t)qosFlowItem_p->qosFlowIdentifier;
zhenghuangkun's avatar
zhenghuangkun committed
1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773
                if(qosFlowItem_p->qosFlowLevelQosParameters) {
                  NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].qos[qosIdx].allocation_retention_priority.priority_level =
                    qosFlowItem_p->qosFlowLevelQosParameters->allocationAndRetentionPriority.priorityLevelARP;
                  NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].qos[qosIdx].allocation_retention_priority.pre_emp_capability =
                    qosFlowItem_p->qosFlowLevelQosParameters->allocationAndRetentionPriority.pre_emptionCapability;
                  NGAP_PDUSESSION_MODIFY_REQ(message_p).pdusession_modify_params[i].qos[qosIdx].allocation_retention_priority.pre_emp_vulnerability =
                    qosFlowItem_p->qosFlowLevelQosParameters->allocationAndRetentionPriority.pre_emptionVulnerability;
                }
              }
            }
            break;

          /* optional QosFlowToReleaseList */
          case NGAP_ProtocolIE_ID_id_QosFlowToReleaseList:
            break;

          /* optional AdditionalUL-NGU-UP-TNLInformation */
          case NGAP_ProtocolIE_ID_id_AdditionalUL_NGU_UP_TNLInformation:
            break;

          /* optional CommonNetworkInstance */
          case NGAP_ProtocolIE_ID_id_CommonNetworkInstance:
            break;
            
          default:
            NGAP_ERROR("could not found protocolIEs id %ld\n", pdusessionTransfer_ies->id);
            return -1;
        }
      }
zhenghuangkun's avatar
zhenghuangkun committed
1774 1775 1776 1777 1778 1779
    }

    itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
  } else { /* of if (ie != NULL)*/
    return -1;
  }
zhenghuangkun's avatar
zhenghuangkun committed
1780

zhenghuangkun's avatar
zhenghuangkun committed
1781 1782
  return 0;
}
1783
// handle pdu session release command and send it to rrc_end
zhenghuangkun's avatar
zhenghuangkun committed
1784
static
zhenghuangkun's avatar
zhenghuangkun committed
1785
int ngap_gNB_handle_pdusession_release_command(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
1786 1787
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu) {
1788

zhenghuangkun's avatar
zhenghuangkun committed
1789
  int i;
zhenghuangkun's avatar
zhenghuangkun committed
1790
  ngap_gNB_amf_data_t   *amf_desc_p       = NULL;
zhenghuangkun's avatar
zhenghuangkun committed
1791 1792
  ngap_gNB_ue_context_t *ue_desc_p        = NULL;
  MessageDef            *message_p        = NULL;
1793 1794 1795 1796
  NGAP_PDUSessionResourceReleaseCommand_t     *container;
  NGAP_PDUSessionResourceReleaseCommandIEs_t  *ie;
  NGAP_RAN_UE_NGAP_ID_t           gnb_ue_ngap_id;
  uint64_t                        amf_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
1797
  DevAssert(pdu != NULL);
1798
  container = &pdu->choice.initiatingMessage->value.choice.PDUSessionResourceReleaseCommand;
zhenghuangkun's avatar
zhenghuangkun committed
1799

zhenghuangkun's avatar
zhenghuangkun committed
1800
  if ((amf_desc_p = ngap_gNB_get_AMF(NULL, assoc_id, 0)) == NULL) {
1801
    NGAP_ERROR("[SCTP %d] Received pdu session release command for non existing AMF context\n", assoc_id);
zhenghuangkun's avatar
zhenghuangkun committed
1802 1803 1804 1805
    return -1;
  }


zhenghuangkun's avatar
zhenghuangkun committed
1806
  /* id-AMF-UE-NGAP-ID */
1807
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceReleaseCommandIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
1808
                             NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID, true);
zhenghuangkun's avatar
zhenghuangkun committed
1809 1810

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
1811
    asn_INTEGER2ulong(&(ie->value.choice.AMF_UE_NGAP_ID), &amf_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
1812 1813 1814 1815
  } else {
    return -1;
  }

1816 1817 1818
  /* id-RAN-UE-NGAP-ID */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceReleaseCommandIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_RAN_UE_NGAP_ID, true);
zhenghuangkun's avatar
zhenghuangkun committed
1819 1820

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
1821
    gnb_ue_ngap_id = ie->value.choice.RAN_UE_NGAP_ID;
zhenghuangkun's avatar
zhenghuangkun committed
1822 1823 1824 1825
  } else {
    return -1;
  }

zhenghuangkun's avatar
zhenghuangkun committed
1826
  if ((ue_desc_p = ngap_gNB_get_ue_context(amf_desc_p->ngap_gNB_instance,
1827 1828 1829
                   gnb_ue_ngap_id)) == NULL) {
    NGAP_ERROR("[SCTP %d] Received PDUSession Resource release command for non existing UE context 0x%08lx\n", assoc_id,
               ie->value.choice.RAN_UE_NGAP_ID);
zhenghuangkun's avatar
zhenghuangkun committed
1830 1831 1832 1833
    return -1;
  }

  /* Initial context request = UE-related procedure -> stream != 0 */
1834 1835 1836 1837 1838
  // if (stream == 0) {
  //   NGAP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d)\n",
  //              assoc_id, stream);
  //   return -1;
  // }
zhenghuangkun's avatar
zhenghuangkun committed
1839 1840 1841

  ue_desc_p->rx_stream = stream;

zhenghuangkun's avatar
zhenghuangkun committed
1842
  if (ue_desc_p->amf_ue_ngap_id != amf_ue_ngap_id) {
1843 1844
    NGAP_WARN("UE context amf_ue_ngap_id is different form that of the message (%lu != %lu)",
              (uint64_t)ue_desc_p->amf_ue_ngap_id, amf_ue_ngap_id);
zhenghuangkun's avatar
zhenghuangkun committed
1845 1846
  }

1847
  NGAP_DEBUG("[SCTP %d] Received pdu session release command for gNB_UE_NGAP_ID %lu amf_ue_ngap_id %lu\n",
1848
             assoc_id, gnb_ue_ngap_id, amf_ue_ngap_id);
1849
  message_p = itti_alloc_new_message(TASK_NGAP, 0, NGAP_PDUSESSION_RELEASE_COMMAND);
1850
  NGAP_PDUSESSION_RELEASE_COMMAND(message_p).gNB_ue_ngap_id = gnb_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
1851
  NGAP_PDUSESSION_RELEASE_COMMAND(message_p).amf_ue_ngap_id = amf_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
1852
  /* id-NAS-PDU */
1853
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceReleaseCommandIEs_t, ie, container,
zhenghuangkun's avatar
zhenghuangkun committed
1854 1855 1856
                             NGAP_ProtocolIE_ID_id_NAS_PDU, false);

  if(ie && ie->value.choice.NAS_PDU.size > 0) {
zhenghuangkun's avatar
zhenghuangkun committed
1857
    NGAP_PDUSESSION_RELEASE_COMMAND(message_p).nas_pdu.length = ie->value.choice.NAS_PDU.size;
1858
    NGAP_PDUSESSION_RELEASE_COMMAND(message_p).nas_pdu.buffer = malloc(sizeof(uint8_t) * ie->value.choice.NAS_PDU.size);
zhenghuangkun's avatar
zhenghuangkun committed
1859
    memcpy(NGAP_PDUSESSION_RELEASE_COMMAND(message_p).nas_pdu.buffer,
zhenghuangkun's avatar
zhenghuangkun committed
1860 1861 1862
           ie->value.choice.NAS_PDU.buf,
           ie->value.choice.NAS_PDU.size);
  } else {
zhenghuangkun's avatar
zhenghuangkun committed
1863 1864
    NGAP_PDUSESSION_RELEASE_COMMAND(message_p).nas_pdu.length = 0;
    NGAP_PDUSESSION_RELEASE_COMMAND(message_p).nas_pdu.buffer = NULL;
zhenghuangkun's avatar
zhenghuangkun committed
1865 1866
  }

1867 1868 1869
  /* id-PDUSessionResourceToReleaseListRelCmd */
  NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_PDUSessionResourceReleaseCommandIEs_t, ie, container,
                             NGAP_ProtocolIE_ID_id_PDUSessionResourceToReleaseListRelCmd, true);
zhenghuangkun's avatar
zhenghuangkun committed
1870 1871

  if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
1872
    NGAP_PDUSESSION_RELEASE_COMMAND(message_p).nb_pdusessions_torelease = ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.count;
zhenghuangkun's avatar
zhenghuangkun committed
1873

1874 1875 1876 1877 1878
    for (i = 0; i < ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.count; i++) {
      NGAP_PDUSessionResourceToReleaseItemRelCmd_t *item_p;
      item_p = (NGAP_PDUSessionResourceToReleaseItemRelCmd_t *)ie->value.choice.PDUSessionResourceToReleaseListRelCmd.list.array[i];
    
      NGAP_PDUSESSION_RELEASE_COMMAND(message_p).pdusession_release_params[i].pdusession_id = item_p->pDUSessionID;
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890
      if(item_p->pDUSessionResourceReleaseCommandTransfer.size > 0) {
        NGAP_PDUSESSION_RELEASE_COMMAND(message_p).pdusession_release_params[i].transfer_length = item_p->pDUSessionResourceReleaseCommandTransfer.size;
        NGAP_PDUSESSION_RELEASE_COMMAND(message_p).pdusession_release_params[i].transfer_buffer = malloc(sizeof(uint8_t) * item_p->pDUSessionResourceReleaseCommandTransfer.size);
        memcpy(NGAP_PDUSESSION_RELEASE_COMMAND(message_p).pdusession_release_params[i].transfer_buffer,
               item_p->pDUSessionResourceReleaseCommandTransfer.buf,
               item_p->pDUSessionResourceReleaseCommandTransfer.size);
      }else {
        NGAP_PDUSESSION_RELEASE_COMMAND(message_p).pdusession_release_params[i].transfer_length = 0;
        NGAP_PDUSESSION_RELEASE_COMMAND(message_p).pdusession_release_params[i].transfer_buffer = NULL;
        NGAP_ERROR("[NGAP] Received pdu session release command for pDUSessionResourceReleaseCommandTransfer is NULL!\n");
      }
      NGAP_DEBUG("[NGAP] Received pdu session release command for pDUSessionID id %ld\n", item_p->pDUSessionID);
zhenghuangkun's avatar
zhenghuangkun committed
1891 1892 1893 1894 1895 1896
    }
  } else {
    return -1;
  }

  itti_send_msg_to_task(TASK_RRC_GNB, ue_desc_p->gNB_instance->instance, message_p);
1897

zhenghuangkun's avatar
zhenghuangkun committed
1898 1899 1900 1901
  return 0;
}

static
zhenghuangkun's avatar
zhenghuangkun committed
1902
int ngap_gNB_handle_ng_path_switch_request_ack(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
1903 1904
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu) {
1905
  // TODO
zhenghuangkun's avatar
zhenghuangkun committed
1906 1907 1908 1909
  return 0;
}

static
zhenghuangkun's avatar
zhenghuangkun committed
1910
int ngap_gNB_handle_ng_path_switch_request_failure(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
1911 1912 1913
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu) {

1914
  // TODO
zhenghuangkun's avatar
zhenghuangkun committed
1915 1916 1917 1918
  return 0;
}

static
zhenghuangkun's avatar
zhenghuangkun committed
1919
int ngap_gNB_handle_ng_ENDC_pdusession_modification_confirm(uint32_t               assoc_id,
zhenghuangkun's avatar
zhenghuangkun committed
1920 1921 1922
    uint32_t               stream,
    NGAP_NGAP_PDU_t       *pdu){

1923
	LOG_W(NGAP, "Implementation of NGAP Pdusession Modification confirm handler is pending...\n");
zhenghuangkun's avatar
zhenghuangkun committed
1924 1925 1926
	return 0;
}