blob: cc773824b48ddb4aefa8fec65dee91551e75a504 [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 *
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 Welte63b156a2014-12-30 00:43:32 +010026#include <arpa/inet.h>
27
Harald Welte783d0732014-12-29 17:09:11 +010028#include <osmocom/core/talloc.h>
29#include <osmocom/gsm/protocol/gsm_03_41.h>
30
31struct gsm341_ms_message *
32gsm0341_build_msg(void *ctx, uint8_t geo_scope, uint8_t msg_code,
33 uint8_t update, uint16_t msg_id, uint8_t dcs,
34 uint8_t page_total, uint8_t page_cur,
35 uint8_t *data, uint8_t len)
36{
37 struct gsm341_ms_message *cbmsg;
38
Harald Welte63b156a2014-12-30 00:43:32 +010039 msg_id = htons(msg_id);
40
Harald Welte783d0732014-12-29 17:09:11 +010041 if (len > 88)
42 return NULL;
43
44 cbmsg = talloc_zero_size(ctx, sizeof(*cbmsg)+len);
45 if (!cbmsg)
46 return NULL;
47
48 cbmsg->serial.code_hi = (msg_code >> 4) & 0xF;
49 cbmsg->serial.gs = geo_scope;
50 cbmsg->serial.update = update;
51 cbmsg->serial.code_lo = msg_code & 0xF;
52 cbmsg->msg_id = msg_id;
53 cbmsg->dcs.group = dcs >> 4;
54 cbmsg->dcs.language = dcs & 0xF;
55 cbmsg->page.total = page_total;
56 cbmsg->page.current = page_cur;
57 memcpy(cbmsg->data, data, len);
58
59 return cbmsg;
60}