e5c5810ef28f676e7a386041e989956930fed113
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p5 / nr5g_fapi_proc_fapi_msg_header.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 #include "nr5g_fapi_internal.h"
30
31  /** @ingroup group_source_api_p5_fapi2mac_proc
32  *
33  *  @param[in]  p_phy_instance Pointer to PHY instance.
34  *  @param[in]  p_fapi_resp Pointer to IAPI CONFIG.response message structure.
35  *  @return     Returns ::SUCCESS and ::FAILURE.
36  *
37  *  @description
38  *  This Message is the FAPI Message Header.
39  *
40 **/
41 uint8_t nr5g_fapi_message_header(
42     p_nr5g_fapi_phy_ctx_t p_phy_ctx)
43 {
44     uint8_t phy_id = 0;
45
46     p_fapi_api_queue_elem_t p_list_elem = NULL;
47     p_fapi_msg_header_t p_fapi_msg_hdr = NULL;
48
49     for (phy_id = 0; phy_id < FAPI_MAX_PHY_INSTANCES; phy_id++) {
50         if ((FAPI_STATE_CONFIGURED == p_phy_ctx->phy_instance[phy_id].state) ||
51             (FAPI_STATE_RUNNING == p_phy_ctx->phy_instance[phy_id].state)) {
52             p_list_elem =
53                 nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_MSG_HEADER_IND, 1,
54                 sizeof(fapi_msg_header_t));
55             if (!p_list_elem) {
56                 NR5G_FAPI_LOG(ERROR_LOG, ("[FAPI MSG HDR] Unable to create "
57                         "list element. Out of memory!!!"));
58                 return FAILURE;
59             }
60
61             p_fapi_msg_hdr = (fapi_msg_header_t *) (p_list_elem + 1);
62             p_fapi_msg_hdr->num_msg = 0;
63             p_fapi_msg_hdr->handle = phy_id;
64
65             // Add element to send list
66             nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
67             NR5G_FAPI_LOG(DEBUG_LOG,
68                 ("[FAPI MSG HDR] FAPI Message Header Added for PHY: %d",
69                     phy_id));
70         }
71     }
72
73     return SUCCESS;
74 }
75
76 /** @ingroup group_source_api_p5_fapi2mac_proc
77  *
78  *  @param[in]  p_phy_instance Pointer to PHY instance.
79  *  @param[in]  p_fapi_resp Pointer to IAPI CONFIG.response message structure.
80  *  @return     Returns ::SUCCESS and ::FAILURE.
81  *
82  *  @description
83  *  This Message is the FAPI Message Header.
84  *
85 **/
86 uint8_t nr5g_fapi_message_header_per_phy(
87     uint8_t phy_id)
88 {
89     p_fapi_api_queue_elem_t p_list_elem = NULL;
90     p_fapi_msg_header_t p_fapi_msg_hdr = NULL;
91
92     p_list_elem =
93         nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_MSG_HEADER_IND, 1,
94         sizeof(fapi_msg_header_t));
95     if (!p_list_elem) {
96         NR5G_FAPI_LOG(ERROR_LOG, ("[FAPI MSG HDR] Unable to create "
97                 "list element. Out of memory!!!"));
98         return FAILURE;
99     }
100
101     p_fapi_msg_hdr = (fapi_msg_header_t *) (p_list_elem + 1);
102     p_fapi_msg_hdr->num_msg = 0;
103     p_fapi_msg_hdr->handle = phy_id;
104
105     // Add element to send list
106     nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
107     NR5G_FAPI_LOG(DEBUG_LOG,
108         ("[FAPI MSG HDR] FAPI Message Header Added for PHY: %d", phy_id));
109
110     return SUCCESS;
111 }