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> |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 43 | |
| 44 | #include <nacc_fsm.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 45 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 46 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 47 | #include <gprs_rlcmac.h> |
| 48 | #include <pcu_l1_if.h> |
| 49 | #include <gprs_debug.h> |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 50 | #include <gprs_bssgp_pcu.h> |
Harald Welte | 68fc127 | 2016-11-16 22:48:33 +0100 | [diff] [blame] | 51 | #include <osmocom/pcu/pcuif_proto.h> |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 52 | #include <bts.h> |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 53 | #include <pdch.h> |
Pau Espin Pedrol | bd9973a | 2020-09-22 15:57:37 +0200 | [diff] [blame] | 54 | #include <tbf_ul.h> |
| 55 | #include <tbf_dl.h> |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 56 | #include <gprs_ms_storage.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 57 | |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 58 | // FIXME: move this, when changed from c++ to c. |
| 59 | extern "C" { |
Max | 58b6646 | 2016-05-13 10:34:15 +0200 | [diff] [blame] | 60 | void *l1if_open_pdch(uint8_t trx_no, uint32_t hlayer1, |
| 61 | struct gsmtap_inst *gsmtap); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 62 | int l1if_connect_pdch(void *obj, uint8_t ts); |
| 63 | int l1if_pdch_req(void *obj, uint8_t ts, int is_ptcch, uint32_t fn, |
| 64 | uint16_t arfcn, uint8_t block_nr, uint8_t *data, uint8_t len); |
| 65 | } |
| 66 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 67 | extern void *tall_pcu_ctx; |
| 68 | |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 69 | #define PAGING_GROUP_LEN 3 |
| 70 | |
| 71 | /* returns [0,999] on success, > 999 on error */ |
| 72 | uint16_t imsi2paging_group(const char* imsi) |
| 73 | { |
| 74 | uint16_t pgroup = 0; |
Vadim Yanitskiy | bd0b0b3 | 2020-01-16 00:25:48 +0700 | [diff] [blame] | 75 | size_t len; |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 76 | |
Vadim Yanitskiy | bd0b0b3 | 2020-01-16 00:25:48 +0700 | [diff] [blame] | 77 | len = (imsi != NULL) ? strlen(imsi) : 0; |
| 78 | if (len < PAGING_GROUP_LEN) |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 79 | return 0xFFFF; |
| 80 | imsi += len - PAGING_GROUP_LEN; |
| 81 | |
| 82 | while (*imsi != '\0') { |
| 83 | if (!isdigit(*imsi)) |
| 84 | return 0xFFFF; |
| 85 | pgroup *= 10; |
| 86 | pgroup += *imsi - '0'; |
| 87 | imsi++; |
| 88 | } |
| 89 | return pgroup; |
| 90 | } |
| 91 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 92 | /* |
| 93 | * PCU messages |
| 94 | */ |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 95 | |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 96 | /* Can be used to allocate message with non-variable size */ |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 97 | struct msgb *pcu_msgb_alloc(uint8_t msg_type, uint8_t bts_nr) |
| 98 | { |
| 99 | struct msgb *msg; |
| 100 | struct gsm_pcu_if *pcu_prim; |
| 101 | |
| 102 | msg = msgb_alloc(sizeof(struct gsm_pcu_if), "pcu_sock_tx"); |
| 103 | if (!msg) |
| 104 | return NULL; |
| 105 | msgb_put(msg, sizeof(struct gsm_pcu_if)); |
| 106 | pcu_prim = (struct gsm_pcu_if *) msg->data; |
| 107 | pcu_prim->msg_type = msg_type; |
| 108 | pcu_prim->bts_nr = bts_nr; |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 109 | |
| 110 | return msg; |
| 111 | } |
| 112 | |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 113 | /* Allocate message with extra size, only reserve pcuif msg hdr */ |
| 114 | static struct msgb *pcu_msgb_alloc_ext_size(uint8_t msg_type, uint8_t bts_nr, size_t extra_size) |
| 115 | { |
| 116 | struct msgb *msg; |
| 117 | struct gsm_pcu_if *pcu_prim; |
| 118 | msg = msgb_alloc(sizeof(struct gsm_pcu_if) + extra_size, "pcu_sock_tx"); |
| 119 | /* Only header is filled, caller is responible for reserving + filling |
| 120 | * message type specific contents: */ |
| 121 | msgb_put(msg, PCUIF_HDR_SIZE); |
| 122 | pcu_prim = (struct gsm_pcu_if *) msgb_data(msg); |
| 123 | pcu_prim->msg_type = msg_type; |
| 124 | pcu_prim->bts_nr = bts_nr; |
| 125 | return msg; |
| 126 | } |
| 127 | |
Max | 0a8fae8 | 2017-03-08 18:53:30 +0100 | [diff] [blame] | 128 | const struct value_string gsm_pcu_if_text_type_names[] = { |
| 129 | OSMO_VALUE_STRING(PCU_VERSION), |
| 130 | OSMO_VALUE_STRING(PCU_OML_ALERT), |
| 131 | { 0, NULL } |
| 132 | }; |
| 133 | |
| 134 | int pcu_tx_txt_ind(enum gsm_pcu_if_text_type t, const char *fmt, ...) |
| 135 | { |
| 136 | struct gsm_pcu_if *pcu_prim; |
| 137 | struct gsm_pcu_if_txt_ind *txt; |
| 138 | va_list ap; |
| 139 | char *rep; |
| 140 | struct msgb *msg = pcu_msgb_alloc(PCU_IF_MSG_TXT_IND, 0); |
| 141 | if (!msg) |
| 142 | return -ENOMEM; |
| 143 | |
| 144 | pcu_prim = (struct gsm_pcu_if *) msg->data; |
| 145 | txt = &pcu_prim->u.txt_ind; |
| 146 | txt->type = t; |
| 147 | |
| 148 | va_start(ap, fmt); |
| 149 | rep = talloc_vasprintf(tall_pcu_ctx, fmt, ap); |
| 150 | va_end(ap); |
| 151 | |
| 152 | if (!rep) |
| 153 | return -ENOMEM; |
| 154 | |
| 155 | osmo_strlcpy(txt->text, rep, TXT_MAX_LEN); |
| 156 | talloc_free(rep); |
| 157 | |
| 158 | LOGP(DL1IF, LOGL_INFO, "Sending %s TXT as %s to BTS\n", txt->text, |
| 159 | get_value_string(gsm_pcu_if_text_type_names, t)); |
| 160 | |
| 161 | return pcu_sock_send(msg); |
| 162 | } |
| 163 | |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 164 | static int pcu_tx_act_req(struct gprs_rlcmac_bts *bts, const struct gprs_rlcmac_pdch *pdch, |
| 165 | uint8_t activate) |
Ivan Kluchnikov | 4277f0c | 2012-04-12 14:24:35 +0400 | [diff] [blame] | 166 | { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 167 | struct msgb *msg; |
| 168 | struct gsm_pcu_if *pcu_prim; |
| 169 | struct gsm_pcu_if_act_req *act_req; |
| 170 | |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 171 | LOGPDCH(pdch, DL1IF, LOGL_INFO, "Sending %s request\n", |
| 172 | (activate) ? "activate" : "deactivate"); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 173 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 174 | msg = pcu_msgb_alloc(PCU_IF_MSG_ACT_REQ, bts->nr); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 175 | if (!msg) |
| 176 | return -ENOMEM; |
| 177 | pcu_prim = (struct gsm_pcu_if *) msg->data; |
| 178 | act_req = &pcu_prim->u.act_req; |
| 179 | act_req->activate = activate; |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 180 | act_req->trx_nr = pdch->trx_no(); |
| 181 | act_req->ts_nr = pdch->ts_no; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 182 | |
| 183 | return pcu_sock_send(msg); |
| 184 | } |
| 185 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 186 | 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] | 187 | uint16_t arfcn, uint32_t fn, uint8_t block_nr, uint8_t *data, |
| 188 | uint8_t len) |
| 189 | { |
| 190 | struct msgb *msg; |
| 191 | struct gsm_pcu_if *pcu_prim; |
| 192 | struct gsm_pcu_if_data *data_req; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 193 | int current_fn = bts_current_frame_number(bts); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 194 | |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 195 | LOGP(DL1IF, LOGL_DEBUG, "(bts=%u,trx=%u,ts=%u) FN=%u Sending data request: sapi=%d " |
| 196 | "arfcn=%d cur_fn=%d block=%d data=%s\n", bts->nr, trx, ts, fn, sapi, |
| 197 | arfcn, current_fn, block_nr, osmo_hexdump(data, len)); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 198 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 199 | msg = pcu_msgb_alloc(PCU_IF_MSG_DATA_REQ, bts->nr); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 200 | if (!msg) |
| 201 | return -ENOMEM; |
| 202 | pcu_prim = (struct gsm_pcu_if *) msg->data; |
| 203 | data_req = &pcu_prim->u.data_req; |
| 204 | |
| 205 | data_req->sapi = sapi; |
| 206 | data_req->fn = fn; |
| 207 | data_req->arfcn = arfcn; |
| 208 | data_req->trx_nr = trx; |
| 209 | data_req->ts_nr = ts; |
| 210 | data_req->block_nr = block_nr; |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 211 | if (len) |
| 212 | memcpy(data_req->data, data, len); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 213 | data_req->len = len; |
| 214 | |
| 215 | return pcu_sock_send(msg); |
| 216 | } |
| 217 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 218 | 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] | 219 | uint32_t fn, uint8_t block_nr) |
| 220 | { |
Max | b216c6b | 2017-09-01 11:00:39 +0200 | [diff] [blame] | 221 | #ifdef ENABLE_DIRECT_PHY |
Max | 528ff39 | 2016-02-22 11:42:33 +0100 | [diff] [blame] | 222 | if (bts->trx[trx].fl1h) { |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 223 | if (!msg) /* Simply skip sending idle frames to L1 */ |
| 224 | return; |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 225 | l1if_pdch_req(bts->trx[trx].fl1h, ts, 0, fn, arfcn, block_nr, |
| 226 | msg->data, msg->len); |
Max | 528ff39 | 2016-02-22 11:42:33 +0100 | [diff] [blame] | 227 | msgb_free(msg); |
| 228 | return; |
| 229 | } |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 230 | #endif |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 231 | if (!msg) { |
| 232 | pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PDTCH, arfcn, fn, block_nr, |
| 233 | NULL, 0); |
| 234 | return; |
| 235 | } |
| 236 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 237 | 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] | 238 | msg->data, msg->len); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 239 | msgb_free(msg); |
Ivan Kluchnikov | 4277f0c | 2012-04-12 14:24:35 +0400 | [diff] [blame] | 240 | } |
| 241 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 242 | void pcu_l1if_tx_ptcch(struct gprs_rlcmac_bts *bts, |
| 243 | uint8_t trx, uint8_t ts, uint16_t arfcn, |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 244 | uint32_t fn, uint8_t block_nr, |
| 245 | uint8_t *data, size_t data_len) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 246 | { |
Vadim Yanitskiy | f5dde9f | 2022-09-30 02:21:59 +0700 | [diff] [blame] | 247 | 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] | 248 | 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] | 249 | #ifdef ENABLE_DIRECT_PHY |
Max | 528ff39 | 2016-02-22 11:42:33 +0100 | [diff] [blame] | 250 | if (bts->trx[trx].fl1h) { |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 251 | if (!data_len) /* Simply skip sending idle frames to L1 */ |
| 252 | return; |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 253 | 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] | 254 | return; |
| 255 | } |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 256 | #endif |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 257 | if (!data_len) { |
| 258 | pcu_tx_data_req(bts, trx, ts, PCU_IF_SAPI_PTCCH, arfcn, fn, block_nr, NULL, 0); |
| 259 | return; |
| 260 | } |
| 261 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 262 | 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] | 263 | } |
| 264 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 265 | 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] | 266 | { |
Pau Espin Pedrol | d752d7c | 2019-10-07 20:56:48 +0200 | [diff] [blame] | 267 | uint8_t data[GSM_MACBLOCK_LEN]; /* prefix PLEN */ |
| 268 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 269 | /* FIXME: why does OpenBTS has no PLEN and no fill in message? */ |
| 270 | bitvec_pack(block, data + 1); |
| 271 | data[0] = (plen << 2) | 0x01; |
Pau Espin Pedrol | 5854370 | 2019-09-30 19:07:16 +0200 | [diff] [blame] | 272 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 273 | if (the_pcu->gsmtap_categ_mask & (1 << PCU_GSMTAP_C_DL_AGCH)) |
| 274 | 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] | 275 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 276 | pcu_tx_data_req(bts, 0, 0, PCU_IF_SAPI_AGCH, 0, 0, 0, data, GSM_MACBLOCK_LEN); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 277 | } |
| 278 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 279 | void pcu_l1if_tx_pch(struct gprs_rlcmac_bts *bts, bitvec * block, int plen, uint16_t pgroup) |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 280 | { |
Pau Espin Pedrol | 8dc09e7 | 2019-10-07 20:56:02 +0200 | [diff] [blame] | 281 | uint8_t data[PAGING_GROUP_LEN + GSM_MACBLOCK_LEN]; |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 282 | int i; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 283 | |
Pau Espin Pedrol | 8dc09e7 | 2019-10-07 20:56:02 +0200 | [diff] [blame] | 284 | /* prepend paging group */ |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 285 | for (i = 0; i < PAGING_GROUP_LEN; i++) { |
| 286 | data[PAGING_GROUP_LEN - 1 - i] = '0' + (char)(pgroup % 10); |
| 287 | pgroup = pgroup / 10; |
| 288 | } |
| 289 | OSMO_ASSERT(pgroup == 0); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 290 | |
Pau Espin Pedrol | 8dc09e7 | 2019-10-07 20:56:02 +0200 | [diff] [blame] | 291 | /* block provided by upper layer comes without first byte (plen), |
| 292 | * prepend it manually: |
| 293 | */ |
| 294 | OSMO_ASSERT(sizeof(data) >= PAGING_GROUP_LEN + 1 + block->data_len); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 295 | data[3] = (plen << 2) | 0x01; |
Pau Espin Pedrol | 8dc09e7 | 2019-10-07 20:56:02 +0200 | [diff] [blame] | 296 | bitvec_pack(block, data + PAGING_GROUP_LEN + 1); |
Pau Espin Pedrol | 5854370 | 2019-09-30 19:07:16 +0200 | [diff] [blame] | 297 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 298 | if (the_pcu->gsmtap_categ_mask & (1 << PCU_GSMTAP_C_DL_PCH)) |
| 299 | 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] | 300 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 301 | pcu_tx_data_req(bts, 0, 0, PCU_IF_SAPI_PCH, 0, 0, 0, data, PAGING_GROUP_LEN + GSM_MACBLOCK_LEN); |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 302 | } |
| 303 | |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 304 | int pcu_tx_neigh_addr_res_req(struct gprs_rlcmac_bts *bts, const struct neigh_cache_entry_key *neigh_key) |
| 305 | { |
| 306 | struct msgb *msg; |
| 307 | struct gsm_pcu_if *pcu_prim; |
| 308 | struct gsm_pcu_if_neigh_addr_req *naddr_req; |
| 309 | |
| 310 | LOGP(DL1IF, LOGL_DEBUG, "(bts=%u) Tx Neighbor Address Resolution Request: " NEIGH_CACHE_ENTRY_KEY_FMT "\n", |
| 311 | bts->nr, NEIGH_CACHE_ENTRY_KEY_ARGS(neigh_key)); |
| 312 | |
| 313 | msg = pcu_msgb_alloc_ext_size(PCU_IF_MSG_CONTAINER, bts->nr, sizeof(struct gsm_pcu_if_neigh_addr_req)); |
| 314 | if (!msg) |
| 315 | return -ENOMEM; |
| 316 | pcu_prim = (struct gsm_pcu_if *) msgb_data(msg); |
| 317 | naddr_req = (struct gsm_pcu_if_neigh_addr_req *)&pcu_prim->u.container.data[0]; |
| 318 | |
| 319 | msgb_put(msg, sizeof(pcu_prim->u.container) + sizeof(struct gsm_pcu_if_neigh_addr_req)); |
| 320 | pcu_prim->u.container.msg_type = PCU_IF_MSG_NEIGH_ADDR_REQ; |
| 321 | osmo_store16be(sizeof(struct gsm_pcu_if_neigh_addr_req), &pcu_prim->u.container.length); |
| 322 | |
| 323 | osmo_store16be(neigh_key->local_lac, &naddr_req->local_lac); |
| 324 | osmo_store16be(neigh_key->local_ci, &naddr_req->local_ci); |
| 325 | osmo_store16be(neigh_key->tgt_arfcn, &naddr_req->tgt_arfcn); |
| 326 | naddr_req->tgt_bsic = neigh_key->tgt_bsic; |
| 327 | |
| 328 | return pcu_sock_send(msg); |
| 329 | } |
| 330 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 331 | 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] | 332 | { |
Pau Espin Pedrol | fecab50 | 2021-03-17 15:26:37 +0100 | [diff] [blame] | 333 | bts_set_current_block_frame_number(bts, fn); |
Jacob Erlbeck | af75ce8 | 2015-08-26 13:22:28 +0200 | [diff] [blame] | 334 | } |
| 335 | |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 336 | 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] | 337 | uint8_t len, uint32_t fn, struct pcu_l1_meas *meas) |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 338 | { |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 339 | int rc; |
| 340 | |
Pau Espin Pedrol | 3bbb3cc | 2021-08-31 14:09:42 +0200 | [diff] [blame] | 341 | if (!pdch->is_enabled()) { |
| 342 | LOGPDCH(pdch, DL1IF, LOGL_INFO, "Received DATA.ind (PDTCH) on disabled TS\n"); |
| 343 | return -EINVAL; |
| 344 | } |
| 345 | |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 346 | rc = pdch->rcv_block(data, len, fn, meas); |
| 347 | pdch_ulc_expire_fn(pdch->ulc, fn); |
| 348 | return rc; |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 349 | } |
| 350 | |
Pau Espin Pedrol | 86f4c09 | 2021-06-08 18:53:40 +0200 | [diff] [blame] | 351 | static int list_arfcn(const struct gprs_rlcmac_bts *bts, const struct gsm_sysinfo_freq *freq, const char *text) |
| 352 | { |
| 353 | int n = 0, i; |
| 354 | for (i = 0; i < 1024; i++) { |
| 355 | if (freq[i].mask) { |
| 356 | if (!n) |
| 357 | LOGP(DL1IF, LOGL_INFO, "BTS%d: %s", bts->nr, text); |
| 358 | LOGPC(DL1IF, LOGL_INFO, " %d", i); |
| 359 | n++; |
| 360 | } |
| 361 | } |
| 362 | if (n) |
| 363 | LOGPC(DL1IF, LOGL_INFO, "\n"); |
| 364 | |
| 365 | return n; |
| 366 | } |
| 367 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 368 | 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] | 369 | { |
Pau Espin Pedrol | 86f4c09 | 2021-06-08 18:53:40 +0200 | [diff] [blame] | 370 | struct gsm48_system_information_type_2 *si2; |
Pau Espin Pedrol | fe8de45 | 2021-02-09 18:47:34 +0100 | [diff] [blame] | 371 | const uint8_t *si_ro; |
Pau Espin Pedrol | 86f4c09 | 2021-06-08 18:53:40 +0200 | [diff] [blame] | 372 | |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 373 | switch (len) { |
| 374 | case 0: |
| 375 | /* Due to historical reasons also accept a completely empty message as |
| 376 | * revoke command for SI13. */ |
| 377 | LOGP(DL1IF, LOGL_ERROR, |
| 378 | "Received PCU data indication that contains no data -- Revoked SI13.\n"); |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 379 | bts->si13_is_set = false; |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 380 | |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 381 | return 0; |
| 382 | case 1: |
| 383 | /* Revoke SI, type is identified by a single byte which is coded after |
| 384 | * enum osmo_sysinfo_type. */ |
| 385 | switch (data[0]) { |
| 386 | case SYSINFO_TYPE_1: |
| 387 | bts->si1_is_set = false; |
| 388 | break; |
Pau Espin Pedrol | 86f4c09 | 2021-06-08 18:53:40 +0200 | [diff] [blame] | 389 | case SYSINFO_TYPE_2: |
| 390 | bts->si2_is_set = false; |
| 391 | break; |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 392 | case SYSINFO_TYPE_3: |
| 393 | bts->si3_is_set = false; |
| 394 | break; |
| 395 | case SYSINFO_TYPE_13: |
| 396 | bts->si13_is_set = false; |
| 397 | break; |
| 398 | default: |
| 399 | LOGP(DL1IF, LOGL_ERROR, |
| 400 | "Received PCU data indication that contains an unsupported system information identifier (%02x,OSMO) -- ignored.\n", data[0]); |
| 401 | return -EINVAL; |
| 402 | } |
| 403 | LOGP(DPCU, LOGL_DEBUG, |
| 404 | "Received PCU data indication: Revoked SI%s\n", |
| 405 | get_value_string(osmo_sitype_strs, data[0])); |
| 406 | return 0; |
| 407 | case GSM_MACBLOCK_LEN: |
| 408 | /* Update SI, type is identified by the RR sysinfo type, which is the |
| 409 | * 3rd byte in the buffer. */ |
| 410 | switch (data[2]) { |
| 411 | case GSM48_MT_RR_SYSINFO_1: |
| 412 | memcpy(bts->si1, data, GSM_MACBLOCK_LEN); |
| 413 | bts->si1_is_set = true; |
| 414 | break; |
Pau Espin Pedrol | 86f4c09 | 2021-06-08 18:53:40 +0200 | [diff] [blame] | 415 | case GSM48_MT_RR_SYSINFO_2: |
| 416 | memcpy(bts->si2, data, GSM_MACBLOCK_LEN); |
| 417 | bts->si2_is_set = true; |
| 418 | si2 = (struct gsm48_system_information_type_2 *)bts->si2; |
| 419 | gsm48_decode_freq_list(bts->si2_bcch_cell_list, si2->bcch_frequency_list, |
| 420 | sizeof(si2->bcch_frequency_list), 0xce, 1); |
| 421 | list_arfcn(bts, bts->si2_bcch_cell_list, "SI2 Neighbour cells in same band:"); |
| 422 | break; |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 423 | case GSM48_MT_RR_SYSINFO_3: |
| 424 | memcpy(bts->si3, data, GSM_MACBLOCK_LEN); |
| 425 | bts->si3_is_set = true; |
| 426 | break; |
| 427 | case GSM48_MT_RR_SYSINFO_13: |
| 428 | memcpy(bts->si13, data, GSM_MACBLOCK_LEN); |
| 429 | bts->si13_is_set = true; |
Pau Espin Pedrol | fe8de45 | 2021-02-09 18:47:34 +0100 | [diff] [blame] | 430 | si_ro = ((struct gsm48_system_information_type_13*)data)->rest_octets; |
Pau Espin Pedrol | d65bd9d | 2021-06-01 16:43:41 +0200 | [diff] [blame] | 431 | 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] | 432 | LOGP(DPCU, LOGL_ERROR, "Error decoding SI13\n"); |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 433 | break; |
| 434 | default: |
| 435 | LOGP(DL1IF, LOGL_ERROR, |
| 436 | "Received PCU data indication that contains an unsupported system information identifier (%02x,RR) -- ignored.\n", data[2]); |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | LOGP(DPCU, LOGL_DEBUG, |
| 440 | "Received PCU data indication: Updated %s: %s\n", |
| 441 | gsm48_pdisc_msgtype_name(data[1], data[2]), |
| 442 | osmo_hexdump_nospc(data + 1, GSM_MACBLOCK_LEN)); |
| 443 | return 0; |
| 444 | default: |
| 445 | LOGP(DL1IF, LOGL_ERROR, |
| 446 | "Received PCU data indication with unexpected data length: %u -- ignored.\n", |
| 447 | len); |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 448 | return -EINVAL; |
| 449 | } |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 450 | } |
| 451 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 452 | 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] | 453 | { |
Max | 528ff39 | 2016-02-22 11:42:33 +0100 | [diff] [blame] | 454 | int rc; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 455 | int current_fn = bts_current_frame_number(bts); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 456 | struct pcu_l1_meas meas = {0}; |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 457 | struct gprs_rlcmac_pdch *pdch; |
Pau Espin Pedrol | 72e3956 | 2020-06-30 17:57:42 +0200 | [diff] [blame] | 458 | uint8_t gsmtap_chantype; |
Max | b216c6b | 2017-09-01 11:00:39 +0200 | [diff] [blame] | 459 | |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 460 | LOGP(DL1IF, LOGL_DEBUG, "(bts=%" PRIu8 ",trx=%" PRIu8 ",ts=%" PRIu8 ") FN=%u " |
| 461 | "Rx DATA.ind: sapi=%d arfcn=%d cur_fn=%d " |
| 462 | "block=%d data=%s\n", bts->nr, data_ind->trx_nr, data_ind->ts_nr, |
| 463 | data_ind->fn, data_ind->sapi, data_ind->arfcn, current_fn, |
| 464 | data_ind->block_nr, osmo_hexdump(data_ind->data, data_ind->len)); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 465 | |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 466 | switch (data_ind->sapi) { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 467 | case PCU_IF_SAPI_PDTCH: |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 468 | 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] | 469 | pcu_l1_meas_set_rssi(&meas, data_ind->rssi); |
Max | b216c6b | 2017-09-01 11:00:39 +0200 | [diff] [blame] | 470 | /* convert BER to % value */ |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 471 | pcu_l1_meas_set_ber(&meas, data_ind->ber10k / 100); |
| 472 | pcu_l1_meas_set_bto(&meas, data_ind->ta_offs_qbits); |
| 473 | pcu_l1_meas_set_link_qual(&meas, data_ind->lqual_cb / 10); |
Vadim Yanitskiy | f17dfc0 | 2019-07-09 16:16:35 +0700 | [diff] [blame] | 474 | |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 475 | LOGPDCH(pdch, DL1IF, LOGL_DEBUG, "FN=%u Rx DATA.ind PDTCH: " |
| 476 | "BER10k = %d, BTO = %d, Q = %d\n", data_ind->fn, |
| 477 | data_ind->ber10k, data_ind->ta_offs_qbits, data_ind->lqual_cb); |
Vadim Yanitskiy | f17dfc0 | 2019-07-09 16:16:35 +0700 | [diff] [blame] | 478 | |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 479 | rc = pcu_rx_data_ind_pdtch(bts, pdch, data_ind->data, data_ind->len, |
| 480 | data_ind->fn, &meas); |
Pau Espin Pedrol | 72e3956 | 2020-06-30 17:57:42 +0200 | [diff] [blame] | 481 | gsmtap_chantype = GSMTAP_CHANNEL_PDTCH; |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 482 | break; |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 483 | case PCU_IF_SAPI_BCCH: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 484 | 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] | 485 | gsmtap_chantype = GSMTAP_CHANNEL_BCCH; |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 486 | break; |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 487 | default: |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 488 | LOGP(DL1IF, LOGL_ERROR, "(bts=%" PRIu8 ",trx=%" PRIu8 ",ts=%" PRIu8 ") " |
| 489 | "FN=%u Rx DATA.ind with unsupported sapi %d\n", |
| 490 | 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] | 491 | rc = -EINVAL; |
Pau Espin Pedrol | 72e3956 | 2020-06-30 17:57:42 +0200 | [diff] [blame] | 492 | gsmtap_chantype = GSMTAP_CHANNEL_UNKNOWN; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 493 | } |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 494 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 495 | if (rc < 0 && (the_pcu->gsmtap_categ_mask & (1 <<PCU_GSMTAP_C_UL_UNKNOWN))) { |
| 496 | 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] | 497 | 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] | 498 | } |
| 499 | |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 500 | return rc; |
| 501 | } |
| 502 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 503 | 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] | 504 | { |
| 505 | int rc = 0; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 506 | int current_fn = bts_current_frame_number(bts); |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 507 | |
Philipp Maier | 7e8e397 | 2018-04-10 13:31:45 +0200 | [diff] [blame] | 508 | LOGP(DL1IF, LOGL_DEBUG, "Data confirm received: sapi=%d fn=%d cur_fn=%d\n", |
| 509 | data_cnf->sapi, data_cnf->fn, current_fn); |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 510 | |
| 511 | switch (data_cnf->sapi) { |
| 512 | case PCU_IF_SAPI_PCH: |
Pau Espin Pedrol | f510f5b | 2022-10-14 16:37:18 +0200 | [diff] [blame] | 513 | if (data_cnf->data[2] == GSM48_MT_RR_IMM_ASS) |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 514 | bts_rcv_imm_ass_cnf(bts, data_cnf->data, data_cnf->fn); |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 515 | break; |
| 516 | default: |
| 517 | LOGP(DL1IF, LOGL_ERROR, "Received PCU data confirm with " |
| 518 | "unsupported sapi %d\n", data_cnf->sapi); |
| 519 | rc = -EINVAL; |
| 520 | } |
| 521 | |
| 522 | return rc; |
| 523 | } |
| 524 | |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 525 | // FIXME: remove this, when changed from c++ to c. |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 526 | 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] | 527 | uint32_t fn, uint8_t block_nr) |
| 528 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 529 | return gprs_rlcmac_rcv_rts_block(bts, |
Max | 878bd1f | 2016-07-20 13:05:05 +0200 | [diff] [blame] | 530 | trx, ts, fn, block_nr); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 531 | } |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 532 | 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] | 533 | uint32_t fn, uint8_t block_nr) |
| 534 | { |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 535 | struct gprs_rlcmac_pdch *pdch; |
| 536 | |
| 537 | /* Prevent buffer overflow */ |
| 538 | if (trx >= ARRAY_SIZE(bts->trx) || ts >= 8) |
| 539 | return -EINVAL; |
| 540 | |
| 541 | /* Make sure PDCH time-slot is enabled */ |
| 542 | pdch = &bts->trx[trx].pdch[ts]; |
Pau Espin Pedrol | 9c2512a | 2022-04-01 18:27:04 +0200 | [diff] [blame] | 543 | if (!pdch_is_enabled(pdch)) |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 544 | return -EAGAIN; |
| 545 | |
Pau Espin Pedrol | eeae776 | 2021-09-20 11:20:09 +0200 | [diff] [blame] | 546 | /* If there's no TBF attached to this PDCH, we can skip Tx of PTCCH |
| 547 | * since there's nothing worthy of being transmitted. This way BTS can |
| 548 | * identify idle blocks and send nothing or dumy blocks with reduced |
| 549 | * energy for the sake of energy saving. |
| 550 | */ |
| 551 | const unsigned num_tbfs = pdch->num_tbfs(GPRS_RLCMAC_DL_TBF) |
| 552 | + pdch->num_tbfs(GPRS_RLCMAC_UL_TBF); |
| 553 | bool skip_idle = (num_tbfs == 0); |
| 554 | #ifdef ENABLE_DIRECT_PHY |
| 555 | /* In DIRECT_PHY mode we want to always submit something to L1 in |
| 556 | * TRX0, since BTS is not preparing dummy bursts on idle TS for us: */ |
| 557 | skip_idle = skip_idle && trx != 0; |
| 558 | #endif |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 559 | if (skip_idle) { |
| 560 | pcu_l1if_tx_ptcch(bts, trx, ts, bts->trx[trx].arfcn, fn, block_nr, |
| 561 | NULL, 0); |
Pau Espin Pedrol | eeae776 | 2021-09-20 11:20:09 +0200 | [diff] [blame] | 562 | return 0; |
Pau Espin Pedrol | fef3da2 | 2021-09-22 13:56:27 +0200 | [diff] [blame] | 563 | } |
Pau Espin Pedrol | eeae776 | 2021-09-20 11:20:09 +0200 | [diff] [blame] | 564 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 565 | 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] | 566 | pdch->ptcch_msg, GSM_MACBLOCK_LEN); |
| 567 | return 0; |
| 568 | } |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 569 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 570 | 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] | 571 | { |
| 572 | int rc = 0; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 573 | int current_fn = bts_current_frame_number(bts); |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 574 | const struct gprs_rlcmac_pdch *pdch; |
| 575 | pdch = &bts->trx[rts_req->trx_nr].pdch[rts_req->ts_nr]; |
Ivan Kluchnikov | 5310d45 | 2012-04-17 22:00:31 +0400 | [diff] [blame] | 576 | |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 577 | LOGPDCH(pdch, DL1IF, LOGL_DEBUG, "FN=%u RX RTS.req: sapi=%d " |
| 578 | "arfcn=%d cur_fn=%d block=%d\n", rts_req->fn, |
| 579 | rts_req->sapi, rts_req->arfcn, current_fn, rts_req->block_nr); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 580 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 581 | switch (rts_req->sapi) { |
| 582 | case PCU_IF_SAPI_PDTCH: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 583 | 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] | 584 | rts_req->fn, rts_req->block_nr); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 585 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 586 | case PCU_IF_SAPI_PTCCH: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 587 | 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] | 588 | rts_req->fn, rts_req->block_nr); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 589 | break; |
| 590 | default: |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 591 | LOGP(DL1IF, LOGL_ERROR, "(bts=%u,trx=%u,ts=%u) FN=%u RX RTS.req with " |
| 592 | "unsupported sapi %d\n", bts->nr, rts_req->trx_nr, rts_req->ts_nr, |
| 593 | rts_req->fn, rts_req->sapi); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 594 | rc = -EINVAL; |
| 595 | } |
| 596 | |
| 597 | return rc; |
| 598 | } |
| 599 | |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 600 | /* C -> C++ adapter for direct DSP access code (e.g. osmo-bts-sysmo) */ |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 601 | 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] | 602 | { |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 603 | struct rach_ind_params rip = { |
| 604 | /* The content of RA is not of interest on PTCCH/U */ |
| 605 | .burst_type = GSM_L1_BURST_TYPE_ACCESS_0, |
| 606 | .is_11bit = false, |
| 607 | .ra = 0x00, |
| 608 | .trx_nr = trx_nr, |
| 609 | .ts_nr = ts_nr, |
| 610 | .rfn = fn, |
| 611 | .qta = qta, |
| 612 | }; |
| 613 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 614 | return bts_rcv_ptcch_rach(bts, &rip); |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 615 | } |
| 616 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 617 | 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] | 618 | { |
| 619 | int rc = 0; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 620 | int current_fn = bts_current_frame_number(bts); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 621 | |
| 622 | LOGP(DL1IF, LOGL_INFO, "RACH request received: sapi=%d " |
Vadim Yanitskiy | b30f28f | 2020-03-29 19:01:58 +0700 | [diff] [blame] | 623 | "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] | 624 | rach_ind->ra, rach_ind->fn, current_fn, rach_ind->is_11bit); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 625 | |
Vadim Yanitskiy | a0a0b7f | 2020-05-21 19:55:46 +0700 | [diff] [blame] | 626 | struct rach_ind_params rip = { |
| 627 | .burst_type = (enum ph_burst_type) rach_ind->burst_type, |
| 628 | .is_11bit = rach_ind->is_11bit > 0, |
| 629 | .ra = rach_ind->ra, |
| 630 | .trx_nr = rach_ind->trx_nr, |
| 631 | .ts_nr = rach_ind->ts_nr, |
| 632 | .rfn = rach_ind->fn, |
| 633 | .qta = rach_ind->qta, |
| 634 | }; |
| 635 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 636 | switch (rach_ind->sapi) { |
| 637 | case PCU_IF_SAPI_RACH: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 638 | rc = bts_rcv_rach(bts, &rip); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 639 | break; |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 640 | case PCU_IF_SAPI_PTCCH: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 641 | rc = bts_rcv_ptcch_rach(bts, &rip); |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 642 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 643 | default: |
| 644 | LOGP(DL1IF, LOGL_ERROR, "Received PCU rach request with " |
| 645 | "unsupported sapi %d\n", rach_ind->sapi); |
| 646 | rc = -EINVAL; |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 647 | } |
| 648 | |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 649 | return rc; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 650 | } |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 651 | |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 652 | static int pcu_info_ind_ns(struct gprs_rlcmac_bts *bts, |
| 653 | const struct gsm_pcu_if_info_ind *info_ind) |
| 654 | { |
| 655 | struct osmo_sockaddr remote[PCU_IF_NUM_NSVC] = { }; |
| 656 | struct osmo_sockaddr local[PCU_IF_NUM_NSVC] = { }; |
| 657 | uint16_t nsvci[PCU_IF_NUM_NSVC] = { }; |
| 658 | uint16_t valid = 0; |
| 659 | |
| 660 | for (unsigned int i = 0; i < PCU_IF_NUM_NSVC; i++) { |
| 661 | struct osmo_sockaddr_str sockstr; |
| 662 | |
| 663 | switch (info_ind->address_type[i]) { |
| 664 | case PCU_IF_ADDR_TYPE_IPV4: |
| 665 | local[i].u.sin.sin_family = AF_INET; |
| 666 | local[i].u.sin.sin_addr.s_addr = INADDR_ANY; |
| 667 | local[i].u.sin.sin_port = htons(info_ind->local_port[i]); |
| 668 | |
| 669 | remote[i].u.sin.sin_family = AF_INET; |
Alexander Couzens | 87c6dd3 | 2020-10-27 13:24:40 +0100 | [diff] [blame] | 670 | memcpy(&remote[i].u.sin.sin_addr, &info_ind->remote_ip[i].v4, |
| 671 | sizeof(struct in_addr)); |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 672 | remote[i].u.sin.sin_port = htons(info_ind->remote_port[i]); |
| 673 | break; |
| 674 | case PCU_IF_ADDR_TYPE_IPV6: |
| 675 | local[i].u.sin6.sin6_family = AF_INET6; |
| 676 | local[i].u.sin6.sin6_addr = in6addr_any; |
| 677 | local[i].u.sin6.sin6_port = htons(info_ind->local_port[i]); |
| 678 | |
| 679 | remote[i].u.sin6.sin6_family = AF_INET6; |
Alexander Couzens | 87c6dd3 | 2020-10-27 13:24:40 +0100 | [diff] [blame] | 680 | memcpy(&remote[i].u.sin6.sin6_addr, |
| 681 | &info_ind->remote_ip[i].v6, |
| 682 | sizeof(struct in6_addr)); |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 683 | remote[i].u.sin6.sin6_port = htons(info_ind->remote_port[i]); |
| 684 | break; |
| 685 | default: |
| 686 | continue; |
| 687 | } |
| 688 | nsvci[i] = info_ind->nsvci[i]; |
| 689 | |
| 690 | LOGP(DL1IF, LOGL_DEBUG, " NS%u nsvci=%u\n", i, nsvci[i]); |
| 691 | if (osmo_sockaddr_str_from_sockaddr(&sockstr, &remote[i].u.sas)) |
| 692 | strcpy(sockstr.ip, "invalid"); |
| 693 | |
| 694 | LOGP(DL1IF, LOGL_DEBUG, " NS%u address: r=%s:%u<->l=NULL:%u\n", |
| 695 | i, sockstr.ip, sockstr.port, info_ind->local_port[i]); |
| 696 | |
| 697 | valid |= 1 << i; |
| 698 | } |
| 699 | |
| 700 | if (valid == 0) { |
| 701 | LOGP(DL1IF, LOGL_ERROR, "No NSVC available to connect to the SGSN!\n"); |
| 702 | return -EINVAL; |
| 703 | } |
| 704 | |
Alexander Couzens | 94a367f | 2021-02-16 16:57:15 +0100 | [diff] [blame] | 705 | 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] | 706 | } |
| 707 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 708 | 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] | 709 | { |
Holger Hans Peter Freyther | e8d9a5f | 2013-07-28 19:11:20 +0200 | [diff] [blame] | 710 | struct gprs_bssgp_pcu *pcu; |
Harald Welte | bb47d95 | 2016-11-17 18:40:02 +0100 | [diff] [blame] | 711 | int rc = 0; |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 712 | unsigned int trx_nr, ts_nr; |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 713 | unsigned int i; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 714 | |
Andreas Eversberg | 8389fd0 | 2012-07-18 10:06:48 +0200 | [diff] [blame] | 715 | if (info_ind->version != PCU_IF_VERSION) { |
Vadim Yanitskiy | fad2128 | 2020-07-19 02:05:33 +0700 | [diff] [blame] | 716 | fprintf(stderr, "PCU interface version number of BTS (%u) is " |
| 717 | "different (%u).\nPlease re-compile!\n", |
Andreas Eversberg | 8389fd0 | 2012-07-18 10:06:48 +0200 | [diff] [blame] | 718 | info_ind->version, PCU_IF_VERSION); |
| 719 | exit(-1); |
| 720 | } |
| 721 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 722 | LOGP(DL1IF, LOGL_DEBUG, "Info indication received:\n"); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 723 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 724 | if (!(info_ind->flags & PCU_IF_FLAG_ACTIVE)) { |
| 725 | LOGP(DL1IF, LOGL_NOTICE, "BTS not available\n"); |
Stefan Sperling | 5b22fb7 | 2018-02-14 19:46:33 +0100 | [diff] [blame] | 726 | if (!bts->active) |
| 727 | return -EAGAIN; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 728 | bssgp_failed: |
Stefan Sperling | 5b22fb7 | 2018-02-14 19:46:33 +0100 | [diff] [blame] | 729 | bts->active = false; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 730 | /* free all TBF */ |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 731 | for (trx_nr = 0; trx_nr < ARRAY_SIZE(bts->trx); trx_nr++) { |
| 732 | bts->trx[trx_nr].arfcn = info_ind->trx[trx_nr].arfcn; |
| 733 | 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] | 734 | if (bts->trx[trx_nr].pdch[ts_nr].is_enabled()) |
| 735 | bts->trx[trx_nr].pdch[ts_nr].disable(); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 736 | } |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 737 | gprs_bssgp_destroy(bts); |
Daniel Willmann | 6d8884d | 2014-06-04 18:30:59 +0200 | [diff] [blame] | 738 | exit(0); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 739 | } |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 740 | LOGP(DL1IF, LOGL_INFO, "BTS available\n"); |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 741 | LOGP(DL1IF, LOGL_DEBUG, " mcc=%03u\n", info_ind->mcc); |
| 742 | 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] | 743 | LOGP(DL1IF, LOGL_DEBUG, " lac=%d\n", info_ind->lac); |
| 744 | LOGP(DL1IF, LOGL_DEBUG, " rac=%d\n", info_ind->rac); |
Harald Welte | 1473b37 | 2019-03-21 19:48:55 +0100 | [diff] [blame] | 745 | LOGP(DL1IF, LOGL_DEBUG, " cell_id=%d\n", info_ind->cell_id); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 746 | LOGP(DL1IF, LOGL_DEBUG, " bsic=%d\n", info_ind->bsic); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 747 | LOGP(DL1IF, LOGL_DEBUG, " nsei=%d\n", info_ind->nsei); |
| 748 | LOGP(DL1IF, LOGL_DEBUG, " nse_timer=%d %d %d %d %d %d %d\n", |
| 749 | info_ind->nse_timer[0], info_ind->nse_timer[1], |
| 750 | info_ind->nse_timer[2], info_ind->nse_timer[3], |
| 751 | info_ind->nse_timer[4], info_ind->nse_timer[5], |
| 752 | info_ind->nse_timer[6]); |
| 753 | LOGP(DL1IF, LOGL_DEBUG, " cell_timer=%d %d %d %d %d %d %d %d %d %d " |
| 754 | "%d\n", |
| 755 | info_ind->cell_timer[0], info_ind->cell_timer[1], |
| 756 | info_ind->cell_timer[2], info_ind->cell_timer[3], |
| 757 | info_ind->cell_timer[4], info_ind->cell_timer[5], |
| 758 | info_ind->cell_timer[6], info_ind->cell_timer[7], |
| 759 | info_ind->cell_timer[8], info_ind->cell_timer[9], |
| 760 | info_ind->cell_timer[10]); |
| 761 | LOGP(DL1IF, LOGL_DEBUG, " repeat_time=%d\n", info_ind->repeat_time); |
| 762 | LOGP(DL1IF, LOGL_DEBUG, " repeat_count=%d\n", info_ind->repeat_count); |
| 763 | LOGP(DL1IF, LOGL_DEBUG, " bvci=%d\n", info_ind->bvci); |
| 764 | LOGP(DL1IF, LOGL_DEBUG, " t3142=%d\n", info_ind->t3142); |
| 765 | LOGP(DL1IF, LOGL_DEBUG, " t3169=%d\n", info_ind->t3169); |
| 766 | LOGP(DL1IF, LOGL_DEBUG, " t3191=%d\n", info_ind->t3191); |
| 767 | LOGP(DL1IF, LOGL_DEBUG, " t3193=%d (ms)\n", info_ind->t3193_10ms * 10); |
| 768 | LOGP(DL1IF, LOGL_DEBUG, " t3195=%d\n", info_ind->t3195); |
| 769 | LOGP(DL1IF, LOGL_DEBUG, " n3101=%d\n", info_ind->n3101); |
| 770 | LOGP(DL1IF, LOGL_DEBUG, " n3103=%d\n", info_ind->n3103); |
| 771 | LOGP(DL1IF, LOGL_DEBUG, " n3105=%d\n", info_ind->n3105); |
| 772 | LOGP(DL1IF, LOGL_DEBUG, " cv_countdown=%d\n", info_ind->cv_countdown); |
| 773 | LOGP(DL1IF, LOGL_DEBUG, " dl_tbf_ext=%d\n", info_ind->dl_tbf_ext); |
| 774 | 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] | 775 | bts->cgi_ps.rai.lac.plmn.mcc = info_ind->mcc; |
| 776 | bts->cgi_ps.rai.lac.plmn.mnc = info_ind->mnc; |
| 777 | bts->cgi_ps.rai.lac.plmn.mnc_3_digits = info_ind->mnc_3_digits; |
| 778 | bts->cgi_ps.rai.lac.lac = info_ind->lac; |
| 779 | bts->cgi_ps.rai.rac = info_ind->rac; |
| 780 | bts->cgi_ps.cell_identity = info_ind->cell_id; |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 781 | bts->bsic = info_ind->bsic; |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 782 | |
| 783 | 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] | 784 | for (i = 0; i < 4; i++) { |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 785 | uint8_t allowed = !!(info_ind->flags & (PCU_IF_FLAG_CS1 << i)); |
| 786 | bts->cs_mask |= allowed << i; |
| 787 | if (allowed) |
| 788 | LOGP(DL1IF, LOGL_DEBUG, " Use CS%d\n", i + 1); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 789 | } |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 790 | bts_recalc_max_cs(bts); |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 791 | |
| 792 | bts->mcs_mask = 0; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 793 | for (i = 0; i < 9; i++) { |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 794 | uint8_t allowed = !!(info_ind->flags & (PCU_IF_FLAG_MCS1 << i)); |
| 795 | bts->mcs_mask |= allowed << i; |
Pau Espin Pedrol | 87eec1f | 2020-10-30 18:46:24 +0100 | [diff] [blame] | 796 | if (allowed) |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 797 | LOGP(DL1IF, LOGL_DEBUG, " Use MCS%d\n", i + 1); |
Pau Espin Pedrol | 87eec1f | 2020-10-30 18:46:24 +0100 | [diff] [blame] | 798 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 799 | } |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 800 | bts_recalc_max_mcs(bts); |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 801 | |
Pau Espin Pedrol | b47b137 | 2020-11-03 15:59:39 +0100 | [diff] [blame] | 802 | 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] | 803 | the_pcu->vty.force_initial_cs ? " (VTY forced, ignoring)" : ""); |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 804 | bts->pcuif_info_ind.initial_cs = info_ind->initial_cs; |
| 805 | bts_recalc_initial_cs(bts); |
Pau Espin Pedrol | b47b137 | 2020-11-03 15:59:39 +0100 | [diff] [blame] | 806 | |
| 807 | 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] | 808 | the_pcu->vty.force_initial_mcs ? " (VTY forced, ignoring)" : ""); |
Pau Espin Pedrol | 793583e | 2021-01-14 16:20:57 +0100 | [diff] [blame] | 809 | bts->pcuif_info_ind.initial_mcs = info_ind->initial_mcs; |
| 810 | bts_recalc_initial_mcs(bts); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 811 | |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 812 | pcu = gprs_bssgp_init( |
| 813 | bts, |
| 814 | info_ind->nsei, info_ind->bvci, |
| 815 | info_ind->mcc, info_ind->mnc, info_ind->mnc_3_digits, |
| 816 | info_ind->lac, info_ind->rac, info_ind->cell_id); |
| 817 | if (!pcu) { |
Vadim Yanitskiy | c1a726c | 2020-10-08 22:46:26 +0700 | [diff] [blame] | 818 | LOGP(DL1IF, LOGL_ERROR, "Failed to init BSSGP\n"); |
Alexander Couzens | 9b5c960 | 2020-07-28 13:47:18 +0200 | [diff] [blame] | 819 | goto bssgp_failed; |
| 820 | } |
| 821 | |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 822 | rc = pcu_info_ind_ns(pcu->bts, info_ind); |
| 823 | if (rc < 0) { |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 824 | 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] | 825 | goto bssgp_failed; |
| 826 | } |
| 827 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 828 | if (info_ind->t3142) { /* if timer values are set */ |
Pau Espin Pedrol | 28f160e | 2019-09-05 14:48:35 +0200 | [diff] [blame] | 829 | osmo_tdef_set(bts->T_defs_bts, 3142, info_ind->t3142, OSMO_TDEF_S); |
| 830 | osmo_tdef_set(bts->T_defs_bts, 3169, info_ind->t3169, OSMO_TDEF_S); |
| 831 | osmo_tdef_set(bts->T_defs_bts, 3191, info_ind->t3191, OSMO_TDEF_S); |
| 832 | osmo_tdef_set(bts->T_defs_bts, 3193, info_ind->t3193_10ms * 10, OSMO_TDEF_MS); |
| 833 | 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] | 834 | bts->n3101 = info_ind->n3101; |
| 835 | bts->n3103 = info_ind->n3103; |
| 836 | bts->n3105 = info_ind->n3105; |
| 837 | } |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 838 | |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 839 | for (trx_nr = 0; trx_nr < ARRAY_SIZE(bts->trx); trx_nr++) { |
| 840 | bts->trx[trx_nr].arfcn = info_ind->trx[trx_nr].arfcn; |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 841 | if ((info_ind->flags & PCU_IF_FLAG_SYSMO) |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 842 | && info_ind->trx[trx_nr].hlayer1) { |
Max | cad867e | 2016-04-21 14:35:55 +0200 | [diff] [blame] | 843 | #ifdef ENABLE_DIRECT_PHY |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 844 | LOGP(DL1IF, LOGL_DEBUG, " TRX %d hlayer1=%x\n", trx_nr, |
| 845 | info_ind->trx[trx_nr].hlayer1); |
| 846 | if (!bts->trx[trx_nr].fl1h) |
| 847 | bts->trx[trx_nr].fl1h = l1if_open_pdch( |
| 848 | trx_nr, |
| 849 | info_ind->trx[trx_nr].hlayer1, |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 850 | the_pcu->gsmtap); |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 851 | if (!bts->trx[trx_nr].fl1h) { |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 852 | LOGP(DL1IF, LOGL_FATAL, "Failed to open direct " |
| 853 | "DSP access for PDCH.\n"); |
| 854 | exit(0); |
| 855 | } |
| 856 | #else |
| 857 | LOGP(DL1IF, LOGL_FATAL, "Compiled without direct DSP " |
| 858 | "access for PDCH, but enabled at " |
| 859 | "BTS. Please deactivate it!\n"); |
| 860 | exit(0); |
| 861 | #endif |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 862 | } |
| 863 | |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 864 | 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] | 865 | 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] | 866 | struct gprs_rlcmac_pdch *pdch = &bts->trx[trx_nr].pdch[ts_nr]; |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 867 | if ((info_ind->trx[trx_nr].pdch_mask & (1 << ts_nr))) { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 868 | /* FIXME: activate dynamically at RLCMAC */ |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 869 | if (!pdch->is_enabled()) { |
Max | cad867e | 2016-04-21 14:35:55 +0200 | [diff] [blame] | 870 | #ifdef ENABLE_DIRECT_PHY |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 871 | if ((info_ind->flags & |
| 872 | PCU_IF_FLAG_SYSMO)) |
| 873 | l1if_connect_pdch( |
Vadim Yanitskiy | 11b0f00 | 2020-07-24 01:24:47 +0700 | [diff] [blame] | 874 | bts->trx[trx_nr].fl1h, ts_nr); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 875 | #endif |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 876 | pcu_tx_act_req(bts, pdch, 1); |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 877 | pdch->enable(); |
Andreas Eversberg | 3b7461c | 2012-07-20 11:19:59 +0200 | [diff] [blame] | 878 | } |
Vadim Yanitskiy | 8e2bd1e | 2020-07-21 00:54:42 +0700 | [diff] [blame] | 879 | |
| 880 | pdch->tsc = its->tsc; |
| 881 | |
| 882 | /* (Optional) frequency hopping parameters */ |
Philipp Maier | 2e49058 | 2022-10-27 15:07:57 +0200 | [diff] [blame] | 883 | if (its->hopping) { |
Vadim Yanitskiy | 8e2bd1e | 2020-07-21 00:54:42 +0700 | [diff] [blame] | 884 | pdch->fh.enabled = true; |
| 885 | pdch->fh.maio = its->maio; |
| 886 | pdch->fh.hsn = its->hsn; |
| 887 | |
| 888 | OSMO_ASSERT(its->ma_bit_len <= sizeof(pdch->fh.ma) * 8); |
| 889 | pdch->fh.ma_oct_len = OSMO_BYTES_FOR_BITS(its->ma_bit_len); |
| 890 | pdch->fh.ma_bit_len = its->ma_bit_len; |
| 891 | |
| 892 | /* Mobile Allocation + padding (byte/bit order as on the wire): |
| 893 | * | 00 00 00 00 00 cc bb aa | -> | cc bb aa 00 00 00 00 00 | */ |
| 894 | unsigned int offset = sizeof(pdch->fh.ma) - pdch->fh.ma_oct_len; |
| 895 | memcpy(pdch->fh.ma, its->ma + offset, pdch->fh.ma_oct_len); |
| 896 | } |
| 897 | |
| 898 | LOGP(DL1IF, LOGL_INFO, "PDCH (trx=%u, ts=%u): tsc=%u, hopping=%s\n", |
| 899 | trx_nr, ts_nr, pdch->tsc, pdch->fh.enabled ? "yes" : "no"); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 900 | } else { |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 901 | if (pdch->is_enabled()) { |
Pau Espin Pedrol | df58ddf | 2021-03-09 16:19:22 +0100 | [diff] [blame] | 902 | pcu_tx_act_req(bts, pdch, 0); |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 903 | pdch->disable(); |
Andreas Eversberg | 3b7461c | 2012-07-20 11:19:59 +0200 | [diff] [blame] | 904 | } |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 905 | } |
| 906 | } |
| 907 | } |
| 908 | |
Stefan Sperling | 5b22fb7 | 2018-02-14 19:46:33 +0100 | [diff] [blame] | 909 | bts->active = true; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 910 | return rc; |
| 911 | } |
| 912 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 913 | 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] | 914 | { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 915 | uint8_t fn13 = time_ind->fn % 13; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 916 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 917 | /* omit frame numbers not starting at a MAC block */ |
| 918 | if (fn13 != 0 && fn13 != 4 && fn13 != 8) |
| 919 | return 0; |
Max | 3741f14 | 2017-06-26 12:10:12 +0200 | [diff] [blame] | 920 | |
| 921 | 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] | 922 | |
Pau Espin Pedrol | 3061711 | 2021-03-05 18:59:05 +0100 | [diff] [blame] | 923 | /* Ignore TIME.ind completely, we nowadays relay on DATA.ind always |
| 924 | * providing all block FNs. */ |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 925 | return 0; |
| 926 | } |
| 927 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 928 | 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] | 929 | { |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 930 | struct osmo_mobile_identity mi; |
Pau Espin Pedrol | bd54205 | 2021-05-13 17:44:51 +0200 | [diff] [blame] | 931 | struct GprsMs *ms = NULL; |
| 932 | struct paging_req_cs req = { .chan_needed = pag_req->chan_needed, |
| 933 | .tlli = GSM_RESERVED_TMSI }; |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 934 | int rc; |
| 935 | |
Andreas Eversberg | 2b91464 | 2012-07-19 13:06:26 +0200 | [diff] [blame] | 936 | LOGP(DL1IF, LOGL_DEBUG, "Paging request received: chan_needed=%d " |
| 937 | "length=%d\n", pag_req->chan_needed, pag_req->identity_lv[0]); |
| 938 | |
Pau Espin Pedrol | 32499b6 | 2019-12-09 13:55:12 +0100 | [diff] [blame] | 939 | /* check if identity does not fit: length > sizeof(lv) - 1 */ |
| 940 | if (pag_req->identity_lv[0] >= sizeof(pag_req->identity_lv)) { |
| 941 | LOGP(DL1IF, LOGL_ERROR, "Paging identity too large (%" PRIu8 ")\n", |
| 942 | pag_req->identity_lv[0]); |
| 943 | return -EINVAL; |
| 944 | } |
| 945 | |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 946 | rc = osmo_mobile_identity_decode(&mi, &pag_req->identity_lv[1], pag_req->identity_lv[0], true); |
| 947 | if (rc < 0) { |
| 948 | LOGP(DL1IF, LOGL_ERROR, "Failed to decode Mobile Identity in Paging Request (rc=%d)\n", rc); |
| 949 | return -EINVAL; |
| 950 | } |
| 951 | |
Pau Espin Pedrol | bd54205 | 2021-05-13 17:44:51 +0200 | [diff] [blame] | 952 | switch (mi.type) { |
| 953 | case GSM_MI_TYPE_TMSI: |
| 954 | req.mi_tmsi = mi; |
| 955 | req.mi_tmsi_present = true; |
| 956 | /* TODO: look up MS by TMSI? Derive TLLI? */ |
| 957 | break; |
| 958 | case GSM_MI_TYPE_IMSI: |
| 959 | req.mi_imsi = mi; |
| 960 | req.mi_imsi_present = true; |
| 961 | ms = bts_ms_by_imsi(bts, req.mi_imsi.imsi); |
| 962 | break; |
| 963 | default: |
| 964 | LOGP(DL1IF, LOGL_ERROR, "Unexpected MI type %u\n", mi.type); |
| 965 | return -EINVAL; |
| 966 | } |
| 967 | |
| 968 | return bts_add_paging(bts, &req, ms); |
Andreas Eversberg | 2b91464 | 2012-07-19 13:06:26 +0200 | [diff] [blame] | 969 | } |
| 970 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 971 | 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] | 972 | { |
Philipp Maier | a58ec61 | 2021-01-25 23:43:52 +0100 | [diff] [blame] | 973 | struct bssgp_bvc_ctx *bctx = the_pcu->bssgp.bctx; |
Pau Espin Pedrol | bd9973a | 2020-09-22 15:57:37 +0200 | [diff] [blame] | 974 | GprsMs *ms; |
| 975 | struct gprs_rlcmac_dl_tbf *dl_tbf; |
| 976 | struct gprs_rlcmac_ul_tbf *ul_tbf; |
Harald Welte | 3447c4a | 2017-07-11 00:06:38 +0200 | [diff] [blame] | 977 | struct gprs_ra_id ra_id; |
| 978 | |
| 979 | gsm48_parse_ra(&ra_id, susp_req->ra_id); |
| 980 | |
| 981 | LOGP(DL1IF, LOGL_INFO, "GPRS Suspend request received: TLLI=0x%08x RAI=%s\n", |
| 982 | susp_req->tlli, osmo_rai_name(&ra_id)); |
| 983 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 984 | if ((ms = bts_ms_store(bts)->get_ms(susp_req->tlli))) { |
Pau Espin Pedrol | bd9973a | 2020-09-22 15:57:37 +0200 | [diff] [blame] | 985 | /* We need to catch both pointers here since MS may become freed |
| 986 | 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] | 987 | dl_tbf = ms_dl_tbf(ms); |
| 988 | ul_tbf = ms_ul_tbf(ms); |
Pau Espin Pedrol | bd9973a | 2020-09-22 15:57:37 +0200 | [diff] [blame] | 989 | if (dl_tbf) |
| 990 | tbf_free(dl_tbf); |
| 991 | if (ul_tbf) |
| 992 | tbf_free(ul_tbf); |
| 993 | } |
| 994 | |
Harald Welte | 3447c4a | 2017-07-11 00:06:38 +0200 | [diff] [blame] | 995 | if (!bctx) |
| 996 | return -1; |
| 997 | |
| 998 | return bssgp_tx_suspend(bctx->nsei, susp_req->tlli, &ra_id); |
| 999 | } |
| 1000 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1001 | 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] | 1002 | { |
Pau Espin Pedrol | 54faf02 | 2021-01-14 12:12:43 +0100 | [diff] [blame] | 1003 | struct llist_head *tmp; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1004 | |
| 1005 | LOGP(DL1IF, LOGL_DEBUG, "Application Information Request received: type=0x%08x len=%i\n", |
| 1006 | app_info_req->application_type, app_info_req->len); |
| 1007 | |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1008 | bts->app_info_pending = 0; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 1009 | llist_for_each(tmp, bts_ms_store(bts)->ms_list()) { |
Pau Espin Pedrol | 54faf02 | 2021-01-14 12:12:43 +0100 | [diff] [blame] | 1010 | GprsMs *ms = llist_entry(tmp, typeof(*ms), list); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 1011 | if (!ms_dl_tbf(ms)) |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1012 | continue; |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1013 | bts->app_info_pending++; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1014 | ms->app_info_pending = true; |
| 1015 | } |
| 1016 | |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1017 | if (!bts->app_info_pending) { |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1018 | LOGP(DL1IF, LOGL_NOTICE, "Packet Application Information will not be sent, no subscribers with active" |
| 1019 | " TBF\n"); |
| 1020 | return -1; |
| 1021 | } |
| 1022 | |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1023 | if (bts->app_info) { |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1024 | LOGP(DL1IF, LOGL_NOTICE, "Previous Packet Application Information was not sent to all subscribers," |
| 1025 | " overwriting with new one\n"); |
Pau Espin Pedrol | 0ece97d | 2021-01-18 12:53:54 +0100 | [diff] [blame] | 1026 | msgb_free(bts->app_info); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | 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] | 1030 | bts->app_info_pending); |
| 1031 | bts->app_info = gprs_rlcmac_app_info_msg(app_info_req); |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1032 | return 0; |
| 1033 | } |
| 1034 | |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 1035 | static int pcu_rx_neigh_addr_cnf(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_neigh_addr_cnf *naddr_cnf) |
| 1036 | { |
| 1037 | struct llist_head *tmp; |
| 1038 | struct osmo_cell_global_id_ps cgi_ps; |
| 1039 | struct osmo_cell_global_id_ps *cgi_ps_ptr = &cgi_ps; |
| 1040 | |
| 1041 | struct neigh_cache_entry_key neigh_key = { |
| 1042 | .local_lac = osmo_load16be(&naddr_cnf->orig_req.local_lac), |
| 1043 | .local_ci = osmo_load16be(&naddr_cnf->orig_req.local_ci), |
| 1044 | .tgt_arfcn = osmo_load16be(&naddr_cnf->orig_req.tgt_arfcn), |
| 1045 | .tgt_bsic = naddr_cnf->orig_req.tgt_bsic, |
| 1046 | }; |
| 1047 | |
| 1048 | if (naddr_cnf->err_code == 0) { |
| 1049 | cgi_ps.rai.lac.plmn.mcc = osmo_load16be(&naddr_cnf->cgi_ps.mcc); |
| 1050 | cgi_ps.rai.lac.plmn.mnc = osmo_load16be(&naddr_cnf->cgi_ps.mnc); |
| 1051 | cgi_ps.rai.lac.plmn.mnc_3_digits = naddr_cnf->cgi_ps.mnc_3_digits; |
| 1052 | cgi_ps.rai.lac.lac = osmo_load16be(&naddr_cnf->cgi_ps.lac); |
| 1053 | cgi_ps.rai.rac = naddr_cnf->cgi_ps.rac; |
| 1054 | cgi_ps.cell_identity = osmo_load16be(&naddr_cnf->cgi_ps.cell_identity); |
| 1055 | |
| 1056 | LOGP(DL1IF, LOGL_INFO, "Rx Neighbor Address Resolution Confirmation for " NEIGH_CACHE_ENTRY_KEY_FMT ": %s\n", |
| 1057 | NEIGH_CACHE_ENTRY_KEY_ARGS(&neigh_key), osmo_cgi_ps_name(&cgi_ps)); |
| 1058 | |
| 1059 | /* Cache the cgi_ps so we can avoid requesting again same resolution for a while */ |
| 1060 | neigh_cache_add(bts->pcu->neigh_cache, &neigh_key, &cgi_ps); |
| 1061 | } else { |
| 1062 | cgi_ps_ptr = NULL; |
| 1063 | LOGP(DL1IF, LOGL_INFO, "Rx Neighbor Address Resolution Confirmation for " NEIGH_CACHE_ENTRY_KEY_FMT ": failed with err_code=%u\n", |
| 1064 | NEIGH_CACHE_ENTRY_KEY_ARGS(&neigh_key), naddr_cnf->err_code); |
| 1065 | } |
| 1066 | |
| 1067 | llist_for_each(tmp, bts_ms_store(bts)->ms_list()) { |
| 1068 | GprsMs *ms = llist_entry(tmp, typeof(*ms), list); |
| 1069 | if (ms->nacc && nacc_fsm_is_waiting_addr_resolution(ms->nacc, &neigh_key)) |
| 1070 | osmo_fsm_inst_dispatch(ms->nacc->fi, NACC_EV_RX_RAC_CI, cgi_ps_ptr); |
| 1071 | } |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1075 | static int pcu_rx_container(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_container *container) |
| 1076 | { |
| 1077 | int rc; |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 1078 | uint16_t data_length = osmo_load16be(&container->length); |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1079 | |
| 1080 | switch (container->msg_type) { |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 1081 | case PCU_IF_MSG_NEIGH_ADDR_CNF: |
| 1082 | if (data_length < sizeof(struct gsm_pcu_if_neigh_addr_cnf)) { |
| 1083 | LOGP(DL1IF, LOGL_ERROR, "Rx container(NEIGH_ADDR_CNF) message too short: %u vs exp %zu\n", |
| 1084 | data_length, sizeof(struct gsm_pcu_if_neigh_addr_cnf)); |
| 1085 | return -EINVAL; |
| 1086 | } |
| 1087 | rc = pcu_rx_neigh_addr_cnf(bts, (struct gsm_pcu_if_neigh_addr_cnf*)&container->data); |
| 1088 | break; |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1089 | default: |
| 1090 | LOGP(DL1IF, LOGL_NOTICE, "(bts=%d) Rx unexpected msg type (%u) inside container!\n", |
| 1091 | bts->nr, container->msg_type); |
| 1092 | rc = -1; |
| 1093 | } |
| 1094 | return rc; |
| 1095 | } |
| 1096 | |
| 1097 | #define CHECK_IF_MSG_SIZE(prim_len, prim_msg) \ |
| 1098 | do { \ |
| 1099 | size_t _len = PCUIF_HDR_SIZE + sizeof(prim_msg); \ |
| 1100 | if (prim_len < _len) { \ |
| 1101 | LOGP(DL1IF, LOGL_ERROR, "Received %zu bytes on PCU Socket, but primitive %s " \ |
| 1102 | "size is %zu, discarding\n", prim_len, #prim_msg, _len); \ |
| 1103 | return -EINVAL; \ |
| 1104 | } \ |
| 1105 | } while(0); |
| 1106 | 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] | 1107 | { |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1108 | int rc = 0; |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1109 | size_t exp_len; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1110 | struct gprs_rlcmac_bts *bts = gprs_pcu_get_bts_by_nr(the_pcu, pcu_prim->bts_nr); |
| 1111 | if (!bts) { |
| 1112 | LOGP(DL1IF, LOGL_NOTICE, "Received message for new BTS%d\n", pcu_prim->bts_nr); |
| 1113 | bts = bts_alloc(the_pcu, pcu_prim->bts_nr); |
| 1114 | if (!bts) { |
| 1115 | LOGP(DL1IF, LOGL_ERROR, "Failed to create object for BTS%d!\n", pcu_prim->bts_nr); |
| 1116 | return -EAGAIN; |
| 1117 | } |
| 1118 | } |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 1119 | |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1120 | switch (pcu_prim->msg_type) { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1121 | case PCU_IF_MSG_DATA_IND: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1122 | 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] | 1123 | rc = pcu_rx_data_ind(bts, &pcu_prim->u.data_ind); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1124 | break; |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 1125 | case PCU_IF_MSG_DATA_CNF: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1126 | 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] | 1127 | rc = pcu_rx_data_cnf(bts, &pcu_prim->u.data_cnf); |
Andreas Eversberg | a9be154 | 2012-09-27 09:23:24 +0200 | [diff] [blame] | 1128 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1129 | case PCU_IF_MSG_RTS_REQ: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1130 | 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] | 1131 | rc = pcu_rx_rts_req(bts, &pcu_prim->u.rts_req); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1132 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1133 | case PCU_IF_MSG_RACH_IND: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1134 | 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] | 1135 | rc = pcu_rx_rach_ind(bts, &pcu_prim->u.rach_ind); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1136 | break; |
| 1137 | case PCU_IF_MSG_INFO_IND: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1138 | 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] | 1139 | rc = pcu_rx_info_ind(bts, &pcu_prim->u.info_ind); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1140 | break; |
| 1141 | case PCU_IF_MSG_TIME_IND: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1142 | 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] | 1143 | rc = pcu_rx_time_ind(bts, &pcu_prim->u.time_ind); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1144 | break; |
Andreas Eversberg | 2b91464 | 2012-07-19 13:06:26 +0200 | [diff] [blame] | 1145 | case PCU_IF_MSG_PAG_REQ: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1146 | 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] | 1147 | rc = pcu_rx_pag_req(bts, &pcu_prim->u.pag_req); |
Andreas Eversberg | 2b91464 | 2012-07-19 13:06:26 +0200 | [diff] [blame] | 1148 | break; |
Harald Welte | 3447c4a | 2017-07-11 00:06:38 +0200 | [diff] [blame] | 1149 | case PCU_IF_MSG_SUSP_REQ: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1150 | 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] | 1151 | rc = pcu_rx_susp_req(bts, &pcu_prim->u.susp_req); |
Harald Welte | 3447c4a | 2017-07-11 00:06:38 +0200 | [diff] [blame] | 1152 | break; |
Oliver Smith | cfb6321 | 2019-09-05 17:13:33 +0200 | [diff] [blame] | 1153 | case PCU_IF_MSG_APP_INFO_REQ: |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1154 | 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] | 1155 | 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] | 1156 | break; |
Vadim Yanitskiy | b657213 | 2021-06-20 21:05:24 +0200 | [diff] [blame] | 1157 | case PCU_IF_MSG_INTERF_IND: |
| 1158 | /* TODO: handle interference reports */ |
| 1159 | break; |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1160 | case PCU_IF_MSG_CONTAINER: |
| 1161 | CHECK_IF_MSG_SIZE(pcu_prim_length, pcu_prim->u.container); |
| 1162 | /* ^ check if we can access container fields, v check with container data length */ |
| 1163 | exp_len = PCUIF_HDR_SIZE + sizeof(pcu_prim->u.container) + osmo_load16be(&pcu_prim->u.container.length); |
| 1164 | if (pcu_prim_length < exp_len) { |
| 1165 | LOGP(DL1IF, LOGL_ERROR, "Received %zu bytes on PCU Socket, but primitive container size" \ |
| 1166 | "is %zu, discarding\n", pcu_prim_length, exp_len); |
| 1167 | } |
| 1168 | rc = pcu_rx_container(bts, &pcu_prim->u.container); |
| 1169 | break; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1170 | default: |
Thorsten Alteholz | 8bb7904 | 2018-10-06 10:42:58 +0200 | [diff] [blame] | 1171 | LOGP(DL1IF, LOGL_ERROR, "Received unknown PCU msg type %d\n", |
Pau Espin Pedrol | 1989a19 | 2021-06-23 19:46:07 +0200 | [diff] [blame] | 1172 | pcu_prim->msg_type); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 1173 | rc = -EINVAL; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 1174 | } |
Philipp Maier | 8ccf704 | 2018-04-10 13:12:42 +0200 | [diff] [blame] | 1175 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1176 | return rc; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 1177 | } |