blob: 7e9efcd76e4eb3305c87298ffbb849de513308fe [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
Philipp Maier7741bc32021-01-07 21:55:48 +010057/* 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 Maier7450f772021-01-06 20:56:43 +010061int bssgp_parse_rim_ri(struct bssgp_rim_routing_info *ri, const uint8_t *buf, unsigned int len);
62int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri);
63
Philipp Maier9828d282021-01-06 20:40:23 +010064/* 3GPP TS 48.018, table 11.3.63.1.1: RAN-INFORMATION-REQUEST Application Container coding for NACC */
65struct bssgp_ran_inf_req_app_cont_nacc {
66 struct osmo_cell_global_id_ps reprt_cell;
67};
68
69int bssgp_dec_ran_inf_req_app_cont_nacc(struct bssgp_ran_inf_req_app_cont_nacc *cont, const uint8_t *buf, size_t len);
70int 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 */
77struct 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
86int bssgp_dec_ran_inf_app_cont_nacc(struct bssgp_ran_inf_app_cont_nacc *cont, const uint8_t *buf, size_t len);
87int 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 */
90enum 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
99/* 3GPP TS 48.018, table 11.3.64.1.a, Application Error Container coding for NACC */
100struct bssgp_app_err_cont_nacc {
101 enum bssgp_nacc_cause nacc_cause;
102
103 /* Pointer to errornous application container */
104 const uint8_t *err_app_cont;
105 size_t err_app_cont_len;
106};
107
108int bssgp_dec_app_err_cont_nacc(struct bssgp_app_err_cont_nacc *cont, const uint8_t *buf, size_t len);
109int bssgp_enc_app_err_cont_nacc(uint8_t *buf, size_t len, const struct bssgp_app_err_cont_nacc *cont);
110
111/* 3GPP TS 48.018, table 11.3.61.b: RIM Application Identity coding */
112enum bssgp_ran_inf_app_id {
113 BSSGP_RAN_INF_APP_ID_NACC = 1,
114 BSSGP_RAN_INF_APP_ID_SI3 = 2,
115 BSSGP_RAN_INF_APP_ID_MBMS = 3,
116 BSSGP_RAN_INF_APP_ID_SON = 4,
117 BSSGP_RAN_INF_APP_ID_UTRA_SI = 5,
118};
119
120/* 3GPP TS 48.018, table 11.3.62a.1.b: RAN-INFORMATION-REQUEST RIM Container Contents */
121struct bssgp_ran_inf_req_rim_cont {
122 enum bssgp_ran_inf_app_id app_id;
123 uint32_t seq_num;
124 struct bssgp_rim_pdu_ind pdu_ind;
125 uint8_t prot_ver;
126
127 /* Nested application container */
128 union {
129 struct bssgp_ran_inf_req_app_cont_nacc app_cont_nacc;
130 /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */
131 } u;
132
133 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
134 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
135 const uint8_t *son_trans_app_id;
136 size_t son_trans_app_id_len;
137};
138
139int bssgp_dec_ran_inf_req_rim_cont(struct bssgp_ran_inf_req_rim_cont *cont, const uint8_t *buf, size_t len);
140int bssgp_enc_ran_inf_req_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_req_rim_cont *cont);
141
142/* 3GPP TS 48.018, table 11.3.62a.2.b: RAN-INFORMATION RIM Container Contents */
143struct bssgp_ran_inf_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 bool app_err;
149
150 /* Nested application container */
151 union {
152 struct bssgp_ran_inf_app_cont_nacc app_cont_nacc;
153 struct bssgp_app_err_cont_nacc app_err_cont_nacc;
154 /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */
155 } u;
156
157 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
158 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
159 const uint8_t *son_trans_app_id;
160 size_t son_trans_app_id_len;
161};
162
163int bssgp_dec_ran_inf_rim_cont(struct bssgp_ran_inf_rim_cont *cont, const uint8_t *buf, size_t len);
164int bssgp_enc_ran_inf_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_rim_cont *cont);
165
166/* 3GPP TS 48.018, table 11.3.62a.3.b: RAN-INFORMATION-ACK RIM Container Contents */
167struct bssgp_ran_inf_ack_rim_cont {
168 enum bssgp_ran_inf_app_id app_id;
169 uint32_t seq_num;
170 uint8_t prot_ver;
171
172 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
173 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
174 const uint8_t *son_trans_app_id;
175 size_t son_trans_app_id_len;
176};
177
178int bssgp_dec_ran_inf_ack_rim_cont(struct bssgp_ran_inf_ack_rim_cont *cont, const uint8_t *buf, size_t len);
179int bssgp_enc_ran_inf_ack_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_ack_rim_cont *cont);
180
181/* 3GPP TS 48.018, table 11.3.62a.4.b: RAN-INFORMATION-ERROR RIM Container Contents */
182struct bssgp_ran_inf_err_rim_cont {
183 enum bssgp_ran_inf_app_id app_id;
184 uint8_t cause;
185 uint8_t prot_ver;
186
187 /* Pointer to (encoded) errornous PDU,
188 * see also: 3GPP TS 48.018, section 11.3.24 */
189 const uint8_t *err_pdu;
190 size_t err_pdu_len;
191
192 /* Pointer to SON-transfer application identity, only present if app_id is indicating "son-transfer",
193 * see also 3GPP TS 48.018, section 11.3.108 and 3GPP TS 36.413 annex B.1.1 */
194 const uint8_t *son_trans_app_id;
195 size_t son_trans_app_id_len;
196};
197
198int bssgp_dec_ran_inf_err_rim_cont(struct bssgp_ran_inf_err_rim_cont *cont, const uint8_t *buf, size_t len);
199int bssgp_enc_ran_inf_err_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_err_rim_cont *cont);
200
201/* 3GPP TS 48.018, table 11.3.62a.5.b: RAN-INFORMATION-APPLICATION-ERROR RIM Container Contents */
202struct bssgp_ran_inf_app_err_rim_cont {
203 enum bssgp_ran_inf_app_id app_id;
204 uint32_t seq_num;
205 struct bssgp_rim_pdu_ind pdu_ind;
206 uint8_t prot_ver;
207
208 /* Nested application container */
209 union {
210 struct bssgp_app_err_cont_nacc app_err_cont_nacc;
211 /* TODO: add containers for Si3, MBMS, SON, UTRA-SI */
212 } u;
213};
214
215int bssgp_dec_ran_inf_app_err_rim_cont(struct bssgp_ran_inf_app_err_rim_cont *cont, const uint8_t *buf, size_t len);
216int bssgp_enc_ran_inf_app_err_rim_cont(uint8_t *buf, size_t len, const struct bssgp_ran_inf_app_err_rim_cont *cont);