Refactor (MAC): extract CellGroupConfig encoding into shared function

Extract common CellGroupConfig encoding logic from
ue_context_setup_request() and ue_context_modification_request() into
encode_cellgroup_config().

Replace uper_encode_to_buffer() with uper_encode_to_new_buffer() to:
- Remove 1024-byte buffer size limit
- Automatically allocate correct buffer size
- Simplify code (no manual bit-to-byte conversion)
- Align with other protocol encoders
This commit is contained in:
Guido Casati
2026-01-22 14:56:11 +00:00
committed by luis_pereira87
parent 94bb169ac5
commit 0b8fb49a38
+16 -15
View File
@@ -607,6 +607,20 @@ static NR_UE_info_t *create_new_UE(gNB_MAC_INST *mac, uint32_t cu_id, const NR_C
return UE;
}
/** @brief Encode CellGroupConfig to byte array for transparent forwarding in F1AP messages.
* The encoded bytes are intended for transparent forwarding to the UE without
* decode/re-encode cycles per TS 38.473 transparency requirements.
* @param cellGroup CellGroupConfig to encode
* @return Encoded byte array */
static byte_array_t encode_cellgroup_config(const NR_CellGroupConfig_t *cellGroup)
{
byte_array_t cgc = {0};
ssize_t encoded = uper_encode_to_new_buffer(&asn_DEF_NR_CellGroupConfig, NULL, cellGroup, (void **)&cgc.buf);
AssertFatal(encoded > 0, "Could not encode CellGroup\n");
cgc.len = encoded;
return cgc;
}
void ue_context_setup_request(const f1ap_ue_context_setup_req_t *req)
{
const bool is_SA = IS_SA_MODE(get_softmodem_params());
@@ -688,12 +702,7 @@ void ue_context_setup_request(const f1ap_ue_context_setup_req_t *req)
}
}
byte_array_t cgc = { .buf = calloc_or_fail(1,1024) };
asn_enc_rval_t enc_rval =
uper_encode_to_buffer(&asn_DEF_NR_CellGroupConfig, NULL, new_CellGroup, cgc.buf, 1024);
AssertFatal(enc_rval.encoded > 0, "Could not encode CellGroup, failed element %s\n", enc_rval.failed_type->name);
cgc.len = (enc_rval.encoded + 7) >> 3;
resp.du_to_cu_rrc_info.cell_group_config = cgc;
resp.du_to_cu_rrc_info.cell_group_config = encode_cellgroup_config(new_CellGroup);
ASN_STRUCT_FREE(asn_DEF_NR_CellGroupConfig, UE->reconfigCellGroup);
UE->reconfigCellGroup = new_CellGroup;
@@ -803,15 +812,7 @@ void ue_context_modification_request(const f1ap_ue_context_mod_req_t *req)
if (req->srbs_len > 0 || req->drbs_len > 0 || req->drbs_rel_len > 0 || ue_cap != NULL) {
resp.du_to_cu_rrc_info = calloc_or_fail(1, sizeof(du_to_cu_rrc_information_t));
byte_array_t cgc = { .buf = calloc_or_fail(1, 1024) };
asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CellGroupConfig,
NULL,
new_CellGroup,
cgc.buf,
1024);
AssertFatal(enc_rval.encoded > 0, "Could not encode CellGroup, failed element %s\n", enc_rval.failed_type->name);
cgc.len = (enc_rval.encoded + 7) >> 3;
resp.du_to_cu_rrc_info->cell_group_config = cgc;
resp.du_to_cu_rrc_info->cell_group_config = encode_cellgroup_config(new_CellGroup);
ASN_STRUCT_FREE(asn_DEF_NR_CellGroupConfig, UE->reconfigCellGroup);
UE->reconfigCellGroup = new_CellGroup;