blob: c400f5c883745131b7afc75a10a16930e93dc3b5 [file] [log] [blame]
Harald Welte783d0732014-12-29 17:09:11 +01001/*
2 * (C) 2014 by Harald Welte <laforge@gnumonks.org>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <string.h>
22#include <stdio.h>
23#include <stdlib.h>
Holger Hans Peter Freytherfdb46672015-11-09 16:32:43 +000024#include <time.h>
Harald Welte783d0732014-12-29 17:09:11 +010025
26#include <osmocom/gsm/protocol/gsm_03_41.h>
27#include <osmocom/gsm/gsm0341.h>
28#include <osmocom/gsm/gsm_utils.h>
29#include <osmocom/core/utils.h>
30#include <osmocom/core/msgb.h>
31
32struct gsm341_ms_message *gen_msg_from_text(uint16_t msg_id, const char *text)
33{
34 struct gsm341_ms_message *cbmsg;
35 int text_len = strlen(text);
36 /* assuming default GSM alphabet, the encoded payload cannot be
37 * longer than the input text */
38 uint8_t payload[text_len];
39 int payload_octets;
40
Harald Welte65f676d2014-12-30 00:43:39 +010041 srand(time(NULL));
42
Harald Welte783d0732014-12-29 17:09:11 +010043 gsm_7bit_encode_n(payload, sizeof(payload), text, &payload_octets);
Harald Welte65f676d2014-12-30 00:43:39 +010044 //cbmsg = gsm0341_build_msg(NULL, 0, rand(), 0, msg_id, 0x0f, 1, 1, payload, payload_octets);
45 cbmsg = gsm0341_build_msg(NULL, 0, rand(), 0, msg_id, 0x00, 1, 1, payload, payload_octets);
Harald Welte783d0732014-12-29 17:09:11 +010046
47 printf("%s\n", osmo_hexdump_nospc((uint8_t *)cbmsg, sizeof(*cbmsg)+payload_octets));
48
49 return cbmsg;
50}
51
52int main(int argc, char **argv)
53{
54 uint16_t msg_id = GSM341_MSGID_ETWS_CMAS_MONTHLY_TEST;
55 char *text = "Mahlzeit!";
Harald Weltec993a072014-12-30 13:22:56 +010056 char tbuf[GSM341_MAX_CHARS+1];
Harald Welte783d0732014-12-29 17:09:11 +010057
58 if (argc > 1)
59 msg_id = atoi(argv[1]);
60
61 if (argc > 2)
62 text = argv[2];
63
Harald Weltec993a072014-12-30 13:22:56 +010064 strncpy(tbuf, text, GSM341_MAX_CHARS);
65 if (strlen(text) < GSM341_MAX_CHARS)
Harald Weltec13cf8b2014-12-30 13:25:44 +010066 memset(tbuf+strlen(text), GSM341_7BIT_PADDING,
67 sizeof(tbuf)-strlen(text));
68 tbuf[GSM341_MAX_CHARS] = 0;
Daniel Willmannf6261232014-12-30 12:07:17 +010069
70 gen_msg_from_text(msg_id, tbuf);
Harald Welte783d0732014-12-29 17:09:11 +010071
72 return EXIT_SUCCESS;
73}