blob: 536c54d6572b0e9200ce611299e95957ee3d0eb2 [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.
Harald Welte07958e42019-05-03 09:39:10 +020027 */
28
29/* Decoded 8.2.3 Message Content */
30struct osmo_cbsp_content {
31 struct llist_head list;
32 uint8_t user_len;
33 uint8_t data[82];
34};
35
36/* Decoded Entry in a 8.2.6 Cell List */
37struct osmo_cbsp_cell_ent {
38 struct llist_head list; /* entry in osmo_cbsp_cell_list.list */
39 union gsm0808_cell_id_u cell_id;
40};
41struct osmo_cbsp_cell_list {
42 enum CELL_IDENT id_discr;
43 struct llist_head list; /* list of osmo_cbsp_cell_ent */
44};
45
46/* Decoded Entry in a 8.2.10 Completed List */
47struct osmo_cbsp_num_compl_ent {
48 struct llist_head list; /* entry in osmo_cbsp_num_compl_list.list */
49 union gsm0808_cell_id_u cell_id;
50 uint16_t num_compl;
51 uint8_t num_bcast_info;
52};
53struct osmo_cbsp_num_compl_list {
54 enum CELL_IDENT id_discr;
55 struct llist_head list; /* list of osmo_cbsp_num_compl_ent */
56};
57
58/* Decoded Entry in a 8.2.12 Radio Resource Loading List */
59struct osmo_cbsp_loading_ent {
60 struct llist_head list; /* entry in osmo_cbsp_loading_list */
61 union gsm0808_cell_id_u cell_id;
62 uint8_t load[2];
63};
64struct osmo_cbsp_loading_list {
65 enum CELL_IDENT id_discr;
66 struct llist_head list; /* list of osmo_cbsp_loading_ent */
67};
68
69/* Decoded Entry in a 8.2.11 Failure List */
70struct osmo_cbsp_fail_ent {
71 struct llist_head list; /* entry in a fail_list below */
72 enum CELL_IDENT id_discr;
73 union gsm0808_cell_id_u cell_id;
Pau Espin Pedrol0cdd0ab2022-06-09 18:13:39 +020074 uint8_t cause; /* enum osmo_cbsp_cause */
Harald Welte07958e42019-05-03 09:39:10 +020075};
76
77
78/* 8.1.3.1 */
79struct osmo_cbsp_write_replace {
80 uint16_t msg_id; /* 8.2.16 M */
81 uint16_t new_serial_nr; /* 8.2.5 M */
82 uint16_t *old_serial_nr; /* 8.2.4 */
83 struct osmo_cbsp_cell_list cell_list;
84
85 bool is_cbs;
86 union {
87 struct {
88 enum cbsp_channel_ind channel_ind;
89 enum cbsp_category category;
90 uint16_t rep_period;
91 uint16_t num_bcast_req;
92 /* num_of_pages implicit as llist_count(msg_content) */
93 uint8_t dcs;
94 struct llist_head msg_content;
95 } cbs;
96 struct {
97 uint8_t indicator;
98 uint16_t warning_type;
99 uint8_t warning_sec_info[50];
100 uint32_t warning_period; /* in seconds; 0xffffffff = unlimited */
101 } emergency;
102 } u;
103};
104
105/* 8.1.3.2 */
106struct osmo_cbsp_write_replace_complete {
107 uint16_t msg_id;
108 uint16_t new_serial_nr;
109 uint16_t *old_serial_nr;
110 struct osmo_cbsp_num_compl_list num_compl_list;
111 struct osmo_cbsp_cell_list cell_list;
112 enum cbsp_channel_ind *channel_ind;
113};
114
115/* 8.1.3.3 */
116struct osmo_cbsp_write_replace_failure {
117 uint16_t msg_id;
118 uint16_t new_serial_nr;
119 uint16_t *old_serial_nr;
120 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
121 struct osmo_cbsp_num_compl_list num_compl_list;
122 struct osmo_cbsp_cell_list cell_list;
123 enum cbsp_channel_ind *channel_ind;
124};
125
126/* 8.1.3.4 */
127struct osmo_cbsp_kill {
128 uint16_t msg_id;
129 uint16_t old_serial_nr;
130 struct osmo_cbsp_cell_list cell_list;
131 enum cbsp_channel_ind *channel_ind;
132};
133
134/* 8.1.3.5 */
135struct osmo_cbsp_kill_complete {
136 uint16_t msg_id;
137 uint16_t old_serial_nr;
138 struct osmo_cbsp_num_compl_list num_compl_list;
139 struct osmo_cbsp_cell_list cell_list;
140 enum cbsp_channel_ind *channel_ind;
141};
142
143/* 8.1.3.6 */
144struct osmo_cbsp_kill_failure {
145 uint16_t msg_id;
146 uint16_t old_serial_nr;
147 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
148 struct osmo_cbsp_num_compl_list num_compl_list;
149 struct osmo_cbsp_cell_list cell_list;
150 enum cbsp_channel_ind *channel_ind;
151};
152
153/* 8.1.3.7 */
154struct osmo_cbsp_load_query {
155 struct osmo_cbsp_cell_list cell_list;
156 enum cbsp_channel_ind channel_ind;
157};
158
159/* 8.1.3.8 */
160struct osmo_cbsp_load_query_complete {
161 struct osmo_cbsp_loading_list loading_list;
162 enum cbsp_channel_ind channel_ind;
163};
164
165/* 8.1.3.9 */
166struct osmo_cbsp_load_query_failure {
167 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
168 enum cbsp_channel_ind channel_ind;
169 struct osmo_cbsp_loading_list loading_list;
170};
171
172/* 8.1.3.10 */
173struct osmo_cbsp_msg_status_query {
174 uint16_t msg_id;
175 uint16_t old_serial_nr;
176 struct osmo_cbsp_cell_list cell_list;
177 enum cbsp_channel_ind channel_ind;
178};
179
180/* 8.1.3.11 */
181struct osmo_cbsp_msg_status_query_complete {
182 uint16_t msg_id;
183 uint16_t old_serial_nr;
184 struct osmo_cbsp_num_compl_list num_compl_list;
185 enum cbsp_channel_ind channel_ind;
186};
187
188/* 8.1.3.12 */
189struct osmo_cbsp_msg_status_query_failure {
190 uint16_t msg_id;
191 uint16_t old_serial_nr;
192 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
193 enum cbsp_channel_ind channel_ind;
194 struct osmo_cbsp_num_compl_list num_compl_list;
195};
196
197/* 8.1.3.16 */
198struct osmo_cbsp_reset {
199 struct osmo_cbsp_cell_list cell_list;
200};
201
202/* 8.1.3.17 */
203struct osmo_cbsp_reset_complete {
204 struct osmo_cbsp_cell_list cell_list;
205};
206
207/* 8.1.3.18 */
208struct osmo_cbsp_reset_failure {
209 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
210 struct osmo_cbsp_cell_list cell_list;
211};
212
213/* 8.1.3.18a */
214struct osmo_cbsp_keep_alive {
215 uint8_t repetition_period;
216};
217
218/* 8.1.3.18b */
219struct osmo_cbsp_keep_alive_complete {
220};
221
222/* 8.1.3.19 */
223struct osmo_cbsp_restart {
224 struct osmo_cbsp_cell_list cell_list;
225 uint8_t bcast_msg_type;
226 uint8_t recovery_ind;
227};
228
229/* 8.1.3.20 */
230struct osmo_cbsp_failure {
231 struct llist_head fail_list; /* list of osmo_cbsp_fail_ent */
232 uint8_t bcast_msg_type;
233};
234
235/* 8.1.3.21 */
236struct osmo_cbsp_error_ind {
237 enum cbsp_cell_id_cause cause;
238 uint16_t *msg_id;
239 uint16_t *new_serial_nr;
240 uint16_t *old_serial_nr;
241 enum cbsp_channel_ind *channel_ind;
242};
243
Pau Espin Pedrol0cdd0ab2022-06-09 18:13:39 +0200244/* 8.2.13 Cause */
245enum osmo_cbsp_cause {
246 OSMO_CBSP_CAUSE_PARAM_NOT_RECOGNISED = 0,
247 OSMO_CBSP_CAUSE_PARAM_VALUE_INVALID,
248 OSMO_CBSP_CAUSE_MSG_REF_NOT_IDENTIFIED,
249 OSMO_CBSP_CAUSE_CELL_ID_NOT_VALID,
250 OSMO_CBSP_CAUSE_UNRECOGNISED_MESSAGE,
251 OSMO_CBSP_CAUSE_MISSING_MANDATORY_ELEMENT,
252 OSMO_CBSP_CAUSE_BSC_CAPACITY_EXCEEDED,
253 OSMO_CBSP_CAUSE_CELL_MEMORY_EXCEEDED,
254 OSMO_CBSP_CAUSE_BSC_MEMORY_EXCEEDED,
255 OSMO_CBSP_CAUSE_CELL_BROADCAST_NOT_SUPPORTED,
256 OSMO_CBSP_CAUSE_CELL_BROADCAST_NOT_OPERATIONAL,
257 OSMO_CBSP_CAUSE_INCOMPATIBLE_DRX_PARAM,
258 OSMO_CBSP_CAUSE_EXT_CHAN_NOT_SUPPORTED,
259 OSMO_CBSP_CAUSE_MSG_REF_ALREADY_USED,
260 OSMO_CBSP_CAUSE_UNSPECIFIED_ERROR,
261 OSMO_CBSP_CAUSE_LAI_OR_LAC_NOT_VALID,
262};
263extern const struct value_string osmo_cbsp_cause_names[];
264static inline const char *osmo_cbsp_cause_name(enum osmo_cbsp_cause cause)
265{
266 return get_value_string(osmo_cbsp_cause_names, cause);
267}
Harald Welte07958e42019-05-03 09:39:10 +0200268
269/* decoded CBSP message */
270struct osmo_cbsp_decoded {
271 enum cbsp_msg_type msg_type;
272 union {
273 struct osmo_cbsp_write_replace write_replace;
274 struct osmo_cbsp_write_replace_complete write_replace_compl;
275 struct osmo_cbsp_write_replace_failure write_replace_fail;
276
277 struct osmo_cbsp_kill kill;
278 struct osmo_cbsp_kill_complete kill_compl;
279 struct osmo_cbsp_kill_failure kill_fail;
280
281 struct osmo_cbsp_load_query load_query;
282 struct osmo_cbsp_load_query_complete load_query_compl;
283 struct osmo_cbsp_load_query_failure load_query_fail;
284
285 struct osmo_cbsp_msg_status_query msg_status_query;
286 struct osmo_cbsp_msg_status_query_complete msg_status_query_compl;
287 struct osmo_cbsp_msg_status_query_failure msg_status_query_fail;
288
289 /* TODO: set DRX */
290
291 struct osmo_cbsp_reset reset;
292 struct osmo_cbsp_reset_complete reset_compl;
293 struct osmo_cbsp_reset_failure reset_fail;
294
295 struct osmo_cbsp_restart restart;
296
297 struct osmo_cbsp_failure failure;
298
299 struct osmo_cbsp_error_ind error_ind;
300
301 struct osmo_cbsp_keep_alive keep_alive;
302 struct osmo_cbsp_keep_alive_complete keep_alive_compl;
303 } u;
304};
305
Eric573f2fa2023-01-09 17:48:15 +0100306extern __thread const char *osmo_cbsp_errstr;
Harald Weltef72155a2019-06-15 23:05:19 +0200307
Harald Welte07958e42019-05-03 09:39:10 +0200308struct msgb *osmo_cbsp_msgb_alloc(void *ctx, const char *name);
309struct msgb *osmo_cbsp_encode(void *ctx, const struct osmo_cbsp_decoded *in);
310struct osmo_cbsp_decoded *osmo_cbsp_decode(void *ctx, struct msgb *in);
311void osmo_cbsp_init_struct(struct osmo_cbsp_decoded *cbsp, enum cbsp_msg_type msg_type);
312struct osmo_cbsp_decoded *osmo_cbsp_decoded_alloc(void *ctx, enum cbsp_msg_type msg_type);
313
314int osmo_cbsp_recv_buffered(void *ctx, int fd, struct msgb **rmsg, struct msgb **tmp_msg);