blob: 577ba5707b2f719f59b0b9a1fada9617ec5bb919 [file] [log] [blame]
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001/* pcu_l1_if.cpp
2 *
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04003 * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04004 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040014 */
15
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040016#include <stdio.h>
17#include <unistd.h>
Pau Espin Pedrol32499b62019-12-09 13:55:12 +010018#include <inttypes.h>
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040019#include <stdlib.h>
Andreas Eversberg0aed6542012-06-23 10:33:16 +020020#include <string.h>
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040021#include <errno.h>
22#include <assert.h>
Andreas Eversberg0aed6542012-06-23 10:33:16 +020023#include <sys/socket.h>
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040024#include <sys/un.h>
Andreas Eversberg81a12be2013-03-16 16:16:41 +010025#include <arpa/inet.h>
Pau Espin Pedrol754b0932020-03-26 14:47:13 +010026#include <ctype.h>
Max1187a772018-01-26 13:31:42 +010027
Andreas Eversberg0aed6542012-06-23 10:33:16 +020028extern "C" {
29#include <osmocom/core/talloc.h>
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040030#include <osmocom/core/select.h>
31#include <osmocom/core/msgb.h>
Max528ff392016-02-22 11:42:33 +010032#include <osmocom/core/gsmtap_util.h>
33#include <osmocom/core/gsmtap.h>
Max1187a772018-01-26 13:31:42 +010034#include <osmocom/core/bitvec.h>
Alexander Couzens290d9032020-09-16 21:52:02 +020035#include <osmocom/core/sockaddr_str.h>
Max1187a772018-01-26 13:31:42 +010036#include <osmocom/core/logging.h>
37#include <osmocom/core/utils.h>
Alexander Couzens5bece2a2020-10-12 02:27:22 +020038#include <osmocom/gprs/gprs_ns2.h>
Max1187a772018-01-26 13:31:42 +010039#include <osmocom/gsm/l1sap.h>
40#include <osmocom/gsm/protocol/gsm_04_08.h>
Pau Espin Pedrolfe8de452021-02-09 18:47:34 +010041#include <osmocom/gsm/gsm48_rest_octets.h>
Philipp Maiera58ec612021-01-25 23:43:52 +010042#include <osmocom/gsm/sysinfo.h>
Philipp Maier40db4c32023-01-10 12:49:28 +010043#include <osmocom/gsm/gsm0502.h>
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +020044
45#include <nacc_fsm.h>
Philipp Maiereaf5da32023-02-13 13:37:22 +010046#include <pcu_l1_if_phy.h>
Andreas Eversberg0aed6542012-06-23 10:33:16 +020047}
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040048
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040049#include <gprs_rlcmac.h>
50#include <pcu_l1_if.h>
51#include <gprs_debug.h>
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040052#include <gprs_bssgp_pcu.h>
Harald Welte68fc1272016-11-16 22:48:33 +010053#include <osmocom/pcu/pcuif_proto.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020054#include <bts.h>
Max6dc90b82018-02-19 17:17:28 +010055#include <pdch.h>
Pau Espin Pedrolbd9973a2020-09-22 15:57:37 +020056#include <tbf_ul.h>
57#include <tbf_dl.h>
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010058#include <gprs_ms_storage.h>
Andreas Eversberg0aed6542012-06-23 10:33:16 +020059
Andreas Eversberge266bd42012-07-13 14:00:21 +020060extern void *tall_pcu_ctx;
61
Philipp Maier4bac3982023-02-03 16:52:42 +010062struct e1_ccu_conn_pars {
63 struct llist_head entry;
64
65 /* Related air interface */
66 uint8_t bts_nr;
67 uint8_t trx_nr;
68 uint8_t ts_nr;
69
70 /* E1 communication parameter */
71 struct e1_conn_pars e1_conn_pars;
72};
73
74/* List storage to collect E1 connection information that we receive through the pcu_sock. The collected data serves as
75 * a lookup table so that we can lookup the E1 connection information for each PDCH (trx number and timeslot number)
76 * when it is needed. */
77static LLIST_HEAD(e1_ccu_table);
78
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040079/*
80 * PCU messages
81 */
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040082
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +020083/* Can be used to allocate message with non-variable size */
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +040084struct msgb *pcu_msgb_alloc(uint8_t msg_type, uint8_t bts_nr)
85{
86 struct msgb *msg;
87 struct gsm_pcu_if *pcu_prim;
88
89 msg = msgb_alloc(sizeof(struct gsm_pcu_if), "pcu_sock_tx");
90 if (!msg)
91 return NULL;
92 msgb_put(msg, sizeof(struct gsm_pcu_if));
93 pcu_prim = (struct gsm_pcu_if *) msg->data;
94 pcu_prim->msg_type = msg_type;
95 pcu_prim->bts_nr = bts_nr;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040096
97 return msg;
98}
99
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +0200100/* Allocate message with extra size, only reserve pcuif msg hdr */
101static struct msgb *pcu_msgb_alloc_ext_size(uint8_t msg_type, uint8_t bts_nr, size_t extra_size)
102{
103 struct msgb *msg;
104 struct gsm_pcu_if *pcu_prim;
105 msg = msgb_alloc(sizeof(struct gsm_pcu_if) + extra_size, "pcu_sock_tx");
106 /* Only header is filled, caller is responible for reserving + filling
107 * message type specific contents: */
108 msgb_put(msg, PCUIF_HDR_SIZE);
109 pcu_prim = (struct gsm_pcu_if *) msgb_data(msg);
110 pcu_prim->msg_type = msg_type;
111 pcu_prim->bts_nr = bts_nr;
112 return msg;
113}
114
Max0a8fae82017-03-08 18:53:30 +0100115const struct value_string gsm_pcu_if_text_type_names[] = {
116 OSMO_VALUE_STRING(PCU_VERSION),
117 OSMO_VALUE_STRING(PCU_OML_ALERT),
118 { 0, NULL }
119};
120
121int pcu_tx_txt_ind(enum gsm_pcu_if_text_type t, const char *fmt, ...)
122{
123 struct gsm_pcu_if *pcu_prim;
124 struct gsm_pcu_if_txt_ind *txt;
125 va_list ap;
126 char *rep;
127 struct msgb *msg = pcu_msgb_alloc(PCU_IF_MSG_TXT_IND, 0);
128 if (!msg)
129 return -ENOMEM;
130
131 pcu_prim = (struct gsm_pcu_if *) msg->data;
132 txt = &pcu_prim->u.txt_ind;
133 txt->type = t;
134
135 va_start(ap, fmt);
136 rep = talloc_vasprintf(tall_pcu_ctx, fmt, ap);
137 va_end(ap);
138
139 if (!rep)
140 return -ENOMEM;
141
142 osmo_strlcpy(txt->text, rep, TXT_MAX_LEN);
143 talloc_free(rep);
144
145 LOGP(DL1IF, LOGL_INFO, "Sending %s TXT as %s to BTS\n", txt->text,
146 get_value_string(gsm_pcu_if_text_type_names, t));
147
148 return pcu_sock_send(msg);
149}
150
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100151static int pcu_tx_act_req(struct gprs_rlcmac_bts *bts, const struct gprs_rlcmac_pdch *pdch,
152 uint8_t activate)
Ivan Kluchnikov4277f0c2012-04-12 14:24:35 +0400153{
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400154 struct msgb *msg;
155 struct gsm_pcu_if *pcu_prim;
156 struct gsm_pcu_if_act_req *act_req;
157
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100158 LOGPDCH(pdch, DL1IF, LOGL_INFO, "Sending %s request\n",
159 (activate) ? "activate" : "deactivate");
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400160
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100161 msg = pcu_msgb_alloc(PCU_IF_MSG_ACT_REQ, bts->nr);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400162 if (!msg)
163 return -ENOMEM;
164 pcu_prim = (struct gsm_pcu_if *) msg->data;
165 act_req = &pcu_prim->u.act_req;
166 act_req->activate = activate;
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100167 act_req->trx_nr = pdch->trx_no();
168 act_req->ts_nr = pdch->ts_no;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400169
170 return pcu_sock_send(msg);
171}
172
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100173static int pcu_tx_data_req(struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts, uint8_t sapi,
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400174 uint16_t arfcn, uint32_t fn, uint8_t block_nr, uint8_t *data,
175 uint8_t len)
176{
177 struct msgb *msg;
178 struct gsm_pcu_if *pcu_prim;
179 struct gsm_pcu_if_data *data_req;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100180 int current_fn = bts_current_frame_number(bts);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400181
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100182 LOGP(DL1IF, LOGL_DEBUG, "(bts=%u,trx=%u,ts=%u) FN=%u Sending data request: sapi=%d "
183 "arfcn=%d cur_fn=%d block=%d data=%s\n", bts->nr, trx, ts, fn, sapi,
184 arfcn, current_fn, block_nr, osmo_hexdump(data, len));
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400185
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100186 msg = pcu_msgb_alloc(PCU_IF_MSG_DATA_REQ, bts->nr);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400187 if (!msg)
188 return -ENOMEM;
189 pcu_prim = (struct gsm_pcu_if *) msg->data;
190 data_req = &pcu_prim->u.data_req;
191
192 data_req->sapi = sapi;
193 data_req->fn = fn;
194 data_req->arfcn = arfcn;
195 data_req->trx_nr = trx;
196 data_req->ts_nr = ts;
197 data_req->block_nr = block_nr;
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200198 if (len)
199 memcpy(data_req->data, data, len);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400200 data_req->len = len;
201
202 return pcu_sock_send(msg);
203}
204
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100205void pcu_l1if_tx_pdtch(msgb *msg, struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts, uint16_t arfcn,
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400206 uint32_t fn, uint8_t block_nr)
207{
Maxb216c6b2017-09-01 11:00:39 +0200208#ifdef ENABLE_DIRECT_PHY
Max528ff392016-02-22 11:42:33 +0100209 if (bts->trx[trx].fl1h) {
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200210 if (!msg) /* Simply skip sending idle frames to L1 */
211 return;
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100212 l1if_pdch_req(bts->trx[trx].fl1h, ts, 0, fn, arfcn, block_nr,
213 msg->data, msg->len);
Max528ff392016-02-22 11:42:33 +0100214 msgb_free(msg);
215 return;
216 }
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100217#endif
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200218 if (!msg) {
219 pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PDTCH, arfcn, fn, block_nr,
220 NULL, 0);
221 return;
222 }
223
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100224 pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PDTCH, arfcn, fn, block_nr,
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100225 msg->data, msg->len);
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200226 msgb_free(msg);
Ivan Kluchnikov4277f0c2012-04-12 14:24:35 +0400227}
228
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100229void pcu_l1if_tx_ptcch(struct gprs_rlcmac_bts *bts,
230 uint8_t trx, uint8_t ts, uint16_t arfcn,
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700231 uint32_t fn, uint8_t block_nr,
232 uint8_t *data, size_t data_len)
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400233{
Vadim Yanitskiyf5dde9f2022-09-30 02:21:59 +0700234 if (data_len && the_pcu->gsmtap_categ_mask & (1 << PCU_GSMTAP_C_DL_PTCCH))
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100235 gsmtap_send(the_pcu->gsmtap, arfcn, ts, GSMTAP_CHANNEL_PTCCH, 0, fn, 0, 0, data, data_len);
Maxcad867e2016-04-21 14:35:55 +0200236#ifdef ENABLE_DIRECT_PHY
Max528ff392016-02-22 11:42:33 +0100237 if (bts->trx[trx].fl1h) {
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200238 if (!data_len) /* Simply skip sending idle frames to L1 */
239 return;
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700240 l1if_pdch_req(bts->trx[trx].fl1h, ts, 1, fn, arfcn, block_nr, data, data_len);
Max528ff392016-02-22 11:42:33 +0100241 return;
242 }
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100243#endif
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200244 if (!data_len) {
245 pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PTCCH, arfcn, fn, block_nr, NULL, 0);
246 return;
247 }
248
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100249 pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PTCCH, arfcn, fn, block_nr, data, data_len);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400250}
251
Philipp Maier6f417622023-02-03 13:11:27 +0100252void pcu_l1if_tx_agch(struct gprs_rlcmac_bts *bts, bitvec *block, int plen)
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400253{
Pau Espin Pedrold752d7c2019-10-07 20:56:48 +0200254 uint8_t data[GSM_MACBLOCK_LEN]; /* prefix PLEN */
255
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400256 /* FIXME: why does OpenBTS has no PLEN and no fill in message? */
257 bitvec_pack(block, data + 1);
258 data[0] = (plen << 2) | 0x01;
Pau Espin Pedrol58543702019-09-30 19:07:16 +0200259
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100260 if (the_pcu->gsmtap_categ_mask & (1 << PCU_GSMTAP_C_DL_AGCH))
261 gsmtap_send(the_pcu->gsmtap, 0, 0, GSMTAP_CHANNEL_AGCH, 0, 0, 0, 0, data, GSM_MACBLOCK_LEN);
Pau Espin Pedrol58543702019-09-30 19:07:16 +0200262
Philipp Maier3b66bbf2023-02-03 15:45:14 +0100263 pcu_tx_data_req(bts, 0, 0, PCU_IF_SAPI_AGCH, 0, 0, 0, data, sizeof(data));
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400264}
265
Philipp Maier41e38472023-03-03 16:04:26 +0100266#define IMSI_DIGITS_FOR_PAGING 3
267void pcu_l1if_tx_pch(struct gprs_rlcmac_bts *bts, bitvec *block, int plen, const char *imsi)
Ivan Kluchnikovc7e7f682012-06-29 22:53:15 +0400268{
Philipp Maier41e38472023-03-03 16:04:26 +0100269 uint8_t data[IMSI_DIGITS_FOR_PAGING + GSM_MACBLOCK_LEN];
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400270
Philipp Maier41e38472023-03-03 16:04:26 +0100271 /* prepend last three IMSI digits (if present) from which BTS/BSC will calculate the paging group */
272 if (imsi && strlen(imsi) >= IMSI_DIGITS_FOR_PAGING)
273 memcpy(data, imsi + strlen(imsi) - IMSI_DIGITS_FOR_PAGING, IMSI_DIGITS_FOR_PAGING);
274 else
275 memset(data, '0', IMSI_DIGITS_FOR_PAGING);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400276
Pau Espin Pedrol8dc09e72019-10-07 20:56:02 +0200277 /* block provided by upper layer comes without first byte (plen),
278 * prepend it manually:
279 */
Philipp Maier41e38472023-03-03 16:04:26 +0100280 OSMO_ASSERT(sizeof(data) >= IMSI_DIGITS_FOR_PAGING + 1 + block->data_len);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400281 data[3] = (plen << 2) | 0x01;
Philipp Maier41e38472023-03-03 16:04:26 +0100282 bitvec_pack(block, data + IMSI_DIGITS_FOR_PAGING + 1);
Pau Espin Pedrol58543702019-09-30 19:07:16 +0200283
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100284 if (the_pcu->gsmtap_categ_mask & (1 << PCU_GSMTAP_C_DL_PCH))
285 gsmtap_send(the_pcu->gsmtap, 0, 0, GSMTAP_CHANNEL_PCH, 0, 0, 0, 0, data + 3, GSM_MACBLOCK_LEN);
Pau Espin Pedrol58543702019-09-30 19:07:16 +0200286
Philipp Maier3b66bbf2023-02-03 15:45:14 +0100287 pcu_tx_data_req(bts, 0, 0, PCU_IF_SAPI_PCH, 0, 0, 0, data, sizeof(data));
Ivan Kluchnikovc7e7f682012-06-29 22:53:15 +0400288}
289
Philipp Maier2353ed42023-02-01 13:51:56 +0100290/* Send a block via the paging channel and require a confirmation by the receiving end */
291void pcu_l1if_tx_pch_dt(struct gprs_rlcmac_bts *bts, bitvec *block, int plen, const char *imsi, uint32_t tlli)
292{
293 /* NOTE: This is in practice only used to transmit IMMEDIATE ASSIGNMENT messages through the paging channel and
294 * it is not guaranteed to work with other message types. The prepended TLLI will be used as an identifier in
295 * the confirmation message. */
296
Philipp Maier07e06d32023-03-07 18:19:08 +0100297 struct gsm_pcu_if_pch_dt pch_dt = { 0 };
Philipp Maier2353ed42023-02-01 13:51:56 +0100298
299 pch_dt.tlli = tlli;
Philipp Maier07e06d32023-03-07 18:19:08 +0100300 if (imsi)
301 OSMO_STRLCPY_ARRAY(pch_dt.imsi, imsi);
Philipp Maier2353ed42023-02-01 13:51:56 +0100302
303 pch_dt.data[0] = (plen << 2) | 0x01;
304 bitvec_pack(block, pch_dt.data + 1);
305
306 pcu_tx_data_req(bts, 0, 0, PCU_IF_SAPI_PCH_DT, 0, 0, 0, (uint8_t*)&pch_dt, sizeof(pch_dt));
307}
308
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +0200309int pcu_tx_neigh_addr_res_req(struct gprs_rlcmac_bts *bts, const struct neigh_cache_entry_key *neigh_key)
310{
311 struct msgb *msg;
312 struct gsm_pcu_if *pcu_prim;
313 struct gsm_pcu_if_neigh_addr_req *naddr_req;
314
315 LOGP(DL1IF, LOGL_DEBUG, "(bts=%u) Tx Neighbor Address Resolution Request: " NEIGH_CACHE_ENTRY_KEY_FMT "\n",
316 bts->nr, NEIGH_CACHE_ENTRY_KEY_ARGS(neigh_key));
317
318 msg = pcu_msgb_alloc_ext_size(PCU_IF_MSG_CONTAINER, bts->nr, sizeof(struct gsm_pcu_if_neigh_addr_req));
319 if (!msg)
320 return -ENOMEM;
321 pcu_prim = (struct gsm_pcu_if *) msgb_data(msg);
322 naddr_req = (struct gsm_pcu_if_neigh_addr_req *)&pcu_prim->u.container.data[0];
323
324 msgb_put(msg, sizeof(pcu_prim->u.container) + sizeof(struct gsm_pcu_if_neigh_addr_req));
325 pcu_prim->u.container.msg_type = PCU_IF_MSG_NEIGH_ADDR_REQ;
326 osmo_store16be(sizeof(struct gsm_pcu_if_neigh_addr_req), &pcu_prim->u.container.length);
327
328 osmo_store16be(neigh_key->local_lac, &naddr_req->local_lac);
329 osmo_store16be(neigh_key->local_ci, &naddr_req->local_ci);
330 osmo_store16be(neigh_key->tgt_arfcn, &naddr_req->tgt_arfcn);
331 naddr_req->tgt_bsic = neigh_key->tgt_bsic;
332
333 return pcu_sock_send(msg);
334}
335
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100336void pcu_rx_block_time(struct gprs_rlcmac_bts *bts, uint16_t arfcn, uint32_t fn, uint8_t ts_no)
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200337{
Pau Espin Pedrolfecab502021-03-17 15:26:37 +0100338 bts_set_current_block_frame_number(bts, fn);
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200339}
340
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100341int pcu_rx_data_ind_pdtch(struct gprs_rlcmac_bts *bts, struct gprs_rlcmac_pdch *pdch, uint8_t *data,
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +0200342 uint8_t len, uint32_t fn, struct pcu_l1_meas *meas)
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100343{
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +0100344 int rc;
345
Pau Espin Pedrol3bbb3cc2021-08-31 14:09:42 +0200346 if (!pdch->is_enabled()) {
347 LOGPDCH(pdch, DL1IF, LOGL_INFO, "Received DATA.ind (PDTCH) on disabled TS\n");
348 return -EINVAL;
349 }
350
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +0100351 rc = pdch->rcv_block(data, len, fn, meas);
352 pdch_ulc_expire_fn(pdch->ulc, fn);
353 return rc;
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100354}
355
Pau Espin Pedrol86f4c092021-06-08 18:53:40 +0200356static int list_arfcn(const struct gprs_rlcmac_bts *bts, const struct gsm_sysinfo_freq *freq, const char *text)
357{
358 int n = 0, i;
359 for (i = 0; i < 1024; i++) {
360 if (freq[i].mask) {
361 if (!n)
362 LOGP(DL1IF, LOGL_INFO, "BTS%d: %s", bts->nr, text);
363 LOGPC(DL1IF, LOGL_INFO, " %d", i);
364 n++;
365 }
366 }
367 if (n)
368 LOGPC(DL1IF, LOGL_INFO, "\n");
369
370 return n;
371}
372
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100373static int pcu_rx_data_ind_bcch(struct gprs_rlcmac_bts *bts, uint8_t *data, uint8_t len)
Max84bf0fa2017-09-01 11:02:40 +0200374{
Pau Espin Pedrol86f4c092021-06-08 18:53:40 +0200375 struct gsm48_system_information_type_2 *si2;
Pau Espin Pedrolfe8de452021-02-09 18:47:34 +0100376 const uint8_t *si_ro;
Pau Espin Pedrol86f4c092021-06-08 18:53:40 +0200377
Philipp Maiera58ec612021-01-25 23:43:52 +0100378 switch (len) {
379 case 0:
380 /* Due to historical reasons also accept a completely empty message as
381 * revoke command for SI13. */
382 LOGP(DL1IF, LOGL_ERROR,
383 "Received PCU data indication that contains no data -- Revoked SI13.\n");
Max84bf0fa2017-09-01 11:02:40 +0200384 bts->si13_is_set = false;
Max84bf0fa2017-09-01 11:02:40 +0200385
Philipp Maiera58ec612021-01-25 23:43:52 +0100386 return 0;
387 case 1:
388 /* Revoke SI, type is identified by a single byte which is coded after
389 * enum osmo_sysinfo_type. */
390 switch (data[0]) {
391 case SYSINFO_TYPE_1:
392 bts->si1_is_set = false;
393 break;
Pau Espin Pedrol86f4c092021-06-08 18:53:40 +0200394 case SYSINFO_TYPE_2:
395 bts->si2_is_set = false;
396 break;
Philipp Maiera58ec612021-01-25 23:43:52 +0100397 case SYSINFO_TYPE_3:
398 bts->si3_is_set = false;
399 break;
400 case SYSINFO_TYPE_13:
401 bts->si13_is_set = false;
402 break;
403 default:
404 LOGP(DL1IF, LOGL_ERROR,
405 "Received PCU data indication that contains an unsupported system information identifier (%02x,OSMO) -- ignored.\n", data[0]);
406 return -EINVAL;
407 }
408 LOGP(DPCU, LOGL_DEBUG,
409 "Received PCU data indication: Revoked SI%s\n",
410 get_value_string(osmo_sitype_strs, data[0]));
411 return 0;
412 case GSM_MACBLOCK_LEN:
413 /* Update SI, type is identified by the RR sysinfo type, which is the
414 * 3rd byte in the buffer. */
415 switch (data[2]) {
416 case GSM48_MT_RR_SYSINFO_1:
417 memcpy(bts->si1, data, GSM_MACBLOCK_LEN);
418 bts->si1_is_set = true;
419 break;
Pau Espin Pedrol86f4c092021-06-08 18:53:40 +0200420 case GSM48_MT_RR_SYSINFO_2:
421 memcpy(bts->si2, data, GSM_MACBLOCK_LEN);
422 bts->si2_is_set = true;
423 si2 = (struct gsm48_system_information_type_2 *)bts->si2;
424 gsm48_decode_freq_list(bts->si2_bcch_cell_list, si2->bcch_frequency_list,
425 sizeof(si2->bcch_frequency_list), 0xce, 1);
426 list_arfcn(bts, bts->si2_bcch_cell_list, "SI2 Neighbour cells in same band:");
427 break;
Philipp Maiera58ec612021-01-25 23:43:52 +0100428 case GSM48_MT_RR_SYSINFO_3:
429 memcpy(bts->si3, data, GSM_MACBLOCK_LEN);
430 bts->si3_is_set = true;
431 break;
432 case GSM48_MT_RR_SYSINFO_13:
433 memcpy(bts->si13, data, GSM_MACBLOCK_LEN);
434 bts->si13_is_set = true;
Pau Espin Pedrolfe8de452021-02-09 18:47:34 +0100435 si_ro = ((struct gsm48_system_information_type_13*)data)->rest_octets;
Pau Espin Pedrold65bd9d2021-06-01 16:43:41 +0200436 if (osmo_gsm48_rest_octets_si13_decode(&bts->si13_ro_decoded, si_ro) < 0)
Pau Espin Pedrolfe8de452021-02-09 18:47:34 +0100437 LOGP(DPCU, LOGL_ERROR, "Error decoding SI13\n");
Philipp Maiera58ec612021-01-25 23:43:52 +0100438 break;
439 default:
440 LOGP(DL1IF, LOGL_ERROR,
441 "Received PCU data indication that contains an unsupported system information identifier (%02x,RR) -- ignored.\n", data[2]);
442 return -EINVAL;
443 }
444 LOGP(DPCU, LOGL_DEBUG,
445 "Received PCU data indication: Updated %s: %s\n",
446 gsm48_pdisc_msgtype_name(data[1], data[2]),
447 osmo_hexdump_nospc(data + 1, GSM_MACBLOCK_LEN));
448 return 0;
449 default:
450 LOGP(DL1IF, LOGL_ERROR,
451 "Received PCU data indication with unexpected data length: %u -- ignored.\n",
452 len);
Max84bf0fa2017-09-01 11:02:40 +0200453 return -EINVAL;
454 }
Max84bf0fa2017-09-01 11:02:40 +0200455}
456
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100457static int pcu_rx_data_ind(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_data *data_ind)
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400458{
Max528ff392016-02-22 11:42:33 +0100459 int rc;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100460 int current_fn = bts_current_frame_number(bts);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100461 struct pcu_l1_meas meas = {0};
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100462 struct gprs_rlcmac_pdch *pdch;
Pau Espin Pedrol72e39562020-06-30 17:57:42 +0200463 uint8_t gsmtap_chantype;
Maxb216c6b2017-09-01 11:00:39 +0200464
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100465 LOGP(DL1IF, LOGL_DEBUG, "(bts=%" PRIu8 ",trx=%" PRIu8 ",ts=%" PRIu8 ") FN=%u "
466 "Rx DATA.ind: sapi=%d arfcn=%d cur_fn=%d "
467 "block=%d data=%s\n", bts->nr, data_ind->trx_nr, data_ind->ts_nr,
468 data_ind->fn, data_ind->sapi, data_ind->arfcn, current_fn,
469 data_ind->block_nr, osmo_hexdump(data_ind->data, data_ind->len));
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400470
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400471 switch (data_ind->sapi) {
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400472 case PCU_IF_SAPI_PDTCH:
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100473 pdch = &bts->trx[data_ind->trx_nr].pdch[data_ind->ts_nr];
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100474 pcu_l1_meas_set_rssi(&meas, data_ind->rssi);
Maxb216c6b2017-09-01 11:00:39 +0200475 /* convert BER to % value */
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100476 pcu_l1_meas_set_ber(&meas, data_ind->ber10k / 100);
477 pcu_l1_meas_set_bto(&meas, data_ind->ta_offs_qbits);
478 pcu_l1_meas_set_link_qual(&meas, data_ind->lqual_cb / 10);
Vadim Yanitskiyf17dfc02019-07-09 16:16:35 +0700479
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100480 LOGPDCH(pdch, DL1IF, LOGL_DEBUG, "FN=%u Rx DATA.ind PDTCH: "
481 "BER10k = %d, BTO = %d, Q = %d\n", data_ind->fn,
482 data_ind->ber10k, data_ind->ta_offs_qbits, data_ind->lqual_cb);
Vadim Yanitskiyf17dfc02019-07-09 16:16:35 +0700483
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100484 rc = pcu_rx_data_ind_pdtch(bts, pdch, data_ind->data, data_ind->len,
485 data_ind->fn, &meas);
Pau Espin Pedrol72e39562020-06-30 17:57:42 +0200486 gsmtap_chantype = GSMTAP_CHANNEL_PDTCH;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400487 break;
Max84bf0fa2017-09-01 11:02:40 +0200488 case PCU_IF_SAPI_BCCH:
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100489 rc = pcu_rx_data_ind_bcch(bts, data_ind->data, data_ind->len);
Pau Espin Pedrol72e39562020-06-30 17:57:42 +0200490 gsmtap_chantype = GSMTAP_CHANNEL_BCCH;
Max84bf0fa2017-09-01 11:02:40 +0200491 break;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400492 default:
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100493 LOGP(DL1IF, LOGL_ERROR, "(bts=%" PRIu8 ",trx=%" PRIu8 ",ts=%" PRIu8 ") "
494 "FN=%u Rx DATA.ind with unsupported sapi %d\n",
495 bts->nr, data_ind->trx_nr, data_ind->ts_nr, data_ind->fn, data_ind->sapi);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400496 rc = -EINVAL;
Pau Espin Pedrol72e39562020-06-30 17:57:42 +0200497 gsmtap_chantype = GSMTAP_CHANNEL_UNKNOWN;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400498 }
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400499
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100500 if (rc < 0 && (the_pcu->gsmtap_categ_mask & (1 <<PCU_GSMTAP_C_UL_UNKNOWN))) {
501 gsmtap_send(the_pcu->gsmtap, data_ind->arfcn | GSMTAP_ARFCN_F_UPLINK, data_ind->ts_nr,
Pau Espin Pedrol72e39562020-06-30 17:57:42 +0200502 gsmtap_chantype, 0, data_ind->fn, meas.rssi, meas.link_qual, data_ind->data, data_ind->len);
Harald Welte717cdf52017-07-21 21:56:23 +0200503 }
504
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400505 return rc;
506}
507
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100508static int pcu_rx_data_cnf(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_data *data_cnf)
Andreas Eversberga9be1542012-09-27 09:23:24 +0200509{
510 int rc = 0;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100511 int current_fn = bts_current_frame_number(bts);
Andreas Eversberga9be1542012-09-27 09:23:24 +0200512
Philipp Maier7e8e3972018-04-10 13:31:45 +0200513 LOGP(DL1IF, LOGL_DEBUG, "Data confirm received: sapi=%d fn=%d cur_fn=%d\n",
514 data_cnf->sapi, data_cnf->fn, current_fn);
Andreas Eversberga9be1542012-09-27 09:23:24 +0200515
516 switch (data_cnf->sapi) {
517 case PCU_IF_SAPI_PCH:
Pau Espin Pedrolf510f5b2022-10-14 16:37:18 +0200518 if (data_cnf->data[2] == GSM48_MT_RR_IMM_ASS)
Philipp Maier7c3fd982023-02-01 16:10:52 +0100519 bts_rcv_imm_ass_cnf(bts, data_cnf->data, GSM_RESERVED_TMSI, data_cnf->fn);
Andreas Eversberga9be1542012-09-27 09:23:24 +0200520 break;
521 default:
522 LOGP(DL1IF, LOGL_ERROR, "Received PCU data confirm with "
523 "unsupported sapi %d\n", data_cnf->sapi);
524 rc = -EINVAL;
525 }
526
527 return rc;
528}
529
Philipp Maier7c3fd982023-02-01 16:10:52 +0100530static int pcu_rx_data_cnf_dt(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_data_cnf_dt *data_cnf_dt)
531{
532 int rc = 0;
533 int current_fn = bts_current_frame_number(bts);
534
535 LOGP(DL1IF, LOGL_DEBUG, "Data confirm received: sapi=%d fn=%d cur_fn=%d\n",
536 data_cnf_dt->sapi, data_cnf_dt->fn, current_fn);
537
538 switch (data_cnf_dt->sapi) {
539 case PCU_IF_SAPI_PCH:
540 bts_rcv_imm_ass_cnf(bts, NULL, data_cnf_dt->tlli, data_cnf_dt->fn);
541 break;
542 default:
543 LOGP(DL1IF, LOGL_ERROR, "Received PCU data confirm with unsupported sapi %d\n", data_cnf_dt->sapi);
544 rc = -EINVAL;
545 }
546
547 return rc;
548}
549
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100550// FIXME: remove this, when changed from c++ to c.
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100551int pcu_rx_rts_req_pdtch(struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts,
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100552 uint32_t fn, uint8_t block_nr)
553{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100554 return gprs_rlcmac_rcv_rts_block(bts,
Max878bd1f2016-07-20 13:05:05 +0200555 trx, ts, fn, block_nr);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100556}
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100557int pcu_rx_rts_req_ptcch(struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts,
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700558 uint32_t fn, uint8_t block_nr)
559{
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700560 struct gprs_rlcmac_pdch *pdch;
561
562 /* Prevent buffer overflow */
563 if (trx >= ARRAY_SIZE(bts->trx) || ts >= 8)
564 return -EINVAL;
565
566 /* Make sure PDCH time-slot is enabled */
567 pdch = &bts->trx[trx].pdch[ts];
Pau Espin Pedrol9c2512a2022-04-01 18:27:04 +0200568 if (!pdch_is_enabled(pdch))
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700569 return -EAGAIN;
570
Pau Espin Pedroleeae7762021-09-20 11:20:09 +0200571 /* If there's no TBF attached to this PDCH, we can skip Tx of PTCCH
572 * since there's nothing worthy of being transmitted. This way BTS can
573 * identify idle blocks and send nothing or dumy blocks with reduced
574 * energy for the sake of energy saving.
575 */
576 const unsigned num_tbfs = pdch->num_tbfs(GPRS_RLCMAC_DL_TBF)
577 + pdch->num_tbfs(GPRS_RLCMAC_UL_TBF);
578 bool skip_idle = (num_tbfs == 0);
579#ifdef ENABLE_DIRECT_PHY
580 /* In DIRECT_PHY mode we want to always submit something to L1 in
581 * TRX0, since BTS is not preparing dummy bursts on idle TS for us: */
582 skip_idle = skip_idle && trx != 0;
583#endif
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200584 if (skip_idle) {
585 pcu_l1if_tx_ptcch(bts, trx, ts, bts->trx[trx].arfcn, fn, block_nr,
586 NULL, 0);
Pau Espin Pedroleeae7762021-09-20 11:20:09 +0200587 return 0;
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200588 }
Pau Espin Pedroleeae7762021-09-20 11:20:09 +0200589
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100590 pcu_l1if_tx_ptcch(bts, trx, ts, bts->trx[trx].arfcn, fn, block_nr,
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700591 pdch->ptcch_msg, GSM_MACBLOCK_LEN);
592 return 0;
593}
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100594
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100595static int pcu_rx_rts_req(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_rts_req *rts_req)
Ivan Kluchnikov5310d452012-04-17 22:00:31 +0400596{
597 int rc = 0;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100598 int current_fn = bts_current_frame_number(bts);
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100599 const struct gprs_rlcmac_pdch *pdch;
600 pdch = &bts->trx[rts_req->trx_nr].pdch[rts_req->ts_nr];
Ivan Kluchnikov5310d452012-04-17 22:00:31 +0400601
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100602 LOGPDCH(pdch, DL1IF, LOGL_DEBUG, "FN=%u RX RTS.req: sapi=%d "
603 "arfcn=%d cur_fn=%d block=%d\n", rts_req->fn,
604 rts_req->sapi, rts_req->arfcn, current_fn, rts_req->block_nr);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400605
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400606 switch (rts_req->sapi) {
607 case PCU_IF_SAPI_PDTCH:
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100608 pcu_rx_rts_req_pdtch(bts, rts_req->trx_nr, rts_req->ts_nr,
Max878bd1f2016-07-20 13:05:05 +0200609 rts_req->fn, rts_req->block_nr);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400610 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400611 case PCU_IF_SAPI_PTCCH:
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100612 pcu_rx_rts_req_ptcch(bts, rts_req->trx_nr, rts_req->ts_nr,
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700613 rts_req->fn, rts_req->block_nr);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400614 break;
615 default:
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100616 LOGP(DL1IF, LOGL_ERROR, "(bts=%u,trx=%u,ts=%u) FN=%u RX RTS.req with "
617 "unsupported sapi %d\n", bts->nr, rts_req->trx_nr, rts_req->ts_nr,
618 rts_req->fn, rts_req->sapi);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400619 rc = -EINVAL;
620 }
621
622 return rc;
623}
624
Philipp Maier0cb3b2a2023-02-27 15:11:29 +0100625/* C -> C++ adapter for direct PHY access code (e.g. osmo-bts-sysmo) */
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100626extern "C" int pcu_rx_rach_ind_ptcch(struct gprs_rlcmac_bts *bts, uint8_t trx_nr, uint8_t ts_nr, uint32_t fn, int16_t qta)
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700627{
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700628 struct rach_ind_params rip = {
629 /* The content of RA is not of interest on PTCCH/U */
630 .burst_type = GSM_L1_BURST_TYPE_ACCESS_0,
631 .is_11bit = false,
632 .ra = 0x00,
633 .trx_nr = trx_nr,
634 .ts_nr = ts_nr,
635 .rfn = fn,
636 .qta = qta,
637 };
638
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100639 return bts_rcv_ptcch_rach(bts, &rip);
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700640}
641
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100642static int pcu_rx_rach_ind(struct gprs_rlcmac_bts *bts, const struct gsm_pcu_if_rach_ind *rach_ind)
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400643{
644 int rc = 0;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100645 int current_fn = bts_current_frame_number(bts);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400646
647 LOGP(DL1IF, LOGL_INFO, "RACH request received: sapi=%d "
Vadim Yanitskiyb30f28f2020-03-29 19:01:58 +0700648 "qta=%d, ra=0x%02x, fn=%u, cur_fn=%d, is_11bit=%d\n", rach_ind->sapi, rach_ind->qta,
Philipp Maier7e8e3972018-04-10 13:31:45 +0200649 rach_ind->ra, rach_ind->fn, current_fn, rach_ind->is_11bit);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400650
Philipp Maier40db4c32023-01-10 12:49:28 +0100651 if (OSMO_UNLIKELY(rach_ind->fn > GSM_TDMA_HYPERFRAME - 1)) {
652 LOGP(DL1IF, LOGL_ERROR, "RACH request contains fn=%u that exceeds valid limits (0-%u) -- ignored!\n",
653 rach_ind->fn, GSM_TDMA_HYPERFRAME - 1);
654 return -EINVAL;
655 }
656
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700657 struct rach_ind_params rip = {
658 .burst_type = (enum ph_burst_type) rach_ind->burst_type,
659 .is_11bit = rach_ind->is_11bit > 0,
660 .ra = rach_ind->ra,
661 .trx_nr = rach_ind->trx_nr,
662 .ts_nr = rach_ind->ts_nr,
663 .rfn = rach_ind->fn,
664 .qta = rach_ind->qta,
665 };
666
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400667 switch (rach_ind->sapi) {
668 case PCU_IF_SAPI_RACH:
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100669 rc = bts_rcv_rach(bts, &rip);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400670 break;
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700671 case PCU_IF_SAPI_PTCCH:
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100672 rc = bts_rcv_ptcch_rach(bts, &rip);
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700673 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400674 default:
675 LOGP(DL1IF, LOGL_ERROR, "Received PCU rach request with "
676 "unsupported sapi %d\n", rach_ind->sapi);
677 rc = -EINVAL;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400678 }
679
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400680 return rc;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400681}
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200682
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200683static int pcu_info_ind_ns(struct gprs_rlcmac_bts *bts,
684 const struct gsm_pcu_if_info_ind *info_ind)
685{
686 struct osmo_sockaddr remote[PCU_IF_NUM_NSVC] = { };
687 struct osmo_sockaddr local[PCU_IF_NUM_NSVC] = { };
688 uint16_t nsvci[PCU_IF_NUM_NSVC] = { };
689 uint16_t valid = 0;
690
691 for (unsigned int i = 0; i < PCU_IF_NUM_NSVC; i++) {
692 struct osmo_sockaddr_str sockstr;
693
694 switch (info_ind->address_type[i]) {
695 case PCU_IF_ADDR_TYPE_IPV4:
696 local[i].u.sin.sin_family = AF_INET;
697 local[i].u.sin.sin_addr.s_addr = INADDR_ANY;
698 local[i].u.sin.sin_port = htons(info_ind->local_port[i]);
699
700 remote[i].u.sin.sin_family = AF_INET;
Alexander Couzens87c6dd32020-10-27 13:24:40 +0100701 memcpy(&remote[i].u.sin.sin_addr, &info_ind->remote_ip[i].v4,
702 sizeof(struct in_addr));
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200703 remote[i].u.sin.sin_port = htons(info_ind->remote_port[i]);
704 break;
705 case PCU_IF_ADDR_TYPE_IPV6:
706 local[i].u.sin6.sin6_family = AF_INET6;
707 local[i].u.sin6.sin6_addr = in6addr_any;
708 local[i].u.sin6.sin6_port = htons(info_ind->local_port[i]);
709
710 remote[i].u.sin6.sin6_family = AF_INET6;
Alexander Couzens87c6dd32020-10-27 13:24:40 +0100711 memcpy(&remote[i].u.sin6.sin6_addr,
712 &info_ind->remote_ip[i].v6,
713 sizeof(struct in6_addr));
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200714 remote[i].u.sin6.sin6_port = htons(info_ind->remote_port[i]);
715 break;
716 default:
717 continue;
718 }
719 nsvci[i] = info_ind->nsvci[i];
720
721 LOGP(DL1IF, LOGL_DEBUG, " NS%u nsvci=%u\n", i, nsvci[i]);
722 if (osmo_sockaddr_str_from_sockaddr(&sockstr, &remote[i].u.sas))
723 strcpy(sockstr.ip, "invalid");
724
725 LOGP(DL1IF, LOGL_DEBUG, " NS%u address: r=%s:%u<->l=NULL:%u\n",
726 i, sockstr.ip, sockstr.port, info_ind->local_port[i]);
727
728 valid |= 1 << i;
729 }
730
731 if (valid == 0) {
732 LOGP(DL1IF, LOGL_ERROR, "No NSVC available to connect to the SGSN!\n");
733 return -EINVAL;
734 }
735
Alexander Couzens94a367f2021-02-16 16:57:15 +0100736 return gprs_ns_update_config(bts, info_ind->nsei, local, remote, nsvci, valid);
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200737}
738
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100739static int pcu_rx_info_ind(struct gprs_rlcmac_bts *bts, const struct gsm_pcu_if_info_ind *info_ind)
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200740{
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +0200741 struct gprs_bssgp_pcu *pcu;
Harald Weltebb47d952016-11-17 18:40:02 +0100742 int rc = 0;
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700743 unsigned int trx_nr, ts_nr;
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100744 unsigned int i;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200745
Philipp Maierc82c9482023-03-03 11:39:00 +0100746 if (llist_count(&the_pcu->bts_list) > 1)
747 LOGP(DL1IF, LOGL_ERROR, "more than one BTS regsitered at this PCU. This PCU has only been tested with one BTS! OS#5930\n");
748
Philipp Maier2353ed42023-02-01 13:51:56 +0100749 LOGP(DL1IF, LOGL_DEBUG, "Info indication received:\n");
750
751 /* NOTE: The classic way to confirm an IMMEDIATE assignment is to send the whole MAC block payload back to the
752 * PCU. So it is the MAC block itsself that serves a reference for the confirmation. This method has certain
753 * disadvantages so it was replaced with a method that uses the TLLI as a reference ("Direct TLLI"). This new
754 * method will replace the old one. The code that handles the old method will be removed in the foreseeable
755 * future. (see also OS#5927) */
756 if (info_ind->version == 0x0a) {
757 LOGP(DL1IF, LOGL_NOTICE, "PCUIF version 10 is deprecated. OS#5927\n");
758 } else if (info_ind->version != PCU_IF_VERSION) {
759 fprintf(stderr, "PCU interface version number of BTS/BSC (%u) is different (%u).\nPlease use a BTS/BSC with a compatble interface!\n",
Andreas Eversberg8389fd02012-07-18 10:06:48 +0200760 info_ind->version, PCU_IF_VERSION);
761 exit(-1);
762 }
763
Philipp Maier2353ed42023-02-01 13:51:56 +0100764 the_pcu->pcu_if_version = info_ind->version;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200765
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400766 if (!(info_ind->flags & PCU_IF_FLAG_ACTIVE)) {
767 LOGP(DL1IF, LOGL_NOTICE, "BTS not available\n");
Stefan Sperling5b22fb72018-02-14 19:46:33 +0100768 if (!bts->active)
769 return -EAGAIN;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400770bssgp_failed:
Stefan Sperling5b22fb72018-02-14 19:46:33 +0100771 bts->active = false;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400772 /* free all TBF */
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700773 for (trx_nr = 0; trx_nr < ARRAY_SIZE(bts->trx); trx_nr++) {
774 bts->trx[trx_nr].arfcn = info_ind->trx[trx_nr].arfcn;
775 for (ts_nr = 0; ts_nr < ARRAY_SIZE(bts->trx[0].pdch); ts_nr++)
Pau Espin Pedrol2d92e392022-03-30 22:09:06 +0200776 if (bts->trx[trx_nr].pdch[ts_nr].is_enabled())
777 bts->trx[trx_nr].pdch[ts_nr].disable();
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400778 }
Alexander Couzens290d9032020-09-16 21:52:02 +0200779 gprs_bssgp_destroy(bts);
Daniel Willmann6d8884d2014-06-04 18:30:59 +0200780 exit(0);
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200781 }
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400782 LOGP(DL1IF, LOGL_INFO, "BTS available\n");
Neels Hofmeyrbdc55fa2018-02-21 00:39:07 +0100783 LOGP(DL1IF, LOGL_DEBUG, " mcc=%03u\n", info_ind->mcc);
784 LOGP(DL1IF, LOGL_DEBUG, " mnc=%0*u\n", info_ind->mnc_3_digits, info_ind->mnc);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400785 LOGP(DL1IF, LOGL_DEBUG, " lac=%d\n", info_ind->lac);
786 LOGP(DL1IF, LOGL_DEBUG, " rac=%d\n", info_ind->rac);
Harald Welte1473b372019-03-21 19:48:55 +0100787 LOGP(DL1IF, LOGL_DEBUG, " cell_id=%d\n", info_ind->cell_id);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100788 LOGP(DL1IF, LOGL_DEBUG, " bsic=%d\n", info_ind->bsic);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400789 LOGP(DL1IF, LOGL_DEBUG, " nsei=%d\n", info_ind->nsei);
790 LOGP(DL1IF, LOGL_DEBUG, " nse_timer=%d %d %d %d %d %d %d\n",
791 info_ind->nse_timer[0], info_ind->nse_timer[1],
792 info_ind->nse_timer[2], info_ind->nse_timer[3],
793 info_ind->nse_timer[4], info_ind->nse_timer[5],
794 info_ind->nse_timer[6]);
795 LOGP(DL1IF, LOGL_DEBUG, " cell_timer=%d %d %d %d %d %d %d %d %d %d "
796 "%d\n",
797 info_ind->cell_timer[0], info_ind->cell_timer[1],
798 info_ind->cell_timer[2], info_ind->cell_timer[3],
799 info_ind->cell_timer[4], info_ind->cell_timer[5],
800 info_ind->cell_timer[6], info_ind->cell_timer[7],
801 info_ind->cell_timer[8], info_ind->cell_timer[9],
802 info_ind->cell_timer[10]);
803 LOGP(DL1IF, LOGL_DEBUG, " repeat_time=%d\n", info_ind->repeat_time);
804 LOGP(DL1IF, LOGL_DEBUG, " repeat_count=%d\n", info_ind->repeat_count);
805 LOGP(DL1IF, LOGL_DEBUG, " bvci=%d\n", info_ind->bvci);
806 LOGP(DL1IF, LOGL_DEBUG, " t3142=%d\n", info_ind->t3142);
807 LOGP(DL1IF, LOGL_DEBUG, " t3169=%d\n", info_ind->t3169);
808 LOGP(DL1IF, LOGL_DEBUG, " t3191=%d\n", info_ind->t3191);
809 LOGP(DL1IF, LOGL_DEBUG, " t3193=%d (ms)\n", info_ind->t3193_10ms * 10);
810 LOGP(DL1IF, LOGL_DEBUG, " t3195=%d\n", info_ind->t3195);
811 LOGP(DL1IF, LOGL_DEBUG, " n3101=%d\n", info_ind->n3101);
812 LOGP(DL1IF, LOGL_DEBUG, " n3103=%d\n", info_ind->n3103);
813 LOGP(DL1IF, LOGL_DEBUG, " n3105=%d\n", info_ind->n3105);
814 LOGP(DL1IF, LOGL_DEBUG, " cv_countdown=%d\n", info_ind->cv_countdown);
815 LOGP(DL1IF, LOGL_DEBUG, " dl_tbf_ext=%d\n", info_ind->dl_tbf_ext);
816 LOGP(DL1IF, LOGL_DEBUG, " ul_tbf_ext=%d\n", info_ind->ul_tbf_ext);
Pau Espin Pedrol2e6b60d2021-01-20 13:48:31 +0100817 bts->cgi_ps.rai.lac.plmn.mcc = info_ind->mcc;
818 bts->cgi_ps.rai.lac.plmn.mnc = info_ind->mnc;
819 bts->cgi_ps.rai.lac.plmn.mnc_3_digits = info_ind->mnc_3_digits;
820 bts->cgi_ps.rai.lac.lac = info_ind->lac;
821 bts->cgi_ps.rai.rac = info_ind->rac;
822 bts->cgi_ps.cell_identity = info_ind->cell_id;
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100823 bts->bsic = info_ind->bsic;
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100824
825 bts->cs_mask = 1 << 0; /* We need at least 1 CS, let's enable CS1 */
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400826 for (i = 0; i < 4; i++) {
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100827 uint8_t allowed = !!(info_ind->flags & (PCU_IF_FLAG_CS1 << i));
828 bts->cs_mask |= allowed << i;
829 if (allowed)
830 LOGP(DL1IF, LOGL_DEBUG, " Use CS%d\n", i + 1);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400831 }
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100832 bts_recalc_max_cs(bts);
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100833
834 bts->mcs_mask = 0;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400835 for (i = 0; i < 9; i++) {
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100836 uint8_t allowed = !!(info_ind->flags & (PCU_IF_FLAG_MCS1 << i));
837 bts->mcs_mask |= allowed << i;
Pau Espin Pedrol87eec1f2020-10-30 18:46:24 +0100838 if (allowed)
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100839 LOGP(DL1IF, LOGL_DEBUG, " Use MCS%d\n", i + 1);
Pau Espin Pedrol87eec1f2020-10-30 18:46:24 +0100840
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400841 }
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100842 bts_recalc_max_mcs(bts);
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100843
Pau Espin Pedrolb47b1372020-11-03 15:59:39 +0100844 LOGP(DL1IF, LOGL_DEBUG, " initial_cs=%u%s\n", info_ind->initial_cs,
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100845 the_pcu->vty.force_initial_cs ? " (VTY forced, ignoring)" : "");
Pau Espin Pedrol793583e2021-01-14 16:20:57 +0100846 bts->pcuif_info_ind.initial_cs = info_ind->initial_cs;
847 bts_recalc_initial_cs(bts);
Pau Espin Pedrolb47b1372020-11-03 15:59:39 +0100848
849 LOGP(DL1IF, LOGL_DEBUG, " initial_mcs=%u%s\n", info_ind->initial_mcs,
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100850 the_pcu->vty.force_initial_mcs ? " (VTY forced, ignoring)" : "");
Pau Espin Pedrol793583e2021-01-14 16:20:57 +0100851 bts->pcuif_info_ind.initial_mcs = info_ind->initial_mcs;
852 bts_recalc_initial_mcs(bts);
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200853
Alexander Couzens290d9032020-09-16 21:52:02 +0200854 pcu = gprs_bssgp_init(
855 bts,
856 info_ind->nsei, info_ind->bvci,
857 info_ind->mcc, info_ind->mnc, info_ind->mnc_3_digits,
858 info_ind->lac, info_ind->rac, info_ind->cell_id);
859 if (!pcu) {
Vadim Yanitskiyc1a726c2020-10-08 22:46:26 +0700860 LOGP(DL1IF, LOGL_ERROR, "Failed to init BSSGP\n");
Alexander Couzens9b5c9602020-07-28 13:47:18 +0200861 goto bssgp_failed;
862 }
863
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200864 rc = pcu_info_ind_ns(pcu->bts, info_ind);
865 if (rc < 0) {
Alexander Couzens290d9032020-09-16 21:52:02 +0200866 LOGP(DL1IF, LOGL_ERROR, "No NSVC available to connect to the SGSN!\n");
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400867 goto bssgp_failed;
868 }
869
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400870 if (info_ind->t3142) { /* if timer values are set */
Pau Espin Pedrol28f160e2019-09-05 14:48:35 +0200871 osmo_tdef_set(bts->T_defs_bts, 3142, info_ind->t3142, OSMO_TDEF_S);
872 osmo_tdef_set(bts->T_defs_bts, 3169, info_ind->t3169, OSMO_TDEF_S);
873 osmo_tdef_set(bts->T_defs_bts, 3191, info_ind->t3191, OSMO_TDEF_S);
874 osmo_tdef_set(bts->T_defs_bts, 3193, info_ind->t3193_10ms * 10, OSMO_TDEF_MS);
875 osmo_tdef_set(bts->T_defs_bts, 3195, info_ind->t3195, OSMO_TDEF_S);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400876 bts->n3101 = info_ind->n3101;
877 bts->n3103 = info_ind->n3103;
878 bts->n3105 = info_ind->n3105;
879 }
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400880
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700881 for (trx_nr = 0; trx_nr < ARRAY_SIZE(bts->trx); trx_nr++) {
882 bts->trx[trx_nr].arfcn = info_ind->trx[trx_nr].arfcn;
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100883 if ((info_ind->flags & PCU_IF_FLAG_SYSMO)
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700884 && info_ind->trx[trx_nr].hlayer1) {
Maxcad867e2016-04-21 14:35:55 +0200885#ifdef ENABLE_DIRECT_PHY
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700886 LOGP(DL1IF, LOGL_DEBUG, " TRX %d hlayer1=%x\n", trx_nr,
887 info_ind->trx[trx_nr].hlayer1);
888 if (!bts->trx[trx_nr].fl1h)
889 bts->trx[trx_nr].fl1h = l1if_open_pdch(
Philipp Maierc82c9482023-03-03 11:39:00 +0100890 bts->nr, trx_nr,
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700891 info_ind->trx[trx_nr].hlayer1,
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100892 the_pcu->gsmtap);
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700893 if (!bts->trx[trx_nr].fl1h) {
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100894 LOGP(DL1IF, LOGL_FATAL, "Failed to open direct "
Philipp Maier0cb3b2a2023-02-27 15:11:29 +0100895 "PHY access for PDCH.\n");
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100896 exit(0);
897 }
898#else
Philipp Maier0cb3b2a2023-02-27 15:11:29 +0100899 LOGP(DL1IF, LOGL_FATAL, "Compiled without direct PHY "
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100900 "access for PDCH, but enabled at "
901 "BTS. Please deactivate it!\n");
902 exit(0);
903#endif
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100904 }
905
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700906 for (ts_nr = 0; ts_nr < ARRAY_SIZE(bts->trx[0].pdch); ts_nr++) {
Philipp Maier2d222a12022-10-27 15:25:31 +0200907 const struct gsm_pcu_if_info_trx_ts *its = &info_ind->trx[trx_nr].ts[ts_nr];
Vadim Yanitskiy0f41b712020-07-24 01:28:13 +0700908 struct gprs_rlcmac_pdch *pdch = &bts->trx[trx_nr].pdch[ts_nr];
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700909 if ((info_ind->trx[trx_nr].pdch_mask & (1 << ts_nr))) {
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400910 /* FIXME: activate dynamically at RLCMAC */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200911 if (!pdch->is_enabled()) {
Maxcad867e2016-04-21 14:35:55 +0200912#ifdef ENABLE_DIRECT_PHY
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100913 if ((info_ind->flags &
914 PCU_IF_FLAG_SYSMO))
915 l1if_connect_pdch(
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700916 bts->trx[trx_nr].fl1h, ts_nr);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100917#endif
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100918 pcu_tx_act_req(bts, pdch, 1);
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200919 pdch->enable();
Andreas Eversberg3b7461c2012-07-20 11:19:59 +0200920 }
Vadim Yanitskiy8e2bd1e2020-07-21 00:54:42 +0700921
922 pdch->tsc = its->tsc;
923
924 /* (Optional) frequency hopping parameters */
Philipp Maier2e490582022-10-27 15:07:57 +0200925 if (its->hopping) {
Vadim Yanitskiy8e2bd1e2020-07-21 00:54:42 +0700926 pdch->fh.enabled = true;
927 pdch->fh.maio = its->maio;
928 pdch->fh.hsn = its->hsn;
929
930 OSMO_ASSERT(its->ma_bit_len <= sizeof(pdch->fh.ma) * 8);
931 pdch->fh.ma_oct_len = OSMO_BYTES_FOR_BITS(its->ma_bit_len);
932 pdch->fh.ma_bit_len = its->ma_bit_len;
933
934 /* Mobile Allocation + padding (byte/bit order as on the wire):
935 * | 00 00 00 00 00 cc bb aa | -> | cc bb aa 00 00 00 00 00 | */
936 unsigned int offset = sizeof(pdch->fh.ma) - pdch->fh.ma_oct_len;
937 memcpy(pdch->fh.ma, its->ma + offset, pdch->fh.ma_oct_len);
938 }
939
940 LOGP(DL1IF, LOGL_INFO, "PDCH (trx=%u, ts=%u): tsc=%u, hopping=%s\n",
941 trx_nr, ts_nr, pdch->tsc, pdch->fh.enabled ? "yes" : "no");
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400942 } else {
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200943 if (pdch->is_enabled()) {
Philipp Maier72ed3332023-02-27 15:32:00 +0100944#ifdef ENABLE_DIRECT_PHY
945 if ((info_ind->flags & PCU_IF_FLAG_SYSMO))
946 l1if_disconnect_pdch(bts->trx[trx_nr].fl1h, ts_nr);
947#endif
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100948 pcu_tx_act_req(bts, pdch, 0);
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200949 pdch->disable();
Andreas Eversberg3b7461c2012-07-20 11:19:59 +0200950 }
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400951 }
952 }
953 }
954
Stefan Sperling5b22fb72018-02-14 19:46:33 +0100955 bts->active = true;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200956 return rc;
957}
958
Philipp Maier4bac3982023-02-03 16:52:42 +0100959/* Query E1 CCU connection parameters by TS and TRX number */
960int pcu_l1if_get_e1_ccu_conn_pars(struct e1_conn_pars **e1_conn_pars, uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
961{
962 struct e1_ccu_conn_pars *e1_ccu_conn_pars;
963
964 llist_for_each_entry(e1_ccu_conn_pars, &e1_ccu_table, entry) {
965 if (e1_ccu_conn_pars->bts_nr == bts_nr && e1_ccu_conn_pars->trx_nr == trx_nr
966 && e1_ccu_conn_pars->ts_nr == ts_nr) {
967 *e1_conn_pars = &e1_ccu_conn_pars->e1_conn_pars;
968 return 0;
969 }
970 }
971
972 return -EINVAL;
973}
974
975/* Allocate a new connection parameter struct and store connection parameters */
976static void new_e1_ccu_conn_pars(const struct gsm_pcu_if_e1_ccu_ind *e1_ccu_ind, uint8_t bts_nr)
977{
978 struct e1_ccu_conn_pars *e1_ccu_conn_pars;
979
980 e1_ccu_conn_pars = talloc_zero(tall_pcu_ctx, struct e1_ccu_conn_pars);
981 OSMO_ASSERT(e1_ccu_conn_pars);
982 e1_ccu_conn_pars->bts_nr = bts_nr;
983 e1_ccu_conn_pars->trx_nr = e1_ccu_ind->trx_nr;
984 e1_ccu_conn_pars->ts_nr = e1_ccu_ind->ts_nr;
985 e1_ccu_conn_pars->e1_conn_pars.e1_nr = e1_ccu_ind->e1_nr;
986 e1_ccu_conn_pars->e1_conn_pars.e1_ts = e1_ccu_ind->e1_ts;
987 e1_ccu_conn_pars->e1_conn_pars.e1_ts_ss = e1_ccu_ind->e1_ts_ss;
988 llist_add(&e1_ccu_conn_pars->entry, &e1_ccu_table);
989}
990
991static int pcu_rx_e1_ccu_ind(struct gprs_rlcmac_bts *bts, const struct gsm_pcu_if_e1_ccu_ind *e1_ccu_ind)
992{
993 struct e1_conn_pars *e1_conn_pars;
994 uint8_t rate;
995 uint8_t subslot_nr;
996 int rc;
997
998 /* only used with log statement below, no technical relevance otherwise. */
999 if (e1_ccu_ind->e1_ts_ss > 3) {
1000 rate = 64;
1001 subslot_nr = 0;
1002 } else {
1003 rate = 16;
1004 subslot_nr = e1_ccu_ind->e1_ts_ss;
1005 }
1006
1007 LOGP(DL1IF, LOGL_NOTICE,
1008 "(ts=%u,trx=%u) new E1 CCU communication parameters for CCU (E1-line:%u, E1-TS:%u, E1-SS:%u, rate:%ukbps)\n",
1009 e1_ccu_ind->ts_nr, e1_ccu_ind->trx_nr, e1_ccu_ind->e1_nr, e1_ccu_ind->e1_ts,
1010 subslot_nr, rate);
1011
1012 /* Search for an existing entry, when found, update it. */
1013 rc = pcu_l1if_get_e1_ccu_conn_pars(&e1_conn_pars, bts->nr, e1_ccu_ind->trx_nr, e1_ccu_ind->ts_nr);
1014 if (rc == 0) {
1015 e1_conn_pars->e1_nr = e1_ccu_ind->e1_nr;
1016 e1_conn_pars->e1_ts = e1_ccu_ind->e1_ts;
1017 e1_conn_pars->e1_ts_ss = e1_ccu_ind->e1_ts_ss;
1018 return 0;
1019 }
1020
1021 /* Create new connection parameter entry */
1022 new_e1_ccu_conn_pars(e1_ccu_ind, bts->nr);
1023 return 0;
1024}
1025
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001026static int pcu_rx_time_ind(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_time_ind *time_ind)
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001027{
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001028 uint8_t fn13 = time_ind->fn % 13;
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001029
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001030 /* omit frame numbers not starting at a MAC block */
1031 if (fn13 != 0 && fn13 != 4 && fn13 != 8)
1032 return 0;
Max3741f142017-06-26 12:10:12 +02001033
1034 LOGP(DL1IF, LOGL_DEBUG, "Time indication received: %d\n", time_ind->fn % 52);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001035
Pau Espin Pedrol30617112021-03-05 18:59:05 +01001036 /* Ignore TIME.ind completely, we nowadays relay on DATA.ind always
1037 * providing all block FNs. */
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001038 return 0;
1039}
1040
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001041static int pcu_rx_pag_req(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_pag_req *pag_req)
Andreas Eversberg2b914642012-07-19 13:06:26 +02001042{
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +02001043 struct osmo_mobile_identity mi;
Pau Espin Pedrolbd542052021-05-13 17:44:51 +02001044 struct GprsMs *ms = NULL;
1045 struct paging_req_cs req = { .chan_needed = pag_req->chan_needed,
1046 .tlli = GSM_RESERVED_TMSI };
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +02001047 int rc;
1048
Andreas Eversberg2b914642012-07-19 13:06:26 +02001049 LOGP(DL1IF, LOGL_DEBUG, "Paging request received: chan_needed=%d "
1050 "length=%d\n", pag_req->chan_needed, pag_req->identity_lv[0]);
1051
Pau Espin Pedrol32499b62019-12-09 13:55:12 +01001052 /* check if identity does not fit: length > sizeof(lv) - 1 */
1053 if (pag_req->identity_lv[0] >= sizeof(pag_req->identity_lv)) {
1054 LOGP(DL1IF, LOGL_ERROR, "Paging identity too large (%" PRIu8 ")\n",
1055 pag_req->identity_lv[0]);
1056 return -EINVAL;
1057 }
1058
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +02001059 rc = osmo_mobile_identity_decode(&mi, &pag_req->identity_lv[1], pag_req->identity_lv[0], true);
1060 if (rc < 0) {
1061 LOGP(DL1IF, LOGL_ERROR, "Failed to decode Mobile Identity in Paging Request (rc=%d)\n", rc);
1062 return -EINVAL;
1063 }
1064
Pau Espin Pedrolbd542052021-05-13 17:44:51 +02001065 switch (mi.type) {
1066 case GSM_MI_TYPE_TMSI:
1067 req.mi_tmsi = mi;
1068 req.mi_tmsi_present = true;
1069 /* TODO: look up MS by TMSI? Derive TLLI? */
1070 break;
1071 case GSM_MI_TYPE_IMSI:
1072 req.mi_imsi = mi;
1073 req.mi_imsi_present = true;
1074 ms = bts_ms_by_imsi(bts, req.mi_imsi.imsi);
1075 break;
1076 default:
1077 LOGP(DL1IF, LOGL_ERROR, "Unexpected MI type %u\n", mi.type);
1078 return -EINVAL;
1079 }
1080
1081 return bts_add_paging(bts, &req, ms);
Andreas Eversberg2b914642012-07-19 13:06:26 +02001082}
1083
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001084static int pcu_rx_susp_req(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_susp_req *susp_req)
Harald Welte3447c4a2017-07-11 00:06:38 +02001085{
Philipp Maiera58ec612021-01-25 23:43:52 +01001086 struct bssgp_bvc_ctx *bctx = the_pcu->bssgp.bctx;
Pau Espin Pedrolbd9973a2020-09-22 15:57:37 +02001087 GprsMs *ms;
1088 struct gprs_rlcmac_dl_tbf *dl_tbf;
1089 struct gprs_rlcmac_ul_tbf *ul_tbf;
Harald Welte3447c4a2017-07-11 00:06:38 +02001090 struct gprs_ra_id ra_id;
1091
1092 gsm48_parse_ra(&ra_id, susp_req->ra_id);
1093
1094 LOGP(DL1IF, LOGL_INFO, "GPRS Suspend request received: TLLI=0x%08x RAI=%s\n",
1095 susp_req->tlli, osmo_rai_name(&ra_id));
1096
Pau Espin Pedrol2182e622021-01-14 16:48:38 +01001097 if ((ms = bts_ms_store(bts)->get_ms(susp_req->tlli))) {
Pau Espin Pedrolbd9973a2020-09-22 15:57:37 +02001098 /* We need to catch both pointers here since MS may become freed
1099 after first tbf_free(dl_tbf) if only DL TBF was available */
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +01001100 dl_tbf = ms_dl_tbf(ms);
1101 ul_tbf = ms_ul_tbf(ms);
Pau Espin Pedrolbd9973a2020-09-22 15:57:37 +02001102 if (dl_tbf)
1103 tbf_free(dl_tbf);
1104 if (ul_tbf)
1105 tbf_free(ul_tbf);
1106 }
1107
Harald Welte3447c4a2017-07-11 00:06:38 +02001108 if (!bctx)
1109 return -1;
1110
1111 return bssgp_tx_suspend(bctx->nsei, susp_req->tlli, &ra_id);
1112}
1113
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001114static int pcu_rx_app_info_req(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_app_info_req *app_info_req)
Oliver Smithcfb63212019-09-05 17:13:33 +02001115{
Pau Espin Pedrol54faf022021-01-14 12:12:43 +01001116 struct llist_head *tmp;
Oliver Smithcfb63212019-09-05 17:13:33 +02001117
1118 LOGP(DL1IF, LOGL_DEBUG, "Application Information Request received: type=0x%08x len=%i\n",
1119 app_info_req->application_type, app_info_req->len);
1120
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001121 bts->app_info_pending = 0;
Pau Espin Pedrol2182e622021-01-14 16:48:38 +01001122 llist_for_each(tmp, bts_ms_store(bts)->ms_list()) {
Pau Espin Pedrol54faf022021-01-14 12:12:43 +01001123 GprsMs *ms = llist_entry(tmp, typeof(*ms), list);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +01001124 if (!ms_dl_tbf(ms))
Oliver Smithcfb63212019-09-05 17:13:33 +02001125 continue;
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001126 bts->app_info_pending++;
Oliver Smithcfb63212019-09-05 17:13:33 +02001127 ms->app_info_pending = true;
1128 }
1129
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001130 if (!bts->app_info_pending) {
Oliver Smithcfb63212019-09-05 17:13:33 +02001131 LOGP(DL1IF, LOGL_NOTICE, "Packet Application Information will not be sent, no subscribers with active"
1132 " TBF\n");
1133 return -1;
1134 }
1135
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001136 if (bts->app_info) {
Oliver Smithcfb63212019-09-05 17:13:33 +02001137 LOGP(DL1IF, LOGL_NOTICE, "Previous Packet Application Information was not sent to all subscribers,"
1138 " overwriting with new one\n");
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001139 msgb_free(bts->app_info);
Oliver Smithcfb63212019-09-05 17:13:33 +02001140 }
1141
1142 LOGP(DL1IF, LOGL_INFO, "Sending Packet Application Information to %i subscribers with active TBF\n",
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001143 bts->app_info_pending);
1144 bts->app_info = gprs_rlcmac_app_info_msg(app_info_req);
Oliver Smithcfb63212019-09-05 17:13:33 +02001145 return 0;
1146}
1147
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +02001148static int pcu_rx_neigh_addr_cnf(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_neigh_addr_cnf *naddr_cnf)
1149{
1150 struct llist_head *tmp;
1151 struct osmo_cell_global_id_ps cgi_ps;
1152 struct osmo_cell_global_id_ps *cgi_ps_ptr = &cgi_ps;
1153
1154 struct neigh_cache_entry_key neigh_key = {
1155 .local_lac = osmo_load16be(&naddr_cnf->orig_req.local_lac),
1156 .local_ci = osmo_load16be(&naddr_cnf->orig_req.local_ci),
1157 .tgt_arfcn = osmo_load16be(&naddr_cnf->orig_req.tgt_arfcn),
1158 .tgt_bsic = naddr_cnf->orig_req.tgt_bsic,
1159 };
1160
1161 if (naddr_cnf->err_code == 0) {
1162 cgi_ps.rai.lac.plmn.mcc = osmo_load16be(&naddr_cnf->cgi_ps.mcc);
1163 cgi_ps.rai.lac.plmn.mnc = osmo_load16be(&naddr_cnf->cgi_ps.mnc);
1164 cgi_ps.rai.lac.plmn.mnc_3_digits = naddr_cnf->cgi_ps.mnc_3_digits;
1165 cgi_ps.rai.lac.lac = osmo_load16be(&naddr_cnf->cgi_ps.lac);
1166 cgi_ps.rai.rac = naddr_cnf->cgi_ps.rac;
1167 cgi_ps.cell_identity = osmo_load16be(&naddr_cnf->cgi_ps.cell_identity);
1168
1169 LOGP(DL1IF, LOGL_INFO, "Rx Neighbor Address Resolution Confirmation for " NEIGH_CACHE_ENTRY_KEY_FMT ": %s\n",
1170 NEIGH_CACHE_ENTRY_KEY_ARGS(&neigh_key), osmo_cgi_ps_name(&cgi_ps));
1171
1172 /* Cache the cgi_ps so we can avoid requesting again same resolution for a while */
1173 neigh_cache_add(bts->pcu->neigh_cache, &neigh_key, &cgi_ps);
1174 } else {
1175 cgi_ps_ptr = NULL;
1176 LOGP(DL1IF, LOGL_INFO, "Rx Neighbor Address Resolution Confirmation for " NEIGH_CACHE_ENTRY_KEY_FMT ": failed with err_code=%u\n",
1177 NEIGH_CACHE_ENTRY_KEY_ARGS(&neigh_key), naddr_cnf->err_code);
1178 }
1179
1180 llist_for_each(tmp, bts_ms_store(bts)->ms_list()) {
1181 GprsMs *ms = llist_entry(tmp, typeof(*ms), list);
1182 if (ms->nacc && nacc_fsm_is_waiting_addr_resolution(ms->nacc, &neigh_key))
1183 osmo_fsm_inst_dispatch(ms->nacc->fi, NACC_EV_RX_RAC_CI, cgi_ps_ptr);
1184 }
1185 return 0;
1186}
1187
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001188static int pcu_rx_container(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_container *container)
1189{
1190 int rc;
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +02001191 uint16_t data_length = osmo_load16be(&container->length);
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001192
1193 switch (container->msg_type) {
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +02001194 case PCU_IF_MSG_NEIGH_ADDR_CNF:
1195 if (data_length < sizeof(struct gsm_pcu_if_neigh_addr_cnf)) {
1196 LOGP(DL1IF, LOGL_ERROR, "Rx container(NEIGH_ADDR_CNF) message too short: %u vs exp %zu\n",
1197 data_length, sizeof(struct gsm_pcu_if_neigh_addr_cnf));
1198 return -EINVAL;
1199 }
1200 rc = pcu_rx_neigh_addr_cnf(bts, (struct gsm_pcu_if_neigh_addr_cnf*)&container->data);
1201 break;
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001202 default:
1203 LOGP(DL1IF, LOGL_NOTICE, "(bts=%d) Rx unexpected msg type (%u) inside container!\n",
1204 bts->nr, container->msg_type);
1205 rc = -1;
1206 }
1207 return rc;
1208}
1209
1210#define CHECK_IF_MSG_SIZE(prim_len, prim_msg) \
1211 do { \
1212 size_t _len = PCUIF_HDR_SIZE + sizeof(prim_msg); \
1213 if (prim_len < _len) { \
1214 LOGP(DL1IF, LOGL_ERROR, "Received %zu bytes on PCU Socket, but primitive %s " \
1215 "size is %zu, discarding\n", prim_len, #prim_msg, _len); \
1216 return -EINVAL; \
1217 } \
1218 } while(0);
1219int pcu_rx(struct gsm_pcu_if *pcu_prim, size_t pcu_prim_length)
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001220{
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001221 int rc = 0;
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001222 size_t exp_len;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001223 struct gprs_rlcmac_bts *bts = gprs_pcu_get_bts_by_nr(the_pcu, pcu_prim->bts_nr);
1224 if (!bts) {
1225 LOGP(DL1IF, LOGL_NOTICE, "Received message for new BTS%d\n", pcu_prim->bts_nr);
1226 bts = bts_alloc(the_pcu, pcu_prim->bts_nr);
1227 if (!bts) {
1228 LOGP(DL1IF, LOGL_ERROR, "Failed to create object for BTS%d!\n", pcu_prim->bts_nr);
1229 return -EAGAIN;
1230 }
1231 }
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001232
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001233 switch (pcu_prim->msg_type) {
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001234 case PCU_IF_MSG_DATA_IND:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001235 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.data_ind);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001236 rc = pcu_rx_data_ind(bts, &pcu_prim->u.data_ind);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001237 break;
Andreas Eversberga9be1542012-09-27 09:23:24 +02001238 case PCU_IF_MSG_DATA_CNF:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001239 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.data_cnf);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001240 rc = pcu_rx_data_cnf(bts, &pcu_prim->u.data_cnf);
Andreas Eversberga9be1542012-09-27 09:23:24 +02001241 break;
Philipp Maier7c3fd982023-02-01 16:10:52 +01001242 case PCU_IF_MSG_DATA_CNF_DT:
1243 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.data_cnf_dt);
1244 rc = pcu_rx_data_cnf_dt(bts, &pcu_prim->u.data_cnf_dt);
1245 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001246 case PCU_IF_MSG_RTS_REQ:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001247 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.rts_req);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001248 rc = pcu_rx_rts_req(bts, &pcu_prim->u.rts_req);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001249 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001250 case PCU_IF_MSG_RACH_IND:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001251 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.rach_ind);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001252 rc = pcu_rx_rach_ind(bts, &pcu_prim->u.rach_ind);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001253 break;
1254 case PCU_IF_MSG_INFO_IND:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001255 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.info_ind);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001256 rc = pcu_rx_info_ind(bts, &pcu_prim->u.info_ind);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001257 break;
Philipp Maier4bac3982023-02-03 16:52:42 +01001258 case PCU_IF_MSG_E1_CCU_IND:
1259 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.e1_ccu_ind);
1260 rc = pcu_rx_e1_ccu_ind(bts, &pcu_prim->u.e1_ccu_ind);
1261 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001262 case PCU_IF_MSG_TIME_IND:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001263 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.time_ind);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001264 rc = pcu_rx_time_ind(bts, &pcu_prim->u.time_ind);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001265 break;
Andreas Eversberg2b914642012-07-19 13:06:26 +02001266 case PCU_IF_MSG_PAG_REQ:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001267 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.pag_req);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001268 rc = pcu_rx_pag_req(bts, &pcu_prim->u.pag_req);
Andreas Eversberg2b914642012-07-19 13:06:26 +02001269 break;
Harald Welte3447c4a2017-07-11 00:06:38 +02001270 case PCU_IF_MSG_SUSP_REQ:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001271 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.susp_req);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001272 rc = pcu_rx_susp_req(bts, &pcu_prim->u.susp_req);
Harald Welte3447c4a2017-07-11 00:06:38 +02001273 break;
Oliver Smithcfb63212019-09-05 17:13:33 +02001274 case PCU_IF_MSG_APP_INFO_REQ:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001275 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.app_info_req);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001276 rc = pcu_rx_app_info_req(bts, &pcu_prim->u.app_info_req);
Oliver Smithcfb63212019-09-05 17:13:33 +02001277 break;
Vadim Yanitskiyb6572132021-06-20 21:05:24 +02001278 case PCU_IF_MSG_INTERF_IND:
1279 /* TODO: handle interference reports */
1280 break;
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001281 case PCU_IF_MSG_CONTAINER:
1282 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.container);
1283 /* ^ check if we can access container fields, v check with container data length */
1284 exp_len = PCUIF_HDR_SIZE + sizeof(pcu_prim->u.container) + osmo_load16be(&pcu_prim->u.container.length);
1285 if (pcu_prim_length < exp_len) {
1286 LOGP(DL1IF, LOGL_ERROR, "Received %zu bytes on PCU Socket, but primitive container size" \
1287 "is %zu, discarding\n", pcu_prim_length, exp_len);
Vadim Yanitskiy52f882e2023-03-27 04:23:54 +07001288 rc = -EINVAL;
1289 break;
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001290 }
1291 rc = pcu_rx_container(bts, &pcu_prim->u.container);
1292 break;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001293 default:
Thorsten Alteholz8bb79042018-10-06 10:42:58 +02001294 LOGP(DL1IF, LOGL_ERROR, "Received unknown PCU msg type %d\n",
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001295 pcu_prim->msg_type);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001296 rc = -EINVAL;
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001297 }
Philipp Maier8ccf7042018-04-10 13:12:42 +02001298
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001299 return rc;
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001300}