mac_proto.h 11.5 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 proto.h
23
 * \brief MAC functions prototypes for gNB and UE
24 25 26 27 28 29 30
 * \author R. Knopp, K.H. HSU
 * \date 2018
 * \version 0.1
 * \company Eurecom / NTUST
 * \email: knopp@eurecom.fr, kai-hsiang.hsu@eurecom.fr
 * \note
 * \warning
31
 */
32

laurent's avatar
laurent committed
33 34
#ifndef __LAYER2_MAC_UE_PROTO_H__
#define __LAYER2_MAC_UE_PROTO_H__
35

36
#include "mac_defs.h"
37
#include "mac.h"
38 39 40
#include "PHY/defs_nr_UE.h"
#include "RRC/NR_UE/rrc_defs.h"

41 42

/**\brief decode mib pdu in NR_UE, from if_module ul_ind with P7 tx_ind message
43
   \param module_id      module id
44
   \param cc_id          component carrier id
45 46
   \param gNB_index      gNB index
   \param extra_bits     extra bits for frame calculation
47
   \param l_ssb_equal_64 check if ssb number of candicate is equal 64, 1=equal; 0=non equal. Reference 38.212 7.1.1
48
   \param pduP           pointer to pdu
49 50
   \param pdu_length     length of pdu
   \param cell_id        cell id */
51 52 53 54 55
int8_t nr_ue_decode_mib(
    module_id_t module_id, 
    int cc_id, 
    uint8_t gNB_index, 
    uint8_t extra_bits, 
56 57
    uint32_t ssb_length, 
    uint32_t ssb_index,
58 59
    void *pduP, 
    uint16_t cell_id );
60 61 62 63


/**\brief primitive from RRC layer to MAC layer for configuration L1/L2, now supported 4 rrc messages: MIB, cell_group_config for MAC/PHY, spcell_config(serving cell config)
   \param module_id                 module id
64
   \param cc_id                     component carrier id
65 66
   \param gNB_index                 gNB index
   \param mibP                      pointer to RRC message MIB
Raymond Knopp's avatar
Raymond Knopp committed
67
   \param sccP                      pointer to ServingCellConfigCommon structure,
68
   \param spcell_configP            pointer to RRC message serving cell config*/
69 70 71 72 73
int nr_rrc_mac_config_req_ue(
    module_id_t                     module_id,
    int                             cc_idP,
    uint8_t                         gNB_index,
    NR_MIB_t                        *mibP,
74
    //NR_ServingCellConfigCommon_t    *sccP,
75
    NR_CellGroupConfig_t            *cell_group_config);
Raymond Knopp's avatar
Raymond Knopp committed
76

77
/**\brief initialization NR UE MAC instance(s), total number of MAC instance based on NB_NR_UE_MAC_INST*/
78
NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst);
79

80 81 82 83 84 85 86
/**\brief fetch MAC instance by module_id, within 0 - (NB_NR_UE_MAC_INST-1)
   \param module_id index of MAC instance(s)*/
NR_UE_MAC_INST_t *get_mac_inst(
    module_id_t module_id);

/**\brief called at each slot, slot length based on numerology. now use u=0, scs=15kHz, slot=1ms
          performs BSR/SR/PHR procedures, random access procedure handler and DLSCH/ULSCH procedures.
cig's avatar
cig committed
87 88 89
   \param dl_info     DL indication
   \param ul_info     UL indication*/
NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_indication_t *ul_info);
90 91 92 93 94 95 96 97 98 99 100 101

/* \brief Get SR payload (0,1) from UE MAC
@param Mod_id Instance id of UE in machine
@param CC_id Component Carrier index
@param eNB_id Index of eNB that UE is attached to
@param rnti C_RNTI of UE
@param subframe subframe number
@returns 0 for no SR, 1 for SR
*/
uint32_t ue_get_SR(module_id_t module_idP, int CC_id, frame_t frameP,
       uint8_t eNB_id, rnti_t rnti, sub_frame_t subframe);

102
int8_t nr_ue_get_SR(module_id_t module_idP, int CC_id, frame_t frameP, uint8_t eNB_id, uint16_t rnti, sub_frame_t subframe);
103

104
int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, dci_pdu_rel15_t *dci, uint16_t rnti, uint32_t dci_format);
105
int nr_ue_process_dci_indication_pdu(module_id_t module_id,int cc_id, int gNB_index,fapi_nr_dci_indication_pdu_t *dci);
106

107
uint32_t get_ssb_frame(uint32_t test);
108 109 110 111
uint32_t get_ssb_slot(uint32_t ssb_index);


uint32_t mr_ue_get_SR(module_id_t module_idP, int CC_id, frame_t frameP, uint8_t eNB_id, uint16_t rnti, sub_frame_t subframe);
112

113 114 115 116
/* \brief Get payload (MAC PDU) from UE PHY
@param module_idP Instance id of UE in machine
@param CC_id Component Carrier index
@param frameP Current Rx frame
cig's avatar
cig committed
117
@param slotP Current Rx slot
118 119
@param pdu Pointer to the MAC PDU
@param pdu_len Length of the MAC PDU
cig's avatar
cig committed
120 121
@param gNB_id Index of gNB that UE is attached to
@param ul_time_alignment of struct handling the timing advance parameters
122 123
@returns void
*/
cig's avatar
cig committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
void nr_ue_send_sdu(module_id_t module_idP, 
                    uint8_t CC_id,
                    frame_t frameP,
                    int slotP,
                    uint8_t * pdu,
                    uint16_t pdu_len,
                    uint8_t gNB_index,
                    NR_UL_TIME_ALIGNMENT_t *ul_time_alignment);

void nr_ue_process_mac_pdu(module_id_t module_idP,
                           uint8_t CC_id,
                           frame_t frameP,
                           uint8_t *pduP, 
                           uint16_t mac_pdu_len,
                           uint8_t gNB_index,
                           NR_UL_TIME_ALIGNMENT_t *ul_time_alignment);
140

cig's avatar
cig committed
141

142
uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload,
cig's avatar
cig committed
143 144 145 146 147 148 149 150 151
                                    uint8_t *pdu,
                                    uint8_t num_sdus,
                                    uint16_t *sdu_lengths,
                                    uint8_t *sdu_lcids,
                                    uint8_t power_headroom,
                                    uint16_t crnti,
                                    uint16_t truncated_bsr,
                                    uint16_t short_bsr,
                                    uint16_t long_bsr,
152 153
                                    unsigned short post_padding,
                                    uint16_t buflen);
cig's avatar
cig committed
154

155
int8_t nr_ue_process_dlsch(module_id_t module_id, int cc_id, uint8_t gNB_index, fapi_nr_dci_indication_t *dci_ind, void *pduP, uint32_t pdu_len);
156

cig's avatar
cig committed
157
void ue_dci_configuration(NR_UE_MAC_INST_t *mac, fapi_nr_dl_config_request_t *dl_config, frame_t frame, int slot);
158

Francesco Mani's avatar
Francesco Mani committed
159
void nr_extract_dci_info(NR_UE_MAC_INST_t *mac,
cig's avatar
cig committed
160 161 162 163
                         int dci_format,
                         uint8_t dci_length,
                         uint16_t rnti,
                         uint64_t *dci_pdu,
164
                         dci_pdu_rel15_t *nr_pdci_info_extracted);
165 166


laurent's avatar
laurent committed
167 168
uint8_t
nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
169
           sub_frame_t subframe, uint8_t eNB_index,
laurent's avatar
laurent committed
170 171
           uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode) ;

172 173 174
int set_tdd_config_nr_ue(fapi_nr_config_request_t *cfg, int mu,
                         int nrofDownlinkSlots, int nrofDownlinkSymbols,
                         int nrofUplinkSlots,   int nrofUplinkSymbols);
175

176 177 178 179
/** \brief Function for UE/PHY to compute PUSCH transmit power in power-control procedure.
    @param Mod_id Module id of UE
    @returns Po_NOMINAL_PUSCH (PREAMBLE_RECEIVED_TARGET_POWER+DELTA_PREAMBLE
*/
cig's avatar
cig committed
180
int nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_t module_idP, uint8_t CC_id);
181 182 183 184 185 186

/** \brief Function to compute DELTA_PREAMBLE from 38.321 subclause 7.3
   (for RA power ramping procedure and Msg3 PUSCH power control policy)
    @param Mod_id Module id of UE
    @returns DELTA_PREAMBLE
*/
cig's avatar
cig committed
187
int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id, uint16_t prach_format);
188

cig's avatar
cig committed
189 190
/* Random Access */

cig's avatar
cig committed
191 192 193 194 195 196 197 198 199
/* \brief This function schedules the PRACH according to prach_ConfigurationIndex and TS 38.211 tables 6.3.3.2.x
and fills the PRACH PDU per each FD occasion.
@param module_idP Index of UE instance
@param frameP Frame index
@param slotP Slot index
@returns void
*/
void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t slotP);

200 201 202 203 204 205 206 207 208 209 210 211
/* \brief Function called by PHY to process the received RAR and check that the preamble matches what was sent by the gNB. It provides the timing advance and t-CRNTI.
@param Mod_id Index of UE instance
@param CC_id Index to a component carrier
@param frame Frame index
@param ra_rnti RA_RNTI value
@param dlsch_buffer  Pointer to dlsch_buffer containing RAR PDU
@param t_crnti Pointer to PHY variable containing the T_CRNTI
@param preamble_index Preamble Index used by PHY to transmit the PRACH.  This should match the received RAR to trigger the rest of
random-access procedure
@param selected_rar_buffer the output buffer for storing the selected RAR header and RAR payload
@returns timing advance or 0xffff if preamble doesn't match
*/
cig's avatar
cig committed
212 213 214 215 216 217
uint16_t nr_ue_process_rar(module_id_t mod_id,
                           int CC_id,
                           frame_t frameP,
                           uint8_t * dlsch_buffer,
                           rnti_t * t_crnti,
                           uint8_t preamble_index,
218 219
                           uint8_t * selected_rar_buffer);

cig's avatar
cig committed
220 221
void nr_process_rar(nr_downlink_indication_t *dl_info);

222 223 224 225
void ue_contention_resolution(module_id_t module_id, uint8_t gNB_index, int cc_id, frame_t tx_frame);

void nr_ra_failed(uint8_t Mod_id, uint8_t CC_id, uint8_t gNB_index);

cig's avatar
cig committed
226 227 228 229 230 231 232 233 234 235 236 237
void nr_ra_succeeded(uint8_t Mod_id, uint8_t CC_id, uint8_t gNB_index);

/* \brief Function called by PHY to retrieve information to be transmitted using the RA procedure.
If the UE is not in PUSCH mode for a particular eNB index, this is assumed to be an Msg3 and MAC
attempts to retrieves the CCCH message from RRC. If the UE is in PUSCH mode for a particular eNB
index and PUCCH format 0 (Scheduling Request) is not activated, the MAC may use this resource for
andom-access to transmit a BSR along with the C-RNTI control element (see 5.1.4 from 36.321)
@param mod_id Index of UE instance
@param CC_id Component Carrier Index
@param frame
@param gNB_id gNB index
@param nr_tti_tx slot for PRACH transmission
cig's avatar
cig committed
238 239 240 241 242 243 244 245
@returns indication to generate PRACH to phy */
uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
                       module_id_t mod_id,
                       int CC_id,
                       UE_MODE_t UE_mode,
                       frame_t frame,
                       uint8_t gNB_id,
                       int nr_tti_tx);
cig's avatar
cig committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265

/* \brief Function implementing the routine for the selection of Random Access resources (5.1.2 TS 38.321).
@param module_idP Index of UE instance
@param CC_id Component Carrier Index
@param gNB_index gNB index
@param t_id
@param rach_ConfigDedicated
@returns void */
void nr_get_prach_resources(module_id_t mod_id,
                            int CC_id,
                            uint8_t gNB_id,
                            uint8_t t_id,
                            uint8_t first_Msg3,
                            NR_PRACH_RESOURCES_t *prach_resources,
                            NR_RACH_ConfigDedicated_t * rach_ConfigDedicated);

void nr_Msg1_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint8_t gNB_id);

void nr_Msg3_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint8_t gNB_id);

laurent's avatar
laurent committed
266
void nr_ue_msg2_scheduler(module_id_t mod_id, uint16_t rach_frame, uint16_t rach_slot, uint16_t *msg2_frame, uint16_t *msg2_slot);
267
#endif
268
/** @}*/