2014-12-29 16:09:11 +00:00
|
|
|
/*
|
|
|
|
* (C) 2014 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
2017-11-12 16:00:26 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*
|
2014-12-29 16:09:11 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-05-15 10:11:36 +00:00
|
|
|
#include <osmocom/core/byteswap.h>
|
2014-12-29 16:09:11 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
|
|
|
#include <osmocom/gsm/protocol/gsm_03_41.h>
|
|
|
|
|
2017-06-12 19:44:18 +00:00
|
|
|
/*! \addtogroup sms
|
|
|
|
* @{
|
2017-10-16 16:25:45 +00:00
|
|
|
* \file gsm0341.c
|
2017-06-12 19:44:18 +00:00
|
|
|
*/
|
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Encode a 3GPP TS 03.41 SMS-CB message
|
2017-06-12 19:44:18 +00:00
|
|
|
* \param[in] ctx talloc allocation context
|
|
|
|
* \param[in] geo_scope Geographic Scope
|
|
|
|
* \param[in] msg_code Message Code
|
|
|
|
* \param[in] update Is this an update?
|
|
|
|
* \param[in] msg_id Message ID
|
|
|
|
* \param[in] dcs Data Coding Scheme
|
|
|
|
* \param[in] page_total Total number of pages
|
|
|
|
* \param[in] page_cur Current Page (up to \a page_total)
|
|
|
|
* \param[in] data Message data (copied 1:1)
|
|
|
|
* \param[in] len Length of \a data in bytes (up to 88)
|
|
|
|
* \returns callee-allocated TS 03.41 message with encoded data */
|
2014-12-29 16:09:11 +00:00
|
|
|
struct gsm341_ms_message *
|
|
|
|
gsm0341_build_msg(void *ctx, uint8_t geo_scope, uint8_t msg_code,
|
|
|
|
uint8_t update, uint16_t msg_id, uint8_t dcs,
|
|
|
|
uint8_t page_total, uint8_t page_cur,
|
|
|
|
uint8_t *data, uint8_t len)
|
|
|
|
{
|
|
|
|
struct gsm341_ms_message *cbmsg;
|
|
|
|
|
2017-05-15 10:11:36 +00:00
|
|
|
msg_id = osmo_htons(msg_id);
|
2014-12-29 23:43:32 +00:00
|
|
|
|
2014-12-29 16:09:11 +00:00
|
|
|
if (len > 88)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cbmsg = talloc_zero_size(ctx, sizeof(*cbmsg)+len);
|
|
|
|
if (!cbmsg)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cbmsg->serial.code_hi = (msg_code >> 4) & 0xF;
|
|
|
|
cbmsg->serial.gs = geo_scope;
|
|
|
|
cbmsg->serial.update = update;
|
|
|
|
cbmsg->serial.code_lo = msg_code & 0xF;
|
|
|
|
cbmsg->msg_id = msg_id;
|
|
|
|
cbmsg->dcs.group = dcs >> 4;
|
|
|
|
cbmsg->dcs.language = dcs & 0xF;
|
|
|
|
cbmsg->page.total = page_total;
|
|
|
|
cbmsg->page.current = page_cur;
|
|
|
|
memcpy(cbmsg->data, data, len);
|
|
|
|
|
|
|
|
return cbmsg;
|
|
|
|
}
|
2017-06-12 19:44:18 +00:00
|
|
|
|
|
|
|
/*! @} */
|