Endianness assumptions
The conversions.h
: these macros assume the cpu is little endian, that is wrong for ARM
-
replace
INT32_TO_BUFFER(a,b)
as call to*(int32_t*)b=htonl(a)
; maybe better -
furthermore, in the same file
hton_int32()
is not necessary: thehtonl()
libc library do the same
two side points:
If we consider (n)FAPI, the problem is a bit different: FAPI can be "native" because it runs on same machine, this is another possible choice: native against nFAPI order (probably big endian, but i have not verified)
-
Performance: if performance matter, these byte swaps are available in SIMD, for a performance x10
-
openair3/NAS/UE/ESM/esm_ebr_context.c:215
=> this one, no doubts, htonl/ntohl should be used the developer is wrong -
openair2/UTIL/OSA/osa_internal.h:43
: yet another inet_to32 surprisingly not used in the same block of code:openair2/UTIL/OSA/osa_snow3g.c:144
:return ( ( ((uint32_t)r0) << 24 ) | ( ((uint32_t)r1) << 16 ) | ( ((uint32_t)r2) << 8 ) | ( ((uint32_t)r3) ) );
for example -
i still missed to removed some duplicated code:
openair3/SECU/snow3g.c
=> same "error" in duplicated file -
openair3/S1AP/s1ap_eNB.c:121
also clearly assuming endianness -
nfapi/open-nFAPI/nfapi/src/nfapi.c:224
same -
why is it a macro ? a C function would be normal C code and allows to verify parameters. i don't like the name: maybe
encode_eNBid_to_asn1c()
? thecalloc
should of course bemalloc
(erases all values just after)
#define
MACRO_ENB_ID_TO_BIT_STRING(mACRO, bITsTRING) \
do { \
(bITsTRING)->buf = calloc(3, sizeof(uint8_t)); \
(bITsTRING)->buf[0] = ((mACRO) >> 12); \
(bITsTRING)->buf[1] = (mACRO) >> 4; \
(bITsTRING)->buf[2] = ((mACRO) & 0x0f) << 4; \
(bITsTRING)->size = 3; \
(bITsTRING)->bits_unused = 4; \
} while(0)