diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2013-08-08 12:38:52 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2013-08-08 14:25:09 +0200 |
commit | 6bfa7445fca074fdf94707681d93e92ec0993bbd (patch) | |
tree | 308ad534d0593808982294563d7f3eb6c13bf938 | |
parent | 94b2f64ae735b85e7b7c42a76b5456dd09e00b2b (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.
Reviewed-by: Jacob Erlbeck <jerlbeck@sysmocom.de>
-rw-r--r-- | include/osmocom/gsm/gsm_utils.h | 1 | ||||
-rw-r--r-- | src/gsm/gsm_utils.c | 10 | ||||
-rw-r--r-- | src/gsm/libosmogsm.map | 1 | ||||
-rw-r--r-- | tests/sms/sms_test.c | 15 | ||||
-rw-r--r-- | tests/sms/sms_test.ok | 3 |
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 |