diff options
author | Daniel Willmann <dwillmann@sysmocom.de> | 2015-12-08 13:55:17 +0100 |
---|---|---|
committer | Daniel Willmann <dwillmann@sysmocom.de> | 2015-12-14 10:21:51 +0100 |
commit | d6a45b402c5c09e079371eddbb6fbb6c4757aeab (patch) | |
tree | 0955c1b42f8f448313bf7fa4075af5a2ddbc593b | |
parent | a1e202e15eab6c4f5ea84659472a3bb2a503a59a (diff) |
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.
-rw-r--r-- | src/asn1helpers.c | 15 | ||||
-rw-r--r-- | src/hnbgw_hnbap.c | 2 | ||||
-rw-r--r-- | src/tests/hnb-test.c | 5 |
3 files changed, 18 insertions, 4 deletions
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 @@ void asn1_u32_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in) 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 @@ uint32_t asn1bitstr_to_u32(const BIT_STRING_t *in) 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); diff --git a/src/hnbgw_hnbap.c b/src/hnbgw_hnbap.c index 3e3715c..97cb32b 100644 --- a/src/hnbgw_hnbap.c +++ b/src/hnbgw_hnbap.c @@ -120,7 +120,7 @@ static int hnbgw_rx_hnb_register_req(struct hnb_context *ctx, ANY_t *in) ctx->id.lac = asn1str_to_u16(&ies.lac); ctx->id.sac = asn1str_to_u16(&ies.sac); ctx->id.rac = asn1str_to_u8(&ies.rac); - ctx->id.cid = asn1bitstr_to_u32(&ies.cellIdentity); + ctx->id.cid = asn1bitstr_to_u28(&ies.cellIdentity); //ctx->id.mcc FIXME //ctx->id.mnc FIXME diff --git a/src/tests/hnb-test.c b/src/tests/hnb-test.c index 92170d5..6c717d0 100644 --- a/src/tests/hnb-test.c +++ b/src/tests/hnb-test.c @@ -144,13 +144,12 @@ static void hnb_send_register_req(struct hnb_test *hnb_test) lac = 0xc0fe; sac = 0xabab; rac = 0x42; - cid = 0xadce00; + cid = 0xadceaab; asn1_u16_to_str(&request.lac, &lac, lac); asn1_u16_to_str(&request.sac, &sac, sac); asn1_u8_to_str(&request.rac, &rac, rac); - asn1_u32_to_bitstring(&request.cellIdentity, &cid, cid); - request.cellIdentity.bits_unused = 4; + asn1_u28_to_bitstring(&request.cellIdentity, &cid, cid); request.hnB_Identity.hNB_Identity_Info.buf = identity; request.hnB_Identity.hNB_Identity_Info.size = strlen(identity); |