diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ussd/ussd_test.c | 75 | ||||
-rw-r--r-- | tests/ussd/ussd_test.ok | 6 |
2 files changed, 81 insertions, 0 deletions
diff --git a/tests/ussd/ussd_test.c b/tests/ussd/ussd_test.c index 1f79063b..23fd7393 100644 --- a/tests/ussd/ussd_test.c +++ b/tests/ussd/ussd_test.c @@ -34,6 +34,17 @@ static const uint8_t ussd_request[] = { 0x01, 0x7f, 0x01, 0x00 }; +static const uint8_t ussd_facility[] = { + 0x1b, 0x3a, 0x12, 0xa2, 0x10, 0x02, 0x01, 0x01, + 0x30, 0x0b, 0x02, 0x01, 0x3c, 0x30, 0x06, 0x04, + 0x01, 0x0f, 0x04, 0x01, 0x32 +}; + +static const uint8_t ussd_release[] = { + 0x8b, 0x2a, 0x1c, 0x08, 0xa3, 0x06, 0x02, 0x01, + 0x05, 0x02, 0x01, 0x24 +}; + static const uint8_t interrogate_ss[] = { 0x0b, 0x7b, 0x1c, 0x0d, 0xa1, 0x0b, 0x02, 0x01, 0x03, 0x02, 0x01, 0x0e, 0x30, 0x03, 0x04, 0x01, @@ -116,6 +127,67 @@ static void test_7bit_ussd(const char *text, const char *encoded_hex, const char } } +static void test_extract_ie_by_tag(void) +{ + uint16_t ie_len; + uint8_t *ie; + int rc; + + printf("[i] Testing gsm0480_extract_ie_by_tag()\n"); + + /* REGISTER message with Facility IE */ + rc = gsm0480_extract_ie_by_tag((struct gsm48_hdr *) ussd_request, + sizeof(ussd_request), &ie, &ie_len, GSM0480_IE_FACILITY); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(ie != NULL && ie_len > 0); + printf("[?] REGISTER message with Facility IE " + "(len=%u): %s\n", ie_len, osmo_hexdump(ie, ie_len)); + + /* REGISTER message with SS version IE */ + rc = gsm0480_extract_ie_by_tag((struct gsm48_hdr *) ussd_request, + sizeof(ussd_request), &ie, &ie_len, GSM0480_IE_SS_VERSION); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(ie != NULL && ie_len > 0); + printf("[?] REGISTER message with SS version IE " + "(len=%u): %s\n", ie_len, osmo_hexdump(ie, ie_len)); + + /* REGISTER message with unknown IE */ + rc = gsm0480_extract_ie_by_tag((struct gsm48_hdr *) ussd_request, + sizeof(ussd_request), &ie, &ie_len, 0xff); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(ie == NULL && ie_len == 0); + + /* FACILITY message with Facility IE */ + rc = gsm0480_extract_ie_by_tag((struct gsm48_hdr *) ussd_facility, + sizeof(ussd_facility), &ie, &ie_len, GSM0480_IE_FACILITY); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(ie != NULL && ie_len > 0); + printf("[?] FACILITY message with Facility IE " + "(len=%u): %s\n", ie_len, osmo_hexdump(ie, ie_len)); + + /* FACILITY message with unknown IE */ + rc = gsm0480_extract_ie_by_tag((struct gsm48_hdr *) ussd_facility, + sizeof(ussd_facility), &ie, &ie_len, 0xff); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(ie == NULL && ie_len == 0); + + /* RELEASE COMPLETE message with Facility IE */ + rc = gsm0480_extract_ie_by_tag((struct gsm48_hdr *) ussd_release, + sizeof(ussd_release), &ie, &ie_len, GSM0480_IE_FACILITY); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(ie != NULL && ie_len > 0); + printf("[?] RELEASE COMPLETE message with Facility IE " + "(len=%u): %s\n", ie_len, osmo_hexdump(ie, ie_len)); + + /* RELEASE COMPLETE message without Facility IE */ + rc = gsm0480_extract_ie_by_tag((struct gsm48_hdr *) ussd_release, + sizeof(struct gsm48_hdr), &ie, &ie_len, GSM0480_IE_FACILITY); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(ie == NULL && ie_len == 0); + + printf("\n"); +} + int main(int argc, char **argv) { struct ss_request req; @@ -126,6 +198,9 @@ int main(int argc, char **argv) osmo_init_logging2(ctx, &info); + /* Test gsm0480_extract_ie_by_tag() */ + test_extract_ie_by_tag(); + memset(&req, 0, sizeof(req)); gsm0480_decode_ss_request((struct gsm48_hdr *) ussd_request, sizeof(ussd_request), &req); diff --git a/tests/ussd/ussd_test.ok b/tests/ussd/ussd_test.ok index aff383eb..8fa4348f 100644 --- a/tests/ussd/ussd_test.ok +++ b/tests/ussd/ussd_test.ok @@ -1,3 +1,9 @@ +[i] Testing gsm0480_extract_ie_by_tag() +[?] REGISTER message with Facility IE (len=21): a1 13 02 01 03 02 01 3b 30 0b 04 01 0f 04 06 2a d5 4c 16 1b 01 +[?] REGISTER message with SS version IE (len=1): 00 +[?] FACILITY message with Facility IE (len=18): a2 10 02 01 01 30 0b 02 01 3c 30 06 04 01 0f 04 01 32 +[?] RELEASE COMPLETE message with Facility IE (len=8): a3 06 02 01 05 02 01 24 + Tested if it still works. Text was: **321# interrogateSS CFU text..'' code 33 Testing parsing a USSD request and truncated versions |