Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1 | /* pcu_l1_if.cpp |
| 2 | * |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 3 | * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 4 | * |
| 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 Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 14 | */ |
| 15 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 16 | #include <stdio.h> |
| 17 | #include <unistd.h> |
Pau Espin Pedrol | 32499b6 | 2019-12-09 13:55:12 +0100 | [diff] [blame] | 18 | #include <inttypes.h> |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 19 | #include <stdlib.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 20 | #include <string.h> |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 21 | #include <errno.h> |
| 22 | #include <assert.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 23 | #include <sys/socket.h> |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 24 | #include <sys/un.h> |
Andreas Eversberg | 81a12be | 2013-03-16 16:16:41 +0100 | [diff] [blame] | 25 | #include <arpa/inet.h> |
Pau Espin Pedrol | 754b093 | 2020-03-26 14:47:13 +0100 | [diff] [blame] | 26 | #include <ctype.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 27 | |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 28 | extern "C" { |
| 29 | #include <osmocom/core/talloc.h> |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 30 | #include <osmocom/core/select.h> |
| 31 | #include <osmocom/core/msgb.h> |
Max | 528ff39 | 2016-02-22 11:42:33 +0100 | [diff] [blame] | 32 | #include <osmocom/core/gsmtap_util.h> |
| 33 | #include <osmocom/core/gsmtap.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 34 | #include <osmocom/core/bitvec.h> |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 35 | #include <osmocom/core/sockaddr_str.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 36 | #include <osmocom/core/logging.h> |
| 37 | #include <osmocom/core/utils.h> |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 38 | #include <osmocom/gprs/gprs_ns2.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 39 | #include <osmocom/gsm/l1sap.h> |
| 40 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Pau Espin Pedrol | fe8de45 | 2021-02-09 18:47:34 +0100 | [diff] [blame] | 41 | #include <osmocom/gsm/gsm48_rest_octets.h> |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 42 | #include <osmocom/gsm/sysinfo.h> |
Philipp Maier | 40db4c3 | 2023-01-10 12:49:28 +0100 | [diff] [blame] | 43 | #include <osmocom/gsm/gsm0502.h> |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 44 | |
| 45 | #include <nacc_fsm.h> |
Philipp Maier | eaf5da3 | 2023-02-13 13:37:22 +0100 | [diff] [blame] | 46 | #include <pcu_l1_if_phy.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 47 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 48 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 49 | #include <gprs_rlcmac.h> |
| 50 | #include <pcu_l1_if.h> |
| 51 | #include <gprs_debug.h> |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 52 | #include <gprs_bssgp_pcu.h> |
Harald Welte | 68fc127 | 2016-11-16 22:48:33 +0100 | [diff] [blame] | 53 | #include <osmocom/pcu/pcuif_proto.h> |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 54 | #include <bts.h> |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 55 | #include <pdch.h> |
Pau Espin Pedrol | bd9973a | 2020-09-22 15:57:37 +0200 | [diff] [blame] | 56 | #include <tbf_ul.h> |
| 57 | #include <tbf_dl.h> |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 58 | #include <gprs_ms_storage.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 59 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 60 | extern void *tall_pcu_ctx; |
| 61 | |
Philipp Maier | 4bac398 | 2023-02-03 16:52:42 +0100 | [diff] [blame] | 62 | struct 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. */ |
| 77 | static LLIST_HEAD(e1_ccu_table); |
| 78 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 79 | /* |
| 80 | * PCU messages |
| 81 | */ |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 82 | |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 83 | /* Can be used to allocate message with non-variable size */ |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 84 | struct 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 Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 96 | |
| 97 | return msg; |
| 98 | } |
| 99 | |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 100 | /* Allocate message with extra size, only reserve pcuif msg hdr */ |
| 101 | static 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 | |
Max | 0a8fae8 | 2017-03-08 18:53:30 +0100 | [diff] [blame] | 115 | const 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 | |
| 121 | int 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 Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 151 | static int pcu_tx_act_req(struct gprs_rlcmac_bts *bts, const struct gprs_rlcmac_pdch *pdch, |
| 152 | uint8_t activate) |
Ivan Kluchnikov | 4277f0c | 2012-04-12 14:24:35 +0400 | [diff] [blame] | 153 | { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 154 | struct msgb *msg; |
| 155 | struct gsm_pcu_if *pcu_prim; |
| 156 | struct gsm_pcu_if_act_req *act_req; |
| 157 | |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 158 | LOGPDCH(pdch, DL1IF, LOGL_INFO, "Sending %s request\n", |
| 159 | (activate) ? "activate" : "deactivate"); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 160 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 161 | msg = pcu_msgb_alloc(PCU_IF_MSG_ACT_REQ, bts->nr); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 162 | 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 Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 167 | act_req->trx_nr = pdch->trx_no(); |
| 168 | act_req->ts_nr = pdch->ts_no; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 169 | |
| 170 | return pcu_sock_send(msg); |
| 171 | } |
| 172 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 173 | static int pcu_tx_data_req(struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts, uint8_t sapi, |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 174 | 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 Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 180 | int current_fn = bts_current_frame_number(bts); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 181 | |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 182 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 185 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 186 | msg = pcu_msgb_alloc(PCU_IF_MSG_DATA_REQ, bts->nr); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 187 | 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 Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 198 | if (len) |
| 199 | memcpy(data_req->data, data, len); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 200 | data_req->len = len; |
| 201 | |
| 202 | return pcu_sock_send(msg); |
| 203 | } |
| 204 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 205 | void pcu_l1if_tx_pdtch(msgb *msg, struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts, uint16_t arfcn, |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 206 | uint32_t fn, uint8_t block_nr) |
| 207 | { |
Max | b216c6b | 2017-09-01 11:00:39 +0200 | [diff] [blame] | 208 | #ifdef ENABLE_DIRECT_PHY |
Max | 528ff39 | 2016-02-22 11:42:33 +0100 | [diff] [blame] | 209 | if (bts->trx[trx].fl1h) { |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 210 | if (!msg) /* Simply skip sending idle frames to L1 */ |
| 211 | return; |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 212 | l1if_pdch_req(bts->trx[trx].fl1h, ts, 0, fn, arfcn, block_nr, |
| 213 | msg->data, msg->len); |
Max | 528ff39 | 2016-02-22 11:42:33 +0100 | [diff] [blame] | 214 | msgb_free(msg); |
| 215 | return; |
| 216 | } |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 217 | #endif |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 218 | 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 Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 224 | pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PDTCH, arfcn, fn, block_nr, |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 225 | msg->data, msg->len); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 226 | msgb_free(msg); |
Ivan Kluchnikov | 4277f0c | 2012-04-12 14:24:35 +0400 | [diff] [blame] | 227 | } |
| 228 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 229 | void pcu_l1if_tx_ptcch(struct gprs_rlcmac_bts *bts, |
| 230 | uint8_t trx, uint8_t ts, uint16_t arfcn, |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 231 | uint32_t fn, uint8_t block_nr, |
| 232 | uint8_t *data, size_t data_len) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 233 | { |
Vadim Yanitskiy | f5dde9f | 2022-09-30 02:21:59 +0700 | [diff] [blame] | 234 | if (data_len && the_pcu->gsmtap_categ_mask & (1 << PCU_GSMTAP_C_DL_PTCCH)) |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 235 | gsmtap_send(the_pcu->gsmtap, arfcn, ts, GSMTAP_CHANNEL_PTCCH, 0, fn, 0, 0, data, data_len); |
Max | cad867e | 2016-04-21 14:35:55 +0200 | [diff] [blame] | 236 | #ifdef ENABLE_DIRECT_PHY |
Max | 528ff39 | 2016-02-22 11:42:33 +0100 | [diff] [blame] | 237 | if (bts->trx[trx].fl1h) { |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 238 | if (!data_len) /* Simply skip sending idle frames to L1 */ |
| 239 | return; |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 240 | l1if_pdch_req(bts->trx[trx].fl1h, ts, 1, fn, arfcn, block_nr, data, data_len); |
Max | 528ff39 | 2016-02-22 11:42:33 +0100 | [diff] [blame] | 241 | return; |
| 242 | } |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 243 | #endif |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 244 | 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 Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 249 | pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PTCCH, arfcn, fn, block_nr, data, data_len); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 250 | } |
| 251 | |
Philipp Maier | 6f41762 | 2023-02-03 13:11:27 +0100 | [diff] [blame] | 252 | void pcu_l1if_tx_agch(struct gprs_rlcmac_bts *bts, bitvec *block, int plen) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 253 | { |
Pau Espin Pedrol | d752d7c | 2019-10-07 20:56:48 +0200 | [diff] [blame] | 254 | uint8_t data[GSM_MACBLOCK_LEN]; /* prefix PLEN */ |
| 255 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 256 | /* 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 Pedrol | 5854370 | 2019-09-30 19:07:16 +0200 | [diff] [blame] | 259 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 260 | 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 Pedrol | 5854370 | 2019-09-30 19:07:16 +0200 | [diff] [blame] | 262 | |
Philipp Maier | 3b66bbf | 2023-02-03 15:45:14 +0100 | [diff] [blame] | 263 | pcu_tx_data_req(bts, 0, 0, PCU_IF_SAPI_AGCH, 0, 0, 0, data, sizeof(data)); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 264 | } |
| 265 | |
Philipp Maier | 41e3847 | 2023-03-03 16:04:26 +0100 | [diff] [blame] | 266 | #define IMSI_DIGITS_FOR_PAGING 3 |
| 267 | void pcu_l1if_tx_pch(struct gprs_rlcmac_bts *bts, bitvec *block, int plen, const char *imsi) |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 268 | { |
Philipp Maier | 41e3847 | 2023-03-03 16:04:26 +0100 | [diff] [blame] | 269 | uint8_t data[IMSI_DIGITS_FOR_PAGING + GSM_MACBLOCK_LEN]; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 270 | |
Philipp Maier | 41e3847 | 2023-03-03 16:04:26 +0100 | [diff] [blame] | 271 | /* 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 276 | |
Pau Espin Pedrol | 8dc09e7 | 2019-10-07 20:56:02 +0200 | [diff] [blame] | 277 | /* block provided by upper layer comes without first byte (plen), |
| 278 | * prepend it manually: |
| 279 | */ |
Philipp Maier | 41e3847 | 2023-03-03 16:04:26 +0100 | [diff] [blame] | 280 | OSMO_ASSERT(sizeof(data) >= IMSI_DIGITS_FOR_PAGING + 1 + block->data_len); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 281 | data[3] = (plen << 2) | 0x01; |
Philipp Maier | 41e3847 | 2023-03-03 16:04:26 +0100 | [diff] [blame] | 282 | bitvec_pack(block, data + IMSI_DIGITS_FOR_PAGING + 1); |
Pau Espin Pedrol | 5854370 | 2019-09-30 19:07:16 +0200 | [diff] [blame] | 283 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 284 | 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 Pedrol | 5854370 | 2019-09-30 19:07:16 +0200 | [diff] [blame] | 286 | |
Philipp Maier | 3b66bbf | 2023-02-03 15:45:14 +0100 | [diff] [blame] | 287 | pcu_tx_data_req(bts, 0, 0, PCU_IF_SAPI_PCH, 0, 0, 0, data, sizeof(data)); |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 288 | } |
| 289 | |
Philipp Maier | 2353ed4 | 2023-02-01 13:51:56 +0100 | [diff] [blame] | 290 | /* Send a block via the paging channel and require a confirmation by the receiving end */ |
| 291 | void 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 Maier | 07e06d3 | 2023-03-07 18:19:08 +0100 | [diff] [blame] | 297 | struct gsm_pcu_if_pch_dt pch_dt = { 0 }; |
Philipp Maier | 2353ed4 | 2023-02-01 13:51:56 +0100 | [diff] [blame] | 298 | |
| 299 | pch_dt.tlli = tlli; |
Philipp Maier | 07e06d3 | 2023-03-07 18:19:08 +0100 | [diff] [blame] | 300 | if (imsi) |
| 301 | OSMO_STRLCPY_ARRAY(pch_dt.imsi, imsi); |
Philipp Maier | 2353ed4 | 2023-02-01 13:51:56 +0100 | [diff] [blame] | 302 | |
| 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 Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 309 | int 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 Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 336 | void pcu_rx_block_time(struct gprs_rlcmac_bts *bts, uint16_t arfcn, uint32_t fn, uint8_t ts_no) |
Jacob Erlbeck | af75ce8 | 2015-08-26 13:22:28 +0200 | [diff] [blame] | 337 | { |
Pau Espin Pedrol | fecab50 | 2021-03-17 15:26:37 +0100 | [diff] [blame] | 338 | bts_set_current_block_frame_number(bts, fn); |
Jacob Erlbeck | af75ce8 | 2015-08-26 13:22:28 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 341 | int pcu_rx_data_ind_pdtch(struct gprs_rlcmac_bts *bts, struct gprs_rlcmac_pdch *pdch, uint8_t *data, |
Jacob Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 342 | uint8_t len, uint32_t fn, struct pcu_l1_meas *meas) |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 343 | { |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 344 | int rc; |
| 345 | |
Pau Espin Pedrol | 3bbb3cc | 2021-08-31 14:09:42 +0200 | [diff] [blame] | 346 | 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 Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 351 | rc = pdch->rcv_block(data, len, fn, meas); |
| 352 | pdch_ulc_expire_fn(pdch->ulc, fn); |
| 353 | return rc; |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Pau Espin Pedrol | 86f4c09 | 2021-06-08 18:53:40 +0200 | [diff] [blame] | 356 | static 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 Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 373 | static int pcu_rx_data_ind_bcch(struct gprs_rlcmac_bts *bts, uint8_t *data, uint8_t len) |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 374 | { |
Pau Espin Pedrol | 86f4c09 | 2021-06-08 18:53:40 +0200 | [diff] [blame] | 375 | struct gsm48_system_information_type_2 *si2; |
Pau Espin Pedrol | fe8de45 | 2021-02-09 18:47:34 +0100 | [diff] [blame] | 376 | const uint8_t *si_ro; |
Pau Espin Pedrol | 86f4c09 | 2021-06-08 18:53:40 +0200 | [diff] [blame] | 377 | |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 378 | 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"); |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 384 | bts->si13_is_set = false; |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 385 | |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 386 | 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 Pedrol | 86f4c09 | 2021-06-08 18:53:40 +0200 | [diff] [blame] | 394 | case SYSINFO_TYPE_2: |
| 395 | bts->si2_is_set = false; |
| 396 | break; |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 397 | 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 Pedrol | 86f4c09 | 2021-06-08 18:53:40 +0200 | [diff] [blame] | 420 | 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 Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 428 | 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 Pedrol | fe8de45 | 2021-02-09 18:47:34 +0100 | [diff] [blame] | 435 | si_ro = ((struct gsm48_system_information_type_13*)data)->rest_octets; |
Pau Espin Pedrol | d65bd9d | 2021-06-01 16:43:41 +0200 | [diff] [blame] | 436 | if (osmo_gsm48_rest_octets_si13_decode(&bts->si13_ro_decoded, si_ro) < 0) |
Pau Espin Pedrol | fe8de45 | 2021-02-09 18:47:34 +0100 | [diff] [blame] | 437 | LOGP(DPCU, LOGL_ERROR, "Error decoding SI13\n"); |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 438 | 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); |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 453 | return -EINVAL; |
| 454 | } |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 455 | } |
| 456 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 457 | static int pcu_rx_data_ind(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_data *data_ind) |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 458 | { |
Max | 528ff39 | 2016-02-22 11:42:33 +0100 | [diff] [blame] | 459 | int rc; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 460 | int current_fn = bts_current_frame_number(bts); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 461 | struct pcu_l1_meas meas = {0}; |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 462 | struct gprs_rlcmac_pdch *pdch; |
Pau Espin Pedrol | 72e3956 | 2020-06-30 17:57:42 +0200 | [diff] [blame] | 463 | uint8_t gsmtap_chantype; |
Max | b216c6b | 2017-09-01 11:00:39 +0200 | [diff] [blame] | 464 | |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 465 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 470 | |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 471 | switch (data_ind->sapi) { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 472 | case PCU_IF_SAPI_PDTCH: |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 473 | pdch = &bts->trx[data_ind->trx_nr].pdch[data_ind->ts_nr]; |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 474 | pcu_l1_meas_set_rssi(&meas, data_ind->rssi); |
Max | b216c6b | 2017-09-01 11:00:39 +0200 | [diff] [blame] | 475 | /* convert BER to % value */ |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 476 | 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 Yanitskiy | f17dfc0 | 2019-07-09 16:16:35 +0700 | [diff] [blame] | 479 | |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 480 | 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 Yanitskiy | f17dfc0 | 2019-07-09 16:16:35 +0700 | [diff] [blame] | 483 | |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 484 | rc = pcu_rx_data_ind_pdtch(bts, pdch, data_ind->data, data_ind->len, |
| 485 | data_ind->fn, &meas); |
Pau Espin Pedrol | 72e3956 | 2020-06-30 17:57:42 +0200 | [diff] [blame] | 486 | gsmtap_chantype = GSMTAP_CHANNEL_PDTCH; |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 487 | break; |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 488 | case PCU_IF_SAPI_BCCH: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 489 | rc = pcu_rx_data_ind_bcch(bts, data_ind->data, data_ind->len); |
Pau Espin Pedrol | 72e3956 | 2020-06-30 17:57:42 +0200 | [diff] [blame] | 490 | gsmtap_chantype = GSMTAP_CHANNEL_BCCH; |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 491 | break; |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 492 | default: |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 493 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 496 | rc = -EINVAL; |
Pau Espin Pedrol | 72e3956 | 2020-06-30 17:57:42 +0200 | [diff] [blame] | 497 | gsmtap_chantype = GSMTAP_CHANNEL_UNKNOWN; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 498 | } |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 499 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 500 | 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 Pedrol | 72e3956 | 2020-06-30 17:57:42 +0200 | [diff] [blame] | 502 | gsmtap_chantype, 0, data_ind->fn, meas.rssi, meas.link_qual, data_ind->data, data_ind->len); |
Harald Welte | 717cdf5 | 2017-07-21 21:56:23 +0200 | [diff] [blame] | 503 | } |
| 504 | |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 505 | return rc; |
| 506 | } |
| 507 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 508 | static int pcu_rx_data_cnf(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_data *data_cnf) |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 509 | { |
| 510 | int rc = 0; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 511 | int current_fn = bts_current_frame_number(bts); |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 512 | |
Philipp Maier | 7e8e397 | 2018-04-10 13:31:45 +0200 | [diff] [blame] | 513 | 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 Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 515 | |
| 516 | switch (data_cnf->sapi) { |
| 517 | case PCU_IF_SAPI_PCH: |
Pau Espin Pedrol | f510f5b | 2022-10-14 16:37:18 +0200 | [diff] [blame] | 518 | if (data_cnf->data[2] == GSM48_MT_RR_IMM_ASS) |
Philipp Maier | 7c3fd98 | 2023-02-01 16:10:52 +0100 | [diff] [blame] | 519 | bts_rcv_imm_ass_cnf(bts, data_cnf->data, GSM_RESERVED_TMSI, data_cnf->fn); |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 520 | 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 Maier | 7c3fd98 | 2023-02-01 16:10:52 +0100 | [diff] [blame] | 530 | static 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 Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 550 | // FIXME: remove this, when changed from c++ to c. |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 551 | int pcu_rx_rts_req_pdtch(struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts, |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 552 | uint32_t fn, uint8_t block_nr) |
| 553 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 554 | return gprs_rlcmac_rcv_rts_block(bts, |
Max | 878bd1f | 2016-07-20 13:05:05 +0200 | [diff] [blame] | 555 | trx, ts, fn, block_nr); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 556 | } |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 557 | int pcu_rx_rts_req_ptcch(struct gprs_rlcmac_bts *bts, uint8_t trx, uint8_t ts, |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 558 | uint32_t fn, uint8_t block_nr) |
| 559 | { |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 560 | 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 Pedrol | 9c2512a | 2022-04-01 18:27:04 +0200 | [diff] [blame] | 568 | if (!pdch_is_enabled(pdch)) |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 569 | return -EAGAIN; |
| 570 | |
Pau Espin Pedrol | eeae776 | 2021-09-20 11:20:09 +0200 | [diff] [blame] | 571 | /* 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 Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 584 | if (skip_idle) { |
| 585 | pcu_l1if_tx_ptcch(bts, trx, ts, bts->trx[trx].arfcn, fn, block_nr, |
| 586 | NULL, 0); |
Pau Espin Pedrol | eeae776 | 2021-09-20 11:20:09 +0200 | [diff] [blame] | 587 | return 0; |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 588 | } |
Pau Espin Pedrol | eeae776 | 2021-09-20 11:20:09 +0200 | [diff] [blame] | 589 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 590 | pcu_l1if_tx_ptcch(bts, trx, ts, bts->trx[trx].arfcn, fn, block_nr, |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 591 | pdch->ptcch_msg, GSM_MACBLOCK_LEN); |
| 592 | return 0; |
| 593 | } |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 594 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 595 | static int pcu_rx_rts_req(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_rts_req *rts_req) |
Ivan Kluchnikov | 5310d45 | 2012-04-17 22:00:31 +0400 | [diff] [blame] | 596 | { |
| 597 | int rc = 0; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 598 | int current_fn = bts_current_frame_number(bts); |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 599 | const struct gprs_rlcmac_pdch *pdch; |
| 600 | pdch = &bts->trx[rts_req->trx_nr].pdch[rts_req->ts_nr]; |
Ivan Kluchnikov | 5310d45 | 2012-04-17 22:00:31 +0400 | [diff] [blame] | 601 | |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 602 | 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 Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 605 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 606 | switch (rts_req->sapi) { |
| 607 | case PCU_IF_SAPI_PDTCH: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 608 | pcu_rx_rts_req_pdtch(bts, rts_req->trx_nr, rts_req->ts_nr, |
Max | 878bd1f | 2016-07-20 13:05:05 +0200 | [diff] [blame] | 609 | rts_req->fn, rts_req->block_nr); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 610 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 611 | case PCU_IF_SAPI_PTCCH: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 612 | pcu_rx_rts_req_ptcch(bts, rts_req->trx_nr, rts_req->ts_nr, |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 613 | rts_req->fn, rts_req->block_nr); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 614 | break; |
| 615 | default: |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 616 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 619 | rc = -EINVAL; |
| 620 | } |
| 621 | |
| 622 | return rc; |
| 623 | } |
| 624 | |
Philipp Maier | 0cb3b2a | 2023-02-27 15:11:29 +0100 | [diff] [blame] | 625 | /* C -> C++ adapter for direct PHY access code (e.g. osmo-bts-sysmo) */ |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 626 | extern "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 Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 627 | { |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 628 | 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 Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 639 | return bts_rcv_ptcch_rach(bts, &rip); |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 640 | } |
| 641 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 642 | static int pcu_rx_rach_ind(struct gprs_rlcmac_bts *bts, const struct gsm_pcu_if_rach_ind *rach_ind) |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 643 | { |
| 644 | int rc = 0; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 645 | int current_fn = bts_current_frame_number(bts); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 646 | |
| 647 | LOGP(DL1IF, LOGL_INFO, "RACH request received: sapi=%d " |
Vadim Yanitskiy | b30f28f | 2020-03-29 19:01:58 +0700 | [diff] [blame] | 648 | "qta=%d, ra=0x%02x, fn=%u, cur_fn=%d, is_11bit=%d\n", rach_ind->sapi, rach_ind->qta, |
Philipp Maier | 7e8e397 | 2018-04-10 13:31:45 +0200 | [diff] [blame] | 649 | rach_ind->ra, rach_ind->fn, current_fn, rach_ind->is_11bit); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 650 | |
Philipp Maier | 40db4c3 | 2023-01-10 12:49:28 +0100 | [diff] [blame] | 651 | 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 Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 657 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 667 | switch (rach_ind->sapi) { |
| 668 | case PCU_IF_SAPI_RACH: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 669 | rc = bts_rcv_rach(bts, &rip); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 670 | break; |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 671 | case PCU_IF_SAPI_PTCCH: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 672 | rc = bts_rcv_ptcch_rach(bts, &rip); |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 673 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 674 | default: |
| 675 | LOGP(DL1IF, LOGL_ERROR, "Received PCU rach request with " |
| 676 | "unsupported sapi %d\n", rach_ind->sapi); |
| 677 | rc = -EINVAL; |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 678 | } |
| 679 | |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 680 | return rc; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 681 | } |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 682 | |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 683 | static 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 Couzens | 87c6dd3 | 2020-10-27 13:24:40 +0100 | [diff] [blame] | 701 | memcpy(&remote[i].u.sin.sin_addr, &info_ind->remote_ip[i].v4, |
| 702 | sizeof(struct in_addr)); |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 703 | 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 Couzens | 87c6dd3 | 2020-10-27 13:24:40 +0100 | [diff] [blame] | 711 | memcpy(&remote[i].u.sin6.sin6_addr, |
| 712 | &info_ind->remote_ip[i].v6, |
| 713 | sizeof(struct in6_addr)); |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 714 | 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 Couzens | 94a367f | 2021-02-16 16:57:15 +0100 | [diff] [blame] | 736 | return gprs_ns_update_config(bts, info_ind->nsei, local, remote, nsvci, valid); |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 737 | } |
| 738 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 739 | static int pcu_rx_info_ind(struct gprs_rlcmac_bts *bts, const struct gsm_pcu_if_info_ind *info_ind) |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 740 | { |
Holger Hans Peter Freyther | e8d9a5f | 2013-07-28 19:11:20 +0200 | [diff] [blame] | 741 | struct gprs_bssgp_pcu *pcu; |
Harald Welte | bb47d95 | 2016-11-17 18:40:02 +0100 | [diff] [blame] | 742 | int rc = 0; |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 743 | unsigned int trx_nr, ts_nr; |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 744 | unsigned int i; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 745 | |
Philipp Maier | c82c948 | 2023-03-03 11:39:00 +0100 | [diff] [blame] | 746 | 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 Maier | 2353ed4 | 2023-02-01 13:51:56 +0100 | [diff] [blame] | 749 | 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 Eversberg | 8389fd0 | 2012-07-18 10:06:48 +0200 | [diff] [blame] | 760 | info_ind->version, PCU_IF_VERSION); |
| 761 | exit(-1); |
| 762 | } |
| 763 | |
Philipp Maier | 2353ed4 | 2023-02-01 13:51:56 +0100 | [diff] [blame] | 764 | the_pcu->pcu_if_version = info_ind->version; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 765 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 766 | if (!(info_ind->flags & PCU_IF_FLAG_ACTIVE)) { |
| 767 | LOGP(DL1IF, LOGL_NOTICE, "BTS not available\n"); |
Stefan Sperling | 5b22fb7 | 2018-02-14 19:46:33 +0100 | [diff] [blame] | 768 | if (!bts->active) |
| 769 | return -EAGAIN; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 770 | bssgp_failed: |
Stefan Sperling | 5b22fb7 | 2018-02-14 19:46:33 +0100 | [diff] [blame] | 771 | bts->active = false; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 772 | /* free all TBF */ |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 773 | 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 Pedrol | 2d92e39 | 2022-03-30 22:09:06 +0200 | [diff] [blame] | 776 | if (bts->trx[trx_nr].pdch[ts_nr].is_enabled()) |
| 777 | bts->trx[trx_nr].pdch[ts_nr].disable(); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 778 | } |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 779 | gprs_bssgp_destroy(bts); |
Daniel Willmann | 6d8884d | 2014-06-04 18:30:59 +0200 | [diff] [blame] | 780 | exit(0); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 781 | } |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 782 | LOGP(DL1IF, LOGL_INFO, "BTS available\n"); |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 783 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 785 | LOGP(DL1IF, LOGL_DEBUG, " lac=%d\n", info_ind->lac); |
| 786 | LOGP(DL1IF, LOGL_DEBUG, " rac=%d\n", info_ind->rac); |
Harald Welte | 1473b37 | 2019-03-21 19:48:55 +0100 | [diff] [blame] | 787 | LOGP(DL1IF, LOGL_DEBUG, " cell_id=%d\n", info_ind->cell_id); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 788 | LOGP(DL1IF, LOGL_DEBUG, " bsic=%d\n", info_ind->bsic); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 789 | 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 Pedrol | 2e6b60d | 2021-01-20 13:48:31 +0100 | [diff] [blame] | 817 | 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 Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 823 | bts->bsic = info_ind->bsic; |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 824 | |
| 825 | bts->cs_mask = 1 << 0; /* We need at least 1 CS, let's enable CS1 */ |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 826 | for (i = 0; i < 4; i++) { |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 827 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 831 | } |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 832 | bts_recalc_max_cs(bts); |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 833 | |
| 834 | bts->mcs_mask = 0; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 835 | for (i = 0; i < 9; i++) { |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 836 | uint8_t allowed = !!(info_ind->flags & (PCU_IF_FLAG_MCS1 << i)); |
| 837 | bts->mcs_mask |= allowed << i; |
Pau Espin Pedrol | 87eec1f | 2020-10-30 18:46:24 +0100 | [diff] [blame] | 838 | if (allowed) |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 839 | LOGP(DL1IF, LOGL_DEBUG, " Use MCS%d\n", i + 1); |
Pau Espin Pedrol | 87eec1f | 2020-10-30 18:46:24 +0100 | [diff] [blame] | 840 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 841 | } |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 842 | bts_recalc_max_mcs(bts); |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 843 | |
Pau Espin Pedrol | b47b137 | 2020-11-03 15:59:39 +0100 | [diff] [blame] | 844 | LOGP(DL1IF, LOGL_DEBUG, " initial_cs=%u%s\n", info_ind->initial_cs, |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 845 | the_pcu->vty.force_initial_cs ? " (VTY forced, ignoring)" : ""); |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 846 | bts->pcuif_info_ind.initial_cs = info_ind->initial_cs; |
| 847 | bts_recalc_initial_cs(bts); |
Pau Espin Pedrol | b47b137 | 2020-11-03 15:59:39 +0100 | [diff] [blame] | 848 | |
| 849 | LOGP(DL1IF, LOGL_DEBUG, " initial_mcs=%u%s\n", info_ind->initial_mcs, |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 850 | the_pcu->vty.force_initial_mcs ? " (VTY forced, ignoring)" : ""); |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 851 | bts->pcuif_info_ind.initial_mcs = info_ind->initial_mcs; |
| 852 | bts_recalc_initial_mcs(bts); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 853 | |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 854 | 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 Yanitskiy | c1a726c | 2020-10-08 22:46:26 +0700 | [diff] [blame] | 860 | LOGP(DL1IF, LOGL_ERROR, "Failed to init BSSGP\n"); |
Alexander Couzens | 9b5c960 | 2020-07-28 13:47:18 +0200 | [diff] [blame] | 861 | goto bssgp_failed; |
| 862 | } |
| 863 | |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 864 | rc = pcu_info_ind_ns(pcu->bts, info_ind); |
| 865 | if (rc < 0) { |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 866 | LOGP(DL1IF, LOGL_ERROR, "No NSVC available to connect to the SGSN!\n"); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 867 | goto bssgp_failed; |
| 868 | } |
| 869 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 870 | if (info_ind->t3142) { /* if timer values are set */ |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 871 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 876 | bts->n3101 = info_ind->n3101; |
| 877 | bts->n3103 = info_ind->n3103; |
| 878 | bts->n3105 = info_ind->n3105; |
| 879 | } |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 880 | |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 881 | 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 Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 883 | if ((info_ind->flags & PCU_IF_FLAG_SYSMO) |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 884 | && info_ind->trx[trx_nr].hlayer1) { |
Max | cad867e | 2016-04-21 14:35:55 +0200 | [diff] [blame] | 885 | #ifdef ENABLE_DIRECT_PHY |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 886 | 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 Maier | c82c948 | 2023-03-03 11:39:00 +0100 | [diff] [blame] | 890 | bts->nr, trx_nr, |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 891 | info_ind->trx[trx_nr].hlayer1, |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 892 | the_pcu->gsmtap); |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 893 | if (!bts->trx[trx_nr].fl1h) { |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 894 | LOGP(DL1IF, LOGL_FATAL, "Failed to open direct " |
Philipp Maier | 0cb3b2a | 2023-02-27 15:11:29 +0100 | [diff] [blame] | 895 | "PHY access for PDCH.\n"); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 896 | exit(0); |
| 897 | } |
| 898 | #else |
Philipp Maier | 0cb3b2a | 2023-02-27 15:11:29 +0100 | [diff] [blame] | 899 | LOGP(DL1IF, LOGL_FATAL, "Compiled without direct PHY " |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 900 | "access for PDCH, but enabled at " |
| 901 | "BTS. Please deactivate it!\n"); |
| 902 | exit(0); |
| 903 | #endif |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 904 | } |
| 905 | |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 906 | for (ts_nr = 0; ts_nr < ARRAY_SIZE(bts->trx[0].pdch); ts_nr++) { |
Philipp Maier | 2d222a1 | 2022-10-27 15:25:31 +0200 | [diff] [blame] | 907 | const struct gsm_pcu_if_info_trx_ts *its = &info_ind->trx[trx_nr].ts[ts_nr]; |
Vadim Yanitskiy | 0f41b71 | 2020-07-24 01:28:13 +0700 | [diff] [blame] | 908 | struct gprs_rlcmac_pdch *pdch = &bts->trx[trx_nr].pdch[ts_nr]; |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 909 | if ((info_ind->trx[trx_nr].pdch_mask & (1 << ts_nr))) { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 910 | /* FIXME: activate dynamically at RLCMAC */ |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 911 | if (!pdch->is_enabled()) { |
Max | cad867e | 2016-04-21 14:35:55 +0200 | [diff] [blame] | 912 | #ifdef ENABLE_DIRECT_PHY |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 913 | if ((info_ind->flags & |
| 914 | PCU_IF_FLAG_SYSMO)) |
| 915 | l1if_connect_pdch( |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 916 | bts->trx[trx_nr].fl1h, ts_nr); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 917 | #endif |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 918 | pcu_tx_act_req(bts, pdch, 1); |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 919 | pdch->enable(); |
Andreas Eversberg | 3b7461c | 2012-07-20 11:19:59 +0200 | [diff] [blame] | 920 | } |
Vadim Yanitskiy | 8e2bd1e | 2020-07-21 00:54:42 +0700 | [diff] [blame] | 921 | |
| 922 | pdch->tsc = its->tsc; |
| 923 | |
| 924 | /* (Optional) frequency hopping parameters */ |
Philipp Maier | 2e49058 | 2022-10-27 15:07:57 +0200 | [diff] [blame] | 925 | if (its->hopping) { |
Vadim Yanitskiy | 8e2bd1e | 2020-07-21 00:54:42 +0700 | [diff] [blame] | 926 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 942 | } else { |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 943 | if (pdch->is_enabled()) { |
Philipp Maier | 72ed333 | 2023-02-27 15:32:00 +0100 | [diff] [blame] | 944 | #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 Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 948 | pcu_tx_act_req(bts, pdch, 0); |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 949 | pdch->disable(); |
Andreas Eversberg | 3b7461c | 2012-07-20 11:19:59 +0200 | [diff] [blame] | 950 | } |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | } |
| 954 | |
Stefan Sperling | 5b22fb7 | 2018-02-14 19:46:33 +0100 | [diff] [blame] | 955 | bts->active = true; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 956 | return rc; |
| 957 | } |
| 958 | |
Philipp Maier | 4bac398 | 2023-02-03 16:52:42 +0100 | [diff] [blame] | 959 | /* Query E1 CCU connection parameters by TS and TRX number */ |
| 960 | int 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 */ |
| 976 | static 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 | |
| 991 | static 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 Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1026 | static int pcu_rx_time_ind(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_time_ind *time_ind) |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 1027 | { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1028 | uint8_t fn13 = time_ind->fn % 13; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 1029 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1030 | /* omit frame numbers not starting at a MAC block */ |
| 1031 | if (fn13 != 0 && fn13 != 4 && fn13 != 8) |
| 1032 | return 0; |
Max | 3741f14 | 2017-06-26 12:10:12 +0200 | [diff] [blame] | 1033 | |
| 1034 | LOGP(DL1IF, LOGL_DEBUG, "Time indication received: %d\n", time_ind->fn % 52); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1035 | |
Pau Espin Pedrol | 3061711 | 2021-03-05 18:59:05 +0100 | [diff] [blame] | 1036 | /* Ignore TIME.ind completely, we nowadays relay on DATA.ind always |
| 1037 | * providing all block FNs. */ |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 1038 | return 0; |
| 1039 | } |
| 1040 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1041 | static int pcu_rx_pag_req(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_pag_req *pag_req) |
Andreas Eversberg | 2b91464 | 2012-07-19 13:06:26 +0200 | [diff] [blame] | 1042 | { |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 1043 | struct osmo_mobile_identity mi; |
Pau Espin Pedrol | bd54205 | 2021-05-13 17:44:51 +0200 | [diff] [blame] | 1044 | struct GprsMs *ms = NULL; |
| 1045 | struct paging_req_cs req = { .chan_needed = pag_req->chan_needed, |
| 1046 | .tlli = GSM_RESERVED_TMSI }; |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 1047 | int rc; |
| 1048 | |
Andreas Eversberg | 2b91464 | 2012-07-19 13:06:26 +0200 | [diff] [blame] | 1049 | 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 Pedrol | 32499b6 | 2019-12-09 13:55:12 +0100 | [diff] [blame] | 1052 | /* 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 Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 1059 | 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 Pedrol | bd54205 | 2021-05-13 17:44:51 +0200 | [diff] [blame] | 1065 | 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 Eversberg | 2b91464 | 2012-07-19 13:06:26 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1084 | static int pcu_rx_susp_req(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_susp_req *susp_req) |
Harald Welte | 3447c4a | 2017-07-11 00:06:38 +0200 | [diff] [blame] | 1085 | { |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 1086 | struct bssgp_bvc_ctx *bctx = the_pcu->bssgp.bctx; |
Pau Espin Pedrol | bd9973a | 2020-09-22 15:57:37 +0200 | [diff] [blame] | 1087 | GprsMs *ms; |
| 1088 | struct gprs_rlcmac_dl_tbf *dl_tbf; |
| 1089 | struct gprs_rlcmac_ul_tbf *ul_tbf; |
Harald Welte | 3447c4a | 2017-07-11 00:06:38 +0200 | [diff] [blame] | 1090 | 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 Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1097 | if ((ms = bts_ms_store(bts)->get_ms(susp_req->tlli))) { |
Pau Espin Pedrol | bd9973a | 2020-09-22 15:57:37 +0200 | [diff] [blame] | 1098 | /* 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 Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1100 | dl_tbf = ms_dl_tbf(ms); |
| 1101 | ul_tbf = ms_ul_tbf(ms); |
Pau Espin Pedrol | bd9973a | 2020-09-22 15:57:37 +0200 | [diff] [blame] | 1102 | if (dl_tbf) |
| 1103 | tbf_free(dl_tbf); |
| 1104 | if (ul_tbf) |
| 1105 | tbf_free(ul_tbf); |
| 1106 | } |
| 1107 | |
Harald Welte | 3447c4a | 2017-07-11 00:06:38 +0200 | [diff] [blame] | 1108 | if (!bctx) |
| 1109 | return -1; |
| 1110 | |
| 1111 | return bssgp_tx_suspend(bctx->nsei, susp_req->tlli, &ra_id); |
| 1112 | } |
| 1113 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1114 | static int pcu_rx_app_info_req(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_app_info_req *app_info_req) |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1115 | { |
Pau Espin Pedrol | 54faf02 | 2021-01-14 12:12:43 +0100 | [diff] [blame] | 1116 | struct llist_head *tmp; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1117 | |
| 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 Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1121 | bts->app_info_pending = 0; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1122 | llist_for_each(tmp, bts_ms_store(bts)->ms_list()) { |
Pau Espin Pedrol | 54faf02 | 2021-01-14 12:12:43 +0100 | [diff] [blame] | 1123 | GprsMs *ms = llist_entry(tmp, typeof(*ms), list); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1124 | if (!ms_dl_tbf(ms)) |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1125 | continue; |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1126 | bts->app_info_pending++; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1127 | ms->app_info_pending = true; |
| 1128 | } |
| 1129 | |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1130 | if (!bts->app_info_pending) { |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1131 | 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 Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1136 | if (bts->app_info) { |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1137 | LOGP(DL1IF, LOGL_NOTICE, "Previous Packet Application Information was not sent to all subscribers," |
| 1138 | " overwriting with new one\n"); |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1139 | msgb_free(bts->app_info); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | LOGP(DL1IF, LOGL_INFO, "Sending Packet Application Information to %i subscribers with active TBF\n", |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1143 | bts->app_info_pending); |
| 1144 | bts->app_info = gprs_rlcmac_app_info_msg(app_info_req); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1145 | return 0; |
| 1146 | } |
| 1147 | |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 1148 | static 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 Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1188 | static int pcu_rx_container(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_container *container) |
| 1189 | { |
| 1190 | int rc; |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 1191 | uint16_t data_length = osmo_load16be(&container->length); |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1192 | |
| 1193 | switch (container->msg_type) { |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 1194 | 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 Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1202 | 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); |
| 1219 | int pcu_rx(struct gsm_pcu_if *pcu_prim, size_t pcu_prim_length) |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 1220 | { |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1221 | int rc = 0; |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1222 | size_t exp_len; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1223 | 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 Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 1232 | |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1233 | switch (pcu_prim->msg_type) { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1234 | case PCU_IF_MSG_DATA_IND: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1235 | CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.data_ind); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1236 | rc = pcu_rx_data_ind(bts, &pcu_prim->u.data_ind); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1237 | break; |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 1238 | case PCU_IF_MSG_DATA_CNF: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1239 | CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.data_cnf); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1240 | rc = pcu_rx_data_cnf(bts, &pcu_prim->u.data_cnf); |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 1241 | break; |
Philipp Maier | 7c3fd98 | 2023-02-01 16:10:52 +0100 | [diff] [blame] | 1242 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1246 | case PCU_IF_MSG_RTS_REQ: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1247 | CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.rts_req); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1248 | rc = pcu_rx_rts_req(bts, &pcu_prim->u.rts_req); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1249 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1250 | case PCU_IF_MSG_RACH_IND: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1251 | CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.rach_ind); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1252 | rc = pcu_rx_rach_ind(bts, &pcu_prim->u.rach_ind); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1253 | break; |
| 1254 | case PCU_IF_MSG_INFO_IND: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1255 | CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.info_ind); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1256 | rc = pcu_rx_info_ind(bts, &pcu_prim->u.info_ind); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1257 | break; |
Philipp Maier | 4bac398 | 2023-02-03 16:52:42 +0100 | [diff] [blame] | 1258 | 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 Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1262 | case PCU_IF_MSG_TIME_IND: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1263 | CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.time_ind); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1264 | rc = pcu_rx_time_ind(bts, &pcu_prim->u.time_ind); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1265 | break; |
Andreas Eversberg | 2b91464 | 2012-07-19 13:06:26 +0200 | [diff] [blame] | 1266 | case PCU_IF_MSG_PAG_REQ: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1267 | CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.pag_req); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1268 | rc = pcu_rx_pag_req(bts, &pcu_prim->u.pag_req); |
Andreas Eversberg | 2b91464 | 2012-07-19 13:06:26 +0200 | [diff] [blame] | 1269 | break; |
Harald Welte | 3447c4a | 2017-07-11 00:06:38 +0200 | [diff] [blame] | 1270 | case PCU_IF_MSG_SUSP_REQ: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1271 | CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.susp_req); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1272 | rc = pcu_rx_susp_req(bts, &pcu_prim->u.susp_req); |
Harald Welte | 3447c4a | 2017-07-11 00:06:38 +0200 | [diff] [blame] | 1273 | break; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1274 | case PCU_IF_MSG_APP_INFO_REQ: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1275 | CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.app_info_req); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1276 | rc = pcu_rx_app_info_req(bts, &pcu_prim->u.app_info_req); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1277 | break; |
Vadim Yanitskiy | b657213 | 2021-06-20 21:05:24 +0200 | [diff] [blame] | 1278 | case PCU_IF_MSG_INTERF_IND: |
| 1279 | /* TODO: handle interference reports */ |
| 1280 | break; |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1281 | 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 Yanitskiy | 52f882e | 2023-03-27 04:23:54 +0700 | [diff] [blame] | 1288 | rc = -EINVAL; |
| 1289 | break; |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1290 | } |
| 1291 | rc = pcu_rx_container(bts, &pcu_prim->u.container); |
| 1292 | break; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1293 | default: |
Thorsten Alteholz | 8bb7904 | 2018-10-06 10:42:58 +0200 | [diff] [blame] | 1294 | LOGP(DL1IF, LOGL_ERROR, "Received unknown PCU msg type %d\n", |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1295 | pcu_prim->msg_type); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1296 | rc = -EINVAL; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 1297 | } |
Philipp Maier | 8ccf704 | 2018-04-10 13:12:42 +0200 | [diff] [blame] | 1298 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1299 | return rc; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 1300 | } |