3 * Copyright 2019 AT&T Intellectual Property
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include "x2ap_message_handler.h"
26 typedef int (*x2ap_message_decoded_handler)(X2AP_PDU_t *pdu, sctp_data_t *response);
28 static int handle_x2_setup_request(X2AP_PDU_t *pdu, sctp_data_t *response);
30 static int handle_x2_setup_response(X2AP_PDU_t *pdu, sctp_data_t *response);
32 static int handle_x2_setup_failure(X2AP_PDU_t *pdu, sctp_data_t *response);
34 /* Handlers matrix. Only eNB related procedure present here
35 /* rowID = procedureCode (start with 0)
37 x2ap_message_decoded_handler x2ap_messages_handler[][3] = {
38 { 0, 0, 0 }, /* handoverPreparation */
39 { 0, 0, 0 }, /* handoverCancel */
40 { 0, 0, 0 }, /* loadIndication */
41 { 0, 0, 0 }, /* errorIndication */
42 { 0, 0, 0 }, /* snStatusTransfer */
43 { 0, 0, 0 }, /* uEContextRelease */
44 { handle_x2_setup_request, handle_x2_setup_response, handle_x2_setup_failure }, /* x2Setup */
45 { 0, 0, 0 }, /* reset */
46 { 0, 0, 0 }, /* eNBConfigurationUpdate */
47 { 0, 0, 0 }, /* resourceStatusReportingInitiation */
48 { 0, 0, 0 }, /* resourceStatusReporting */
49 { 0, 0, 0 }, /* privateMessage */
50 { 0, 0, 0 }, /* mobilitySettingsChange */
51 { 0, 0, 0 }, /* rLFIndication */
52 { 0, 0, 0 }, /* handoverReport */
53 { 0, 0, 0 }, /* cellActivation */
54 { 0, 0, 0 }, /* x2Release */
55 { 0, 0, 0 }, /* x2APMessageTransfer */
56 { 0, 0, 0 }, /* x2Removal */
57 { 0, 0, 0 }, /* seNBAdditionPreparation */
58 { 0, 0, 0 }, /* seNBReconfigurationCompletion */
59 { 0, 0, 0 }, /* meNBinitiatedSeNBModificationPreparation */
60 { 0, 0, 0 }, /* seNBinitiatedSeNBModification */
61 { 0, 0, 0 }, /* meNBinitiatedSeNBRelease */
62 { 0, 0, 0 }, /* seNBinitiatedSeNBRelease */
63 { 0, 0, 0 }, /* seNBCounterCheck */
64 { 0, 0, 0 } /* retrieveUEContext */
67 char *x2ap_direction2String(int x2ap_dir)
69 static char *x2ap_direction_String[] = {
71 "Originating message", /* originating message */
72 "Successfull outcome", /* successfull outcome */
73 "UnSuccessfull outcome", /* successfull outcome */
75 return(x2ap_direction_String[x2ap_dir]);
78 int x2ap_eNB_handle_message(const uint8_t *const data, const int data_len, sctp_data_t* response)
83 memset(&pdu, 0, sizeof(pdu));
85 //printf("Decode the PDU \n");
87 if (X2AP_ASN_decode(&pdu, data, data_len) < 0){
91 /* Checking procedure Code and direction of message */
92 if (pdu.choice.initiatingMessage.procedureCode > sizeof(x2ap_messages_handler)
93 / (3 * sizeof(x2ap_message_decoded_handler))
94 || (pdu.present > X2AP_PDU_PR_unsuccessfulOutcome)) {
96 fprintf(stderr, "Either procedureCode %ld or direction %d exceed expected\n",
97 pdu.choice.initiatingMessage.procedureCode, pdu.present);
98 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_PDU, &pdu);
102 if (x2ap_messages_handler[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1] == NULL)
104 fprintf(stderr, "No handler for procedureCode %ld in direction %s\n",
105 pdu.choice.initiatingMessage.procedureCode,
106 x2ap_direction2String(pdu.present - 1));
107 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_PDU, &pdu);
111 /*calling the appropriate handler */
112 ret = (*x2ap_messages_handler[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1])(&pdu, response);
113 ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_PDU, &pdu);
117 int handle_x2_setup_request(X2AP_PDU_t *pdu, sctp_data_t* response)
119 fprintf(stderr, "Received X2 SETUP REQUEST\n");
121 /* Todo: when to generate X2 Setup Failure???
124 response->len = x2ap_generate_x2_setup_response(&response->data);
129 int handle_x2_setup_response(X2AP_PDU_t *pdu, sctp_data_t* response)
131 fprintf(stderr, "Received X2 SETUP RESPONSE\n");
135 int handle_x2_setup_failure(X2AP_PDU_t *pdu, sctp_data_t* response)
137 fprintf(stderr, "Received X2 SETUP FAILURE\n");