blob: 966a00fd30b1ce735839c11b8de05941677b8705 [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 *
Harald Welte783d0732014-12-29 17:09:11 +010015 */
16
17#include <string.h>
18#include <stdio.h>
19#include <stdlib.h>
Holger Hans Peter Freytherfdb46672015-11-09 16:32:43 +000020#include <time.h>
Harald Welte783d0732014-12-29 17:09:11 +010021
22#include <osmocom/gsm/protocol/gsm_03_41.h>
23#include <osmocom/gsm/gsm0341.h>
24#include <osmocom/gsm/gsm_utils.h>
25#include <osmocom/core/utils.h>
26#include <osmocom/core/msgb.h>
27
Pau Espin Pedrol061f96d2022-08-05 13:46:44 +020028struct gsm341_ms_message *gen_msg_from_text(uint16_t msg_id, uint8_t msg_code, const char *text)
Harald Welte783d0732014-12-29 17:09:11 +010029{
30 struct gsm341_ms_message *cbmsg;
31 int text_len = strlen(text);
32 /* assuming default GSM alphabet, the encoded payload cannot be
33 * longer than the input text */
34 uint8_t payload[text_len];
35 int payload_octets;
36
Pau Espin Pedrol061f96d2022-08-05 13:46:44 +020037 //srand(time(NULL));
Harald Welte65f676d2014-12-30 00:43:39 +010038
Harald Welte783d0732014-12-29 17:09:11 +010039 gsm_7bit_encode_n(payload, sizeof(payload), text, &payload_octets);
Harald Welte65f676d2014-12-30 00:43:39 +010040 //cbmsg = gsm0341_build_msg(NULL, 0, rand(), 0, msg_id, 0x0f, 1, 1, payload, payload_octets);
Pau Espin Pedrol061f96d2022-08-05 13:46:44 +020041 cbmsg = gsm0341_build_msg(NULL, 0, msg_code, 0, msg_id, 0x00, 1, 1, payload, payload_octets);
Harald Welte783d0732014-12-29 17:09:11 +010042
43 printf("%s\n", osmo_hexdump_nospc((uint8_t *)cbmsg, sizeof(*cbmsg)+payload_octets));
44
45 return cbmsg;
46}
47
48int main(int argc, char **argv)
49{
50 uint16_t msg_id = GSM341_MSGID_ETWS_CMAS_MONTHLY_TEST;
51 char *text = "Mahlzeit!";
Harald Weltec993a072014-12-30 13:22:56 +010052 char tbuf[GSM341_MAX_CHARS+1];
Pau Espin Pedrol061f96d2022-08-05 13:46:44 +020053 struct gsm341_ms_message *cbmsg;
Harald Welte783d0732014-12-29 17:09:11 +010054
55 if (argc > 1)
56 msg_id = atoi(argv[1]);
57
58 if (argc > 2)
59 text = argv[2];
60
Harald Weltec993a072014-12-30 13:22:56 +010061 strncpy(tbuf, text, GSM341_MAX_CHARS);
62 if (strlen(text) < GSM341_MAX_CHARS)
Harald Weltec13cf8b2014-12-30 13:25:44 +010063 memset(tbuf+strlen(text), GSM341_7BIT_PADDING,
64 sizeof(tbuf)-strlen(text));
65 tbuf[GSM341_MAX_CHARS] = 0;
Daniel Willmannf6261232014-12-30 12:07:17 +010066
Pau Espin Pedrol061f96d2022-08-05 13:46:44 +020067 cbmsg = gen_msg_from_text(msg_id, 1, tbuf);
68 talloc_free(cbmsg);
Harald Welte783d0732014-12-29 17:09:11 +010069
70 return EXIT_SUCCESS;
71}