Update to odulow per maintenance bronze
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / nr5g_fapi_proc_error_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 ERROR.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_proc_error_ind.h"
29
30  /** @ingroup group_source_api_fapi2mac_proc
31  *
32  *  @param[in]  p_phy_ctx Pointer to PHY context.
33  *  @param[in]  p_iapi_resp Pointer to IAPI ERROR.indication message structure.
34  *  @return     Returns ::SUCCESS and ::FAILURE.
35  *
36  *  @description
37  *  This message allows PHY to report errors to L2/L3.
38  *
39 **/
40 uint8_t nr5g_fapi_error_indication(
41     p_nr5g_fapi_phy_ctx_t p_phy_ctx,
42     PERRORIndicationStruct p_iapi_resp)
43 {
44     uint8_t phy_id;
45     fapi_error_ind_t *p_fapi_error_ind;
46     p_fapi_api_queue_elem_t p_list_elem;
47     p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
48
49     if (NULL == p_phy_ctx) {
50         NR5G_FAPI_LOG(ERROR_LOG,
51             ("[NR5G_FAPI] [ERROR.indication] Invalid handle to "
52                 "phy context"));
53         return FAILURE;
54     }
55
56     if (NULL == p_iapi_resp) {
57         NR5G_FAPI_LOG(ERROR_LOG,
58             ("[NR5G_FAPI] [ERROR.indication] Invalid handle to iapi "
59                 "stop indication message"));
60         return FAILURE;
61     }
62
63     phy_id = p_iapi_resp->sSFN_Slot.nCarrierIdx;
64     p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
65     if (p_phy_instance->phy_id != p_iapi_resp->sSFN_Slot.nCarrierIdx) {
66         NR5G_FAPI_LOG(ERROR_LOG,
67             ("[NR5G_FAPI] [ERROR.indication] Invalid handle"
68                 "to phy instance"));
69         return FAILURE;
70     }
71
72     p_list_elem =
73         nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_ERROR_INDICATION, 1,
74         sizeof(fapi_error_ind_t));
75     if (!p_list_elem) {
76         NR5G_FAPI_LOG(ERROR_LOG,
77             ("[NR5G_FAPI] [ERROR.indication] Unable to create "
78                 "list element. Out of memory!!!"));
79         return FAILURE;
80     }
81
82     p_fapi_error_ind = (fapi_error_ind_t *) (p_list_elem + 1);
83     p_fapi_error_ind->header.msg_id = FAPI_ERROR_INDICATION;
84     p_fapi_error_ind->header.length = p_iapi_resp->sMsgHdr.nMessageLen;
85     p_fapi_error_ind->sfn = p_iapi_resp->sSFN_Slot.nSFN;
86     p_fapi_error_ind->slot = p_iapi_resp->sSFN_Slot.nSlot;
87     // p_fapi_error_ind->message_id     =   ; // TODO message id is not supported in IAPI error indication
88     p_fapi_error_ind->error_code = p_iapi_resp->nStatus;
89
90     nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
91
92     // phyStats->iaL1ApiStats.errorInd++; //TODO
93     NR5G_FAPI_LOG(INFO_LOG, ("[NR5G_FAPI][ERROR.indication][%d][%d,%d]",
94             p_phy_instance->phy_id,
95             p_iapi_resp->sSFN_Slot.nSFN, p_iapi_resp->sSFN_Slot.nSlot));
96
97     return SUCCESS;
98 }