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