From 29ae9c7465a13f8b3fa31fa0928263f68530432d Mon Sep 17 00:00:00 2001
From: Alexander Chemeris <Alexander.Chemeris@gmail.com>
Date: Sun, 9 Mar 2014 01:33:28 +0100
Subject: [PATCH] sms: Rename gsm340_gen_oa() to gsm340_gen_address_field().

According to 03.40 9.1.2.5 Address fields, this function generates different
types of addresses and not only originating addresses.
---
 include/osmocom/gsm/gsm0411_utils.h |    3 +++
 src/gsm/gsm0411_utils.c             |    9 ++++++++-
 src/gsm/libosmogsm.map              |    1 +
 tests/sms/sms_test.c                |   16 ++++++++--------
 tests/sms/sms_test.ok               |    2 +-
 5 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/include/osmocom/gsm/gsm0411_utils.h b/include/osmocom/gsm/gsm0411_utils.h
index cad3625..2895a8d 100644
--- a/include/osmocom/gsm/gsm0411_utils.h
+++ b/include/osmocom/gsm/gsm0411_utils.h
@@ -2,6 +2,7 @@
 #define _GSM0411_UTILS_H
 
 #include <time.h>
+#include <osmocom/core/defs.h>
 
 /* Default SMS validity period is 2 days */
 #define SMS_DEFAULT_VALIDITY_PERIOD	(2 * 24 * 60 * 60)
@@ -28,6 +29,8 @@ enum sms_alphabet gsm338_get_sms_alphabet(uint8_t dcs);
 
 /* generate a TPDU address field compliant with 03.40 sec. 9.1.2.5 */
 int gsm340_gen_oa(uint8_t *oa, unsigned int oa_len, uint8_t type,
+	uint8_t plan, const char *number) OSMO_DEPRECATED("Use gsm340_gen_address_field() instead");
+int gsm340_gen_address_field(uint8_t *oa, unsigned int oa_len, uint8_t type,
 	uint8_t plan, const char *number);
 
 /* Prefix msg with a RP header */
diff --git a/src/gsm/gsm0411_utils.c b/src/gsm/gsm0411_utils.c
index 12f45d6..e897136 100644
--- a/src/gsm/gsm0411_utils.c
+++ b/src/gsm/gsm0411_utils.c
@@ -275,7 +275,7 @@ enum sms_alphabet gsm338_get_sms_alphabet(uint8_t dcs)
 }
 
 /* generate a TPDU address field compliant with 03.40 sec. 9.1.2.5 */
-int gsm340_gen_oa(uint8_t *oa, unsigned int oa_len, uint8_t type,
+int gsm340_gen_address_field(uint8_t *oa, unsigned int oa_len, uint8_t type,
 	uint8_t plan, const char *number)
 {
 	int len_in_bytes;
@@ -304,6 +304,13 @@ int gsm340_gen_oa(uint8_t *oa, unsigned int oa_len, uint8_t type,
 	return len_in_bytes;
 }
 
+/* DEPRECATED: use gsm340_gen_address_field() instead */
+int gsm340_gen_oa(uint8_t *oa, unsigned int oa_len, uint8_t type,
+	uint8_t plan, const char *number)
+{
+	return gsm340_gen_address_field(oa, oa_len, type, plan, number);
+}
+
 /* Prefix msg with a RP header */
 int gsm411_push_rp_header(struct msgb *msg, uint8_t rp_msg_type,
 	uint8_t rp_msg_ref)
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 9d15d66..46be0ca 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -63,6 +63,7 @@ gsm0808_prepend_dtap_header;
 gsm338_get_sms_alphabet;
 
 gsm340_gen_oa;
+gsm340_gen_address_field;
 gsm340_gen_scts;
 gsm340_scts;
 gsm340_validity_period;
diff --git a/tests/sms/sms_test.c b/tests/sms/sms_test.c
index 6681ba0..7414d16 100644
--- a/tests/sms/sms_test.c
+++ b/tests/sms/sms_test.c
@@ -233,37 +233,37 @@ static void test_octet_return()
 	printf("Done\n");
 }
 
-static void test_gen_oa(void)
+static void test_gsm340_gen_address_field(void)
 {
 	uint8_t oa[12];
 	int len;
 
-	printf("Testing gsm340_gen_oa\n");
+	printf("Testing gsm340_gen_address_field\n");
 
 	/* first try... */
-	len = gsm340_gen_oa(oa, ARRAY_SIZE(oa), GSM340_TYPE_UNKNOWN,
+	len = gsm340_gen_address_field(oa, ARRAY_SIZE(oa), GSM340_TYPE_UNKNOWN,
 			GSM340_PLAN_ISDN, "12345678901234567891");
 	OSMO_ASSERT(len == 12);
 	printf("Result: len(%d) data(%s)\n", len, osmo_hexdump(oa, len));
-	len = gsm340_gen_oa(oa, ARRAY_SIZE(oa), GSM340_TYPE_NATIONAL,
+	len = gsm340_gen_address_field(oa, ARRAY_SIZE(oa), GSM340_TYPE_NATIONAL,
 			GSM340_PLAN_ISDN, "12345678901234567891");
 	OSMO_ASSERT(len == 12);
 	printf("Result: len(%d) data(%s)\n", len, osmo_hexdump(oa, len));
 
 	/* long input.. will fail and just prints the header*/
-	len = gsm340_gen_oa(oa, ARRAY_SIZE(oa), GSM340_TYPE_INTERNATIONAL,
+	len = gsm340_gen_address_field(oa, ARRAY_SIZE(oa), GSM340_TYPE_INTERNATIONAL,
 			GSM340_PLAN_ISDN, "123456789123456789120");
 	OSMO_ASSERT(len == 2);
 	printf("Result: len(%d) data(%s)\n", len, osmo_hexdump(oa, len));
 
 	/* try the alpha numeric encoding */
-	len = gsm340_gen_oa(oa, ARRAY_SIZE(oa), GSM340_TYPE_ALPHA_NUMERIC,
+	len = gsm340_gen_address_field(oa, ARRAY_SIZE(oa), GSM340_TYPE_ALPHA_NUMERIC,
 			GSM340_PLAN_UNKNOWN, "OpenBSC");
 	OSMO_ASSERT(len == 9);
 	printf("Result: len(%d) data(%s)\n", len, osmo_hexdump(oa, len));
 
 	/* long alpha numeric text */
-	len = gsm340_gen_oa(oa, ARRAY_SIZE(oa), GSM340_TYPE_ALPHA_NUMERIC,
+	len = gsm340_gen_address_field(oa, ARRAY_SIZE(oa), GSM340_TYPE_ALPHA_NUMERIC,
 			GSM340_PLAN_UNKNOWN, "OpenBSCabcdefghijklm");
 	OSMO_ASSERT(len == 12);
 	printf("Result: len(%d) data(%s)\n", len, osmo_hexdump(oa, len));
@@ -541,7 +541,7 @@ int main(int argc, char** argv)
 	}
 
 	test_octet_return();
-	test_gen_oa();
+	test_gsm340_gen_address_field();
 	test_validity_period();
 
 	printf("OK\n");
diff --git a/tests/sms/sms_test.ok b/tests/sms/sms_test.ok
index 5ff3e0b..77b22ec 100644
--- a/tests/sms/sms_test.ok
+++ b/tests/sms/sms_test.ok
@@ -20,7 +20,7 @@ Decode case 5: return value 40 (expected 40)
 Encoding some tests and printing number of septets/octets
 SEPTETS: 8 OCTETS: 7
 Done
-Testing gsm340_gen_oa
+Testing gsm340_gen_address_field
 Result: len(12) data(14 81 21 43 65 87 09 21 43 65 87 19 )
 Result: len(12) data(14 a1 21 43 65 87 09 21 43 65 87 19 )
 Result: len(2) data(00 91 )
-- 
1.7.9.5

