From e9ff62884422725fbe92d2e7f84a71f43bb4bcb0 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 19 Nov 2024 18:55:29 +0100 Subject: [PATCH] Add macros to deep copy and compare optional E1 IEs --- openair2/E1AP/lib/e1ap_lib_common.h | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/openair2/E1AP/lib/e1ap_lib_common.h b/openair2/E1AP/lib/e1ap_lib_common.h index f3c6b24da2..eceddb263f 100644 --- a/openair2/E1AP/lib/e1ap_lib_common.h +++ b/openair2/E1AP/lib/e1ap_lib_common.h @@ -66,4 +66,36 @@ } \ } while (0) +/* deep copy of optional E1AP IE */ +#define _E1_CP_OPTIONAL_IE(dest, src, field) \ + do { \ + if ((src)->field) { \ + (dest)->field = malloc_or_fail(sizeof(*(dest)->field)); \ + *(dest)->field = *(src)->field; \ + } \ + } while (0) + +#define _E1_EQ_CHECK_OPTIONAL_IE(a, b, field, EQ_MACRO) \ + do { \ + if (((a)->field && !(b)->field) || (!(a)->field && (b)->field)) { \ + return false; /* One of the two is not allocated */ \ + } \ + if ((a)->field && (b)->field) { \ + EQ_MACRO(*(a)->field, *(b)->field) \ + } \ + } while (0) + +#define _E1_EQ_CHECK_OPTIONAL_PTR(a, b, field) \ + do { \ + if (((a)->field && !(b)->field) || (!(a)->field && (b)->field)) { \ + PRINT_ERROR("%s:%d: optional IE '%s' not allocated: %p, %p\n", \ + __FILE__, \ + __LINE__, \ + #field, \ + (void *)(a)->field, \ + (void *)(b)->field); \ + return false; /* One of the two is not allocated */ \ + } \ + } while (0) + #endif /* E1AP_LIB_COMMON_H_ */