blob: a6238b3619422909e17fa4cce348c51973effe94 [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 *
Harald Weltee08da972017-11-13 01:00:26 +09005 * SPDX-License-Identifier: GPL-2.0+
6 *
Harald Welte783d0732014-12-29 17:09:11 +01007 * 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 Welte783d0732014-12-29 17:09:11 +010017 */
18
19
20#include <stdint.h>
21#include <stdlib.h>
22#include <string.h>
23
Harald Welte95871da2017-05-15 12:11:36 +020024#include <osmocom/core/byteswap.h>
Harald Welte783d0732014-12-29 17:09:11 +010025#include <osmocom/core/talloc.h>
26#include <osmocom/gsm/protocol/gsm_03_41.h>
27
Harald Welte96e2a002017-06-12 21:44:18 +020028/*! \addtogroup sms
29 * @{
Harald Welte55d724a2017-10-16 18:25:45 +020030 * \file gsm0341.c
Harald Welte96e2a002017-06-12 21:44:18 +020031 */
32
Neels Hofmeyr87e45502017-06-20 00:17:59 +020033/*! Encode a 3GPP TS 03.41 SMS-CB message
Harald Welte96e2a002017-06-12 21:44:18 +020034 * \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 Welte783d0732014-12-29 17:09:11 +010045struct gsm341_ms_message *
46gsm0341_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 Welte95871da2017-05-15 12:11:36 +020053 msg_id = osmo_htons(msg_id);
Harald Welte63b156a2014-12-30 00:43:32 +010054
Harald Welte783d0732014-12-29 17:09:11 +010055 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 Welte96e2a002017-06-12 21:44:18 +020075
76/*! @} */