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