Commit e3e158a7 authored by francescomani's avatar francescomani

RRC go to IDLE

parent 4b019293
......@@ -4277,33 +4277,6 @@ void get_type0_PDCCH_CSS_config_parameters(NR_Type0_PDCCH_CSS_config_t *type0_PD
AssertFatal(type0_PDCCH_CSS_config->num_symbols != -1, "Type0 PDCCH coreset num_symbols undefined");
AssertFatal(type0_PDCCH_CSS_config->rb_offset != -1, "Type0 PDCCH coreset rb_offset undefined");
//uint32_t cell_id = 0; // obtain from L1 later
//mac->type0_pdcch_dci_config.coreset.rb_start = rb_offset;
//mac->type0_pdcch_dci_config.coreset.rb_end = rb_offset + num_rbs - 1;
// uint64_t mask = 0x0;
// uint8_t i;
// for(i=0; i<(type0_PDCCH_CSS_config->num_rbs/6); ++i){ // 38.331 Each bit corresponds a group of 6 RBs
// mask = mask >> 1;
// mask = mask | 0x100000000000;
// }
//LOG_I(MAC,">>>>>>>>mask %x num_rbs %d rb_offset %d\n", mask, num_rbs, rb_offset);
// mac->type0_pdcch_dci_config.coreset.frequency_domain_resource = mask;
// mac->type0_pdcch_dci_config.coreset.rb_offset = rb_offset; // additional parameter other than coreset
//
// //mac->type0_pdcch_dci_config.type0_pdcch_coreset.duration = num_symbols;
// mac->type0_pdcch_dci_config.coreset.cce_reg_mapping_type = CCE_REG_MAPPING_TYPE_INTERLEAVED;
// mac->type0_pdcch_dci_config.coreset.cce_reg_interleaved_reg_bundle_size = 6; // L 38.211 7.3.2.2
// mac->type0_pdcch_dci_config.coreset.cce_reg_interleaved_interleaver_size = 2; // R 38.211 7.3.2.2
// mac->type0_pdcch_dci_config.coreset.cce_reg_interleaved_shift_index = cell_id;
// mac->type0_pdcch_dci_config.coreset.precoder_granularity = PRECODER_GRANULARITY_SAME_AS_REG_BUNDLE;
// mac->type0_pdcch_dci_config.coreset.pdcch_dmrs_scrambling_id = cell_id;
// type0-pdcch search space
float big_o = 0.0f;
float big_m = 0.0f;
......
......@@ -1351,6 +1351,32 @@ static void configure_common_BWP_ul(NR_UE_MAC_INST_t *mac, int bwp_id, NR_BWP_Up
}
}
void nr_rrc_mac_config_req_reset(module_id_t module_id)
{
NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
reset_mac_inst(mac);
}
void nr_rrc_mac_config_req_release(module_id_t module_id)
{
NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
reset_ra(&mac->ra);
release_mac_configuration(mac);
mac->first_sync_frame = -1;
mac->get_sib1 = false;
mac->phy_config_request_sent = false;
mac->state = UE_NOT_SYNC;
// Sending to PHY a request to resync
// with no target cell ID
mac->synch_request.Mod_id = module_id;
mac->synch_request.CC_id = 0;
mac->synch_request.synch_req.target_Nid_cell = -1;
mac->if_module->synch_request(&mac->synch_request);
}
void nr_rrc_mac_config_req_sib1(module_id_t module_id,
int cc_idP,
NR_SI_SchedulingInfo_t *si_SchedulingInfo,
......
......@@ -472,13 +472,6 @@ typedef struct {
bool phy_config_request_sent;
frame_type_t frame_type;
/// Type0-PDCCH seach space
fapi_nr_dl_config_dci_dl_pdu_rel15_t type0_pdcch_dci_config;
uint32_t type0_pdcch_ss_mux_pattern;
int type0_pdcch_ss_sfn_c;
uint32_t type0_pdcch_ss_n_c;
uint32_t type0_pdcch_consecutive_slots;
/* PDUs */
/// Outgoing CCCH pdu for PHY
CCCH_PDU CCCH_pdu;
......
......@@ -136,6 +136,8 @@ void nr_ue_mac_default_configs(NR_UE_MAC_INST_t *mac);
void nr_ue_decode_mib(module_id_t module_id, int cc_id);
void release_common_ss_cset(NR_BWP_PDCCH_t *pdcch);
/**\brief decode SIB1 and other SIs pdus in NR_UE, from if_module dl_ind
\param module_id module id
\param cc_id component carrier id
......@@ -168,6 +170,9 @@ void nr_rrc_mac_config_req_sib1(module_id_t module_id,
NR_SI_SchedulingInfo_t *si_SchedulingInfo,
NR_ServingCellConfigCommonSIB_t *scc);
void nr_rrc_mac_config_req_reset(module_id_t module_id);
void nr_rrc_mac_config_req_release(module_id_t module_id);
/**\brief initialization NR UE MAC instance(s), total number of MAC instance based on NB_NR_UE_MAC_INST*/
NR_UE_MAC_INST_t * nr_l2_init_ue();
......@@ -176,6 +181,8 @@ NR_UE_MAC_INST_t * nr_l2_init_ue();
NR_UE_MAC_INST_t *get_mac_inst(module_id_t module_id);
void reset_mac_inst(NR_UE_MAC_INST_t *nr_mac);
void reset_ra(RA_config_t *ra);
void release_mac_configuration(NR_UE_MAC_INST_t *mac);
/**\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.
......
......@@ -60,27 +60,72 @@ void send_msg3_rrc_request(module_id_t mod_id, int rnti)
nr_mac_rrc_msg3_ind(mod_id, rnti);
}
NR_UE_MAC_INST_t * nr_l2_init_ue()
void nr_ue_init_mac(module_id_t module_idP)
{
LOG_I(NR_MAC, "MAIN: init UE MAC functions \n");
//init mac here
nr_ue_mac_inst = (NR_UE_MAC_INST_t *)calloc(NB_NR_UE_MAC_INST, sizeof(NR_UE_MAC_INST_t));
LOG_I(NR_MAC, "[UE%d] Applying default macMainConfig\n", module_idP);
NR_UE_MAC_INST_t *mac = get_mac_inst(module_idP);
nr_ue_mac_default_configs(mac);
mac->first_sync_frame = -1;
mac->get_sib1 = false;
mac->get_otherSI = false;
mac->phy_config_request_sent = false;
memset(&mac->phy_config, 0, sizeof(mac->phy_config));
mac->state = UE_NOT_SYNC;
mac->si_window_start = -1;
mac->servCellIndex = 0;
}
for (int j = 0; j < NB_NR_UE_MAC_INST; j++)
nr_ue_init_mac(j);
void nr_ue_mac_default_configs(NR_UE_MAC_INST_t *mac)
{
// default values as defined in 38.331 sec 9.2.2
mac->scheduling_info.retxBSR_Timer = NR_BSR_Config__retxBSR_Timer_sf10240;
mac->scheduling_info.periodicBSR_Timer = NR_BSR_Config__periodicBSR_Timer_infinity;
mac->scheduling_info.SR_COUNTER = 0;
mac->scheduling_info.SR_pending = 0;
mac->scheduling_info.sr_ProhibitTimer = 0;
mac->scheduling_info.sr_ProhibitTimer_Running = 0;
mac->scheduling_info.sr_id = -1; // invalid init value
// set init value 0xFFFF, make sure periodic timer and retx time counters are NOT active, after bsr transmission set the value
// configured by the NW.
mac->scheduling_info.periodicBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING;
mac->scheduling_info.retxBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING;
mac->BSR_reporting_active = BSR_TRIGGER_NONE;
for (int i = 0; i < NR_MAX_NUM_LCID; i++) {
LOG_D(NR_MAC, "Applying default logical channel config for LCGID %d\n", i);
mac->scheduling_info.lc_sched_info[i].Bj = -1;
mac->scheduling_info.lc_sched_info[i].bucket_size = -1;
mac->scheduling_info.lc_sched_info[i].LCGID = 0; // defaults to 0 irrespective of SRB or DRB
mac->scheduling_info.lc_sched_info[i].LCID_status = LCID_EMPTY;
mac->scheduling_info.lc_sched_info[i].LCID_buffer_remain = 0;
for (int k = 0; k < NR_MAX_HARQ_PROCESSES; k++)
mac->UL_ndi[k] = -1; // initialize to invalid value
}
memset(&mac->ssb_measurements, 0, sizeof(mac->ssb_measurements));
memset(&mac->ul_time_alignment, 0, sizeof(mac->ul_time_alignment));
}
if (get_softmodem_params()->sa)
ue_init_config_request(nr_ue_mac_inst, get_softmodem_params()->numerology);
NR_UE_MAC_INST_t *nr_l2_init_ue()
{
//init mac here
nr_ue_mac_inst = (NR_UE_MAC_INST_t *)calloc(NB_NR_UE_MAC_INST, sizeof(NR_UE_MAC_INST_t));
int rc = rlc_module_init(0);
AssertFatal(rc == 0, "%s: Could not initialize RLC layer\n", __FUNCTION__);
for (int j = 0; j < NB_NR_UE_MAC_INST; j++)
nr_ue_init_mac(j);
return (nr_ue_mac_inst);
if (get_softmodem_params()->sa)
ue_init_config_request(nr_ue_mac_inst, get_softmodem_params()->numerology);
int rc = rlc_module_init(0);
AssertFatal(rc == 0, "%s: Could not initialize RLC layer\n", __FUNCTION__);
return (nr_ue_mac_inst);
}
NR_UE_MAC_INST_t *get_mac_inst(module_id_t module_id)
{
return &nr_ue_mac_inst[(int)module_id];
NR_UE_MAC_INST_t *get_mac_inst(module_id_t module_id) {
return &nr_ue_mac_inst[(int)module_id];
}
void reset_mac_inst(NR_UE_MAC_INST_t *nr_mac)
......@@ -133,3 +178,28 @@ void reset_mac_inst(NR_UE_MAC_INST_t *nr_mac)
// reset BFI_COUNTER
// TODO beam failure procedure not implemented
}
void release_mac_configuration(NR_UE_MAC_INST_t *mac)
{
if(mac->mib)
ASN_STRUCT_FREE(asn_DEF_NR_MIB, mac->mib);
for (int i = 0; i < 5; i++) {
NR_BWP_PDCCH_t *pdcch = &mac->config_BWP_PDCCH[5];
release_common_ss_cset(pdcch);
for (int j = 0; j < pdcch->list_Coreset.count; j++)
asn_sequence_del(&pdcch->list_Coreset, j, 1);
for (int j = 0; j < pdcch->list_SS.count; j++)
asn_sequence_del(&pdcch->list_SS, j, 1);
}
memset(&mac->ssb_measurements, 0, sizeof(mac->ssb_measurements));
memset(&mac->csirs_measurements, 0, sizeof(mac->csirs_measurements));
memset(&mac->ul_time_alignment, 0, sizeof(mac->ul_time_alignment));
}
void reset_ra(RA_config_t *ra)
{
if(ra->rach_ConfigDedicated)
ASN_STRUCT_FREE(asn_DEF_NR_RACH_ConfigDedicated, ra->rach_ConfigDedicated);
memset(ra, 0, sizeof(RA_config_t));
}
......@@ -158,53 +158,6 @@ static uint8_t nr_extract_dci_info(NR_UE_MAC_INST_t *mac,
dci_pdu_rel15_t *dci_pdu_rel15,
int slot);
void nr_ue_init_mac(module_id_t module_idP)
{
LOG_I(NR_MAC, "[UE%d] Applying default macMainConfig\n", module_idP);
NR_UE_MAC_INST_t *mac = get_mac_inst(module_idP);
nr_ue_mac_default_configs(mac);
mac->first_sync_frame = -1;
mac->get_sib1 = false;
mac->get_otherSI = false;
mac->phy_config_request_sent = false;
memset(&mac->phy_config, 0, sizeof(mac->phy_config));
mac->state = UE_NOT_SYNC;
mac->si_window_start = -1;
mac->servCellIndex = 0;
}
void nr_ue_mac_default_configs(NR_UE_MAC_INST_t *mac)
{
// default values as defined in 38.331 sec 9.2.2
mac->scheduling_info.retxBSR_Timer = NR_BSR_Config__retxBSR_Timer_sf10240;
mac->scheduling_info.periodicBSR_Timer = NR_BSR_Config__periodicBSR_Timer_infinity;
mac->scheduling_info.SR_COUNTER = 0;
mac->scheduling_info.SR_pending = 0;
mac->scheduling_info.sr_ProhibitTimer = 0;
mac->scheduling_info.sr_ProhibitTimer_Running = 0;
mac->scheduling_info.sr_id = -1; // invalid init value
// set init value 0xFFFF, make sure periodic timer and retx time counters are NOT active, after bsr transmission set the value
// configured by the NW.
mac->scheduling_info.periodicBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING;
mac->scheduling_info.retxBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING;
mac->BSR_reporting_active = BSR_TRIGGER_NONE;
for (int i = 0; i < NR_MAX_NUM_LCID; i++) {
LOG_D(NR_MAC, "Applying default logical channel config for LCGID %d\n", i);
mac->scheduling_info.lc_sched_info[i].Bj = -1;
mac->scheduling_info.lc_sched_info[i].bucket_size = -1;
mac->scheduling_info.lc_sched_info[i].LCGID = 0; // defaults to 0 irrespective of SRB or DRB
mac->scheduling_info.lc_sched_info[i].LCID_status = LCID_EMPTY;
mac->scheduling_info.lc_sched_info[i].LCID_buffer_remain = 0;
for (int k = 0; k < NR_MAX_HARQ_PROCESSES; k++)
mac->UL_ndi[k] = -1; // initialize to invalid value
}
memset(&mac->ssb_measurements, 0, sizeof(mac->ssb_measurements));
memset(&mac->ul_time_alignment, 0, sizeof(mac->ul_time_alignment));
}
int get_rnti_type(NR_UE_MAC_INST_t *mac, uint16_t rnti)
{
......
......@@ -958,13 +958,11 @@ bool pdcp_remove_UE(const protocol_ctxt_t *const ctxt_pP)
abort();
}
bool nr_pdcp_remove_UE(ue_id_t ue_id)
void nr_pdcp_remove_UE(ue_id_t ue_id)
{
nr_pdcp_manager_lock(nr_pdcp_ue_manager);
nr_pdcp_manager_remove_ue(nr_pdcp_ue_manager, ue_id);
nr_pdcp_manager_unlock(nr_pdcp_ue_manager);
return 1;
}
/* hack: dummy function needed due to LTE dependencies */
......
......@@ -63,7 +63,7 @@ void add_drb(int is_gnb,
void nr_DRB_preconfiguration(ue_id_t crntiMaybeUEid);
bool nr_pdcp_remove_UE(ue_id_t ue_id);
void nr_pdcp_remove_UE(ue_id_t ue_id);
void nr_pdcp_reestablishment(ue_id_t ue_id, int rb_id, bool srb_flag);
void nr_pdcp_suspend_srb(ue_id_t ue_id, int srb_id);
......
......@@ -707,7 +707,6 @@ static int8_t nr_rrc_ue_decode_NR_BCCH_DL_SCH_Message(instance_t instance,
nr_rrc_configure_default_SI(SI_info, sib1);
// configure timers and constant
nr_rrc_set_sib1_timers_and_constants(&rrc->timers_and_constants, sib1);
// take ServingCellConfigCommon and configure L1/L2
nr_rrc_mac_config_req_sib1(instance, 0, sib1->si_SchedulingInfo, sib1->servingCellConfigCommon);
break;
case NR_BCCH_DL_SCH_MessageType__c1_PR_systemInformation:
......@@ -1847,6 +1846,163 @@ static void process_lte_nsa_msg(NR_UE_RRC_INST_t *rrc, nsa_msg_t *msg, int msg_l
}
}
void nr_rrc_going_to_IDLE(instance_t instance,
NR_RRCRelease_t *RRCRelease)
{
NR_UE_RRC_INST_t *rrc = &NR_UE_rrc_inst[instance];
NR_UE_Timers_Constants_t *tac = &rrc->timers_and_constants;
// reset MAC
nr_rrc_mac_config_req_reset(instance);
// if going to RRC_IDLE was triggered by reception
// of the RRCRelease message including a waitTime
NR_RejectWaitTime_t *waitTime = NULL;
if (RRCRelease) {
struct NR_RRCRelease_IEs *rrcReleaseIEs = RRCRelease->criticalExtensions.choice.rrcRelease;
if(rrcReleaseIEs) {
waitTime = rrcReleaseIEs->nonCriticalExtension ?
rrcReleaseIEs->nonCriticalExtension->waitTime : NULL;
if (waitTime) {
if (tac->T302_active)
tac->T302_cnt = 0; // stop 302
// start timer T302 with the value set to the waitTime
tac->T302_active = true;
tac->T302_k = *waitTime * 1000; // waitTime is in seconds
// inform upper layers that access barring is applicable
// for all access categories except categories '0' and '2'.
// TODO no idea what that means
LOG_E(NR_RRC,"Go to IDLE. Handling RRCRelease message including a waitTime not implemented\n");
}
}
}
if (!waitTime) {
if (tac->T302_active) {
tac->T302_cnt = 0;
tac->T302_active = false;
// TODO barring alleviation as in 5.3.14.4
// not implemented
LOG_E(NR_RRC,"Go to IDLE. Barring alleviation not implemented\n");
}
}
if (tac->T390_active) {
tac->T390_cnt = 0;
tac->T390_active = false;
// TODO barring alleviation as in 5.3.14.4
// not implemented
LOG_E(NR_RRC,"Go to IDLE. Barring alleviation not implemented\n");
}
if (!RRCRelease && rrc->nrRrcState == RRC_STATE_INACTIVE_NR) {
// TODO discard the cell reselection priority information provided by the cellReselectionPriorities
// cell reselection priorities not implemented yet
if (tac->T320_active) {
tac->T320_cnt = 0;
tac->T320_active = false;
}
}
// Stop all the timers except T302, T320 and T325
tac->T300_active = false;
tac->T300_cnt = 0;
tac->T301_active = false;
tac->T301_cnt = 0;
tac->T304_active = false;
tac->T304_cnt = 0;
tac->T310_active = false;
tac->T310_cnt = 0;
tac->T311_active = false;
tac->T311_cnt = 0;
tac->T319_active = false;
tac->T319_cnt = 0;
// discard the UE Inactive AS context
// TODO there is no inactive AS context
// release the suspendConfig
// TODO suspendConfig not handled yet
// discard the keys (only kgnb is stored)
memset(rrc->kgnb, 0, sizeof(rrc->kgnb));
// TODO release all radio resources, including release of the RLC entity,
// the MAC configuration and the associated PDCP entity
// and SDAP for all established RBs
nr_pdcp_remove_UE(rrc->rnti);
nr_rlc_remove_ue(rrc->rnti);
if(rrc->meas_config) {
ASN_STRUCT_FREE(asn_DEF_NR_MeasConfig, rrc->meas_config);
rrc->meas_config = NULL;
}
for (int i = 0; i < NB_CNX_UE; i++) {
rrcPerNB_t *nb = &rrc->perNB[i];
NR_UE_RRC_SI_INFO *SI_info = &nb->SInfo;
if(SI_info->sib1) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB1, SI_info->sib1);
SI_info->sib1 = NULL;
}
if(SI_info->sib2) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB2, SI_info->sib2);
SI_info->sib2 = NULL;
}
if(SI_info->sib3) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB3, SI_info->sib3);
SI_info->sib3 = NULL;
}
if(SI_info->sib4) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB4, SI_info->sib4);
SI_info->sib4 = NULL;
}
if(SI_info->sib5) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB5, SI_info->sib5);
SI_info->sib5 = NULL;
}
if(SI_info->sib6) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB6, SI_info->sib6);
SI_info->sib6 = NULL;
}
if(SI_info->sib7) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB7, SI_info->sib7);
SI_info->sib7 = NULL;
}
if(SI_info->sib8) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB8, SI_info->sib8);
SI_info->sib8 = NULL;
}
if(SI_info->sib9) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB9, SI_info->sib9);
SI_info->sib9 = NULL;
}
if(SI_info->sib10) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB10_r16, SI_info->sib10);
SI_info->sib10 = NULL;
}
if(SI_info->sib11) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB11_r16, SI_info->sib11);
SI_info->sib11 = NULL;
}
if(SI_info->sib12) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB12_r16, SI_info->sib12);
SI_info->sib12 = NULL;
}
if(SI_info->sib13) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB13_r16, SI_info->sib13);
SI_info->sib13 = NULL;
}
if(SI_info->sib14) {
ASN_STRUCT_FREE(asn_DEF_NR_SIB14_r16, SI_info->sib14);
SI_info->sib14 = NULL;
}
}
nr_rrc_mac_config_req_release(instance);
// TODO indicate the release of the RRC connection to upper layers
// together with the release cause
// enter RRC_IDLE
rrc->nrRrcState = RRC_STATE_IDLE_NR;
rrc->rnti = 0;
}
void nr_ue_rrc_timer_trigger(int instance, int frame, int gnb_id)
{
MessageDef *message_p;
......
......@@ -148,17 +148,25 @@ typedef struct NR_UE_Timers_Constants_s {
// timers status
bool T300_active;
bool T301_active;
bool T302_active;
bool T304_active;
bool T310_active;
bool T311_active;
bool T319_active;
bool T320_active;
bool T325_active;
bool T390_active;
// timers
uint32_t T300_cnt;
uint32_t T301_cnt;
uint32_t T302_cnt;
uint32_t T304_cnt;
uint32_t T310_cnt;
uint32_t T311_cnt;
uint32_t T319_cnt;
uint32_t T320_cnt;
uint32_t T325_cnt;
uint32_t T390_cnt;
// counters
uint32_t N310_cnt;
uint32_t N311_cnt;
......@@ -167,10 +175,14 @@ typedef struct NR_UE_Timers_Constants_s {
uint32_t N311_k;
uint32_t T300_k;
uint32_t T301_k;
uint32_t T302_k;
uint32_t T304_k;
uint32_t T310_k;
uint32_t T311_k;
uint32_t T319_k;
uint32_t T320_k;
uint32_t T325_k;
uint32_t T390_k;
} NR_UE_Timers_Constants_t;
typedef enum {
......@@ -210,7 +222,7 @@ typedef struct NR_UE_RRC_INST_s {
NR_BWP_Id_t dl_bwp_id;
NR_BWP_Id_t ul_bwp_id;
/* KeNB as computed from parameters within USIM card */
/* KgNB as computed from parameters within USIM card */
uint8_t kgnb[32];
/* Used integrity/ciphering algorithms */
//RRC_LIST_TYPE(NR_SecurityAlgorithmConfig_t, NR_SecurityAlgorithmConfig) SecurityAlgorithmConfig_list;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment