blob: 10ea58bd6442b72e420c78d35a9f76188b247f5f [file] [log] [blame]
Philipp Maier9828d282021-01-06 20:40:23 +01001/*! \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 Pedrol445a3662021-01-26 13:06:51 +010028#include <osmocom/gsm/gsm48.h>
Philipp Maier9828d282021-01-06 20:40:23 +010029#include <osmocom/gprs/protocol/gsm_08_18.h>
Pau Espin Pedrol445a3662021-01-26 13:06:51 +010030#include <osmocom/gprs/protocol/gsm_24_301.h>
Philipp Maier9828d282021-01-06 20:40:23 +010031
Philipp Maier7450f772021-01-06 20:56:43 +010032enum 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 Maiercf114112021-01-22 18:24:12 +010038extern const struct value_string bssgp_rim_routing_info_discr_strs[];
39
40/*! Obtain a human-readable string for NACC Cause code */
41static 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 Maier7450f772021-01-06 20:56:43 +010044/*! BSSGP RIM Routing information, see also 3GPP TS 48.018, section 11.3.70 */
45struct 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 Maier7741bc32021-01-07 21:55:48 +010065/* 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 Maierc08a3fd2021-01-25 22:00:01 +010069char *bssgp_rim_ri_name_buf(char *buf, size_t buf_len, const struct bssgp_rim_routing_info *ri);
70const char *bssgp_rim_ri_name(const struct bssgp_rim_routing_info *ri);
Philipp Maier7450f772021-01-06 20:56:43 +010071int bssgp_parse_rim_ri(struct bssgp_rim_routing_info *ri, const uint8_t *buf, unsigned int len);
Philipp Maier3c577262023-08-10 11:47:54 +020072int bssgp_parse_rim_ra(struct bssgp_rim_routing_info *ri, const uint8_t *buf, unsigned int len, uint8_t discr);
Philipp Maier7450f772021-01-06 20:56:43 +010073int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri);
74
Philipp Maier9828d282021-01-06 20:40:23 +010075/* 3GPP TS 48.018, table 11.3.63.1.1: RAN-INFORMATION-REQUEST Application Container coding for NACC */
76struct bssgp_ran_inf_req_app_cont_nacc {
77 struct osmo_cell_global_id_ps reprt_cell;
78};
79
80int bssgp_dec_ran_inf_req_app_cont_nacc(struct bssgp_ran_inf_req_app_cont_nacc *cont, const uint8_t *buf, size_t len);
81int bssgp_enc_ran_inf_req_app_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_ran_inf_req_app_cont_nacc *cont);
82
83/* Length of NACC system information, see also: 3GPP TS 48.018 11.3.63.2.1 */
84#define BSSGP_RIM_SI_LEN 21
85#define BSSGP_RIM_PSI_LEN 22
86
87/* 3GPP TS 48.018, table 11.3.63.2.1.a: RAN-INFORMATION Application Container coding for NACC */
88struct bssgp_ran_inf_app_cont_nacc {
89 struct osmo_cell_global_id_ps reprt_cell;
90 bool type_psi;
91 uint8_t num_si;
92
93 /* Pointer to system information messages */
94 const uint8_t *si[127];
95};
96
97int bssgp_dec_ran_inf_app_cont_nacc(struct bssgp_ran_inf_app_cont_nacc *cont, const uint8_t *buf, size_t len);
98int bssgp_enc_ran_inf_app_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_ran_inf_app_cont_nacc *cont);
99
100/* 3GPP TS 48.018, table 11.3.64.1.b, NACC Cause coding */
101enum bssgp_nacc_cause {
102 BSSGP_NACC_CAUSE_UNSPEC,
103 BSSGP_NACC_CAUSE_SYNTAX_ERR,
104 BSSGP_NACC_CAUSE_RPRT_CELL_MISSMTCH,
105 BSSGP_NACC_CAUSE_SIPSI_TYPE_ERR,
106 BSSGP_NACC_CAUSE_SIPSI_LEN_ERR,
107 BSSGP_NACC_CAUSE_SIPSI_SET_ERR,
108};
109
Philipp Maier139c4ae2021-01-22 17:19:05 +0100110extern const struct value_string bssgp_nacc_cause_strs[];
111
112/*! Obtain a human-readable string for NACC Cause code */
113static inline const char *bssgp_nacc_cause_str(enum bssgp_nacc_cause val)
114{ return get_value_string(bssgp_nacc_cause_strs, val); }
115
Philipp Maier9828d282021-01-06 20:40:23 +0100116/* 3GPP TS 48.018, table 11.3.64.1.a, Application Error Container coding for NACC */
117struct bssgp_app_err_cont_nacc {
118 enum bssgp_nacc_cause nacc_cause;
119
120 /* Pointer to errornous application container */
121 const uint8_t *err_app_cont;
122 size_t err_app_cont_len;
123};
124
125int bssgp_dec_app_err_cont_nacc(struct bssgp_app_err_cont_nacc *cont, const uint8_t *buf, size_t len);
126int bssgp_enc_app_err_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_app_err_cont_nacc *cont);
127
128/* 3GPP TS 48.018, table 11.3.61.b: RIM Application Identity coding */
129enum bssgp_ran_inf_app_id {
130 BSSGP_RAN_INF_APP_ID_NACC = 1,
131 BSSGP_RAN_INF_APP_ID_SI3 = 2,
132 BSSGP_RAN_INF_APP_ID_MBMS = 3,
133 BSSGP_RAN_INF_APP_ID_SON = 4,
134 BSSGP_RAN_INF_APP_ID_UTRA_SI = 5,
135};
136
Philipp Maier8b19d062021-01-22 18:05:35 +0100137extern const struct value_string bssgp_ran_inf_app_id_strs[];
138
139/*! Obtain a human-readable string for RIM Application Identity code */
140static inline const char *bssgp_ran_inf_app_id_str(enum bssgp_ran_inf_app_id val)
141{ return get_value_string(bssgp_ran_inf_app_id_strs, val); }
142
Philipp Maier9828d282021-01-06 20:40:23 +0100143/* 3GPP TS 48.018, table 11.3.62a.1.b: RAN-INFORMATION-REQUEST RIM Container Contents */
144struct bssgp_ran_inf_req_rim_cont {
145 enum bssgp_ran_inf_app_id app_id;
146 uint32_t seq_num;
147 struct bssgp_rim_pdu_ind pdu_ind;
148 uint8_t prot_ver;
149
150 /* Nested application container */
151 union {
152 struct bssgp_ran_inf_req_app_cont_nacc app_cont_nacc;
153 /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */
154 } u;
155
156 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
157 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
158 const uint8_t *son_trans_app_id;
159 size_t son_trans_app_id_len;
160};
161
162int bssgp_dec_ran_inf_req_rim_cont(struct bssgp_ran_inf_req_rim_cont *cont, const uint8_t *buf, size_t len);
163int bssgp_enc_ran_inf_req_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_req_rim_cont *cont);
164
165/* 3GPP TS 48.018, table 11.3.62a.2.b: RAN-INFORMATION RIM Container Contents */
166struct bssgp_ran_inf_rim_cont {
167 enum bssgp_ran_inf_app_id app_id;
168 uint32_t seq_num;
169 struct bssgp_rim_pdu_ind pdu_ind;
170 uint8_t prot_ver;
171 bool app_err;
172
173 /* Nested application container */
174 union {
175 struct bssgp_ran_inf_app_cont_nacc app_cont_nacc;
176 struct bssgp_app_err_cont_nacc app_err_cont_nacc;
177 /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */
178 } u;
179
180 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
181 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
182 const uint8_t *son_trans_app_id;
183 size_t son_trans_app_id_len;
184};
185
186int bssgp_dec_ran_inf_rim_cont(struct bssgp_ran_inf_rim_cont *cont, const uint8_t *buf, size_t len);
187int bssgp_enc_ran_inf_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_rim_cont *cont);
188
189/* 3GPP TS 48.018, table 11.3.62a.3.b: RAN-INFORMATION-ACK RIM Container Contents */
190struct bssgp_ran_inf_ack_rim_cont {
191 enum bssgp_ran_inf_app_id app_id;
192 uint32_t seq_num;
193 uint8_t prot_ver;
194
195 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
196 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
197 const uint8_t *son_trans_app_id;
198 size_t son_trans_app_id_len;
199};
200
201int bssgp_dec_ran_inf_ack_rim_cont(struct bssgp_ran_inf_ack_rim_cont *cont, const uint8_t *buf, size_t len);
202int bssgp_enc_ran_inf_ack_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_ack_rim_cont *cont);
203
204/* 3GPP TS 48.018, table 11.3.62a.4.b: RAN-INFORMATION-ERROR RIM Container Contents */
205struct bssgp_ran_inf_err_rim_cont {
206 enum bssgp_ran_inf_app_id app_id;
207 uint8_t cause;
208 uint8_t prot_ver;
209
210 /* Pointer to (encoded) errornous PDU,
211 * see also: 3GPP TS 48.018, section 11.3.24 */
212 const uint8_t *err_pdu;
213 size_t err_pdu_len;
214
215 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
216 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
217 const uint8_t *son_trans_app_id;
218 size_t son_trans_app_id_len;
219};
220
221int bssgp_dec_ran_inf_err_rim_cont(struct bssgp_ran_inf_err_rim_cont *cont, const uint8_t *buf, size_t len);
222int bssgp_enc_ran_inf_err_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_err_rim_cont *cont);
223
224/* 3GPP TS 48.018, table 11.3.62a.5.b: RAN-INFORMATION-APPLICATION-ERROR RIM Container Contents */
225struct bssgp_ran_inf_app_err_rim_cont {
226 enum bssgp_ran_inf_app_id app_id;
227 uint32_t seq_num;
228 struct bssgp_rim_pdu_ind pdu_ind;
229 uint8_t prot_ver;
230
231 /* Nested application container */
232 union {
233 struct bssgp_app_err_cont_nacc app_err_cont_nacc;
234 /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */
235 } u;
236};
237
238int bssgp_dec_ran_inf_app_err_rim_cont(struct bssgp_ran_inf_app_err_rim_cont *cont, const uint8_t *buf, size_t len);
239int 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 Maier4d400472021-01-26 12:57:13 +0100240
241/* Chapter 10.6.1: RAN-INFORMATION-REQUEST */
242struct bssgp_ran_information_pdu {
243 struct bssgp_rim_routing_info routing_info_dest;
244 struct bssgp_rim_routing_info routing_info_src;
245
246 /* Encoded variant of the RIM container */
247 uint8_t rim_cont_iei;
248 const uint8_t *rim_cont;
249 unsigned int rim_cont_len;
250
251 /* Decoded variant of the RIM container */
252 bool decoded_present;
253 union {
254 struct bssgp_ran_inf_req_rim_cont req_rim_cont;
255 struct bssgp_ran_inf_rim_cont rim_cont;
256 struct bssgp_ran_inf_ack_rim_cont ack_rim_cont;
257 struct bssgp_ran_inf_err_rim_cont err_rim_cont;
258 struct bssgp_ran_inf_app_err_rim_cont app_err_rim_cont;
259 } decoded;
260
261 /* When receiving a PDU from BSSGP the encoded variant of the RIM
262 * container will always be present. The decoded variant will be
263 * present in addition whenever BSSGP was able to decode the container.
264 *
265 * When sending a PDU to BSSGP, then the decoded variant is used when
266 * it is available. The encoded variant (if present) will be ignored
267 * then. */
268};
269
270int bssgp_parse_rim_pdu(struct bssgp_ran_information_pdu *pdu, const struct msgb *msg);
Pau Espin Pedroladef5462021-05-06 18:17:18 +0200271struct msgb *bssgp_encode_rim_pdu(const struct bssgp_ran_information_pdu *pdu);
Philipp Maier4d400472021-01-26 12:57:13 +0100272
273int bssgp_tx_rim(const struct bssgp_ran_information_pdu *pdu, uint16_t nsei);
Philipp Maier9e755442023-08-09 16:39:06 +0200274int bssgp_tx_rim_encoded(struct msgb *msg, uint16_t nsei);