blob: 6ec806bee2072a81ae2dadced8dbb9397c7a7bbb [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
Pau Espin Pedrold7c32652019-12-23 12:41:34 +010062#define PAGING_GROUP_LEN 3
63
Philipp Maier4bac3982023-02-03 16:52:42 +010064struct e1_ccu_conn_pars {
65 struct llist_head entry;
66
67 /* Related air interface */
68 uint8_t bts_nr;
69 uint8_t trx_nr;
70 uint8_t ts_nr;
71
72 /* E1 communication parameter */
73 struct e1_conn_pars e1_conn_pars;
74};
75
76/* List storage to collect E1 connection information that we receive through the pcu_sock. The collected data serves as
77 * a lookup table so that we can lookup the E1 connection information for each PDCH (trx number and timeslot number)
78 * when it is needed. */
79static LLIST_HEAD(e1_ccu_table);
80
Pau Espin Pedrold7c32652019-12-23 12:41:34 +010081/* returns [0,999] on success, > 999 on error */
82uint16_t imsi2paging_group(const char* imsi)
83{
84 uint16_t pgroup = 0;
Vadim Yanitskiybd0b0b32020-01-16 00:25:48 +070085 size_t len;
Pau Espin Pedrold7c32652019-12-23 12:41:34 +010086
Vadim Yanitskiybd0b0b32020-01-16 00:25:48 +070087 len = (imsi != NULL) ? strlen(imsi) : 0;
88 if (len < PAGING_GROUP_LEN)
Pau Espin Pedrold7c32652019-12-23 12:41:34 +010089 return 0xFFFF;
90 imsi += len - PAGING_GROUP_LEN;
91
92 while (*imsi != '\0') {
93 if (!isdigit(*imsi))
94 return 0xFFFF;
95 pgroup *= 10;
96 pgroup += *imsi - '0';
97 imsi++;
98 }
99 return pgroup;
100}
101
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400102/*
103 * PCU messages
104 */
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400105
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +0200106/* Can be used to allocate message with non-variable size */
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400107struct msgb *pcu_msgb_alloc(uint8_t msg_type, uint8_t bts_nr)
108{
109 struct msgb *msg;
110 struct gsm_pcu_if *pcu_prim;
111
112 msg = msgb_alloc(sizeof(struct gsm_pcu_if), "pcu_sock_tx");
113 if (!msg)
114 return NULL;
115 msgb_put(msg, sizeof(struct gsm_pcu_if));
116 pcu_prim = (struct gsm_pcu_if *) msg->data;
117 pcu_prim->msg_type = msg_type;
118 pcu_prim->bts_nr = bts_nr;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400119
120 return msg;
121}
122
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +0200123/* Allocate message with extra size, only reserve pcuif msg hdr */
124static struct msgb *pcu_msgb_alloc_ext_size(uint8_t msg_type, uint8_t bts_nr, size_t extra_size)
125{
126 struct msgb *msg;
127 struct gsm_pcu_if *pcu_prim;
128 msg = msgb_alloc(sizeof(struct gsm_pcu_if) + extra_size, "pcu_sock_tx");
129 /* Only header is filled, caller is responible for reserving + filling
130 * message type specific contents: */
131 msgb_put(msg, PCUIF_HDR_SIZE);
132 pcu_prim = (struct gsm_pcu_if *) msgb_data(msg);
133 pcu_prim->msg_type = msg_type;
134 pcu_prim->bts_nr = bts_nr;
135 return msg;
136}
137
Max0a8fae82017-03-08 18:53:30 +0100138const struct value_string gsm_pcu_if_text_type_names[] = {
139 OSMO_VALUE_STRING(PCU_VERSION),
140 OSMO_VALUE_STRING(PCU_OML_ALERT),
141 { 0, NULL }
142};
143
144int pcu_tx_txt_ind(enum gsm_pcu_if_text_type t, const char *fmt, ...)
145{
146 struct gsm_pcu_if *pcu_prim;
147 struct gsm_pcu_if_txt_ind *txt;
148 va_list ap;
149 char *rep;
150 struct msgb *msg = pcu_msgb_alloc(PCU_IF_MSG_TXT_IND, 0);
151 if (!msg)
152 return -ENOMEM;
153
154 pcu_prim = (struct gsm_pcu_if *) msg->data;
155 txt = &pcu_prim->u.txt_ind;
156 txt->type = t;
157
158 va_start(ap, fmt);
159 rep = talloc_vasprintf(tall_pcu_ctx, fmt, ap);
160 va_end(ap);
161
162 if (!rep)
163 return -ENOMEM;
164
165 osmo_strlcpy(txt->text, rep, TXT_MAX_LEN);
166 talloc_free(rep);
167
168 LOGP(DL1IF, LOGL_INFO, "Sending %s TXT as %s to BTS\n", txt->text,
169 get_value_string(gsm_pcu_if_text_type_names, t));
170
171 return pcu_sock_send(msg);
172}
173
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100174static int pcu_tx_act_req(struct gprs_rlcmac_bts *bts, const struct gprs_rlcmac_pdch *pdch,
175 uint8_t activate)
Ivan Kluchnikov4277f0c2012-04-12 14:24:35 +0400176{
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400177 struct msgb *msg;
178 struct gsm_pcu_if *pcu_prim;
179 struct gsm_pcu_if_act_req *act_req;
180
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100181 LOGPDCH(pdch, DL1IF, LOGL_INFO, "Sending %s request\n",
182 (activate) ? "activate" : "deactivate");
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400183
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100184 msg = pcu_msgb_alloc(PCU_IF_MSG_ACT_REQ, bts->nr);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400185 if (!msg)
186 return -ENOMEM;
187 pcu_prim = (struct gsm_pcu_if *) msg->data;
188 act_req = &pcu_prim->u.act_req;
189 act_req->activate = activate;
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100190 act_req->trx_nr = pdch->trx_no();
191 act_req->ts_nr = pdch->ts_no;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400192
193 return pcu_sock_send(msg);
194}
195
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100196static 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 +0400197 uint16_t arfcn, uint32_t fn, uint8_t block_nr, uint8_t *data,
198 uint8_t len)
199{
200 struct msgb *msg;
201 struct gsm_pcu_if *pcu_prim;
202 struct gsm_pcu_if_data *data_req;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100203 int current_fn = bts_current_frame_number(bts);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400204
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100205 LOGP(DL1IF, LOGL_DEBUG, "(bts=%u,trx=%u,ts=%u) FN=%u Sending data request: sapi=%d "
206 "arfcn=%d cur_fn=%d block=%d data=%s\n", bts->nr, trx, ts, fn, sapi,
207 arfcn, current_fn, block_nr, osmo_hexdump(data, len));
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400208
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100209 msg = pcu_msgb_alloc(PCU_IF_MSG_DATA_REQ, bts->nr);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400210 if (!msg)
211 return -ENOMEM;
212 pcu_prim = (struct gsm_pcu_if *) msg->data;
213 data_req = &pcu_prim->u.data_req;
214
215 data_req->sapi = sapi;
216 data_req->fn = fn;
217 data_req->arfcn = arfcn;
218 data_req->trx_nr = trx;
219 data_req->ts_nr = ts;
220 data_req->block_nr = block_nr;
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200221 if (len)
222 memcpy(data_req->data, data, len);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400223 data_req->len = len;
224
225 return pcu_sock_send(msg);
226}
227
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100228void 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 +0400229 uint32_t fn, uint8_t block_nr)
230{
Maxb216c6b2017-09-01 11:00:39 +0200231#ifdef ENABLE_DIRECT_PHY
Max528ff392016-02-22 11:42:33 +0100232 if (bts->trx[trx].fl1h) {
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200233 if (!msg) /* Simply skip sending idle frames to L1 */
234 return;
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100235 l1if_pdch_req(bts->trx[trx].fl1h, ts, 0, fn, arfcn, block_nr,
236 msg->data, msg->len);
Max528ff392016-02-22 11:42:33 +0100237 msgb_free(msg);
238 return;
239 }
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100240#endif
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200241 if (!msg) {
242 pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PDTCH, arfcn, fn, block_nr,
243 NULL, 0);
244 return;
245 }
246
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100247 pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PDTCH, arfcn, fn, block_nr,
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100248 msg->data, msg->len);
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200249 msgb_free(msg);
Ivan Kluchnikov4277f0c2012-04-12 14:24:35 +0400250}
251
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100252void pcu_l1if_tx_ptcch(struct gprs_rlcmac_bts *bts,
253 uint8_t trx, uint8_t ts, uint16_t arfcn,
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700254 uint32_t fn, uint8_t block_nr,
255 uint8_t *data, size_t data_len)
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400256{
Vadim Yanitskiyf5dde9f2022-09-30 02:21:59 +0700257 if (data_len && the_pcu->gsmtap_categ_mask & (1 << PCU_GSMTAP_C_DL_PTCCH))
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100258 gsmtap_send(the_pcu->gsmtap, arfcn, ts, GSMTAP_CHANNEL_PTCCH, 0, fn, 0, 0, data, data_len);
Maxcad867e2016-04-21 14:35:55 +0200259#ifdef ENABLE_DIRECT_PHY
Max528ff392016-02-22 11:42:33 +0100260 if (bts->trx[trx].fl1h) {
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200261 if (!data_len) /* Simply skip sending idle frames to L1 */
262 return;
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700263 l1if_pdch_req(bts->trx[trx].fl1h, ts, 1, fn, arfcn, block_nr, data, data_len);
Max528ff392016-02-22 11:42:33 +0100264 return;
265 }
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100266#endif
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200267 if (!data_len) {
268 pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PTCCH, arfcn, fn, block_nr, NULL, 0);
269 return;
270 }
271
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100272 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 +0400273}
274
Philipp Maier6f417622023-02-03 13:11:27 +0100275void pcu_l1if_tx_agch(struct gprs_rlcmac_bts *bts, bitvec *block, int plen)
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400276{
Pau Espin Pedrold752d7c2019-10-07 20:56:48 +0200277 uint8_t data[GSM_MACBLOCK_LEN]; /* prefix PLEN */
278
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400279 /* FIXME: why does OpenBTS has no PLEN and no fill in message? */
280 bitvec_pack(block, data + 1);
281 data[0] = (plen << 2) | 0x01;
Pau Espin Pedrol58543702019-09-30 19:07:16 +0200282
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100283 if (the_pcu->gsmtap_categ_mask & (1 << PCU_GSMTAP_C_DL_AGCH))
284 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 +0200285
Philipp Maier3b66bbf2023-02-03 15:45:14 +0100286 pcu_tx_data_req(bts, 0, 0, PCU_IF_SAPI_AGCH, 0, 0, 0, data, sizeof(data));
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400287}
288
Philipp Maier6f417622023-02-03 13:11:27 +0100289void pcu_l1if_tx_pch(struct gprs_rlcmac_bts *bts, bitvec *block, int plen, uint16_t pgroup)
Ivan Kluchnikovc7e7f682012-06-29 22:53:15 +0400290{
Pau Espin Pedrol8dc09e72019-10-07 20:56:02 +0200291 uint8_t data[PAGING_GROUP_LEN + GSM_MACBLOCK_LEN];
Pau Espin Pedrold7c32652019-12-23 12:41:34 +0100292 int i;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400293
Pau Espin Pedrol8dc09e72019-10-07 20:56:02 +0200294 /* prepend paging group */
Pau Espin Pedrold7c32652019-12-23 12:41:34 +0100295 for (i = 0; i < PAGING_GROUP_LEN; i++) {
296 data[PAGING_GROUP_LEN - 1 - i] = '0' + (char)(pgroup % 10);
297 pgroup = pgroup / 10;
298 }
299 OSMO_ASSERT(pgroup == 0);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400300
Pau Espin Pedrol8dc09e72019-10-07 20:56:02 +0200301 /* block provided by upper layer comes without first byte (plen),
302 * prepend it manually:
303 */
304 OSMO_ASSERT(sizeof(data) >= PAGING_GROUP_LEN + 1 + block->data_len);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400305 data[3] = (plen << 2) | 0x01;
Pau Espin Pedrol8dc09e72019-10-07 20:56:02 +0200306 bitvec_pack(block, data + PAGING_GROUP_LEN + 1);
Pau Espin Pedrol58543702019-09-30 19:07:16 +0200307
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100308 if (the_pcu->gsmtap_categ_mask & (1 << PCU_GSMTAP_C_DL_PCH))
309 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 +0200310
Philipp Maier3b66bbf2023-02-03 15:45:14 +0100311 pcu_tx_data_req(bts, 0, 0, PCU_IF_SAPI_PCH, 0, 0, 0, data, sizeof(data));
Ivan Kluchnikovc7e7f682012-06-29 22:53:15 +0400312}
313
Philipp Maier2353ed42023-02-01 13:51:56 +0100314/* Send a block via the paging channel and require a confirmation by the receiving end */
315void pcu_l1if_tx_pch_dt(struct gprs_rlcmac_bts *bts, bitvec *block, int plen, const char *imsi, uint32_t tlli)
316{
317 /* NOTE: This is in practice only used to transmit IMMEDIATE ASSIGNMENT messages through the paging channel and
318 * it is not guaranteed to work with other message types. The prepended TLLI will be used as an identifier in
319 * the confirmation message. */
320
321 struct gsm_pcu_if_pch_dt pch_dt;
322
323 pch_dt.tlli = tlli;
324 strcpy(pch_dt.imsi, imsi);
325
326 pch_dt.data[0] = (plen << 2) | 0x01;
327 bitvec_pack(block, pch_dt.data + 1);
328
329 pcu_tx_data_req(bts, 0, 0, PCU_IF_SAPI_PCH_DT, 0, 0, 0, (uint8_t*)&pch_dt, sizeof(pch_dt));
330}
331
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +0200332int pcu_tx_neigh_addr_res_req(struct gprs_rlcmac_bts *bts, const struct neigh_cache_entry_key *neigh_key)
333{
334 struct msgb *msg;
335 struct gsm_pcu_if *pcu_prim;
336 struct gsm_pcu_if_neigh_addr_req *naddr_req;
337
338 LOGP(DL1IF, LOGL_DEBUG, "(bts=%u) Tx Neighbor Address Resolution Request: " NEIGH_CACHE_ENTRY_KEY_FMT "\n",
339 bts->nr, NEIGH_CACHE_ENTRY_KEY_ARGS(neigh_key));
340
341 msg = pcu_msgb_alloc_ext_size(PCU_IF_MSG_CONTAINER, bts->nr, sizeof(struct gsm_pcu_if_neigh_addr_req));
342 if (!msg)
343 return -ENOMEM;
344 pcu_prim = (struct gsm_pcu_if *) msgb_data(msg);
345 naddr_req = (struct gsm_pcu_if_neigh_addr_req *)&pcu_prim->u.container.data[0];
346
347 msgb_put(msg, sizeof(pcu_prim->u.container) + sizeof(struct gsm_pcu_if_neigh_addr_req));
348 pcu_prim->u.container.msg_type = PCU_IF_MSG_NEIGH_ADDR_REQ;
349 osmo_store16be(sizeof(struct gsm_pcu_if_neigh_addr_req), &pcu_prim->u.container.length);
350
351 osmo_store16be(neigh_key->local_lac, &naddr_req->local_lac);
352 osmo_store16be(neigh_key->local_ci, &naddr_req->local_ci);
353 osmo_store16be(neigh_key->tgt_arfcn, &naddr_req->tgt_arfcn);
354 naddr_req->tgt_bsic = neigh_key->tgt_bsic;
355
356 return pcu_sock_send(msg);
357}
358
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100359void 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 +0200360{
Pau Espin Pedrolfecab502021-03-17 15:26:37 +0100361 bts_set_current_block_frame_number(bts, fn);
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200362}
363
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100364int 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 +0200365 uint8_t len, uint32_t fn, struct pcu_l1_meas *meas)
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100366{
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +0100367 int rc;
368
Pau Espin Pedrol3bbb3cc2021-08-31 14:09:42 +0200369 if (!pdch->is_enabled()) {
370 LOGPDCH(pdch, DL1IF, LOGL_INFO, "Received DATA.ind (PDTCH) on disabled TS\n");
371 return -EINVAL;
372 }
373
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +0100374 rc = pdch->rcv_block(data, len, fn, meas);
375 pdch_ulc_expire_fn(pdch->ulc, fn);
376 return rc;
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100377}
378
Pau Espin Pedrol86f4c092021-06-08 18:53:40 +0200379static int list_arfcn(const struct gprs_rlcmac_bts *bts, const struct gsm_sysinfo_freq *freq, const char *text)
380{
381 int n = 0, i;
382 for (i = 0; i < 1024; i++) {
383 if (freq[i].mask) {
384 if (!n)
385 LOGP(DL1IF, LOGL_INFO, "BTS%d: %s", bts->nr, text);
386 LOGPC(DL1IF, LOGL_INFO, " %d", i);
387 n++;
388 }
389 }
390 if (n)
391 LOGPC(DL1IF, LOGL_INFO, "\n");
392
393 return n;
394}
395
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100396static int pcu_rx_data_ind_bcch(struct gprs_rlcmac_bts *bts, uint8_t *data, uint8_t len)
Max84bf0fa2017-09-01 11:02:40 +0200397{
Pau Espin Pedrol86f4c092021-06-08 18:53:40 +0200398 struct gsm48_system_information_type_2 *si2;
Pau Espin Pedrolfe8de452021-02-09 18:47:34 +0100399 const uint8_t *si_ro;
Pau Espin Pedrol86f4c092021-06-08 18:53:40 +0200400
Philipp Maiera58ec612021-01-25 23:43:52 +0100401 switch (len) {
402 case 0:
403 /* Due to historical reasons also accept a completely empty message as
404 * revoke command for SI13. */
405 LOGP(DL1IF, LOGL_ERROR,
406 "Received PCU data indication that contains no data -- Revoked SI13.\n");
Max84bf0fa2017-09-01 11:02:40 +0200407 bts->si13_is_set = false;
Max84bf0fa2017-09-01 11:02:40 +0200408
Philipp Maiera58ec612021-01-25 23:43:52 +0100409 return 0;
410 case 1:
411 /* Revoke SI, type is identified by a single byte which is coded after
412 * enum osmo_sysinfo_type. */
413 switch (data[0]) {
414 case SYSINFO_TYPE_1:
415 bts->si1_is_set = false;
416 break;
Pau Espin Pedrol86f4c092021-06-08 18:53:40 +0200417 case SYSINFO_TYPE_2:
418 bts->si2_is_set = false;
419 break;
Philipp Maiera58ec612021-01-25 23:43:52 +0100420 case SYSINFO_TYPE_3:
421 bts->si3_is_set = false;
422 break;
423 case SYSINFO_TYPE_13:
424 bts->si13_is_set = false;
425 break;
426 default:
427 LOGP(DL1IF, LOGL_ERROR,
428 "Received PCU data indication that contains an unsupported system information identifier (%02x,OSMO) -- ignored.\n", data[0]);
429 return -EINVAL;
430 }
431 LOGP(DPCU, LOGL_DEBUG,
432 "Received PCU data indication: Revoked SI%s\n",
433 get_value_string(osmo_sitype_strs, data[0]));
434 return 0;
435 case GSM_MACBLOCK_LEN:
436 /* Update SI, type is identified by the RR sysinfo type, which is the
437 * 3rd byte in the buffer. */
438 switch (data[2]) {
439 case GSM48_MT_RR_SYSINFO_1:
440 memcpy(bts->si1, data, GSM_MACBLOCK_LEN);
441 bts->si1_is_set = true;
442 break;
Pau Espin Pedrol86f4c092021-06-08 18:53:40 +0200443 case GSM48_MT_RR_SYSINFO_2:
444 memcpy(bts->si2, data, GSM_MACBLOCK_LEN);
445 bts->si2_is_set = true;
446 si2 = (struct gsm48_system_information_type_2 *)bts->si2;
447 gsm48_decode_freq_list(bts->si2_bcch_cell_list, si2->bcch_frequency_list,
448 sizeof(si2->bcch_frequency_list), 0xce, 1);
449 list_arfcn(bts, bts->si2_bcch_cell_list, "SI2 Neighbour cells in same band:");
450 break;
Philipp Maiera58ec612021-01-25 23:43:52 +0100451 case GSM48_MT_RR_SYSINFO_3:
452 memcpy(bts->si3, data, GSM_MACBLOCK_LEN);
453 bts->si3_is_set = true;
454 break;
455 case GSM48_MT_RR_SYSINFO_13:
456 memcpy(bts->si13, data, GSM_MACBLOCK_LEN);
457 bts->si13_is_set = true;
Pau Espin Pedrolfe8de452021-02-09 18:47:34 +0100458 si_ro = ((struct gsm48_system_information_type_13*)data)->rest_octets;
Pau Espin Pedrold65bd9d2021-06-01 16:43:41 +0200459 if (osmo_gsm48_rest_octets_si13_decode(&bts->si13_ro_decoded, si_ro) < 0)
Pau Espin Pedrolfe8de452021-02-09 18:47:34 +0100460 LOGP(DPCU, LOGL_ERROR, "Error decoding SI13\n");
Philipp Maiera58ec612021-01-25 23:43:52 +0100461 break;
462 default:
463 LOGP(DL1IF, LOGL_ERROR,
464 "Received PCU data indication that contains an unsupported system information identifier (%02x,RR) -- ignored.\n", data[2]);
465 return -EINVAL;
466 }
467 LOGP(DPCU, LOGL_DEBUG,
468 "Received PCU data indication: Updated %s: %s\n",
469 gsm48_pdisc_msgtype_name(data[1], data[2]),
470 osmo_hexdump_nospc(data + 1, GSM_MACBLOCK_LEN));
471 return 0;
472 default:
473 LOGP(DL1IF, LOGL_ERROR,
474 "Received PCU data indication with unexpected data length: %u -- ignored.\n",
475 len);
Max84bf0fa2017-09-01 11:02:40 +0200476 return -EINVAL;
477 }
Max84bf0fa2017-09-01 11:02:40 +0200478}
479
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100480static int pcu_rx_data_ind(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_data *data_ind)
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400481{
Max528ff392016-02-22 11:42:33 +0100482 int rc;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100483 int current_fn = bts_current_frame_number(bts);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100484 struct pcu_l1_meas meas = {0};
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100485 struct gprs_rlcmac_pdch *pdch;
Pau Espin Pedrol72e39562020-06-30 17:57:42 +0200486 uint8_t gsmtap_chantype;
Maxb216c6b2017-09-01 11:00:39 +0200487
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100488 LOGP(DL1IF, LOGL_DEBUG, "(bts=%" PRIu8 ",trx=%" PRIu8 ",ts=%" PRIu8 ") FN=%u "
489 "Rx DATA.ind: sapi=%d arfcn=%d cur_fn=%d "
490 "block=%d data=%s\n", bts->nr, data_ind->trx_nr, data_ind->ts_nr,
491 data_ind->fn, data_ind->sapi, data_ind->arfcn, current_fn,
492 data_ind->block_nr, osmo_hexdump(data_ind->data, data_ind->len));
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400493
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400494 switch (data_ind->sapi) {
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400495 case PCU_IF_SAPI_PDTCH:
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100496 pdch = &bts->trx[data_ind->trx_nr].pdch[data_ind->ts_nr];
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100497 pcu_l1_meas_set_rssi(&meas, data_ind->rssi);
Maxb216c6b2017-09-01 11:00:39 +0200498 /* convert BER to % value */
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100499 pcu_l1_meas_set_ber(&meas, data_ind->ber10k / 100);
500 pcu_l1_meas_set_bto(&meas, data_ind->ta_offs_qbits);
501 pcu_l1_meas_set_link_qual(&meas, data_ind->lqual_cb / 10);
Vadim Yanitskiyf17dfc02019-07-09 16:16:35 +0700502
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100503 LOGPDCH(pdch, DL1IF, LOGL_DEBUG, "FN=%u Rx DATA.ind PDTCH: "
504 "BER10k = %d, BTO = %d, Q = %d\n", data_ind->fn,
505 data_ind->ber10k, data_ind->ta_offs_qbits, data_ind->lqual_cb);
Vadim Yanitskiyf17dfc02019-07-09 16:16:35 +0700506
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100507 rc = pcu_rx_data_ind_pdtch(bts, pdch, data_ind->data, data_ind->len,
508 data_ind->fn, &meas);
Pau Espin Pedrol72e39562020-06-30 17:57:42 +0200509 gsmtap_chantype = GSMTAP_CHANNEL_PDTCH;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400510 break;
Max84bf0fa2017-09-01 11:02:40 +0200511 case PCU_IF_SAPI_BCCH:
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100512 rc = pcu_rx_data_ind_bcch(bts, data_ind->data, data_ind->len);
Pau Espin Pedrol72e39562020-06-30 17:57:42 +0200513 gsmtap_chantype = GSMTAP_CHANNEL_BCCH;
Max84bf0fa2017-09-01 11:02:40 +0200514 break;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400515 default:
Pau Espin Pedrolc1f31c42021-03-09 14:50:14 +0100516 LOGP(DL1IF, LOGL_ERROR, "(bts=%" PRIu8 ",trx=%" PRIu8 ",ts=%" PRIu8 ") "
517 "FN=%u Rx DATA.ind with unsupported sapi %d\n",
518 bts->nr, data_ind->trx_nr, data_ind->ts_nr, data_ind->fn, data_ind->sapi);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400519 rc = -EINVAL;
Pau Espin Pedrol72e39562020-06-30 17:57:42 +0200520 gsmtap_chantype = GSMTAP_CHANNEL_UNKNOWN;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400521 }
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400522
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100523 if (rc < 0 && (the_pcu->gsmtap_categ_mask & (1 <<PCU_GSMTAP_C_UL_UNKNOWN))) {
524 gsmtap_send(the_pcu->gsmtap, data_ind->arfcn | GSMTAP_ARFCN_F_UPLINK, data_ind->ts_nr,
Pau Espin Pedrol72e39562020-06-30 17:57:42 +0200525 gsmtap_chantype, 0, data_ind->fn, meas.rssi, meas.link_qual, data_ind->data, data_ind->len);
Harald Welte717cdf52017-07-21 21:56:23 +0200526 }
527
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400528 return rc;
529}
530
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100531static int pcu_rx_data_cnf(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_data *data_cnf)
Andreas Eversberga9be1542012-09-27 09:23:24 +0200532{
533 int rc = 0;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100534 int current_fn = bts_current_frame_number(bts);
Andreas Eversberga9be1542012-09-27 09:23:24 +0200535
Philipp Maier7e8e3972018-04-10 13:31:45 +0200536 LOGP(DL1IF, LOGL_DEBUG, "Data confirm received: sapi=%d fn=%d cur_fn=%d\n",
537 data_cnf->sapi, data_cnf->fn, current_fn);
Andreas Eversberga9be1542012-09-27 09:23:24 +0200538
539 switch (data_cnf->sapi) {
540 case PCU_IF_SAPI_PCH:
Pau Espin Pedrolf510f5b2022-10-14 16:37:18 +0200541 if (data_cnf->data[2] == GSM48_MT_RR_IMM_ASS)
Philipp Maier7c3fd982023-02-01 16:10:52 +0100542 bts_rcv_imm_ass_cnf(bts, data_cnf->data, GSM_RESERVED_TMSI, data_cnf->fn);
Andreas Eversberga9be1542012-09-27 09:23:24 +0200543 break;
544 default:
545 LOGP(DL1IF, LOGL_ERROR, "Received PCU data confirm with "
546 "unsupported sapi %d\n", data_cnf->sapi);
547 rc = -EINVAL;
548 }
549
550 return rc;
551}
552
Philipp Maier7c3fd982023-02-01 16:10:52 +0100553static int pcu_rx_data_cnf_dt(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_data_cnf_dt *data_cnf_dt)
554{
555 int rc = 0;
556 int current_fn = bts_current_frame_number(bts);
557
558 LOGP(DL1IF, LOGL_DEBUG, "Data confirm received: sapi=%d fn=%d cur_fn=%d\n",
559 data_cnf_dt->sapi, data_cnf_dt->fn, current_fn);
560
561 switch (data_cnf_dt->sapi) {
562 case PCU_IF_SAPI_PCH:
563 bts_rcv_imm_ass_cnf(bts, NULL, data_cnf_dt->tlli, data_cnf_dt->fn);
564 break;
565 default:
566 LOGP(DL1IF, LOGL_ERROR, "Received PCU data confirm with unsupported sapi %d\n", data_cnf_dt->sapi);
567 rc = -EINVAL;
568 }
569
570 return rc;
571}
572
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100573// FIXME: remove this, when changed from c++ to c.
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100574int pcu_rx_rts_req_pdtch(struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts,
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100575 uint32_t fn, uint8_t block_nr)
576{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100577 return gprs_rlcmac_rcv_rts_block(bts,
Max878bd1f2016-07-20 13:05:05 +0200578 trx, ts, fn, block_nr);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100579}
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100580int pcu_rx_rts_req_ptcch(struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts,
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700581 uint32_t fn, uint8_t block_nr)
582{
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700583 struct gprs_rlcmac_pdch *pdch;
584
585 /* Prevent buffer overflow */
586 if (trx >= ARRAY_SIZE(bts->trx) || ts >= 8)
587 return -EINVAL;
588
589 /* Make sure PDCH time-slot is enabled */
590 pdch = &bts->trx[trx].pdch[ts];
Pau Espin Pedrol9c2512a2022-04-01 18:27:04 +0200591 if (!pdch_is_enabled(pdch))
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700592 return -EAGAIN;
593
Pau Espin Pedroleeae7762021-09-20 11:20:09 +0200594 /* If there's no TBF attached to this PDCH, we can skip Tx of PTCCH
595 * since there's nothing worthy of being transmitted. This way BTS can
596 * identify idle blocks and send nothing or dumy blocks with reduced
597 * energy for the sake of energy saving.
598 */
599 const unsigned num_tbfs = pdch->num_tbfs(GPRS_RLCMAC_DL_TBF)
600 + pdch->num_tbfs(GPRS_RLCMAC_UL_TBF);
601 bool skip_idle = (num_tbfs == 0);
602#ifdef ENABLE_DIRECT_PHY
603 /* In DIRECT_PHY mode we want to always submit something to L1 in
604 * TRX0, since BTS is not preparing dummy bursts on idle TS for us: */
605 skip_idle = skip_idle && trx != 0;
606#endif
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200607 if (skip_idle) {
608 pcu_l1if_tx_ptcch(bts, trx, ts, bts->trx[trx].arfcn, fn, block_nr,
609 NULL, 0);
Pau Espin Pedroleeae7762021-09-20 11:20:09 +0200610 return 0;
Pau Espin Pedrolfef3da22021-09-22 13:56:27 +0200611 }
Pau Espin Pedroleeae7762021-09-20 11:20:09 +0200612
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100613 pcu_l1if_tx_ptcch(bts, trx, ts, bts->trx[trx].arfcn, fn, block_nr,
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700614 pdch->ptcch_msg, GSM_MACBLOCK_LEN);
615 return 0;
616}
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100617
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100618static 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 +0400619{
620 int rc = 0;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100621 int current_fn = bts_current_frame_number(bts);
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100622 const struct gprs_rlcmac_pdch *pdch;
623 pdch = &bts->trx[rts_req->trx_nr].pdch[rts_req->ts_nr];
Ivan Kluchnikov5310d452012-04-17 22:00:31 +0400624
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100625 LOGPDCH(pdch, DL1IF, LOGL_DEBUG, "FN=%u RX RTS.req: sapi=%d "
626 "arfcn=%d cur_fn=%d block=%d\n", rts_req->fn,
627 rts_req->sapi, rts_req->arfcn, current_fn, rts_req->block_nr);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400628
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400629 switch (rts_req->sapi) {
630 case PCU_IF_SAPI_PDTCH:
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100631 pcu_rx_rts_req_pdtch(bts, rts_req->trx_nr, rts_req->ts_nr,
Max878bd1f2016-07-20 13:05:05 +0200632 rts_req->fn, rts_req->block_nr);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400633 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400634 case PCU_IF_SAPI_PTCCH:
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100635 pcu_rx_rts_req_ptcch(bts, rts_req->trx_nr, rts_req->ts_nr,
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700636 rts_req->fn, rts_req->block_nr);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400637 break;
638 default:
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100639 LOGP(DL1IF, LOGL_ERROR, "(bts=%u,trx=%u,ts=%u) FN=%u RX RTS.req with "
640 "unsupported sapi %d\n", bts->nr, rts_req->trx_nr, rts_req->ts_nr,
641 rts_req->fn, rts_req->sapi);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400642 rc = -EINVAL;
643 }
644
645 return rc;
646}
647
Philipp Maier0cb3b2a2023-02-27 15:11:29 +0100648/* C -> C++ adapter for direct PHY access code (e.g. osmo-bts-sysmo) */
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100649extern "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 +0700650{
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700651 struct rach_ind_params rip = {
652 /* The content of RA is not of interest on PTCCH/U */
653 .burst_type = GSM_L1_BURST_TYPE_ACCESS_0,
654 .is_11bit = false,
655 .ra = 0x00,
656 .trx_nr = trx_nr,
657 .ts_nr = ts_nr,
658 .rfn = fn,
659 .qta = qta,
660 };
661
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100662 return bts_rcv_ptcch_rach(bts, &rip);
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700663}
664
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100665static 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 +0400666{
667 int rc = 0;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100668 int current_fn = bts_current_frame_number(bts);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400669
670 LOGP(DL1IF, LOGL_INFO, "RACH request received: sapi=%d "
Vadim Yanitskiyb30f28f2020-03-29 19:01:58 +0700671 "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 +0200672 rach_ind->ra, rach_ind->fn, current_fn, rach_ind->is_11bit);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400673
Philipp Maier40db4c32023-01-10 12:49:28 +0100674 if (OSMO_UNLIKELY(rach_ind->fn > GSM_TDMA_HYPERFRAME - 1)) {
675 LOGP(DL1IF, LOGL_ERROR, "RACH request contains fn=%u that exceeds valid limits (0-%u) -- ignored!\n",
676 rach_ind->fn, GSM_TDMA_HYPERFRAME - 1);
677 return -EINVAL;
678 }
679
Vadim Yanitskiya0a0b7f2020-05-21 19:55:46 +0700680 struct rach_ind_params rip = {
681 .burst_type = (enum ph_burst_type) rach_ind->burst_type,
682 .is_11bit = rach_ind->is_11bit > 0,
683 .ra = rach_ind->ra,
684 .trx_nr = rach_ind->trx_nr,
685 .ts_nr = rach_ind->ts_nr,
686 .rfn = rach_ind->fn,
687 .qta = rach_ind->qta,
688 };
689
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400690 switch (rach_ind->sapi) {
691 case PCU_IF_SAPI_RACH:
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100692 rc = bts_rcv_rach(bts, &rip);
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400693 break;
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700694 case PCU_IF_SAPI_PTCCH:
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100695 rc = bts_rcv_ptcch_rach(bts, &rip);
Vadim Yanitskiyffebd242019-10-05 23:45:31 +0700696 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400697 default:
698 LOGP(DL1IF, LOGL_ERROR, "Received PCU rach request with "
699 "unsupported sapi %d\n", rach_ind->sapi);
700 rc = -EINVAL;
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400701 }
702
Ivan Kluchnikove3a05962012-03-18 15:48:51 +0400703 return rc;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400704}
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200705
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200706static int pcu_info_ind_ns(struct gprs_rlcmac_bts *bts,
707 const struct gsm_pcu_if_info_ind *info_ind)
708{
709 struct osmo_sockaddr remote[PCU_IF_NUM_NSVC] = { };
710 struct osmo_sockaddr local[PCU_IF_NUM_NSVC] = { };
711 uint16_t nsvci[PCU_IF_NUM_NSVC] = { };
712 uint16_t valid = 0;
713
714 for (unsigned int i = 0; i < PCU_IF_NUM_NSVC; i++) {
715 struct osmo_sockaddr_str sockstr;
716
717 switch (info_ind->address_type[i]) {
718 case PCU_IF_ADDR_TYPE_IPV4:
719 local[i].u.sin.sin_family = AF_INET;
720 local[i].u.sin.sin_addr.s_addr = INADDR_ANY;
721 local[i].u.sin.sin_port = htons(info_ind->local_port[i]);
722
723 remote[i].u.sin.sin_family = AF_INET;
Alexander Couzens87c6dd32020-10-27 13:24:40 +0100724 memcpy(&remote[i].u.sin.sin_addr, &info_ind->remote_ip[i].v4,
725 sizeof(struct in_addr));
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200726 remote[i].u.sin.sin_port = htons(info_ind->remote_port[i]);
727 break;
728 case PCU_IF_ADDR_TYPE_IPV6:
729 local[i].u.sin6.sin6_family = AF_INET6;
730 local[i].u.sin6.sin6_addr = in6addr_any;
731 local[i].u.sin6.sin6_port = htons(info_ind->local_port[i]);
732
733 remote[i].u.sin6.sin6_family = AF_INET6;
Alexander Couzens87c6dd32020-10-27 13:24:40 +0100734 memcpy(&remote[i].u.sin6.sin6_addr,
735 &info_ind->remote_ip[i].v6,
736 sizeof(struct in6_addr));
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200737 remote[i].u.sin6.sin6_port = htons(info_ind->remote_port[i]);
738 break;
739 default:
740 continue;
741 }
742 nsvci[i] = info_ind->nsvci[i];
743
744 LOGP(DL1IF, LOGL_DEBUG, " NS%u nsvci=%u\n", i, nsvci[i]);
745 if (osmo_sockaddr_str_from_sockaddr(&sockstr, &remote[i].u.sas))
746 strcpy(sockstr.ip, "invalid");
747
748 LOGP(DL1IF, LOGL_DEBUG, " NS%u address: r=%s:%u<->l=NULL:%u\n",
749 i, sockstr.ip, sockstr.port, info_ind->local_port[i]);
750
751 valid |= 1 << i;
752 }
753
754 if (valid == 0) {
755 LOGP(DL1IF, LOGL_ERROR, "No NSVC available to connect to the SGSN!\n");
756 return -EINVAL;
757 }
758
Alexander Couzens94a367f2021-02-16 16:57:15 +0100759 return gprs_ns_update_config(bts, info_ind->nsei, local, remote, nsvci, valid);
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200760}
761
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100762static 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 +0200763{
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +0200764 struct gprs_bssgp_pcu *pcu;
Harald Weltebb47d952016-11-17 18:40:02 +0100765 int rc = 0;
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700766 unsigned int trx_nr, ts_nr;
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100767 unsigned int i;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200768
Philipp Maierc82c9482023-03-03 11:39:00 +0100769 if (llist_count(&the_pcu->bts_list) > 1)
770 LOGP(DL1IF, LOGL_ERROR, "more than one BTS regsitered at this PCU. This PCU has only been tested with one BTS! OS#5930\n");
771
Philipp Maier2353ed42023-02-01 13:51:56 +0100772 LOGP(DL1IF, LOGL_DEBUG, "Info indication received:\n");
773
774 /* NOTE: The classic way to confirm an IMMEDIATE assignment is to send the whole MAC block payload back to the
775 * PCU. So it is the MAC block itsself that serves a reference for the confirmation. This method has certain
776 * disadvantages so it was replaced with a method that uses the TLLI as a reference ("Direct TLLI"). This new
777 * method will replace the old one. The code that handles the old method will be removed in the foreseeable
778 * future. (see also OS#5927) */
779 if (info_ind->version == 0x0a) {
780 LOGP(DL1IF, LOGL_NOTICE, "PCUIF version 10 is deprecated. OS#5927\n");
781 } else if (info_ind->version != PCU_IF_VERSION) {
782 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 +0200783 info_ind->version, PCU_IF_VERSION);
784 exit(-1);
785 }
786
Philipp Maier2353ed42023-02-01 13:51:56 +0100787 the_pcu->pcu_if_version = info_ind->version;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200788
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400789 if (!(info_ind->flags & PCU_IF_FLAG_ACTIVE)) {
790 LOGP(DL1IF, LOGL_NOTICE, "BTS not available\n");
Stefan Sperling5b22fb72018-02-14 19:46:33 +0100791 if (!bts->active)
792 return -EAGAIN;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400793bssgp_failed:
Stefan Sperling5b22fb72018-02-14 19:46:33 +0100794 bts->active = false;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400795 /* free all TBF */
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700796 for (trx_nr = 0; trx_nr < ARRAY_SIZE(bts->trx); trx_nr++) {
797 bts->trx[trx_nr].arfcn = info_ind->trx[trx_nr].arfcn;
798 for (ts_nr = 0; ts_nr < ARRAY_SIZE(bts->trx[0].pdch); ts_nr++)
Pau Espin Pedrol2d92e392022-03-30 22:09:06 +0200799 if (bts->trx[trx_nr].pdch[ts_nr].is_enabled())
800 bts->trx[trx_nr].pdch[ts_nr].disable();
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400801 }
Alexander Couzens290d9032020-09-16 21:52:02 +0200802 gprs_bssgp_destroy(bts);
Daniel Willmann6d8884d2014-06-04 18:30:59 +0200803 exit(0);
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200804 }
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400805 LOGP(DL1IF, LOGL_INFO, "BTS available\n");
Neels Hofmeyrbdc55fa2018-02-21 00:39:07 +0100806 LOGP(DL1IF, LOGL_DEBUG, " mcc=%03u\n", info_ind->mcc);
807 LOGP(DL1IF, LOGL_DEBUG, " mnc=%0*u\n", info_ind->mnc_3_digits, info_ind->mnc);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400808 LOGP(DL1IF, LOGL_DEBUG, " lac=%d\n", info_ind->lac);
809 LOGP(DL1IF, LOGL_DEBUG, " rac=%d\n", info_ind->rac);
Harald Welte1473b372019-03-21 19:48:55 +0100810 LOGP(DL1IF, LOGL_DEBUG, " cell_id=%d\n", info_ind->cell_id);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100811 LOGP(DL1IF, LOGL_DEBUG, " bsic=%d\n", info_ind->bsic);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400812 LOGP(DL1IF, LOGL_DEBUG, " nsei=%d\n", info_ind->nsei);
813 LOGP(DL1IF, LOGL_DEBUG, " nse_timer=%d %d %d %d %d %d %d\n",
814 info_ind->nse_timer[0], info_ind->nse_timer[1],
815 info_ind->nse_timer[2], info_ind->nse_timer[3],
816 info_ind->nse_timer[4], info_ind->nse_timer[5],
817 info_ind->nse_timer[6]);
818 LOGP(DL1IF, LOGL_DEBUG, " cell_timer=%d %d %d %d %d %d %d %d %d %d "
819 "%d\n",
820 info_ind->cell_timer[0], info_ind->cell_timer[1],
821 info_ind->cell_timer[2], info_ind->cell_timer[3],
822 info_ind->cell_timer[4], info_ind->cell_timer[5],
823 info_ind->cell_timer[6], info_ind->cell_timer[7],
824 info_ind->cell_timer[8], info_ind->cell_timer[9],
825 info_ind->cell_timer[10]);
826 LOGP(DL1IF, LOGL_DEBUG, " repeat_time=%d\n", info_ind->repeat_time);
827 LOGP(DL1IF, LOGL_DEBUG, " repeat_count=%d\n", info_ind->repeat_count);
828 LOGP(DL1IF, LOGL_DEBUG, " bvci=%d\n", info_ind->bvci);
829 LOGP(DL1IF, LOGL_DEBUG, " t3142=%d\n", info_ind->t3142);
830 LOGP(DL1IF, LOGL_DEBUG, " t3169=%d\n", info_ind->t3169);
831 LOGP(DL1IF, LOGL_DEBUG, " t3191=%d\n", info_ind->t3191);
832 LOGP(DL1IF, LOGL_DEBUG, " t3193=%d (ms)\n", info_ind->t3193_10ms * 10);
833 LOGP(DL1IF, LOGL_DEBUG, " t3195=%d\n", info_ind->t3195);
834 LOGP(DL1IF, LOGL_DEBUG, " n3101=%d\n", info_ind->n3101);
835 LOGP(DL1IF, LOGL_DEBUG, " n3103=%d\n", info_ind->n3103);
836 LOGP(DL1IF, LOGL_DEBUG, " n3105=%d\n", info_ind->n3105);
837 LOGP(DL1IF, LOGL_DEBUG, " cv_countdown=%d\n", info_ind->cv_countdown);
838 LOGP(DL1IF, LOGL_DEBUG, " dl_tbf_ext=%d\n", info_ind->dl_tbf_ext);
839 LOGP(DL1IF, LOGL_DEBUG, " ul_tbf_ext=%d\n", info_ind->ul_tbf_ext);
Pau Espin Pedrol2e6b60d2021-01-20 13:48:31 +0100840 bts->cgi_ps.rai.lac.plmn.mcc = info_ind->mcc;
841 bts->cgi_ps.rai.lac.plmn.mnc = info_ind->mnc;
842 bts->cgi_ps.rai.lac.plmn.mnc_3_digits = info_ind->mnc_3_digits;
843 bts->cgi_ps.rai.lac.lac = info_ind->lac;
844 bts->cgi_ps.rai.rac = info_ind->rac;
845 bts->cgi_ps.cell_identity = info_ind->cell_id;
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100846 bts->bsic = info_ind->bsic;
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100847
848 bts->cs_mask = 1 << 0; /* We need at least 1 CS, let's enable CS1 */
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400849 for (i = 0; i < 4; i++) {
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100850 uint8_t allowed = !!(info_ind->flags & (PCU_IF_FLAG_CS1 << i));
851 bts->cs_mask |= allowed << i;
852 if (allowed)
853 LOGP(DL1IF, LOGL_DEBUG, " Use CS%d\n", i + 1);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400854 }
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100855 bts_recalc_max_cs(bts);
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100856
857 bts->mcs_mask = 0;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400858 for (i = 0; i < 9; i++) {
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100859 uint8_t allowed = !!(info_ind->flags & (PCU_IF_FLAG_MCS1 << i));
860 bts->mcs_mask |= allowed << i;
Pau Espin Pedrol87eec1f2020-10-30 18:46:24 +0100861 if (allowed)
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100862 LOGP(DL1IF, LOGL_DEBUG, " Use MCS%d\n", i + 1);
Pau Espin Pedrol87eec1f2020-10-30 18:46:24 +0100863
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400864 }
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100865 bts_recalc_max_mcs(bts);
Pau Espin Pedrold87722d2020-10-30 17:14:26 +0100866
Pau Espin Pedrolb47b1372020-11-03 15:59:39 +0100867 LOGP(DL1IF, LOGL_DEBUG, " initial_cs=%u%s\n", info_ind->initial_cs,
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100868 the_pcu->vty.force_initial_cs ? " (VTY forced, ignoring)" : "");
Pau Espin Pedrol793583e2021-01-14 16:20:57 +0100869 bts->pcuif_info_ind.initial_cs = info_ind->initial_cs;
870 bts_recalc_initial_cs(bts);
Pau Espin Pedrolb47b1372020-11-03 15:59:39 +0100871
872 LOGP(DL1IF, LOGL_DEBUG, " initial_mcs=%u%s\n", info_ind->initial_mcs,
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100873 the_pcu->vty.force_initial_mcs ? " (VTY forced, ignoring)" : "");
Pau Espin Pedrol793583e2021-01-14 16:20:57 +0100874 bts->pcuif_info_ind.initial_mcs = info_ind->initial_mcs;
875 bts_recalc_initial_mcs(bts);
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200876
Alexander Couzens290d9032020-09-16 21:52:02 +0200877 pcu = gprs_bssgp_init(
878 bts,
879 info_ind->nsei, info_ind->bvci,
880 info_ind->mcc, info_ind->mnc, info_ind->mnc_3_digits,
881 info_ind->lac, info_ind->rac, info_ind->cell_id);
882 if (!pcu) {
Vadim Yanitskiyc1a726c2020-10-08 22:46:26 +0700883 LOGP(DL1IF, LOGL_ERROR, "Failed to init BSSGP\n");
Alexander Couzens9b5c9602020-07-28 13:47:18 +0200884 goto bssgp_failed;
885 }
886
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200887 rc = pcu_info_ind_ns(pcu->bts, info_ind);
888 if (rc < 0) {
Alexander Couzens290d9032020-09-16 21:52:02 +0200889 LOGP(DL1IF, LOGL_ERROR, "No NSVC available to connect to the SGSN!\n");
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400890 goto bssgp_failed;
891 }
892
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400893 if (info_ind->t3142) { /* if timer values are set */
Pau Espin Pedrol28f160e2019-09-05 14:48:35 +0200894 osmo_tdef_set(bts->T_defs_bts, 3142, info_ind->t3142, OSMO_TDEF_S);
895 osmo_tdef_set(bts->T_defs_bts, 3169, info_ind->t3169, OSMO_TDEF_S);
896 osmo_tdef_set(bts->T_defs_bts, 3191, info_ind->t3191, OSMO_TDEF_S);
897 osmo_tdef_set(bts->T_defs_bts, 3193, info_ind->t3193_10ms * 10, OSMO_TDEF_MS);
898 osmo_tdef_set(bts->T_defs_bts, 3195, info_ind->t3195, OSMO_TDEF_S);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400899 bts->n3101 = info_ind->n3101;
900 bts->n3103 = info_ind->n3103;
901 bts->n3105 = info_ind->n3105;
902 }
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400903
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700904 for (trx_nr = 0; trx_nr < ARRAY_SIZE(bts->trx); trx_nr++) {
905 bts->trx[trx_nr].arfcn = info_ind->trx[trx_nr].arfcn;
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100906 if ((info_ind->flags & PCU_IF_FLAG_SYSMO)
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700907 && info_ind->trx[trx_nr].hlayer1) {
Maxcad867e2016-04-21 14:35:55 +0200908#ifdef ENABLE_DIRECT_PHY
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700909 LOGP(DL1IF, LOGL_DEBUG, " TRX %d hlayer1=%x\n", trx_nr,
910 info_ind->trx[trx_nr].hlayer1);
911 if (!bts->trx[trx_nr].fl1h)
912 bts->trx[trx_nr].fl1h = l1if_open_pdch(
Philipp Maierc82c9482023-03-03 11:39:00 +0100913 bts->nr, trx_nr,
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700914 info_ind->trx[trx_nr].hlayer1,
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100915 the_pcu->gsmtap);
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700916 if (!bts->trx[trx_nr].fl1h) {
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100917 LOGP(DL1IF, LOGL_FATAL, "Failed to open direct "
Philipp Maier0cb3b2a2023-02-27 15:11:29 +0100918 "PHY access for PDCH.\n");
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100919 exit(0);
920 }
921#else
Philipp Maier0cb3b2a2023-02-27 15:11:29 +0100922 LOGP(DL1IF, LOGL_FATAL, "Compiled without direct PHY "
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100923 "access for PDCH, but enabled at "
924 "BTS. Please deactivate it!\n");
925 exit(0);
926#endif
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100927 }
928
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700929 for (ts_nr = 0; ts_nr < ARRAY_SIZE(bts->trx[0].pdch); ts_nr++) {
Philipp Maier2d222a12022-10-27 15:25:31 +0200930 const struct gsm_pcu_if_info_trx_ts *its = &info_ind->trx[trx_nr].ts[ts_nr];
Vadim Yanitskiy0f41b712020-07-24 01:28:13 +0700931 struct gprs_rlcmac_pdch *pdch = &bts->trx[trx_nr].pdch[ts_nr];
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700932 if ((info_ind->trx[trx_nr].pdch_mask & (1 << ts_nr))) {
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400933 /* FIXME: activate dynamically at RLCMAC */
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200934 if (!pdch->is_enabled()) {
Maxcad867e2016-04-21 14:35:55 +0200935#ifdef ENABLE_DIRECT_PHY
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100936 if ((info_ind->flags &
937 PCU_IF_FLAG_SYSMO))
938 l1if_connect_pdch(
Vadim Yanitskiy11b0f002020-07-24 01:24:47 +0700939 bts->trx[trx_nr].fl1h, ts_nr);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100940#endif
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100941 pcu_tx_act_req(bts, pdch, 1);
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200942 pdch->enable();
Andreas Eversberg3b7461c2012-07-20 11:19:59 +0200943 }
Vadim Yanitskiy8e2bd1e2020-07-21 00:54:42 +0700944
945 pdch->tsc = its->tsc;
946
947 /* (Optional) frequency hopping parameters */
Philipp Maier2e490582022-10-27 15:07:57 +0200948 if (its->hopping) {
Vadim Yanitskiy8e2bd1e2020-07-21 00:54:42 +0700949 pdch->fh.enabled = true;
950 pdch->fh.maio = its->maio;
951 pdch->fh.hsn = its->hsn;
952
953 OSMO_ASSERT(its->ma_bit_len <= sizeof(pdch->fh.ma) * 8);
954 pdch->fh.ma_oct_len = OSMO_BYTES_FOR_BITS(its->ma_bit_len);
955 pdch->fh.ma_bit_len = its->ma_bit_len;
956
957 /* Mobile Allocation + padding (byte/bit order as on the wire):
958 * | 00 00 00 00 00 cc bb aa | -> | cc bb aa 00 00 00 00 00 | */
959 unsigned int offset = sizeof(pdch->fh.ma) - pdch->fh.ma_oct_len;
960 memcpy(pdch->fh.ma, its->ma + offset, pdch->fh.ma_oct_len);
961 }
962
963 LOGP(DL1IF, LOGL_INFO, "PDCH (trx=%u, ts=%u): tsc=%u, hopping=%s\n",
964 trx_nr, ts_nr, pdch->tsc, pdch->fh.enabled ? "yes" : "no");
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400965 } else {
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200966 if (pdch->is_enabled()) {
Philipp Maier72ed3332023-02-27 15:32:00 +0100967#ifdef ENABLE_DIRECT_PHY
968 if ((info_ind->flags & PCU_IF_FLAG_SYSMO))
969 l1if_disconnect_pdch(bts->trx[trx_nr].fl1h, ts_nr);
970#endif
Pau Espin Pedroldf58ddf2021-03-09 16:19:22 +0100971 pcu_tx_act_req(bts, pdch, 0);
Holger Hans Peter Freyther17b0d832013-10-19 17:37:48 +0200972 pdch->disable();
Andreas Eversberg3b7461c2012-07-20 11:19:59 +0200973 }
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400974 }
975 }
976 }
977
Stefan Sperling5b22fb72018-02-14 19:46:33 +0100978 bts->active = true;
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200979 return rc;
980}
981
Philipp Maier4bac3982023-02-03 16:52:42 +0100982/* Query E1 CCU connection parameters by TS and TRX number */
983int 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)
984{
985 struct e1_ccu_conn_pars *e1_ccu_conn_pars;
986
987 llist_for_each_entry(e1_ccu_conn_pars, &e1_ccu_table, entry) {
988 if (e1_ccu_conn_pars->bts_nr == bts_nr && e1_ccu_conn_pars->trx_nr == trx_nr
989 && e1_ccu_conn_pars->ts_nr == ts_nr) {
990 *e1_conn_pars = &e1_ccu_conn_pars->e1_conn_pars;
991 return 0;
992 }
993 }
994
995 return -EINVAL;
996}
997
998/* Allocate a new connection parameter struct and store connection parameters */
999static void new_e1_ccu_conn_pars(const struct gsm_pcu_if_e1_ccu_ind *e1_ccu_ind, uint8_t bts_nr)
1000{
1001 struct e1_ccu_conn_pars *e1_ccu_conn_pars;
1002
1003 e1_ccu_conn_pars = talloc_zero(tall_pcu_ctx, struct e1_ccu_conn_pars);
1004 OSMO_ASSERT(e1_ccu_conn_pars);
1005 e1_ccu_conn_pars->bts_nr = bts_nr;
1006 e1_ccu_conn_pars->trx_nr = e1_ccu_ind->trx_nr;
1007 e1_ccu_conn_pars->ts_nr = e1_ccu_ind->ts_nr;
1008 e1_ccu_conn_pars->e1_conn_pars.e1_nr = e1_ccu_ind->e1_nr;
1009 e1_ccu_conn_pars->e1_conn_pars.e1_ts = e1_ccu_ind->e1_ts;
1010 e1_ccu_conn_pars->e1_conn_pars.e1_ts_ss = e1_ccu_ind->e1_ts_ss;
1011 llist_add(&e1_ccu_conn_pars->entry, &e1_ccu_table);
1012}
1013
1014static int pcu_rx_e1_ccu_ind(struct gprs_rlcmac_bts *bts, const struct gsm_pcu_if_e1_ccu_ind *e1_ccu_ind)
1015{
1016 struct e1_conn_pars *e1_conn_pars;
1017 uint8_t rate;
1018 uint8_t subslot_nr;
1019 int rc;
1020
1021 /* only used with log statement below, no technical relevance otherwise. */
1022 if (e1_ccu_ind->e1_ts_ss > 3) {
1023 rate = 64;
1024 subslot_nr = 0;
1025 } else {
1026 rate = 16;
1027 subslot_nr = e1_ccu_ind->e1_ts_ss;
1028 }
1029
1030 LOGP(DL1IF, LOGL_NOTICE,
1031 "(ts=%u,trx=%u) new E1 CCU communication parameters for CCU (E1-line:%u, E1-TS:%u, E1-SS:%u, rate:%ukbps)\n",
1032 e1_ccu_ind->ts_nr, e1_ccu_ind->trx_nr, e1_ccu_ind->e1_nr, e1_ccu_ind->e1_ts,
1033 subslot_nr, rate);
1034
1035 /* Search for an existing entry, when found, update it. */
1036 rc = pcu_l1if_get_e1_ccu_conn_pars(&e1_conn_pars, bts->nr, e1_ccu_ind->trx_nr, e1_ccu_ind->ts_nr);
1037 if (rc == 0) {
1038 e1_conn_pars->e1_nr = e1_ccu_ind->e1_nr;
1039 e1_conn_pars->e1_ts = e1_ccu_ind->e1_ts;
1040 e1_conn_pars->e1_ts_ss = e1_ccu_ind->e1_ts_ss;
1041 return 0;
1042 }
1043
1044 /* Create new connection parameter entry */
1045 new_e1_ccu_conn_pars(e1_ccu_ind, bts->nr);
1046 return 0;
1047}
1048
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001049static 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 +02001050{
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001051 uint8_t fn13 = time_ind->fn % 13;
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001052
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001053 /* omit frame numbers not starting at a MAC block */
1054 if (fn13 != 0 && fn13 != 4 && fn13 != 8)
1055 return 0;
Max3741f142017-06-26 12:10:12 +02001056
1057 LOGP(DL1IF, LOGL_DEBUG, "Time indication received: %d\n", time_ind->fn % 52);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001058
Pau Espin Pedrol30617112021-03-05 18:59:05 +01001059 /* Ignore TIME.ind completely, we nowadays relay on DATA.ind always
1060 * providing all block FNs. */
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001061 return 0;
1062}
1063
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001064static 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 +02001065{
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +02001066 struct osmo_mobile_identity mi;
Pau Espin Pedrolbd542052021-05-13 17:44:51 +02001067 struct GprsMs *ms = NULL;
1068 struct paging_req_cs req = { .chan_needed = pag_req->chan_needed,
1069 .tlli = GSM_RESERVED_TMSI };
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +02001070 int rc;
1071
Andreas Eversberg2b914642012-07-19 13:06:26 +02001072 LOGP(DL1IF, LOGL_DEBUG, "Paging request received: chan_needed=%d "
1073 "length=%d\n", pag_req->chan_needed, pag_req->identity_lv[0]);
1074
Pau Espin Pedrol32499b62019-12-09 13:55:12 +01001075 /* check if identity does not fit: length > sizeof(lv) - 1 */
1076 if (pag_req->identity_lv[0] >= sizeof(pag_req->identity_lv)) {
1077 LOGP(DL1IF, LOGL_ERROR, "Paging identity too large (%" PRIu8 ")\n",
1078 pag_req->identity_lv[0]);
1079 return -EINVAL;
1080 }
1081
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +02001082 rc = osmo_mobile_identity_decode(&mi, &pag_req->identity_lv[1], pag_req->identity_lv[0], true);
1083 if (rc < 0) {
1084 LOGP(DL1IF, LOGL_ERROR, "Failed to decode Mobile Identity in Paging Request (rc=%d)\n", rc);
1085 return -EINVAL;
1086 }
1087
Pau Espin Pedrolbd542052021-05-13 17:44:51 +02001088 switch (mi.type) {
1089 case GSM_MI_TYPE_TMSI:
1090 req.mi_tmsi = mi;
1091 req.mi_tmsi_present = true;
1092 /* TODO: look up MS by TMSI? Derive TLLI? */
1093 break;
1094 case GSM_MI_TYPE_IMSI:
1095 req.mi_imsi = mi;
1096 req.mi_imsi_present = true;
1097 ms = bts_ms_by_imsi(bts, req.mi_imsi.imsi);
1098 break;
1099 default:
1100 LOGP(DL1IF, LOGL_ERROR, "Unexpected MI type %u\n", mi.type);
1101 return -EINVAL;
1102 }
1103
1104 return bts_add_paging(bts, &req, ms);
Andreas Eversberg2b914642012-07-19 13:06:26 +02001105}
1106
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001107static 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 +02001108{
Philipp Maiera58ec612021-01-25 23:43:52 +01001109 struct bssgp_bvc_ctx *bctx = the_pcu->bssgp.bctx;
Pau Espin Pedrolbd9973a2020-09-22 15:57:37 +02001110 GprsMs *ms;
1111 struct gprs_rlcmac_dl_tbf *dl_tbf;
1112 struct gprs_rlcmac_ul_tbf *ul_tbf;
Harald Welte3447c4a2017-07-11 00:06:38 +02001113 struct gprs_ra_id ra_id;
1114
1115 gsm48_parse_ra(&ra_id, susp_req->ra_id);
1116
1117 LOGP(DL1IF, LOGL_INFO, "GPRS Suspend request received: TLLI=0x%08x RAI=%s\n",
1118 susp_req->tlli, osmo_rai_name(&ra_id));
1119
Pau Espin Pedrol2182e622021-01-14 16:48:38 +01001120 if ((ms = bts_ms_store(bts)->get_ms(susp_req->tlli))) {
Pau Espin Pedrolbd9973a2020-09-22 15:57:37 +02001121 /* We need to catch both pointers here since MS may become freed
1122 after first tbf_free(dl_tbf) if only DL TBF was available */
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +01001123 dl_tbf = ms_dl_tbf(ms);
1124 ul_tbf = ms_ul_tbf(ms);
Pau Espin Pedrolbd9973a2020-09-22 15:57:37 +02001125 if (dl_tbf)
1126 tbf_free(dl_tbf);
1127 if (ul_tbf)
1128 tbf_free(ul_tbf);
1129 }
1130
Harald Welte3447c4a2017-07-11 00:06:38 +02001131 if (!bctx)
1132 return -1;
1133
1134 return bssgp_tx_suspend(bctx->nsei, susp_req->tlli, &ra_id);
1135}
1136
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001137static 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 +02001138{
Pau Espin Pedrol54faf022021-01-14 12:12:43 +01001139 struct llist_head *tmp;
Oliver Smithcfb63212019-09-05 17:13:33 +02001140
1141 LOGP(DL1IF, LOGL_DEBUG, "Application Information Request received: type=0x%08x len=%i\n",
1142 app_info_req->application_type, app_info_req->len);
1143
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001144 bts->app_info_pending = 0;
Pau Espin Pedrol2182e622021-01-14 16:48:38 +01001145 llist_for_each(tmp, bts_ms_store(bts)->ms_list()) {
Pau Espin Pedrol54faf022021-01-14 12:12:43 +01001146 GprsMs *ms = llist_entry(tmp, typeof(*ms), list);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +01001147 if (!ms_dl_tbf(ms))
Oliver Smithcfb63212019-09-05 17:13:33 +02001148 continue;
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001149 bts->app_info_pending++;
Oliver Smithcfb63212019-09-05 17:13:33 +02001150 ms->app_info_pending = true;
1151 }
1152
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001153 if (!bts->app_info_pending) {
Oliver Smithcfb63212019-09-05 17:13:33 +02001154 LOGP(DL1IF, LOGL_NOTICE, "Packet Application Information will not be sent, no subscribers with active"
1155 " TBF\n");
1156 return -1;
1157 }
1158
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001159 if (bts->app_info) {
Oliver Smithcfb63212019-09-05 17:13:33 +02001160 LOGP(DL1IF, LOGL_NOTICE, "Previous Packet Application Information was not sent to all subscribers,"
1161 " overwriting with new one\n");
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001162 msgb_free(bts->app_info);
Oliver Smithcfb63212019-09-05 17:13:33 +02001163 }
1164
1165 LOGP(DL1IF, LOGL_INFO, "Sending Packet Application Information to %i subscribers with active TBF\n",
Pau Espin Pedrol0ece97d2021-01-18 12:53:54 +01001166 bts->app_info_pending);
1167 bts->app_info = gprs_rlcmac_app_info_msg(app_info_req);
Oliver Smithcfb63212019-09-05 17:13:33 +02001168 return 0;
1169}
1170
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +02001171static int pcu_rx_neigh_addr_cnf(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_neigh_addr_cnf *naddr_cnf)
1172{
1173 struct llist_head *tmp;
1174 struct osmo_cell_global_id_ps cgi_ps;
1175 struct osmo_cell_global_id_ps *cgi_ps_ptr = &cgi_ps;
1176
1177 struct neigh_cache_entry_key neigh_key = {
1178 .local_lac = osmo_load16be(&naddr_cnf->orig_req.local_lac),
1179 .local_ci = osmo_load16be(&naddr_cnf->orig_req.local_ci),
1180 .tgt_arfcn = osmo_load16be(&naddr_cnf->orig_req.tgt_arfcn),
1181 .tgt_bsic = naddr_cnf->orig_req.tgt_bsic,
1182 };
1183
1184 if (naddr_cnf->err_code == 0) {
1185 cgi_ps.rai.lac.plmn.mcc = osmo_load16be(&naddr_cnf->cgi_ps.mcc);
1186 cgi_ps.rai.lac.plmn.mnc = osmo_load16be(&naddr_cnf->cgi_ps.mnc);
1187 cgi_ps.rai.lac.plmn.mnc_3_digits = naddr_cnf->cgi_ps.mnc_3_digits;
1188 cgi_ps.rai.lac.lac = osmo_load16be(&naddr_cnf->cgi_ps.lac);
1189 cgi_ps.rai.rac = naddr_cnf->cgi_ps.rac;
1190 cgi_ps.cell_identity = osmo_load16be(&naddr_cnf->cgi_ps.cell_identity);
1191
1192 LOGP(DL1IF, LOGL_INFO, "Rx Neighbor Address Resolution Confirmation for " NEIGH_CACHE_ENTRY_KEY_FMT ": %s\n",
1193 NEIGH_CACHE_ENTRY_KEY_ARGS(&neigh_key), osmo_cgi_ps_name(&cgi_ps));
1194
1195 /* Cache the cgi_ps so we can avoid requesting again same resolution for a while */
1196 neigh_cache_add(bts->pcu->neigh_cache, &neigh_key, &cgi_ps);
1197 } else {
1198 cgi_ps_ptr = NULL;
1199 LOGP(DL1IF, LOGL_INFO, "Rx Neighbor Address Resolution Confirmation for " NEIGH_CACHE_ENTRY_KEY_FMT ": failed with err_code=%u\n",
1200 NEIGH_CACHE_ENTRY_KEY_ARGS(&neigh_key), naddr_cnf->err_code);
1201 }
1202
1203 llist_for_each(tmp, bts_ms_store(bts)->ms_list()) {
1204 GprsMs *ms = llist_entry(tmp, typeof(*ms), list);
1205 if (ms->nacc && nacc_fsm_is_waiting_addr_resolution(ms->nacc, &neigh_key))
1206 osmo_fsm_inst_dispatch(ms->nacc->fi, NACC_EV_RX_RAC_CI, cgi_ps_ptr);
1207 }
1208 return 0;
1209}
1210
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001211static int pcu_rx_container(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_container *container)
1212{
1213 int rc;
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +02001214 uint16_t data_length = osmo_load16be(&container->length);
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001215
1216 switch (container->msg_type) {
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +02001217 case PCU_IF_MSG_NEIGH_ADDR_CNF:
1218 if (data_length < sizeof(struct gsm_pcu_if_neigh_addr_cnf)) {
1219 LOGP(DL1IF, LOGL_ERROR, "Rx container(NEIGH_ADDR_CNF) message too short: %u vs exp %zu\n",
1220 data_length, sizeof(struct gsm_pcu_if_neigh_addr_cnf));
1221 return -EINVAL;
1222 }
1223 rc = pcu_rx_neigh_addr_cnf(bts, (struct gsm_pcu_if_neigh_addr_cnf*)&container->data);
1224 break;
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001225 default:
1226 LOGP(DL1IF, LOGL_NOTICE, "(bts=%d) Rx unexpected msg type (%u) inside container!\n",
1227 bts->nr, container->msg_type);
1228 rc = -1;
1229 }
1230 return rc;
1231}
1232
1233#define CHECK_IF_MSG_SIZE(prim_len, prim_msg) \
1234 do { \
1235 size_t _len = PCUIF_HDR_SIZE + sizeof(prim_msg); \
1236 if (prim_len < _len) { \
1237 LOGP(DL1IF, LOGL_ERROR, "Received %zu bytes on PCU Socket, but primitive %s " \
1238 "size is %zu, discarding\n", prim_len, #prim_msg, _len); \
1239 return -EINVAL; \
1240 } \
1241 } while(0);
1242int pcu_rx(struct gsm_pcu_if *pcu_prim, size_t pcu_prim_length)
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001243{
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001244 int rc = 0;
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001245 size_t exp_len;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001246 struct gprs_rlcmac_bts *bts = gprs_pcu_get_bts_by_nr(the_pcu, pcu_prim->bts_nr);
1247 if (!bts) {
1248 LOGP(DL1IF, LOGL_NOTICE, "Received message for new BTS%d\n", pcu_prim->bts_nr);
1249 bts = bts_alloc(the_pcu, pcu_prim->bts_nr);
1250 if (!bts) {
1251 LOGP(DL1IF, LOGL_ERROR, "Failed to create object for BTS%d!\n", pcu_prim->bts_nr);
1252 return -EAGAIN;
1253 }
1254 }
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001255
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001256 switch (pcu_prim->msg_type) {
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001257 case PCU_IF_MSG_DATA_IND:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001258 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.data_ind);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001259 rc = pcu_rx_data_ind(bts, &pcu_prim->u.data_ind);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001260 break;
Andreas Eversberga9be1542012-09-27 09:23:24 +02001261 case PCU_IF_MSG_DATA_CNF:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001262 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.data_cnf);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001263 rc = pcu_rx_data_cnf(bts, &pcu_prim->u.data_cnf);
Andreas Eversberga9be1542012-09-27 09:23:24 +02001264 break;
Philipp Maier7c3fd982023-02-01 16:10:52 +01001265 case PCU_IF_MSG_DATA_CNF_DT:
1266 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.data_cnf_dt);
1267 rc = pcu_rx_data_cnf_dt(bts, &pcu_prim->u.data_cnf_dt);
1268 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001269 case PCU_IF_MSG_RTS_REQ:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001270 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.rts_req);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001271 rc = pcu_rx_rts_req(bts, &pcu_prim->u.rts_req);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001272 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001273 case PCU_IF_MSG_RACH_IND:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001274 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.rach_ind);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001275 rc = pcu_rx_rach_ind(bts, &pcu_prim->u.rach_ind);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001276 break;
1277 case PCU_IF_MSG_INFO_IND:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001278 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.info_ind);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001279 rc = pcu_rx_info_ind(bts, &pcu_prim->u.info_ind);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001280 break;
Philipp Maier4bac3982023-02-03 16:52:42 +01001281 case PCU_IF_MSG_E1_CCU_IND:
1282 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.e1_ccu_ind);
1283 rc = pcu_rx_e1_ccu_ind(bts, &pcu_prim->u.e1_ccu_ind);
1284 break;
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001285 case PCU_IF_MSG_TIME_IND:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001286 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.time_ind);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001287 rc = pcu_rx_time_ind(bts, &pcu_prim->u.time_ind);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001288 break;
Andreas Eversberg2b914642012-07-19 13:06:26 +02001289 case PCU_IF_MSG_PAG_REQ:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001290 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.pag_req);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001291 rc = pcu_rx_pag_req(bts, &pcu_prim->u.pag_req);
Andreas Eversberg2b914642012-07-19 13:06:26 +02001292 break;
Harald Welte3447c4a2017-07-11 00:06:38 +02001293 case PCU_IF_MSG_SUSP_REQ:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001294 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.susp_req);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001295 rc = pcu_rx_susp_req(bts, &pcu_prim->u.susp_req);
Harald Welte3447c4a2017-07-11 00:06:38 +02001296 break;
Oliver Smithcfb63212019-09-05 17:13:33 +02001297 case PCU_IF_MSG_APP_INFO_REQ:
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001298 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.app_info_req);
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +01001299 rc = pcu_rx_app_info_req(bts, &pcu_prim->u.app_info_req);
Oliver Smithcfb63212019-09-05 17:13:33 +02001300 break;
Vadim Yanitskiyb6572132021-06-20 21:05:24 +02001301 case PCU_IF_MSG_INTERF_IND:
1302 /* TODO: handle interference reports */
1303 break;
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001304 case PCU_IF_MSG_CONTAINER:
1305 CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.container);
1306 /* ^ check if we can access container fields, v check with container data length */
1307 exp_len = PCUIF_HDR_SIZE + sizeof(pcu_prim->u.container) + osmo_load16be(&pcu_prim->u.container.length);
1308 if (pcu_prim_length < exp_len) {
1309 LOGP(DL1IF, LOGL_ERROR, "Received %zu bytes on PCU Socket, but primitive container size" \
1310 "is %zu, discarding\n", pcu_prim_length, exp_len);
1311 }
1312 rc = pcu_rx_container(bts, &pcu_prim->u.container);
1313 break;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001314 default:
Thorsten Alteholz8bb79042018-10-06 10:42:58 +02001315 LOGP(DL1IF, LOGL_ERROR, "Received unknown PCU msg type %d\n",
Pau Espin Pedrol1989a192021-06-23 19:46:07 +02001316 pcu_prim->msg_type);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +04001317 rc = -EINVAL;
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001318 }
Philipp Maier8ccf7042018-04-10 13:12:42 +02001319
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001320 return rc;
Andreas Eversberg0aed6542012-06-23 10:33:16 +02001321}