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 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | * |
Harald Welte | 783d073 | 2014-12-29 17:09:11 +0100 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
Harald Welte | 783d073 | 2014-12-29 17:09:11 +0100 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 24 | #include <osmocom/core/byteswap.h> |
Harald Welte | 783d073 | 2014-12-29 17:09:11 +0100 | [diff] [blame] | 25 | #include <osmocom/core/talloc.h> |
| 26 | #include <osmocom/gsm/protocol/gsm_03_41.h> |
| 27 | |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 28 | /*! \addtogroup sms |
| 29 | * @{ |
Harald Welte | 55d724a | 2017-10-16 18:25:45 +0200 | [diff] [blame] | 30 | * \file gsm0341.c |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 31 | */ |
| 32 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 33 | /*! Encode a 3GPP TS 03.41 SMS-CB message |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 34 | * \param[in] ctx talloc allocation context |
| 35 | * \param[in] geo_scope Geographic Scope |
| 36 | * \param[in] msg_code Message Code |
| 37 | * \param[in] update Is this an update? |
| 38 | * \param[in] msg_id Message ID |
| 39 | * \param[in] dcs Data Coding Scheme |
| 40 | * \param[in] page_total Total number of pages |
| 41 | * \param[in] page_cur Current Page (up to \a page_total) |
| 42 | * \param[in] data Message data (copied 1:1) |
| 43 | * \param[in] len Length of \a data in bytes (up to 88) |
| 44 | * \returns callee-allocated TS 03.41 message with encoded data */ |
Harald Welte | 783d073 | 2014-12-29 17:09:11 +0100 | [diff] [blame] | 45 | struct gsm341_ms_message * |
| 46 | gsm0341_build_msg(void *ctx, uint8_t geo_scope, uint8_t msg_code, |
| 47 | uint8_t update, uint16_t msg_id, uint8_t dcs, |
| 48 | uint8_t page_total, uint8_t page_cur, |
| 49 | uint8_t *data, uint8_t len) |
| 50 | { |
| 51 | struct gsm341_ms_message *cbmsg; |
| 52 | |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 53 | msg_id = osmo_htons(msg_id); |
Harald Welte | 63b156a | 2014-12-30 00:43:32 +0100 | [diff] [blame] | 54 | |
Harald Welte | 783d073 | 2014-12-29 17:09:11 +0100 | [diff] [blame] | 55 | if (len > 88) |
| 56 | return NULL; |
| 57 | |
| 58 | cbmsg = talloc_zero_size(ctx, sizeof(*cbmsg)+len); |
| 59 | if (!cbmsg) |
| 60 | return NULL; |
| 61 | |
| 62 | cbmsg->serial.code_hi = (msg_code >> 4) & 0xF; |
| 63 | cbmsg->serial.gs = geo_scope; |
| 64 | cbmsg->serial.update = update; |
| 65 | cbmsg->serial.code_lo = msg_code & 0xF; |
| 66 | cbmsg->msg_id = msg_id; |
| 67 | cbmsg->dcs.group = dcs >> 4; |
| 68 | cbmsg->dcs.language = dcs & 0xF; |
| 69 | cbmsg->page.total = page_total; |
| 70 | cbmsg->page.current = page_cur; |
| 71 | memcpy(cbmsg->data, data, len); |
| 72 | |
| 73 | return cbmsg; |
| 74 | } |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 75 | |
| 76 | /*! @} */ |