pespin has uploaded this change for review.

View Change

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
---
M include/osmocom/sgsn/gprs_utils.h
M src/gprs/gprs_utils.c
M tests/sgsn/sgsn_test.c
3 files changed, 19 insertions(+), 55 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/61/30861/1
diff --git a/include/osmocom/sgsn/gprs_utils.h b/include/osmocom/sgsn/gprs_utils.h
index 8a6731f..1e6c831 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 9fddc73..46028c6 100644
--- a/src/gprs/gprs_utils.c
+++ b/src/gprs/gprs_utils.c
@@ -30,40 +30,6 @@

#include <string.h>

-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 a09f1a5..36a9915 100644
--- a/tests/sgsn/sgsn_test.c
+++ b/tests/sgsn/sgsn_test.c
@@ -19,26 +19,26 @@
*
*/

-#include <osmocom/sgsn/gprs_llc.h>
-#include <osmocom/sgsn/sgsn.h>
-#include <osmocom/sgsn/gprs_gmm.h>
-#include <osmocom/sgsn/debug.h>
-#include <osmocom/sgsn/gprs_subscriber.h>
-#include <osmocom/gsm/gsup.h>
-#include <osmocom/gsupclient/gsup_client.h>
-#include <osmocom/sgsn/gprs_utils.h>
-#include <osmocom/sgsn/gprs_gmm_fsm.h>
-
-#include <osmocom/gprs/gprs_bssgp.h>
-
-#include <osmocom/gsm/gsm_utils.h>
-
#include <osmocom/core/application.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/utils.h>
#include <osmocom/vty/vty.h>

+#include <osmocom/gsm/apn.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/gsup.h>
+#include <osmocom/gprs/gprs_bssgp.h>
+
+#include <osmocom/sgsn/gprs_llc.h>
+#include <osmocom/sgsn/sgsn.h>
+#include <osmocom/sgsn/gprs_gmm.h>
+#include <osmocom/sgsn/debug.h>
+#include <osmocom/sgsn/gprs_subscriber.h>
+#include <osmocom/gsupclient/gsup_client.h>
+#include <osmocom/sgsn/gprs_utils.h>
+#include <osmocom/sgsn/gprs_gmm_fsm.h>
+
#include <stdio.h>

#include "gprs_gb_parse.h"
@@ -1492,7 +1492,7 @@
/* 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 @@
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 @@
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 @@
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 @@
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);

To view, visit change 30861. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: Ibef55a648f2d58f4fdd24fa553efde530982af2d
Gerrit-Change-Number: 30861
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-MessageType: newchange