summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/gsm/gsm_utils.h1
-rw-r--r--src/gsm/gsm_utils.c10
-rw-r--r--src/gsm/libosmogsm.map1
-rw-r--r--tests/sms/sms_test.c15
-rw-r--r--tests/sms/sms_test.ok3
5 files changed, 28 insertions, 2 deletions
diff --git a/include/osmocom/gsm/gsm_utils.h b/include/osmocom/gsm/gsm_utils.h
index cf63ea43..a572f504 100644
--- a/include/osmocom/gsm/gsm_utils.h
+++ b/include/osmocom/gsm/gsm_utils.h
@@ -59,6 +59,7 @@ enum gsm_band gsm_band_parse(const char *mhz);
int gsm_7bit_decode(char *decoded, const uint8_t *user_data, uint8_t length);
int gsm_7bit_decode_hdr(char *decoded, const uint8_t *user_data, uint8_t length, uint8_t ud_hdr_ind);
int gsm_7bit_encode(uint8_t *result, const char *data);
+int gsm_7bit_encode_oct(uint8_t *result, const char *data, int *octets_written);
/* the three functions below are helper functions and here for the unit test */
int gsm_septets2octets(uint8_t *result, const uint8_t *rdata, uint8_t septet_len, uint8_t padding);
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index 9569cf32..54b965e2 100644
--- a/src/gsm/gsm_utils.c
+++ b/src/gsm/gsm_utils.c
@@ -1,6 +1,6 @@
/*
* (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de>
- * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2009,2013 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
* (C) 2010-2012 by Nico Golde <nico@ngolde.de>
*
@@ -250,12 +250,18 @@ int gsm_septets2octets(uint8_t *result, const uint8_t *rdata, uint8_t septet_len
/* GSM 03.38 6.2.1 Character packing */
int gsm_7bit_encode(uint8_t *result, const char *data)
{
+ int out;
+ return gsm_7bit_encode_oct(result, data, &out);
+}
+
+int gsm_7bit_encode_oct(uint8_t *result, const char *data, int *octets)
+{
int y = 0;
/* prepare for the worst case, every character expanding to two bytes */
uint8_t *rdata = calloc(strlen(data) * 2, sizeof(uint8_t));
y = gsm_septet_encode(rdata, data);
- gsm_septets2octets(result, rdata, y, 0);
+ *octets = gsm_septets2octets(result, rdata, y, 0);
free(rdata);
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index b2278f15..8a020dbd 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -134,6 +134,7 @@ gsm48_rr_att_tlvdef;
gsm_7bit_decode;
gsm_7bit_decode_hdr;
gsm_7bit_encode;
+gsm_7bit_encode_oct;
gsm_arfcn2band;
gsm_arfcn2freq10;
diff --git a/tests/sms/sms_test.c b/tests/sms/sms_test.c
index 6df4b623..e48f9a36 100644
--- a/tests/sms/sms_test.c
+++ b/tests/sms/sms_test.c
@@ -209,6 +209,19 @@ static const struct test_case test_decode[] =
},
};
+static void test_octet_return()
+{
+ char out[256];
+ int oct, septets;
+
+ printf("Encoding some tests and printing number of septets/octets\n");
+
+ septets = gsm_7bit_encode_oct((uint8_t *) out, "test1234", &oct);
+ printf("SEPTETS: %d OCTETS: %d\n", septets, oct);
+
+ printf("Done\n");
+}
+
int main(int argc, char** argv)
{
printf("SMS testing\n");
@@ -314,6 +327,8 @@ int main(int argc, char** argv)
}
}
+ test_octet_return();
+
printf("OK\n");
return 0;
}
diff --git a/tests/sms/sms_test.ok b/tests/sms/sms_test.ok
index d0e09838..ce6cb178 100644
--- a/tests/sms/sms_test.ok
+++ b/tests/sms/sms_test.ok
@@ -1,2 +1,5 @@
SMS testing
+Encoding some tests and printing number of septets/octets
+SEPTETS: 8 OCTETS: 7
+Done
OK