0ed27b6e57eb538cdecb9a32e60240d768b467db
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p5 / nr5g_fapi_proc_stop_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 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 STOP.indication message structure.
34  *  @return     Returns ::SUCCESS and ::FAILURE.
35  *
36  *  @description
37  *  This message allows PHY to indicate that it has successfully stopped
38  *  and returned to the CONFIGURED state. 
39  *
40 **/
41 uint8_t nr5g_fapi_stop_indication(
42     p_nr5g_fapi_phy_ctx_t p_phy_ctx,
43     PSTOPRESPONSEStruct p_iapi_resp)
44 {
45     uint8_t phy_id;
46
47     fapi_stop_ind_t *p_fapi_resp;
48     fapi_error_ind_t *p_fapi_error_ind;
49     p_fapi_api_queue_elem_t p_list_elem;
50     p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
51     nr5g_fapi_stats_t *p_stats;
52
53     if (NULL == p_phy_ctx) {
54         NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Invalid " "phy context"));
55         return FAILURE;
56     }
57
58     if (NULL == p_iapi_resp) {
59         NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Invalid "
60                 "stop response message"));
61         return FAILURE;
62     }
63
64     phy_id = p_iapi_resp->sSFN_Slot.nCarrierIdx;
65     p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
66     if (p_phy_instance->phy_id != phy_id) {
67         NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Invalid " "phy instance"));
68         return FAILURE;
69     }
70
71     p_stats = &p_phy_instance->stats;
72     p_stats->iapi_stats.iapi_stop_ind++;
73     if (0 == p_iapi_resp->nStatus) {
74         if (FAPI_STATE_RUNNING == p_phy_instance->state) {
75             p_phy_instance->state = FAPI_STATE_CONFIGURED;
76         }
77         p_list_elem =
78             nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_STOP_INDICATION, 1,
79             sizeof(fapi_stop_ind_t));
80         if (!p_list_elem) {
81             NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Unable to create "
82                     "list element. Out of memory!!!"));
83             return FAILURE;
84         }
85
86         p_fapi_resp = (fapi_stop_ind_t *) (p_list_elem + 1);
87         p_fapi_resp->header.msg_id = FAPI_STOP_INDICATION;
88         p_fapi_resp->header.length = (uint16_t) sizeof(fapi_stop_ind_t);
89         /* Add element to send list */
90         nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
91         p_stats->fapi_stats.fapi_stop_ind++;
92         NR5G_FAPI_LOG(INFO_LOG, ("[STOP.indication][%d]", phy_id));
93     } else if (1 == p_iapi_resp->nStatus) {
94         p_list_elem =
95             nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_ERROR_INDICATION, 1,
96             sizeof(fapi_error_ind_t));
97         if (!p_list_elem) {
98             NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Unable to create "
99                     "list element. Out of memory!!!"));
100             return FAILURE;
101         }
102
103         /* PHY STOP Failed. Sending Error Indication to MAC */
104         p_fapi_error_ind = (fapi_error_ind_t *) (p_list_elem + 1);
105         p_fapi_error_ind->header.msg_id = FAPI_ERROR_INDICATION;
106         p_fapi_error_ind->header.length = (uint16_t) sizeof(fapi_error_ind_t);
107         p_fapi_error_ind->sfn = p_iapi_resp->sSFN_Slot.nSFN;
108         p_fapi_error_ind->slot = p_iapi_resp->sSFN_Slot.nSlot;
109         p_fapi_error_ind->message_id = FAPI_STOP_REQUEST;
110         p_fapi_error_ind->error_code = p_iapi_resp->nStatus;
111         /* Add element to send list */
112         nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
113         p_stats->fapi_stats.fapi_error_ind++;
114         NR5G_FAPI_LOG(INFO_LOG, ("[STOP.indication][ERROR.indication][%d]",
115                 phy_id));
116     } else {
117         NR5G_FAPI_LOG(ERROR_LOG, ("[STOP.indication] Invalid status "
118                 "from PHY"));
119         return FAILURE;
120     }
121     return SUCCESS;
122 }