ngap_gNB_trace.c 6.08 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
/*
 * 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
 */

#include <stdint.h>

#include "assertions.h"

#include "intertask_interface.h"

#include "ngap_gNB_default_values.h"

#include "ngap_common.h"
#include "ngap_gNB_defs.h"

#include "ngap_gNB.h"
#include "ngap_gNB_ue_context.h"
#include "ngap_gNB_encoder.h"
#include "ngap_gNB_trace.h"
#include "ngap_gNB_itti_messaging.h"
#include "ngap_gNB_management_procedures.h"

static
void ngap_gNB_generate_trace_failure(struct ngap_gNB_ue_context_s *ue_desc_p,
                                     NGAP_E_UTRAN_Trace_ID_t      *trace_id,
                                     NGAP_Cause_t                 *cause_p)
{
    NGAP_NGAP_PDU_t                     pdu;
    NGAP_TraceFailureIndication_t      *out;
    NGAP_TraceFailureIndicationIEs_t   *ie;
    uint8_t                            *buffer = NULL;
    uint32_t                            length;

    DevAssert(ue_desc_p != NULL);
    DevAssert(trace_id  != NULL);
    DevAssert(cause_p   != NULL);

    /* Prepare the NGAP message to encode */
    memset(&pdu, 0, sizeof(pdu));
    pdu.present = NGAP_NGAP_PDU_PR_initiatingMessage;
    pdu.choice.initiatingMessage.procedureCode = NGAP_ProcedureCode_id_TraceFailureIndication;
    pdu.choice.initiatingMessage.criticality = NGAP_Criticality_ignore;
    pdu.choice.initiatingMessage.value.present = NGAP_InitiatingMessage__value_PR_TraceFailureIndication;
    out = &pdu.choice.initiatingMessage.value.choice.TraceFailureIndication;

    /* mandatory */
    ie = (NGAP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(NGAP_TraceFailureIndicationIEs_t));
zhenghuangkun's avatar
zhenghuangkun committed
65
    ie->id = NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID;
zhenghuangkun's avatar
zhenghuangkun committed
66
    ie->criticality = NGAP_Criticality_reject;
zhenghuangkun's avatar
zhenghuangkun committed
67 68
    ie->value.present = NGAP_TraceFailureIndicationIEs__value_PR_AMF_UE_NGAP_ID;
    ie->value.choice.AMF_UE_NGAP_ID = ue_desc_p->amf_ue_ngap_id;
zhenghuangkun's avatar
zhenghuangkun committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

    /* mandatory */
    ie = (NGAP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(NGAP_TraceFailureIndicationIEs_t));
    ie->id = NGAP_ProtocolIE_ID_id_gNB_UE_NGAP_ID;
    ie->criticality = NGAP_Criticality_reject;
    ie->value.present = NGAP_TraceFailureIndicationIEs__value_PR_GNB_UE_NGAP_ID;
    ie->value.choice.GNB_UE_NGAP_ID = ue_desc_p->gNB_ue_ngap_id;
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

    /* mandatory */
    ie = (NGAP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(NGAP_TraceFailureIndicationIEs_t));
    ie->id = NGAP_ProtocolIE_ID_id_E_UTRAN_Trace_ID;
    ie->criticality = NGAP_Criticality_ignore;
    ie->value.present = NGAP_TraceFailureIndicationIEs__value_PR_E_UTRAN_Trace_ID;
    memcpy(&ie->value.choice.E_UTRAN_Trace_ID, trace_id, sizeof(NGAP_E_UTRAN_Trace_ID_t));
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

    /* mandatory */
    ie = (NGAP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(NGAP_TraceFailureIndicationIEs_t));
    ie->id = NGAP_ProtocolIE_ID_id_Cause;
    ie->criticality = NGAP_Criticality_ignore;
    ie->value.present = NGAP_TraceFailureIndicationIEs__value_PR_Cause;
    memcpy(&ie->value.choice.Cause, cause_p, sizeof(NGAP_Cause_t));
    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);

    if (ngap_gNB_encode_pdu(&pdu, &buffer, &length) < 0) {
        return;
    }

zhenghuangkun's avatar
zhenghuangkun committed
99 100
    ngap_gNB_itti_send_sctp_data_req(ue_desc_p->amf_ref->ngap_gNB_instance->instance,
                                     ue_desc_p->amf_ref->assoc_id, buffer,
zhenghuangkun's avatar
zhenghuangkun committed
101 102 103 104 105 106 107 108 109 110
                                     length, ue_desc_p->tx_stream);
}

int ngap_gNB_handle_trace_start(uint32_t         assoc_id,
                                uint32_t         stream,
                                NGAP_NGAP_PDU_t *pdu)
{
    NGAP_TraceStart_t            *container;
    NGAP_TraceStartIEs_t         *ie;
    struct ngap_gNB_ue_context_s *ue_desc_p = NULL;
zhenghuangkun's avatar
zhenghuangkun committed
111
    struct ngap_gNB_amf_data_s   *amf_ref_p;
zhenghuangkun's avatar
zhenghuangkun committed
112 113 114 115 116 117 118

    DevAssert(pdu != NULL);

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

    NGAP_FIND_PROTOCOLIE_BY_ID(NGAP_TraceStartIEs_t, ie, container,
                               NGAP_ProtocolIE_ID_id_gNB_UE_NGAP_ID, TRUE);
zhenghuangkun's avatar
zhenghuangkun committed
119 120
    amf_ref_p = ngap_gNB_get_AMF(NULL, assoc_id, 0);
    DevAssert(amf_ref_p != NULL);
zhenghuangkun's avatar
zhenghuangkun committed
121
  if (ie != NULL) {
zhenghuangkun's avatar
zhenghuangkun committed
122
    ue_desc_p = ngap_gNB_get_ue_context(amf_ref_p->ngap_gNB_instance,
zhenghuangkun's avatar
zhenghuangkun committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
                                        ie->value.choice.GNB_UE_NGAP_ID);
  }
    if (ue_desc_p == NULL) {
        /* Could not find context associated with this gNB_ue_ngap_id -> generate
         * trace failure indication.
         */
        NGAP_E_UTRAN_Trace_ID_t trace_id;
        NGAP_Cause_t cause;
        memset(&trace_id, 0, sizeof(NGAP_E_UTRAN_Trace_ID_t));
        memset(&cause, 0, sizeof(NGAP_Cause_t));
        cause.present = NGAP_Cause_PR_radioNetwork;
        cause.choice.radioNetwork = NGAP_CauseRadioNetwork_unknown_pair_ue_ngap_id;
        ngap_gNB_generate_trace_failure(NULL, &trace_id, &cause);
    }

    return 0;
}

int ngap_gNB_handle_deactivate_trace(uint32_t         assoc_id,
                                     uint32_t         stream,
                                     NGAP_NGAP_PDU_t *message_p)
{
    //     NGAP_DeactivateTraceIEs_t *deactivate_trace_p;
    //
    //     deactivate_trace_p = &message_p->msg.deactivateTraceIEs;

    return 0;
}