83ab35a304407e1b02878d1efaeee0cfac9def00
[o-du/l2.git] / src / du_app / du_e2ap_mgr.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18 #include "common_def.h"
19 #include "lrg.h"
20 #include "lkw.x"
21 #include "lrg.x"
22 #include "legtp.h"
23 #include "du_app_mac_inf.h"
24 #include "du_app_rlc_inf.h"
25 #include "du_e2ap_mgr.h"
26 #include "du_e2ap_msg_hdl.h"
27 #include "du_cfg.h"
28 #include "du_sctp.h"
29 #include "du_mgr.h"
30 #include "du_mgr_main.h"
31 #include "du_utils.h"
32
33 /*******************************************************************
34  *
35  * @brief Assigns new transaction id to DU initiated procedure
36  *
37  * @details
38  *
39  *    Function : assignTransactionId
40  *
41  *    Functionality: Assigns new transaction id to a DU initiated
42  *       procedure
43  *
44  * @params[in] Region region
45  *             Pool pool
46  * @return ROK     - success
47  *         RFAILED - failure
48  *
49  * ****************************************************************/
50 uint8_t assignTransactionId()
51 {
52    uint8_t currTransId = duCb.e2apDb.transIdCounter;
53
54    /* Update to next valid value */
55    duCb.e2apDb.transIdCounter++;
56    if(duCb.e2apDb.transIdCounter == MAX_NUM_TRANSACTION)
57       duCb.e2apDb.transIdCounter = 0;
58
59    return currTransId;
60 }
61
62 /*******************************************************************
63  *
64  * @brief Sends E2 msg over SCTP
65  *
66  * @details
67  *
68  *    Function : SendE2APMsg
69  *
70  *    Functionality: Sends E2 msg over SCTP
71  *
72  * @params[in] Region region
73  *             Pool pool
74  * @return ROK     - success
75  *         RFAILED - failure
76  *
77  * ****************************************************************/
78
79 uint8_t SendE2APMsg(Region region, Pool pool, char *encBuf, int encBufSize)
80 {
81    Buffer *mBuf=NULLP;
82
83    if(ODU_GET_MSG_BUF(region, pool, &mBuf) == ROK)
84    {
85       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
86       {
87          ODU_PRINT_MSG(mBuf, 0,0);
88
89          if(sctpSend(mBuf, E2_INTERFACE) != ROK)
90          {
91             DU_LOG("\nERROR  -->  E2AP : SCTP Send for E2  failed");
92             ODU_PUT_MSG_BUF(mBuf);
93             return RFAILED;
94          }
95       }
96       else
97       {
98          DU_LOG("\nERROR  -->  E2AP : ODU_ADD_POST_MSG_MULT failed");
99          ODU_PUT_MSG_BUF(mBuf);
100          return RFAILED;
101       }
102       ODU_PUT_MSG_BUF(mBuf);
103    }
104    else
105    {
106       DU_LOG("\nERROR  -->  E2AP : Failed to allocate memory");
107       return RFAILED;
108    }
109
110    return ROK;
111 } /* SendE2APMsg */
112
113 /*******************************************************************
114  *
115  * @brief Resets E2 
116  *
117  * @details
118  *
119  *    Function : ResetE2Request
120  *
121  *    Functionality: This function resets E2.
122  *       As per ORAN WG3 E2GAP v3.0 Spec, section 5.5.3
123  *       If E2 node initates reset procedure then:
124  *        a. Send reset request to RIC
125  *        b. Delete any pre-established RIC subscriptions
126  *        c. Gracefully terminates any ongoing RIC services
127  *       If RIC initiates reset procedure then :
128  *        a. Delete any pre-established RIC subscriptions
129  *        b. Gracefully terminates any ongoing RIC services
130  *        c. Send reset response to RIC
131  *
132  * @params[in]
133  * @return ROK     - success
134  *         RFAILED - failure
135  *
136  * ****************************************************************/
137 uint8_t ResetE2Request(E2ProcedureDirection dir, E2CauseType type, E2Cause cause)
138 {
139    /* Send Reset Request to RIC if DU detects any abnormal failure */
140    if(dir == E2_NODE_INITIATED)
141    {
142       if(BuildAndSendE2ResetRequest(type, cause) != ROK)
143       {
144          DU_LOG("\nERROR  -->  E2AP : BuildAndSendE2ResetRequest failed");
145          return RFAILED;
146       }
147    }
148
149    /* TODO when RIC subscription service model is implemented
150       Process following steps of resetting E2
151       1. Deletes any pre-established RIC subscriptions
152       2. Gracefully terminates any ongoing RIC services
153     */
154
155    /* Send Reset Response if RIC initiated Reset request is received at DU */
156    if(dir == RIC_INITIATED)
157    {
158       //BuildAndSendE2ResetResponse();
159    }   
160    return ROK;
161 }
162
163 /**********************************************************************
164   End of file
165  **********************************************************************/
166