From a78b22ba203d9674bb797623b9c1dd985b523663 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 13 Apr 2018 03:36:49 +0200 Subject: add tlv_parse2(), capable of multiple instances of the same IE Allow passing multiple struct tlv_parsed in an array, to allow parsing as many repeated IEs as are expected by the caller. From tlv_parse(), call tlv_parse2() with dec_multiple = 1 to yield the previous behavior. tlv_parse() remains valid API. An example of multiple IEs is the BSSMAP Handover Request, containing Cell Identifier (Serving) and Cell Identifier (Target), both defined by 3GPP TS 48.008 3.2.2.17 with identical IE tags; both are mandatory. Related: OS#2283 (inter-BSC HO, BSC side) Change-Id: Id04008eaf0a1cafdbdc11b7efc556e3035b1c84d --- tests/tlv/tlv_test.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/tlv/tlv_test.c b/tests/tlv/tlv_test.c index 39732756..e2065b00 100644 --- a/tests/tlv/tlv_test.c +++ b/tests/tlv/tlv_test.c @@ -254,6 +254,7 @@ static void test_tlv_repeated_ie() int i, rc; const uint8_t tag = 0x1a; struct tlv_parsed dec; + struct tlv_parsed dec3[3]; struct tlv_definition def; memset(&def, 0, sizeof(def)); @@ -273,6 +274,16 @@ static void test_tlv_repeated_ie() /* Value pointer should point at first value in test data array. */ OSMO_ASSERT(dec.lv[tag].val == &test_data[2]); OSMO_ASSERT(*dec.lv[tag].val == test_data[2]); + + /* Accept three decodings, pointing at first, second and third val */ + rc = tlv_parse2(dec3, 3, &def, &test_data[1], sizeof(test_data) - 1, tag, 0); + OSMO_ASSERT(rc == i/3); + OSMO_ASSERT(dec3[0].lv[tag].len == 1); + OSMO_ASSERT(dec3[0].lv[tag].val == &test_data[2]); + OSMO_ASSERT(dec3[1].lv[tag].len == 1); + OSMO_ASSERT(dec3[1].lv[tag].val == &test_data[2 + 3]); + OSMO_ASSERT(dec3[2].lv[tag].len == 1); + OSMO_ASSERT(dec3[2].lv[tag].val == &test_data[2 + 3 + 3]); } int main(int argc, char **argv) -- cgit v1.2.3