Harald Welte | 07958e4 | 2019-05-03 09:39:10 +0200 | [diff] [blame] | 1 | #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 Hofmeyr | b19b533 | 2020-08-25 13:34:04 +0200 | [diff] [blame] | 9 | * CBSP (Cell Broadcast Service Protocol, 3GPP TS 48.049). Data here is *not* formatted |
Neels Hofmeyr | 1cbdee3 | 2020-08-25 13:34:39 +0200 | [diff] [blame] | 10 | * like the on-the-wire format. Any similarities are coincidential ;) */ |
Harald Welte | 07958e4 | 2019-05-03 09:39:10 +0200 | [diff] [blame] | 11 | |
| 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 Welte | 07958e4 | 2019-05-03 09:39:10 +0200 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | /* Decoded 8.2.3 Message Content */ |
| 30 | struct 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 */ |
| 37 | struct 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 | }; |
| 41 | struct 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 */ |
| 47 | struct 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 | }; |
| 53 | struct 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 */ |
| 59 | struct 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 | }; |
| 64 | struct 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 */ |
| 70 | struct 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; |
| 74 | uint8_t cause; |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | /* 8.1.3.1 */ |
| 79 | struct 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 */ |
| 106 | struct 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 */ |
| 116 | struct 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 */ |
| 127 | struct 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 */ |
| 135 | struct 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 */ |
| 144 | struct 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 */ |
| 154 | struct 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 */ |
| 160 | struct 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 */ |
| 166 | struct 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 */ |
| 173 | struct 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 */ |
| 181 | struct 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 */ |
| 189 | struct 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 */ |
| 198 | struct osmo_cbsp_reset { |
| 199 | struct osmo_cbsp_cell_list cell_list; |
| 200 | }; |
| 201 | |
| 202 | /* 8.1.3.17 */ |
| 203 | struct osmo_cbsp_reset_complete { |
| 204 | struct osmo_cbsp_cell_list cell_list; |
| 205 | }; |
| 206 | |
| 207 | /* 8.1.3.18 */ |
| 208 | struct 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 */ |
| 214 | struct osmo_cbsp_keep_alive { |
| 215 | uint8_t repetition_period; |
| 216 | }; |
| 217 | |
| 218 | /* 8.1.3.18b */ |
| 219 | struct osmo_cbsp_keep_alive_complete { |
| 220 | }; |
| 221 | |
| 222 | /* 8.1.3.19 */ |
| 223 | struct 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 */ |
| 230 | struct 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 */ |
| 236 | struct 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 | |
| 244 | |
| 245 | /* decoded CBSP message */ |
| 246 | struct osmo_cbsp_decoded { |
| 247 | enum cbsp_msg_type msg_type; |
| 248 | union { |
| 249 | struct osmo_cbsp_write_replace write_replace; |
| 250 | struct osmo_cbsp_write_replace_complete write_replace_compl; |
| 251 | struct osmo_cbsp_write_replace_failure write_replace_fail; |
| 252 | |
| 253 | struct osmo_cbsp_kill kill; |
| 254 | struct osmo_cbsp_kill_complete kill_compl; |
| 255 | struct osmo_cbsp_kill_failure kill_fail; |
| 256 | |
| 257 | struct osmo_cbsp_load_query load_query; |
| 258 | struct osmo_cbsp_load_query_complete load_query_compl; |
| 259 | struct osmo_cbsp_load_query_failure load_query_fail; |
| 260 | |
| 261 | struct osmo_cbsp_msg_status_query msg_status_query; |
| 262 | struct osmo_cbsp_msg_status_query_complete msg_status_query_compl; |
| 263 | struct osmo_cbsp_msg_status_query_failure msg_status_query_fail; |
| 264 | |
| 265 | /* TODO: set DRX */ |
| 266 | |
| 267 | struct osmo_cbsp_reset reset; |
| 268 | struct osmo_cbsp_reset_complete reset_compl; |
| 269 | struct osmo_cbsp_reset_failure reset_fail; |
| 270 | |
| 271 | struct osmo_cbsp_restart restart; |
| 272 | |
| 273 | struct osmo_cbsp_failure failure; |
| 274 | |
| 275 | struct osmo_cbsp_error_ind error_ind; |
| 276 | |
| 277 | struct osmo_cbsp_keep_alive keep_alive; |
| 278 | struct osmo_cbsp_keep_alive_complete keep_alive_compl; |
| 279 | } u; |
| 280 | }; |
| 281 | |
Harald Welte | f72155a | 2019-06-15 23:05:19 +0200 | [diff] [blame] | 282 | extern const __thread char *osmo_cbsp_errstr; |
| 283 | |
Harald Welte | 07958e4 | 2019-05-03 09:39:10 +0200 | [diff] [blame] | 284 | struct msgb *osmo_cbsp_msgb_alloc(void *ctx, const char *name); |
| 285 | struct msgb *osmo_cbsp_encode(void *ctx, const struct osmo_cbsp_decoded *in); |
| 286 | struct osmo_cbsp_decoded *osmo_cbsp_decode(void *ctx, struct msgb *in); |
| 287 | void osmo_cbsp_init_struct(struct osmo_cbsp_decoded *cbsp, enum cbsp_msg_type msg_type); |
| 288 | struct osmo_cbsp_decoded *osmo_cbsp_decoded_alloc(void *ctx, enum cbsp_msg_type msg_type); |
| 289 | |
| 290 | int osmo_cbsp_recv_buffered(void *ctx, int fd, struct msgb **rmsg, struct msgb **tmp_msg); |