Philipp Maier | 9828d28 | 2021-01-06 20:40:23 +0100 | [diff] [blame] | 1 | /*! \file gprs_bssgp.h |
| 2 | * GPRS BSSGP RIM protocol implementation as per 3GPP TS 48.018. */ |
| 3 | /* |
| 4 | * (C) 2020-2021 by sysmocom - s.f.m.c. GmbH |
| 5 | * Author: Philipp Maier <pmaier@sysmocom.de> |
| 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0+ |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
Pau Espin Pedrol | 445a366 | 2021-01-26 13:06:51 +0100 | [diff] [blame] | 28 | #include <osmocom/gsm/gsm48.h> |
Philipp Maier | 9828d28 | 2021-01-06 20:40:23 +0100 | [diff] [blame] | 29 | #include <osmocom/gprs/protocol/gsm_08_18.h> |
Pau Espin Pedrol | 445a366 | 2021-01-26 13:06:51 +0100 | [diff] [blame] | 30 | #include <osmocom/gprs/protocol/gsm_24_301.h> |
Philipp Maier | 9828d28 | 2021-01-06 20:40:23 +0100 | [diff] [blame] | 31 | |
Philipp Maier | 7450f77 | 2021-01-06 20:56:43 +0100 | [diff] [blame] | 32 | enum bssgp_rim_routing_info_discr { |
| 33 | BSSGP_RIM_ROUTING_INFO_GERAN, |
| 34 | BSSGP_RIM_ROUTING_INFO_UTRAN, |
| 35 | BSSGP_RIM_ROUTING_INFO_EUTRAN, |
| 36 | }; |
| 37 | |
Philipp Maier | cf11411 | 2021-01-22 18:24:12 +0100 | [diff] [blame] | 38 | extern const struct value_string bssgp_rim_routing_info_discr_strs[]; |
| 39 | |
| 40 | /*! Obtain a human-readable string for NACC Cause code */ |
| 41 | static inline const char *bssgp_rim_routing_info_discr_str(enum bssgp_rim_routing_info_discr val) |
| 42 | { return get_value_string(bssgp_rim_routing_info_discr_strs, val); } |
| 43 | |
Philipp Maier | 7450f77 | 2021-01-06 20:56:43 +0100 | [diff] [blame] | 44 | /*! BSSGP RIM Routing information, see also 3GPP TS 48.018, section 11.3.70 */ |
| 45 | struct bssgp_rim_routing_info { |
| 46 | enum bssgp_rim_routing_info_discr discr; |
| 47 | union { |
| 48 | struct { |
| 49 | struct gprs_ra_id raid; |
| 50 | uint16_t cid; |
| 51 | } geran; |
| 52 | struct { |
| 53 | struct gprs_ra_id raid; |
| 54 | uint16_t rncid; |
| 55 | } utran; |
| 56 | struct { |
| 57 | struct osmo_eutran_tai tai; |
| 58 | /* See also 3GPP TS 36.413 9.2.1.37 and 3GPP TS 36.401 */ |
| 59 | uint8_t global_enb_id[8]; |
| 60 | uint8_t global_enb_id_len; |
| 61 | } eutran; |
| 62 | }; |
| 63 | }; |
| 64 | |
Philipp Maier | 7741bc3 | 2021-01-07 21:55:48 +0100 | [diff] [blame] | 65 | /* The encoded result of the rim routing information is, depending on the |
| 66 | * address type (discr) of variable length. */ |
| 67 | #define BSSGP_RIM_ROUTING_INFO_MAXLEN 14 |
| 68 | |
Philipp Maier | c08a3fd | 2021-01-25 22:00:01 +0100 | [diff] [blame] | 69 | char *bssgp_rim_ri_name_buf(char *buf, size_t buf_len, const struct bssgp_rim_routing_info *ri); |
| 70 | const char *bssgp_rim_ri_name(const struct bssgp_rim_routing_info *ri); |
Philipp Maier | 7450f77 | 2021-01-06 20:56:43 +0100 | [diff] [blame] | 71 | int bssgp_parse_rim_ri(struct bssgp_rim_routing_info *ri, const uint8_t *buf, unsigned int len); |
| 72 | int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri); |
| 73 | |
Philipp Maier | 9828d28 | 2021-01-06 20:40:23 +0100 | [diff] [blame] | 74 | /* 3GPP TS 48.018, table 11.3.63.1.1: RAN-INFORMATION-REQUEST Application Container coding for NACC */ |
| 75 | struct bssgp_ran_inf_req_app_cont_nacc { |
| 76 | struct osmo_cell_global_id_ps reprt_cell; |
| 77 | }; |
| 78 | |
| 79 | int bssgp_dec_ran_inf_req_app_cont_nacc(struct bssgp_ran_inf_req_app_cont_nacc *cont, const uint8_t *buf, size_t len); |
| 80 | int bssgp_enc_ran_inf_req_app_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_ran_inf_req_app_cont_nacc *cont); |
| 81 | |
| 82 | /* Length of NACC system information, see also: 3GPP TS 48.018 11.3.63.2.1 */ |
| 83 | #define BSSGP_RIM_SI_LEN 21 |
| 84 | #define BSSGP_RIM_PSI_LEN 22 |
| 85 | |
| 86 | /* 3GPP TS 48.018, table 11.3.63.2.1.a: RAN-INFORMATION Application Container coding for NACC */ |
| 87 | struct bssgp_ran_inf_app_cont_nacc { |
| 88 | struct osmo_cell_global_id_ps reprt_cell; |
| 89 | bool type_psi; |
| 90 | uint8_t num_si; |
| 91 | |
| 92 | /* Pointer to system information messages */ |
| 93 | const uint8_t *si[127]; |
| 94 | }; |
| 95 | |
| 96 | int bssgp_dec_ran_inf_app_cont_nacc(struct bssgp_ran_inf_app_cont_nacc *cont, const uint8_t *buf, size_t len); |
| 97 | int bssgp_enc_ran_inf_app_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_ran_inf_app_cont_nacc *cont); |
| 98 | |
| 99 | /* 3GPP TS 48.018, table 11.3.64.1.b, NACC Cause coding */ |
| 100 | enum bssgp_nacc_cause { |
| 101 | BSSGP_NACC_CAUSE_UNSPEC, |
| 102 | BSSGP_NACC_CAUSE_SYNTAX_ERR, |
| 103 | BSSGP_NACC_CAUSE_RPRT_CELL_MISSMTCH, |
| 104 | BSSGP_NACC_CAUSE_SIPSI_TYPE_ERR, |
| 105 | BSSGP_NACC_CAUSE_SIPSI_LEN_ERR, |
| 106 | BSSGP_NACC_CAUSE_SIPSI_SET_ERR, |
| 107 | }; |
| 108 | |
Philipp Maier | 139c4ae | 2021-01-22 17:19:05 +0100 | [diff] [blame] | 109 | extern const struct value_string bssgp_nacc_cause_strs[]; |
| 110 | |
| 111 | /*! Obtain a human-readable string for NACC Cause code */ |
| 112 | static inline const char *bssgp_nacc_cause_str(enum bssgp_nacc_cause val) |
| 113 | { return get_value_string(bssgp_nacc_cause_strs, val); } |
| 114 | |
Philipp Maier | 9828d28 | 2021-01-06 20:40:23 +0100 | [diff] [blame] | 115 | /* 3GPP TS 48.018, table 11.3.64.1.a, Application Error Container coding for NACC */ |
| 116 | struct bssgp_app_err_cont_nacc { |
| 117 | enum bssgp_nacc_cause nacc_cause; |
| 118 | |
| 119 | /* Pointer to errornous application container */ |
| 120 | const uint8_t *err_app_cont; |
| 121 | size_t err_app_cont_len; |
| 122 | }; |
| 123 | |
| 124 | int bssgp_dec_app_err_cont_nacc(struct bssgp_app_err_cont_nacc *cont, const uint8_t *buf, size_t len); |
| 125 | int bssgp_enc_app_err_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_app_err_cont_nacc *cont); |
| 126 | |
| 127 | /* 3GPP TS 48.018, table 11.3.61.b: RIM Application Identity coding */ |
| 128 | enum bssgp_ran_inf_app_id { |
| 129 | BSSGP_RAN_INF_APP_ID_NACC = 1, |
| 130 | BSSGP_RAN_INF_APP_ID_SI3 = 2, |
| 131 | BSSGP_RAN_INF_APP_ID_MBMS = 3, |
| 132 | BSSGP_RAN_INF_APP_ID_SON = 4, |
| 133 | BSSGP_RAN_INF_APP_ID_UTRA_SI = 5, |
| 134 | }; |
| 135 | |
Philipp Maier | 8b19d06 | 2021-01-22 18:05:35 +0100 | [diff] [blame] | 136 | extern const struct value_string bssgp_ran_inf_app_id_strs[]; |
| 137 | |
| 138 | /*! Obtain a human-readable string for RIM Application Identity code */ |
| 139 | static inline const char *bssgp_ran_inf_app_id_str(enum bssgp_ran_inf_app_id val) |
| 140 | { return get_value_string(bssgp_ran_inf_app_id_strs, val); } |
| 141 | |
Philipp Maier | 9828d28 | 2021-01-06 20:40:23 +0100 | [diff] [blame] | 142 | /* 3GPP TS 48.018, table 11.3.62a.1.b: RAN-INFORMATION-REQUEST RIM Container Contents */ |
| 143 | struct bssgp_ran_inf_req_rim_cont { |
| 144 | enum bssgp_ran_inf_app_id app_id; |
| 145 | uint32_t seq_num; |
| 146 | struct bssgp_rim_pdu_ind pdu_ind; |
| 147 | uint8_t prot_ver; |
| 148 | |
| 149 | /* Nested application container */ |
| 150 | union { |
| 151 | struct bssgp_ran_inf_req_app_cont_nacc app_cont_nacc; |
| 152 | /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */ |
| 153 | } u; |
| 154 | |
| 155 | /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer", |
| 156 | * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */ |
| 157 | const uint8_t *son_trans_app_id; |
| 158 | size_t son_trans_app_id_len; |
| 159 | }; |
| 160 | |
| 161 | int bssgp_dec_ran_inf_req_rim_cont(struct bssgp_ran_inf_req_rim_cont *cont, const uint8_t *buf, size_t len); |
| 162 | int bssgp_enc_ran_inf_req_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_req_rim_cont *cont); |
| 163 | |
| 164 | /* 3GPP TS 48.018, table 11.3.62a.2.b: RAN-INFORMATION RIM Container Contents */ |
| 165 | struct bssgp_ran_inf_rim_cont { |
| 166 | enum bssgp_ran_inf_app_id app_id; |
| 167 | uint32_t seq_num; |
| 168 | struct bssgp_rim_pdu_ind pdu_ind; |
| 169 | uint8_t prot_ver; |
| 170 | bool app_err; |
| 171 | |
| 172 | /* Nested application container */ |
| 173 | union { |
| 174 | struct bssgp_ran_inf_app_cont_nacc app_cont_nacc; |
| 175 | struct bssgp_app_err_cont_nacc app_err_cont_nacc; |
| 176 | /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */ |
| 177 | } u; |
| 178 | |
| 179 | /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer", |
| 180 | * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */ |
| 181 | const uint8_t *son_trans_app_id; |
| 182 | size_t son_trans_app_id_len; |
| 183 | }; |
| 184 | |
| 185 | int bssgp_dec_ran_inf_rim_cont(struct bssgp_ran_inf_rim_cont *cont, const uint8_t *buf, size_t len); |
| 186 | int bssgp_enc_ran_inf_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_rim_cont *cont); |
| 187 | |
| 188 | /* 3GPP TS 48.018, table 11.3.62a.3.b: RAN-INFORMATION-ACK RIM Container Contents */ |
| 189 | struct bssgp_ran_inf_ack_rim_cont { |
| 190 | enum bssgp_ran_inf_app_id app_id; |
| 191 | uint32_t seq_num; |
| 192 | uint8_t prot_ver; |
| 193 | |
| 194 | /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer", |
| 195 | * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */ |
| 196 | const uint8_t *son_trans_app_id; |
| 197 | size_t son_trans_app_id_len; |
| 198 | }; |
| 199 | |
| 200 | int bssgp_dec_ran_inf_ack_rim_cont(struct bssgp_ran_inf_ack_rim_cont *cont, const uint8_t *buf, size_t len); |
| 201 | int bssgp_enc_ran_inf_ack_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_ack_rim_cont *cont); |
| 202 | |
| 203 | /* 3GPP TS 48.018, table 11.3.62a.4.b: RAN-INFORMATION-ERROR RIM Container Contents */ |
| 204 | struct bssgp_ran_inf_err_rim_cont { |
| 205 | enum bssgp_ran_inf_app_id app_id; |
| 206 | uint8_t cause; |
| 207 | uint8_t prot_ver; |
| 208 | |
| 209 | /* Pointer to (encoded) errornous PDU, |
| 210 | * see also: 3GPP TS 48.018, section 11.3.24 */ |
| 211 | const uint8_t *err_pdu; |
| 212 | size_t err_pdu_len; |
| 213 | |
| 214 | /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer", |
| 215 | * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */ |
| 216 | const uint8_t *son_trans_app_id; |
| 217 | size_t son_trans_app_id_len; |
| 218 | }; |
| 219 | |
| 220 | int bssgp_dec_ran_inf_err_rim_cont(struct bssgp_ran_inf_err_rim_cont *cont, const uint8_t *buf, size_t len); |
| 221 | int bssgp_enc_ran_inf_err_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_err_rim_cont *cont); |
| 222 | |
| 223 | /* 3GPP TS 48.018, table 11.3.62a.5.b: RAN-INFORMATION-APPLICATION-ERROR RIM Container Contents */ |
| 224 | struct bssgp_ran_inf_app_err_rim_cont { |
| 225 | enum bssgp_ran_inf_app_id app_id; |
| 226 | uint32_t seq_num; |
| 227 | struct bssgp_rim_pdu_ind pdu_ind; |
| 228 | uint8_t prot_ver; |
| 229 | |
| 230 | /* Nested application container */ |
| 231 | union { |
| 232 | struct bssgp_app_err_cont_nacc app_err_cont_nacc; |
| 233 | /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */ |
| 234 | } u; |
| 235 | }; |
| 236 | |
| 237 | int bssgp_dec_ran_inf_app_err_rim_cont(struct bssgp_ran_inf_app_err_rim_cont *cont, const uint8_t *buf, size_t len); |
| 238 | int bssgp_enc_ran_inf_app_err_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_app_err_rim_cont *cont); |
Philipp Maier | 4d40047 | 2021-01-26 12:57:13 +0100 | [diff] [blame] | 239 | |
| 240 | /* Chapter 10.6.1: RAN-INFORMATION-REQUEST */ |
| 241 | struct bssgp_ran_information_pdu { |
| 242 | struct bssgp_rim_routing_info routing_info_dest; |
| 243 | struct bssgp_rim_routing_info routing_info_src; |
| 244 | |
| 245 | /* Encoded variant of the RIM container */ |
| 246 | uint8_t rim_cont_iei; |
| 247 | const uint8_t *rim_cont; |
| 248 | unsigned int rim_cont_len; |
| 249 | |
| 250 | /* Decoded variant of the RIM container */ |
| 251 | bool decoded_present; |
| 252 | union { |
| 253 | struct bssgp_ran_inf_req_rim_cont req_rim_cont; |
| 254 | struct bssgp_ran_inf_rim_cont rim_cont; |
| 255 | struct bssgp_ran_inf_ack_rim_cont ack_rim_cont; |
| 256 | struct bssgp_ran_inf_err_rim_cont err_rim_cont; |
| 257 | struct bssgp_ran_inf_app_err_rim_cont app_err_rim_cont; |
| 258 | } decoded; |
| 259 | |
| 260 | /* When receiving a PDU from BSSGP the encoded variant of the RIM |
| 261 | * container will always be present. The decoded variant will be |
| 262 | * present in addition whenever BSSGP was able to decode the container. |
| 263 | * |
| 264 | * When sending a PDU to BSSGP, then the decoded variant is used when |
| 265 | * it is available. The encoded variant (if present) will be ignored |
| 266 | * then. */ |
| 267 | }; |
| 268 | |
| 269 | int bssgp_parse_rim_pdu(struct bssgp_ran_information_pdu *pdu, const struct msgb *msg); |
Pau Espin Pedrol | adef546 | 2021-05-06 18:17:18 +0200 | [diff] [blame] | 270 | struct msgb *bssgp_encode_rim_pdu(const struct bssgp_ran_information_pdu *pdu); |
Philipp Maier | 4d40047 | 2021-01-26 12:57:13 +0100 | [diff] [blame] | 271 | |
| 272 | int bssgp_tx_rim(const struct bssgp_ran_information_pdu *pdu, uint16_t nsei); |