summaryrefslogtreecommitdiffstats
path: root/tests/smscb
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2014-12-29 17:09:11 +0100
committerHarald Welte <laforge@gnumonks.org>2014-12-29 17:09:11 +0100
commit783d073a370191cdb9cba0f205ded50459663500 (patch)
tree4a439940c51f54ad69852b471594b98deb598482 /tests/smscb
parenta19717a7c50dededf0c8ec8ccb347c1c5d019382 (diff)
add gsm0341_test to generate SMSCB hex strings
Those hex strings can then be copy+pasted into the OSmoNITB VTY
Diffstat (limited to 'tests/smscb')
-rw-r--r--tests/smscb/gsm0341_test.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/smscb/gsm0341_test.c b/tests/smscb/gsm0341_test.c
new file mode 100644
index 00000000..5b728899
--- /dev/null
+++ b/tests/smscb/gsm0341_test.c
@@ -0,0 +1,62 @@
+/*
+ * (C) 2014 by Harald Welte <laforge@gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <osmocom/gsm/protocol/gsm_03_41.h>
+#include <osmocom/gsm/gsm0341.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/msgb.h>
+
+struct gsm341_ms_message *gen_msg_from_text(uint16_t msg_id, const char *text)
+{
+ struct gsm341_ms_message *cbmsg;
+ int text_len = strlen(text);
+ /* assuming default GSM alphabet, the encoded payload cannot be
+ * longer than the input text */
+ uint8_t payload[text_len];
+ int payload_octets;
+
+ gsm_7bit_encode_n(payload, sizeof(payload), text, &payload_octets);
+ cbmsg = gsm0341_build_msg(NULL, 0, 23, 0, msg_id, 0xf0, 1, 1, payload, payload_octets);
+
+ printf("%s\n", osmo_hexdump_nospc((uint8_t *)cbmsg, sizeof(*cbmsg)+payload_octets));
+
+ return cbmsg;
+}
+
+int main(int argc, char **argv)
+{
+ uint16_t msg_id = GSM341_MSGID_ETWS_CMAS_MONTHLY_TEST;
+ char *text = "Mahlzeit!";
+
+ if (argc > 1)
+ msg_id = atoi(argv[1]);
+
+ if (argc > 2)
+ text = argv[2];
+
+ gen_msg_from_text(msg_id, text);
+
+ return EXIT_SUCCESS;
+}