f1ap_handlers.c 4.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

/*! \file f1ap_handlers.c
 * \brief f1ap messages handlers
 * \author EURECOM/NTUST
 * \date 2018
 * \version 0.1
 * \company Eurecom
 * \email: navid.nikaein@eurecom.fr, bing-kai.hong@eurecom.fr
 * \note
 * \warning
 */

#include "f1ap_common.h"
#include "f1ap_handlers.h"
35 36
#include "f1ap_cu_interface_management.h"
#include "f1ap_du_interface_management.h"
37
#include "f1ap_cu_rrc_message_transfer.h"
38

39 40
extern f1ap_setup_req_t *f1ap_du_data_from_du;

Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
41
/* Handlers matrix. Only f1 related procedure present here */
42
f1ap_message_decoded_callback f1ap_messages_callback[][3] = {
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
43 44
  

45
  { 0, 0, 0 }, /* Reset */
46
  { CU_handle_F1_SETUP_REQUEST, DU_handle_F1_SETUP_RESPONSE, 0 }, /* F1Setup */
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
47
  { 0, 0, 0 }, /* ErrorIndication */
48 49 50
  { CU_handle_F1_SETUP_REQUEST, 0, 0 }, /* gNBDUConfigurationUpdate */
  { CU_handle_F1_SETUP_REQUEST, 0, 0 }, /* gNBCUConfigurationUpdate */
  { CU_handle_F1_SETUP_REQUEST, 0, 0 }, /* UEContextSetup */
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
51
  { 0, 0, 0 }, /* UEContextRelease */
52
  { CU_handle_F1_SETUP_REQUEST, 0, 0 }, /* UEContextModification */
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
53 54
  { 0, 0, 0 }, /* UEContextModificationRequired */
  { 0, 0, 0 }, /* UEMobilityCommand */
55
  { 0, 0, 0 }, /* UEContextReleaseRequest */
56
  { CU_handle_INITIAL_UL_RRC_MESSAGE_TRANSFER, 0, 0 }, /* InitialULRRCMessageTransfer */
57 58
  { CU_handle_F1_SETUP_REQUEST, 0, 0 }, /* DLRRCMessageTransfer */
  { CU_handle_F1_SETUP_REQUEST, 0, 0 }, /* ULRRCMessageTransfer */
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
59 60 61 62 63 64
  { 0, 0, 0 }, /* privateMessage */
  { 0, 0, 0 }, /* UEInactivityNotification */
  { 0, 0, 0 }, /* GNBDUResourceCoordination */
  { 0, 0, 0 }, /* SystemInformationDeliveryCommand */
  { 0, 0, 0 }, /* Paging */
  { 0, 0, 0 }, /* Notify */
65
  { 0, 0, 0 }, /* WriteReplaceWarning */
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
66 67 68
  { 0, 0, 0 }, /* PWSCancel */
  { 0, 0, 0 }, /* PWSRestartIndication */
  { 0, 0, 0 }, /* PWSFailureIndication */
69 70
};

71
const char *f1ap_direction2String(int f1ap_dir) {
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
72
static const char *f1ap_direction_String[] = {
73
  "", /* Nothing */
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
74
  "Initiating message", /* initiating message */
75 76 77
  "Successfull outcome", /* successfull outcome */
  "UnSuccessfull outcome", /* successfull outcome */
};
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
78
return(f1ap_direction_String[f1ap_dir]);
79 80
}

81
int f1ap_handle_message(instance_t instance, uint32_t assoc_id, int32_t stream,
82 83
                            const uint8_t * const data, const uint32_t data_length)
{
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
84 85
  F1AP_F1AP_PDU_t pdu;
  int ret;
86 87 88

  DevAssert(data != NULL);

Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
89
  memset(&pdu, 0, sizeof(pdu));
90

Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
91
  if (f1ap_decode_pdu(&pdu, data, data_length) < 0) {
92
    LOG_E(F1AP, "Failed to decode PDU\n");
93 94 95 96
    return -1;
  }

  /* Checking procedure Code and direction of message */
97
  if (pdu.choice.initiatingMessage->procedureCode > sizeof(f1ap_messages_callback) / (3 * sizeof(
98
        f1ap_message_decoded_callback))
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
99
      || (pdu.present > F1AP_F1AP_PDU_PR_unsuccessfulOutcome)) {
100
    LOG_E(F1AP, "[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n",
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
101 102
               assoc_id, pdu.choice.initiatingMessage->procedureCode, pdu.present);
    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_F1AP_F1AP_PDU, &pdu);
103 104 105 106 107 108
    return -1;
  }

  /* No handler present.
   * This can mean not implemented or no procedure for eNB (wrong direction).
   */
109
  if (f1ap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1] == NULL) {
110
    LOG_E(F1AP, "[SCTP %d] No handler for procedureCode %ld in %s\n",
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
111 112 113
                assoc_id, pdu.choice.initiatingMessage->procedureCode,
               f1ap_direction2String(pdu.present - 1));
    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_F1AP_F1AP_PDU, &pdu);
114 115 116 117
    return -1;
  }

  /* Calling the right handler */
118
  ret = (*f1ap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1])
119
        (instance, assoc_id, stream, &pdu);
Bing-Kai Hong's avatar
F1:  
Bing-Kai Hong committed
120 121
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_F1AP_F1AP_PDU, &pdu);
  return ret;
122
}