blob: 7f3a0e433b6a4a9e256f82a4f1bed1116073e85d [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
28#include <osmocom/gprs/protocol/gsm_08_18.h>
29
Philipp Maier7450f772021-01-06 20:56:43 +010030enum 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 */
37struct 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
57int bssgp_parse_rim_ri(struct bssgp_rim_routing_info *ri, const uint8_t *buf, unsigned int len);
58int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri);
59
Philipp Maier9828d282021-01-06 20:40:23 +010060/* 3GPP TS 48.018, table 11.3.63.1.1: RAN-INFORMATION-REQUEST Application Container coding for NACC */
61struct bssgp_ran_inf_req_app_cont_nacc {
62 struct osmo_cell_global_id_ps reprt_cell;
63};
64
65int bssgp_dec_ran_inf_req_app_cont_nacc(struct bssgp_ran_inf_req_app_cont_nacc *cont, const uint8_t *buf, size_t len);
66int bssgp_enc_ran_inf_req_app_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_ran_inf_req_app_cont_nacc *cont);
67
68/* Length of NACC system information, see also: 3GPP TS 48.018 11.3.63.2.1 */
69#define BSSGP_RIM_SI_LEN 21
70#define BSSGP_RIM_PSI_LEN 22
71
72/* 3GPP TS 48.018, table 11.3.63.2.1.a: RAN-INFORMATION Application Container coding for NACC */
73struct bssgp_ran_inf_app_cont_nacc {
74 struct osmo_cell_global_id_ps reprt_cell;
75 bool type_psi;
76 uint8_t num_si;
77
78 /* Pointer to system information messages */
79 const uint8_t *si[127];
80};
81
82int bssgp_dec_ran_inf_app_cont_nacc(struct bssgp_ran_inf_app_cont_nacc *cont, const uint8_t *buf, size_t len);
83int bssgp_enc_ran_inf_app_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_ran_inf_app_cont_nacc *cont);
84
85/* 3GPP TS 48.018, table 11.3.64.1.b, NACC Cause coding */
86enum bssgp_nacc_cause {
87 BSSGP_NACC_CAUSE_UNSPEC,
88 BSSGP_NACC_CAUSE_SYNTAX_ERR,
89 BSSGP_NACC_CAUSE_RPRT_CELL_MISSMTCH,
90 BSSGP_NACC_CAUSE_SIPSI_TYPE_ERR,
91 BSSGP_NACC_CAUSE_SIPSI_LEN_ERR,
92 BSSGP_NACC_CAUSE_SIPSI_SET_ERR,
93};
94
95/* 3GPP TS 48.018, table 11.3.64.1.a, Application Error Container coding for NACC */
96struct bssgp_app_err_cont_nacc {
97 enum bssgp_nacc_cause nacc_cause;
98
99 /* Pointer to errornous application container */
100 const uint8_t *err_app_cont;
101 size_t err_app_cont_len;
102};
103
104int bssgp_dec_app_err_cont_nacc(struct bssgp_app_err_cont_nacc *cont, const uint8_t *buf, size_t len);
105int bssgp_enc_app_err_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_app_err_cont_nacc *cont);
106
107/* 3GPP TS 48.018, table 11.3.61.b: RIM Application Identity coding */
108enum bssgp_ran_inf_app_id {
109 BSSGP_RAN_INF_APP_ID_NACC = 1,
110 BSSGP_RAN_INF_APP_ID_SI3 = 2,
111 BSSGP_RAN_INF_APP_ID_MBMS = 3,
112 BSSGP_RAN_INF_APP_ID_SON = 4,
113 BSSGP_RAN_INF_APP_ID_UTRA_SI = 5,
114};
115
116/* 3GPP TS 48.018, table 11.3.62a.1.b: RAN-INFORMATION-REQUEST RIM Container Contents */
117struct bssgp_ran_inf_req_rim_cont {
118 enum bssgp_ran_inf_app_id app_id;
119 uint32_t seq_num;
120 struct bssgp_rim_pdu_ind pdu_ind;
121 uint8_t prot_ver;
122
123 /* Nested application container */
124 union {
125 struct bssgp_ran_inf_req_app_cont_nacc app_cont_nacc;
126 /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */
127 } u;
128
129 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
130 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
131 const uint8_t *son_trans_app_id;
132 size_t son_trans_app_id_len;
133};
134
135int bssgp_dec_ran_inf_req_rim_cont(struct bssgp_ran_inf_req_rim_cont *cont, const uint8_t *buf, size_t len);
136int bssgp_enc_ran_inf_req_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_req_rim_cont *cont);
137
138/* 3GPP TS 48.018, table 11.3.62a.2.b: RAN-INFORMATION RIM Container Contents */
139struct bssgp_ran_inf_rim_cont {
140 enum bssgp_ran_inf_app_id app_id;
141 uint32_t seq_num;
142 struct bssgp_rim_pdu_ind pdu_ind;
143 uint8_t prot_ver;
144 bool app_err;
145
146 /* Nested application container */
147 union {
148 struct bssgp_ran_inf_app_cont_nacc app_cont_nacc;
149 struct bssgp_app_err_cont_nacc app_err_cont_nacc;
150 /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */
151 } u;
152
153 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
154 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
155 const uint8_t *son_trans_app_id;
156 size_t son_trans_app_id_len;
157};
158
159int bssgp_dec_ran_inf_rim_cont(struct bssgp_ran_inf_rim_cont *cont, const uint8_t *buf, size_t len);
160int bssgp_enc_ran_inf_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_rim_cont *cont);
161
162/* 3GPP TS 48.018, table 11.3.62a.3.b: RAN-INFORMATION-ACK RIM Container Contents */
163struct bssgp_ran_inf_ack_rim_cont {
164 enum bssgp_ran_inf_app_id app_id;
165 uint32_t seq_num;
166 uint8_t prot_ver;
167
168 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
169 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
170 const uint8_t *son_trans_app_id;
171 size_t son_trans_app_id_len;
172};
173
174int bssgp_dec_ran_inf_ack_rim_cont(struct bssgp_ran_inf_ack_rim_cont *cont, const uint8_t *buf, size_t len);
175int bssgp_enc_ran_inf_ack_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_ack_rim_cont *cont);
176
177/* 3GPP TS 48.018, table 11.3.62a.4.b: RAN-INFORMATION-ERROR RIM Container Contents */
178struct bssgp_ran_inf_err_rim_cont {
179 enum bssgp_ran_inf_app_id app_id;
180 uint8_t cause;
181 uint8_t prot_ver;
182
183 /* Pointer to (encoded) errornous PDU,
184 * see also: 3GPP TS 48.018, section 11.3.24 */
185 const uint8_t *err_pdu;
186 size_t err_pdu_len;
187
188 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
189 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
190 const uint8_t *son_trans_app_id;
191 size_t son_trans_app_id_len;
192};
193
194int bssgp_dec_ran_inf_err_rim_cont(struct bssgp_ran_inf_err_rim_cont *cont, const uint8_t *buf, size_t len);
195int bssgp_enc_ran_inf_err_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_err_rim_cont *cont);
196
197/* 3GPP TS 48.018, table 11.3.62a.5.b: RAN-INFORMATION-APPLICATION-ERROR RIM Container Contents */
198struct bssgp_ran_inf_app_err_rim_cont {
199 enum bssgp_ran_inf_app_id app_id;
200 uint32_t seq_num;
201 struct bssgp_rim_pdu_ind pdu_ind;
202 uint8_t prot_ver;
203
204 /* Nested application container */
205 union {
206 struct bssgp_app_err_cont_nacc app_err_cont_nacc;
207 /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */
208 } u;
209};
210
211int bssgp_dec_ran_inf_app_err_rim_cont(struct bssgp_ran_inf_app_err_rim_cont *cont, const uint8_t *buf, size_t len);
212int bssgp_enc_ran_inf_app_err_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_app_err_rim_cont *cont);