Commit 57f0cb13 authored by Robert Schmidt's avatar Robert Schmidt

Merge remote-tracking branch 'origin/fix-cellconfig-segv' into integration_2023_w43

parents a828da1b 60d867a9
...@@ -552,8 +552,6 @@ void itti_set_task_real_time(task_id_t task_id); ...@@ -552,8 +552,6 @@ void itti_set_task_real_time(task_id_t task_id);
void itti_send_terminate_message(task_id_t task_id); void itti_send_terminate_message(task_id_t task_id);
void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize_t size); void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize_t size);
void *calloc_or_fail(size_t size);
void *malloc_or_fail(size_t size);
int memory_read(const char *datafile, void *data, size_t size); int memory_read(const char *datafile, void *data, size_t size);
int itti_free(task_id_t task_id, void *ptr); int itti_free(task_id_t task_id, void *ptr);
......
...@@ -56,23 +56,24 @@ static inline void *malloc16_clear( size_t size ) { ...@@ -56,23 +56,24 @@ static inline void *malloc16_clear( size_t size ) {
return ptr; return ptr;
} }
static inline void *calloc_or_fail(size_t nmemb, size_t size)
static inline void *calloc_or_fail(size_t size) { {
void *ptr = calloc(1, size); void *ptr = calloc(nmemb, size);
if (ptr == NULL) { if (ptr == NULL) {
fprintf(stderr, "[UE] Failed to calloc %zu bytes", size); fprintf(stderr, "Failed to calloc() %zu elements of %zu bytes: out of memory", nmemb, size);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
return ptr; return ptr;
} }
static inline void *malloc_or_fail(size_t size) { static inline void *malloc_or_fail(size_t size)
{
void *ptr = malloc(size); void *ptr = malloc(size);
if (ptr == NULL) { if (ptr == NULL) {
fprintf(stderr, "[UE] Failed to malloc %zu bytes", size); fprintf(stderr, "Failed to malloc() %zu bytes: out of memory", size);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
......
...@@ -970,16 +970,40 @@ static NR_ServingCellConfigCommon_t *get_scc_config(int minRXTXTIME) ...@@ -970,16 +970,40 @@ static NR_ServingCellConfigCommon_t *get_scc_config(int minRXTXTIME)
fix_scc(scc, ssb_bitmap); fix_scc(scc, ssb_bitmap);
} }
nr_rrc_config_ul_tda(scc, minRXTXTIME); nr_rrc_config_ul_tda(scc, minRXTXTIME);
// the gNB uses the servingCellConfigCommon everywhere, even when it should use the servingCellConfigCommonSIB.
// previously (before this commit), the following fields were indirectly populated through get_SIB1_NR().
// since this might lead to memory problems (e.g., double frees), it has been moved here.
// note that the "right solution" would be to not populate the servingCellConfigCommon here, and use
// an "abstraction struct" that contains the corresponding values, from which SCC/SIB1/... is generated.
NR_PDCCH_ConfigCommon_t *pcc = scc->downlinkConfigCommon->initialDownlinkBWP->pdcch_ConfigCommon->choice.setup;
AssertFatal(pcc != NULL && pcc->commonSearchSpaceList == NULL, "memory leak\n");
pcc->commonSearchSpaceList = calloc_or_fail(1, sizeof(*pcc->commonSearchSpaceList));
NR_SearchSpace_t *ss1 = rrc_searchspace_config(true, 1, 0);
asn1cSeqAdd(&pcc->commonSearchSpaceList->list, ss1);
NR_SearchSpace_t *ss2 = rrc_searchspace_config(true, 2, 0);
asn1cSeqAdd(&pcc->commonSearchSpaceList->list, ss2);
NR_SearchSpace_t *ss3 = rrc_searchspace_config(true, 3, 0);
asn1cSeqAdd(&pcc->commonSearchSpaceList->list, ss3);
asn1cCallocOne(pcc->searchSpaceSIB1, 0);
asn1cCallocOne(pcc->ra_SearchSpace, 1);
asn1cCallocOne(pcc->pagingSearchSpace, 2);
asn1cCallocOne(pcc->searchSpaceOtherSystemInformation, 3);
return scc; return scc;
} }
static NR_ServingCellConfig_t *get_scd_config(void) static NR_ServingCellConfig_t *get_scd_config(void)
{ {
char aprefix[MAX_OPTNAME_SIZE*2 + 8];
NR_ServingCellConfig_t *scd = calloc(1, sizeof(*scd)); NR_ServingCellConfig_t *scd = calloc(1, sizeof(*scd));
prepare_scd(scd); prepare_scd(scd);
paramdef_t SCDsParams[] = SCDPARAMS_DESC(scd); paramdef_t SCDsParams[] = SCDPARAMS_DESC(scd);
paramlist_def_t SCDsParamList = {GNB_CONFIG_STRING_SERVINGCELLCONFIGDEDICATED, NULL, 0}; paramlist_def_t SCDsParamList = {GNB_CONFIG_STRING_SERVINGCELLCONFIGDEDICATED, NULL, 0};
char aprefix[MAX_OPTNAME_SIZE * 2 + 8];
snprintf(aprefix, sizeof(aprefix), "%s.[%i]", GNB_CONFIG_STRING_GNB_LIST, 0);
config_getlist(&SCDsParamList, NULL, 0, aprefix); config_getlist(&SCDsParamList, NULL, 0, aprefix);
if (SCDsParamList.numelt > 0) { if (SCDsParamList.numelt > 0) {
sprintf(aprefix, "%s.[%i].%s.[%i]", GNB_CONFIG_STRING_GNB_LIST, 0, GNB_CONFIG_STRING_SERVINGCELLCONFIGDEDICATED, 0); sprintf(aprefix, "%s.[%i].%s.[%i]", GNB_CONFIG_STRING_GNB_LIST, 0, GNB_CONFIG_STRING_SERVINGCELLCONFIGDEDICATED, 0);
......
...@@ -586,6 +586,15 @@ bool nr_find_nb_rb(uint16_t Qm, ...@@ -586,6 +586,15 @@ bool nr_find_nb_rb(uint16_t Qm,
return *tbs >= bytes && *nb_rb <= nb_rb_max; return *tbs >= bytes && *nb_rb <= nb_rb_max;
} }
const NR_DMRS_UplinkConfig_t *get_DMRS_UplinkConfig(const NR_PUSCH_Config_t *pusch_Config, const NR_tda_info_t *tda_info)
{
if (pusch_Config == NULL)
return NULL;
return tda_info->mapping_type == typeA ? pusch_Config->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup
: pusch_Config->dmrs_UplinkForPUSCH_MappingTypeB->choice.setup;
}
NR_pusch_dmrs_t get_ul_dmrs_params(const NR_ServingCellConfigCommon_t *scc, NR_pusch_dmrs_t get_ul_dmrs_params(const NR_ServingCellConfigCommon_t *scc,
const NR_UE_UL_BWP_t *ul_bwp, const NR_UE_UL_BWP_t *ul_bwp,
const NR_tda_info_t *tda_info, const NR_tda_info_t *tda_info,
...@@ -623,8 +632,6 @@ NR_pusch_dmrs_t get_ul_dmrs_params(const NR_ServingCellConfigCommon_t *scc, ...@@ -623,8 +632,6 @@ NR_pusch_dmrs_t get_ul_dmrs_params(const NR_ServingCellConfigCommon_t *scc,
num_dmrs_symb += (dmrs.ul_dmrs_symb_pos >> i) & 1; num_dmrs_symb += (dmrs.ul_dmrs_symb_pos >> i) & 1;
dmrs.num_dmrs_symb = num_dmrs_symb; dmrs.num_dmrs_symb = num_dmrs_symb;
dmrs.N_PRB_DMRS = dmrs.num_dmrs_cdm_grps_no_data * (dmrs.dmrs_config_type == 0 ? 6 : 4); dmrs.N_PRB_DMRS = dmrs.num_dmrs_cdm_grps_no_data * (dmrs.dmrs_config_type == 0 ? 6 : 4);
dmrs.NR_DMRS_UplinkConfig = NR_DMRS_UplinkConfig;
return dmrs; return dmrs;
} }
......
...@@ -2234,7 +2234,7 @@ void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot, n ...@@ -2234,7 +2234,7 @@ void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot, n
/* FAPI: DMRS */ /* FAPI: DMRS */
pusch_pdu->ul_dmrs_symb_pos = sched_pusch->dmrs_info.ul_dmrs_symb_pos; pusch_pdu->ul_dmrs_symb_pos = sched_pusch->dmrs_info.ul_dmrs_symb_pos;
pusch_pdu->dmrs_config_type = sched_pusch->dmrs_info.dmrs_config_type; pusch_pdu->dmrs_config_type = sched_pusch->dmrs_info.dmrs_config_type;
const NR_DMRS_UplinkConfig_t *NR_DMRS_UplinkConfig = sched_pusch->dmrs_info.NR_DMRS_UplinkConfig; const NR_DMRS_UplinkConfig_t *NR_DMRS_UplinkConfig = get_DMRS_UplinkConfig(current_BWP->pusch_Config, &sched_pusch->tda_info);
if (pusch_pdu->transform_precoding) { // transform precoding disabled if (pusch_pdu->transform_precoding) { // transform precoding disabled
long *scramblingid=NULL; long *scramblingid=NULL;
if (NR_DMRS_UplinkConfig && pusch_pdu->scid == 0) if (NR_DMRS_UplinkConfig && pusch_pdu->scid == 0)
......
...@@ -269,6 +269,8 @@ long get_K2(NR_PUSCH_TimeDomainResourceAllocationList_t *tdaList, ...@@ -269,6 +269,8 @@ long get_K2(NR_PUSCH_TimeDomainResourceAllocationList_t *tdaList,
int time_domain_assignment, int time_domain_assignment,
int mu); int mu);
const NR_DMRS_UplinkConfig_t *get_DMRS_UplinkConfig(const NR_PUSCH_Config_t *pusch_Config, const NR_tda_info_t *tda_info);
NR_pusch_dmrs_t get_ul_dmrs_params(const NR_ServingCellConfigCommon_t *scc, NR_pusch_dmrs_t get_ul_dmrs_params(const NR_ServingCellConfigCommon_t *scc,
const NR_UE_UL_BWP_t *ul_bwp, const NR_UE_UL_BWP_t *ul_bwp,
const NR_tda_info_t *tda_info, const NR_tda_info_t *tda_info,
......
...@@ -378,7 +378,6 @@ typedef struct NR_pusch_dmrs { ...@@ -378,7 +378,6 @@ typedef struct NR_pusch_dmrs {
uint16_t ul_dmrs_symb_pos; uint16_t ul_dmrs_symb_pos;
uint8_t num_dmrs_cdm_grps_no_data; uint8_t num_dmrs_cdm_grps_no_data;
nfapi_nr_dmrs_type_e dmrs_config_type; nfapi_nr_dmrs_type_e dmrs_config_type;
NR_DMRS_UplinkConfig_t *NR_DMRS_UplinkConfig;
} NR_pusch_dmrs_t; } NR_pusch_dmrs_t;
typedef struct NR_sched_pusch { typedef struct NR_sched_pusch {
......
This diff is collapsed.
...@@ -43,6 +43,7 @@ void nr_rrc_config_dl_tda(struct NR_PDSCH_TimeDomainResourceAllocationList *pdsc ...@@ -43,6 +43,7 @@ void nr_rrc_config_dl_tda(struct NR_PDSCH_TimeDomainResourceAllocationList *pdsc
NR_TDD_UL_DL_ConfigCommon_t *tdd_UL_DL_ConfigurationCommon, NR_TDD_UL_DL_ConfigCommon_t *tdd_UL_DL_ConfigurationCommon,
int curr_bwp); int curr_bwp);
void nr_rrc_config_ul_tda(NR_ServingCellConfigCommon_t *scc, int min_fb_delay); void nr_rrc_config_ul_tda(NR_ServingCellConfigCommon_t *scc, int min_fb_delay);
NR_SearchSpace_t *rrc_searchspace_config(bool is_common, int searchspaceid, int coresetid);
void prepare_sim_uecap(NR_UE_NR_Capability_t *cap, void prepare_sim_uecap(NR_UE_NR_Capability_t *cap,
NR_ServingCellConfigCommon_t *scc, NR_ServingCellConfigCommon_t *scc,
......
...@@ -107,7 +107,7 @@ static IdleMode_callback_t _emm_indication_notify; ...@@ -107,7 +107,7 @@ static IdleMode_callback_t _emm_indication_notify;
***************************************************************************/ ***************************************************************************/
void IdleMode_initialize(nas_user_t *user, IdleMode_callback_t cb) void IdleMode_initialize(nas_user_t *user, IdleMode_callback_t cb)
{ {
emm_plmn_list_t *emm_plmn_list = calloc_or_fail( sizeof(emm_plmn_list_t)); emm_plmn_list_t *emm_plmn_list = calloc_or_fail(1, sizeof(emm_plmn_list_t));
user->emm_plmn_list = emm_plmn_list; user->emm_plmn_list = emm_plmn_list;
/* Initialize the list of available PLMNs */ /* Initialize the list of available PLMNs */
emm_plmn_list->n_plmns = 0; emm_plmn_list->n_plmns = 0;
......
...@@ -135,7 +135,7 @@ void _emm_detach_initialize(emm_detach_data_t *emm_detach) { ...@@ -135,7 +135,7 @@ void _emm_detach_initialize(emm_detach_data_t *emm_detach) {
void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const char *imei) void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const char *imei)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
user->emm_data = calloc_or_fail(sizeof(emm_data_t)); user->emm_data = calloc_or_fail(1, sizeof(emm_data_t));
/* USIM validity indicator */ /* USIM validity indicator */
user->emm_data->usim_is_valid = false; user->emm_data->usim_is_valid = false;
/* The IMEI read from the UE's non-volatile memory */ /* The IMEI read from the UE's non-volatile memory */
...@@ -433,19 +433,19 @@ void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const c ...@@ -433,19 +433,19 @@ void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const c
/* /*
* Initialize EMM timers * Initialize EMM timers
*/ */
user->emm_data->emm_timers = calloc_or_fail(sizeof(emm_timers_t)); user->emm_data->emm_timers = calloc_or_fail(1, sizeof(emm_timers_t));
_emm_timers_initialize(user->emm_data->emm_timers); _emm_timers_initialize(user->emm_data->emm_timers);
/* /*
* Initialize Internal data used for detach procedure * Initialize Internal data used for detach procedure
*/ */
user->emm_data->emm_detach_data = calloc_or_fail(sizeof(emm_detach_data_t)); user->emm_data->emm_detach_data = calloc_or_fail(1, sizeof(emm_detach_data_t));
_emm_detach_initialize(user->emm_data->emm_detach_data); _emm_detach_initialize(user->emm_data->emm_detach_data);
/* /*
* Initialize Internal data used for attach procedure * Initialize Internal data used for attach procedure
*/ */
user->emm_data->emm_attach_data = calloc_or_fail(sizeof(emm_attach_data_t)); user->emm_data->emm_attach_data = calloc_or_fail(1, sizeof(emm_attach_data_t));
_emm_attach_initialize(user->emm_data->emm_attach_data); _emm_attach_initialize(user->emm_data->emm_attach_data);
/* /*
......
...@@ -119,7 +119,7 @@ esm_ebr_data_t *esm_ebr_initialize(void) ...@@ -119,7 +119,7 @@ esm_ebr_data_t *esm_ebr_initialize(void)
LOG_FUNC_IN; LOG_FUNC_IN;
int i; int i;
esm_ebr_data_t *esm_ebr_data = calloc_or_fail(sizeof(esm_ebr_data_t)); esm_ebr_data_t *esm_ebr_data = calloc_or_fail(1, sizeof(esm_ebr_data_t));
esm_ebr_data->index = 0; esm_ebr_data->index = 0;
......
...@@ -79,7 +79,7 @@ void esm_main_initialize(nas_user_t *user, esm_indication_callback_t cb) ...@@ -79,7 +79,7 @@ void esm_main_initialize(nas_user_t *user, esm_indication_callback_t cb)
int i; int i;
esm_data_t *esm_data = calloc_or_fail(sizeof(esm_data_t)); esm_data_t *esm_data = calloc_or_fail(1, sizeof(esm_data_t));
user->esm_data = esm_data; user->esm_data = esm_data;
default_eps_bearer_context_data_t *default_eps_bearer_context = calloc(1, sizeof(default_eps_bearer_context_data_t)); default_eps_bearer_context_data_t *default_eps_bearer_context = calloc(1, sizeof(default_eps_bearer_context_data_t));
......
...@@ -88,7 +88,7 @@ static int _esm_pt_get_available_entry(esm_pt_data_t *esm_pt_data); ...@@ -88,7 +88,7 @@ static int _esm_pt_get_available_entry(esm_pt_data_t *esm_pt_data);
esm_pt_data_t *esm_pt_initialize(void) esm_pt_data_t *esm_pt_initialize(void)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
esm_pt_data_t *esm_pt_data = calloc_or_fail(sizeof(esm_pt_data_t)); esm_pt_data_t *esm_pt_data = calloc_or_fail(1, sizeof(esm_pt_data_t));
int i; int i;
esm_pt_data->index = 0; esm_pt_data->index = 0;
......
...@@ -97,8 +97,8 @@ void nas_proc_initialize(nas_user_t *user, emm_indication_callback_t emm_cb, ...@@ -97,8 +97,8 @@ void nas_proc_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
user->proc.rsrq = NAS_PROC_RSRQ_UNKNOWN; user->proc.rsrq = NAS_PROC_RSRQ_UNKNOWN;
user->proc.rsrp = NAS_PROC_RSRP_UNKNOWN; user->proc.rsrp = NAS_PROC_RSRP_UNKNOWN;
user->authentication_data = calloc_or_fail(sizeof(authentication_data_t)); user->authentication_data = calloc_or_fail(1, sizeof(authentication_data_t));
user->security_data = calloc_or_fail( sizeof(security_data_t)); user->security_data = calloc_or_fail(1, sizeof(security_data_t));
/* Initialize the EMM procedure manager */ /* Initialize the EMM procedure manager */
emm_main_initialize(user, emm_cb, imei); emm_main_initialize(user, emm_cb, imei);
......
...@@ -67,7 +67,7 @@ static bool nas_ue_process_events(nas_user_container_t *users, struct epoll_even ...@@ -67,7 +67,7 @@ static bool nas_ue_process_events(nas_user_container_t *users, struct epoll_even
// Initialize user api id and port number // Initialize user api id and port number
void nas_user_api_id_initialize(nas_user_t *user) { void nas_user_api_id_initialize(nas_user_t *user) {
user_api_id_t *user_api_id = calloc_or_fail(sizeof(user_api_id_t)); user_api_id_t *user_api_id = calloc_or_fail(1, sizeof(user_api_id_t));
user->user_api_id = user_api_id; user->user_api_id = user_api_id;
char *port = make_port_str_from_ueid(NAS_PARSER_DEFAULT_USER_PORT_NUMBER, user->ueid); char *port = make_port_str_from_ueid(NAS_PARSER_DEFAULT_USER_PORT_NUMBER, user->ueid);
if ( port == NULL ) { if ( port == NULL ) {
...@@ -130,9 +130,9 @@ void *nas_ue_task(void *args_p) ...@@ -130,9 +130,9 @@ void *nas_ue_task(void *args_p)
/* Initialize user interface (to exchange AT commands with user process) */ /* Initialize user interface (to exchange AT commands with user process) */
nas_user_api_id_initialize(user); nas_user_api_id_initialize(user);
/* allocate needed structures */ /* allocate needed structures */
user->user_at_commands = calloc_or_fail(sizeof(user_at_commands_t)); user->user_at_commands = calloc_or_fail(1, sizeof(user_at_commands_t));
user->at_response = calloc_or_fail(sizeof(at_response_t)); user->at_response = calloc_or_fail(1, sizeof(at_response_t));
user->lowerlayer_data = calloc_or_fail(sizeof(lowerlayer_data_t)); user->lowerlayer_data = calloc_or_fail(1, sizeof(lowerlayer_data_t));
/* Initialize NAS user */ /* Initialize NAS user */
nas_user_initialize(user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION); nas_user_initialize(user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION);
} }
...@@ -170,9 +170,9 @@ void *nas_ue_task(void *args_p) ...@@ -170,9 +170,9 @@ void *nas_ue_task(void *args_p)
/* Initialize user interface (to exchange AT commands with user process) */ /* Initialize user interface (to exchange AT commands with user process) */
nas_user_api_id_initialize(user); nas_user_api_id_initialize(user);
/* allocate needed structures */ /* allocate needed structures */
user->user_at_commands = calloc_or_fail(sizeof(user_at_commands_t)); user->user_at_commands = calloc_or_fail(1, sizeof(user_at_commands_t));
user->at_response = calloc_or_fail(sizeof(at_response_t)); user->at_response = calloc_or_fail(1, sizeof(at_response_t));
user->lowerlayer_data = calloc_or_fail(sizeof(lowerlayer_data_t)); user->lowerlayer_data = calloc_or_fail(1, sizeof(lowerlayer_data_t));
/* Initialize NAS user */ /* Initialize NAS user */
nas_user_initialize(user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION); nas_user_initialize(user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION);
user->ueid = 0; user->ueid = 0;
......
...@@ -154,7 +154,7 @@ void nas_user_initialize(nas_user_t *user, emm_indication_callback_t emm_cb, ...@@ -154,7 +154,7 @@ void nas_user_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
user->nas_user_nvdata = calloc_or_fail(sizeof(user_nvdata_t)); user->nas_user_nvdata = calloc_or_fail(1, sizeof(user_nvdata_t));
/* Get UE data stored in the non-volatile memory device */ /* Get UE data stored in the non-volatile memory device */
int rc = memory_read(user->user_nvdata_store, user->nas_user_nvdata, sizeof(user_nvdata_t)); int rc = memory_read(user->user_nvdata_store, user->nas_user_nvdata, sizeof(user_nvdata_t));
...@@ -163,7 +163,7 @@ void nas_user_initialize(nas_user_t *user, emm_indication_callback_t emm_cb, ...@@ -163,7 +163,7 @@ void nas_user_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
abort(); abort();
} }
user->nas_user_context = calloc_or_fail(sizeof(nas_user_context_t)); user->nas_user_context = calloc_or_fail(1, sizeof(nas_user_context_t));
_nas_user_context_initialize(user->nas_user_context, version); _nas_user_context_initialize(user->nas_user_context, version);
/* Initialize the internal NAS processing data */ /* Initialize the internal NAS processing data */
......
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