Update to odulow per maintenance bronze
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p5 / nr5g_fapi_proc_start_resp.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_fapi2mac_p5_proc.h"
29
30 /** @ingroup group_source_api_p5_fapi2mac_proc
31  *
32  *  @param[in]  p_phy_ctx Pointer to PHY context.
33  *  @param[in]  p_fapi_resp Pointer to IAPI START.response message structure.
34  *  @return     Returns ::SUCCESS and ::FAILURE.
35  *
36  *  @description
37  *  This message allows PHY to indicate that it has successfully started PHY
38  *  
39  *
40 **/
41 uint8_t nr5g_fapi_start_resp(
42     p_nr5g_fapi_phy_ctx_t p_phy_ctx,
43     PSTARTRESPONSEStruct p_iapi_resp)
44 {
45     uint8_t phy_id;
46 #ifdef DEBUG_MODE
47     fapi_vendor_ext_start_response_t *p_fapi_resp;
48 #endif
49     fapi_error_ind_t *p_fapi_error_ind;
50     p_fapi_api_queue_elem_t p_list_elem;
51     p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
52     nr5g_fapi_stats_t *p_stats;
53
54     if (NULL == p_phy_ctx) {
55         NR5G_FAPI_LOG(ERROR_LOG, ("[START.response] Invalid " "phy context"));
56         return FAILURE;
57     }
58
59     if (NULL == p_iapi_resp) {
60         NR5G_FAPI_LOG(ERROR_LOG, ("[START.response] Invalid "
61                 "start response message"));
62         return FAILURE;
63     }
64
65     phy_id = p_iapi_resp->sSFN_Slot.nCarrierIdx;
66     p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
67     if (p_phy_instance->phy_id != phy_id) {
68         NR5G_FAPI_LOG(ERROR_LOG, ("[START.response] Invalid  " "phy instance"));
69         return FAILURE;
70     }
71
72     p_stats = &p_phy_instance->stats;
73     p_stats->iapi_stats.iapi_start_res++;
74     if (0 == p_iapi_resp->nStatus) {
75         if (FAPI_STATE_CONFIGURED == p_phy_instance->state) {
76             p_phy_instance->state = FAPI_STATE_RUNNING;
77         }
78 #ifdef DEBUG_MODE
79         p_list_elem =
80             nr5g_fapi_fapi2mac_create_api_list_elem
81             (FAPI_VENDOR_EXT_START_RESPONSE, 1,
82             sizeof(fapi_vendor_ext_start_response_t));
83         if (!p_list_elem) {
84             NR5G_FAPI_LOG(ERROR_LOG, ("[START.Response] Unable to create "
85                     "list element. Out of memory!!!"));
86             return FAILURE;
87         }
88
89         p_fapi_resp = (fapi_vendor_ext_start_response_t *) (p_list_elem + 1);
90         p_fapi_resp->header.msg_id = FAPI_VENDOR_EXT_START_RESPONSE;
91         p_fapi_resp->header.length =
92             (uint16_t) sizeof(fapi_vendor_ext_start_response_t);
93
94         /* Add element to send list */
95         nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
96         p_stats->fapi_stats.fapi_vext_start_res++;
97         NR5G_FAPI_LOG(INFO_LOG, ("[START.response][%d]", phy_id));
98 #endif
99     } else if (1 == p_iapi_resp->nStatus) {
100         p_list_elem =
101             nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_ERROR_INDICATION, 1,
102             sizeof(fapi_error_ind_t));
103         if (!p_list_elem) {
104             NR5G_FAPI_LOG(ERROR_LOG, ("[START.response] Unable to create "
105                     "list element. Out of memory!!!"));
106             return FAILURE;
107         }
108
109         /* PHY STOP Failed. Sending Error Indication to MAC */
110         p_fapi_error_ind = (fapi_error_ind_t *) (p_list_elem + 1);
111         p_fapi_error_ind->header.msg_id = FAPI_ERROR_INDICATION;
112         p_fapi_error_ind->header.length = (uint16_t) sizeof(fapi_error_ind_t);
113         p_fapi_error_ind->sfn = p_iapi_resp->sSFN_Slot.nSFN;
114         p_fapi_error_ind->slot = p_iapi_resp->sSFN_Slot.nSlot;
115         p_fapi_error_ind->message_id = FAPI_START_REQUEST;
116         p_fapi_error_ind->error_code = p_iapi_resp->nStatus;
117
118         /* Add element to send list */
119         nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
120         p_stats->fapi_stats.fapi_error_ind++;
121         NR5G_FAPI_LOG(INFO_LOG, ("[ERROR.Indication][%d]", phy_id));
122     } else {
123         NR5G_FAPI_LOG(ERROR_LOG, ("[START.response] Invalid status "
124                 "from PHY"));
125         return FAILURE;
126     }
127
128     return SUCCESS;
129 }