/*
 * SPDX-License-Identifier: LicenseRef-CSSL-1.0
 */

#ifndef XNAP_MESSAGES_TYPES_H_
#define XNAP_MESSAGES_TYPES_H_

#include "common/5g_platform_types.h"

typedef struct {
  // PLMN Identity
  plmn_id_t plmn;
  // Number of supported S-NSSAIs
  uint16_t num_nssai;
  // List of supported S-NSSAIs
  nssai_t *nssai;
} xnap_plmn_support_t;

typedef struct {
  // Tracking Area Code
  uint32_t tac;
  // Number of supported PLMNs
  uint8_t num_plmn;
  // List of supported PLMNs
  xnap_plmn_support_t *plmn_support;
} xnap_tai_support_t;

typedef struct {
  // PLMN Identity
  plmn_id_t plmn;
  // AMF Region Identifier
  uint8_t amf_region_id;
} xnap_amf_region_info_t;

/* 3GPP TS 38.423 9.1.3.1 – Xn Setup Request */
typedef struct {
  // Global NG-RAN Node ID (gNB_id+plmn) (M)
  uint32_t gNB_id;
  plmn_id_t plmn;
  // TAI Support List (M)
  uint16_t num_tai;
  xnap_tai_support_t *tai_support;
  // AMF Region Information (M)
  uint8_t num_amf_regions;
  xnap_amf_region_info_t *amf_region_info;
} xnap_setup_req_t;

/* 3GPP TS 38.423 9.1.3.2 – Xn Setup Response */
typedef struct {
  // Global NG-RAN Node ID (gNB_id+plmn) (M)
  uint32_t gNB_id;
  plmn_id_t plmn;
  // TAI Support List (M)
  uint16_t num_tai;
  xnap_tai_support_t *tai_support;
} xnap_setup_resp_t;

typedef enum xnap_cause_radio_network_e {
    XNAP_CAUSE_RADIO_NETWORK_LAYER_CELL_NOT_AVAILABLE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_HANDOVER_DESIRABLE_FOR_RADIO_REASONS,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_HANDOVER_TARGET_NOT_ALLOWED,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_INVALID_AMF_SET_ID,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_NO_RADIO_RESOURCES_AVAILABLE_IN_TARGET_CELL,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_PARTIAL_HANDOVER,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_REDUCE_LOAD_IN_SERVING_CELL,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_RESOURCE_OPTIMISATION_HANDOVER,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_TIME_CRITICAL_HANDOVER,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_TXN_RELOCOVERALL_EXPIRY,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_TXN_RELOCPREP_EXPIRY,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UNKNOWN_GUAMI_ID,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UNKNOWN_LOCAL_NG_RAN_NODE_UE_XNAP_ID,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_INCONSISTENT_REMOTE_NG_RAN_NODE_UE_XNAP_ID,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_ENCRYPTION_AND_OR_INTEGRITY_PROTECTION_ALGORITHMS_NOT_SUPPORTED,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_PROTECTION_ALGORITHMS_NOT_SUPPORTED,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_MULTIPLE_PDU_SESSION_ID_INSTANCES,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UNKNOWN_PDU_SESSION_ID,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UNKNOWN_QOS_FLOW_ID,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_MULTIPLE_QOS_FLOW_ID_INSTANCES,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_SWITCH_OFF_ONGOING,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_NOT_SUPPORTED_5QI_VALUE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_TXN_DCOVERALL_EXPIRY,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_TXN_DCPREP_EXPIRY,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_ACTION_DESIRABLE_FOR_RADIO_REASONS,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_REDUCE_LOAD,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_RESOURCE_OPTIMISATION,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_TIME_CRITICAL_ACTION,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_TARGET_NOT_ALLOWED,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_NO_RADIO_RESOURCES_AVAILABLE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_INVALID_QOS_COMBINATION,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_ENCRYPTION_ALGORITHMS_NOT_SUPPORTED,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_PROCEDURE_CANCELLED,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_RRM_PURPOSE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_IMPROVE_USER_BIT_RATE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_USER_INACTIVITY,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_RADIO_CONNECTION_WITH_UE_LOST,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_FAILURE_IN_THE_RADIO_INTERFACE_PROCEDURE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_BEARER_OPTION_NOT_SUPPORTED,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UP_INTEGRITY_PROTECTION_NOT_POSSIBLE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UP_CONFIDENTIALITY_PROTECTION_NOT_POSSIBLE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_RESOURCES_NOT_AVAILABLE_FOR_THE_SLICE_S,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UE_MAX_IP_DATA_RATE_REASON,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_CP_INTEGRITY_PROTECTION_FAILURE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UP_INTEGRITY_PROTECTION_FAILURE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_SLICE_NOT_SUPPORTED_BY_NG_RAN,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_MN_MOBILITY,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_SN_MOBILITY,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_COUNT_REACHES_MAX_VALUE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UNKNOWN_OLD_NG_RAN_NODE_UE_XNAP_ID,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_PDCP_OVERLOAD,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_DRB_ID_NOT_AVAILABLE,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UNSPECIFIED,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_UE_CONTEXT_ID_NOT_KNOWN,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_NON_RELOCATION_OF_CONTEXT,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_CHO_CPC_RESOURCES_TOBECHANGED,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_RSN_NOT_AVAILABLE_FOR_THE_UP,
    XNAP_CAUSE_RADIO_NETWORK_LAYER_NPN_ACCESS_DENIED
} xnap_cause_radio_network_t;

typedef enum xnap_cause_transport_layer_e {
  XNAP_CAUSE_TRANSPORT_LAYER_TRANSPORT_RESOURCE_UNAVAILABLE,
  XNAP_CAUSE_TRANSPORT_LAYER_UNSPECIFIED
} xnap_cause_transport_layer_t;

typedef enum xnap_cause_protocol_e {
  XNAP_CAUSE_PROTOCOL_TRANSFER_SYNTAX_ERROR,
  XNAP_CAUSE_PROTOCOL_ABSTRACT_SYNTAX_ERROR_REJECT,
  XNAP_CAUSE_PROTOCOL_ABSTRACT_SYNTAX_ERROR_IGNORE_AND_NOTIFY,
  XNAP_CAUSE_PROTOCOL_MESSAGE_NOT_COMPATIBLE_WITH_RECEIVER_STATE,
  XNAP_CAUSE_PROTOCOL_SEMANTIC_ERROR,
  XNAP_CAUSE_PROTOCOL_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED,
  XNAP_CAUSE_PROTOCOL_UNSPECIFIED
} xnap_cause_protocol_t;

typedef enum xnap_cause_misc_e {
  XNAP_CAUSE_MISC_CONTROL_PROCESSING_OVERLOAD,
  XNAP_CAUSE_MISC_HARDWARE_FAILURE,
  XNAP_CAUSE_MISC_O_AND_M_INTERVENTION,
  XNAP_CAUSE_MISC_NOT_ENOUGH_USER_PLANE_PROCESSING_RESOURCES,
  XNAP_CAUSE_MISC_UNSPECIFIED
} xnap_cause_misc_t;

typedef enum xnap_cause_group_e {
  XNAP_CAUSE_NOTHING,
  XNAP_CAUSE_RADIO_NETWORK,
  XNAP_CAUSE_TRANSPORT,
  XNAP_CAUSE_PROTOCOL,
  XNAP_CAUSE_MISC,
} xnap_cause_group_t;

typedef struct xnap_cause_s {
  /* Cause group (e.g. radioNetwork, transport, protocol, misc) */
  xnap_cause_group_t type;
  /* Specific cause value within the selected cause group */
  uint8_t value;
} xnap_cause_t;

/* 3GPP TS 38.423 9.1.3.3 – Xn Setup Failure */
typedef struct {
  // Cause (M)
  xnap_cause_t cause;
} xnap_setup_failure_t;

#endif /* XNAP_MESSAGES_TYPES_H_ */
