move BCD string encoding/decoding functions to iu_helpers.[ch]
diff --git a/src/Makefile b/src/Makefile
index 97239b5..67e6e98 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -38,7 +38,7 @@
ranap/libosmo-asn1-ranap.a:
$(MAKE) -C ranap
-hnbgw: asn1helpers.o hnbgw.o hnbgw_hnbap.o hnbgw_rua.o hnbgw_ranap.o $(HNBAP_OBJS) $(RUA_OBJS) $(RANAP_OBJS) $(LIBS)
+hnbgw: iu_helpers.o asn1helpers.o hnbgw.o hnbgw_hnbap.o hnbgw_rua.o hnbgw_ranap.o $(HNBAP_OBJS) $(RUA_OBJS) $(RANAP_OBJS) $(LIBS)
$(CC) $(LDFLAGS) -o $@ $^
%.o: %.c
diff --git a/src/hnbgw_hnbap.c b/src/hnbgw_hnbap.c
index 8b1527e..1915ad6 100644
--- a/src/hnbgw_hnbap.c
+++ b/src/hnbgw_hnbap.c
@@ -24,52 +24,6 @@
return osmo_wqueue_enqueue(&ctx->wqueue, msg);
}
-int decode_iu_bcd(char *out, size_t out_len, const uint8_t *in, size_t in_len)
-{
- const uint8_t *ch;
- char *outch = out;
-
- for (ch = in; ch < in + in_len; ch++) {
- char c = osmo_bcd2char(*ch & 0xF);
- *outch++ = c;
- if (outch + 1 >= out + out_len)
- break;
- c = osmo_bcd2char(*ch >> 4);
- /* skip padding nibble at end */
- if (c == 'F')
- break;
- *outch++ = c;
- }
- *outch++ = '\0';
- return outch - out;
-}
-
-int encode_iu_imsi(uint8_t *out, size_t out_len,
- const char *in)
-{
- unsigned int len = strlen(in);
- uint8_t odd = (len & 0x01) == 1;
- unsigned int off = 0;
- unsigned int i;
-
- len /= 2;
- if (odd)
- len++;
-
- for (i = 0; i < len; i++) {
- uint8_t lower, upper;
-
- lower = osmo_char2bcd(in[++off]) & 0x0f;
- if (!odd && off + 1 == len)
- upper = 0x0f;
- else
- upper = osmo_char2bcd(in[++off]) & 0x0f;
-
- out[i] = (upper << 4) | lower;
- }
- return i;
-}
-
static int hnbgw_tx_hnb_register_acc(struct hnb_context *ctx)
{
HNBRegisterAccept_t accept_out;
diff --git a/src/iu_helpers.c b/src/iu_helpers.c
new file mode 100644
index 0000000..5064665
--- /dev/null
+++ b/src/iu_helpers.c
@@ -0,0 +1,48 @@
+#include <stdint.h>
+
+#include <osmocom/core/utils.h>
+
+int decode_iu_bcd(char *out, size_t out_len, const uint8_t *in, size_t in_len)
+{
+ const uint8_t *ch;
+ char *outch = out;
+
+ for (ch = in; ch < in + in_len; ch++) {
+ char c = osmo_bcd2char(*ch & 0xF);
+ *outch++ = c;
+ if (outch + 1 >= out + out_len)
+ break;
+ c = osmo_bcd2char(*ch >> 4);
+ /* skip padding nibble at end */
+ if (c == 'F')
+ break;
+ *outch++ = c;
+ }
+ *outch++ = '\0';
+ return outch - out;
+}
+
+int encode_iu_imsi(uint8_t *out, size_t out_len, const char *in)
+{
+ unsigned int len = strlen(in);
+ uint8_t odd = (len & 0x01) == 1;
+ unsigned int off = 0;
+ unsigned int i;
+
+ len /= 2;
+ if (odd)
+ len++;
+
+ for (i = 0; i < len; i++) {
+ uint8_t lower, upper;
+
+ lower = osmo_char2bcd(in[++off]) & 0x0f;
+ if (!odd && off + 1 == len)
+ upper = 0x0f;
+ else
+ upper = osmo_char2bcd(in[++off]) & 0x0f;
+
+ out[i] = (upper << 4) | lower;
+ }
+ return i;
+}
diff --git a/src/iu_helpers.h b/src/iu_helpers.h
new file mode 100644
index 0000000..4733bbc
--- /dev/null
+++ b/src/iu_helpers.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#include <stdint.h>
+
+int decode_iu_bcd(char *out, size_t out_len, const uint8_t *in, size_t in_len);
+int encode_iu_imsi(uint8_t *out, size_t out_len, const char *in);