diff options
author | Harald Welte <laforge@gnumonks.org> | 2015-09-11 17:35:52 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2015-09-11 17:35:52 +0200 |
commit | 208b7b07787e8776bca4e143c97972b51d22320c (patch) | |
tree | 63af6f77e13de3d3661aeeb79210d06ce78a1432 /src | |
parent | 393f2bd9fbc9cfe1f48ac6aeabfcda204c7e3d4b (diff) |
iu_helpers: fix encoding of BCD (like IMSI) into OCTET STING
Diffstat (limited to 'src')
-rw-r--r-- | src/iu_helpers.c | 13 | ||||
-rw-r--r-- | src/iu_helpers.h | 1 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/iu_helpers.c b/src/iu_helpers.c index 5064665..fee51bc 100644 --- a/src/iu_helpers.c +++ b/src/iu_helpers.c @@ -25,22 +25,23 @@ 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) { unsigned int len = strlen(in); + unsigned int octlen; uint8_t odd = (len & 0x01) == 1; unsigned int off = 0; unsigned int i; - len /= 2; + octlen = len/2; if (odd) - len++; + octlen++; - for (i = 0; i < len; i++) { + for (i = 0; i < octlen; i++) { uint8_t lower, upper; - lower = osmo_char2bcd(in[++off]) & 0x0f; - if (!odd && off + 1 == len) + lower = osmo_char2bcd(in[off++]) & 0x0f; + if (odd && off == len) upper = 0x0f; else - upper = osmo_char2bcd(in[++off]) & 0x0f; + upper = osmo_char2bcd(in[off++]) & 0x0f; out[i] = (upper << 4) | lower; } diff --git a/src/iu_helpers.h b/src/iu_helpers.h index 4733bbc..531d673 100644 --- a/src/iu_helpers.h +++ b/src/iu_helpers.h @@ -1,6 +1,7 @@ #pragma once #include <stdint.h> +#include <sys/types.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); |