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