NR_IF_Module.c 9.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22
/* \file NR_IF_Module.c
23
 * \brief functions for NR UE FAPI-like interface
24
 * \author R. Knopp, K.H. HSU
25 26
 * \date 2018
 * \version 0.1
27 28
 * \company Eurecom / NTUST
 * \email: knopp@eurecom.fr, kai-hsiang.hsu@eurecom.fr
29 30 31 32 33
 * \note
 * \warning
 */

#include "NR_IF_Module.h"
34
#include "mac_proto.h"
35
#include "assertions.h"
36

37
#include <stdio.h>
38 39 40 41 42

#define MAX_IF_MODULES 100

static nr_ue_if_module_t *nr_ue_if_module_inst[MAX_IF_MODULES];

43
//  L2 Abstraction Layer
44
int handle_bcch_bch(module_id_t module_id, int cc_id, unsigned int gNB_index, uint8_t *pduP, unsigned int additional_bits, uint32_t ssb_index, uint32_t ssb_length, uint16_t cell_id){
45

46 47 48 49 50 51
    return nr_ue_decode_mib( module_id,
                             cc_id,
                             gNB_index,
                             additional_bits,
                             ssb_length,  //  Lssb = 64 is not support    
                             ssb_index,
52 53
                             pduP, 
                             cell_id);
54

55
}
56

57
//  L2 Abstraction Layer
58
int handle_bcch_dlsch(module_id_t module_id, int cc_id, unsigned int gNB_index, uint32_t sibs_mask, uint8_t *pduP, uint32_t pdu_len){
59

60 61
    return 0;
}
62
//  L2 Abstraction Layer
63
int handle_dci(module_id_t module_id, int cc_id, unsigned int gNB_index, fapi_nr_dci_pdu_rel15_t *dci, uint16_t rnti, uint32_t dci_type){
64

65
    return nr_ue_process_dci(module_id, cc_id, gNB_index, dci, rnti, dci_type);
66

67 68 69 70 71 72 73 74 75 76 77 78
}
//  L2 Abstraction Layer
int8_t handle_dlsch (module_id_t module_id, int cc_id, uint8_t gNB_index, fapi_nr_dci_indication_t *dci_ind, uint8_t *pduP, uint32_t pdu_len){

//    return 0;
    return nr_ue_process_dlsch( module_id,
                                cc_id,
                                gNB_index,
                                &dci_ind,
                                pduP,
                                pdu_len);

79 80
}

81
int nr_ue_ul_indication(nr_uplink_indication_t *ul_info){
82 83

    NR_UE_L2_STATE_t ret;
84 85
    module_id_t module_id = ul_info->module_id;
    NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
86

87 88 89 90 91 92
    // clean previous FAPI messages
    mac->tx_request.number_of_pdus = 0;
    mac->ul_config_request.number_pdus = 0;
    mac->dl_config_request.number_pdus = 0;
    // clean previous FAPI messages

93 94 95 96 97 98
    ret = nr_ue_scheduler(
        ul_info->module_id,
        ul_info->gNB_index,
        ul_info->cc_id,
        ul_info->frame,
        ul_info->slot,
99
        ul_info->ssb_index, 
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
        0, 0); //  TODO check tx/rx frame/slot is need for NR version

    switch(ret){
        case CONNECTION_OK:
            break;
        case CONNECTION_LOST:
            break;
        case PHY_RESYNCH:
            break;
        case PHY_HO_PRACH:
            break;
        default:
            break;
    }

115 116 117

    mac->if_module->scheduled_response(&mac->scheduled_response);

118 119 120
    return 0;
}

121
int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){
122
    
123
    int32_t i;
124
    uint32_t ret_mask = 0x0;
125 126 127 128 129
    module_id_t module_id = dl_info->module_id;
    NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);

    //  clean up scheduled_response structure

130

131
    if(dl_info->dci_ind != NULL){
132
        printf("[L2][IF MODULE][DL INDICATION][DCI_IND]\n");
133 134
        for(i=0; i<dl_info->dci_ind->number_of_dcis; ++i){
			//printf(">>>NR_IF_Module i=%d, dl_info->dci_ind->number_of_dcis=%d\n",i,dl_info->dci_ind->number_of_dcis);
Calvin HSU's avatar
Calvin HSU committed
135
            fapi_nr_dci_pdu_rel15_t *dci = &dl_info->dci_ind->dci_list[i].dci;
136 137 138 139 140 141 142 143 144 145 146

            ret_mask |= (handle_dci(
                dl_info->module_id,
                dl_info->cc_id,
                dl_info->gNB_index,
                dci, 
                (dl_info->dci_ind->dci_list+i)->rnti, 
                (dl_info->dci_ind->dci_list+i)->dci_format)) << FAPI_NR_DCI_IND;


            /*switch((dl_info->dci_ind->dci_list+i)->dci_type){
147 148 149 150 151 152 153 154 155 156 157 158
                case FAPI_NR_DCI_TYPE_0_0:
                case FAPI_NR_DCI_TYPE_0_1:
                case FAPI_NR_DCI_TYPE_1_1:
                case FAPI_NR_DCI_TYPE_2_0:
                case FAPI_NR_DCI_TYPE_2_1:
                case FAPI_NR_DCI_TYPE_2_2:
                case FAPI_NR_DCI_TYPE_2_3:
                    AssertFatal(1==0, "Not yet support at this moment!\n");
                    break;
                
                case FAPI_NR_DCI_TYPE_1_0:
                    
159
                    dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH;
160 161

                    //  mapping into DL_CONFIG_REQ for DL-SCH
Calvin HSU's avatar
Calvin HSU committed
162
                    fapi_nr_dl_config_dlsch_pdu_rel15_t *dlsch_config_pdu = &dl_config->dl_config_list[dl_config->number_pdus].dlsch_config_pdu.dlsch_config_rel15;
163
                    
164 165 166
                    dl_config->dl_config_list[dl_config->number_pdus].dlsch_config_pdu.rnti = 0x0000;   //  TX RNTI: UE-spec
                    memcpy(dlsch_config_pdu, dci, sizeof(fapi_nr_dci_pdu_rel15_t));

167 168 169 170 171 172 173 174 175 176 177
                    dl_config->number_pdus = dl_config->number_pdus + 1;

                    ret_mask |= (handle_dci(
                                dl_info->module_id,
                                dl_info->cc_id,
                                dl_info->gNB_index,
                                dci, 
                                (dl_info->dci_ind->dci_list+i)->rnti, 
                                (dl_info->dci_ind->dci_list+i)->dci_type)) << FAPI_NR_DCI_IND;

                    
178

179
                    break;
180

181 182
                default:
                    break;
183
            }*/
184 185 186 187 188 189 190

            //(dl_info->dci_list+i)->rnti
            
            


        }
191
    }
192

193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
    if(dl_info->rx_ind != NULL){
        printf("[L2][IF MODULE][DL INDICATION][RX_IND]\n");
        for(i=0; i<dl_info->rx_ind->number_pdus; ++i){
            switch(dl_info->rx_ind->rx_indication_body[i].pdu_type){
                case FAPI_NR_RX_PDU_TYPE_MIB:
                    ret_mask |= (handle_bcch_bch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index,
                                (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.pdu,
                                (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.additional_bits,
                                (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.ssb_index,
                                (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.ssb_length,
                                (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.cell_id )) << FAPI_NR_RX_PDU_TYPE_MIB;
                    break;
                case FAPI_NR_RX_PDU_TYPE_SIB:
                    ret_mask |= (handle_bcch_dlsch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index,
                                (dl_info->rx_ind->rx_indication_body+i)->sib_pdu.sibs_mask,
                                (dl_info->rx_ind->rx_indication_body+i)->sib_pdu.pdu,
                                (dl_info->rx_ind->rx_indication_body+i)->sib_pdu.pdu_length )) << FAPI_NR_RX_PDU_TYPE_SIB;
                    break;
                case FAPI_NR_RX_PDU_TYPE_DLSCH:
//                    ret_mask |= (0) << FAPI_NR_RX_PDU_TYPE_DLSCH;
                    ret_mask |= (handle_dlsch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index, &dl_info->dci_ind,
                                (dl_info->rx_ind->rx_indication_body+i)->pdsch_pdu.pdu,
                                (dl_info->rx_ind->rx_indication_body+i)->pdsch_pdu.pdu_length)) << FAPI_NR_RX_PDU_TYPE_DLSCH;

                    break;
                default:

                    break;

            }
        }
    }


227 228
    AssertFatal( nr_ue_if_module_inst[module_id] != NULL, "IF module is void!\n" );
    nr_ue_if_module_inst[module_id]->scheduled_response(&mac->scheduled_response);
229

230 231
    return 0;
}
232 233 234 235

nr_ue_if_module_t *nr_ue_if_module_init(uint32_t module_id){

    if (nr_ue_if_module_inst[module_id] == NULL) {
236
        nr_ue_if_module_inst[module_id] = (nr_ue_if_module_t *)malloc(sizeof(nr_ue_if_module_t));
237 238
        memset((void*)nr_ue_if_module_inst[module_id],0,sizeof(nr_ue_if_module_t));

239 240 241 242 243
        nr_ue_if_module_inst[module_id]->cc_mask=0;
        nr_ue_if_module_inst[module_id]->current_frame = 0;
        nr_ue_if_module_inst[module_id]->current_slot = 0;
        nr_ue_if_module_inst[module_id]->phy_config_request = NULL;
        nr_ue_if_module_inst[module_id]->scheduled_response = NULL;
244
        nr_ue_if_module_inst[module_id]->dl_indication = nr_ue_dl_indication;
245
        nr_ue_if_module_inst[module_id]->ul_indication = nr_ue_ul_indication;
246 247 248 249 250
    }

    return nr_ue_if_module_inst[module_id];
}

251
int nr_ue_if_module_kill(uint32_t module_id) {
252 253 254 255 256 257

    if (nr_ue_if_module_inst[module_id] != NULL){
        free(nr_ue_if_module_inst[module_id]);
    } 
    return 0;
}