Commit eecd5935 authored by Melissa Elkadi's avatar Melissa Elkadi

Not working pRACH but starting it

parent f3c2a2a6
......@@ -97,6 +97,8 @@ typedef enum {
si = 2
} sync_mode_t;
static void *NRUE_phy_stub_standalone_pnf_task(void *arg);
void init_nr_ue_vars(PHY_VARS_NR_UE *ue,
uint8_t UE_id,
uint8_t abstraction_flag)
......@@ -136,12 +138,15 @@ void init_nrUE_standalone_thread(int ue_idx)
LOG_E(NR_MAC, "pthread_create failed for calling nrue_standalone_pnf_task");
}
pthread_setname_np(thread, "oai:nrue-stand");
pthread_t phy_thread;
if (pthread_create(&phy_thread, NULL, NRUE_phy_stub_standalone_pnf_task, NULL) != 0) {
LOG_E(NR_MAC, "pthread_create failed for calling NRUE_phy_stub_standalone_pnf_task");
}
pthread_setname_np(phy_thread, "oai:nrue-stand-phy");
}
#if 0
static void *NRUE_phy_stub_standalone_pnf_task(void *arg)
{
int current_sfn_slot;
sem_t sfn_slot_semaphore;
int last_sfn_slot = -1;
while (!oai_exit)
......@@ -156,57 +161,41 @@ static void *NRUE_phy_stub_standalone_pnf_task(void *arg)
if (sfn_slot == last_sfn_slot)
{
LOG_W(NR_MAC, "repeated sfn_sf = %d.%d\n",
sfn_slot >> 4, sfn_slot & 15);
sfn_slot >> 6, sfn_slot & 0x3F);
continue;
}
last_sfn_slot = sfn_slot;
struct rx_tx_thread_data *rtd = arg;
if (rtd == NULL) {
LOG_E(MAC, "[SCHED][UE] rx_tx_thread_data *rtd: NULL pointer\n");
exit_fun("nothing to add");
frame_t frame_tx = NFAPI_SFNSLOT2SFN(sfn_slot);
int nr_slot_tx = NFAPI_SFNSLOT2SLOT(sfn_slot);
NR_PRACH_RESOURCES_t *prach_resources = NULL;
fapi_nr_ul_config_prach_pdu *prach_pdu = NULL;
module_id_t mod_id = 0;
int CC_id = 0;
uint8_t gNB_id = 0;
LOG_I(NR_PHY, "Melissa In %s:[%d.%d] getting PRACH resources\n", __FUNCTION__, frame_tx, nr_slot_tx);
uint8_t nr_prach = nr_ue_get_rach(prach_resources, prach_pdu, mod_id, CC_id, frame_tx, gNB_id, nr_slot_tx);
LOG_I(NR_PHY, "In %s: [UE %d] This is nr_prach: %d\n", __FUNCTION__, mod_id, nr_prach);
if (nr_prach == 1)
{
LOG_I(NR_PHY, "Melissa! Calling nr_Msg1_transmitted!!!\n");
nr_Msg1_transmitted(mod_id, CC_id, frame_tx, gNB_id);
}
UE_nr_rxtx_proc_t *proc = rtd->proc;
PHY_VARS_NR_UE *UE = NULL;
proc = &PHY_vars_UE_g[0][0]->proc;
int frame_tx = proc->frame_tx;
int nr_slot_tx = proc->nr_slot_tx;
uint8_t mod_id = UE->Mod_id;
NR_PRACH_RESOURCES_t *prach_resources = UE->prach_resources[0];
AssertFatal(prach_resources != NULL, "UE->prach_resources[%u] == NULL\n", 0);
uint8_t nr_prach = 0;
if (UE->mac_enabled == 0)
else if (nr_prach == 2)
{
prach_resources->ra_TDD_map_index = 0;
prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER = 10;
prach_resources->ra_RNTI = 0x1234;
nr_prach = 1;
prach_resources->init_msg1 = 1;
LOG_I(NR_PHY, "In %s: [UE %d] RA completed, setting UE mode to PUSCH\n", __FUNCTION__, mod_id);
//UE->UE_mode[0] = PUSCH;
}
else
else if(nr_prach == 3)
{
LOG_D(PHY, "In %s:[%d.%d] getting PRACH resources\n", __FUNCTION__, frame_tx, nr_slot_tx);
nr_prach = nr_ue_get_rach(prach_resources, &UE->prach_vars[0]->prach_pdu, mod_id, UE->CC_id, frame_tx, 0, nr_slot_tx);
if (nr_prach == 1)
{
nr_Msg1_transmitted(mod_id, UE->CC_id, frame_tx, 0); //Once rach is = 1, then call this
}
else if (nr_prach == 2)
{
LOG_D(PHY, "In %s: [UE %d] RA completed, setting UE mode to PUSCH\n", __FUNCTION__, mod_id);
UE->UE_mode[0] = PUSCH;
}
else if(nr_prach == 3)
{
LOG_D(PHY, "In %s: [UE %d] RA failed, setting UE mode to PRACH\n", __FUNCTION__, mod_id);
UE->UE_mode[0] = PRACH;
}
LOG_I(NR_PHY, "In %s: [UE %d] RA failed, setting UE mode to PRACH\n", __FUNCTION__, mod_id);
//UE->UE_mode[0] = PRACH;
}
}
}
#endif
/*!
* It performs band scanning and synchonization.
......
......@@ -500,11 +500,31 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
int nr_slot_tx){
NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
NR_CellGroupConfig_t *secondaryCellGroup = calloc(1, sizeof(*secondaryCellGroup));
//NR_ServingCellConfigCommon_t *scc = calloc(1, sizeof(*scc));
prepare_scc(mac->scc);
uint64_t ssb_bitmap;
fill_scc(mac->scc, &ssb_bitmap, 106, 106, 1, 1);
fix_scc(mac->scc, ssb_bitmap);
fill_default_secondaryCellGroup(mac->scc, secondaryCellGroup, 0, 1, 1, 0);
if (mac == NULL){
LOG_I(MAC, "Melissa mac is null\n");
}
if (&mac->ra == NULL){
LOG_I(MAC, "Melissa mac->ra is null\n");
}
if (mac->scc == NULL){
LOG_I(MAC, "Melissa scc is null\n");
return 0;
}
LOG_I(MAC, "Melissa got here %s: %d\n", __FUNCTION__, __LINE__);
RA_config_t *ra = &mac->ra;
uint8_t mac_sdus[MAX_NR_ULSCH_PAYLOAD_BYTES];
uint8_t lcid = UL_SCH_LCID_CCCH_MSG3, *payload;
uint16_t size_sdu = 0;
unsigned short post_padding;
NR_ServingCellConfigCommon_t *scc = mac->scc;
AssertFatal(scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup != NULL, "In %s: FATAL! nr_rach_ConfigCommon is NULL...\n", __FUNCTION__);
NR_RACH_ConfigCommon_t *setup = scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup;
......@@ -514,8 +534,13 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
uint8_t sdu_lcids[NB_RB_MAX] = {0};
uint16_t sdu_lengths[NB_RB_MAX] = {0};
int TBS_bytes = 848, header_length_total=0, num_sdus, offset, mac_ce_len;
int mac_ce_len = 0;
unsigned short post_padding = 1;
int header_length_total = 0;
uint16_t size_sdu = 0;
int TBS_bytes = 848;
uint8_t mac_sdus[MAX_NR_ULSCH_PAYLOAD_BYTES];
// Delay init RA procedure to allow the convergence of the IIR filter on PRACH noise measurements at gNB side
if (!prach_resources->init_msg1) {
if (((MAX_FRAME_NUMBER + frame - prach_resources->sync_frame) % MAX_FRAME_NUMBER) > 150){
......@@ -530,45 +555,25 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
if (ra->RA_active == 0) {
/* RA not active - checking if RRC is ready to initiate the RA procedure */
LOG_D(MAC, "RA not active. Checking for data to transmit from upper layers...\n");
payload = (uint8_t*) &mac->CCCH_pdu.payload;
mac_ce_len = 0;
num_sdus = 1;
post_padding = 1;
if (0){
// initialisation by RRC
// CCCH PDU
// size_sdu = (uint16_t) mac_rrc_data_req_ue(mod_id,
// CC_id,
// frame,
// CCCH,
// 1,
// mac_sdus,
// gNB_id,
// 0);
LOG_D(MAC,"[UE %d] Frame %d: Requested RRCConnectionRequest, got %d bytes\n", mod_id, frame, size_sdu);
} else {
// fill ulsch_buffer with random data
for (int i = 0; i < TBS_bytes; i++){
mac_sdus[i] = (unsigned char) (lrand48()&0xff);
}
//Sending SDUs with size 1
//Initialize elements of sdu_lcids and sdu_lengths
sdu_lcids[0] = lcid;
sdu_lengths[0] = TBS_bytes - 3 - post_padding - mac_ce_len;
header_length_total += 2 + (sdu_lengths[0] >= 128);
size_sdu += sdu_lengths[0];
LOG_I(MAC, "RA not active. Checking for data to transmit from upper layers...\n");
for (int i = 0; i < TBS_bytes; i++){
mac_sdus[i] = (unsigned char) (lrand48()&0xff);
}
sdu_lcids[0] = UL_SCH_LCID_CCCH_MSG3;
sdu_lengths[0] = TBS_bytes - 3 - post_padding - mac_ce_len;
header_length_total += 2 + (sdu_lengths[0] >= 128);
size_sdu += sdu_lengths[0];
if (size_sdu > 0) {
LOG_D(MAC, "[UE %d][%d.%d]: starting initialisation Random Access Procedure...\n", mod_id, frame, nr_slot_tx);
LOG_I(MAC, "[UE %d][%d.%d]: starting initialisation Random Access Procedure...\n", mod_id, frame, nr_slot_tx);
ra->Msg3_size = size_sdu + sizeof(NR_MAC_SUBHEADER_SHORT) + sizeof(NR_MAC_SUBHEADER_SHORT);
init_RA(mod_id, prach_resources, setup, rach_ConfigGeneric, rach_ConfigDedicated);
uint8_t *payload = (uint8_t*) &mac->CCCH_pdu.payload;
prach_resources->Msg3 = payload;
nr_get_RA_window(mac);
......@@ -576,9 +581,9 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
if (ra->generate_nr_prach == 1)
nr_get_prach_resources(mod_id, CC_id, gNB_id, prach_resources, prach_pdu, rach_ConfigDedicated);
offset = nr_generate_ulsch_pdu((uint8_t *) mac_sdus, // sdus buffer
int offset = nr_generate_ulsch_pdu((uint8_t *) mac_sdus, // sdus buffer
(uint8_t *) payload, // UL MAC pdu pointer
num_sdus, // num sdus
1, // num sdus
sdu_lengths, // sdu length
sdu_lcids, // sdu lcid
0, // power headroom
......@@ -594,10 +599,10 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
for (int j = 0; j < (TBS_bytes - offset); j++)
payload[offset + j] = 0; // mac_pdu[offset + j] = 0;
}
}
}
} else if (ra->RA_window_cnt != -1) { // RACH is active
LOG_D(MAC, "In %s [%d.%d] RA is active: RA window count %d, RA backoff count %d\n", __FUNCTION__, frame, nr_slot_tx, ra->RA_window_cnt, ra->RA_backoff_cnt);
LOG_I(MAC, "In %s [%d.%d] RA is active: RA window count %d, RA backoff count %d\n", __FUNCTION__, frame, nr_slot_tx, ra->RA_window_cnt, ra->RA_backoff_cnt);
if (ra->RA_BI_found){
prach_resources->RA_PREAMBLE_BACKOFF = prach_resources->RA_SCALING_FACTOR_BI * ra->RA_backoff_indicator;
......@@ -618,7 +623,7 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
} else if (ra->RA_window_cnt > 0) {
LOG_D(MAC, "[UE %d][%d.%d]: RAR not received yet (RA window count %d) \n", mod_id, frame, nr_slot_tx, ra->RA_window_cnt);
LOG_I(MAC, "[UE %d][%d.%d]: RAR not received yet (RA window count %d) \n", mod_id, frame, nr_slot_tx, ra->RA_window_cnt);
// Fill in preamble and PRACH resources
ra->RA_window_cnt--;
......@@ -626,14 +631,13 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
} else if (ra->RA_backoff_cnt > 0) {
LOG_D(MAC, "[UE %d][%d.%d]: RAR not received yet (RA backoff count %d) \n", mod_id, frame, nr_slot_tx, ra->RA_backoff_cnt);
LOG_I(MAC, "[UE %d][%d.%d]: RAR not received yet (RA backoff count %d) \n", mod_id, frame, nr_slot_tx, ra->RA_backoff_cnt);
ra->RA_backoff_cnt--;
if ((ra->RA_backoff_cnt > 0 && ra->generate_nr_prach == 1) || ra->RA_backoff_cnt == 0){
nr_get_prach_resources(mod_id, CC_id, gNB_id, prach_resources, prach_pdu, rach_ConfigDedicated);
}
}
}
}
......@@ -643,7 +647,6 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
}
return ra->generate_nr_prach;
}
void nr_get_RA_window(NR_UE_MAC_INST_t *mac){
......
......@@ -44,8 +44,6 @@
#define MAX_IF_MODULES 100
const char *dl_indication_type[] = {"MIB", "SIB", "DLSCH", "DCI", "RAR"};
int current_sfn_slot;
sem_t sfn_slot_semaphore;
queue_t dl_itti_config_req_tx_data_req_queue;
queue_t ul_dci_config_req_queue;
......@@ -202,7 +200,7 @@ void *nrue_standalone_pnf_task(void *context)
}
int sfn = NFAPI_SFNSLOT2SFN(sfn_slot);
int slot = NFAPI_SFNSLOT2SLOT(sfn_slot);
LOG_D(NR_PHY, "Received from proxy sfn %d slot %d\n", sfn, slot);
LOG_I(NR_PHY, "Received from proxy sfn %d slot %d\n", sfn, slot);
}
else
{
......
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