blob: 5f397c98af0778140c8cff0fda35b5fa40dacbff [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);
72int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri);
73
Philipp Maier9828d282021-01-06 20:40:23 +010074/* 3GPP TS 48.018, table 11.3.63.1.1: RAN-INFORMATION-REQUEST Application Container coding for NACC */
75struct bssgp_ran_inf_req_app_cont_nacc {
76 struct osmo_cell_global_id_ps reprt_cell;
77};
78
79int bssgp_dec_ran_inf_req_app_cont_nacc(struct bssgp_ran_inf_req_app_cont_nacc *cont, const uint8_t *buf, size_t len);
80int 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 */
87struct 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
96int bssgp_dec_ran_inf_app_cont_nacc(struct bssgp_ran_inf_app_cont_nacc *cont, const uint8_t *buf, size_t len);
97int 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 */
100enum 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 Maier139c4ae2021-01-22 17:19:05 +0100109extern const struct value_string bssgp_nacc_cause_strs[];
110
111/*! Obtain a human-readable string for NACC Cause code */
112static inline const char *bssgp_nacc_cause_str(enum bssgp_nacc_cause val)
113{ return get_value_string(bssgp_nacc_cause_strs, val); }
114
Philipp Maier9828d282021-01-06 20:40:23 +0100115/* 3GPP TS 48.018, table 11.3.64.1.a, Application Error Container coding for NACC */
116struct 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
124int bssgp_dec_app_err_cont_nacc(struct bssgp_app_err_cont_nacc *cont, const uint8_t *buf, size_t len);
125int 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 */
128enum 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 Maier8b19d062021-01-22 18:05:35 +0100136extern const struct value_string bssgp_ran_inf_app_id_strs[];
137
138/*! Obtain a human-readable string for RIM Application Identity code */
139static 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 Maier9828d282021-01-06 20:40:23 +0100142/* 3GPP TS 48.018, table 11.3.62a.1.b: RAN-INFORMATION-REQUEST RIM Container Contents */
143struct 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
161int bssgp_dec_ran_inf_req_rim_cont(struct bssgp_ran_inf_req_rim_cont *cont, const uint8_t *buf, size_t len);
162int 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 */
165struct 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
185int bssgp_dec_ran_inf_rim_cont(struct bssgp_ran_inf_rim_cont *cont, const uint8_t *buf, size_t len);
186int 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 */
189struct 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
200int bssgp_dec_ran_inf_ack_rim_cont(struct bssgp_ran_inf_ack_rim_cont *cont, const uint8_t *buf, size_t len);
201int 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 */
204struct 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
220int bssgp_dec_ran_inf_err_rim_cont(struct bssgp_ran_inf_err_rim_cont *cont, const uint8_t *buf, size_t len);
221int 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 */
224struct 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
237int bssgp_dec_ran_inf_app_err_rim_cont(struct bssgp_ran_inf_app_err_rim_cont *cont, const uint8_t *buf, size_t len);
238int 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 +0100239
240/* Chapter 10.6.1: RAN-INFORMATION-REQUEST */
241struct 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
269int bssgp_parse_rim_pdu(struct bssgp_ran_information_pdu *pdu, const struct msgb *msg);
Pau Espin Pedroladef5462021-05-06 18:17:18 +0200270struct msgb *bssgp_encode_rim_pdu(const struct bssgp_ran_information_pdu *pdu);
Philipp Maier4d400472021-01-26 12:57:13 +0100271
272int bssgp_tx_rim(const struct bssgp_ran_information_pdu *pdu, uint16_t nsei);