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