Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1 | /* NS-over-IP proxy */ |
| 2 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 3 | /* (C) 2010-2020 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 90267a9 | 2013-10-23 11:24:17 +0200 | [diff] [blame] | 4 | * (C) 2010-2013 by On-Waves |
| 5 | * (C) 2013 by Holger Hans Peter Freyther |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * GNU Affero General Public License for more details. |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 17 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <unistd.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <getopt.h> |
| 28 | #include <errno.h> |
| 29 | #include <sys/fcntl.h> |
| 30 | #include <sys/stat.h> |
Harald Welte | 7fc9822 | 2010-05-11 10:15:42 +0200 | [diff] [blame] | 31 | #include <arpa/inet.h> |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 32 | #include <time.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 33 | |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 34 | #include <osmocom/core/hashtable.h> |
Daniel Willmann | e8c8ec9 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 35 | #include <osmocom/core/logging.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 36 | #include <osmocom/core/talloc.h> |
| 37 | #include <osmocom/core/select.h> |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 38 | #include <osmocom/core/rate_ctr.h> |
Jacob Erlbeck | 46caed8 | 2015-11-02 15:15:38 +0100 | [diff] [blame] | 39 | #include <osmocom/core/stats.h> |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 40 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 41 | #include <osmocom/gprs/gprs_ns2.h> |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 42 | #include <osmocom/gprs/gprs_bssgp.h> |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 43 | #include <osmocom/gprs/gprs_bssgp_bss.h> |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 44 | #include <osmocom/gprs/bssgp_bvc_fsm.h> |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 45 | |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 46 | #include <osmocom/gsm/gsm_utils.h> |
| 47 | |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 48 | #include <osmocom/sgsn/signal.h> |
| 49 | #include <osmocom/sgsn/debug.h> |
| 50 | #include <osmocom/sgsn/gprs_gb_parse.h> |
| 51 | #include <osmocom/sgsn/gb_proxy.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 52 | |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 53 | #include <osmocom/sgsn/gprs_llc.h> |
Harald Welte | 53373bc | 2016-04-20 17:11:43 +0200 | [diff] [blame] | 54 | #include <osmocom/gsm/protocol/gsm_04_08_gprs.h> |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 55 | #include <osmocom/sgsn/gprs_utils.h> |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 56 | |
Pau Espin Pedrol | b1d1c24 | 2018-10-30 17:27:59 +0100 | [diff] [blame] | 57 | extern void *tall_sgsn_ctx; |
Neels Hofmeyr | ee6cfdc | 2017-07-13 02:03:50 +0200 | [diff] [blame] | 58 | |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 59 | static const struct rate_ctr_desc global_ctr_description[] = { |
| 60 | { "inv-bvci", "Invalid BVC Identifier " }, |
Jacob Erlbeck | 8f50359 | 2014-06-02 10:49:00 +0200 | [diff] [blame] | 61 | { "inv-lai", "Invalid Location Area Identifier" }, |
| 62 | { "inv-rai", "Invalid Routing Area Identifier " }, |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 63 | { "inv-nsei", "No BVC established for NSEI " }, |
Pau Espin Pedrol | 437e209 | 2018-07-24 12:41:26 +0200 | [diff] [blame] | 64 | { "proto-err:bss", "BSSGP protocol error (BSS )" }, |
| 65 | { "proto-err:sgsn", "BSSGP protocol error (SGSN)" }, |
| 66 | { "not-supp:bss", "Feature not supported (BSS )" }, |
| 67 | { "not-supp:sgsn", "Feature not supported (SGSN)" }, |
| 68 | { "restart:sgsn", "Restarted RESET procedure (SGSN)" }, |
| 69 | { "tx-err:sgsn", "NS Transmission error (SGSN)" }, |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 70 | { "error", "Other error " }, |
Jacob Erlbeck | 006c038 | 2014-05-27 13:49:04 +0200 | [diff] [blame] | 71 | { "mod-peer-err", "Patch error: no peer " }, |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | static const struct rate_ctr_group_desc global_ctrg_desc = { |
Max | 8a01a80 | 2017-12-20 13:10:11 +0100 | [diff] [blame] | 75 | .group_name_prefix = "gbproxy:global", |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 76 | .group_description = "GBProxy Global Statistics", |
| 77 | .num_ctr = ARRAY_SIZE(global_ctr_description), |
| 78 | .ctr_desc = global_ctr_description, |
Jacob Erlbeck | 46caed8 | 2015-11-02 15:15:38 +0100 | [diff] [blame] | 79 | .class_id = OSMO_STATS_CLASS_GLOBAL, |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 82 | static int gbprox_relay2peer(struct msgb *old_msg, struct gbproxy_bvc *bvc, |
Daniel Willmann | 8bca8de | 2020-11-03 21:11:45 +0100 | [diff] [blame] | 83 | uint16_t ns_bvci); |
Jacob Erlbeck | 5f4ef32 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 84 | |
Harald Welte | 4bf53ef | 2020-12-05 17:50:23 +0100 | [diff] [blame] | 85 | |
Harald Welte | 052d855 | 2020-12-06 16:32:01 +0100 | [diff] [blame] | 86 | /* generate BVC-STATUS message with cause value derived from TLV-parser error */ |
| 87 | static int tx_status_from_tlvp(enum osmo_tlv_parser_error tlv_p_err, struct msgb *orig_msg) |
| 88 | { |
| 89 | uint8_t bssgp_cause; |
| 90 | switch (tlv_p_err) { |
| 91 | case OSMO_TLVP_ERR_MAND_IE_MISSING: |
| 92 | bssgp_cause = BSSGP_CAUSE_MISSING_MAND_IE; |
| 93 | break; |
| 94 | default: |
| 95 | bssgp_cause = BSSGP_CAUSE_PROTO_ERR_UNSPEC; |
| 96 | } |
| 97 | return bssgp_tx_status(bssgp_cause, NULL, orig_msg); |
| 98 | } |
| 99 | |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 100 | /* strip off the NS header */ |
| 101 | static void strip_ns_hdr(struct msgb *msg) |
| 102 | { |
| 103 | int strip_len = msgb_bssgph(msg) - msg->data; |
| 104 | msgb_pull(msg, strip_len); |
| 105 | } |
| 106 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 107 | #if 0 |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 108 | /* feed a message down the NS-VC associated with the specified bvc */ |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 109 | static int gbprox_relay2sgsn(struct gbproxy_config *cfg, struct msgb *old_msg, |
Jacob Erlbeck | f4d60c8 | 2014-08-26 14:47:15 +0200 | [diff] [blame] | 110 | uint16_t ns_bvci, uint16_t sgsn_nsei) |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 111 | { |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 112 | /* create a copy of the message so the old one can |
| 113 | * be free()d safely when we return from gbprox_rcvmsg() */ |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 114 | struct gprs_ns2_inst *nsi = cfg->nsi; |
| 115 | struct osmo_gprs_ns2_prim nsp = {}; |
Pau Espin Pedrol | 816a67d | 2018-08-15 13:53:48 +0200 | [diff] [blame] | 116 | struct msgb *msg = bssgp_msgb_copy(old_msg, "msgb_relay2sgsn"); |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 117 | int rc; |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 118 | |
Daniel Willmann | 103a7ec | 2020-12-02 16:08:02 +0100 | [diff] [blame] | 119 | DEBUGP(DGPRS, "NSE(%05u/BSS)-BVC(%05u) proxying BTS->SGSN NSE(%05u/SGSN)\n", |
Jacob Erlbeck | f4d60c8 | 2014-08-26 14:47:15 +0200 | [diff] [blame] | 120 | msgb_nsei(msg), ns_bvci, sgsn_nsei); |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 121 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 122 | nsp.bvci = ns_bvci; |
| 123 | nsp.nsei = sgsn_nsei; |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 124 | |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 125 | strip_ns_hdr(msg); |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 126 | osmo_prim_init(&nsp.oph, SAP_NS, PRIM_NS_UNIT_DATA, |
| 127 | PRIM_OP_REQUEST, msg); |
| 128 | rc = gprs_ns2_recv_prim(nsi, &nsp.oph); |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 129 | if (rc < 0) |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 130 | rate_ctr_inc(&cfg->ctrg->ctr[GBPROX_GLOB_CTR_TX_ERR_SGSN]); |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 131 | return rc; |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 132 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 133 | #endif |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 134 | |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 135 | /* feed a message down the NSE */ |
| 136 | static int gbprox_relay2nse(struct msgb *old_msg, struct gbproxy_nse *nse, |
Daniel Willmann | 8bca8de | 2020-11-03 21:11:45 +0100 | [diff] [blame] | 137 | uint16_t ns_bvci) |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 138 | { |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 139 | OSMO_ASSERT(nse); |
| 140 | OSMO_ASSERT(nse->cfg); |
| 141 | |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 142 | /* create a copy of the message so the old one can |
| 143 | * be free()d safely when we return from gbprox_rcvmsg() */ |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 144 | struct gprs_ns2_inst *nsi = nse->cfg->nsi; |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 145 | struct osmo_gprs_ns2_prim nsp = {}; |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 146 | struct msgb *msg = bssgp_msgb_copy(old_msg, "msgb_relay2nse"); |
Harald Welte | 2636e89 | 2020-11-18 12:01:46 +0100 | [diff] [blame] | 147 | uint32_t tlli; |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 148 | int rc; |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 149 | |
Daniel Willmann | 103a7ec | 2020-12-02 16:08:02 +0100 | [diff] [blame] | 150 | DEBUGP(DGPRS, "NSE(%05u/SGSN)-BVC(%05u) proxying SGSN->BSS NSE(%05u/BSS)\n", |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 151 | msgb_nsei(msg), ns_bvci, nse->nsei); |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 152 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 153 | nsp.bvci = ns_bvci; |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 154 | nsp.nsei = nse->nsei; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 155 | |
Harald Welte | 0ab535b | 2010-05-13 10:34:56 +0200 | [diff] [blame] | 156 | /* Strip the old NS header, it will be replaced with a new one */ |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 157 | strip_ns_hdr(msg); |
| 158 | |
Harald Welte | 2636e89 | 2020-11-18 12:01:46 +0100 | [diff] [blame] | 159 | /* TS 48.018 Section 5.4.2: The link selector parameter is |
| 160 | * defined in 3GPP TS 48.016. At one side of the Gb interface, |
| 161 | * all BSSGP UNITDATA PDUs related to an MS shall be passed with |
| 162 | * the same LSP, e.g. the LSP contains the MS's TLLI, to the |
| 163 | * underlying network service. */ |
| 164 | if (gprs_gb_parse_tlli(msgb_data(msg), msgb_length(msg), &tlli) == 1) |
| 165 | nsp.u.unitdata.link_selector = tlli; |
| 166 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 167 | osmo_prim_init(&nsp.oph, SAP_NS, PRIM_NS_UNIT_DATA, |
| 168 | PRIM_OP_REQUEST, msg); |
| 169 | rc = gprs_ns2_recv_prim(nsi, &nsp.oph); |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 170 | /* FIXME: We need a counter group for gbproxy_nse */ |
| 171 | //if (rc < 0) |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 172 | // rate_ctr_inc(&bvc->ctrg->ctr[GBPROX_PEER_CTR_TX_ERR]); |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 173 | |
| 174 | return rc; |
| 175 | } |
| 176 | |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 177 | /* feed a message down the NS-VC associated with the specified bvc */ |
| 178 | static int gbprox_relay2peer(struct msgb *old_msg, struct gbproxy_bvc *bvc, |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 179 | uint16_t ns_bvci) |
| 180 | { |
| 181 | int rc; |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 182 | struct gbproxy_nse *nse = bvc->nse; |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 183 | OSMO_ASSERT(nse); |
| 184 | |
| 185 | rc = gbprox_relay2nse(old_msg, nse, ns_bvci); |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 186 | if (rc < 0) |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 187 | rate_ctr_inc(&bvc->ctrg->ctr[GBPROX_PEER_CTR_TX_ERR]); |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 188 | |
| 189 | return rc; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 190 | } |
| 191 | |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 192 | int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx) |
| 193 | { |
| 194 | return 0; |
| 195 | } |
| 196 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 197 | |
| 198 | /*********************************************************************** |
| 199 | * PTP BVC handling |
| 200 | ***********************************************************************/ |
| 201 | |
| 202 | /* route an uplink message on a PTP-BVC to a SGSN using the TLLI */ |
| 203 | static int gbprox_bss2sgsn_tlli(struct gbproxy_cell *cell, struct msgb *msg, uint32_t tlli, |
| 204 | bool sig_bvci) |
| 205 | { |
| 206 | struct gbproxy_bvc *sgsn_bvc; |
| 207 | unsigned int i; |
| 208 | |
| 209 | /* FIXME: derive NRI from TLLI */ |
| 210 | /* FIXME: find the SGSN for that NRI */ |
| 211 | |
| 212 | /* HACK: we currently simply pick the first SGSN we find */ |
| 213 | for (i = 0; i < ARRAY_SIZE(cell->sgsn_bvc); i++) { |
| 214 | sgsn_bvc = cell->sgsn_bvc[i]; |
| 215 | if (sgsn_bvc) |
| 216 | return gbprox_relay2peer(msg, sgsn_bvc, sig_bvci ? 0 : sgsn_bvc->bvci); |
| 217 | } |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static int gbprox_bss2sgsn_null_nri(struct gbproxy_cell *cell, struct msgb *msg) |
| 222 | { |
| 223 | struct gbproxy_bvc *sgsn_bvc; |
| 224 | unsigned int i; |
| 225 | |
| 226 | /* FIXME: find the SGSN for that NRI */ |
| 227 | |
| 228 | /* HACK: we currently simply pick the first SGSN we find */ |
| 229 | for (i = 0; i < ARRAY_SIZE(cell->sgsn_bvc); i++) { |
| 230 | sgsn_bvc = cell->sgsn_bvc[i]; |
| 231 | if (sgsn_bvc) |
| 232 | return gbprox_relay2peer(msg, sgsn_bvc, sgsn_bvc->bvci); |
| 233 | } |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 238 | /* Receive an incoming PTP message from a BSS-side NS-VC */ |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 239 | static int gbprox_rx_ptp_from_bss(struct gbproxy_nse *nse, struct msgb *msg, uint16_t ns_bvci) |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 240 | { |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 241 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 242 | const char *pdut_name = osmo_tlv_prot_msg_name(&osmo_pdef_bssgp, bgph->pdu_type); |
| 243 | struct gbproxy_bvc *bss_bvc; |
| 244 | struct tlv_parsed tp; |
| 245 | char log_pfx[32]; |
| 246 | uint32_t tlli; |
| 247 | int rc; |
| 248 | |
| 249 | snprintf(log_pfx, sizeof(log_pfx), "NSE(%05u/BSS)-BVC(%05u/??)", nse->nsei, ns_bvci); |
| 250 | |
| 251 | LOGP(DGPRS, LOGL_DEBUG, "%s Rx %s\n", log_pfx, pdut_name); |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 252 | |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 253 | if (ns_bvci == 0 && ns_bvci == 1) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 254 | LOGP(DGPRS, LOGL_NOTICE, "%s BVCI=%05u is not PTP\n", log_pfx, ns_bvci); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 255 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 256 | } |
| 257 | |
| 258 | if (!(bssgp_pdu_type_flags(bgph->pdu_type) & BSSGP_PDUF_PTP)) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 259 | LOGP(DGPRS, LOGL_NOTICE, "%s %s not allowed in PTP BVC\n", log_pfx, pdut_name); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 260 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 261 | } |
| 262 | |
| 263 | if (!(bssgp_pdu_type_flags(bgph->pdu_type) & BSSGP_PDUF_UL)) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 264 | LOGP(DGPRS, LOGL_NOTICE, "%s %s not allowed in uplink direction\n", log_pfx, pdut_name); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 265 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 266 | } |
| 267 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 268 | bss_bvc = gbproxy_bvc_by_bvci(nse, ns_bvci); |
| 269 | if (!bss_bvc) { |
| 270 | LOGP(DGPRS, LOGL_NOTICE, "%s %s - Didn't find BVC for PTP message, discarding\n", |
| 271 | log_pfx, pdut_name); |
| 272 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &ns_bvci, msg); |
Jacob Erlbeck | 058ae12 | 2014-10-10 09:07:04 +0200 | [diff] [blame] | 273 | } |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 274 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 275 | /* UL_UNITDATA has a different header than all other uplink PDUs */ |
| 276 | if (bgph->pdu_type == BSSGP_PDUT_UL_UNITDATA) { |
| 277 | const struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
| 278 | if (msgb_bssgp_len(msg) < sizeof(*budh)) |
| 279 | return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, msg); |
| 280 | rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, &tp, 1, bgph->pdu_type, budh->data, |
| 281 | msgb_bssgp_len(msg) - sizeof(*budh), 0, 0, DGPRS, log_pfx); |
| 282 | /* populate TLLI from the fixed headser into the TLV-parsed array so later code |
| 283 | * doesn't have to worry where the TLLI came from */ |
| 284 | tp.lv[BSSGP_IE_TLLI].len = 4; |
| 285 | tp.lv[BSSGP_IE_TLLI].val = (const uint8_t *) &budh->tlli; |
| 286 | } else { |
| 287 | rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, &tp, 1, bgph->pdu_type, bgph->data, |
| 288 | msgb_bssgp_len(msg) - sizeof(*bgph), 0, 0, DGPRS, log_pfx); |
| 289 | } |
| 290 | if (rc < 0) { |
| 291 | rate_ctr_inc(&nse->cfg->ctrg->ctr[GBPROX_GLOB_CTR_PROTO_ERR_BSS]); |
| 292 | return tx_status_from_tlvp(rc, msg); |
| 293 | } |
Jacob Erlbeck | 43b8f9f | 2014-10-02 14:56:44 +0200 | [diff] [blame] | 294 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 295 | switch (bgph->pdu_type) { |
| 296 | case BSSGP_PDUT_UL_UNITDATA: |
| 297 | case BSSGP_PDUT_RA_CAPA_UPDATE: |
| 298 | case BSSGP_PDUT_FLOW_CONTROL_MS: |
| 299 | case BSSGP_PDUT_DOWNLOAD_BSS_PFC: |
| 300 | case BSSGP_PDUT_CREATE_BSS_PFC_ACK: |
| 301 | case BSSGP_PDUT_CREATE_BSS_PFC_NACK: |
| 302 | case BSSGP_PDUT_MODIFY_BSS_PFC_ACK: |
| 303 | case BSSGP_PDUT_DELETE_BSS_PFC_ACK: |
| 304 | case BSSGP_PDUT_FLOW_CONTROL_PFC: |
| 305 | case BSSGP_PDUT_DELETE_BSS_PFC_REQ: |
| 306 | case BSSGP_PDUT_PS_HO_REQUIRED: |
| 307 | case BSSGP_PDUT_PS_HO_REQUEST_ACK: |
| 308 | case BSSGP_PDUT_PS_HO_REQUEST_NACK: |
| 309 | case BSSGP_PDUT_PS_HO_COMPLETE: |
| 310 | case BSSGP_PDUT_PS_HO_CANCEL: |
| 311 | /* We can route based on TLLI-NRI */ |
| 312 | tlli = osmo_load32be(TLVP_VAL(&tp, BSSGP_IE_TLLI)); |
| 313 | rc = gbprox_bss2sgsn_tlli(bss_bvc->cell, msg, tlli, false); |
| 314 | break; |
| 315 | case BSSGP_PDUT_RADIO_STATUS: |
| 316 | if (TLVP_PRESENT(&tp, BSSGP_IE_TLLI)) { |
| 317 | tlli = osmo_load32be(TLVP_VAL(&tp, BSSGP_IE_TLLI)); |
| 318 | rc = gbprox_bss2sgsn_tlli(bss_bvc->cell, msg, tlli, false); |
| 319 | } else if (TLVP_PRESENT(&tp, BSSGP_IE_TMSI)) { |
| 320 | /* we treat the TMSI like a TLLI and extract the NRI from it */ |
| 321 | tlli = osmo_load32be(TLVP_VAL(&tp, BSSGP_IE_TMSI)); |
| 322 | rc = gbprox_bss2sgsn_tlli(bss_bvc->cell, msg, tlli, false); |
| 323 | } else if (TLVP_PRESENT(&tp, BSSGP_IE_IMSI)) { |
| 324 | rc = gbprox_bss2sgsn_null_nri(bss_bvc->cell, msg); |
| 325 | } else |
| 326 | LOGPBVC(bss_bvc, LOGL_ERROR, "Rx RADIO-STATUS without any of the conditional IEs\n"); |
| 327 | break; |
| 328 | case BSSGP_PDUT_DUMMY_PAGING_PS_RESP: |
| 329 | case BSSGP_PDUT_PAGING_PS_REJECT: |
| 330 | /* TODO: Implement via state tracking of PAGING-PS + DUMMY_PAGING_PS */ |
| 331 | LOGPBVC(bss_bvc, LOGL_ERROR, "Rx %s: Implementation missing\n", pdut_name); |
| 332 | break; |
| 333 | case BSSGP_PDUT_FLOW_CONTROL_BVC: |
| 334 | /* TODO: Implement via FSM */ |
| 335 | //rc = osmo_fsm_inst_dispatch(bss_bvc->fi, FIXME, &tp); |
| 336 | LOGPBVC(bss_bvc, LOGL_ERROR, "Rx %s: Implementation missing\n", pdut_name); |
| 337 | break; |
| 338 | case BSSGP_PDUT_STATUS: |
| 339 | /* TODO: Implement by inspecting the contained PDU */ |
| 340 | if (!TLVP_PRESENT(&tp, BSSGP_IE_PDU_IN_ERROR)) |
| 341 | break; |
| 342 | LOGPBVC(bss_bvc, LOGL_ERROR, "Rx %s: Implementation missing\n", pdut_name); |
| 343 | break; |
| 344 | } |
| 345 | |
| 346 | return 0; |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /* Receive an incoming PTP message from a SGSN-side NS-VC */ |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 350 | static int gbprox_rx_ptp_from_sgsn(struct gbproxy_nse *nse, struct msgb *msg, uint16_t ns_bvci) |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 351 | { |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 352 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 353 | const char *pdut_name = osmo_tlv_prot_msg_name(&osmo_pdef_bssgp, bgph->pdu_type); |
| 354 | struct gbproxy_bvc *sgsn_bvc, *bss_bvc; |
| 355 | char log_pfx[32]; |
| 356 | |
| 357 | snprintf(log_pfx, sizeof(log_pfx), "NSE(%05u/SGSN)-BVC(%05u/??)", nse->nsei, ns_bvci); |
| 358 | |
| 359 | LOGP(DGPRS, LOGL_DEBUG, "%s Rx %s\n", log_pfx, pdut_name); |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 360 | |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 361 | if (ns_bvci == 0 && ns_bvci == 1) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 362 | LOGP(DGPRS, LOGL_NOTICE, "%s BVCI is not PTP\n", log_pfx); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 363 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 364 | } |
| 365 | |
| 366 | if (!(bssgp_pdu_type_flags(bgph->pdu_type) & BSSGP_PDUF_PTP)) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 367 | LOGP(DGPRS, LOGL_NOTICE, "%s %s not allowed in PTP BVC\n", log_pfx, pdut_name); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 368 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 369 | } |
| 370 | |
| 371 | if (!(bssgp_pdu_type_flags(bgph->pdu_type) & BSSGP_PDUF_DL)) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 372 | LOGP(DGPRS, LOGL_NOTICE, "%s %s not allowed in downlink direction\n", log_pfx, pdut_name); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 373 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 374 | } |
| 375 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 376 | sgsn_bvc = gbproxy_bvc_by_bvci(nse, ns_bvci); |
| 377 | if (!sgsn_bvc) { |
| 378 | LOGP(DGPRS, LOGL_NOTICE, "%s %s - Didn't find BVC for for PTP message, discarding\n", |
| 379 | log_pfx, pdut_name); |
| 380 | rate_ctr_inc(&nse->cfg->ctrg-> ctr[GBPROX_GLOB_CTR_INV_BVCI]); |
| 381 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &ns_bvci, msg); |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 382 | } |
| 383 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 384 | if (!bssgp_bvc_fsm_is_unblocked(sgsn_bvc->fi)) { |
| 385 | LOGPBVC(sgsn_bvc, LOGL_NOTICE, "Rx %s: Dropping on blocked BVC\n", pdut_name); |
| 386 | rate_ctr_inc(&sgsn_bvc->ctrg->ctr[GBPROX_PEER_CTR_DROPPED]); |
Jacob Erlbeck | 17b42b8 | 2014-08-29 12:20:15 +0200 | [diff] [blame] | 387 | return bssgp_tx_status(BSSGP_CAUSE_BVCI_BLOCKED, &ns_bvci, msg); |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 388 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 389 | OSMO_ASSERT(sgsn_bvc->cell); |
| 390 | bss_bvc = sgsn_bvc->cell->bss_bvc; |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 391 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 392 | return gbprox_relay2peer(msg, bss_bvc, bss_bvc->bvci); |
Jacob Erlbeck | 46f1d6f | 2014-08-21 13:45:04 +0200 | [diff] [blame] | 393 | } |
| 394 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 395 | /*********************************************************************** |
| 396 | * BVC FSM call-backs |
| 397 | ***********************************************************************/ |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 398 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 399 | /* helper function to dispatch a FSM event to all SGSN-side BVC FSMs of a cell */ |
| 400 | static void dispatch_to_all_sgsn_bvc(struct gbproxy_cell *cell, uint32_t event, void *priv) |
| 401 | { |
| 402 | unsigned int i; |
| 403 | |
| 404 | for (i = 0; i < ARRAY_SIZE(cell->sgsn_bvc); i++) { |
| 405 | struct gbproxy_bvc *sgsn_bvc = cell->sgsn_bvc[i]; |
| 406 | if (!sgsn_bvc) |
| 407 | continue; |
| 408 | osmo_fsm_inst_dispatch(sgsn_bvc->fi, event, priv); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | /* BVC FSM informs us about a BSS-side reset of the signaling BVC */ |
| 413 | static void bss_sig_bvc_reset_notif(uint16_t nsei, uint16_t bvci, const struct gprs_ra_id *ra_id, |
| 414 | uint16_t cell_id, uint8_t cause, void *priv) |
| 415 | { |
| 416 | struct gbproxy_bvc *sig_bvc = priv; |
| 417 | struct gbproxy_nse *nse = sig_bvc->nse; |
| 418 | struct gbproxy_bvc *ptp_bvc; |
| 419 | unsigned int i; |
| 420 | |
| 421 | /* BLOCK all SGSN-side PTP BVC within this NSE */ |
| 422 | hash_for_each(nse->bvcs, i, ptp_bvc, list) { |
| 423 | if (ptp_bvc == sig_bvc) |
| 424 | continue; |
| 425 | OSMO_ASSERT(ptp_bvc->cell); |
| 426 | |
| 427 | dispatch_to_all_sgsn_bvc(ptp_bvc->cell, BSSGP_BVCFSM_E_REQ_BLOCK, &cause); |
Harald Welte | fb7f8c5 | 2020-12-02 23:29:38 +0100 | [diff] [blame] | 428 | } |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 429 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 430 | /* Delete all BSS-side PTP BVC within this NSE */ |
| 431 | gbproxy_cleanup_bvcs(nse, 0); |
| 432 | |
| 433 | /* TODO: we keep the "CELL" around for now, re-connecting it to |
| 434 | * any (later) new PTP-BVC for that BVCI. Not sure if that's the |
| 435 | * best idea ? */ |
| 436 | } |
| 437 | |
| 438 | /* forward declaration */ |
| 439 | static const struct bssgp_bvc_fsm_ops sgsn_ptp_bvc_fsm_ops; |
| 440 | |
| 441 | static const struct bssgp_bvc_fsm_ops bss_sig_bvc_fsm_ops = { |
| 442 | .reset_notification = bss_sig_bvc_reset_notif, |
| 443 | }; |
| 444 | |
| 445 | /* BVC FSM informs us about a BSS-side reset of a PTP BVC */ |
| 446 | static void bss_ptp_bvc_reset_notif(uint16_t nsei, uint16_t bvci, const struct gprs_ra_id *ra_id, |
| 447 | uint16_t cell_id, uint8_t cause, void *priv) |
| 448 | { |
| 449 | struct gbproxy_bvc *bvc = priv; |
| 450 | struct gbproxy_config *cfg = bvc->nse->cfg; |
| 451 | unsigned int i; |
| 452 | |
| 453 | OSMO_ASSERT(bvci != 0); |
| 454 | |
| 455 | if (!bvc->cell) { |
| 456 | /* see if we have a CELL dangling around */ |
| 457 | bvc->cell = gbproxy_cell_by_bvci(cfg, bvci); |
| 458 | if (bvc->cell) { |
| 459 | /* the CELL already exists. This means either it * was created before at an |
| 460 | * earlier PTP BVC-RESET, or that there are non-unique BVCIs and hence a |
| 461 | * malconfiguration */ |
| 462 | if (bvc->cell->bss_bvc) { |
| 463 | LOGPBVC(bvc, LOGL_NOTICE, "Rx BVC-RESET via this NSE, but CELL already " |
| 464 | "has BVC on NSEI=%05u\n", bvc->cell->bss_bvc->nse->nsei); |
| 465 | LOGPBVC(bvc->cell->bss_bvc, LOGL_NOTICE, "Destroying due to conflicting " |
| 466 | "BVCI configuration (new NSEI=%05u)!\n", bvc->nse->nsei); |
| 467 | gbproxy_bvc_free(bvc->cell->bss_bvc); |
| 468 | } |
| 469 | bvc->cell->bss_bvc = bvc; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | if (!bvc->cell) { |
| 474 | struct gbproxy_nse *sgsn_nse; |
| 475 | /* if we end up here, it means this is the first time we received a BVC-RESET |
| 476 | * for this BVC. We need to create the 'cell' data structure and the SGSN-side |
| 477 | * BVC counterparts */ |
| 478 | |
| 479 | bvc->cell = gbproxy_cell_alloc(cfg, bvci); |
| 480 | OSMO_ASSERT(bvc->cell); |
| 481 | |
| 482 | /* link us to the cell and vice-versa */ |
| 483 | bvc->cell->bss_bvc = bvc; |
| 484 | |
| 485 | /* allocate the SGSN-side BVCs within the cell, and reset them */ |
| 486 | hash_for_each(cfg->sgsn_nses, i, sgsn_nse, list) { |
| 487 | struct gbproxy_bvc *sgsn_bvc = gbproxy_bvc_by_bvci(sgsn_nse, bvci); |
| 488 | if (sgsn_bvc) |
| 489 | OSMO_ASSERT(!sgsn_bvc->cell); |
| 490 | |
| 491 | if (!sgsn_bvc) { |
| 492 | sgsn_bvc = gbproxy_bvc_alloc(sgsn_nse, bvci); |
| 493 | OSMO_ASSERT(sgsn_bvc); |
| 494 | |
| 495 | sgsn_bvc->cell = bvc->cell; |
| 496 | sgsn_bvc->fi = bssgp_bvc_fsm_alloc_ptp_bss(sgsn_bvc, cfg->nsi, sgsn_nse->nsei, |
| 497 | bvci, ra_id, cell_id); |
| 498 | OSMO_ASSERT(sgsn_bvc->fi); |
| 499 | bssgp_bvc_fsm_set_ops(sgsn_bvc->fi, &sgsn_ptp_bvc_fsm_ops, sgsn_bvc); |
| 500 | |
| 501 | gbproxy_cell_add_sgsn_bvc(bvc->cell, sgsn_bvc); |
| 502 | } else { |
| 503 | OSMO_ASSERT(sgsn_bvc->cell == bvc->cell); |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | /* Trigger outbound BVC-RESET procedure toward each SGSN */ |
| 509 | dispatch_to_all_sgsn_bvc(bvc->cell, BSSGP_BVCFSM_E_REQ_RESET, &cause); |
| 510 | } |
| 511 | |
| 512 | /* BVC FSM informs us about a BSS-side FSM state change */ |
| 513 | static void bss_ptp_bvc_state_chg_notif(uint16_t nsei, uint16_t bvci, int old_state, int state, void *priv) |
| 514 | { |
| 515 | struct gbproxy_bvc *bvc = priv; |
| 516 | struct gbproxy_cell *cell = bvc->cell; |
| 517 | uint8_t cause = bssgp_bvc_fsm_get_block_cause(bvc->fi); |
| 518 | |
| 519 | /* we have just been created but due to callback ordering the cell is not associated */ |
| 520 | if (!cell) |
| 521 | return; |
| 522 | |
| 523 | switch (state) { |
| 524 | case BSSGP_BVCFSM_S_BLOCKED: |
| 525 | /* block the corresponding SGSN-side PTP BVCs */ |
| 526 | dispatch_to_all_sgsn_bvc(cell, BSSGP_BVCFSM_E_REQ_BLOCK, &cause); |
| 527 | break; |
| 528 | case BSSGP_BVCFSM_S_UNBLOCKED: |
| 529 | /* unblock the corresponding SGSN-side PTP BVCs */ |
| 530 | dispatch_to_all_sgsn_bvc(cell, BSSGP_BVCFSM_E_REQ_UNBLOCK, NULL); |
| 531 | break; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | static const struct bssgp_bvc_fsm_ops bss_ptp_bvc_fsm_ops = { |
| 536 | .reset_notification = bss_ptp_bvc_reset_notif, |
| 537 | .state_chg_notification = bss_ptp_bvc_state_chg_notif, |
| 538 | }; |
| 539 | |
| 540 | /* BVC FSM informs us about a SGSN-side reset of a PTP BVC */ |
| 541 | static void sgsn_ptp_bvc_reset_notif(uint16_t nsei, uint16_t bvci, const struct gprs_ra_id *ra_id, |
| 542 | uint16_t cell_id, uint8_t cause, void *priv) |
| 543 | { |
| 544 | struct gbproxy_bvc *bvc = priv; |
| 545 | |
| 546 | if (!bvc->cell) { |
| 547 | LOGPBVC(bvc, LOGL_ERROR, "RESET of PTP BVC on SGSN side for which we have no BSS?\n"); |
| 548 | return; |
| 549 | } |
| 550 | |
| 551 | OSMO_ASSERT(bvc->cell->bss_bvc); |
| 552 | |
| 553 | /* request reset of BSS-facing PTP-BVC */ |
| 554 | osmo_fsm_inst_dispatch(bvc->cell->bss_bvc->fi, BSSGP_BVCFSM_E_REQ_RESET, &cause); |
| 555 | } |
| 556 | |
| 557 | static const struct bssgp_bvc_fsm_ops sgsn_ptp_bvc_fsm_ops = { |
| 558 | .reset_notification = sgsn_ptp_bvc_reset_notif, |
| 559 | }; |
| 560 | |
| 561 | /* BVC FSM informs us about a SGSN-side reset of the signaling BVC */ |
| 562 | static void sgsn_sig_bvc_reset_notif(uint16_t nsei, uint16_t bvci, const struct gprs_ra_id *ra_id, |
| 563 | uint16_t cell_id, uint8_t cause, void *priv) |
| 564 | { |
| 565 | struct gbproxy_bvc *bvc = priv; |
| 566 | struct gbproxy_config *cfg = bvc->nse->cfg; |
| 567 | struct gbproxy_nse *bss_nse; |
| 568 | unsigned int i; |
| 569 | |
| 570 | /* delete all SGSN-side PTP BVC for this SGSN */ |
| 571 | gbproxy_cleanup_bvcs(bvc->nse, 0); |
| 572 | /* FIXME: what to do about the cells? */ |
| 573 | /* FIXME: do we really want to RESET all signaling BVC on the BSS and affect all other SGSN? */ |
| 574 | |
| 575 | /* we need to trigger generating a reset procedure towards each BSS side signaling BVC */ |
| 576 | hash_for_each(cfg->bss_nses, i, bss_nse, list) { |
| 577 | struct gbproxy_bvc *bss_bvc = gbproxy_bvc_by_bvci(bss_nse, 0); |
| 578 | if (!bss_bvc) { |
| 579 | LOGPNSE(bss_nse, LOGL_ERROR, "Doesn't have BVC with BVCI=0 ?!?\n"); |
| 580 | continue; |
| 581 | } |
| 582 | osmo_fsm_inst_dispatch(bss_bvc->fi, BSSGP_BVCFSM_E_REQ_RESET, &cause); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | const struct bssgp_bvc_fsm_ops sgsn_sig_bvc_fsm_ops = { |
| 587 | .reset_notification = sgsn_sig_bvc_reset_notif, |
| 588 | }; |
| 589 | |
| 590 | /*********************************************************************** |
| 591 | * Signaling BVC handling |
| 592 | ***********************************************************************/ |
| 593 | |
| 594 | /* process a BVC-RESET message from the BSS side */ |
| 595 | static int rx_bvc_reset_from_bss(struct gbproxy_nse *nse, struct msgb *msg, struct tlv_parsed *tp) |
| 596 | { |
| 597 | struct gbproxy_bvc *from_bvc = NULL; |
| 598 | uint16_t bvci = ntohs(tlvp_val16_unal(tp, BSSGP_IE_BVCI)); |
| 599 | uint32_t features = 0; // FIXME: make configurable |
| 600 | |
| 601 | LOGPNSE(nse, LOGL_INFO, "Rx BVC-RESET (BVCI=%05u)\n", bvci); |
| 602 | |
Harald Welte | 1239cf4 | 2020-12-02 23:03:22 +0100 | [diff] [blame] | 603 | if (bvci == 0) { |
| 604 | /* If we receive a BVC reset on the signalling endpoint, we |
| 605 | * don't want the SGSN to reset, as the signalling endpoint |
| 606 | * is common for all point-to-point BVCs (and thus all BTS) */ |
Harald Welte | 5525371 | 2020-12-02 23:06:37 +0100 | [diff] [blame] | 607 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 608 | from_bvc = gbproxy_bvc_by_bvci(nse, 0); |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 609 | if (!from_bvc) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 610 | from_bvc = gbproxy_bvc_alloc(nse, 0); |
| 611 | OSMO_ASSERT(from_bvc); |
| 612 | from_bvc->fi = bssgp_bvc_fsm_alloc_sig_sgsn(from_bvc, nse->cfg->nsi, nse->nsei, features); |
| 613 | if (!from_bvc->fi) { |
| 614 | LOGPNSE(nse, LOGL_ERROR, "Cannot allocate SIG-BVC FSM\n"); |
| 615 | gbproxy_bvc_free(from_bvc); |
| 616 | return -ENOMEM; |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 617 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 618 | bssgp_bvc_fsm_set_ops(from_bvc->fi, &bss_sig_bvc_fsm_ops, from_bvc); |
| 619 | } |
| 620 | } else { |
| 621 | from_bvc = gbproxy_bvc_by_bvci(nse, bvci); |
| 622 | if (!from_bvc) { |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 623 | /* if a PTP-BVC is reset, and we don't know that |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 624 | * PTP-BVCI yet, we should allocate a new bvc */ |
| 625 | from_bvc = gbproxy_bvc_alloc(nse, bvci); |
| 626 | OSMO_ASSERT(from_bvc); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 627 | from_bvc->fi = bssgp_bvc_fsm_alloc_ptp_sgsn(from_bvc, nse->cfg->nsi, |
| 628 | nse->nsei, bvci); |
| 629 | if (!from_bvc->fi) { |
| 630 | LOGPNSE(nse, LOGL_ERROR, "Cannot allocate SIG-BVC FSM\n"); |
| 631 | gbproxy_bvc_free(from_bvc); |
| 632 | return -ENOMEM; |
| 633 | } |
| 634 | bssgp_bvc_fsm_set_ops(from_bvc->fi, &bss_ptp_bvc_fsm_ops, from_bvc); |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 635 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 636 | #if 0 |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 637 | /* Could have moved to a different NSE */ |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 638 | if (!check_bvc_nsei(from_bvc, nsei)) { |
| 639 | LOGPBVC(from_bvc, LOGL_NOTICE, "moving bvc to NSE(%05u)\n", nsei); |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 640 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 641 | struct gbproxy_nse *nse_new = gbproxy_nse_by_nsei(cfg, nsei, false); |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 642 | if (!nse_new) { |
| 643 | LOGP(DGPRS, LOGL_NOTICE, "NSE(%05u) Got PtP BVC reset before signalling reset for " |
| 644 | "BVCI=%05u\n", bvci, nsei); |
| 645 | bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_STATE, NULL, msg); |
| 646 | return 0; |
| 647 | } |
| 648 | |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 649 | /* Move bvc to different NSE */ |
| 650 | gbproxy_bvc_move(from_bvc, nse_new); |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 651 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 652 | #endif |
| 653 | /* FIXME: do we need this, if it happens within FSM? */ |
Harald Welte | 6c4c6f0 | 2020-12-03 15:36:59 +0100 | [diff] [blame] | 654 | if (TLVP_PRES_LEN(tp, BSSGP_IE_CELL_ID, 8)) { |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 655 | struct gprs_ra_id raid; |
| 656 | /* We have a Cell Identifier present in this |
| 657 | * PDU, this means we can extend our local |
| 658 | * state information about this particular cell |
| 659 | * */ |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 660 | memcpy(from_bvc->ra, TLVP_VAL(tp, BSSGP_IE_CELL_ID), sizeof(from_bvc->ra)); |
| 661 | gsm48_parse_ra(&raid, from_bvc->ra); |
| 662 | LOGPBVC(from_bvc, LOGL_INFO, "Cell ID %s\n", osmo_rai_name(&raid)); |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 663 | } |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 664 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 665 | /* hand into FSM for further processing */ |
| 666 | osmo_fsm_inst_dispatch(from_bvc->fi, BSSGP_BVCFSM_E_RX_RESET, msg); |
| 667 | return 0; |
Harald Welte | ac44d6b | 2020-12-02 22:53:26 +0100 | [diff] [blame] | 668 | } |
| 669 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 670 | /* Receive an incoming signalling message from a BSS-side NS-VC */ |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 671 | static int gbprox_rx_sig_from_bss(struct gbproxy_nse *nse, struct msgb *msg, uint16_t ns_bvci) |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 672 | { |
Harald Welte | ca3620a | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 673 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 674 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 675 | const char *pdut_name = osmo_tlv_prot_msg_name(&osmo_pdef_bssgp, bgph->pdu_type); |
| 676 | struct tlv_parsed tp; |
Harald Welte | ca3620a | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 677 | int data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 678 | struct gbproxy_bvc *from_bvc = NULL; |
Harald Welte | 052d855 | 2020-12-06 16:32:01 +0100 | [diff] [blame] | 679 | char log_pfx[32]; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 680 | uint16_t ptp_bvci; |
| 681 | uint32_t tlli; |
Jacob Erlbeck | 5930064 | 2014-09-08 09:04:01 +0200 | [diff] [blame] | 682 | int rc; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 683 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 684 | snprintf(log_pfx, sizeof(log_pfx), "NSE(%05u/BSS)-BVC(%05u/??)", nse->nsei, ns_bvci); |
| 685 | |
| 686 | LOGP(DGPRS, LOGL_DEBUG, "%s Rx %s\n", log_pfx, pdut_name); |
Harald Welte | 052d855 | 2020-12-06 16:32:01 +0100 | [diff] [blame] | 687 | |
Harald Welte | c471d3d | 2011-02-06 17:13:12 +0100 | [diff] [blame] | 688 | if (ns_bvci != 0 && ns_bvci != 1) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 689 | LOGP(DGPRS, LOGL_NOTICE, "%s %s BVCI=%05u is not signalling\n", log_pfx, pdut_name, ns_bvci); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 690 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 691 | } |
| 692 | |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 693 | if (!(bssgp_pdu_type_flags(pdu_type) & BSSGP_PDUF_SIG)) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 694 | LOGP(DGPRS, LOGL_NOTICE, "%s %s not allowed in signalling BVC\n", log_pfx, pdut_name); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 695 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 696 | } |
| 697 | |
| 698 | if (!(bssgp_pdu_type_flags(pdu_type) & BSSGP_PDUF_UL)) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 699 | LOGP(DGPRS, LOGL_NOTICE, "%s %s not allowed in uplink direction\n", log_pfx, pdut_name); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 700 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 701 | } |
| 702 | |
Harald Welte | 052d855 | 2020-12-06 16:32:01 +0100 | [diff] [blame] | 703 | rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, &tp, 1, pdu_type, bgph->data, data_len, 0, 0, |
| 704 | DGPRS, log_pfx); |
| 705 | if (rc < 0) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 706 | rate_ctr_inc(&nse->cfg->ctrg->ctr[GBPROX_GLOB_CTR_PROTO_ERR_BSS]); |
Harald Welte | 052d855 | 2020-12-06 16:32:01 +0100 | [diff] [blame] | 707 | return tx_status_from_tlvp(rc, msg); |
| 708 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 709 | /* hack to get both msg + tlv_parsed passed via osmo_fsm_inst_dispatch */ |
| 710 | msgb_bcid(msg) = (void *)&tp; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 711 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 712 | /* special case handling for some PDU types */ |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 713 | switch (pdu_type) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 714 | case BSSGP_PDUT_BVC_RESET: |
| 715 | /* resolve or create gbproxy_bvc + handlei n BVC-FSM */ |
| 716 | ptp_bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
| 717 | return rx_bvc_reset_from_bss(nse, msg, &tp); |
| 718 | case BSSGP_PDUT_BVC_RESET_ACK: |
| 719 | ptp_bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
| 720 | from_bvc = gbproxy_bvc_by_bvci(nse, ptp_bvci); |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 721 | if (!from_bvc) |
| 722 | goto err_no_bvc; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 723 | return osmo_fsm_inst_dispatch(from_bvc->fi, BSSGP_BVCFSM_E_RX_RESET_ACK, msg); |
| 724 | case BSSGP_PDUT_BVC_BLOCK: |
| 725 | ptp_bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
| 726 | from_bvc = gbproxy_bvc_by_bvci(nse, ptp_bvci); |
| 727 | if (!from_bvc) |
| 728 | goto err_no_bvc; |
| 729 | return osmo_fsm_inst_dispatch(from_bvc->fi, BSSGP_BVCFSM_E_RX_BLOCK, msg); |
| 730 | case BSSGP_PDUT_BVC_UNBLOCK: |
| 731 | ptp_bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
| 732 | from_bvc = gbproxy_bvc_by_bvci(nse, ptp_bvci); |
| 733 | if (!from_bvc) |
| 734 | goto err_no_bvc; |
| 735 | return osmo_fsm_inst_dispatch(from_bvc->fi, BSSGP_BVCFSM_E_RX_UNBLOCK, msg); |
| 736 | case BSSGP_PDUT_SUSPEND: |
| 737 | case BSSGP_PDUT_RESUME: |
| 738 | /* FIXME: Implement TLLI Cache. Every SUSPEND/RESUME we must |
| 739 | * take record of the TLLI->BVC mapping so we can map |
| 740 | * back from TLLI->BVC when the SUSPEND/RESUME-ACK |
| 741 | * arrives. Cache should have a timeout of 1-3 seconds |
| 742 | * and the ACK should explicitly delete entries. */ |
| 743 | #if 0 |
| 744 | /* TODO: Validate the RAI for consistency with the RAI |
| 745 | * we expect for any of the BVC within this BSS side NSE */ |
| 746 | memcpy(ra, TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA), sizeof(from_bvc->ra)); |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 747 | gsm48_parse_ra(&raid, from_bvc->ra); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 748 | #endif |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 749 | break; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 750 | case BSSGP_PDUT_STATUS: |
| 751 | /* FIXME: inspect the erroneous PDU IE (if any) and check |
| 752 | * if we can extract a TLLI/RNI to route it to the correct SGSN */ |
| 753 | break; |
| 754 | case BSSGP_PDUT_RAN_INFO: |
| 755 | case BSSGP_PDUT_RAN_INFO_REQ: |
| 756 | case BSSGP_PDUT_RAN_INFO_ACK: |
| 757 | case BSSGP_PDUT_RAN_INFO_ERROR: |
| 758 | case BSSGP_PDUT_RAN_INFO_APP_ERROR: |
| 759 | /* FIXME: route based in RIM Routing IE */ |
| 760 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
| 761 | break; |
| 762 | case BSSGP_PDUT_LLC_DISCARD: |
| 763 | case BSSGP_PDUT_FLUSH_LL_ACK: |
| 764 | /* route based on BVCI + TLLI */ |
| 765 | ptp_bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
| 766 | tlli = osmo_load32be(TLVP_VAL(&tp, BSSGP_IE_TLLI)); |
| 767 | from_bvc = gbproxy_bvc_by_bvci(nse, ptp_bvci); |
| 768 | if (!from_bvc) |
| 769 | goto err_no_bvc; |
| 770 | gbprox_bss2sgsn_tlli(from_bvc->cell, msg, tlli, true); |
| 771 | break; |
| 772 | default: |
| 773 | LOGPNSE(nse, LOGL_ERROR, "Rx %s: Implementation missing\n", pdut_name); |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 774 | break; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 775 | } |
| 776 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 777 | return rc; |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 778 | err_no_bvc: |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 779 | LOGPNSE(nse, LOGL_ERROR, "Rx %s: cannot find BVC for BVCI=%05u\n", pdut_name, ptp_bvci); |
| 780 | rate_ctr_inc(&nse->cfg->ctrg->ctr[GBPROX_GLOB_CTR_INV_NSEI]); |
Jacob Erlbeck | 17b42b8 | 2014-08-29 12:20:15 +0200 | [diff] [blame] | 781 | return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /* Receive paging request from SGSN, we need to relay to proper BSS */ |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 785 | static int gbprox_rx_paging(struct gbproxy_nse *nse, struct msgb *msg, const char *pdut_name, |
| 786 | struct tlv_parsed *tp, uint16_t ns_bvci) |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 787 | { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 788 | struct gbproxy_config *cfg = nse->cfg; |
| 789 | struct gbproxy_bvc *sgsn_bvc, *bss_bvc; |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 790 | unsigned int n_nses = 0; |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 791 | int errctr = GBPROX_GLOB_CTR_PROTO_ERR_SGSN; |
Harald Welte | 993d3f4 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 792 | int i, j; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 793 | |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 794 | /* FIXME: Handle paging logic to only page each matching NSE */ |
| 795 | |
Harald Welte | 6c4c6f0 | 2020-12-03 15:36:59 +0100 | [diff] [blame] | 796 | if (TLVP_PRES_LEN(tp, BSSGP_IE_BVCI, 2)) { |
Holger Hans Peter Freyther | ffd6856 | 2012-09-04 20:42:20 +0200 | [diff] [blame] | 797 | uint16_t bvci = ntohs(tlvp_val16_unal(tp, BSSGP_IE_BVCI)); |
Jacob Erlbeck | bc55574 | 2013-10-18 14:34:55 +0200 | [diff] [blame] | 798 | errctr = GBPROX_GLOB_CTR_OTHER_ERR; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 799 | sgsn_bvc = gbproxy_bvc_by_bvci(nse, bvci); |
| 800 | if (!sgsn_bvc) { |
| 801 | LOGPNSE(nse, LOGL_NOTICE, "Rx %s: unable to route: BVCI=%05u unknown\n", |
| 802 | pdut_name, bvci); |
Harald Welte | 3375fa4 | 2020-11-23 15:14:20 +0100 | [diff] [blame] | 803 | rate_ctr_inc(&cfg->ctrg->ctr[errctr]); |
| 804 | return -EINVAL; |
| 805 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 806 | LOGPBVC(sgsn_bvc, LOGL_INFO, "Rx %s: routing by BVCI\n", pdut_name); |
| 807 | return gbprox_relay2peer(msg, sgsn_bvc->cell->bss_bvc, ns_bvci); |
Harald Welte | 6c4c6f0 | 2020-12-03 15:36:59 +0100 | [diff] [blame] | 808 | } else if (TLVP_PRES_LEN(tp, BSSGP_IE_ROUTEING_AREA, 6)) { |
Jacob Erlbeck | 8f50359 | 2014-06-02 10:49:00 +0200 | [diff] [blame] | 809 | errctr = GBPROX_GLOB_CTR_INV_RAI; |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 810 | /* iterate over all bvcs and dispatch the paging to each matching one */ |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 811 | hash_for_each(cfg->bss_nses, i, nse, list) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 812 | hash_for_each(nse->bvcs, j, bss_bvc, list) { |
| 813 | if (!memcmp(bss_bvc->ra, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA), 6)) { |
| 814 | LOGPNSE(nse, LOGL_INFO, "Rx %s: routing to NSE (RAI match)\n", |
| 815 | pdut_name); |
| 816 | gbprox_relay2peer(msg, bss_bvc, ns_bvci); |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 817 | n_nses++; |
| 818 | /* Only send it once to each NSE */ |
| 819 | break; |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 820 | } |
Harald Welte | 3375fa4 | 2020-11-23 15:14:20 +0100 | [diff] [blame] | 821 | } |
| 822 | } |
Harald Welte | 6c4c6f0 | 2020-12-03 15:36:59 +0100 | [diff] [blame] | 823 | } else if (TLVP_PRES_LEN(tp, BSSGP_IE_LOCATION_AREA, 5)) { |
Jacob Erlbeck | 8f50359 | 2014-06-02 10:49:00 +0200 | [diff] [blame] | 824 | errctr = GBPROX_GLOB_CTR_INV_LAI; |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 825 | /* iterate over all bvcs and dispatch the paging to each matching one */ |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 826 | hash_for_each(cfg->bss_nses, i, nse, list) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 827 | hash_for_each(nse->bvcs, j, bss_bvc, list) { |
| 828 | if (!memcmp(bss_bvc->ra, TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA), 5)) { |
| 829 | LOGPNSE(nse, LOGL_INFO, "Rx %s: routing to NSE (LAI match)\n", |
| 830 | pdut_name); |
| 831 | gbprox_relay2peer(msg, bss_bvc, ns_bvci); |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 832 | n_nses++; |
| 833 | /* Only send it once to each NSE */ |
| 834 | break; |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 835 | } |
Harald Welte | 3375fa4 | 2020-11-23 15:14:20 +0100 | [diff] [blame] | 836 | } |
| 837 | } |
Harald Welte | 6c4c6f0 | 2020-12-03 15:36:59 +0100 | [diff] [blame] | 838 | } else if (TLVP_PRES_LEN(tp, BSSGP_IE_BSS_AREA_ID, 1)) { |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 839 | /* iterate over all bvcs and dispatch the paging to each matching one */ |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 840 | hash_for_each(cfg->bss_nses, i, nse, list) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 841 | hash_for_each(nse->bvcs, j, bss_bvc, list) { |
| 842 | LOGPNSE(nse, LOGL_INFO, "Rx %s:routing to NSE (broadcast)\n", pdut_name); |
| 843 | gbprox_relay2peer(msg, bss_bvc, ns_bvci); |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 844 | n_nses++; |
| 845 | /* Only send it once to each NSE */ |
| 846 | break; |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 847 | } |
Harald Welte | 8553f55 | 2020-11-24 11:31:13 +0100 | [diff] [blame] | 848 | } |
| 849 | } else { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 850 | LOGPNSE(nse, LOGL_ERROR, "BSSGP PAGING: unable to route, missing IE\n"); |
Harald Welte | 8553f55 | 2020-11-24 11:31:13 +0100 | [diff] [blame] | 851 | rate_ctr_inc(&cfg->ctrg->ctr[errctr]); |
| 852 | } |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 853 | |
Daniel Willmann | 5937dfd | 2020-11-30 17:08:58 +0100 | [diff] [blame] | 854 | if (n_nses == 0) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 855 | LOGPNSE(nse, LOGL_ERROR, "BSSGP PAGING: unable to route, no destination found\n"); |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 856 | rate_ctr_inc(&cfg->ctrg->ctr[errctr]); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 857 | return -EINVAL; |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 858 | } |
Harald Welte | 3375fa4 | 2020-11-23 15:14:20 +0100 | [diff] [blame] | 859 | return 0; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 860 | } |
| 861 | |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 862 | /* Receive an incoming BVC-RESET message from the SGSN */ |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 863 | static int rx_bvc_reset_from_sgsn(struct gbproxy_nse *nse, struct msgb *msg, struct tlv_parsed *tp, |
| 864 | uint16_t ns_bvci) |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 865 | { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 866 | uint16_t ptp_bvci = ntohs(tlvp_val16_unal(tp, BSSGP_IE_BVCI)); |
| 867 | struct gbproxy_bvc *from_bvc; |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 868 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 869 | LOGPNSE(nse, LOGL_INFO, "Rx BVC-RESET (BVCI=%05u)\n", ptp_bvci); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 870 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 871 | if (ptp_bvci == 0) { |
| 872 | from_bvc = gbproxy_bvc_by_bvci(nse, 0); |
| 873 | OSMO_ASSERT(from_bvc); |
| 874 | osmo_fsm_inst_dispatch(from_bvc->fi, BSSGP_BVCFSM_E_RX_RESET, msg); |
| 875 | } else { |
| 876 | from_bvc = gbproxy_bvc_by_bvci(nse, ptp_bvci); |
| 877 | if (!from_bvc) { |
| 878 | LOGPNSE(nse, LOGL_ERROR, "Rx BVC-RESET BVCI=%05u: Cannot find BVC\n", ptp_bvci); |
| 879 | rate_ctr_inc(&nse->cfg->ctrg->ctr[GBPROX_GLOB_CTR_INV_BVCI]); |
| 880 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &ptp_bvci, msg); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 881 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 882 | osmo_fsm_inst_dispatch(from_bvc->fi, BSSGP_BVCFSM_E_RX_RESET, msg); |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 883 | } |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 884 | |
| 885 | return 0; |
| 886 | } |
| 887 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 888 | /* Receive an incoming signalling message from the SGSN-side NS-VC */ |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 889 | static int gbprox_rx_sig_from_sgsn(struct gbproxy_nse *nse, struct msgb *orig_msg, uint16_t ns_bvci) |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 890 | { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 891 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(orig_msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 892 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 893 | const char *pdut_name = osmo_tlv_prot_msg_name(&osmo_pdef_bssgp, bgph->pdu_type); |
| 894 | struct gbproxy_config *cfg = nse->cfg; |
| 895 | struct gbproxy_bvc *sgsn_bvc; |
| 896 | struct tlv_parsed tp; |
Jacob Erlbeck | 4b663ac | 2014-08-21 15:07:11 +0200 | [diff] [blame] | 897 | int data_len; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 898 | uint16_t bvci; |
Jacob Erlbeck | 4b663ac | 2014-08-21 15:07:11 +0200 | [diff] [blame] | 899 | struct msgb *msg; |
Harald Welte | 052d855 | 2020-12-06 16:32:01 +0100 | [diff] [blame] | 900 | char log_pfx[32]; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 901 | int rc = 0; |
Jacob Erlbeck | 1e65b0e | 2014-08-29 13:32:17 +0200 | [diff] [blame] | 902 | int cause; |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 903 | int i; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 904 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 905 | snprintf(log_pfx, sizeof(log_pfx), "NSE(%05u/SGSN)-BVC(%05u/??)", nse->nsei, ns_bvci); |
| 906 | |
| 907 | LOGP(DGPRS, LOGL_DEBUG, "%s Rx %s\n", log_pfx, pdut_name); |
Harald Welte | 052d855 | 2020-12-06 16:32:01 +0100 | [diff] [blame] | 908 | |
Harald Welte | c471d3d | 2011-02-06 17:13:12 +0100 | [diff] [blame] | 909 | if (ns_bvci != 0 && ns_bvci != 1) { |
Harald Welte | 052d855 | 2020-12-06 16:32:01 +0100 | [diff] [blame] | 910 | LOGP(DGPRS, LOGL_NOTICE, "%s BVCI=%05u is not signalling\n", log_pfx, ns_bvci); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 911 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, orig_msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 912 | } |
| 913 | |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 914 | if (!(bssgp_pdu_type_flags(pdu_type) & BSSGP_PDUF_SIG)) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 915 | LOGP(DGPRS, LOGL_NOTICE, "%s %s not allowed in signalling BVC\n", log_pfx, pdut_name); |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 916 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, orig_msg); |
| 917 | } |
| 918 | |
| 919 | if (!(bssgp_pdu_type_flags(pdu_type) & BSSGP_PDUF_DL)) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 920 | LOGP(DGPRS, LOGL_NOTICE, "%s %s not allowed in downlink direction\n", log_pfx, pdut_name); |
Jacob Erlbeck | 4b663ac | 2014-08-21 15:07:11 +0200 | [diff] [blame] | 921 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, orig_msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 922 | } |
| 923 | |
Pau Espin Pedrol | 816a67d | 2018-08-15 13:53:48 +0200 | [diff] [blame] | 924 | msg = bssgp_msgb_copy(orig_msg, "rx_sig_from_sgsn"); |
Jacob Erlbeck | 4b663ac | 2014-08-21 15:07:11 +0200 | [diff] [blame] | 925 | /* Update message info */ |
| 926 | bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 927 | data_len = msgb_bssgp_len(orig_msg) - sizeof(*bgph); |
Harald Welte | 052d855 | 2020-12-06 16:32:01 +0100 | [diff] [blame] | 928 | |
| 929 | rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, &tp, 1, pdu_type, bgph->data, data_len, 0, 0, |
| 930 | DGPRS, log_pfx); |
| 931 | if (rc < 0) { |
| 932 | rc = tx_status_from_tlvp(rc, msg); |
| 933 | msgb_free(msg); |
| 934 | rate_ctr_inc(&cfg->ctrg->ctr[GBPROX_GLOB_CTR_PROTO_ERR_SGSN]); |
| 935 | return rc; |
| 936 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 937 | /* hack to get both msg + tlv_parsed passed via osmo_fsm_inst_dispatch */ |
| 938 | msgb_bcid(msg) = (void *)&tp; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 939 | |
| 940 | switch (pdu_type) { |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 941 | case BSSGP_PDUT_BVC_RESET: |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 942 | /* resolve or create ggbproxy_bvc + handle in BVC-FSM */ |
| 943 | bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
| 944 | rc = rx_bvc_reset_from_sgsn(nse, msg, &tp, ns_bvci); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 945 | break; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 946 | case BSSGP_PDUT_BVC_RESET_ACK: |
Daniel Willmann | 15c9da2 | 2020-11-03 21:12:42 +0100 | [diff] [blame] | 947 | bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 948 | sgsn_bvc = gbproxy_bvc_by_bvci(nse, bvci); |
| 949 | if (!sgsn_bvc) |
| 950 | goto err_no_bvc; |
| 951 | rc = osmo_fsm_inst_dispatch(sgsn_bvc->fi, BSSGP_BVCFSM_E_RX_RESET_ACK, msg); |
| 952 | break; |
| 953 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 954 | bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
| 955 | sgsn_bvc = gbproxy_bvc_by_bvci(nse, bvci); |
| 956 | if (!sgsn_bvc) |
| 957 | goto err_no_bvc; |
| 958 | rc = osmo_fsm_inst_dispatch(sgsn_bvc->fi, BSSGP_BVCFSM_E_RX_BLOCK_ACK, msg); |
| 959 | break; |
| 960 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 961 | bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
| 962 | sgsn_bvc = gbproxy_bvc_by_bvci(nse, bvci); |
| 963 | if (!sgsn_bvc) |
| 964 | goto err_no_bvc; |
| 965 | rc = osmo_fsm_inst_dispatch(sgsn_bvc->fi, BSSGP_BVCFSM_E_RX_UNBLOCK_ACK, msg); |
Daniel Willmann | 15c9da2 | 2020-11-03 21:12:42 +0100 | [diff] [blame] | 966 | break; |
Jacob Erlbeck | c1c57d3 | 2014-08-28 13:20:39 +0200 | [diff] [blame] | 967 | case BSSGP_PDUT_FLUSH_LL: |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 968 | /* simple case: BVCI IE is mandatory */ |
Holger Hans Peter Freyther | ffd6856 | 2012-09-04 20:42:20 +0200 | [diff] [blame] | 969 | bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 970 | sgsn_bvc = gbproxy_bvc_by_bvci(nse, bvci); |
| 971 | if (!sgsn_bvc) |
| 972 | goto err_no_bvc; |
| 973 | if (sgsn_bvc->cell && sgsn_bvc->cell->bss_bvc) |
| 974 | rc = gbprox_relay2peer(msg, sgsn_bvc->cell->bss_bvc, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 975 | break; |
| 976 | case BSSGP_PDUT_PAGING_PS: |
| 977 | case BSSGP_PDUT_PAGING_CS: |
Jacob Erlbeck | 8f50359 | 2014-06-02 10:49:00 +0200 | [diff] [blame] | 978 | /* process the paging request (LAI/RAI lookup) */ |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 979 | rc = gbprox_rx_paging(nse, msg, pdut_name, &tp, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 980 | break; |
| 981 | case BSSGP_PDUT_STATUS: |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 982 | /* Some exception has occurred */ |
Jacob Erlbeck | 1e65b0e | 2014-08-29 13:32:17 +0200 | [diff] [blame] | 983 | cause = *TLVP_VAL(&tp, BSSGP_IE_CAUSE); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 984 | LOGPNSE(nse, LOGL_NOTICE, "Rx STATUS cause=0x%02x(%s) ", cause, |
Jacob Erlbeck | 1e65b0e | 2014-08-29 13:32:17 +0200 | [diff] [blame] | 985 | bssgp_cause_str(cause)); |
Harald Welte | 6c4c6f0 | 2020-12-03 15:36:59 +0100 | [diff] [blame] | 986 | if (TLVP_PRES_LEN(&tp, BSSGP_IE_BVCI, 2)) { |
Jacob Erlbeck | 1e65b0e | 2014-08-29 13:32:17 +0200 | [diff] [blame] | 987 | bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI)); |
Daniel Willmann | 103a7ec | 2020-12-02 16:08:02 +0100 | [diff] [blame] | 988 | LOGPC(DGPRS, LOGL_NOTICE, "BVCI=%05u\n", bvci); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 989 | sgsn_bvc = gbproxy_bvc_by_bvci(nse, bvci); |
| 990 | /* don't send STATUS in response to STATUS if !bvc */ |
| 991 | if (sgsn_bvc && sgsn_bvc->cell && sgsn_bvc->cell->bss_bvc) |
| 992 | rc = gbprox_relay2peer(msg, sgsn_bvc->cell->bss_bvc, ns_bvci); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 993 | } else |
| 994 | LOGPC(DGPRS, LOGL_NOTICE, "\n"); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 995 | break; |
| 996 | /* those only exist in the SGSN -> BSS direction */ |
| 997 | case BSSGP_PDUT_SUSPEND_ACK: |
| 998 | case BSSGP_PDUT_SUSPEND_NACK: |
| 999 | case BSSGP_PDUT_RESUME_ACK: |
| 1000 | case BSSGP_PDUT_RESUME_NACK: |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1001 | /* FIXME: handle based on TLLI cache. The RA-ID is not a unique |
| 1002 | * criterion, so we have to rely on the TLLI->BVC state created |
| 1003 | * while processing the SUSPEND/RESUME in uplink */ |
| 1004 | /* FIXME: route to SGSN baed on NRI derived from TLLI */ |
Harald Welte | 36f98d9 | 2011-02-06 13:09:29 +0100 | [diff] [blame] | 1005 | break; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1006 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | c8d98ac | 2020-12-02 20:06:04 +0100 | [diff] [blame] | 1007 | case BSSGP_PDUT_OVERLOAD: |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1008 | LOGPNSE(nse, LOGL_DEBUG, "Rx %s: broadcasting\n", pdut_name); |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 1009 | /* broadcast to all BSS-side bvcs */ |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 1010 | hash_for_each(cfg->bss_nses, i, nse, list) { |
Harald Welte | c8d98ac | 2020-12-02 20:06:04 +0100 | [diff] [blame] | 1011 | gbprox_relay2nse(msg, nse, 0); |
| 1012 | } |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1013 | break; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1014 | case BSSGP_PDUT_RAN_INFO: |
| 1015 | case BSSGP_PDUT_RAN_INFO_REQ: |
| 1016 | case BSSGP_PDUT_RAN_INFO_ACK: |
| 1017 | case BSSGP_PDUT_RAN_INFO_ERROR: |
| 1018 | case BSSGP_PDUT_RAN_INFO_APP_ERROR: |
| 1019 | /* FIXME: route based in RIM Routing IE */ |
| 1020 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, orig_msg); |
| 1021 | break; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1022 | default: |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1023 | LOGPNSE(nse, LOGL_NOTICE, "Rx %s: Not supported\n", pdut_name); |
| 1024 | rate_ctr_inc(&cfg->ctrg->ctr[GBPROX_GLOB_CTR_PROTO_ERR_SGSN]); |
Jacob Erlbeck | 4b663ac | 2014-08-21 15:07:11 +0200 | [diff] [blame] | 1025 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, orig_msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1026 | break; |
| 1027 | } |
| 1028 | |
Jacob Erlbeck | 4b663ac | 2014-08-21 15:07:11 +0200 | [diff] [blame] | 1029 | msgb_free(msg); |
| 1030 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1031 | return rc; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1032 | |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 1033 | err_no_bvc: |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1034 | LOGPNSE(nse, LOGL_ERROR, "Rx %s: Cannot find BVC\n", pdut_name); |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 1035 | rate_ctr_inc(&cfg->ctrg-> ctr[GBPROX_GLOB_CTR_INV_RAI]); |
Jacob Erlbeck | 4b663ac | 2014-08-21 15:07:11 +0200 | [diff] [blame] | 1036 | msgb_free(msg); |
Jacob Erlbeck | 17b42b8 | 2014-08-29 12:20:15 +0200 | [diff] [blame] | 1037 | return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, orig_msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1040 | |
| 1041 | /*********************************************************************** |
| 1042 | * libosmogb NS/BSSGP integration |
| 1043 | ***********************************************************************/ |
| 1044 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1045 | int gbprox_bssgp_send_cb(void *ctx, struct msgb *msg) |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1046 | { |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 1047 | int rc; |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1048 | struct gbproxy_config *cfg = (struct gbproxy_config *) ctx; |
| 1049 | struct gprs_ns2_inst *nsi = cfg->nsi; |
| 1050 | struct osmo_gprs_ns2_prim nsp = {}; |
| 1051 | |
| 1052 | nsp.bvci = msgb_bvci(msg); |
| 1053 | nsp.nsei = msgb_nsei(msg); |
| 1054 | |
| 1055 | osmo_prim_init(&nsp.oph, SAP_NS, PRIM_NS_UNIT_DATA, PRIM_OP_REQUEST, msg); |
| 1056 | rc = gprs_ns2_recv_prim(nsi, &nsp.oph); |
| 1057 | |
| 1058 | return rc; |
| 1059 | } |
| 1060 | |
| 1061 | /* Main input function for Gb proxy */ |
| 1062 | int gbprox_rcvmsg(void *ctx, struct msgb *msg) |
| 1063 | { |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1064 | struct gbproxy_config *cfg = (struct gbproxy_config *) ctx; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1065 | uint16_t ns_bvci = msgb_bvci(msg); |
| 1066 | uint16_t nsei = msgb_nsei(msg); |
| 1067 | struct gbproxy_nse *nse; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1068 | |
Harald Welte | d651edc | 2020-12-06 13:35:24 +0100 | [diff] [blame] | 1069 | /* ensure minimum length to decode PCU type */ |
| 1070 | if (msgb_bssgp_len(msg) < sizeof(struct bssgp_normal_hdr)) |
| 1071 | return bssgp_tx_status(BSSGP_CAUSE_SEM_INCORR_PDU, NULL, msg); |
| 1072 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1073 | nse = gbproxy_nse_by_nsei(cfg, nsei, NSE_F_SGSN); |
| 1074 | if (nse) { |
| 1075 | if (ns_bvci == 0 || ns_bvci == 1) |
| 1076 | return gbprox_rx_sig_from_sgsn(nse, msg, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1077 | else |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1078 | return gbprox_rx_ptp_from_sgsn(nse, msg, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1079 | } |
| 1080 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1081 | nse = gbproxy_nse_by_nsei(cfg, nsei, NSE_F_BSS); |
| 1082 | if (!nse) { |
| 1083 | LOGP(DGPRS, LOGL_NOTICE, "NSE(%05u/BSS) not known -> allocating\n", nsei); |
| 1084 | nse = gbproxy_nse_alloc(cfg, nsei, false); |
| 1085 | } |
| 1086 | if (nse) { |
| 1087 | if (ns_bvci == 0 || ns_bvci == 1) |
| 1088 | return gbprox_rx_sig_from_bss(nse, msg, ns_bvci); |
| 1089 | else |
| 1090 | return gbprox_rx_ptp_from_bss(nse, msg, ns_bvci); |
| 1091 | } |
| 1092 | |
| 1093 | return 0; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1094 | } |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 1095 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1096 | /* TODO: What about handling: |
| 1097 | * NS_AFF_CAUSE_VC_FAILURE, |
| 1098 | NS_AFF_CAUSE_VC_RECOVERY, |
| 1099 | NS_AFF_CAUSE_FAILURE, |
| 1100 | NS_AFF_CAUSE_RECOVERY, |
| 1101 | osmocom own causes |
| 1102 | NS_AFF_CAUSE_SNS_CONFIGURED, |
| 1103 | NS_AFF_CAUSE_SNS_FAILURE, |
| 1104 | */ |
Harald Welte | 1ccbf44 | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 1105 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1106 | void gprs_ns_prim_status_cb(struct gbproxy_config *cfg, struct osmo_gprs_ns2_prim *nsp) |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 1107 | { |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 1108 | /* TODO: bss nsei available/unavailable bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK, nsvc->nsei, bvc->bvci, 0); |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1109 | * TODO: sgsn nsei available/unavailable |
| 1110 | */ |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1111 | |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 1112 | struct gbproxy_bvc *bvc; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1113 | struct gbproxy_nse *sgsn_nse; |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 1114 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1115 | switch (nsp->u.status.cause) { |
| 1116 | case NS_AFF_CAUSE_SNS_FAILURE: |
| 1117 | case NS_AFF_CAUSE_SNS_CONFIGURED: |
| 1118 | break; |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 1119 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1120 | case NS_AFF_CAUSE_RECOVERY: |
| 1121 | LOGP(DPCU, LOGL_NOTICE, "NS-NSE %d became available\n", nsp->nsei); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1122 | sgsn_nse = gbproxy_nse_by_nsei(cfg, nsp->nsei, NSE_F_SGSN); |
| 1123 | if (sgsn_nse) { |
| 1124 | uint8_t cause = BSSGP_CAUSE_OML_INTERV; |
| 1125 | bvc = gbproxy_bvc_by_bvci(sgsn_nse, 0); |
| 1126 | if (bvc) |
| 1127 | osmo_fsm_inst_dispatch(bvc->fi, BSSGP_BVCFSM_E_REQ_RESET, &cause); |
Harald Welte | 5e106d7 | 2011-02-06 16:33:29 +0100 | [diff] [blame] | 1128 | } |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1129 | break; |
| 1130 | case NS_AFF_CAUSE_FAILURE: |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1131 | #if 0 |
Harald Welte | 4bf53ef | 2020-12-05 17:50:23 +0100 | [diff] [blame] | 1132 | if (gbproxy_is_sgsn_nsei(cfg, nsp->nsei)) { |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1133 | /* sgsn */ |
| 1134 | /* TODO: BSVC: block all PtP towards bss */ |
| 1135 | rate_ctr_inc(&cfg->ctrg-> |
| 1136 | ctr[GBPROX_GLOB_CTR_RESTART_RESET_SGSN]); |
| 1137 | } else { |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 1138 | /* bss became unavailable |
| 1139 | * TODO: Block all BVC belonging to that NSE */ |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 1140 | bvc = gbproxy_bvc_by_nsei(cfg, nsp->nsei); |
| 1141 | if (!bvc) { |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1142 | /* TODO: use primitive name + status cause name */ |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 1143 | LOGP(DGPRS, LOGL_NOTICE, "Received ns2 primitive %d for unknown bvc NSEI=%u\n", |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1144 | nsp->u.status.cause, nsp->nsei); |
Harald Welte | 5e106d7 | 2011-02-06 16:33:29 +0100 | [diff] [blame] | 1145 | break; |
| 1146 | } |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1147 | |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 1148 | if (!bvc->blocked) |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1149 | break; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1150 | hash_for_each(cfg->sgsn_nses, _sgsn, sgsn_nse, list) { |
| 1151 | bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK, sgsn_nse->nsei, bvc->bvci, 0); |
| 1152 | } |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 1153 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1154 | #endif |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1155 | LOGP(DPCU, LOGL_NOTICE, "NS-NSE %d became unavailable\n", nsp->nsei); |
| 1156 | break; |
| 1157 | default: |
Harald Welte | d97ff68 | 2020-11-30 10:55:22 +0100 | [diff] [blame] | 1158 | LOGP(DPCU, LOGL_NOTICE, "NS: Unknown NS-STATUS.ind cause=%s from NS\n", |
| 1159 | gprs_ns2_aff_cause_prim_str(nsp->u.status.cause)); |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1160 | break; |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 1161 | } |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1162 | } |
| 1163 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1164 | /* called by the ns layer */ |
| 1165 | int gprs_ns2_prim_cb(struct osmo_prim_hdr *oph, void *ctx) |
| 1166 | { |
| 1167 | struct osmo_gprs_ns2_prim *nsp; |
| 1168 | struct gbproxy_config *cfg = (struct gbproxy_config *) ctx; |
Daniel Willmann | e8c8ec9 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 1169 | uintptr_t bvci; |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1170 | int rc = 0; |
| 1171 | |
| 1172 | if (oph->sap != SAP_NS) |
| 1173 | return 0; |
| 1174 | |
| 1175 | nsp = container_of(oph, struct osmo_gprs_ns2_prim, oph); |
| 1176 | |
| 1177 | if (oph->operation != PRIM_OP_INDICATION) { |
Harald Welte | d97ff68 | 2020-11-30 10:55:22 +0100 | [diff] [blame] | 1178 | LOGP(DPCU, LOGL_NOTICE, "NS: Unexpected primitive operation %s from NS\n", |
| 1179 | get_value_string(osmo_prim_op_names, oph->operation)); |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | switch (oph->primitive) { |
| 1184 | case PRIM_NS_UNIT_DATA: |
Daniel Willmann | e8c8ec9 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 1185 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1186 | /* hand the message into the BSSGP implementation */ |
| 1187 | msgb_bssgph(oph->msg) = oph->msg->l3h; |
| 1188 | msgb_bvci(oph->msg) = nsp->bvci; |
| 1189 | msgb_nsei(oph->msg) = nsp->nsei; |
Daniel Willmann | e8c8ec9 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 1190 | bvci = nsp->bvci | BVC_LOG_CTX_FLAG; |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1191 | |
Daniel Willmann | e8c8ec9 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 1192 | log_set_context(LOG_CTX_GB_BVC, (void *)bvci); |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1193 | rc = gbprox_rcvmsg(cfg, oph->msg); |
Daniel Willmann | 02f2c34 | 2020-11-04 17:32:56 +0100 | [diff] [blame] | 1194 | msgb_free(oph->msg); |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1195 | break; |
| 1196 | case PRIM_NS_STATUS: |
| 1197 | gprs_ns_prim_status_cb(cfg, nsp); |
| 1198 | break; |
| 1199 | default: |
Harald Welte | d97ff68 | 2020-11-30 10:55:22 +0100 | [diff] [blame] | 1200 | LOGP(DPCU, LOGL_NOTICE, "NS: Unknown prim %s %s from NS\n", |
| 1201 | gprs_ns2_prim_str(oph->primitive), |
| 1202 | get_value_string(osmo_prim_op_names, oph->operation)); |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 1203 | break; |
| 1204 | } |
| 1205 | |
| 1206 | return rc; |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 1207 | } |
| 1208 | |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 1209 | void gbprox_reset(struct gbproxy_config *cfg) |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1210 | { |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 1211 | struct gbproxy_nse *nse; |
| 1212 | struct hlist_node *ntmp; |
Harald Welte | 993d3f4 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 1213 | int i, j; |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1214 | |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 1215 | hash_for_each_safe(cfg->bss_nses, i, ntmp, nse, list) { |
Harald Welte | 993d3f4 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 1216 | struct gbproxy_bvc *bvc; |
| 1217 | struct hlist_node *tmp; |
| 1218 | hash_for_each_safe(nse->bvcs, j, tmp, bvc, list) |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 1219 | gbproxy_bvc_free(bvc); |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 1220 | |
| 1221 | gbproxy_nse_free(nse); |
| 1222 | } |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame^] | 1223 | /* FIXME: cells */ |
| 1224 | /* FIXME: SGSN side BVCs (except signaling) */ |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1225 | |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 1226 | rate_ctr_group_free(cfg->ctrg); |
| 1227 | gbproxy_init_config(cfg); |
Jacob Erlbeck | 72b401f | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 1228 | } |
| 1229 | |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 1230 | int gbproxy_init_config(struct gbproxy_config *cfg) |
Jacob Erlbeck | 4211d79 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 1231 | { |
Jacob Erlbeck | 0d37671 | 2014-08-11 19:12:24 +0200 | [diff] [blame] | 1232 | struct timespec tp; |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 1233 | |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 1234 | hash_init(cfg->bss_nses); |
Pau Espin Pedrol | b1d1c24 | 2018-10-30 17:27:59 +0100 | [diff] [blame] | 1235 | cfg->ctrg = rate_ctr_group_alloc(tall_sgsn_ctx, &global_ctrg_desc, 0); |
Harald Welte | 26c1465 | 2017-07-12 00:25:51 +0200 | [diff] [blame] | 1236 | if (!cfg->ctrg) { |
| 1237 | LOGP(DGPRS, LOGL_ERROR, "Cannot allocate global counter group!\n"); |
| 1238 | return -1; |
| 1239 | } |
Pau Espin Pedrol | 36abead | 2018-08-17 13:27:20 +0200 | [diff] [blame] | 1240 | osmo_clock_gettime(CLOCK_REALTIME, &tp); |
Harald Welte | a54ed46 | 2020-12-07 13:12:13 +0100 | [diff] [blame] | 1241 | osmo_fsm_log_timeouts(true); |
Jacob Erlbeck | 9a83d7a | 2014-09-25 11:17:31 +0200 | [diff] [blame] | 1242 | |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 1243 | return 0; |
Jacob Erlbeck | 4211d79 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 1244 | } |