* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p5 / nr5g_fapi_proc_config_resp.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2021 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 CONFIG.response message.
22  *
23  **/
24
25 #include "nr5g_fapi_framework.h"
26 #include "nr5g_fapi_fapi2mac_api.h"
27 #include "nr5g_fapi_fapi2mac_p5_proc.h"
28
29  /** @ingroup group_source_api_p5_fapi2mac_proc
30  *
31  *  @param[in]  p_phy_instance Pointer to PHY instance.
32  *  @param[in]  p_fapi_resp Pointer to IAPI CONFIG.response message structure.
33  *  @return     Returns ::SUCCESS and ::FAILURE.
34  *
35  *  @description
36  *  This message allows PHY to report L2/L3 about CONFIG.request's status.
37  *
38 **/
39 uint8_t nr5g_fapi_config_response(
40     p_nr5g_fapi_phy_ctx_t p_phy_ctx,
41     PCONFIGRESPONSEStruct p_iapi_resp)
42 {
43     uint8_t phy_id;
44     fapi_config_resp_t *p_fapi_resp;
45     p_fapi_api_queue_elem_t p_list_elem;
46     p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
47     nr5g_fapi_stats_t *p_stats;
48
49     if (NULL == p_phy_ctx) {
50         NR5G_FAPI_LOG(ERROR_LOG, ("[CONFIG.response] Invalid " "phy context"));
51         return FAILURE;
52     }
53
54     if (NULL == p_iapi_resp) {
55         NR5G_FAPI_LOG(ERROR_LOG, ("[CONFIG.response] Invalid iapi "
56                 "config response message"));
57         return FAILURE;
58     }
59
60     phy_id = p_iapi_resp->nCarrierIdx;
61     p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
62     if (p_phy_instance->phy_id != phy_id) {
63         NR5G_FAPI_LOG(ERROR_LOG, ("[CONFIG.response] Invalid " "phy instance"));
64         return FAILURE;
65     }
66     // Create FAPI message header
67     if (FAPI_STATE_IDLE == p_phy_instance->state)
68         nr5g_fapi_message_header_per_phy(phy_id, false);
69
70     p_stats = &p_phy_instance->stats;
71     p_stats->iapi_stats.iapi_config_res++;
72     p_list_elem =
73         nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_CONFIG_RESPONSE, 1,
74         sizeof(fapi_config_resp_t));
75     if (!p_list_elem) {
76         NR5G_FAPI_LOG(ERROR_LOG, ("[CONFIG.response] Unable to create "
77                 "list element. Out of memory!!!"));
78         return FAILURE;
79     }
80
81     p_fapi_resp = (fapi_config_resp_t *) (p_list_elem + 1);
82     p_fapi_resp->header.msg_id = FAPI_CONFIG_RESPONSE;
83     p_fapi_resp->header.length = (uint16_t) sizeof(fapi_config_resp_t);
84     p_fapi_resp->error_code = p_iapi_resp->nStatus;
85
86     if (FAPI_STATE_IDLE == p_phy_instance->state && 0 == p_iapi_resp->nStatus) {
87         p_phy_ctx->num_phy_instance += 1;
88         p_phy_instance->state = FAPI_STATE_CONFIGURED;
89     }
90     // TODO: Update phy_id to 0 in phy_instance on error.
91
92     /* TLV report is not supported in PHY */
93     p_fapi_resp->number_of_invalid_tlvs = 0;
94     p_fapi_resp->number_of_inv_tlvs_idle_only = 0;
95     p_fapi_resp->number_of_inv_tlvs_running_only = 0;
96     p_fapi_resp->number_of_missing_tlvs = 0;
97
98     // Add element to send list
99     nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem, false);
100
101     p_stats->fapi_stats.fapi_config_res++;
102     NR5G_FAPI_LOG(INFO_LOG, ("[CONFIG.response][%d]", phy_id));
103
104     return SUCCESS;
105 }