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 | |
| 28 | #include <osmocom/gprs/protocol/gsm_08_18.h> |
| 29 | |
Philipp Maier | 7450f77 | 2021-01-06 20:56:43 +0100 | [diff] [blame] | 30 | enum bssgp_rim_routing_info_discr { |
| 31 | BSSGP_RIM_ROUTING_INFO_GERAN, |
| 32 | BSSGP_RIM_ROUTING_INFO_UTRAN, |
| 33 | BSSGP_RIM_ROUTING_INFO_EUTRAN, |
| 34 | }; |
| 35 | |
| 36 | /*! BSSGP RIM Routing information, see also 3GPP TS 48.018, section 11.3.70 */ |
| 37 | struct bssgp_rim_routing_info { |
| 38 | enum bssgp_rim_routing_info_discr discr; |
| 39 | union { |
| 40 | struct { |
| 41 | struct gprs_ra_id raid; |
| 42 | uint16_t cid; |
| 43 | } geran; |
| 44 | struct { |
| 45 | struct gprs_ra_id raid; |
| 46 | uint16_t rncid; |
| 47 | } utran; |
| 48 | struct { |
| 49 | struct osmo_eutran_tai tai; |
| 50 | /* See also 3GPP TS 36.413 9.2.1.37 and 3GPP TS 36.401 */ |
| 51 | uint8_t global_enb_id[8]; |
| 52 | uint8_t global_enb_id_len; |
| 53 | } eutran; |
| 54 | }; |
| 55 | }; |
| 56 | |
Philipp Maier | 7741bc3 | 2021-01-07 21:55:48 +0100 | [diff] [blame] | 57 | /* The encoded result of the rim routing information is, depending on the |
| 58 | * address type (discr) of variable length. */ |
| 59 | #define BSSGP_RIM_ROUTING_INFO_MAXLEN 14 |
| 60 | |
Philipp Maier | 7450f77 | 2021-01-06 20:56:43 +0100 | [diff] [blame] | 61 | int bssgp_parse_rim_ri(struct bssgp_rim_routing_info *ri, const uint8_t *buf, unsigned int len); |
| 62 | int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri); |
| 63 | |
Philipp Maier | 9828d28 | 2021-01-06 20:40:23 +0100 | [diff] [blame] | 64 | /* 3GPP TS 48.018, table 11.3.63.1.1: RAN-INFORMATION-REQUEST Application Container coding for NACC */ |
| 65 | struct bssgp_ran_inf_req_app_cont_nacc { |
| 66 | struct osmo_cell_global_id_ps reprt_cell; |
| 67 | }; |
| 68 | |
| 69 | 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); |
| 70 | 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); |
| 71 | |
| 72 | /* Length of NACC system information, see also: 3GPP TS 48.018 11.3.63.2.1 */ |
| 73 | #define BSSGP_RIM_SI_LEN 21 |
| 74 | #define BSSGP_RIM_PSI_LEN 22 |
| 75 | |
| 76 | /* 3GPP TS 48.018, table 11.3.63.2.1.a: RAN-INFORMATION Application Container coding for NACC */ |
| 77 | struct bssgp_ran_inf_app_cont_nacc { |
| 78 | struct osmo_cell_global_id_ps reprt_cell; |
| 79 | bool type_psi; |
| 80 | uint8_t num_si; |
| 81 | |
| 82 | /* Pointer to system information messages */ |
| 83 | const uint8_t *si[127]; |
| 84 | }; |
| 85 | |
| 86 | int bssgp_dec_ran_inf_app_cont_nacc(struct bssgp_ran_inf_app_cont_nacc *cont, const uint8_t *buf, size_t len); |
| 87 | int bssgp_enc_ran_inf_app_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_ran_inf_app_cont_nacc *cont); |
| 88 | |
| 89 | /* 3GPP TS 48.018, table 11.3.64.1.b, NACC Cause coding */ |
| 90 | enum bssgp_nacc_cause { |
| 91 | BSSGP_NACC_CAUSE_UNSPEC, |
| 92 | BSSGP_NACC_CAUSE_SYNTAX_ERR, |
| 93 | BSSGP_NACC_CAUSE_RPRT_CELL_MISSMTCH, |
| 94 | BSSGP_NACC_CAUSE_SIPSI_TYPE_ERR, |
| 95 | BSSGP_NACC_CAUSE_SIPSI_LEN_ERR, |
| 96 | BSSGP_NACC_CAUSE_SIPSI_SET_ERR, |
| 97 | }; |
| 98 | |
Philipp Maier | 139c4ae | 2021-01-22 17:19:05 +0100 | [diff] [blame^] | 99 | extern const struct value_string bssgp_nacc_cause_strs[]; |
| 100 | |
| 101 | /*! Obtain a human-readable string for NACC Cause code */ |
| 102 | static inline const char *bssgp_nacc_cause_str(enum bssgp_nacc_cause val) |
| 103 | { return get_value_string(bssgp_nacc_cause_strs, val); } |
| 104 | |
Philipp Maier | 9828d28 | 2021-01-06 20:40:23 +0100 | [diff] [blame] | 105 | /* 3GPP TS 48.018, table 11.3.64.1.a, Application Error Container coding for NACC */ |
| 106 | struct bssgp_app_err_cont_nacc { |
| 107 | enum bssgp_nacc_cause nacc_cause; |
| 108 | |
| 109 | /* Pointer to errornous application container */ |
| 110 | const uint8_t *err_app_cont; |
| 111 | size_t err_app_cont_len; |
| 112 | }; |
| 113 | |
| 114 | int bssgp_dec_app_err_cont_nacc(struct bssgp_app_err_cont_nacc *cont, const uint8_t *buf, size_t len); |
| 115 | int bssgp_enc_app_err_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_app_err_cont_nacc *cont); |
| 116 | |
| 117 | /* 3GPP TS 48.018, table 11.3.61.b: RIM Application Identity coding */ |
| 118 | enum bssgp_ran_inf_app_id { |
| 119 | BSSGP_RAN_INF_APP_ID_NACC = 1, |
| 120 | BSSGP_RAN_INF_APP_ID_SI3 = 2, |
| 121 | BSSGP_RAN_INF_APP_ID_MBMS = 3, |
| 122 | BSSGP_RAN_INF_APP_ID_SON = 4, |
| 123 | BSSGP_RAN_INF_APP_ID_UTRA_SI = 5, |
| 124 | }; |
| 125 | |
| 126 | /* 3GPP TS 48.018, table 11.3.62a.1.b: RAN-INFORMATION-REQUEST RIM Container Contents */ |
| 127 | struct bssgp_ran_inf_req_rim_cont { |
| 128 | enum bssgp_ran_inf_app_id app_id; |
| 129 | uint32_t seq_num; |
| 130 | struct bssgp_rim_pdu_ind pdu_ind; |
| 131 | uint8_t prot_ver; |
| 132 | |
| 133 | /* Nested application container */ |
| 134 | union { |
| 135 | struct bssgp_ran_inf_req_app_cont_nacc app_cont_nacc; |
| 136 | /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */ |
| 137 | } u; |
| 138 | |
| 139 | /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer", |
| 140 | * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */ |
| 141 | const uint8_t *son_trans_app_id; |
| 142 | size_t son_trans_app_id_len; |
| 143 | }; |
| 144 | |
| 145 | int bssgp_dec_ran_inf_req_rim_cont(struct bssgp_ran_inf_req_rim_cont *cont, const uint8_t *buf, size_t len); |
| 146 | int bssgp_enc_ran_inf_req_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_req_rim_cont *cont); |
| 147 | |
| 148 | /* 3GPP TS 48.018, table 11.3.62a.2.b: RAN-INFORMATION RIM Container Contents */ |
| 149 | struct bssgp_ran_inf_rim_cont { |
| 150 | enum bssgp_ran_inf_app_id app_id; |
| 151 | uint32_t seq_num; |
| 152 | struct bssgp_rim_pdu_ind pdu_ind; |
| 153 | uint8_t prot_ver; |
| 154 | bool app_err; |
| 155 | |
| 156 | /* Nested application container */ |
| 157 | union { |
| 158 | struct bssgp_ran_inf_app_cont_nacc app_cont_nacc; |
| 159 | struct bssgp_app_err_cont_nacc app_err_cont_nacc; |
| 160 | /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */ |
| 161 | } u; |
| 162 | |
| 163 | /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer", |
| 164 | * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */ |
| 165 | const uint8_t *son_trans_app_id; |
| 166 | size_t son_trans_app_id_len; |
| 167 | }; |
| 168 | |
| 169 | int bssgp_dec_ran_inf_rim_cont(struct bssgp_ran_inf_rim_cont *cont, const uint8_t *buf, size_t len); |
| 170 | int bssgp_enc_ran_inf_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_rim_cont *cont); |
| 171 | |
| 172 | /* 3GPP TS 48.018, table 11.3.62a.3.b: RAN-INFORMATION-ACK RIM Container Contents */ |
| 173 | struct bssgp_ran_inf_ack_rim_cont { |
| 174 | enum bssgp_ran_inf_app_id app_id; |
| 175 | uint32_t seq_num; |
| 176 | uint8_t prot_ver; |
| 177 | |
| 178 | /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer", |
| 179 | * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */ |
| 180 | const uint8_t *son_trans_app_id; |
| 181 | size_t son_trans_app_id_len; |
| 182 | }; |
| 183 | |
| 184 | int bssgp_dec_ran_inf_ack_rim_cont(struct bssgp_ran_inf_ack_rim_cont *cont, const uint8_t *buf, size_t len); |
| 185 | int bssgp_enc_ran_inf_ack_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_ack_rim_cont *cont); |
| 186 | |
| 187 | /* 3GPP TS 48.018, table 11.3.62a.4.b: RAN-INFORMATION-ERROR RIM Container Contents */ |
| 188 | struct bssgp_ran_inf_err_rim_cont { |
| 189 | enum bssgp_ran_inf_app_id app_id; |
| 190 | uint8_t cause; |
| 191 | uint8_t prot_ver; |
| 192 | |
| 193 | /* Pointer to (encoded) errornous PDU, |
| 194 | * see also: 3GPP TS 48.018, section 11.3.24 */ |
| 195 | const uint8_t *err_pdu; |
| 196 | size_t err_pdu_len; |
| 197 | |
| 198 | /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer", |
| 199 | * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */ |
| 200 | const uint8_t *son_trans_app_id; |
| 201 | size_t son_trans_app_id_len; |
| 202 | }; |
| 203 | |
| 204 | int bssgp_dec_ran_inf_err_rim_cont(struct bssgp_ran_inf_err_rim_cont *cont, const uint8_t *buf, size_t len); |
| 205 | int bssgp_enc_ran_inf_err_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_err_rim_cont *cont); |
| 206 | |
| 207 | /* 3GPP TS 48.018, table 11.3.62a.5.b: RAN-INFORMATION-APPLICATION-ERROR RIM Container Contents */ |
| 208 | struct bssgp_ran_inf_app_err_rim_cont { |
| 209 | enum bssgp_ran_inf_app_id app_id; |
| 210 | uint32_t seq_num; |
| 211 | struct bssgp_rim_pdu_ind pdu_ind; |
| 212 | uint8_t prot_ver; |
| 213 | |
| 214 | /* Nested application container */ |
| 215 | union { |
| 216 | struct bssgp_app_err_cont_nacc app_err_cont_nacc; |
| 217 | /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */ |
| 218 | } u; |
| 219 | }; |
| 220 | |
| 221 | 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); |
| 222 | 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); |