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 | |
| 22 | #include <stdint.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 26 | #include <osmocom/core/byteswap.h> |
Harald Welte | 783d073 | 2014-12-29 17:09:11 +0100 | [diff] [blame] | 27 | #include <osmocom/core/talloc.h> |
| 28 | #include <osmocom/gsm/protocol/gsm_03_41.h> |
| 29 | |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 30 | /*! \addtogroup sms |
| 31 | * @{ |
| 32 | */ |
| 33 | |
| 34 | /*! \brief Encode a 3GPP TS 03.41 SMS-CB message |
| 35 | * \param[in] ctx talloc allocation context |
| 36 | * \param[in] geo_scope Geographic Scope |
| 37 | * \param[in] msg_code Message Code |
| 38 | * \param[in] update Is this an update? |
| 39 | * \param[in] msg_id Message ID |
| 40 | * \param[in] dcs Data Coding Scheme |
| 41 | * \param[in] page_total Total number of pages |
| 42 | * \param[in] page_cur Current Page (up to \a page_total) |
| 43 | * \param[in] data Message data (copied 1:1) |
| 44 | * \param[in] len Length of \a data in bytes (up to 88) |
| 45 | * \returns callee-allocated TS 03.41 message with encoded data */ |
Harald Welte | 783d073 | 2014-12-29 17:09:11 +0100 | [diff] [blame] | 46 | struct gsm341_ms_message * |
| 47 | gsm0341_build_msg(void *ctx, uint8_t geo_scope, uint8_t msg_code, |
| 48 | uint8_t update, uint16_t msg_id, uint8_t dcs, |
| 49 | uint8_t page_total, uint8_t page_cur, |
| 50 | uint8_t *data, uint8_t len) |
| 51 | { |
| 52 | struct gsm341_ms_message *cbmsg; |
| 53 | |
Harald Welte | 95871da | 2017-05-15 12:11:36 +0200 | [diff] [blame] | 54 | msg_id = osmo_htons(msg_id); |
Harald Welte | 63b156a | 2014-12-30 00:43:32 +0100 | [diff] [blame] | 55 | |
Harald Welte | 783d073 | 2014-12-29 17:09:11 +0100 | [diff] [blame] | 56 | if (len > 88) |
| 57 | return NULL; |
| 58 | |
| 59 | cbmsg = talloc_zero_size(ctx, sizeof(*cbmsg)+len); |
| 60 | if (!cbmsg) |
| 61 | return NULL; |
| 62 | |
| 63 | cbmsg->serial.code_hi = (msg_code >> 4) & 0xF; |
| 64 | cbmsg->serial.gs = geo_scope; |
| 65 | cbmsg->serial.update = update; |
| 66 | cbmsg->serial.code_lo = msg_code & 0xF; |
| 67 | cbmsg->msg_id = msg_id; |
| 68 | cbmsg->dcs.group = dcs >> 4; |
| 69 | cbmsg->dcs.language = dcs & 0xF; |
| 70 | cbmsg->page.total = page_total; |
| 71 | cbmsg->page.current = page_cur; |
| 72 | memcpy(cbmsg->data, data, len); |
| 73 | |
| 74 | return cbmsg; |
| 75 | } |
Harald Welte | 96e2a00 | 2017-06-12 21:44:18 +0200 | [diff] [blame] | 76 | |
| 77 | /*! @} */ |