From fc1a5538d0e155a4bebc6af6c400e7b6a39b4553 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 4 Jan 2023 16:34:16 +0100 Subject: [PATCH] Replace gprs_str_to_apn() with libosmocore API osmo_apn_from_str() The exact same function exists in libosmocore with a different naming. Change-Id: Ibef55a648f2d58f4fdd24fa553efde530982af2d --- include/osmocom/sgsn/gprs_utils.h | 2 -- src/gprs/gprs_utils.c | 34 ------------------------------- tests/sgsn/sgsn_test.c | 34 +++++++++++++++---------------- 3 files changed, 17 insertions(+), 53 deletions(-) diff --git a/include/osmocom/sgsn/gprs_utils.h b/include/osmocom/sgsn/gprs_utils.h index 8a6731f12..1e6c8319c 100644 --- a/include/osmocom/sgsn/gprs_utils.h +++ b/include/osmocom/sgsn/gprs_utils.h @@ -29,8 +29,6 @@ struct msgb; struct gprs_ra_id; -int gprs_str_to_apn(uint8_t *apn_enc, size_t max_len, const char *str); - /* GSM 04.08, 10.5.7.3 GPRS Timer */ uint8_t gprs_secs_to_tmr_floor(int secs); diff --git a/src/gprs/gprs_utils.c b/src/gprs/gprs_utils.c index 9fddc73aa..46028c63c 100644 --- a/src/gprs/gprs_utils.c +++ b/src/gprs/gprs_utils.c @@ -30,40 +30,6 @@ #include -int gprs_str_to_apn(uint8_t *apn_enc, size_t max_len, const char *str) -{ - uint8_t *last_len_field; - int len; - - /* Can we even write the length field to the output? */ - if (max_len == 0) - return -1; - - /* Remember where we need to put the length once we know it */ - last_len_field = apn_enc; - len = 1; - apn_enc += 1; - - while (str[0]) { - if (len >= max_len) - return -1; - - if (str[0] == '.') { - *last_len_field = (apn_enc - last_len_field) - 1; - last_len_field = apn_enc; - } else { - *apn_enc = str[0]; - } - apn_enc += 1; - str += 1; - len += 1; - } - - *last_len_field = (apn_enc - last_len_field) - 1; - - return len; -} - /* This functions returns a tmr value such that * - f is monotonic * - f(s) <= s diff --git a/tests/sgsn/sgsn_test.c b/tests/sgsn/sgsn_test.c index a09f1a5b6..91a3dcf56 100644 --- a/tests/sgsn/sgsn_test.c +++ b/tests/sgsn/sgsn_test.c @@ -19,26 +19,26 @@ * */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + #include #include #include #include #include -#include -#include #include #include -#include - -#include - -#include -#include -#include -#include -#include - #include #include "gprs_gb_parse.h" @@ -1492,7 +1492,7 @@ static void test_ggsn_selection(void) /* Resolve GGSNs */ tp.lv[GSM48_IE_GSM_APN].len = - gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Test.Apn"); + osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Test.Apn"); ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); OSMO_ASSERT(ggc != NULL); @@ -1500,7 +1500,7 @@ static void test_ggsn_selection(void) OSMO_ASSERT(strcmp(apn_str, "Test.Apn") == 0); tp.lv[GSM48_IE_GSM_APN].len = - gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Other.Apn"); + osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Other.Apn"); ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); OSMO_ASSERT(ggc != NULL); @@ -1526,7 +1526,7 @@ static void test_ggsn_selection(void) tp.lv[GSM48_IE_GSM_APN].val = apn_enc; tp.lv[GSM48_IE_GSM_APN].len = - gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Foo.Bar"); + osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Foo.Bar"); ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); OSMO_ASSERT(ggc == NULL); @@ -1543,7 +1543,7 @@ static void test_ggsn_selection(void) osmo_strlcpy(pdp_data->apn_str, "Test.Apn", sizeof(pdp_data->apn_str)); tp.lv[GSM48_IE_GSM_APN].len = - gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Test.Apn"); + osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Test.Apn"); ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); OSMO_ASSERT(ggc != NULL); @@ -1551,7 +1551,7 @@ static void test_ggsn_selection(void) OSMO_ASSERT(strcmp(apn_str, "Test.Apn") == 0); tp.lv[GSM48_IE_GSM_APN].len = - gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Other.Apn"); + osmo_apn_from_str(apn_enc, sizeof(apn_enc), "Other.Apn"); ggc = sgsn_mm_ctx_find_ggsn_ctx(ctx, &tp, &gsm_cause, apn_str); OSMO_ASSERT(ggc == NULL);