Update to odulow per maintenance bronze
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p5 / nr5g_fapi_proc_stop_ind.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2019 Intel.
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
19 /**
20  * @file
21  * This file consist of implementation of FAPI STOP.indication message.
22  *
23  **/
24
25 #include "nr5g_fapi_framework.h"
26 #include "gnb_l1_l2_api.h"
27 #include "nr5g_fapi_fapi2mac_api.h"
28 #include "nr5g_fapi_fapi2phy_api.h"
29 #include "nr5g_fapi_fapi2mac_p5_proc.h"
30 #include "nr5g_fapi_fapi2phy_p5_proc.h"
31 #include "nr5g_fapi_fapi2phy_p5_pvt_proc.h"
32
33 /** @ingroup group_source_api_p5_fapi2mac_proc
34  *
35  *  @param[in]  p_phy_ctx Pointer to PHY context.
36  *  @param[in]  p_fapi_resp Pointer to IAPI STOP.indication message structure.
37  *  @return     Returns ::SUCCESS and ::FAILURE.
38  *
39  *  @description
40  *  This message allows PHY to indicate that it has successfully stopped
41  *  and returned to the CONFIGURED state. 
42  *
43 **/
44 uint8_t nr5g_fapi_stop_indication(
45     p_nr5g_fapi_phy_ctx_t p_phy_ctx,
46     PSTOPRESPONSEStruct p_iapi_resp)
47 {
48     uint8_t phy_id;
49
50     fapi_error_ind_t *p_fapi_error_ind;
51     p_fapi_api_queue_elem_t p_list_elem;
52     p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
53     nr5g_fapi_stats_t *p_stats;
54
55     if (NULL == p_phy_ctx) {
56         NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Invalid " "phy context"));
57         return FAILURE;
58     }
59
60     if (NULL == p_iapi_resp) {
61         NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Invalid "
62                 "stop response message"));
63         return FAILURE;
64     }
65
66     phy_id = p_iapi_resp->sSFN_Slot.nCarrierIdx;
67     p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
68     if (p_phy_instance->phy_id != phy_id) {
69         NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Invalid " "phy instance"));
70         return FAILURE;
71     }
72
73     p_stats = &p_phy_instance->stats;
74     p_stats->iapi_stats.iapi_stop_ind++;
75     if (SUCCESS == p_iapi_resp->nStatus) {
76         if (FAPI_STATE_RUNNING == p_phy_instance->state) {
77             p_phy_instance->state = FAPI_STATE_CONFIGURED;
78         }
79 #ifdef DEBUG_MODE
80         p_list_elem =
81             nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_STOP_INDICATION, 1,
82             sizeof(fapi_stop_ind_t));
83         if (!p_list_elem) {
84             NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Unable to create "
85                     "list element. Out of memory!!!"));
86             return FAILURE;
87         }
88         fapi_stop_ind_t *p_fapi_resp;
89         p_fapi_resp = (fapi_stop_ind_t *) (p_list_elem + 1);
90         p_fapi_resp->header.msg_id = FAPI_STOP_INDICATION;
91         p_fapi_resp->header.length = (uint16_t) sizeof(fapi_stop_ind_t);
92         /* Add element to send list */
93         nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
94         p_stats->fapi_stats.fapi_stop_ind++;
95         NR5G_FAPI_LOG(INFO_LOG, ("[STOP.indication][%d]", phy_id));
96 #else
97         fapi_vendor_ext_shutdown_req_t fapi_req;
98         fapi_req.header.msg_id = FAPI_VENDOR_EXT_SHUTDOWN_REQUEST;
99         fapi_req.header.length = sizeof(fapi_vendor_ext_shutdown_req_t);
100         fapi_req.sfn = 0;
101         fapi_req.slot = 0;
102         fapi_req.test_type = 0;
103         nr5g_fapi_shutdown_request(p_phy_instance, &fapi_req);
104         nr5g_fapi_fapi2phy_send_api_list();
105 #endif
106     } else if (FAILURE == p_iapi_resp->nStatus) {
107         p_list_elem =
108             nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_ERROR_INDICATION, 1,
109             sizeof(fapi_error_ind_t));
110         if (!p_list_elem) {
111             NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Unable to create "
112                     "list element. Out of memory!!!"));
113             return FAILURE;
114         }
115
116         /* PHY STOP Failed. Sending Error Indication to MAC */
117         p_fapi_error_ind = (fapi_error_ind_t *) (p_list_elem + 1);
118         p_fapi_error_ind->header.msg_id = FAPI_ERROR_INDICATION;
119         p_fapi_error_ind->header.length = (uint16_t) sizeof(fapi_error_ind_t);
120         p_fapi_error_ind->sfn = p_iapi_resp->sSFN_Slot.nSFN;
121         p_fapi_error_ind->slot = p_iapi_resp->sSFN_Slot.nSlot;
122         p_fapi_error_ind->message_id = FAPI_STOP_REQUEST;
123         p_fapi_error_ind->error_code = p_iapi_resp->nStatus;
124         /* Add element to send list */
125         nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
126         p_stats->fapi_stats.fapi_error_ind++;
127         NR5G_FAPI_LOG(INFO_LOG, ("[STOP.indication][ERROR.indication][%d]",
128                 phy_id));
129     } else {
130         NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Invalid status "
131                 "from PHY"));
132         return FAILURE;
133     }
134     return SUCCESS;
135 }