blob: d456ce2f7b298cc5758abd7d7c3fdef8389c01b3 [file] [log] [blame]
Harald Welte07958e42019-05-03 09:39:10 +02001#pragma once
2
3#include <stdint.h>
4#include <osmocom/core/linuxlist.h>
5#include <osmocom/gsm/protocol/gsm_48_049.h>
6#include <osmocom/gsm/gsm0808_utils.h>
7
8/* Definitions for parsed / abstract representation of messages in the
Neels Hofmeyrb19b5332020-08-25 13:34:04 +02009 * CBSP (Cell Broadcast Service Protocol, 3GPP TS 48.049). Data here is *not* formatted
Neels Hofmeyr1cbdee32020-08-25 13:34:39 +020010 * like the on-the-wire format. Any similarities are coincidential ;) */
Harald Welte07958e42019-05-03 09:39:10 +020011
12/* Copyright (C) 2019 Harald Welte <laforge@gnumonks.org>
13 *
14 * All Rights Reserved
15 *
16 * SPDX-License-Identifier: GPL-2.0+
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 */
32
33/* Decoded 8.2.3 Message Content */
34struct osmo_cbsp_content {
35 struct llist_head list;
36 uint8_t user_len;
37 uint8_t data[82];
38};
39
40/* Decoded Entry in a 8.2.6 Cell List */
41struct osmo_cbsp_cell_ent {
42 struct llist_head list; /* entry in osmo_cbsp_cell_list.list */
43 union gsm0808_cell_id_u cell_id;
44};
45struct osmo_cbsp_cell_list {
46 enum CELL_IDENT id_discr;
47 struct llist_head list; /* list of osmo_cbsp_cell_ent */
48};
49
50/* Decoded Entry in a 8.2.10 Completed List */
51struct osmo_cbsp_num_compl_ent {
52 struct llist_head list; /* entry in osmo_cbsp_num_compl_list.list */
53 union gsm0808_cell_id_u cell_id;
54 uint16_t num_compl;
55 uint8_t num_bcast_info;
56};
57struct osmo_cbsp_num_compl_list {
58 enum CELL_IDENT id_discr;
59 struct llist_head list; /* list of osmo_cbsp_num_compl_ent */
60};
61
62/* Decoded Entry in a 8.2.12 Radio Resource Loading List */
63struct osmo_cbsp_loading_ent {
64 struct llist_head list; /* entry in osmo_cbsp_loading_list */
65 union gsm0808_cell_id_u cell_id;
66 uint8_t load[2];
67};
68struct osmo_cbsp_loading_list {
69 enum CELL_IDENT id_discr;
70 struct llist_head list; /* list of osmo_cbsp_loading_ent */
71};
72
73/* Decoded Entry in a 8.2.11 Failure List */
74struct osmo_cbsp_fail_ent {
75 struct llist_head list; /* entry in a fail_list below */
76 enum CELL_IDENT id_discr;
77 union gsm0808_cell_id_u cell_id;
78 uint8_t cause;
79};
80
81
82/* 8.1.3.1 */
83struct osmo_cbsp_write_replace {
84 uint16_t msg_id; /* 8.2.16 M */
85 uint16_t new_serial_nr; /* 8.2.5 M */
86 uint16_t *old_serial_nr; /* 8.2.4 */
87 struct osmo_cbsp_cell_list cell_list;
88
89 bool is_cbs;
90 union {
91 struct {
92 enum cbsp_channel_ind channel_ind;
93 enum cbsp_category category;
94 uint16_t rep_period;
95 uint16_t num_bcast_req;
96 /* num_of_pages implicit as llist_count(msg_content) */
97 uint8_t dcs;
98 struct llist_head msg_content;
99 } cbs;
100 struct {
101 uint8_t indicator;
102 uint16_t warning_type;
103 uint8_t warning_sec_info[50];
104 uint32_t warning_period; /* in seconds; 0xffffffff = unlimited */
105 } emergency;
106 } u;
107};
108
109/* 8.1.3.2 */
110struct osmo_cbsp_write_replace_complete {
111 uint16_t msg_id;
112 uint16_t new_serial_nr;
113 uint16_t *old_serial_nr;
114 struct osmo_cbsp_num_compl_list num_compl_list;
115 struct osmo_cbsp_cell_list cell_list;
116 enum cbsp_channel_ind *channel_ind;
117};
118
119/* 8.1.3.3 */
120struct osmo_cbsp_write_replace_failure {
121 uint16_t msg_id;
122 uint16_t new_serial_nr;
123 uint16_t *old_serial_nr;
124 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
125 struct osmo_cbsp_num_compl_list num_compl_list;
126 struct osmo_cbsp_cell_list cell_list;
127 enum cbsp_channel_ind *channel_ind;
128};
129
130/* 8.1.3.4 */
131struct osmo_cbsp_kill {
132 uint16_t msg_id;
133 uint16_t old_serial_nr;
134 struct osmo_cbsp_cell_list cell_list;
135 enum cbsp_channel_ind *channel_ind;
136};
137
138/* 8.1.3.5 */
139struct osmo_cbsp_kill_complete {
140 uint16_t msg_id;
141 uint16_t old_serial_nr;
142 struct osmo_cbsp_num_compl_list num_compl_list;
143 struct osmo_cbsp_cell_list cell_list;
144 enum cbsp_channel_ind *channel_ind;
145};
146
147/* 8.1.3.6 */
148struct osmo_cbsp_kill_failure {
149 uint16_t msg_id;
150 uint16_t old_serial_nr;
151 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
152 struct osmo_cbsp_num_compl_list num_compl_list;
153 struct osmo_cbsp_cell_list cell_list;
154 enum cbsp_channel_ind *channel_ind;
155};
156
157/* 8.1.3.7 */
158struct osmo_cbsp_load_query {
159 struct osmo_cbsp_cell_list cell_list;
160 enum cbsp_channel_ind channel_ind;
161};
162
163/* 8.1.3.8 */
164struct osmo_cbsp_load_query_complete {
165 struct osmo_cbsp_loading_list loading_list;
166 enum cbsp_channel_ind channel_ind;
167};
168
169/* 8.1.3.9 */
170struct osmo_cbsp_load_query_failure {
171 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
172 enum cbsp_channel_ind channel_ind;
173 struct osmo_cbsp_loading_list loading_list;
174};
175
176/* 8.1.3.10 */
177struct osmo_cbsp_msg_status_query {
178 uint16_t msg_id;
179 uint16_t old_serial_nr;
180 struct osmo_cbsp_cell_list cell_list;
181 enum cbsp_channel_ind channel_ind;
182};
183
184/* 8.1.3.11 */
185struct osmo_cbsp_msg_status_query_complete {
186 uint16_t msg_id;
187 uint16_t old_serial_nr;
188 struct osmo_cbsp_num_compl_list num_compl_list;
189 enum cbsp_channel_ind channel_ind;
190};
191
192/* 8.1.3.12 */
193struct osmo_cbsp_msg_status_query_failure {
194 uint16_t msg_id;
195 uint16_t old_serial_nr;
196 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
197 enum cbsp_channel_ind channel_ind;
198 struct osmo_cbsp_num_compl_list num_compl_list;
199};
200
201/* 8.1.3.16 */
202struct osmo_cbsp_reset {
203 struct osmo_cbsp_cell_list cell_list;
204};
205
206/* 8.1.3.17 */
207struct osmo_cbsp_reset_complete {
208 struct osmo_cbsp_cell_list cell_list;
209};
210
211/* 8.1.3.18 */
212struct osmo_cbsp_reset_failure {
213 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
214 struct osmo_cbsp_cell_list cell_list;
215};
216
217/* 8.1.3.18a */
218struct osmo_cbsp_keep_alive {
219 uint8_t repetition_period;
220};
221
222/* 8.1.3.18b */
223struct osmo_cbsp_keep_alive_complete {
224};
225
226/* 8.1.3.19 */
227struct osmo_cbsp_restart {
228 struct osmo_cbsp_cell_list cell_list;
229 uint8_t bcast_msg_type;
230 uint8_t recovery_ind;
231};
232
233/* 8.1.3.20 */
234struct osmo_cbsp_failure {
235 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
236 uint8_t bcast_msg_type;
237};
238
239/* 8.1.3.21 */
240struct osmo_cbsp_error_ind {
241 enum cbsp_cell_id_cause cause;
242 uint16_t *msg_id;
243 uint16_t *new_serial_nr;
244 uint16_t *old_serial_nr;
245 enum cbsp_channel_ind *channel_ind;
246};
247
248
249/* decoded CBSP message */
250struct osmo_cbsp_decoded {
251 enum cbsp_msg_type msg_type;
252 union {
253 struct osmo_cbsp_write_replace write_replace;
254 struct osmo_cbsp_write_replace_complete write_replace_compl;
255 struct osmo_cbsp_write_replace_failure write_replace_fail;
256
257 struct osmo_cbsp_kill kill;
258 struct osmo_cbsp_kill_complete kill_compl;
259 struct osmo_cbsp_kill_failure kill_fail;
260
261 struct osmo_cbsp_load_query load_query;
262 struct osmo_cbsp_load_query_complete load_query_compl;
263 struct osmo_cbsp_load_query_failure load_query_fail;
264
265 struct osmo_cbsp_msg_status_query msg_status_query;
266 struct osmo_cbsp_msg_status_query_complete msg_status_query_compl;
267 struct osmo_cbsp_msg_status_query_failure msg_status_query_fail;
268
269 /* TODO: set DRX */
270
271 struct osmo_cbsp_reset reset;
272 struct osmo_cbsp_reset_complete reset_compl;
273 struct osmo_cbsp_reset_failure reset_fail;
274
275 struct osmo_cbsp_restart restart;
276
277 struct osmo_cbsp_failure failure;
278
279 struct osmo_cbsp_error_ind error_ind;
280
281 struct osmo_cbsp_keep_alive keep_alive;
282 struct osmo_cbsp_keep_alive_complete keep_alive_compl;
283 } u;
284};
285
Harald Weltef72155a2019-06-15 23:05:19 +0200286extern const __thread char *osmo_cbsp_errstr;
287
Harald Welte07958e42019-05-03 09:39:10 +0200288struct msgb *osmo_cbsp_msgb_alloc(void *ctx, const char *name);
289struct msgb *osmo_cbsp_encode(void *ctx, const struct osmo_cbsp_decoded *in);
290struct osmo_cbsp_decoded *osmo_cbsp_decode(void *ctx, struct msgb *in);
291void osmo_cbsp_init_struct(struct osmo_cbsp_decoded *cbsp, enum cbsp_msg_type msg_type);
292struct osmo_cbsp_decoded *osmo_cbsp_decoded_alloc(void *ctx, enum cbsp_msg_type msg_type);
293
294int osmo_cbsp_recv_buffered(void *ctx, int fd, struct msgb **rmsg, struct msgb **tmp_msg);