refactor: harmonize AS key BIT_STRING macro

Replace duplicated KENB_STAR_TO_BIT_STRING and
KGNB_STAR_TO_BIT_STRING macros with the unified
AS_KEY_STAR_TO_BIT_STRING helper across X2AP,
XNAP, M2AP, and M3AP code paths.

Also switch allocation to calloc_or_fail for
safer memory handling.

No functional change intended.

Signed-off-by: Rakesh BB <rakesh.bb@fsid-iisc.in>
This commit is contained in:
Rakesh BB
2026-05-27 12:56:29 +05:30
parent 6d6930ce20
commit e33ffd5e8c
5 changed files with 12 additions and 19 deletions

View File

@@ -449,7 +449,7 @@ int m2ap_eNB_set_cause (M2AP_Cause_t * cause_p,
// //@TODO: consider to update this value
// ie->value.choice.UE_ContextInformation.mME_UE_S1AP_ID = m2ap_handover_req->mme_ue_s1ap_id;
//
// KENB_STAR_TO_BIT_STRING(m2ap_handover_req->kenb,&ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star);
// AS_KEY_STAR_TO_BIT_STRING(m2ap_handover_req->kenb,&ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star);
//
// if (m2ap_handover_req->kenb_ncc >=0) { // Check this condition
// ie->value.choice.UE_ContextInformation.aS_SecurityInformation.nextHopChainingCount = m2ap_handover_req->kenb_ncc;

View File

@@ -627,7 +627,8 @@ int x2ap_eNB_generate_x2_handover_request (x2ap_eNB_instance_t *instance_p, x2ap
//@TODO: consider to update this value
ie->value.choice.UE_ContextInformation.mME_UE_S1AP_ID = x2ap_handover_req->mme_ue_s1ap_id;
KENB_STAR_TO_BIT_STRING(x2ap_handover_req->kenb,&ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star);
AS_KEY_STAR_TO_BIT_STRING(x2ap_handover_req->kenb,
&ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star);
if (x2ap_handover_req->kenb_ncc >=0) { // Check this condition
ie->value.choice.UE_ContextInformation.aS_SecurityInformation.nextHopChainingCount = x2ap_handover_req->kenb_ncc;
@@ -1608,7 +1609,7 @@ int x2ap_eNB_generate_ENDC_x2_SgNB_addition_request(
ie->id = X2AP_ProtocolIE_ID_id_SgNBSecurityKey;
ie->criticality = X2AP_Criticality_reject;
ie->value.present = X2AP_SgNBAdditionRequest_IEs__value_PR_SgNBSecurityKey;
KENB_STAR_TO_BIT_STRING(SgNBSecurityKey, &ie->value.choice.SgNBSecurityKey);
AS_KEY_STAR_TO_BIT_STRING(SgNBSecurityKey, &ie->value.choice.SgNBSecurityKey);
asn1cSeqAdd(&out->protocolIEs.list, ie);
ie = (X2AP_SgNBAdditionRequest_IEs_t *)calloc(1, sizeof(X2AP_SgNBAdditionRequest_IEs_t));

View File

@@ -257,7 +257,7 @@ XNAP_XnAP_PDU_t *encode_xnap_handover_request(const xnap_handover_req_t *req)
ctx->ueSecurityCapabilities = xnap_encode_security_capabilities(s_cap);
/* AS Security Information */
KGNB_STAR_TO_BIT_STRING(req->ue_context.as_security_key_ranstar, &ctx->securityInformation.key_NG_RAN_Star);
AS_KEY_STAR_TO_BIT_STRING(req->ue_context.as_security_key_ranstar, &ctx->securityInformation.key_NG_RAN_Star);
ctx->securityInformation.ncc = req->ue_context.as_security_ncc;
/* RRC Context (Handover Preparation Information) */

View File

@@ -450,7 +450,7 @@ int m2ap_eNB_set_cause (M2AP_Cause_t * cause_p,
// //@TODO: consider to update this value
// ie->value.choice.UE_ContextInformation.mME_UE_S1AP_ID = m2ap_handover_req->mme_ue_s1ap_id;
//
// KENB_STAR_TO_BIT_STRING(m2ap_handover_req->kenb,&ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star);
// AS_KEY_STAR_TO_BIT_STRING(m2ap_handover_req->kenb,&ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star);
//
// if (m2ap_handover_req->kenb_ncc >=0) { // Check this condition
// ie->value.choice.UE_ContextInformation.aS_SecurityInformation.nextHopChainingCount = m2ap_handover_req->kenb_ncc;

View File

@@ -208,20 +208,12 @@ do { \
(bitstring)->buf[1] = (intprotalg); \
}while(0)
#define KENB_STAR_TO_BIT_STRING(kenbstar, bitstring) \
do { \
(bitstring)->size=32; \
(bitstring)->bits_unused=0; \
(bitstring)->buf= calloc (32, sizeof (uint8_t));\
memcpy((bitstring)->buf, kenbstar, 32*sizeof(uint8_t)); \
}while(0)
#define KGNB_STAR_TO_BIT_STRING(kgnbstar, bitstring) \
#define AS_KEY_STAR_TO_BIT_STRING(askeystar, bitstring) \
do { \
(bitstring)->size = 32; \
(bitstring)->bits_unused = 0; \
(bitstring)->buf = calloc(32, sizeof(uint8_t)); \
memcpy((bitstring)->buf, kgnbstar, 32 * sizeof(uint8_t)); \
(bitstring)->buf = calloc_or_fail(32, sizeof(uint8_t)); \
memcpy((bitstring)->buf, askeystar, 32 * sizeof(uint8_t)); \
} while (0)
#define UEAGMAXBITRTD_TO_ASN_PRIMITIVES(uegmaxbitrtd, asnprimitives) \