blob: f7f6bc0261835b741e2383908a528b732e0b7b73 [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>
24
25#include <osmocom/gsm/protocol/gsm_03_41.h>
26#include <osmocom/gsm/gsm0341.h>
27#include <osmocom/gsm/gsm_utils.h>
28#include <osmocom/core/utils.h>
29#include <osmocom/core/msgb.h>
30
31struct gsm341_ms_message *gen_msg_from_text(uint16_t msg_id, const char *text)
32{
33 struct gsm341_ms_message *cbmsg;
34 int text_len = strlen(text);
35 /* assuming default GSM alphabet, the encoded payload cannot be
36 * longer than the input text */
37 uint8_t payload[text_len];
38 int payload_octets;
39
Harald Welte65f676d2014-12-30 00:43:39 +010040 srand(time(NULL));
41
Harald Welte783d0732014-12-29 17:09:11 +010042 gsm_7bit_encode_n(payload, sizeof(payload), text, &payload_octets);
Harald Welte65f676d2014-12-30 00:43:39 +010043 //cbmsg = gsm0341_build_msg(NULL, 0, rand(), 0, msg_id, 0x0f, 1, 1, payload, payload_octets);
44 cbmsg = gsm0341_build_msg(NULL, 0, rand(), 0, msg_id, 0x00, 1, 1, payload, payload_octets);
Harald Welte783d0732014-12-29 17:09:11 +010045
46 printf("%s\n", osmo_hexdump_nospc((uint8_t *)cbmsg, sizeof(*cbmsg)+payload_octets));
47
48 return cbmsg;
49}
50
51int main(int argc, char **argv)
52{
53 uint16_t msg_id = GSM341_MSGID_ETWS_CMAS_MONTHLY_TEST;
54 char *text = "Mahlzeit!";
Harald Weltec993a072014-12-30 13:22:56 +010055 char tbuf[GSM341_MAX_CHARS+1];
Harald Welte783d0732014-12-29 17:09:11 +010056
57 if (argc > 1)
58 msg_id = atoi(argv[1]);
59
60 if (argc > 2)
61 text = argv[2];
62
Harald Weltec993a072014-12-30 13:22:56 +010063 strncpy(tbuf, text, GSM341_MAX_CHARS);
64 if (strlen(text) < GSM341_MAX_CHARS)
Daniel Willmannf6261232014-12-30 12:07:17 +010065 memset(tbuf+strlen(text), '\r', sizeof(tbuf)-strlen(text));
66 tbuf[93] = 0;
67
68 gen_msg_from_text(msg_id, tbuf);
Harald Welte783d0732014-12-29 17:09:11 +010069
70 return EXIT_SUCCESS;
71}