1 /*****************************************************************************
3 # Copyright 2019 AT&T Intellectual Property *
4 # Copyright 2019 Nokia *
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. *
18 ******************************************************************************/
19 #include "x2ap_message_handler.hpp"
22 void x2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data)
24 //decode the data into X2AP-PDU
25 x2ap_pdu_t* pdu = new_x2ap_pdu();
27 x2ap_decode_pdu(pdu, data.buffer, data.len);
31 int index = x2ap_get_index(pdu);
32 int procedureCode = x2ap_get_procedureCode(pdu);
39 case 1: //initiatingMessage
40 LOG_D("[X2AP] Received X2 SETUP REQUEST");
41 x2ap_handle_X2SetupRequest(pdu, socket_fd);
44 case 2: //successfulOutcome
45 LOG_D("[X2AP] Received X2 SETUP RESPONSE");
46 //x2ap_handle_X2SetupResponse(pdu, socket_fd);
50 LOG_D("[X2AP] Received X2 SETUP FAILURE");
54 LOG_E("[X2AP] Invalid message index=%d in X2AP-PDU", index);
59 case 36: //ENDCX2Setup
62 case 1: //initiatingMessage
63 LOG_D("[X2AP] Received ENDC X2 SETUP REQUEST");
64 x2ap_handle_ENDCX2SetupRequest(pdu, socket_fd);
67 case 2: //successfulOutcome
68 LOG_D("[X2AP] Received ENDC X2 SETUP RESPONSE");
69 //x2ap_handle_X2SetupResponse(pdu, socket_fd);
73 LOG_D("[X2AP] Received ENDC X2 SETUP FAILURE");
77 LOG_E("[X2AP] Invalid message index=%d in X2AP-PDU", index);
83 LOG_E("[X2AP] No available handler for procedureCode=%d", procedureCode);
88 void x2ap_handle_X2SetupRequest(x2ap_pdu_t* pdu, int &socket_fd)
91 Simply send back X2SetupResponse
92 Todo: add more handling options (failure, duplicated request, etc.)
95 x2ap_pdu_t* res_pdu = new_x2ap_pdu();
98 x2ap_create_X2SetupResponse(res_pdu, cfg);
99 LOG_D("[X2AP] Created X2 SETUP RESPONSE")
101 x2ap_print_pdu(res_pdu);
103 //encode response pdu into buffer
104 sctp_buffer_t res_data;
105 x2ap_encode_pdu(res_pdu, res_data.buffer, sizeof(res_data.buffer), res_data.len);
107 //send response data over sctp
108 if(sctp_send_data(socket_fd, res_data) > 0) {
109 LOG_D("[SCTP] Sent X2 SETUP RESPONSE");
111 LOG_D("[SCTP] Unable to send X2 SETUP RESPONSE to peer");
115 void x2ap_handle_X2SetupResponse(x2ap_pdu_t* pdu, int &socket_fd)
121 void x2ap_handle_ENDCX2SetupRequest(x2ap_pdu_t* pdu, int &socket_fd)
124 Simply send back ENDCX2SetupResponse
125 Todo: add more handling options (failure, duplicated request, etc.)