aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2013-05-02 20:51:28 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2013-07-13 09:15:47 +0200
commitc7223231b5398a00496d01609ff92875bf6a7b1b (patch)
tree1a19f9886ebe55aa13adf47bd77933b0bfca269d
parent2909942a9fe54a8c1f98588dcfece6f4fe35d100 (diff)
encoding: Provide an overload for the gsm_7bit_encode and a simple test
This is required for encoding the SMS header using the alpha numeric rules.
-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 308803d..b736de9 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);
int gsm_septets2octets(uint8_t *result, const uint8_t *rdata, uint8_t septet_len, uint8_t padding);
int gsm_septet_encode(uint8_t *result, const char *data);
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index 9569cf3..54b965e 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 b2278f1..8a020db 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 6df4b62..e48f9a3 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 d0e0983..ce6cb17 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