Harald Welte | 783d073 | 2014-12-29 17:09:11 +0100 | [diff] [blame^] | 1 | /* |
| 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 | |
| 31 | struct 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 | |
| 40 | gsm_7bit_encode_n(payload, sizeof(payload), text, &payload_octets); |
| 41 | cbmsg = gsm0341_build_msg(NULL, 0, 23, 0, msg_id, 0xf0, 1, 1, payload, payload_octets); |
| 42 | |
| 43 | printf("%s\n", osmo_hexdump_nospc((uint8_t *)cbmsg, sizeof(*cbmsg)+payload_octets)); |
| 44 | |
| 45 | return cbmsg; |
| 46 | } |
| 47 | |
| 48 | int main(int argc, char **argv) |
| 49 | { |
| 50 | uint16_t msg_id = GSM341_MSGID_ETWS_CMAS_MONTHLY_TEST; |
| 51 | char *text = "Mahlzeit!"; |
| 52 | |
| 53 | if (argc > 1) |
| 54 | msg_id = atoi(argv[1]); |
| 55 | |
| 56 | if (argc > 2) |
| 57 | text = argv[2]; |
| 58 | |
| 59 | gen_msg_from_text(msg_id, text); |
| 60 | |
| 61 | return EXIT_SUCCESS; |
| 62 | } |