Enhanced SIM for E2AP v1 for TS UC
[sim/e2-interface.git] / e2sim / e2apv1sim / src / X2AP / x2ap_message_handler.cpp
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 # Copyright 2019 Nokia                                                       *
5 #                                                                            *
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                                    *
9 #                                                                            *
10 #      http://www.apache.org/licenses/LICENSE-2.0                            *
11 #                                                                            *
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.                                             *
17 #                                                                            *
18 ******************************************************************************/
19 #include "x2ap_message_handler.hpp"
20
21
22 void x2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data)
23 {
24   //decode the data into X2AP-PDU
25   x2ap_pdu_t* pdu = new_x2ap_pdu();
26
27   x2ap_decode_pdu(pdu, data.buffer, data.len);
28
29   x2ap_print_pdu(pdu);
30
31   int index = x2ap_get_index(pdu);
32   int procedureCode = x2ap_get_procedureCode(pdu);
33
34   switch(procedureCode)
35   {
36     case 6: //X2Setup
37       switch(index)
38       {
39         case 1: //initiatingMessage
40           LOG_D("[X2AP] Received X2 SETUP REQUEST");
41           x2ap_handle_X2SetupRequest(pdu, socket_fd);
42           break;
43
44         case 2: //successfulOutcome
45           LOG_D("[X2AP] Received X2 SETUP RESPONSE");
46           //x2ap_handle_X2SetupResponse(pdu, socket_fd);
47           break;
48
49         case 3:
50           LOG_D("[X2AP] Received X2 SETUP FAILURE");
51           break;
52
53         default:
54           LOG_E("[X2AP] Invalid message index=%d in X2AP-PDU", index);
55           break;
56       }
57       break;
58
59     case 36: //ENDCX2Setup
60       switch(index)
61       {
62         case 1: //initiatingMessage
63           LOG_D("[X2AP] Received ENDC X2 SETUP REQUEST");
64           x2ap_handle_ENDCX2SetupRequest(pdu, socket_fd);
65           break;
66
67         case 2: //successfulOutcome
68           LOG_D("[X2AP] Received ENDC X2 SETUP RESPONSE");
69           //x2ap_handle_X2SetupResponse(pdu, socket_fd);
70           break;
71
72         case 3:
73           LOG_D("[X2AP] Received ENDC X2 SETUP FAILURE");
74           break;
75
76         default:
77           LOG_E("[X2AP] Invalid message index=%d in X2AP-PDU", index);
78           break;
79       }
80       break;
81
82     default:
83       LOG_E("[X2AP] No available handler for procedureCode=%d", procedureCode);
84       break;
85   }
86 }
87
88 void x2ap_handle_X2SetupRequest(x2ap_pdu_t* pdu, int &socket_fd)
89 {
90   /*
91   Simply send back X2SetupResponse
92   Todo: add more handling options (failure, duplicated request, etc.)
93   */
94
95   x2ap_pdu_t* res_pdu = new_x2ap_pdu();
96   eNB_config cfg;
97
98   x2ap_create_X2SetupResponse(res_pdu, cfg);
99   LOG_D("[X2AP] Created X2 SETUP RESPONSE")
100
101   x2ap_print_pdu(res_pdu);
102
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);
106
107   //send response data over sctp
108   if(sctp_send_data(socket_fd, res_data) > 0) {
109     LOG_D("[SCTP] Sent X2 SETUP RESPONSE");
110   } else {
111     LOG_D("[SCTP] Unable to send X2 SETUP RESPONSE to peer");
112   }
113 }
114
115 void x2ap_handle_X2SetupResponse(x2ap_pdu_t* pdu, int &socket_fd)
116 {
117   ;
118 }
119
120
121 void x2ap_handle_ENDCX2SetupRequest(x2ap_pdu_t* pdu, int &socket_fd)
122 {
123   /*
124   Simply send back ENDCX2SetupResponse
125   Todo: add more handling options (failure, duplicated request, etc.)
126   */
127   ;
128 }