asn1helpers: Add 28 bit conversion function and use it for Cell ID
The padding bits in the bit string are at the end and the byte-order is
MSB-first. This means the number needs to be shifted left so the padding
bits are the least significant.
diff --git a/src/asn1helpers.c b/src/asn1helpers.c
index f6378e6..791d0ed 100644
--- a/src/asn1helpers.c
+++ b/src/asn1helpers.c
@@ -33,6 +33,14 @@
bitstr->bits_unused = 0;
}
+void asn1_u28_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in)
+{
+ *buf = htonl(in<<4);
+ bitstr->buf = (uint8_t *) buf;
+ bitstr->size = sizeof(uint32_t);
+ bitstr->bits_unused = 4;
+}
+
void asn1_u24_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in)
{
*buf = htonl(in);
@@ -87,6 +95,13 @@
return ntohl(*(uint32_t *)in->buf);
}
+uint32_t asn1bitstr_to_u28(const BIT_STRING_t *in)
+{
+ OSMO_ASSERT(in && in->size == sizeof(uint32_t) && in->bits_unused == 4);
+
+ return ntohl(*(uint32_t *)in->buf) >> 4;
+}
+
uint32_t asn1bitstr_to_u24(const BIT_STRING_t *in)
{
OSMO_ASSERT(in && in->size == 3);