Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1 | /* gprs_bssgp_pcu.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012 Ivan Klyuchnikov |
Holger Hans Peter Freyther | 416ce69 | 2013-08-22 08:44:04 +0200 | [diff] [blame] | 4 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
| 21 | #include <gprs_rlcmac.h> |
| 22 | #include <gprs_bssgp_pcu.h> |
Pau Espin Pedrol | 3a27102 | 2021-01-21 18:44:23 +0100 | [diff] [blame] | 23 | #include <gprs_bssgp_rim.h> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 24 | #include <pcu_l1_if.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 25 | #include <gprs_debug.h> |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 26 | #include <bts.h> |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 27 | #include <tbf.h> |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 28 | #include <coding_scheme.h> |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 29 | #include <pdch.h> |
Pau Espin Pedrol | de7bb75 | 2020-01-23 12:37:15 +0100 | [diff] [blame] | 30 | #include <decoding.h> |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 31 | |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 32 | #include <osmocom/gprs/gprs_ns2.h> |
| 33 | #include <osmocom/gsm/protocol/gsm_23_003.h> |
| 34 | #include <osmocom/gprs/protocol/gsm_08_16.h> |
| 35 | #include <osmocom/core/utils.h> |
Oliver Smith | 9783967 | 2021-07-05 11:11:42 +0200 | [diff] [blame] | 36 | #include <osmocom/core/stats.h> |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 37 | #include <osmocom/gsm/gsm48.h> |
| 38 | #include "coding_scheme.h" |
| 39 | #include "tbf_dl.h" |
| 40 | #include "llc.h" |
| 41 | #include "gprs_rlcmac.h" |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 42 | #include "bts_pch_timer.h" |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 43 | |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 44 | /* Tuning parameters for BSSGP flow control */ |
| 45 | #define FC_DEFAULT_LIFE_TIME_SECS 10 /* experimental value, 10s */ |
| 46 | #define FC_MS_BUCKET_SIZE_BY_BMAX(bmax) ((bmax) / 2 + 500) /* experimental */ |
| 47 | #define FC_FALLBACK_BVC_BUCKET_SIZE 2000 /* e.g. on R = 0, value taken from PCAP files */ |
| 48 | #define FC_MS_MAX_RX_SLOTS 4 /* limit MS default R to 4 TS per MS */ |
| 49 | |
| 50 | /* Constants for BSSGP flow control */ |
| 51 | #define FC_MAX_BUCKET_LEAK_RATE (6553500 / 8) /* Byte/s */ |
| 52 | #define FC_MAX_BUCKET_SIZE 6553500 /* Octets */ |
| 53 | |
Andreas Eversberg | 71cce91 | 2013-01-16 13:49:00 +0100 | [diff] [blame] | 54 | extern void *tall_pcu_ctx; |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 55 | extern uint16_t spoof_mcc, spoof_mnc; |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 56 | extern bool spoof_mnc_3_digits; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 57 | |
Oliver Smith | 9783967 | 2021-07-05 11:11:42 +0200 | [diff] [blame] | 58 | static const struct rate_ctr_desc sgsn_ctr_description[] = { |
| 59 | [SGSN_CTR_RX_PAGING_CS] = { "rx_paging_cs", "Amount of paging CS requests received" }, |
| 60 | [SGSN_CTR_RX_PAGING_PS] = { "rx_paging_ps", "Amount of paging PS requests received" }, |
| 61 | }; |
| 62 | |
| 63 | static const struct rate_ctr_group_desc sgsn_ctrg_desc = { |
| 64 | .group_name_prefix = "pcu:sgsn", |
| 65 | .group_description = "SGSN Statistics", |
| 66 | .class_id = OSMO_STATS_CLASS_SUBSCRIBER, |
| 67 | .num_ctr = ARRAY_SIZE(sgsn_ctr_description), |
| 68 | .ctr_desc = sgsn_ctr_description, |
| 69 | }; |
| 70 | |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 71 | static void bvc_timeout(void *_priv); |
| 72 | |
Jacob Erlbeck | 4a07a3b | 2016-01-20 12:22:07 +0100 | [diff] [blame] | 73 | static int parse_ra_cap(struct tlv_parsed *tp, MS_Radio_Access_capability_t *rac) |
Holger Hans Peter Freyther | 98fe945 | 2013-07-13 15:23:58 +0200 | [diff] [blame] | 74 | { |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 75 | struct bitvec *block; |
Holger Hans Peter Freyther | 98fe945 | 2013-07-13 15:23:58 +0200 | [diff] [blame] | 76 | uint8_t cap_len; |
| 77 | uint8_t *cap; |
| 78 | |
Jacob Erlbeck | 4a07a3b | 2016-01-20 12:22:07 +0100 | [diff] [blame] | 79 | memset(rac, 0, sizeof(*rac)); |
| 80 | |
Holger Hans Peter Freyther | 98fe945 | 2013-07-13 15:23:58 +0200 | [diff] [blame] | 81 | if (!TLVP_PRESENT(tp, BSSGP_IE_MS_RADIO_ACCESS_CAP)) |
Jacob Erlbeck | 4a07a3b | 2016-01-20 12:22:07 +0100 | [diff] [blame] | 82 | return -EINVAL; |
Holger Hans Peter Freyther | 98fe945 | 2013-07-13 15:23:58 +0200 | [diff] [blame] | 83 | |
| 84 | cap_len = TLVP_LEN(tp, BSSGP_IE_MS_RADIO_ACCESS_CAP); |
| 85 | cap = (uint8_t *) TLVP_VAL(tp, BSSGP_IE_MS_RADIO_ACCESS_CAP); |
| 86 | |
Jacob Erlbeck | 4a07a3b | 2016-01-20 12:22:07 +0100 | [diff] [blame] | 87 | LOGP(DBSSGP, LOGL_DEBUG, "Got BSSGP RA Capability of size %d\n", cap_len); |
| 88 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 89 | block = bitvec_alloc(cap_len, tall_pcu_ctx); |
Holger Hans Peter Freyther | 98fe945 | 2013-07-13 15:23:58 +0200 | [diff] [blame] | 90 | bitvec_unpack(block, cap); |
Jacob Erlbeck | 4a07a3b | 2016-01-20 12:22:07 +0100 | [diff] [blame] | 91 | |
| 92 | /* TS 24.008, 10.5.5.12a */ |
| 93 | decode_gsm_ra_cap(block, rac); |
Holger Hans Peter Freyther | 98fe945 | 2013-07-13 15:23:58 +0200 | [diff] [blame] | 94 | |
| 95 | bitvec_free(block); |
Jacob Erlbeck | 4a07a3b | 2016-01-20 12:22:07 +0100 | [diff] [blame] | 96 | return 0; |
Holger Hans Peter Freyther | 98fe945 | 2013-07-13 15:23:58 +0200 | [diff] [blame] | 97 | } |
| 98 | |
Holger Hans Peter Freyther | 90d5df4 | 2013-07-28 21:14:15 +0200 | [diff] [blame] | 99 | static int gprs_bssgp_pcu_rx_dl_ud(struct msgb *msg, struct tlv_parsed *tp) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 100 | { |
| 101 | struct bssgp_ud_hdr *budh; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 102 | |
Andreas Eversberg | e6228b3 | 2012-07-03 13:36:03 +0200 | [diff] [blame] | 103 | uint32_t tlli; |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame] | 104 | uint32_t tlli_old = GSM_RESERVED_TMSI; |
Andreas Eversberg | e6228b3 | 2012-07-03 13:36:03 +0200 | [diff] [blame] | 105 | uint8_t *data; |
| 106 | uint16_t len; |
Jacob Erlbeck | 4a07a3b | 2016-01-20 12:22:07 +0100 | [diff] [blame] | 107 | uint8_t ms_class = 0; |
| 108 | uint8_t egprs_ms_class = 0; |
Vadim Yanitskiy | 6170ac0 | 2019-07-24 16:44:13 +0700 | [diff] [blame] | 109 | int rc; |
Jacob Erlbeck | 4a07a3b | 2016-01-20 12:22:07 +0100 | [diff] [blame] | 110 | MS_Radio_Access_capability_t rac; |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 111 | /* TODO: is it really necessary to initialize this as a "000" IMSI? It seems, the function should just return an |
| 112 | * error if no IMSI IE was found. */ |
| 113 | struct osmo_mobile_identity mi_imsi = { |
| 114 | .type = GSM_MI_TYPE_TMSI, |
| 115 | }; |
| 116 | OSMO_STRLCPY_ARRAY(mi_imsi.imsi, "000"); |
Andreas Eversberg | 7d7cf54 | 2012-06-25 09:26:15 +0200 | [diff] [blame] | 117 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 118 | budh = (struct bssgp_ud_hdr *)msgb_bssgph(msg); |
Andreas Eversberg | e6228b3 | 2012-07-03 13:36:03 +0200 | [diff] [blame] | 119 | tlli = ntohl(budh->tlli); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 120 | |
Ivan Kluchnikov | 5e0df93 | 2012-06-12 15:33:52 +0400 | [diff] [blame] | 121 | /* LLC_PDU is mandatory IE */ |
| 122 | if (!TLVP_PRESENT(tp, BSSGP_IE_LLC_PDU)) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 123 | { |
Andreas Eversberg | 0e40309 | 2012-07-06 11:04:57 +0200 | [diff] [blame] | 124 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP TLLI=0x%08x Rx UL-UD missing mandatory IE\n", tlli); |
Ivan Kluchnikov | 5e0df93 | 2012-06-12 15:33:52 +0400 | [diff] [blame] | 125 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
| 126 | } |
Ivan Kluchnikov | b172b1b | 2012-06-07 01:51:49 +0400 | [diff] [blame] | 127 | |
Andreas Eversberg | e6228b3 | 2012-07-03 13:36:03 +0200 | [diff] [blame] | 128 | data = (uint8_t *) TLVP_VAL(tp, BSSGP_IE_LLC_PDU); |
| 129 | len = TLVP_LEN(tp, BSSGP_IE_LLC_PDU); |
Vadim Yanitskiy | 3568fcf | 2020-02-03 16:38:51 +0700 | [diff] [blame] | 130 | if (len > LLC_MAX_LEN) |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 131 | { |
Andreas Eversberg | 0e40309 | 2012-07-06 11:04:57 +0200 | [diff] [blame] | 132 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP TLLI=0x%08x Rx UL-UD IE_LLC_PDU too large\n", tlli); |
Andreas Eversberg | e6228b3 | 2012-07-03 13:36:03 +0200 | [diff] [blame] | 133 | return bssgp_tx_status(BSSGP_CAUSE_COND_IE_ERR, NULL, msg); |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 134 | } |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 135 | |
Andreas Eversberg | e13fa2d | 2012-07-09 17:10:44 +0200 | [diff] [blame] | 136 | /* read IMSI. if no IMSI exists, use first paging block (any paging), |
| 137 | * because during attachment the IMSI might not be known, so the MS |
| 138 | * will listen to all paging blocks. */ |
Vadim Yanitskiy | aad87b6 | 2019-07-24 16:36:45 +0700 | [diff] [blame] | 139 | if (TLVP_PRESENT(tp, BSSGP_IE_IMSI)) |
| 140 | { |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 141 | rc = osmo_mobile_identity_decode(&mi_imsi, TLVP_VAL(tp, BSSGP_IE_IMSI), TLVP_LEN(tp, BSSGP_IE_IMSI), |
| 142 | true); |
Pau Espin Pedrol | 1d68cdf | 2020-08-26 13:41:45 +0200 | [diff] [blame] | 143 | if (rc < 0 || mi_imsi.type != GSM_MI_TYPE_IMSI) { |
Vadim Yanitskiy | 6170ac0 | 2019-07-24 16:44:13 +0700 | [diff] [blame] | 144 | LOGP(DBSSGP, LOGL_NOTICE, "Failed to parse IMSI IE (rc=%d)\n", rc); |
| 145 | return bssgp_tx_status(BSSGP_CAUSE_COND_IE_ERR, NULL, msg); |
| 146 | } |
Vadim Yanitskiy | aad87b6 | 2019-07-24 16:36:45 +0700 | [diff] [blame] | 147 | } |
Andreas Eversberg | 51ab134 | 2012-07-13 14:52:50 +0200 | [diff] [blame] | 148 | |
| 149 | /* parse ms radio access capability */ |
Jacob Erlbeck | 4a07a3b | 2016-01-20 12:22:07 +0100 | [diff] [blame] | 150 | if (parse_ra_cap(tp, &rac) >= 0) { |
| 151 | /* Get the EGPRS class from the RA capability */ |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 152 | ms_class = get_ms_class_by_capability(&rac); |
| 153 | egprs_ms_class = get_egprs_ms_class_by_capability(&rac); |
Jacob Erlbeck | 4a07a3b | 2016-01-20 12:22:07 +0100 | [diff] [blame] | 154 | LOGP(DBSSGP, LOGL_DEBUG, "Got downlink MS class %d/%d\n", |
| 155 | ms_class, egprs_ms_class); |
| 156 | } |
Andreas Eversberg | 51ab134 | 2012-07-13 14:52:50 +0200 | [diff] [blame] | 157 | |
Andreas Eversberg | 24131bf | 2012-07-21 11:09:58 +0200 | [diff] [blame] | 158 | /* get lifetime */ |
| 159 | uint16_t delay_csec = 0xffff; |
| 160 | if (TLVP_PRESENT(tp, BSSGP_IE_PDU_LIFETIME)) |
| 161 | { |
| 162 | uint8_t lt_len = TLVP_LEN(tp, BSSGP_IE_PDU_LIFETIME); |
Andreas Eversberg | 24131bf | 2012-07-21 11:09:58 +0200 | [diff] [blame] | 163 | if (lt_len == 2) |
Harald Welte | 49b7822 | 2017-06-11 11:27:59 +0200 | [diff] [blame] | 164 | delay_csec = tlvp_val16be(tp, BSSGP_IE_PDU_LIFETIME); |
Andreas Eversberg | 24131bf | 2012-07-21 11:09:58 +0200 | [diff] [blame] | 165 | else |
| 166 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP invalid length of " |
| 167 | "PDU_LIFETIME IE\n"); |
| 168 | } else |
| 169 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP missing mandatory " |
| 170 | "PDU_LIFETIME IE\n"); |
| 171 | |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 172 | /* get optional TLLI old */ |
| 173 | if (TLVP_PRESENT(tp, BSSGP_IE_TLLI)) |
| 174 | { |
| 175 | uint8_t tlli_len = TLVP_LEN(tp, BSSGP_IE_PDU_LIFETIME); |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 176 | if (tlli_len == 2) |
Harald Welte | 49b7822 | 2017-06-11 11:27:59 +0200 | [diff] [blame] | 177 | tlli_old = tlvp_val16be(tp, BSSGP_IE_TLLI); |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 178 | else |
| 179 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP invalid length of " |
| 180 | "TLLI (old) IE\n"); |
| 181 | } |
| 182 | |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 183 | LOGP(DBSSGP, LOGL_INFO, "LLC [SGSN -> PCU] = TLLI: 0x%08x IMSI: %s len: %d\n", tlli, mi_imsi.imsi, len); |
Ivan Kluchnikov | 5e0df93 | 2012-06-12 15:33:52 +0400 | [diff] [blame] | 184 | |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 185 | return dl_tbf_handle(the_pcu->bssgp.bts, tlli, tlli_old, mi_imsi.imsi, |
Jacob Erlbeck | 14e00f8 | 2015-11-27 18:10:39 +0100 | [diff] [blame] | 186 | ms_class, egprs_ms_class, delay_csec, data, len); |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 187 | } |
Ivan Kluchnikov | a9e6dc5 | 2012-06-17 08:30:06 +0400 | [diff] [blame] | 188 | |
Pau Espin Pedrol | bd54205 | 2021-05-13 17:44:51 +0200 | [diff] [blame] | 189 | /* 3GPP TS 48.018 Table 10.3.2. Returns 0 on success, suggested BSSGP cause otherwise */ |
| 190 | static unsigned int get_paging_cs_mi(struct paging_req_cs *req, const struct tlv_parsed *tp) |
| 191 | { |
| 192 | int rc; |
| 193 | |
| 194 | req->chan_needed = tlvp_val8(tp, BSSGP_IE_CHAN_NEEDED, 0); |
| 195 | |
| 196 | if (!TLVP_PRESENT(tp, BSSGP_IE_IMSI)) { |
| 197 | LOGP(DBSSGP, LOGL_ERROR, "IMSI Mobile Identity mandatory IE not found\n"); |
| 198 | return BSSGP_CAUSE_MISSING_MAND_IE; |
| 199 | } |
| 200 | |
| 201 | rc = osmo_mobile_identity_decode(&req->mi_imsi, TLVP_VAL(tp, BSSGP_IE_IMSI), |
| 202 | TLVP_LEN(tp, BSSGP_IE_IMSI), true); |
| 203 | if (rc < 0 || req->mi_imsi.type != GSM_MI_TYPE_IMSI) { |
| 204 | LOGP(DBSSGP, LOGL_ERROR, "Invalid IMSI Mobile Identity\n"); |
| 205 | return BSSGP_CAUSE_INV_MAND_INF; |
| 206 | } |
| 207 | req->mi_imsi_present = true; |
| 208 | |
Pau Espin Pedrol | 2761e57 | 2021-05-21 13:44:02 +0200 | [diff] [blame] | 209 | /* TMSI is optional */ |
Pau Espin Pedrol | bd54205 | 2021-05-13 17:44:51 +0200 | [diff] [blame] | 210 | req->mi_tmsi_present = false; |
| 211 | if (TLVP_PRESENT(tp, BSSGP_IE_TMSI)) { |
| 212 | /* Be safe against an evil SGSN - check the length */ |
| 213 | if (TLVP_LEN(tp, BSSGP_IE_TMSI) != GSM23003_TMSI_NUM_BYTES) { |
| 214 | LOGP(DBSSGP, LOGL_NOTICE, "TMSI IE has odd length (!= 4)\n"); |
| 215 | return BSSGP_CAUSE_COND_IE_ERR; |
| 216 | } |
| 217 | |
| 218 | /* NOTE: TMSI (unlike IMSI) IE comes without MI type header */ |
| 219 | req->mi_tmsi = (struct osmo_mobile_identity){ |
| 220 | .type = GSM_MI_TYPE_TMSI, |
| 221 | }; |
| 222 | req->mi_tmsi.tmsi = osmo_load32be(TLVP_VAL(tp, BSSGP_IE_TMSI)); |
| 223 | req->mi_tmsi_present = true; |
| 224 | } |
| 225 | |
| 226 | if (TLVP_PRESENT(tp, BSSGP_IE_TLLI)) |
| 227 | req->tlli = osmo_load32be(TLVP_VAL(tp, BSSGP_IE_TLLI)); |
| 228 | else |
| 229 | req->tlli = GSM_RESERVED_TMSI; |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | static int gprs_bssgp_pcu_rx_paging_cs(struct msgb *msg, const struct tlv_parsed *tp) |
| 235 | { |
| 236 | struct paging_req_cs req; |
| 237 | struct gprs_rlcmac_bts *bts; |
| 238 | struct GprsMs *ms; |
| 239 | int rc; |
| 240 | |
Oliver Smith | 9783967 | 2021-07-05 11:11:42 +0200 | [diff] [blame] | 241 | rate_ctr_inc(rate_ctr_group_get_ctr(the_pcu->bssgp.ctrs, SGSN_CTR_RX_PAGING_CS)); |
| 242 | |
Pau Espin Pedrol | bd54205 | 2021-05-13 17:44:51 +0200 | [diff] [blame] | 243 | if ((rc = get_paging_cs_mi(&req, tp)) > 0) |
| 244 | return bssgp_tx_status((enum gprs_bssgp_cause) rc, NULL, msg); |
| 245 | |
| 246 | /* We need to page all BTSs since even if a BTS has a matching MS, it |
| 247 | * may have already moved to a newer BTS. On Each BTS, if the MS is |
| 248 | * known, then bts_add_paging() can optimize and page only on PDCHs the |
| 249 | * target MS is using. */ |
| 250 | llist_for_each_entry(bts, &the_pcu->bts_list, list) { |
| 251 | /* TODO: Match by TMSI before IMSI if present?! */ |
| 252 | ms = bts_ms_by_tlli(bts, req.tlli, req.tlli); |
| 253 | if (!ms && req.mi_imsi_present) |
| 254 | ms = bts_ms_by_imsi(bts, req.mi_imsi.imsi); |
| 255 | bts_add_paging(bts, &req, ms); |
| 256 | } |
| 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | |
Vadim Yanitskiy | 0b25f69 | 2020-03-26 03:38:05 +0700 | [diff] [blame] | 261 | /* Returns 0 on success, suggested BSSGP cause otherwise */ |
Pau Espin Pedrol | bd54205 | 2021-05-13 17:44:51 +0200 | [diff] [blame] | 262 | static unsigned int get_paging_ps_mi(struct osmo_mobile_identity *mi, const struct tlv_parsed *tp) |
Vadim Yanitskiy | 0b25f69 | 2020-03-26 03:38:05 +0700 | [diff] [blame] | 263 | { |
Vadim Yanitskiy | 0b25f69 | 2020-03-26 03:38:05 +0700 | [diff] [blame] | 264 | /* Use TMSI (if present) or IMSI */ |
| 265 | if (TLVP_PRESENT(tp, BSSGP_IE_TMSI)) { |
| 266 | /* Be safe against an evil SGSN - check the length */ |
| 267 | if (TLVP_LEN(tp, BSSGP_IE_TMSI) != GSM23003_TMSI_NUM_BYTES) { |
| 268 | LOGP(DBSSGP, LOGL_NOTICE, "TMSI IE has odd length (!= 4)\n"); |
| 269 | return BSSGP_CAUSE_COND_IE_ERR; |
| 270 | } |
| 271 | |
| 272 | /* NOTE: TMSI (unlike IMSI) IE comes without MI type header */ |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 273 | *mi = (struct osmo_mobile_identity){ |
| 274 | .type = GSM_MI_TYPE_TMSI, |
| 275 | }; |
| 276 | mi->tmsi = osmo_load32be(TLVP_VAL(tp, BSSGP_IE_TMSI)); |
Vadim Yanitskiy | 0b25f69 | 2020-03-26 03:38:05 +0700 | [diff] [blame] | 277 | } else if (TLVP_PRESENT(tp, BSSGP_IE_IMSI)) { |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 278 | int rc = osmo_mobile_identity_decode(mi, TLVP_VAL(tp, BSSGP_IE_IMSI), TLVP_LEN(tp, BSSGP_IE_IMSI), |
| 279 | true); |
| 280 | if (rc < 0 || mi->type != GSM_MI_TYPE_IMSI) { |
| 281 | LOGP(DBSSGP, LOGL_ERROR, "Invalid IMSI Mobile Identity\n"); |
| 282 | return BSSGP_CAUSE_COND_IE_ERR; |
| 283 | } |
Vadim Yanitskiy | 0b25f69 | 2020-03-26 03:38:05 +0700 | [diff] [blame] | 284 | } else { |
| 285 | LOGP(DBSSGP, LOGL_ERROR, "Neither TMSI IE nor IMSI IE is present\n"); |
| 286 | return BSSGP_CAUSE_MISSING_COND_IE; |
| 287 | } |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
Vadim Yanitskiy | 2c1fed2 | 2020-10-31 02:00:21 +0700 | [diff] [blame] | 292 | static int gprs_bssgp_pcu_rx_paging_ps(struct msgb *msg, const struct tlv_parsed *tp) |
Andreas Eversberg | 8c3680d | 2012-10-08 12:30:56 +0200 | [diff] [blame] | 293 | { |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 294 | struct osmo_mobile_identity mi_imsi; |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 295 | struct osmo_mobile_identity paging_mi; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 296 | struct gprs_rlcmac_bts *bts; |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 297 | uint16_t pgroup; |
Vadim Yanitskiy | 6170ac0 | 2019-07-24 16:44:13 +0700 | [diff] [blame] | 298 | int rc; |
Andreas Eversberg | 8c3680d | 2012-10-08 12:30:56 +0200 | [diff] [blame] | 299 | |
Oliver Smith | 9783967 | 2021-07-05 11:11:42 +0200 | [diff] [blame] | 300 | rate_ctr_inc(rate_ctr_group_get_ctr(the_pcu->bssgp.ctrs, SGSN_CTR_RX_PAGING_PS)); |
| 301 | |
Max | f3038e7 | 2019-03-19 15:39:05 +0100 | [diff] [blame] | 302 | if (!TLVP_PRESENT(tp, BSSGP_IE_IMSI)) { |
Andreas Eversberg | 8c3680d | 2012-10-08 12:30:56 +0200 | [diff] [blame] | 303 | LOGP(DBSSGP, LOGL_ERROR, "No IMSI\n"); |
Pau Espin Pedrol | 5530f12 | 2019-12-10 19:26:27 +0100 | [diff] [blame] | 304 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Andreas Eversberg | 8c3680d | 2012-10-08 12:30:56 +0200 | [diff] [blame] | 305 | } |
| 306 | |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 307 | rc = osmo_mobile_identity_decode(&mi_imsi, TLVP_VAL(tp, BSSGP_IE_IMSI), TLVP_LEN(tp, BSSGP_IE_IMSI), true); |
| 308 | if (rc < 0 || mi_imsi.type != GSM_MI_TYPE_IMSI) { |
Vadim Yanitskiy | 6170ac0 | 2019-07-24 16:44:13 +0700 | [diff] [blame] | 309 | LOGP(DBSSGP, LOGL_NOTICE, "Failed to parse IMSI IE (rc=%d)\n", rc); |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 310 | return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, msg); |
| 311 | } |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 312 | pgroup = imsi2paging_group(mi_imsi.imsi); |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 313 | if (pgroup > 999) { |
Neels Hofmeyr | 0052051 | 2020-08-21 15:44:58 +0200 | [diff] [blame] | 314 | LOGP(DBSSGP, LOGL_NOTICE, "Failed to compute IMSI %s paging group\n", mi_imsi.imsi); |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 315 | return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, msg); |
Vadim Yanitskiy | 6170ac0 | 2019-07-24 16:44:13 +0700 | [diff] [blame] | 316 | } |
Max | f3038e7 | 2019-03-19 15:39:05 +0100 | [diff] [blame] | 317 | |
Pau Espin Pedrol | bd54205 | 2021-05-13 17:44:51 +0200 | [diff] [blame] | 318 | if ((rc = get_paging_ps_mi(&paging_mi, tp)) > 0) |
Vadim Yanitskiy | 0b25f69 | 2020-03-26 03:38:05 +0700 | [diff] [blame] | 319 | return bssgp_tx_status((enum gprs_bssgp_cause) rc, NULL, msg); |
Pau Espin Pedrol | 5530f12 | 2019-12-10 19:26:27 +0100 | [diff] [blame] | 320 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 321 | /* FIXME: look if MS is attached a specific BTS and then only page on that one? */ |
| 322 | llist_for_each_entry(bts, &the_pcu->bts_list, list) { |
Pau Espin Pedrol | ef8a730 | 2021-11-08 19:19:25 +0100 | [diff] [blame] | 323 | if (bts_pch_timer_get_by_imsi(bts, mi_imsi.imsi)) { |
| 324 | LOGP(DBSSGP, LOGL_INFO, "PS-Paging request already pending for IMSI=%s\n", mi_imsi.imsi); |
| 325 | bts_do_rate_ctr_inc(bts, CTR_PCH_REQUESTS_ALREADY); |
| 326 | continue; |
| 327 | } |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 328 | if (gprs_rlcmac_paging_request(bts, &paging_mi, pgroup) < 0) |
| 329 | continue; |
| 330 | bts_pch_timer_start(bts, &paging_mi, mi_imsi.imsi); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 331 | } |
| 332 | return 0; |
Andreas Eversberg | 8c3680d | 2012-10-08 12:30:56 +0200 | [diff] [blame] | 333 | } |
| 334 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 335 | /* Receive a BSSGP PDU from a BSS on a PTP BVCI */ |
Holger Hans Peter Freyther | 90d5df4 | 2013-07-28 21:14:15 +0200 | [diff] [blame] | 336 | static int gprs_bssgp_pcu_rx_ptp(struct msgb *msg, struct tlv_parsed *tp, struct bssgp_bvc_ctx *bctx) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 337 | { |
| 338 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Max | a49475b | 2017-05-23 17:53:38 +0200 | [diff] [blame] | 339 | enum bssgp_pdu_type pdu_type = (enum bssgp_pdu_type) bgph->pdu_type; |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 340 | int bvci = bctx ? bctx->bvci : -1; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 341 | unsigned rc = 0; |
| 342 | |
Andreas Eversberg | ba1cd9b | 2012-07-25 09:14:09 +0200 | [diff] [blame] | 343 | if (!bctx) |
| 344 | return -EINVAL; |
| 345 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 346 | /* If traffic is received on a BVC that is marked as blocked, the |
| 347 | * received PDU shall not be accepted and a STATUS PDU (Cause value: |
| 348 | * BVC Blocked) shall be sent to the peer entity on the signalling BVC */ |
| 349 | if (bctx->state & BVC_S_BLOCKED && pdu_type != BSSGP_PDUT_STATUS) |
| 350 | { |
| 351 | uint16_t bvci = msgb_bvci(msg); |
| 352 | LOGP(DBSSGP, LOGL_NOTICE, "rx BVC_S_BLOCKED\n"); |
| 353 | return bssgp_tx_status(BSSGP_CAUSE_BVCI_BLOCKED, &bvci, msg); |
| 354 | } |
| 355 | |
| 356 | switch (pdu_type) { |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 357 | case BSSGP_PDUT_STATUS: |
| 358 | /* already handled in libosmogb */ |
| 359 | OSMO_ASSERT(0); |
| 360 | break; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 361 | case BSSGP_PDUT_DL_UNITDATA: |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 362 | LOGP(DBSSGP, LOGL_DEBUG, "Rx BSSGP BVCI=%d (PTP) DL_UNITDATA\n", bvci); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 363 | if (the_pcu->bssgp.on_dl_unit_data) |
| 364 | the_pcu->bssgp.on_dl_unit_data(&the_pcu->bssgp, msg, tp); |
Ivan Kluchnikov | 5e0df93 | 2012-06-12 15:33:52 +0400 | [diff] [blame] | 365 | gprs_bssgp_pcu_rx_dl_ud(msg, tp); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 366 | break; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 367 | case BSSGP_PDUT_FLOW_CONTROL_BVC_ACK: |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 368 | case BSSGP_PDUT_FLOW_CONTROL_MS_ACK: |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 369 | LOGP(DBSSGP, LOGL_DEBUG, "Rx BSSGP BVCI=%d (PTP) %s\n", |
| 370 | bvci, bssgp_pdu_str(pdu_type)); |
| 371 | break; |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 372 | case BSSGP_PDUT_PAGING_CS: |
Pau Espin Pedrol | 771de1f | 2019-12-10 19:31:25 +0100 | [diff] [blame] | 373 | gprs_bssgp_pcu_rx_paging_cs(msg, tp); |
| 374 | break; |
| 375 | case BSSGP_PDUT_PAGING_PS: |
| 376 | gprs_bssgp_pcu_rx_paging_ps(msg, tp); |
| 377 | break; |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 378 | case BSSGP_PDUT_RA_CAPABILITY: |
| 379 | case BSSGP_PDUT_RA_CAPA_UPDATE_ACK: |
| 380 | LOGP(DBSSGP, LOGL_INFO, "Rx BSSGP BVCI=%d (PTP) PDU type %s not implemented\n", |
| 381 | bvci, bssgp_pdu_str(pdu_type)); |
| 382 | break; |
| 383 | /* See TS 08.18 5.4.1 */ |
| 384 | case BSSGP_PDUT_SUSPEND: |
| 385 | case BSSGP_PDUT_SUSPEND_ACK: |
| 386 | case BSSGP_PDUT_SUSPEND_NACK: |
| 387 | case BSSGP_PDUT_RESUME: |
| 388 | case BSSGP_PDUT_RESUME_ACK: |
| 389 | case BSSGP_PDUT_RESUME_NACK: |
| 390 | case BSSGP_PDUT_FLUSH_LL: |
| 391 | case BSSGP_PDUT_FLUSH_LL_ACK: |
| 392 | case BSSGP_PDUT_LLC_DISCARD: |
| 393 | case BSSGP_PDUT_BVC_BLOCK: |
| 394 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 395 | case BSSGP_PDUT_BVC_UNBLOCK: |
| 396 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 397 | case BSSGP_PDUT_BVC_RESET: |
| 398 | case BSSGP_PDUT_BVC_RESET_ACK: |
| 399 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
| 400 | LOGP(DBSSGP, LOGL_NOTICE, "Rx BSSGP BVCI=%u (PTP) PDU type %s unexpected at PTP\n", |
| 401 | bctx->bvci, bssgp_pdu_str(pdu_type)); |
| 402 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 403 | break; |
| 404 | default: |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 405 | LOGP(DBSSGP, LOGL_NOTICE, "Rx BSSGP BVCI=%u (PTP) PDU type %s unknown\n", |
Harald Welte | 356ac61 | 2017-05-25 19:05:32 +0200 | [diff] [blame] | 406 | bctx->bvci, bssgp_pdu_str(pdu_type)); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 407 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 408 | break; |
| 409 | } |
| 410 | return rc; |
| 411 | } |
| 412 | |
| 413 | /* Receive a BSSGP PDU from a SGSN on a SIGNALLING BVCI */ |
Holger Hans Peter Freyther | 90d5df4 | 2013-07-28 21:14:15 +0200 | [diff] [blame] | 414 | static int gprs_bssgp_pcu_rx_sign(struct msgb *msg, struct tlv_parsed *tp, struct bssgp_bvc_ctx *bctx) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 415 | { |
| 416 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Max | a49475b | 2017-05-23 17:53:38 +0200 | [diff] [blame] | 417 | enum bssgp_pdu_type pdu_type = (enum bssgp_pdu_type) bgph->pdu_type; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 418 | int rc = 0; |
Vadim Yanitskiy | ce27d1e | 2019-11-08 04:18:46 +0700 | [diff] [blame] | 419 | int bvci = bctx ? bctx->bvci : msgb_bvci(msg); |
Max | a49475b | 2017-05-23 17:53:38 +0200 | [diff] [blame] | 420 | switch (pdu_type) { |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 421 | case BSSGP_PDUT_STATUS: |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 422 | /* already handled in libosmogb */ |
| 423 | OSMO_ASSERT(0); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 424 | break; |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 425 | case BSSGP_PDUT_SUSPEND_ACK: |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 426 | case BSSGP_PDUT_RESUME_ACK: |
| 427 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 428 | LOGP(DBSSGP, LOGL_DEBUG, "Rx BSSGP BVCI=%d (SIGN) %s\n", |
| 429 | bvci, bssgp_pdu_str(pdu_type)); |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 430 | break; |
| 431 | case BSSGP_PDUT_BVC_RESET_ACK: |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 432 | LOGP(DBSSGP, LOGL_NOTICE, "Rx BSSGP BVCI=%d (SIGN) BVC_RESET_ACK\n", bvci); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 433 | if (!the_pcu->bssgp.bvc_sig_reset) |
| 434 | the_pcu->bssgp.bvc_sig_reset = 1; |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 435 | else |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 436 | the_pcu->bssgp.bvc_reset = 1; |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 437 | bvc_timeout(NULL); |
| 438 | break; |
Pau Espin Pedrol | 65a0d1d | 2019-12-10 19:29:22 +0100 | [diff] [blame] | 439 | case BSSGP_PDUT_PAGING_CS: |
| 440 | gprs_bssgp_pcu_rx_paging_cs(msg, tp); |
| 441 | break; |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 442 | case BSSGP_PDUT_PAGING_PS: |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 443 | gprs_bssgp_pcu_rx_paging_ps(msg, tp); |
| 444 | break; |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 445 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 446 | LOGP(DBSSGP, LOGL_NOTICE, "Rx BSSGP BVCI=%d (SIGN) BVC_UNBLOCK_ACK\n", bvci); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 447 | the_pcu->bssgp.bvc_unblocked = 1; |
| 448 | if (the_pcu->bssgp.on_unblock_ack) |
| 449 | the_pcu->bssgp.on_unblock_ack(&the_pcu->bssgp); |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 450 | bvc_timeout(NULL); |
| 451 | break; |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 452 | case BSSGP_PDUT_SUSPEND_NACK: |
| 453 | case BSSGP_PDUT_RESUME_NACK: |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 454 | case BSSGP_PDUT_FLUSH_LL: |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 455 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 456 | LOGP(DBSSGP, LOGL_INFO, "Rx BSSGP BVCI=%d (SIGN) PDU type %s not implemented\n", |
| 457 | bvci, bssgp_pdu_str(pdu_type)); |
| 458 | break; |
| 459 | /* See TS 08.18 5.4.1 */ |
| 460 | case BSSGP_PDUT_UL_UNITDATA: |
| 461 | case BSSGP_PDUT_DL_UNITDATA: |
| 462 | case BSSGP_PDUT_RA_CAPABILITY: |
| 463 | case BSSGP_PDUT_PTM_UNITDATA: |
| 464 | case BSSGP_PDUT_RA_CAPA_UDPATE: |
| 465 | case BSSGP_PDUT_RA_CAPA_UPDATE_ACK: |
| 466 | case BSSGP_PDUT_RADIO_STATUS: |
| 467 | case BSSGP_PDUT_FLOW_CONTROL_BVC: |
| 468 | case BSSGP_PDUT_FLOW_CONTROL_BVC_ACK: |
| 469 | case BSSGP_PDUT_FLOW_CONTROL_MS: |
| 470 | case BSSGP_PDUT_FLOW_CONTROL_MS_ACK: |
| 471 | case BSSGP_PDUT_DOWNLOAD_BSS_PFC: |
| 472 | case BSSGP_PDUT_CREATE_BSS_PFC: |
| 473 | case BSSGP_PDUT_CREATE_BSS_PFC_ACK: |
| 474 | case BSSGP_PDUT_CREATE_BSS_PFC_NACK: |
| 475 | case BSSGP_PDUT_MODIFY_BSS_PFC: |
| 476 | case BSSGP_PDUT_MODIFY_BSS_PFC_ACK: |
| 477 | case BSSGP_PDUT_DELETE_BSS_PFC: |
| 478 | case BSSGP_PDUT_DELETE_BSS_PFC_ACK: |
| 479 | LOGP(DBSSGP, LOGL_NOTICE, "Rx BSSGP BVCI=%d (SIGN) PDU type %s unexpected at SIGN\n", |
| 480 | bvci, bssgp_pdu_str(pdu_type)); |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 481 | break; |
| 482 | default: |
Harald Welte | 05d7b5d | 2017-07-29 10:16:44 +0200 | [diff] [blame] | 483 | LOGP(DBSSGP, LOGL_NOTICE, "Rx BSSGP BVCI=%d (SIGN) PDU type %s unknown\n", |
Max | a49475b | 2017-05-23 17:53:38 +0200 | [diff] [blame] | 484 | bvci, bssgp_pdu_str(pdu_type)); |
Holger Hans Peter Freyther | a9744de | 2013-07-28 19:01:20 +0200 | [diff] [blame] | 485 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 486 | break; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 487 | } |
| 488 | return rc; |
| 489 | } |
| 490 | |
Holger Hans Peter Freyther | 90d5df4 | 2013-07-28 21:14:15 +0200 | [diff] [blame] | 491 | static int gprs_bssgp_pcu_rcvmsg(struct msgb *msg) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 492 | { |
| 493 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 494 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
| 495 | struct tlv_parsed tp; |
Max | a49475b | 2017-05-23 17:53:38 +0200 | [diff] [blame] | 496 | enum bssgp_pdu_type pdu_type = (enum bssgp_pdu_type) bgph->pdu_type; |
Max | 2813f93 | 2017-06-27 17:18:40 +0200 | [diff] [blame] | 497 | uint16_t ns_bvci = msgb_bvci(msg), nsei = msgb_nsei(msg); |
Alexander Couzens | 8251926 | 2021-02-22 02:08:18 +0100 | [diff] [blame] | 498 | uint16_t bvci; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 499 | int data_len; |
| 500 | int rc = 0; |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 501 | struct bssgp_bvc_ctx *bctx; |
| 502 | |
Pau Espin Pedrol | 3a27102 | 2021-01-21 18:44:23 +0100 | [diff] [blame] | 503 | switch (pdu_type) { |
| 504 | case BSSGP_PDUT_STATUS: |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 505 | /* Pass the message to the generic BSSGP parser, which handles |
Max | 2813f93 | 2017-06-27 17:18:40 +0200 | [diff] [blame] | 506 | * STATUS and RESET messages in either direction. */ |
Pau Espin Pedrol | 3a27102 | 2021-01-21 18:44:23 +0100 | [diff] [blame] | 507 | case BSSGP_PDUT_RAN_INFO: |
| 508 | case BSSGP_PDUT_RAN_INFO_REQ: |
| 509 | case BSSGP_PDUT_RAN_INFO_ACK: |
| 510 | case BSSGP_PDUT_RAN_INFO_ERROR: |
| 511 | case BSSGP_PDUT_RAN_INFO_APP_ERROR: |
| 512 | /* Also pass all RIM related messages to the generic BSSGP |
| 513 | * parser so that it can deliver primitive to the RIM SAP |
| 514 | * (SAP_BSSGP_RIM) */ |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 515 | return bssgp_rcvmsg(msg); |
Pau Espin Pedrol | 3a27102 | 2021-01-21 18:44:23 +0100 | [diff] [blame] | 516 | default: |
| 517 | break; |
| 518 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 519 | |
| 520 | /* Identifiers from DOWN: NSEI, BVCI (both in msg->cb) */ |
| 521 | |
| 522 | /* UNITDATA BSSGP headers have TLLI in front */ |
| 523 | if (pdu_type != BSSGP_PDUT_UL_UNITDATA && pdu_type != BSSGP_PDUT_DL_UNITDATA) |
| 524 | { |
| 525 | data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
| 526 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 527 | } |
| 528 | else |
| 529 | { |
| 530 | data_len = msgb_bssgp_len(msg) - sizeof(*budh); |
| 531 | rc = bssgp_tlv_parse(&tp, budh->data, data_len); |
| 532 | } |
Stefan Sperling | 3df1532 | 2018-06-25 12:17:39 +0200 | [diff] [blame] | 533 | if (rc < 0) { |
| 534 | LOGP(DBSSGP, LOGL_ERROR, "Failed to parse BSSGP %s message. Invalid message was: %s\n", |
| 535 | bssgp_pdu_str(pdu_type), msgb_hexdump(msg)); |
Harald Welte | 7b7f204 | 2019-07-21 09:26:20 +0200 | [diff] [blame] | 536 | return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, msg); |
Stefan Sperling | 3df1532 | 2018-06-25 12:17:39 +0200 | [diff] [blame] | 537 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 538 | |
Max | 2813f93 | 2017-06-27 17:18:40 +0200 | [diff] [blame] | 539 | if (pdu_type == BSSGP_PDUT_BVC_RESET) { |
Alexander Couzens | 8251926 | 2021-02-22 02:08:18 +0100 | [diff] [blame] | 540 | if (ns_bvci != BVCI_SIGNALLING || !TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) { |
| 541 | LOGP(DBSSGP, LOGL_ERROR, "Rx an invalid BVC-RESET %s\n", msgb_hexdump(msg)); |
| 542 | return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, msg); |
| 543 | } |
| 544 | |
| 545 | bvci = tlvp_val16be(&tp, BSSGP_IE_BVCI); |
| 546 | if (bvci != BVCI_SIGNALLING && bvci != the_pcu->bssgp.bctx->bvci) { |
| 547 | LOGP(DBSSGP, LOGL_ERROR, "Rx BVC-RESET for an unknown BVCI %d\n", bvci); |
| 548 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 549 | } |
| 550 | |
Alexander Couzens | 423bf8c | 2021-02-17 02:31:37 +0100 | [diff] [blame] | 551 | return bssgp_rcvmsg(msg); |
Max | 2813f93 | 2017-06-27 17:18:40 +0200 | [diff] [blame] | 552 | } |
| 553 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 554 | /* look-up or create the BTS context for this BVC */ |
| 555 | bctx = btsctx_by_bvci_nsei(ns_bvci, msgb_nsei(msg)); |
| 556 | |
Vadim Yanitskiy | ef44414 | 2019-11-08 04:02:31 +0700 | [diff] [blame] | 557 | if (!bctx && ns_bvci != BVCI_SIGNALLING) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 558 | { |
Max | 2813f93 | 2017-06-27 17:18:40 +0200 | [diff] [blame] | 559 | LOGP(DBSSGP, LOGL_NOTICE, "NSEI=%u/BVCI=%u Rejecting PDU type %s for unknown BVCI\n", |
| 560 | nsei, ns_bvci, bssgp_pdu_str(pdu_type)); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 561 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, NULL, msg); |
| 562 | } |
| 563 | |
| 564 | if (bctx) |
| 565 | { |
Neels Hofmeyr | a01e2ee | 2017-02-23 18:10:13 +0100 | [diff] [blame] | 566 | log_set_context(LOG_CTX_GB_BVC, bctx); |
Pau Espin Pedrol | 9c1db17 | 2021-06-04 17:05:51 +0200 | [diff] [blame] | 567 | rate_ctr_inc(rate_ctr_group_get_ctr(bctx->ctrg, BSSGP_CTR_PKTS_IN)); |
| 568 | rate_ctr_add(rate_ctr_group_get_ctr(bctx->ctrg, BSSGP_CTR_BYTES_IN), msgb_bssgp_len(msg)); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | if (ns_bvci == BVCI_SIGNALLING) |
| 572 | { |
Andreas Eversberg | 0e40309 | 2012-07-06 11:04:57 +0200 | [diff] [blame] | 573 | LOGP(DBSSGP, LOGL_DEBUG, "rx BVCI_SIGNALLING gprs_bssgp_rx_sign\n"); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 574 | rc = gprs_bssgp_pcu_rx_sign(msg, &tp, bctx); |
| 575 | } |
| 576 | else if (ns_bvci == BVCI_PTM) |
| 577 | { |
Andreas Eversberg | 0e40309 | 2012-07-06 11:04:57 +0200 | [diff] [blame] | 578 | LOGP(DBSSGP, LOGL_DEBUG, "rx BVCI_PTM bssgp_tx_status\n"); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 579 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
| 580 | } |
| 581 | else |
| 582 | { |
Pau Espin Pedrol | db12f25 | 2019-12-23 14:27:54 +0100 | [diff] [blame] | 583 | LOGP(DBSSGP, LOGL_DEBUG, "rx BVCI_PTP=%u gprs_bssgp_rx_ptp\n", ns_bvci); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 584 | rc = gprs_bssgp_pcu_rx_ptp(msg, &tp, bctx); |
| 585 | } |
| 586 | return rc; |
| 587 | } |
Harald Welte | 477e79e | 2012-06-18 12:21:03 +0800 | [diff] [blame] | 588 | |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 589 | static void handle_nm_status(struct osmo_bssgp_prim *bp) |
| 590 | { |
| 591 | enum gprs_bssgp_cause cause; |
| 592 | |
| 593 | LOGP(DPCU, LOGL_DEBUG, |
| 594 | "Got NM-STATUS.ind, BVCI=%d, NSEI=%d\n", |
| 595 | bp->bvci, bp->nsei); |
| 596 | |
| 597 | if (!TLVP_PRESENT(bp->tp, BSSGP_IE_CAUSE)) |
| 598 | return; |
| 599 | |
| 600 | cause = (enum gprs_bssgp_cause)*TLVP_VAL(bp->tp, BSSGP_IE_CAUSE); |
| 601 | |
| 602 | if (cause != BSSGP_CAUSE_BVCI_BLOCKED && |
| 603 | cause != BSSGP_CAUSE_UNKNOWN_BVCI) |
| 604 | return; |
| 605 | |
| 606 | if (!TLVP_PRESENT(bp->tp, BSSGP_IE_BVCI)) |
| 607 | return; |
| 608 | |
Pau Espin Pedrol | db5e339 | 2021-01-21 18:02:40 +0100 | [diff] [blame] | 609 | if (the_pcu->bssgp.bctx->bvci != bp->bvci) { |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 610 | LOGP(DPCU, LOGL_NOTICE, |
| 611 | "Received BSSGP STATUS message for an unknown BVCI (%d), " |
| 612 | "ignored\n", |
| 613 | bp->bvci); |
| 614 | return; |
| 615 | } |
| 616 | |
| 617 | switch (cause) { |
| 618 | case BSSGP_CAUSE_BVCI_BLOCKED: |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 619 | if (the_pcu->bssgp.bvc_unblocked) { |
| 620 | the_pcu->bssgp.bvc_unblocked = 0; |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 621 | bvc_timeout(NULL); |
| 622 | } |
| 623 | break; |
| 624 | |
| 625 | case BSSGP_CAUSE_UNKNOWN_BVCI: |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 626 | if (the_pcu->bssgp.bvc_reset) { |
| 627 | the_pcu->bssgp.bvc_reset = 0; |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 628 | bvc_timeout(NULL); |
| 629 | } |
| 630 | break; |
| 631 | default: |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | |
Harald Welte | 477e79e | 2012-06-18 12:21:03 +0800 | [diff] [blame] | 636 | int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx) |
| 637 | { |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 638 | struct osmo_bssgp_prim *bp; |
Alexander Couzens | 423bf8c | 2021-02-17 02:31:37 +0100 | [diff] [blame] | 639 | int rc; |
| 640 | enum gprs_bssgp_cause cause; |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 641 | bp = container_of(oph, struct osmo_bssgp_prim, oph); |
| 642 | |
| 643 | switch (oph->sap) { |
| 644 | case SAP_BSSGP_NM: |
Alexander Couzens | 423bf8c | 2021-02-17 02:31:37 +0100 | [diff] [blame] | 645 | switch (oph->primitive) { |
| 646 | case PRIM_NM_STATUS: |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 647 | handle_nm_status(bp); |
Alexander Couzens | 423bf8c | 2021-02-17 02:31:37 +0100 | [diff] [blame] | 648 | break; |
| 649 | case PRIM_NM_BVC_RESET: |
| 650 | /* received a BVC PTP reset */ |
| 651 | LOGP(DPCU, LOGL_INFO, "Rx BVC_RESET on bvci %d\n", bp->bvci); |
| 652 | /* Rx Reset from SGSN */ |
| 653 | if (bp->bvci == BVCI_SIGNALLING) { |
| 654 | if (TLVP_PRES_LEN(bp->tp, BSSGP_IE_CAUSE, 1)) |
| 655 | cause = (enum gprs_bssgp_cause)*TLVP_VAL(bp->tp, BSSGP_IE_CAUSE); |
| 656 | else { |
| 657 | LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u BVC RESET without cause?!\n", bp->nsei); |
| 658 | break; |
| 659 | } |
| 660 | |
| 661 | rc = bssgp_tx_bvc_ptp_reset(bp->nsei, cause); |
| 662 | if (rc < 0) { |
| 663 | LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u BVC PTP reset procedure failed: %d\n", bp->nsei, rc); |
| 664 | break; |
| 665 | } |
| 666 | the_pcu->bssgp.bvc_sig_reset = 1; |
| 667 | the_pcu->bssgp.bvc_reset = 0; |
| 668 | the_pcu->bssgp.bvc_unblocked = 0; |
| 669 | } else if (bp->bvci == the_pcu->bssgp.bctx->bvci) { |
| 670 | the_pcu->bssgp.bvc_reset = 1; |
| 671 | the_pcu->bssgp.bvc_unblocked = 0; |
| 672 | bvc_timeout(NULL); |
| 673 | } |
| 674 | break; |
| 675 | } |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 676 | break; |
Pau Espin Pedrol | 3a27102 | 2021-01-21 18:44:23 +0100 | [diff] [blame] | 677 | case SAP_BSSGP_RIM: |
| 678 | return handle_rim(bp); |
Jacob Erlbeck | 39645b8 | 2015-03-16 12:27:11 +0100 | [diff] [blame] | 679 | default: |
| 680 | break; |
| 681 | } |
Harald Welte | 477e79e | 2012-06-18 12:21:03 +0800 | [diff] [blame] | 682 | return 0; |
| 683 | } |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 684 | |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 685 | void gprs_ns_prim_status_cb(struct osmo_gprs_ns2_prim *nsp) |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 686 | { |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 687 | switch (nsp->u.status.cause) { |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 688 | case GPRS_NS2_AFF_CAUSE_SNS_CONFIGURED: |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 689 | LOGP(DPCU, LOGL_NOTICE, "NS-NSE %d SNS configured.\n", nsp->nsei); |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 690 | break; |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 691 | case GPRS_NS2_AFF_CAUSE_RECOVERY: |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 692 | LOGP(DPCU, LOGL_NOTICE, "NS-NSE %d became available\n", nsp->nsei); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 693 | if (!the_pcu->bssgp.nsvc_unblocked) { |
| 694 | the_pcu->bssgp.bvc_sig_reset = 0; |
| 695 | the_pcu->bssgp.bvc_reset = 0; |
| 696 | the_pcu->bssgp.nsvc_unblocked = 1; |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 697 | bvc_timeout(NULL); |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 698 | } |
| 699 | break; |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 700 | case GPRS_NS2_AFF_CAUSE_FAILURE: |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 701 | LOGP(DPCU, LOGL_NOTICE, "NS-NSE %d became unavailable\n", nsp->nsei); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 702 | if (the_pcu->bssgp.nsvc_unblocked) { |
| 703 | the_pcu->bssgp.nsvc_unblocked = 0; |
| 704 | osmo_timer_del(&the_pcu->bssgp.bvc_timer); |
| 705 | the_pcu->bssgp.bvc_sig_reset = 0; |
| 706 | the_pcu->bssgp.bvc_reset = 0; |
| 707 | the_pcu->bssgp.bvc_unblocked = 0; |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 708 | } |
| 709 | break; |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 710 | case GPRS_NS2_AFF_CAUSE_SNS_FAILURE: |
Alexander Couzens | 30d9a59 | 2020-10-27 01:25:51 +0100 | [diff] [blame] | 711 | break; |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 712 | default: |
Alexander Couzens | 30d9a59 | 2020-10-27 01:25:51 +0100 | [diff] [blame] | 713 | LOGP(DPCU, LOGL_DEBUG, |
| 714 | "NS: %s Unknown affecting cause %s / %d from NS\n", |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 715 | get_value_string(osmo_prim_op_names, nsp->oph.operation), |
Alexander Couzens | 30d9a59 | 2020-10-27 01:25:51 +0100 | [diff] [blame] | 716 | gprs_ns2_aff_cause_prim_str(nsp->u.status.cause), nsp->u.status.cause); |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 717 | break; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | /* called by the ns layer */ |
| 722 | int gprs_ns_prim_cb(struct osmo_prim_hdr *oph, void *ctx) |
| 723 | { |
| 724 | struct osmo_gprs_ns2_prim *nsp; |
| 725 | int rc = 0; |
| 726 | |
| 727 | if (oph->sap != SAP_NS) |
| 728 | return 0; |
| 729 | |
| 730 | nsp = container_of(oph, struct osmo_gprs_ns2_prim, oph); |
| 731 | |
| 732 | if (oph->operation != PRIM_OP_INDICATION) { |
| 733 | LOGP(DPCU, LOGL_NOTICE, "NS: %s Unknown prim %d from NS\n", |
| 734 | get_value_string(osmo_prim_op_names, oph->operation), |
| 735 | oph->operation); |
Alexander Couzens | a284854 | 2020-10-26 00:33:31 +0100 | [diff] [blame] | 736 | goto out; |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | switch (oph->primitive) { |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 740 | case GPRS_NS2_PRIM_UNIT_DATA: |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 741 | /* hand the message into the BSSGP implementation */ |
| 742 | /* add required msg fields for Gb layer */ |
| 743 | msgb_bssgph(oph->msg) = oph->msg->l3h; |
| 744 | msgb_bvci(oph->msg) = nsp->bvci; |
| 745 | msgb_nsei(oph->msg) = nsp->nsei; |
| 746 | rc = gprs_bssgp_pcu_rcvmsg(oph->msg); |
| 747 | break; |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 748 | case GPRS_NS2_PRIM_STATUS: |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 749 | gprs_ns_prim_status_cb(nsp); |
| 750 | break; |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 751 | case GPRS_NS2_PRIM_CONGESTION: |
Alexander Couzens | 30d9a59 | 2020-10-27 01:25:51 +0100 | [diff] [blame] | 752 | break; |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 753 | default: |
Alexander Couzens | 30d9a59 | 2020-10-27 01:25:51 +0100 | [diff] [blame] | 754 | LOGP(DPCU, LOGL_DEBUG, |
| 755 | "NS: %s Unknown prim %s / %d from NS\n", |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 756 | get_value_string(osmo_prim_op_names, oph->operation), |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 757 | gprs_ns2_prim_str((enum gprs_ns2_prim) oph->primitive), oph->primitive); |
Jacob Erlbeck | ebebad1 | 2015-08-17 14:43:52 +0200 | [diff] [blame] | 758 | break; |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 759 | } |
| 760 | |
Alexander Couzens | a284854 | 2020-10-26 00:33:31 +0100 | [diff] [blame] | 761 | out: |
| 762 | if (oph->msg) |
| 763 | msgb_free(oph->msg); |
| 764 | |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 765 | return rc; |
| 766 | } |
| 767 | |
| 768 | /* called by the bssgp layer to send NS PDUs */ |
| 769 | int gprs_gp_send_cb(void *ctx, struct msgb *msg) |
| 770 | { |
| 771 | struct gprs_ns2_inst *nsi = (struct gprs_ns2_inst *) ctx; |
| 772 | struct osmo_gprs_ns2_prim nsp = {}; |
| 773 | nsp.nsei = msgb_nsei(msg); |
| 774 | nsp.bvci = msgb_bvci(msg); |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 775 | osmo_prim_init(&nsp.oph, SAP_NS, GPRS_NS2_PRIM_UNIT_DATA, |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 776 | PRIM_OP_REQUEST, msg); |
| 777 | return gprs_ns2_recv_prim(nsi, &nsp.oph); |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 778 | } |
| 779 | |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 780 | static unsigned count_pdch(const struct gprs_rlcmac_bts *bts) |
| 781 | { |
| 782 | size_t trx_no, ts_no; |
| 783 | unsigned num_pdch = 0; |
| 784 | |
| 785 | for (trx_no = 0; trx_no < ARRAY_SIZE(bts->trx); ++trx_no) { |
| 786 | const struct gprs_rlcmac_trx *trx = &bts->trx[trx_no]; |
| 787 | |
| 788 | for (ts_no = 0; ts_no < ARRAY_SIZE(trx->pdch); ++ts_no) { |
| 789 | const struct gprs_rlcmac_pdch *pdch = &trx->pdch[ts_no]; |
| 790 | |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 791 | if (pdch->m_is_enabled) |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 792 | num_pdch += 1; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | return num_pdch; |
| 797 | } |
| 798 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 799 | static uint32_t gprs_bssgp_max_leak_rate(enum CodingScheme cs, int num_pdch) |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 800 | { |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 801 | int bytes_per_rlc_block = mcs_max_data_block_bytes(cs) * num_data_blocks(mcs_header_type(cs)); |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 802 | |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 803 | /* n byte payload per 20ms */ |
| 804 | return bytes_per_rlc_block * (1000 / 20) * num_pdch; |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | static uint32_t compute_bucket_size(struct gprs_rlcmac_bts *bts, |
| 808 | uint32_t leak_rate, uint32_t fallback) |
| 809 | { |
| 810 | uint32_t bucket_size = 0; |
Pau Espin Pedrol | e891222 | 2021-01-14 14:03:17 +0100 | [diff] [blame] | 811 | uint16_t bucket_time = the_pcu->vty.fc_bucket_time; |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 812 | |
Jacob Erlbeck | 0288cdb | 2015-05-06 10:47:30 +0200 | [diff] [blame] | 813 | if (bucket_time == 0) |
Pau Espin Pedrol | f473ec9 | 2021-01-14 14:45:14 +0100 | [diff] [blame] | 814 | bucket_time = the_pcu->vty.force_llc_lifetime; |
Jacob Erlbeck | 0288cdb | 2015-05-06 10:47:30 +0200 | [diff] [blame] | 815 | |
| 816 | if (bucket_time == 0xffff) |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 817 | bucket_size = FC_MAX_BUCKET_SIZE; |
| 818 | |
Jacob Erlbeck | 0288cdb | 2015-05-06 10:47:30 +0200 | [diff] [blame] | 819 | if (bucket_size == 0 && bucket_time && leak_rate) |
| 820 | bucket_size = (uint64_t)leak_rate * bucket_time / 100; |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 821 | |
| 822 | if (bucket_size == 0 && leak_rate) |
| 823 | bucket_size = leak_rate * FC_DEFAULT_LIFE_TIME_SECS; |
| 824 | |
| 825 | if (bucket_size == 0) |
| 826 | bucket_size = fallback; |
| 827 | |
| 828 | if (bucket_size > FC_MAX_BUCKET_SIZE) |
| 829 | bucket_size = FC_MAX_BUCKET_SIZE; |
| 830 | |
| 831 | return bucket_size; |
| 832 | } |
| 833 | |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 834 | static uint32_t get_and_reset_avg_queue_delay(void) |
| 835 | { |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 836 | struct timespec *delay_sum = &the_pcu->bssgp.queue_delay_sum; |
Jacob Erlbeck | 0ae4313 | 2015-06-11 12:03:18 +0200 | [diff] [blame] | 837 | uint32_t delay_sum_ms = delay_sum->tv_sec * 1000 + |
Pau Espin Pedrol | 1de6873 | 2020-03-11 14:04:52 +0100 | [diff] [blame] | 838 | delay_sum->tv_nsec / 1000000000; |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 839 | uint32_t avg_delay_ms = 0; |
| 840 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 841 | if (the_pcu->bssgp.queue_delay_count > 0) |
| 842 | avg_delay_ms = delay_sum_ms / the_pcu->bssgp.queue_delay_count; |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 843 | |
| 844 | /* Reset accumulator */ |
Pau Espin Pedrol | 1de6873 | 2020-03-11 14:04:52 +0100 | [diff] [blame] | 845 | delay_sum->tv_sec = delay_sum->tv_nsec = 0; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 846 | the_pcu->bssgp.queue_delay_count = 0; |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 847 | |
| 848 | return avg_delay_ms; |
| 849 | } |
| 850 | |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 851 | static int get_and_reset_measured_leak_rate(int *usage_by_1000, unsigned num_pdch) |
| 852 | { |
| 853 | int rate; /* byte per second */ |
| 854 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 855 | if (the_pcu->bssgp.queue_frames_sent == 0) |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 856 | return -1; |
| 857 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 858 | if (the_pcu->bssgp.queue_frames_recv == 0) |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 859 | return -1; |
| 860 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 861 | *usage_by_1000 = the_pcu->bssgp.queue_frames_recv * 1000 / |
| 862 | the_pcu->bssgp.queue_frames_sent; |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 863 | |
| 864 | /* 20ms/num_pdch is the average RLC block duration, so the rate is |
| 865 | * calculated as: |
| 866 | * rate = bytes_recv / (block_dur * block_count) */ |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 867 | rate = the_pcu->bssgp.queue_bytes_recv * 1000 * num_pdch / |
| 868 | (20 * the_pcu->bssgp.queue_frames_recv); |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 869 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 870 | the_pcu->bssgp.queue_frames_sent = 0; |
| 871 | the_pcu->bssgp.queue_bytes_recv = 0; |
| 872 | the_pcu->bssgp.queue_frames_recv = 0; |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 873 | |
| 874 | return rate; |
| 875 | } |
| 876 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 877 | static enum CodingScheme max_coding_scheme_dl(struct gprs_rlcmac_bts *bts) |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 878 | { |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 879 | int num = 0; |
| 880 | int i; |
Pau Espin Pedrol | 87eec1f | 2020-10-30 18:46:24 +0100 | [diff] [blame] | 881 | bool mcs_any = false; |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 882 | |
Pau Espin Pedrol | 87eec1f | 2020-10-30 18:46:24 +0100 | [diff] [blame] | 883 | /* First check if we support any MCS: */ |
| 884 | for (i = 8; i >= 0; i--) { |
| 885 | if (bts->mcs_mask & (1 << i)) { |
| 886 | num = i + 1; |
| 887 | mcs_any = true; |
| 888 | break; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | if (mcs_any) { |
Pau Espin Pedrol | e8dcf64 | 2021-01-14 13:17:01 +0100 | [diff] [blame] | 893 | if (!the_pcu->vty.cs_adj_enabled) { |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 894 | if (bts->initial_mcs_dl) { |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 895 | num = bts->initial_mcs_dl; |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 896 | } else { |
Pau Espin Pedrol | 87eec1f | 2020-10-30 18:46:24 +0100 | [diff] [blame] | 897 | /* We found "num" for free in the loop above */ |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 898 | } |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 899 | } else if (bts_max_mcs_dl(bts)) { |
| 900 | num = bts_max_mcs_dl(bts); |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 901 | } else { |
| 902 | num = 9; |
| 903 | } |
| 904 | |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 905 | if (num) |
| 906 | return mcs_get_egprs_by_num(num); |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 907 | } |
| 908 | |
Pau Espin Pedrol | e8dcf64 | 2021-01-14 13:17:01 +0100 | [diff] [blame] | 909 | if (!the_pcu->vty.cs_adj_enabled) { |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 910 | if (bts->initial_cs_dl) { |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 911 | num = bts->initial_cs_dl; |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 912 | } else { |
| 913 | for (i = 3; i >= 0; i--) { |
| 914 | if (bts->cs_mask & (1 << i)) { |
| 915 | num = i + 1; |
| 916 | break; |
| 917 | } |
| 918 | } |
| 919 | } |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 920 | } else if (bts_max_cs_dl(bts)) { |
| 921 | num = bts_max_cs_dl(bts); |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 922 | } |
| 923 | |
Pau Espin Pedrol | d87722d | 2020-10-30 17:14:26 +0100 | [diff] [blame] | 924 | if (!num) |
| 925 | num = 4; |
| 926 | |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 927 | return mcs_get_gprs_by_num(num); |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 928 | } |
| 929 | |
Pau Espin Pedrol | 3f064f5 | 2019-12-10 17:09:51 +0100 | [diff] [blame] | 930 | static int gprs_bssgp_tx_fc_bvc(void) |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 931 | { |
Jacob Erlbeck | 87d7341 | 2015-04-21 12:56:48 +0200 | [diff] [blame] | 932 | struct gprs_rlcmac_bts *bts; |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 933 | uint32_t bucket_size; /* oct */ |
| 934 | uint32_t ms_bucket_size; /* oct */ |
| 935 | uint32_t leak_rate; /* oct/s */ |
| 936 | uint32_t ms_leak_rate; /* oct/s */ |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 937 | uint32_t avg_delay_ms; |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 938 | int num_pdch = -1; |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 939 | enum CodingScheme max_cs_dl; |
Jacob Erlbeck | 87d7341 | 2015-04-21 12:56:48 +0200 | [diff] [blame] | 940 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 941 | if (!the_pcu->bssgp.bctx) { |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 942 | LOGP(DBSSGP, LOGL_ERROR, "No bctx\n"); |
| 943 | return -EIO; |
| 944 | } |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 945 | |
| 946 | /* FIXME: This calculation needs to be redone to support multiple BTS */ |
| 947 | bts = llist_first_entry_or_null(&the_pcu->bts_list, struct gprs_rlcmac_bts, list); |
| 948 | if (!bts) { |
| 949 | LOGP(DBSSGP, LOGL_ERROR, "No bts\n"); |
| 950 | return -EIO; |
| 951 | } |
Jacob Erlbeck | 87d7341 | 2015-04-21 12:56:48 +0200 | [diff] [blame] | 952 | |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 953 | max_cs_dl = max_coding_scheme_dl(bts); |
Jacob Erlbeck | 6eed191 | 2015-07-21 18:29:46 +0200 | [diff] [blame] | 954 | |
Pau Espin Pedrol | e891222 | 2021-01-14 14:03:17 +0100 | [diff] [blame] | 955 | bucket_size = the_pcu->vty.fc_bvc_bucket_size; |
| 956 | leak_rate = the_pcu->vty.fc_bvc_leak_rate; |
| 957 | ms_bucket_size = the_pcu->vty.fc_ms_bucket_size; |
| 958 | ms_leak_rate = the_pcu->vty.fc_ms_leak_rate; |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 959 | |
Pau Espin Pedrol | 87eec1f | 2020-10-30 18:46:24 +0100 | [diff] [blame] | 960 | /* FIXME: This calculation is mostly wrong. It should be done based on |
| 961 | currently established TBF (and whether the related (egprs)_ms_class |
| 962 | as per which CS/MCS they support). */ |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 963 | if (leak_rate == 0) { |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 964 | int meas_rate; |
| 965 | int usage; /* in 0..1000 */ |
| 966 | |
| 967 | if (num_pdch < 0) |
| 968 | num_pdch = count_pdch(bts); |
| 969 | |
| 970 | meas_rate = get_and_reset_measured_leak_rate(&usage, num_pdch); |
| 971 | if (meas_rate > 0) { |
| 972 | leak_rate = gprs_bssgp_max_leak_rate(max_cs_dl, num_pdch); |
| 973 | leak_rate = |
| 974 | (meas_rate * usage + leak_rate * (1000 - usage)) / |
| 975 | 1000; |
| 976 | LOGP(DBSSGP, LOGL_DEBUG, |
| 977 | "Estimated BVC leak rate = %d " |
| 978 | "(measured %d, usage %d%%)\n", |
| 979 | leak_rate, meas_rate, usage/10); |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | if (leak_rate == 0) { |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 984 | if (num_pdch < 0) |
| 985 | num_pdch = count_pdch(bts); |
| 986 | |
Jacob Erlbeck | 6eed191 | 2015-07-21 18:29:46 +0200 | [diff] [blame] | 987 | leak_rate = gprs_bssgp_max_leak_rate(max_cs_dl, num_pdch); |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 988 | |
| 989 | LOGP(DBSSGP, LOGL_DEBUG, |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 990 | "Computed BVC leak rate = %d, num_pdch = %d, cs = %s\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 991 | leak_rate, num_pdch, mcs_name(max_cs_dl)); |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 992 | }; |
| 993 | |
| 994 | if (ms_leak_rate == 0) { |
| 995 | int ms_num_pdch; |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 996 | int max_pdch = gprs_alloc_max_dl_slots_per_ms(bts, 0); |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 997 | |
| 998 | if (num_pdch < 0) |
| 999 | num_pdch = count_pdch(bts); |
| 1000 | |
| 1001 | ms_num_pdch = num_pdch; |
Jacob Erlbeck | 7f79f0d | 2015-07-17 11:38:49 +0200 | [diff] [blame] | 1002 | if (max_pdch > FC_MS_MAX_RX_SLOTS) |
| 1003 | max_pdch = FC_MS_MAX_RX_SLOTS; |
| 1004 | if (ms_num_pdch > max_pdch) |
| 1005 | ms_num_pdch = max_pdch; |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 1006 | |
Jacob Erlbeck | 6eed191 | 2015-07-21 18:29:46 +0200 | [diff] [blame] | 1007 | ms_leak_rate = gprs_bssgp_max_leak_rate(max_cs_dl, ms_num_pdch); |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 1008 | |
| 1009 | /* TODO: To properly support multiple TRX, the per MS leak rate |
| 1010 | * should be derived from the max number of PDCH TS per TRX. |
| 1011 | */ |
| 1012 | LOGP(DBSSGP, LOGL_DEBUG, |
Jacob Erlbeck | 7f28c97 | 2016-02-04 17:54:42 +0100 | [diff] [blame] | 1013 | "Computed MS default leak rate = %d, ms_num_pdch = %d, " |
| 1014 | "cs = %s\n", |
Max | 136ebcc | 2019-03-05 14:59:03 +0100 | [diff] [blame] | 1015 | ms_leak_rate, ms_num_pdch, mcs_name(max_cs_dl)); |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 1016 | }; |
| 1017 | |
| 1018 | /* TODO: Force leak_rate to 0 on buffer bloat */ |
| 1019 | |
| 1020 | if (bucket_size == 0) |
| 1021 | bucket_size = compute_bucket_size(bts, leak_rate, |
| 1022 | FC_FALLBACK_BVC_BUCKET_SIZE); |
| 1023 | |
| 1024 | if (ms_bucket_size == 0) |
| 1025 | ms_bucket_size = compute_bucket_size(bts, ms_leak_rate, |
| 1026 | FC_MS_BUCKET_SIZE_BY_BMAX(bucket_size)); |
| 1027 | |
| 1028 | if (leak_rate > FC_MAX_BUCKET_LEAK_RATE) |
| 1029 | leak_rate = FC_MAX_BUCKET_LEAK_RATE; |
| 1030 | |
| 1031 | if (ms_leak_rate > FC_MAX_BUCKET_LEAK_RATE) |
| 1032 | ms_leak_rate = FC_MAX_BUCKET_LEAK_RATE; |
| 1033 | |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 1034 | /* Avg queue delay monitoring */ |
| 1035 | avg_delay_ms = get_and_reset_avg_queue_delay(); |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 1036 | |
Jacob Erlbeck | 6eeb7c7 | 2015-05-06 15:26:08 +0200 | [diff] [blame] | 1037 | /* Update tag */ |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1038 | the_pcu->bssgp.fc_tag += 1; |
Jacob Erlbeck | 6eeb7c7 | 2015-05-06 15:26:08 +0200 | [diff] [blame] | 1039 | |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 1040 | LOGP(DBSSGP, LOGL_DEBUG, |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 1041 | "Sending FLOW CONTROL BVC, Bmax = %d, R = %d, Bmax_MS = %d, " |
| 1042 | "R_MS = %d, avg_dly = %d\n", |
| 1043 | bucket_size, leak_rate, ms_bucket_size, ms_leak_rate, |
| 1044 | avg_delay_ms); |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 1045 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1046 | return bssgp_tx_fc_bvc(the_pcu->bssgp.bctx, the_pcu->bssgp.fc_tag, |
Jacob Erlbeck | 3d62fc5 | 2015-04-30 15:01:15 +0200 | [diff] [blame] | 1047 | bucket_size, leak_rate, |
| 1048 | ms_bucket_size, ms_leak_rate, |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 1049 | NULL, &avg_delay_ms); |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | static void bvc_timeout(void *_priv) |
| 1053 | { |
Pau Espin Pedrol | 5211d9d | 2019-09-05 16:20:22 +0200 | [diff] [blame] | 1054 | unsigned long secs; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1055 | if (!the_pcu->bssgp.bvc_sig_reset) { |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1056 | LOGP(DBSSGP, LOGL_INFO, "Sending reset on BVCI 0\n"); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1057 | bssgp_tx_bvc_reset(the_pcu->bssgp.bctx, 0, BSSGP_CAUSE_OML_INTERV); |
Pau Espin Pedrol | 14339f6 | 2021-04-26 14:14:37 +0200 | [diff] [blame] | 1058 | secs = osmo_tdef_get(the_pcu->T_defs, -102, OSMO_TDEF_S, -1); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1059 | osmo_timer_schedule(&the_pcu->bssgp.bvc_timer, secs, 0); |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1060 | return; |
| 1061 | } |
| 1062 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1063 | if (!the_pcu->bssgp.bvc_reset) { |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1064 | LOGP(DBSSGP, LOGL_INFO, "Sending reset on BVCI %d\n", |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1065 | the_pcu->bssgp.bctx->bvci); |
| 1066 | bssgp_tx_bvc_reset(the_pcu->bssgp.bctx, the_pcu->bssgp.bctx->bvci, BSSGP_CAUSE_OML_INTERV); |
Pau Espin Pedrol | 14339f6 | 2021-04-26 14:14:37 +0200 | [diff] [blame] | 1067 | secs = osmo_tdef_get(the_pcu->T_defs, -102, OSMO_TDEF_S, -1); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1068 | osmo_timer_schedule(&the_pcu->bssgp.bvc_timer, secs, 0); |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1069 | return; |
| 1070 | } |
| 1071 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1072 | if (!the_pcu->bssgp.bvc_unblocked) { |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1073 | LOGP(DBSSGP, LOGL_INFO, "Sending unblock on BVCI %d\n", |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1074 | the_pcu->bssgp.bctx->bvci); |
| 1075 | bssgp_tx_bvc_unblock(the_pcu->bssgp.bctx); |
Pau Espin Pedrol | 14339f6 | 2021-04-26 14:14:37 +0200 | [diff] [blame] | 1076 | secs = osmo_tdef_get(the_pcu->T_defs, -101, OSMO_TDEF_S, -1); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1077 | osmo_timer_schedule(&the_pcu->bssgp.bvc_timer, secs, 0); |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1078 | return; |
| 1079 | } |
| 1080 | |
| 1081 | LOGP(DBSSGP, LOGL_DEBUG, "Sending flow control info on BVCI %d\n", |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1082 | the_pcu->bssgp.bctx->bvci); |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1083 | gprs_bssgp_tx_fc_bvc(); |
Pau Espin Pedrol | e891222 | 2021-01-14 14:03:17 +0100 | [diff] [blame] | 1084 | osmo_timer_schedule(&the_pcu->bssgp.bvc_timer, the_pcu->vty.fc_interval, 0); |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1085 | } |
| 1086 | |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1087 | /*! configure NS layer |
| 1088 | * |
| 1089 | * \param bts pointer to the bts object |
| 1090 | * \param nsei the NSEI of the BSS |
| 1091 | * \param local pointer to an array of local address to bind on. |
| 1092 | * \param remote pointer to an array of remote address SGSNs. If dynamic IP-SNS is used remote is used as initial SGSN endpoints. |
| 1093 | * \param nsvci pointer to an array of nsvcis |
| 1094 | * \param valid bitmask. a 1 means the position in the array contains a valid entry for local, remote, nsvci |
| 1095 | * \returns 0 if the configuration has succeeded. on error != 0 |
| 1096 | */ |
| 1097 | static int ns_configure_nse(struct gprs_rlcmac_bts *bts, |
| 1098 | uint16_t nsei, |
| 1099 | const struct osmo_sockaddr *local, |
| 1100 | const struct osmo_sockaddr *remote, |
| 1101 | const uint16_t *nsvci, |
| 1102 | uint16_t valid) |
Jacob Erlbeck | ebebad1 | 2015-08-17 14:43:52 +0200 | [diff] [blame] | 1103 | { |
Pau Espin Pedrol | 890de98 | 2021-07-15 14:34:35 +0200 | [diff] [blame] | 1104 | unsigned int i; |
| 1105 | int rc; |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1106 | uint16_t binds = 0; |
| 1107 | bool nsvcs = false; |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 1108 | struct gprs_ns2_vc *nsvc; |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1109 | struct gprs_ns2_vc_bind *bind[PCU_IF_NUM_NSVC] = { }; |
Pau Espin Pedrol | 890de98 | 2021-07-15 14:34:35 +0200 | [diff] [blame] | 1110 | char name[16]; |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1111 | bool sns_configured = false; |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1112 | |
| 1113 | if (!valid) |
| 1114 | return -1; |
| 1115 | |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1116 | bts->nse = gprs_ns2_nse_by_nsei(the_pcu->nsi, nsei); |
| 1117 | if (!bts->nse) |
| 1118 | bts->nse = gprs_ns2_create_nse(the_pcu->nsi, nsei, |
| 1119 | GPRS_NS2_LL_UDP, the_pcu->vty.ns_dialect); |
| 1120 | if (!bts->nse) { |
| 1121 | LOGP(DBSSGP, LOGL_ERROR, "Failed to create NSE\n"); |
| 1122 | return -1; |
| 1123 | } |
| 1124 | |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1125 | for (i = 0; i < PCU_IF_NUM_NSVC; i++) { |
| 1126 | if (!(valid & (1 << i))) |
| 1127 | continue; |
| 1128 | |
Daniel Willmann | dd28f82 | 2021-10-29 17:34:24 +0200 | [diff] [blame] | 1129 | bind[i] = gprs_ns2_ip_bind_by_sockaddr(the_pcu->nsi, &local[i]); |
| 1130 | if (!bind[i]) { |
Pau Espin Pedrol | 890de98 | 2021-07-15 14:34:35 +0200 | [diff] [blame] | 1131 | snprintf(name, sizeof(name), "pcu%u", i); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1132 | rc = gprs_ns2_ip_bind(the_pcu->nsi, name, &local[i], 0, &bind[i]); |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1133 | if (rc < 0) { |
| 1134 | LOGP(DBSSGP, LOGL_ERROR, "Failed to bind to %s\n", osmo_sockaddr_to_str(&local[i])); |
| 1135 | continue; |
| 1136 | } |
Alexander Couzens | 151bc5b | 2021-02-15 05:53:12 +0100 | [diff] [blame] | 1137 | |
| 1138 | if (the_pcu->vty.ns_dialect == GPRS_NS2_DIALECT_SNS) { |
| 1139 | rc = gprs_ns2_sns_add_bind(bts->nse, bind[i]); |
| 1140 | if (rc < 0) { |
| 1141 | LOGP(DBSSGP, LOGL_ERROR, "Failed to add bind %s to the NSE for IP-SNS\n", osmo_sockaddr_to_str(&local[i])); |
| 1142 | continue; |
| 1143 | } |
| 1144 | } |
Harald Welte | d9367e3 | 2021-04-29 22:02:47 +0200 | [diff] [blame] | 1145 | |
| 1146 | if (the_pcu->vty.ns_ip_dscp != -1) |
| 1147 | gprs_ns2_ip_bind_set_dscp(bind[i], the_pcu->vty.ns_ip_dscp); |
| 1148 | if (the_pcu->vty.ns_priority != -1) |
| 1149 | gprs_ns2_ip_bind_set_priority(bind[i], the_pcu->vty.ns_priority); |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | binds |= 1 << i; |
| 1153 | } |
| 1154 | |
| 1155 | if (!binds) { |
| 1156 | LOGP(DBSSGP, LOGL_ERROR, "Failed to bind to any NS-VC\n"); |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1157 | gprs_ns2_free_nses(the_pcu->nsi); |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1158 | return -1; |
| 1159 | } |
Jacob Erlbeck | ebebad1 | 2015-08-17 14:43:52 +0200 | [diff] [blame] | 1160 | |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1161 | for (i = 0; i < PCU_IF_NUM_NSVC; i++) { |
| 1162 | if (!(binds & (1 << i))) |
| 1163 | continue; |
| 1164 | |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 1165 | if (the_pcu->vty.ns_dialect == GPRS_NS2_DIALECT_SNS) { |
Alexander Couzens | 1e6c350 | 2020-12-09 01:41:24 +0100 | [diff] [blame] | 1166 | rc = gprs_ns2_sns_add_endpoint(bts->nse, &remote[i]); |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1167 | if (rc && rc != -EALREADY) { |
| 1168 | LOGP(DBSSGP, LOGL_ERROR, "Failed to add SNS endpoint %s!\n", osmo_sockaddr_to_str(&remote[i])); |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1169 | return rc; |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1170 | } else { |
| 1171 | sns_configured = true; |
| 1172 | } |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1173 | } else { |
| 1174 | nsvc = gprs_ns2_ip_connect(bind[i], &remote[i], bts->nse, nsvci[i]); |
| 1175 | if (nsvc) |
| 1176 | nsvcs = true; |
| 1177 | else |
| 1178 | LOGP(DBSSGP, LOGL_ERROR, "Failed to connect to towards SGSN %s!\n", osmo_sockaddr_to_str(&remote[i])); |
| 1179 | } |
Jacob Erlbeck | ebebad1 | 2015-08-17 14:43:52 +0200 | [diff] [blame] | 1180 | } |
| 1181 | |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1182 | if (the_pcu->vty.ns_dialect == GPRS_NS2_DIALECT_SNS) |
| 1183 | return sns_configured ? 0 : -1; |
| 1184 | else |
| 1185 | return nsvcs ? 0 : -1; |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | struct nsvc_cb { |
| 1189 | const struct osmo_sockaddr *local; |
| 1190 | const struct osmo_sockaddr *remote; |
| 1191 | const uint16_t *nsvci; |
| 1192 | /* [in] bitmask of valid nsvc in local/remote */ |
| 1193 | uint16_t valid; |
| 1194 | /* [out] bitmask of found nsvcs */ |
| 1195 | uint16_t found; |
| 1196 | }; |
| 1197 | |
| 1198 | static int ns_conf_vc_cb(struct gprs_ns2_vc *nsvc, void *ctx) |
| 1199 | { |
| 1200 | struct nsvc_cb *data = (struct nsvc_cb *) ctx; |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1201 | unsigned int i; |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1202 | |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1203 | for (i = 0; i < PCU_IF_NUM_NSVC; i++) { |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1204 | if (!(data->valid & (1 << i))) |
| 1205 | continue; |
| 1206 | if (data->found & (1 << i)) |
| 1207 | continue; |
| 1208 | |
| 1209 | if (gprs_ns2_ip_vc_equal(nsvc, &data->local[i], |
| 1210 | &data->remote[i], |
| 1211 | data->nsvci[i])) { |
| 1212 | data->found |= 1 << i; |
| 1213 | return 0; |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | /* Found an extra nsvc */ |
| 1218 | LOGP(DBSSGP, LOGL_DEBUG, " Removing NSVC %s\n", gprs_ns2_ll_str(nsvc)); |
| 1219 | gprs_ns2_free_nsvc(nsvc); |
| 1220 | |
| 1221 | return 0; |
| 1222 | } |
| 1223 | |
Alexander Couzens | 94a367f | 2021-02-16 16:57:15 +0100 | [diff] [blame] | 1224 | /* update the ns configuration if needed */ |
| 1225 | int gprs_ns_update_config(struct gprs_rlcmac_bts *bts, uint16_t nsei, |
| 1226 | const struct osmo_sockaddr *local, |
| 1227 | const struct osmo_sockaddr *remote, |
| 1228 | uint16_t *nsvci, uint16_t valid) |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1229 | { |
| 1230 | int rc = 0; |
| 1231 | if (!bts->nse) { |
| 1232 | /* there shouldn't any previous state. */ |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1233 | gprs_ns2_free_nses(the_pcu->nsi); |
| 1234 | gprs_ns2_free_binds(the_pcu->nsi); |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1235 | rc = ns_configure_nse(bts, nsei, local, remote, nsvci, valid); |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1236 | } else if (nsei != gprs_ns2_nse_nsei(bts->nse)) { |
| 1237 | /* the NSEI has changed */ |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1238 | gprs_ns2_free_nses(the_pcu->nsi); |
| 1239 | gprs_ns2_free_binds(the_pcu->nsi); |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1240 | rc = ns_configure_nse(bts, nsei, local, remote, nsvci, valid); |
Alexander Couzens | f7ec525 | 2021-01-25 20:28:38 +0100 | [diff] [blame] | 1241 | } else if (the_pcu->vty.ns_dialect == GPRS_NS2_DIALECT_SNS) { |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1242 | /* SNS: check if the initial nsvc is the same, if not recreate it */ |
| 1243 | const struct osmo_sockaddr *initial = gprs_ns2_nse_sns_remote(bts->nse); |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 1244 | unsigned int i; |
| 1245 | for (i = 0; i < PCU_IF_NUM_NSVC; i++) { |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1246 | if (!(valid & (1 << i))) |
| 1247 | continue; |
| 1248 | |
| 1249 | /* found the initial - everything should be fine */ |
| 1250 | if (!osmo_sockaddr_cmp(initial, &remote[i])) |
| 1251 | return 0; |
| 1252 | } |
| 1253 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1254 | gprs_ns2_free_nses(the_pcu->nsi); |
| 1255 | gprs_ns2_free_binds(the_pcu->nsi); |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1256 | rc = ns_configure_nse(bts, nsei, local, remote, nsvci, valid); |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 1257 | } else { |
Alexander Couzens | 5bece2a | 2020-10-12 02:27:22 +0200 | [diff] [blame] | 1258 | /* check if all NSVC are still the same. */ |
| 1259 | struct nsvc_cb data = { |
| 1260 | .local = &local[0], |
| 1261 | .remote = &remote[0], |
| 1262 | .nsvci = &nsvci[0], |
| 1263 | .valid = valid, |
| 1264 | .found = 0, |
| 1265 | }; |
| 1266 | |
| 1267 | /* search the current active nsvcs */ |
| 1268 | gprs_ns2_nse_foreach_nsvc(bts->nse, &ns_conf_vc_cb, &data); |
| 1269 | |
| 1270 | /* we found all our valid nsvcs and might have removed all other nsvcs */ |
| 1271 | if (valid == data.found) |
| 1272 | return 0; |
| 1273 | |
| 1274 | /* remove all found nsvcs from the valid field */ |
| 1275 | valid &= ~data.found; |
Alexander Couzens | 13a12e2 | 2021-02-15 05:50:10 +0100 | [diff] [blame] | 1276 | rc = ns_configure_nse(bts, nsei, local, remote, nsvci, valid); |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | if (rc) |
| 1280 | LOGP(DBSSGP, LOGL_ERROR, "Failed to connect!\n"); |
| 1281 | |
| 1282 | return rc; |
Jacob Erlbeck | ebebad1 | 2015-08-17 14:43:52 +0200 | [diff] [blame] | 1283 | } |
| 1284 | |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 1285 | struct gprs_bssgp_pcu *gprs_bssgp_init( |
| 1286 | struct gprs_rlcmac_bts *bts, |
| 1287 | uint16_t nsei, uint16_t bvci, |
| 1288 | uint16_t mcc, uint16_t mnc, bool mnc_3_digits, |
| 1289 | uint16_t lac, uint16_t rac, uint16_t cell_id) |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 1290 | { |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 1291 | |
Holger Hans Peter Freyther | e8d9a5f | 2013-07-28 19:11:20 +0200 | [diff] [blame] | 1292 | /* if already created... return the current address */ |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1293 | if (the_pcu->bssgp.bctx) |
| 1294 | return &the_pcu->bssgp; |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 1295 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1296 | the_pcu->bssgp.bts = bts; |
| 1297 | the_pcu->bssgp.bctx = btsctx_alloc(bvci, nsei); |
| 1298 | if (!the_pcu->bssgp.bctx) { |
Andreas Eversberg | 0e40309 | 2012-07-06 11:04:57 +0200 | [diff] [blame] | 1299 | LOGP(DBSSGP, LOGL_ERROR, "Failed to create BSSGP context\n"); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1300 | the_pcu->bssgp.bts->nse = NULL; |
Holger Hans Peter Freyther | e8d9a5f | 2013-07-28 19:11:20 +0200 | [diff] [blame] | 1301 | return NULL; |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 1302 | } |
Alexander Couzens | 423bf8c | 2021-02-17 02:31:37 +0100 | [diff] [blame] | 1303 | the_pcu->bssgp.bctx->is_sgsn = false; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1304 | the_pcu->bssgp.bctx->ra_id.mcc = spoof_mcc ? : mcc; |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 1305 | if (spoof_mnc) { |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1306 | the_pcu->bssgp.bctx->ra_id.mnc = spoof_mnc; |
| 1307 | the_pcu->bssgp.bctx->ra_id.mnc_3_digits = spoof_mnc_3_digits; |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 1308 | } else { |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1309 | the_pcu->bssgp.bctx->ra_id.mnc = mnc; |
| 1310 | the_pcu->bssgp.bctx->ra_id.mnc_3_digits = mnc_3_digits; |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 1311 | } |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1312 | the_pcu->bssgp.bctx->ra_id.lac = lac; |
| 1313 | the_pcu->bssgp.bctx->ra_id.rac = rac; |
| 1314 | the_pcu->bssgp.bctx->cell_id = cell_id; |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 1315 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1316 | osmo_timer_setup(&the_pcu->bssgp.bvc_timer, bvc_timeout, bts); |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1317 | |
Oliver Smith | 9783967 | 2021-07-05 11:11:42 +0200 | [diff] [blame] | 1318 | the_pcu->bssgp.ctrs = rate_ctr_group_alloc(the_pcu, &sgsn_ctrg_desc, 0); |
| 1319 | OSMO_ASSERT(the_pcu->bssgp.ctrs) |
| 1320 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1321 | return &the_pcu->bssgp; |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 1322 | } |
| 1323 | |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 1324 | void gprs_bssgp_destroy(struct gprs_rlcmac_bts *bts) |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 1325 | { |
Oliver Smith | 9783967 | 2021-07-05 11:11:42 +0200 | [diff] [blame] | 1326 | rate_ctr_group_free(the_pcu->bssgp.ctrs); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1327 | osmo_timer_del(&the_pcu->bssgp.bvc_timer); |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 1328 | |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 1329 | /* FIXME: blocking... */ |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1330 | the_pcu->bssgp.nsvc_unblocked = 0; |
| 1331 | the_pcu->bssgp.bvc_sig_reset = 0; |
| 1332 | the_pcu->bssgp.bvc_reset = 0; |
| 1333 | the_pcu->bssgp.bvc_unblocked = 0; |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 1334 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1335 | bssgp_bvc_ctx_free(the_pcu->bssgp.bctx); |
| 1336 | the_pcu->bssgp.bctx = NULL; |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 1337 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1338 | gprs_ns2_free(the_pcu->nsi); |
| 1339 | the_pcu->nsi = NULL; |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 1340 | bts->nse = NULL; |
Andreas Eversberg | bf5a0f6 | 2012-07-06 08:58:22 +0200 | [diff] [blame] | 1341 | } |
| 1342 | |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 1343 | void gprs_bssgp_update_frames_sent() |
| 1344 | { |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1345 | the_pcu->bssgp.queue_frames_sent += 1; |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | void gprs_bssgp_update_bytes_received(unsigned bytes_recv, unsigned frames_recv) |
| 1349 | { |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1350 | the_pcu->bssgp.queue_bytes_recv += bytes_recv; |
| 1351 | the_pcu->bssgp.queue_frames_recv += frames_recv; |
Jacob Erlbeck | 2db0f08 | 2015-09-07 18:49:00 +0200 | [diff] [blame] | 1352 | } |
| 1353 | |
Pau Espin Pedrol | 1de6873 | 2020-03-11 14:04:52 +0100 | [diff] [blame] | 1354 | void gprs_bssgp_update_queue_delay(const struct timespec *tv_recv, |
| 1355 | const struct timespec *tv_now) |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 1356 | { |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1357 | struct timespec *delay_sum = &the_pcu->bssgp.queue_delay_sum; |
Pau Espin Pedrol | 1de6873 | 2020-03-11 14:04:52 +0100 | [diff] [blame] | 1358 | struct timespec tv_delay; |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 1359 | |
Pau Espin Pedrol | 1de6873 | 2020-03-11 14:04:52 +0100 | [diff] [blame] | 1360 | timespecsub(tv_now, tv_recv, &tv_delay); |
| 1361 | timespecadd(delay_sum, &tv_delay, delay_sum); |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 1362 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 1363 | the_pcu->bssgp.queue_delay_count += 1; |
Jacob Erlbeck | 6e4ccec | 2015-05-06 14:24:36 +0200 | [diff] [blame] | 1364 | } |