Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1 | /*! \file gprs_ns2_vc_fsm.c |
| 2 | * NS virtual circuit FSM implementation |
| 3 | * 3GPP TS 08.16 version 8.0.1 Release 1999 / ETSI TS 101 299 V8.0.1 (2002-05) |
| 4 | * as well as its successor 3GPP TS 48.016 */ |
| 5 | |
| 6 | /* (C) 2020 sysmocom - s.f.m.c. GmbH |
| 7 | * Author: Alexander Couzens <lynxis@fe80.eu> |
| 8 | * |
| 9 | * All Rights Reserved |
| 10 | * |
| 11 | * SPDX-License-Identifier: GPL-2.0+ |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | /* The BSS NSE only has one SGSN IP address configured, and it will use the SNS procedures |
| 29 | * to communicated its local IPs/ports as well as all the SGSN side IPs/ports and |
| 30 | * associated weights. In theory, the BSS then uses this to establish a full mesh |
| 31 | * of NSVCs between all BSS-side IPs/ports and SGSN-side IPs/ports */ |
| 32 | |
| 33 | #include <errno.h> |
| 34 | |
| 35 | #include <netinet/in.h> |
| 36 | #include <arpa/inet.h> |
| 37 | |
| 38 | #include <osmocom/core/fsm.h> |
| 39 | #include <osmocom/core/msgb.h> |
| 40 | #include <osmocom/core/rate_ctr.h> |
| 41 | #include <osmocom/core/socket.h> |
| 42 | #include <osmocom/core/stat_item.h> |
| 43 | #include <osmocom/gsm/prim.h> |
| 44 | #include <osmocom/gsm/tlv.h> |
| 45 | #include <osmocom/gprs/gprs_msgb.h> |
| 46 | #include <osmocom/gprs/protocol/gsm_08_16.h> |
| 47 | |
| 48 | #include "gprs_ns2_internal.h" |
| 49 | |
| 50 | #define S(x) (1 << (x)) |
| 51 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 52 | struct gprs_ns2_vc_priv { |
| 53 | struct gprs_ns2_vc *nsvc; |
| 54 | /* how often the timer was triggered */ |
| 55 | int N; |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 56 | /* The initiator is responsible to UNBLOCK the VC. The BSS is usually the initiator. |
| 57 | * It can change during runtime. The side which blocks an unblocked side.*/ |
Alexander Couzens | ea01bf2 | 2021-01-18 14:01:01 +0100 | [diff] [blame] | 58 | bool initiator; |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 59 | bool initiate_block; |
| 60 | bool initiate_reset; |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 61 | /* if unitdata is forwarded to the user */ |
| 62 | bool accept_unitdata; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 63 | |
| 64 | /* the alive counter is present in all states */ |
| 65 | struct { |
| 66 | struct osmo_timer_list timer; |
| 67 | enum ns2_timeout mode; |
| 68 | int N; |
Alexander Couzens | ab0e864 | 2021-02-12 02:50:44 +0100 | [diff] [blame] | 69 | struct timespec timer_started; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 70 | } alive; |
| 71 | }; |
| 72 | |
| 73 | |
| 74 | /* The FSM covers both the VC with RESET/BLOCK and without RESET/BLOCK procedure.. |
| 75 | * |
| 76 | * With RESET/BLOCK, the state should follow: |
| 77 | * - UNCONFIGURED -> RESET -> BLOCK -> UNBLOCKED |
| 78 | * |
| 79 | * Without RESET/BLOCK, the state should follow: |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 80 | * - UNCONFIGURED -> RECOVERY -> UNBLOCKED |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 81 | * |
| 82 | * The UNBLOCKED and TEST states are used to send ALIVE PDU using the timeout Tns-test and Tns-alive. |
| 83 | * UNBLOCKED -> TEST: on expire of Tns-Test, send Alive PDU. |
| 84 | * TEST -> UNBLOCKED: on receive of Alive_Ack PDU, go into UNBLOCKED. |
| 85 | * |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 86 | * The RECOVERY state is used as intermediate, because a VC is only valid if it received an Alive ACK when |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 87 | * not using RESET/BLOCK procedure. |
| 88 | */ |
| 89 | |
| 90 | enum gprs_ns2_vc_state { |
| 91 | GPRS_NS2_ST_UNCONFIGURED, |
| 92 | GPRS_NS2_ST_RESET, |
| 93 | GPRS_NS2_ST_BLOCKED, |
| 94 | GPRS_NS2_ST_UNBLOCKED, /* allows sending NS_UNITDATA */ |
| 95 | |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 96 | GPRS_NS2_ST_RECOVERING, /* only used when not using RESET/BLOCK procedure */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | enum gprs_ns2_vc_event { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 100 | GPRS_NS2_EV_REQ_START, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 101 | |
| 102 | /* received messages */ |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 103 | GPRS_NS2_EV_RX_RESET, |
| 104 | GPRS_NS2_EV_RX_RESET_ACK, |
| 105 | GPRS_NS2_EV_RX_UNBLOCK, |
| 106 | GPRS_NS2_EV_RX_UNBLOCK_ACK, |
| 107 | GPRS_NS2_EV_RX_BLOCK, |
| 108 | GPRS_NS2_EV_RX_BLOCK_ACK, |
| 109 | GPRS_NS2_EV_RX_ALIVE, |
| 110 | GPRS_NS2_EV_RX_ALIVE_ACK, |
| 111 | GPRS_NS2_EV_RX_STATUS, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 112 | |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 113 | GPRS_NS2_EV_RX_UNITDATA, |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 114 | |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 115 | GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED, /* called via vty for tests */ |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 116 | GPRS_NS2_EV_REQ_OM_RESET, /* vty cmd: reset */ |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 117 | GPRS_NS2_EV_REQ_OM_BLOCK, /* vty cmd: block */ |
| 118 | GPRS_NS2_EV_REQ_OM_UNBLOCK, /* vty cmd: unblock*/ |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 119 | GPRS_NS2_EV_RX_BLOCK_FOREIGN, /* received a BLOCK over another NSVC */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 120 | }; |
| 121 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 122 | static const struct value_string ns2_vc_event_names[] = { |
Harald Welte | b339cbb | 2021-02-05 14:49:21 +0100 | [diff] [blame] | 123 | { GPRS_NS2_EV_REQ_START, "REQ-START" }, |
| 124 | { GPRS_NS2_EV_RX_RESET, "RX-RESET" }, |
| 125 | { GPRS_NS2_EV_RX_RESET_ACK, "RX-RESET_ACK" }, |
| 126 | { GPRS_NS2_EV_RX_UNBLOCK, "RX-UNBLOCK" }, |
| 127 | { GPRS_NS2_EV_RX_UNBLOCK_ACK, "RX-UNBLOCK_ACK" }, |
| 128 | { GPRS_NS2_EV_RX_BLOCK, "RX-BLOCK" }, |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 129 | { GPRS_NS2_EV_RX_BLOCK_FOREIGN, "RX-BLOCK_FOREIGN" }, |
Harald Welte | b339cbb | 2021-02-05 14:49:21 +0100 | [diff] [blame] | 130 | { GPRS_NS2_EV_RX_BLOCK_ACK, "RX-BLOCK_ACK" }, |
| 131 | { GPRS_NS2_EV_RX_ALIVE, "RX-ALIVE" }, |
| 132 | { GPRS_NS2_EV_RX_ALIVE_ACK, "RX-ALIVE_ACK" }, |
| 133 | { GPRS_NS2_EV_RX_STATUS, "RX-STATUS" }, |
| 134 | { GPRS_NS2_EV_RX_UNITDATA, "RX-UNITDATA" }, |
| 135 | { GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED, "REQ-FORCE_UNCONFIGURED" }, |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 136 | { GPRS_NS2_EV_REQ_OM_RESET, "REQ-O&M-RESET"}, |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 137 | { GPRS_NS2_EV_REQ_OM_BLOCK, "REQ-O&M-BLOCK"}, |
| 138 | { GPRS_NS2_EV_REQ_OM_UNBLOCK, "REQ-O&M-UNBLOCK"}, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 139 | { 0, NULL } |
| 140 | }; |
| 141 | |
| 142 | static inline struct gprs_ns2_inst *ns_inst_from_fi(struct osmo_fsm_inst *fi) |
| 143 | { |
| 144 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 145 | return priv->nsvc->nse->nsi; |
| 146 | } |
| 147 | |
Harald Welte | 5e40831 | 2021-03-23 18:16:30 +0100 | [diff] [blame] | 148 | /* Start the NS-TEST procedure, either with transmitting a tx_alive, |
| 149 | * (start_tx_alive==true) or with starting tns-test */ |
| 150 | static void start_test_procedure(struct osmo_fsm_inst *fi, bool start_tx_alive) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 151 | { |
Harald Welte | 5e40831 | 2021-03-23 18:16:30 +0100 | [diff] [blame] | 152 | struct gprs_ns2_vc_priv *priv = fi->priv; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 153 | struct gprs_ns2_inst *nsi = priv->nsvc->nse->nsi; |
Harald Welte | 5e40831 | 2021-03-23 18:16:30 +0100 | [diff] [blame] | 154 | unsigned int tout_idx; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 155 | |
Harald Welte | 5e40831 | 2021-03-23 18:16:30 +0100 | [diff] [blame] | 156 | if (osmo_timer_pending(&priv->alive.timer)) { |
| 157 | if (start_tx_alive) { |
| 158 | if (priv->alive.mode == NS_TOUT_TNS_ALIVE) |
| 159 | return; |
| 160 | } else { |
| 161 | if (priv->alive.mode == NS_TOUT_TNS_TEST) |
| 162 | return; |
| 163 | } |
| 164 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 165 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 166 | priv->alive.N = 0; |
| 167 | |
Harald Welte | 5e40831 | 2021-03-23 18:16:30 +0100 | [diff] [blame] | 168 | if (start_tx_alive) { |
| 169 | priv->alive.mode = NS_TOUT_TNS_ALIVE; |
| 170 | osmo_clock_gettime(CLOCK_MONOTONIC, &priv->alive.timer_started); |
| 171 | ns2_tx_alive(priv->nsvc); |
| 172 | tout_idx = NS_TOUT_TNS_ALIVE; |
| 173 | } else { |
| 174 | priv->alive.mode = NS_TOUT_TNS_TEST; |
| 175 | tout_idx = NS_TOUT_TNS_TEST; |
| 176 | } |
| 177 | LOGPFSML(fi, LOGL_DEBUG, "Starting Tns-%s of %u seconds\n", |
| 178 | tout_idx == NS_TOUT_TNS_ALIVE ? "alive" : "test", nsi->timeout[tout_idx]); |
| 179 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[tout_idx], 0); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static void stop_test_procedure(struct gprs_ns2_vc_priv *priv) |
| 183 | { |
Alexander Couzens | 8138c53 | 2021-06-15 22:11:40 +0200 | [diff] [blame] | 184 | osmo_stat_item_set(osmo_stat_item_group_get_item(priv->nsvc->statg, NS_STAT_ALIVE_DELAY), 0); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 185 | osmo_timer_del(&priv->alive.timer); |
| 186 | } |
| 187 | |
Harald Welte | 5e40831 | 2021-03-23 18:16:30 +0100 | [diff] [blame] | 188 | /* how many milliseconds have expired since the last alive timer start? */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 189 | static int alive_timer_elapsed_ms(struct gprs_ns2_vc_priv *priv) |
| 190 | { |
Alexander Couzens | ab0e864 | 2021-02-12 02:50:44 +0100 | [diff] [blame] | 191 | struct timespec now, elapsed; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 192 | |
Alexander Couzens | ab0e864 | 2021-02-12 02:50:44 +0100 | [diff] [blame] | 193 | if (osmo_clock_gettime(CLOCK_MONOTONIC, &now) != 0) |
| 194 | return 0; |
| 195 | |
| 196 | timespecsub(&now, &priv->alive.timer_started, &elapsed); |
Alexander Couzens | ab0e864 | 2021-02-12 02:50:44 +0100 | [diff] [blame] | 197 | return elapsed.tv_sec * 1000 + (elapsed.tv_nsec / 1000000); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 198 | } |
| 199 | |
Harald Welte | 5e40831 | 2021-03-23 18:16:30 +0100 | [diff] [blame] | 200 | /* we just received a NS-ALIVE-ACK; re-schedule after Tns-test */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 201 | static void recv_test_procedure(struct osmo_fsm_inst *fi) |
| 202 | { |
| 203 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 204 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 205 | struct gprs_ns2_vc *nsvc = priv->nsvc; |
| 206 | |
| 207 | /* ignoring ACKs without sending an ALIVE */ |
| 208 | if (priv->alive.mode != NS_TOUT_TNS_ALIVE) |
| 209 | return; |
| 210 | |
| 211 | priv->alive.mode = NS_TOUT_TNS_TEST; |
| 212 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_TEST], 0); |
Pau Espin Pedrol | 7b894a7 | 2021-06-04 18:17:12 +0200 | [diff] [blame] | 213 | osmo_stat_item_set(osmo_stat_item_group_get_item(nsvc->statg, NS_STAT_ALIVE_DELAY), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 214 | alive_timer_elapsed_ms(priv)); |
| 215 | } |
| 216 | |
| 217 | |
| 218 | static void alive_timeout_handler(void *data) |
| 219 | { |
| 220 | struct osmo_fsm_inst *fi = data; |
| 221 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 222 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 223 | |
| 224 | switch (priv->alive.mode) { |
| 225 | case NS_TOUT_TNS_TEST: |
| 226 | priv->alive.mode = NS_TOUT_TNS_ALIVE; |
Alexander Couzens | 2f8f7b6 | 2021-02-03 11:04:22 +0100 | [diff] [blame] | 227 | priv->alive.N = 0; |
Alexander Couzens | fa4121d | 2021-02-12 02:54:46 +0100 | [diff] [blame] | 228 | osmo_clock_gettime(CLOCK_MONOTONIC, &priv->alive.timer_started); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 229 | ns2_tx_alive(priv->nsvc); |
| 230 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0); |
| 231 | break; |
| 232 | case NS_TOUT_TNS_ALIVE: |
Daniel Willmann | efa64f9 | 2021-07-09 20:35:00 +0200 | [diff] [blame] | 233 | RATE_CTR_INC_NS(priv->nsvc, NS_CTR_LOST_ALIVE); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 234 | priv->alive.N++; |
| 235 | |
| 236 | if (priv->alive.N <= nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) { |
| 237 | /* retransmission */ |
| 238 | ns2_tx_alive(priv->nsvc); |
| 239 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0); |
| 240 | } else { |
| 241 | /* lost connection */ |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 242 | if (priv->nsvc->mode == GPRS_NS2_VC_MODE_BLOCKRESET) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 243 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 244 | } else { |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 245 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, nsi->timeout[NS_TOUT_TNS_ALIVE], 0); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | break; |
| 249 | default: |
| 250 | break; |
| 251 | } |
| 252 | } |
| 253 | |
Harald Welte | 6a9ec42 | 2021-01-31 18:56:29 +0100 | [diff] [blame] | 254 | |
| 255 | static void ns2_st_unconfigured_onenter(struct osmo_fsm_inst *fi, uint32_t old_state) |
| 256 | { |
Alexander Couzens | a140d44 | 2021-07-12 16:42:32 +0200 | [diff] [blame] | 257 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 258 | |
Harald Welte | 6a9ec42 | 2021-01-31 18:56:29 +0100 | [diff] [blame] | 259 | stop_test_procedure(fi->priv); |
Alexander Couzens | a140d44 | 2021-07-12 16:42:32 +0200 | [diff] [blame] | 260 | ns2_nse_notify_unblocked(priv->nsvc, false); |
Harald Welte | 6a9ec42 | 2021-01-31 18:56:29 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 263 | static void ns2_st_unconfigured(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 264 | { |
| 265 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 266 | struct gprs_ns2_inst *nsi = priv->nsvc->nse->nsi; |
| 267 | |
Alexander Couzens | ea01bf2 | 2021-01-18 14:01:01 +0100 | [diff] [blame] | 268 | priv->initiate_reset = priv->initiate_block = priv->initiator; |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 269 | priv->nsvc->om_blocked = false; |
Alexander Couzens | ea01bf2 | 2021-01-18 14:01:01 +0100 | [diff] [blame] | 270 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 271 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 272 | case GPRS_NS2_EV_REQ_START: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 273 | switch (priv->nsvc->mode) { |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 274 | case GPRS_NS2_VC_MODE_ALIVE: |
Harald Welte | c51ddf2 | 2021-03-05 09:48:18 +0100 | [diff] [blame] | 275 | if (priv->nsvc->nse->dialect == GPRS_NS2_DIALECT_SNS) { |
| 276 | /* In IP-SNS, the NS-VC are assumed initially alive, until the alive |
| 277 | * procedure should fail at some future point */ |
| 278 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, 0, 0); |
| 279 | } else { |
| 280 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, nsi->timeout[NS_TOUT_TNS_ALIVE], NS_TOUT_TNS_ALIVE); |
| 281 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 282 | break; |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 283 | case GPRS_NS2_VC_MODE_BLOCKRESET: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 284 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], NS_TOUT_TNS_RESET); |
| 285 | break; |
| 286 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 287 | break; |
| 288 | default: |
| 289 | OSMO_ASSERT(0); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 294 | static void ns2_st_reset_onenter(struct osmo_fsm_inst *fi, uint32_t old_state) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 295 | { |
| 296 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 297 | |
| 298 | if (old_state != GPRS_NS2_ST_RESET) |
| 299 | priv->N = 0; |
| 300 | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 301 | priv->accept_unitdata = false; |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 302 | if (priv->initiate_reset) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 303 | ns2_tx_reset(priv->nsvc, NS_CAUSE_OM_INTERVENTION); |
| 304 | |
| 305 | stop_test_procedure(priv); |
| 306 | ns2_nse_notify_unblocked(priv->nsvc, false); |
| 307 | } |
| 308 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 309 | static void ns2_st_reset(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 310 | { |
| 311 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 312 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 313 | |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 314 | if (priv->initiate_reset) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 315 | switch (event) { |
Alexander Couzens | 273f063 | 2021-01-20 13:11:26 +0100 | [diff] [blame] | 316 | case GPRS_NS2_EV_RX_RESET: |
| 317 | ns2_tx_reset_ack(priv->nsvc); |
| 318 | /* fall-through */ |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 319 | case GPRS_NS2_EV_RX_RESET_ACK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 320 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, |
| 321 | nsi->timeout[NS_TOUT_TNS_BLOCK], NS_TOUT_TNS_BLOCK); |
| 322 | break; |
| 323 | } |
| 324 | } else { |
| 325 | /* we are on the receiving end */ |
| 326 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 327 | case GPRS_NS2_EV_RX_RESET: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 328 | ns2_tx_reset_ack(priv->nsvc); |
| 329 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, |
| 330 | 0, 0); |
| 331 | break; |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 336 | static void ns2_st_blocked_onenter(struct osmo_fsm_inst *fi, uint32_t old_state) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 337 | { |
| 338 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 339 | |
Harald Welte | 4c54f59 | 2021-01-30 22:42:15 +0100 | [diff] [blame] | 340 | if (old_state != GPRS_NS2_ST_BLOCKED) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 341 | priv->N = 0; |
Daniel Willmann | efa64f9 | 2021-07-09 20:35:00 +0200 | [diff] [blame] | 342 | RATE_CTR_INC_NS(priv->nsvc, NS_CTR_BLOCKED); |
Harald Welte | 4c54f59 | 2021-01-30 22:42:15 +0100 | [diff] [blame] | 343 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 344 | |
Alexander Couzens | e09deb6 | 2021-06-15 21:35:45 +0200 | [diff] [blame] | 345 | ns2_nse_notify_unblocked(priv->nsvc, false); |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 346 | if (priv->nsvc->om_blocked) { |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 347 | /* we are already blocked after a RESET */ |
| 348 | if (old_state == GPRS_NS2_ST_RESET) { |
| 349 | osmo_timer_del(&fi->timer); |
| 350 | } else { |
Alexander Couzens | 67cfc5d | 2021-09-07 01:10:38 +0200 | [diff] [blame] | 351 | ns2_tx_block(priv->nsvc, NS_CAUSE_OM_INTERVENTION, NULL); |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 352 | } |
| 353 | } else if (priv->initiate_block) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 354 | ns2_tx_unblock(priv->nsvc); |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 355 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 356 | |
Harald Welte | 5e40831 | 2021-03-23 18:16:30 +0100 | [diff] [blame] | 357 | start_test_procedure(fi, true); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 358 | } |
| 359 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 360 | static void ns2_st_blocked(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 361 | { |
| 362 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 363 | |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 364 | if (priv->nsvc->om_blocked) { |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 365 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 366 | case GPRS_NS2_EV_RX_BLOCK_ACK: |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 367 | priv->accept_unitdata = false; |
| 368 | osmo_timer_del(&fi->timer); |
| 369 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 370 | case GPRS_NS2_EV_RX_BLOCK: |
Alexander Couzens | 67cfc5d | 2021-09-07 01:10:38 +0200 | [diff] [blame] | 371 | ns2_tx_block_ack(priv->nsvc, NULL); |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 372 | /* fall through */ |
| 373 | case GPRS_NS2_EV_RX_BLOCK_FOREIGN: |
| 374 | /* the BLOCK ACK for foreign BLOCK PDUs (rx over another nsvc) will be sent |
| 375 | * from the receiving nsvc */ |
| 376 | priv->accept_unitdata = false; |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 377 | osmo_timer_del(&fi->timer); |
| 378 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 379 | case GPRS_NS2_EV_RX_UNBLOCK: |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 380 | priv->accept_unitdata = false; |
Alexander Couzens | 67cfc5d | 2021-09-07 01:10:38 +0200 | [diff] [blame] | 381 | ns2_tx_block(priv->nsvc, NS_CAUSE_OM_INTERVENTION, NULL); |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 382 | osmo_timer_add(&fi->timer); |
| 383 | break; |
| 384 | } |
| 385 | } else if (priv->initiate_block) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 386 | switch (event) { |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 387 | case GPRS_NS2_EV_RX_BLOCK_FOREIGN: |
| 388 | /* the block ack will be sent by the rx NSVC */ |
| 389 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 390 | case GPRS_NS2_EV_RX_BLOCK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 391 | /* TODO: BLOCK is a UNBLOCK_NACK */ |
Alexander Couzens | 67cfc5d | 2021-09-07 01:10:38 +0200 | [diff] [blame] | 392 | ns2_tx_block_ack(priv->nsvc, NULL); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 393 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 394 | case GPRS_NS2_EV_RX_UNBLOCK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 395 | ns2_tx_unblock_ack(priv->nsvc); |
| 396 | /* fall through */ |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 397 | case GPRS_NS2_EV_RX_UNBLOCK_ACK: |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 398 | priv->accept_unitdata = true; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 399 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, |
| 400 | 0, NS_TOUT_TNS_TEST); |
| 401 | break; |
| 402 | } |
| 403 | } else { |
| 404 | /* we are on the receiving end. The initiator who sent RESET is responsible to UNBLOCK! */ |
| 405 | switch (event) { |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 406 | case GPRS_NS2_EV_RX_BLOCK_FOREIGN: |
| 407 | /* the block ack will be sent by the rx NSVC */ |
| 408 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 409 | case GPRS_NS2_EV_RX_BLOCK: |
Alexander Couzens | 67cfc5d | 2021-09-07 01:10:38 +0200 | [diff] [blame] | 410 | ns2_tx_block_ack(priv->nsvc, NULL); |
Alexander Couzens | 856b94c | 2021-01-19 19:42:17 +0100 | [diff] [blame] | 411 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 412 | case GPRS_NS2_EV_RX_UNBLOCK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 413 | ns2_tx_unblock_ack(priv->nsvc); |
| 414 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, |
| 415 | 0, 0); |
| 416 | break; |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 421 | static void ns2_st_unblocked_on_enter(struct osmo_fsm_inst *fi, uint32_t old_state) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 422 | { |
| 423 | struct gprs_ns2_vc_priv *priv = fi->priv; |
Daniel Willmann | 15c09a8 | 2020-11-03 23:05:43 +0100 | [diff] [blame] | 424 | struct gprs_ns2_vc *nsvc = priv->nsvc; |
| 425 | struct gprs_ns2_nse *nse = nsvc->nse; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 426 | |
Alexander Couzens | ca5ce0d | 2021-09-05 23:15:56 +0200 | [diff] [blame] | 427 | if (old_state != GPRS_NS2_ST_UNBLOCKED) { |
Daniel Willmann | efa64f9 | 2021-07-09 20:35:00 +0200 | [diff] [blame] | 428 | RATE_CTR_INC_NS(nsvc, NS_CTR_UNBLOCKED); |
Alexander Couzens | ca5ce0d | 2021-09-05 23:15:56 +0200 | [diff] [blame] | 429 | osmo_clock_gettime(CLOCK_MONOTONIC, &nsvc->ts_alive_change); |
| 430 | } |
Harald Welte | b40bf8b | 2021-01-30 22:43:01 +0100 | [diff] [blame] | 431 | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 432 | priv->accept_unitdata = true; |
Daniel Willmann | 15c09a8 | 2020-11-03 23:05:43 +0100 | [diff] [blame] | 433 | ns2_nse_notify_unblocked(nsvc, true); |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 434 | ns2_prim_status_ind(nse, nsvc, 0, GPRS_NS2_AFF_CAUSE_VC_RECOVERY); |
Harald Welte | 5e40831 | 2021-03-23 18:16:30 +0100 | [diff] [blame] | 435 | |
| 436 | /* the closest interpretation of the spec would start Tns-test here first, |
| 437 | * and only send a NS-ALIVE after Tns-test has expired (i.e. setting the |
| 438 | * second argument to 'false'. However, being quick in detecting unavailability |
| 439 | * of a NS-VC seems like a good idea */ |
| 440 | start_test_procedure(fi, true); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 443 | static void ns2_st_unblocked(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 444 | { |
| 445 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 446 | |
| 447 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 448 | case GPRS_NS2_EV_RX_UNBLOCK: |
Alexander Couzens | c4b7462 | 2021-01-10 20:44:26 +0100 | [diff] [blame] | 449 | ns2_tx_unblock_ack(priv->nsvc); |
| 450 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 451 | case GPRS_NS2_EV_RX_BLOCK: |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 452 | ns2_tx_block_ack(priv->nsvc, NULL); |
| 453 | /* fall through */ |
| 454 | case GPRS_NS2_EV_RX_BLOCK_FOREIGN: |
| 455 | /* the BLOCK ACK for foreign BLOCK PDUs (rx over another nsvc) will be sent |
| 456 | * from the receiving nsvc */ |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 457 | priv->initiate_block = false; |
Alexander Couzens | f27fbf6 | 2021-09-06 00:19:15 +0200 | [diff] [blame] | 458 | priv->accept_unitdata = false; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 459 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, |
| 460 | 0, 2); |
| 461 | break; |
| 462 | } |
| 463 | } |
| 464 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 465 | static void ns2_st_alive(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 466 | { |
| 467 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 468 | case GPRS_NS2_EV_RX_ALIVE_ACK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 469 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, 0, 0); |
| 470 | break; |
| 471 | } |
| 472 | } |
| 473 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 474 | static void ns2_st_alive_onenter(struct osmo_fsm_inst *fi, uint32_t old_state) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 475 | { |
| 476 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 477 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 478 | |
| 479 | priv->alive.mode = NS_TOUT_TNS_TEST; |
| 480 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_TEST], 0); |
| 481 | |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 482 | if (old_state != GPRS_NS2_ST_RECOVERING) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 483 | priv->N = 0; |
| 484 | |
Harald Welte | 5e40831 | 2021-03-23 18:16:30 +0100 | [diff] [blame] | 485 | start_test_procedure(fi, true); |
Alexander Couzens | 5b72247 | 2021-04-01 15:36:54 +0200 | [diff] [blame] | 486 | ns2_nse_notify_unblocked(priv->nsvc, false); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 487 | } |
| 488 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 489 | static const struct osmo_fsm_state ns2_vc_states[] = { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 490 | [GPRS_NS2_ST_UNCONFIGURED] = { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 491 | .in_event_mask = S(GPRS_NS2_EV_REQ_START), |
Harald Welte | c51ddf2 | 2021-03-05 09:48:18 +0100 | [diff] [blame] | 492 | .out_state_mask = S(GPRS_NS2_ST_RESET) | |
| 493 | S(GPRS_NS2_ST_RECOVERING) | |
| 494 | S(GPRS_NS2_ST_UNBLOCKED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 495 | .name = "UNCONFIGURED", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 496 | .action = ns2_st_unconfigured, |
Harald Welte | 6a9ec42 | 2021-01-31 18:56:29 +0100 | [diff] [blame] | 497 | .onenter = ns2_st_unconfigured_onenter, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 498 | }, |
| 499 | [GPRS_NS2_ST_RESET] = { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 500 | .in_event_mask = S(GPRS_NS2_EV_RX_RESET_ACK) | S(GPRS_NS2_EV_RX_RESET), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 501 | .out_state_mask = S(GPRS_NS2_ST_RESET) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 502 | S(GPRS_NS2_ST_BLOCKED) | |
| 503 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 504 | .name = "RESET", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 505 | .action = ns2_st_reset, |
| 506 | .onenter = ns2_st_reset_onenter, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 507 | }, |
| 508 | [GPRS_NS2_ST_BLOCKED] = { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 509 | .in_event_mask = S(GPRS_NS2_EV_RX_BLOCK) | S(GPRS_NS2_EV_RX_BLOCK_ACK) | |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 510 | S(GPRS_NS2_EV_RX_UNBLOCK) | S(GPRS_NS2_EV_RX_UNBLOCK_ACK) | |
| 511 | S(GPRS_NS2_EV_RX_BLOCK_FOREIGN), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 512 | .out_state_mask = S(GPRS_NS2_ST_RESET) | |
| 513 | S(GPRS_NS2_ST_UNBLOCKED) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 514 | S(GPRS_NS2_ST_BLOCKED) | |
| 515 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 516 | .name = "BLOCKED", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 517 | .action = ns2_st_blocked, |
| 518 | .onenter = ns2_st_blocked_onenter, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 519 | }, |
| 520 | [GPRS_NS2_ST_UNBLOCKED] = { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 521 | .in_event_mask = S(GPRS_NS2_EV_RX_BLOCK) | S(GPRS_NS2_EV_RX_UNBLOCK_ACK) | |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 522 | S(GPRS_NS2_EV_RX_UNBLOCK) | S(GPRS_NS2_EV_RX_BLOCK_FOREIGN), |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 523 | .out_state_mask = S(GPRS_NS2_ST_RESET) | S(GPRS_NS2_ST_RECOVERING) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 524 | S(GPRS_NS2_ST_BLOCKED) | |
| 525 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 526 | .name = "UNBLOCKED", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 527 | .action = ns2_st_unblocked, |
| 528 | .onenter = ns2_st_unblocked_on_enter, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 529 | }, |
| 530 | |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 531 | /* ST_RECOVERING is only used on VC without RESET/BLOCK */ |
| 532 | [GPRS_NS2_ST_RECOVERING] = { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 533 | .in_event_mask = S(GPRS_NS2_EV_RX_ALIVE_ACK), |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 534 | .out_state_mask = S(GPRS_NS2_ST_RECOVERING) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 535 | S(GPRS_NS2_ST_UNBLOCKED) | |
| 536 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 537 | .name = "RECOVERING", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 538 | .action = ns2_st_alive, |
| 539 | .onenter = ns2_st_alive_onenter, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 540 | }, |
| 541 | }; |
| 542 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 543 | static int ns2_vc_fsm_timer_cb(struct osmo_fsm_inst *fi) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 544 | { |
| 545 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 546 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 547 | |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 548 | switch (fi->state) { |
| 549 | case GPRS_NS2_ST_RESET: |
| 550 | if (priv->initiate_reset) { |
Daniel Willmann | efa64f9 | 2021-07-09 20:35:00 +0200 | [diff] [blame] | 551 | RATE_CTR_INC_NS(priv->nsvc, NS_CTR_LOST_RESET); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 552 | priv->N++; |
| 553 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_RESET_RETRIES]) { |
| 554 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 555 | } else { |
| 556 | priv->N = 0; |
| 557 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 558 | } |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 559 | } |
| 560 | break; |
| 561 | case GPRS_NS2_ST_BLOCKED: |
| 562 | if (priv->initiate_block) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 563 | priv->N++; |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 564 | if (priv->nsvc->om_blocked) { |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 565 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES]) { |
| 566 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0); |
| 567 | } else { |
| 568 | /* 7.2 stop accepting data when BLOCK PDU not responded */ |
| 569 | priv->accept_unitdata = false; |
| 570 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 571 | } else { |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 572 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES]) { |
| 573 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0); |
| 574 | } else { |
| 575 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 576 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 577 | } |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 578 | } |
| 579 | break; |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 580 | case GPRS_NS2_ST_RECOVERING: |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 581 | if (priv->initiate_reset) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 582 | priv->N++; |
| 583 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) { |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 584 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, 0, 0); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 585 | } else { |
| 586 | priv->N = 0; |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 587 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, 0, 0); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 588 | } |
| 589 | break; |
| 590 | } |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 591 | break; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 592 | } |
| 593 | return 0; |
| 594 | } |
| 595 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 596 | static void ns2_recv_unitdata(struct osmo_fsm_inst *fi, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 597 | struct msgb *msg) |
| 598 | { |
| 599 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 600 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 601 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
| 602 | struct osmo_gprs_ns2_prim nsp = {}; |
| 603 | uint16_t bvci; |
| 604 | |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 605 | if (msgb_l2len(msg) < sizeof(*nsh) + 3) { |
| 606 | msgb_free(msg); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 607 | return; |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 608 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 609 | |
| 610 | /* TODO: 7.1: For an IP sub-network, an NS-UNITDATA PDU |
| 611 | * for a PTP BVC may indicate a request to change the IP endpoint |
| 612 | * and/or a response to a change in the IP endpoint. */ |
| 613 | |
| 614 | /* TODO: nsh->data[0] -> C/R only valid in IP SNS */ |
| 615 | bvci = nsh->data[1] << 8 | nsh->data[2]; |
| 616 | |
Alexander Couzens | 89acdef | 2020-09-23 18:22:31 +0200 | [diff] [blame] | 617 | msg->l3h = &nsh->data[3]; |
| 618 | nsp.bvci = bvci; |
| 619 | nsp.nsei = priv->nsvc->nse->nsei; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 620 | |
Alexander Couzens | c1cd333 | 2020-09-23 23:24:02 +0200 | [diff] [blame] | 621 | /* 10.3.9 NS SDU Control Bits */ |
| 622 | if (nsh->data[0] & 0x1) |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 623 | nsp.u.unitdata.change = GPRS_NS2_ENDPOINT_REQUEST_CHANGE; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 624 | |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 625 | osmo_prim_init(&nsp.oph, SAP_NS, GPRS_NS2_PRIM_UNIT_DATA, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 626 | PRIM_OP_INDICATION, msg); |
| 627 | nsi->cb(&nsp.oph, nsi->cb_data); |
| 628 | } |
| 629 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 630 | static void ns2_vc_fsm_allstate_action(struct osmo_fsm_inst *fi, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 631 | uint32_t event, |
| 632 | void *data) |
| 633 | { |
| 634 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 635 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
Alexander Couzens | a7a757f | 2021-09-07 01:22:53 +0200 | [diff] [blame] | 636 | struct tlv_parsed *tp; |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 637 | struct msgb *msg = data; |
Alexander Couzens | a7a757f | 2021-09-07 01:22:53 +0200 | [diff] [blame] | 638 | uint8_t cause; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 639 | |
| 640 | switch (event) { |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 641 | case GPRS_NS2_EV_REQ_OM_RESET: |
| 642 | if (priv->nsvc->mode != GPRS_NS2_VC_MODE_BLOCKRESET) |
| 643 | break; |
| 644 | /* move the FSM into reset */ |
| 645 | if (fi->state != GPRS_NS2_ST_RESET) { |
| 646 | priv->initiate_reset = true; |
| 647 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], NS_TOUT_TNS_RESET); |
| 648 | } |
| 649 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 650 | case GPRS_NS2_EV_RX_RESET: |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 651 | if (priv->nsvc->mode != GPRS_NS2_VC_MODE_BLOCKRESET) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 652 | break; |
| 653 | |
| 654 | /* move the FSM into reset */ |
| 655 | if (fi->state != GPRS_NS2_ST_RESET) { |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 656 | priv->initiate_reset = false; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 657 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], NS_TOUT_TNS_RESET); |
| 658 | } |
| 659 | /* pass the event down into FSM action */ |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 660 | ns2_st_reset(fi, event, data); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 661 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 662 | case GPRS_NS2_EV_RX_ALIVE: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 663 | switch (fi->state) { |
| 664 | case GPRS_NS2_ST_UNCONFIGURED: |
| 665 | case GPRS_NS2_ST_RESET: |
| 666 | /* ignore ALIVE */ |
| 667 | break; |
| 668 | default: |
| 669 | ns2_tx_alive_ack(priv->nsvc); |
| 670 | } |
| 671 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 672 | case GPRS_NS2_EV_RX_ALIVE_ACK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 673 | /* for VCs without RESET/BLOCK/UNBLOCK, the connections comes after ALIVE_ACK unblocked */ |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 674 | if (fi->state == GPRS_NS2_ST_RECOVERING) |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 675 | ns2_st_alive(fi, event, data); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 676 | else |
| 677 | recv_test_procedure(fi); |
| 678 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 679 | case GPRS_NS2_EV_RX_UNITDATA: |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 680 | /* UNITDATA has to handle the release of msg. |
| 681 | * If send upwards (gprs_ns2_recv_unitdata) it must NOT free |
| 682 | * the msg, the upper layer has to do it. |
| 683 | * Otherwise the msg must be freed. |
| 684 | */ |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 685 | |
| 686 | LOG_NS_DATA(priv->nsvc, "Rx", NS_PDUT_UNITDATA, LOGL_INFO, "\n"); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 687 | switch (fi->state) { |
| 688 | case GPRS_NS2_ST_BLOCKED: |
| 689 | /* 7.2.1: the BLOCKED_ACK might be lost */ |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 690 | if (priv->accept_unitdata) { |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 691 | ns2_recv_unitdata(fi, msg); |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 692 | return; |
| 693 | } |
| 694 | |
| 695 | ns2_tx_status(priv->nsvc, |
| 696 | NS_CAUSE_NSVC_BLOCKED, |
Alexander Couzens | d802f9a | 2021-09-23 16:19:32 +0200 | [diff] [blame] | 697 | 0, msg, NULL); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 698 | break; |
| 699 | /* ALIVE can receive UNITDATA if the ALIVE_ACK is lost */ |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 700 | case GPRS_NS2_ST_RECOVERING: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 701 | case GPRS_NS2_ST_UNBLOCKED: |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 702 | ns2_recv_unitdata(fi, msg); |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 703 | return; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 704 | } |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 705 | |
| 706 | msgb_free(msg); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 707 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 708 | case GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED: |
Alexander Couzens | 6f3b738 | 2020-12-21 15:57:04 +0100 | [diff] [blame] | 709 | if (fi->state != GPRS_NS2_ST_UNCONFIGURED) { |
| 710 | /* Force the NSVC back to its initial state */ |
| 711 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNCONFIGURED, 0, 0); |
Alexander Couzens | 6f3b738 | 2020-12-21 15:57:04 +0100 | [diff] [blame] | 712 | return; |
| 713 | } |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 714 | break; |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 715 | case GPRS_NS2_EV_REQ_OM_BLOCK: |
| 716 | /* vty cmd: block */ |
| 717 | priv->initiate_block = true; |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 718 | priv->nsvc->om_blocked = true; |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 719 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0); |
| 720 | break; |
| 721 | case GPRS_NS2_EV_REQ_OM_UNBLOCK: |
| 722 | /* vty cmd: unblock*/ |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 723 | if (!priv->nsvc->om_blocked) |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 724 | return; |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 725 | priv->nsvc->om_blocked = false; |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 726 | if (fi->state == GPRS_NS2_ST_BLOCKED) |
| 727 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0); |
| 728 | break; |
Alexander Couzens | a7a757f | 2021-09-07 01:22:53 +0200 | [diff] [blame] | 729 | case GPRS_NS2_EV_RX_STATUS: |
| 730 | tp = data; |
| 731 | cause = tlvp_val8(tp, NS_IE_CAUSE, 0); |
| 732 | switch (cause) { |
| 733 | case NS_CAUSE_NSVC_BLOCKED: |
| 734 | if (fi->state != GPRS_NS2_ST_BLOCKED) { |
| 735 | LOG_NS_SIGNAL(priv->nsvc, "Rx", NS_PDUT_STATUS, LOGL_ERROR, ": remote side reported blocked state.\n"); |
| 736 | priv->initiate_block = false; |
| 737 | priv->accept_unitdata = false; |
| 738 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0); |
| 739 | } |
| 740 | break; |
| 741 | case NS_CAUSE_NSVC_UNKNOWN: |
| 742 | if (fi->state != GPRS_NS2_ST_RESET && fi->state != GPRS_NS2_ST_UNCONFIGURED) { |
| 743 | LOG_NS_SIGNAL(priv->nsvc, "Rx", NS_PDUT_STATUS, LOGL_ERROR, ": remote side reported unknown nsvc.\n"); |
| 744 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 745 | } |
| 746 | break; |
| 747 | } |
| 748 | |
| 749 | break; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 753 | static void ns2_vc_fsm_clean(struct osmo_fsm_inst *fi, |
Alexander Couzens | 0346b64 | 2020-10-27 13:05:56 +0100 | [diff] [blame] | 754 | enum osmo_fsm_term_cause cause) |
| 755 | { |
| 756 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 757 | |
| 758 | osmo_timer_del(&priv->alive.timer); |
| 759 | } |
| 760 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 761 | static struct osmo_fsm ns2_vc_fsm = { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 762 | .name = "GPRS-NS2-VC", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 763 | .states = ns2_vc_states, |
| 764 | .num_states = ARRAY_SIZE(ns2_vc_states), |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 765 | .allstate_event_mask = S(GPRS_NS2_EV_RX_UNITDATA) | |
| 766 | S(GPRS_NS2_EV_RX_RESET) | |
| 767 | S(GPRS_NS2_EV_RX_ALIVE) | |
| 768 | S(GPRS_NS2_EV_RX_ALIVE_ACK) | |
Alexander Couzens | a7a757f | 2021-09-07 01:22:53 +0200 | [diff] [blame] | 769 | S(GPRS_NS2_EV_RX_STATUS) | |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 770 | S(GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED) | |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 771 | S(GPRS_NS2_EV_REQ_OM_RESET) | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 772 | S(GPRS_NS2_EV_REQ_OM_BLOCK) | |
| 773 | S(GPRS_NS2_EV_REQ_OM_UNBLOCK), |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 774 | .allstate_action = ns2_vc_fsm_allstate_action, |
| 775 | .cleanup = ns2_vc_fsm_clean, |
| 776 | .timer_cb = ns2_vc_fsm_timer_cb, |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 777 | .event_names = ns2_vc_event_names, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 778 | .pre_term = NULL, |
| 779 | .log_subsys = DLNS, |
| 780 | }; |
| 781 | |
| 782 | /*! |
| 783 | * \brief gprs_ns2_vc_fsm_alloc |
| 784 | * \param ctx |
| 785 | * \param vc |
| 786 | * \param id a char representation of the virtual curcuit |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 787 | * \param initiator initiator is the site which starts the connection. Usually the BSS. |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 788 | * \return NULL on error, otherwise the fsm |
| 789 | */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 790 | struct osmo_fsm_inst *ns2_vc_fsm_alloc(struct gprs_ns2_vc *nsvc, |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 791 | const char *id, bool initiator) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 792 | { |
| 793 | struct osmo_fsm_inst *fi; |
| 794 | struct gprs_ns2_vc_priv *priv; |
| 795 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 796 | fi = osmo_fsm_inst_alloc(&ns2_vc_fsm, nsvc, NULL, LOGL_DEBUG, id); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 797 | if (!fi) |
| 798 | return fi; |
| 799 | |
| 800 | nsvc->fi = fi; |
| 801 | priv = fi->priv = talloc_zero(fi, struct gprs_ns2_vc_priv); |
| 802 | priv->nsvc = nsvc; |
Alexander Couzens | ea01bf2 | 2021-01-18 14:01:01 +0100 | [diff] [blame] | 803 | priv->initiator = initiator; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 804 | |
| 805 | osmo_timer_setup(&priv->alive.timer, alive_timeout_handler, fi); |
| 806 | |
| 807 | return fi; |
| 808 | } |
| 809 | |
Harald Welte | 5bef2cc | 2020-09-18 22:33:24 +0200 | [diff] [blame] | 810 | /*! Start a NS-VC FSM. |
| 811 | * \param nsvc the virtual circuit |
| 812 | * \return 0 on success; negative on error */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 813 | int ns2_vc_fsm_start(struct gprs_ns2_vc *nsvc) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 814 | { |
| 815 | /* allows to call this function even for started nsvc by gprs_ns2_start_alive_all_nsvcs */ |
| 816 | if (nsvc->fi->state == GPRS_NS2_ST_UNCONFIGURED) |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 817 | return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_START, NULL); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 818 | return 0; |
| 819 | } |
| 820 | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 821 | /*! Reset a NS-VC FSM. |
| 822 | * \param nsvc the virtual circuit |
| 823 | * \return 0 on success; negative on error */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 824 | int ns2_vc_force_unconfigured(struct gprs_ns2_vc *nsvc) |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 825 | { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 826 | return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED, NULL); |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 827 | } |
| 828 | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 829 | /*! Block a NS-VC. |
| 830 | * \param nsvc the virtual circuit |
| 831 | * \return 0 on success; negative on error */ |
| 832 | int ns2_vc_block(struct gprs_ns2_vc *nsvc) |
| 833 | { |
Alexander Couzens | e7dfeac | 2021-03-21 17:28:36 +0100 | [diff] [blame] | 834 | struct gprs_ns2_vc_priv *priv = nsvc->fi->priv; |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 835 | if (priv->nsvc->om_blocked) |
Alexander Couzens | e7dfeac | 2021-03-21 17:28:36 +0100 | [diff] [blame] | 836 | return -EALREADY; |
| 837 | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 838 | return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_OM_BLOCK, NULL); |
| 839 | } |
| 840 | |
| 841 | /*! Unblock a NS-VC. |
| 842 | * \param nsvc the virtual circuit |
| 843 | * \return 0 on success; negative on error */ |
| 844 | int ns2_vc_unblock(struct gprs_ns2_vc *nsvc) |
| 845 | { |
Alexander Couzens | e7dfeac | 2021-03-21 17:28:36 +0100 | [diff] [blame] | 846 | struct gprs_ns2_vc_priv *priv = nsvc->fi->priv; |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 847 | if (!priv->nsvc->om_blocked) |
Alexander Couzens | e7dfeac | 2021-03-21 17:28:36 +0100 | [diff] [blame] | 848 | return -EALREADY; |
| 849 | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 850 | return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_OM_UNBLOCK, NULL); |
| 851 | } |
| 852 | |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 853 | /*! Reset a NS-VC. |
| 854 | * \param nsvc the virtual circuit |
| 855 | * \return 0 on success; negative on error */ |
| 856 | int ns2_vc_reset(struct gprs_ns2_vc *nsvc) |
| 857 | { |
| 858 | return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_OM_RESET, NULL); |
| 859 | } |
| 860 | |
Harald Welte | 5bef2cc | 2020-09-18 22:33:24 +0200 | [diff] [blame] | 861 | /*! entry point for messages from the driver/VL |
| 862 | * \param nsvc virtual circuit on which the message was received |
| 863 | * \param msg message that was received |
| 864 | * \param tp parsed TLVs of the received message |
| 865 | * \return 0 on success; negative on error */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 866 | int ns2_vc_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 867 | { |
| 868 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
Alexander Couzens | 69cc4b6 | 2021-09-07 16:33:08 +0200 | [diff] [blame] | 869 | struct gprs_ns2_vc *target_nsvc = nsvc; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 870 | struct osmo_fsm_inst *fi = nsvc->fi; |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 871 | int rc = 0; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 872 | uint8_t cause; |
Alexander Couzens | 3f576ab | 2021-01-20 14:50:31 +0100 | [diff] [blame] | 873 | uint16_t nsei, nsvci; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 874 | |
| 875 | /* TODO: 7.2: on UNBLOCK/BLOCK: check if NS-VCI is correct, |
| 876 | * if not answer STATUS with "NS-VC unknown" */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 877 | /* TODO: handle BLOCK/UNBLOCK/ALIVE with different VCI */ |
| 878 | |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 879 | if (ns2_validate(nsvc, nsh->pdu_type, msg, tp, &cause)) { |
Alexander Couzens | cc1621e | 2021-09-07 15:30:26 +0200 | [diff] [blame] | 880 | /* don't answer on a STATUS with a STATUS */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 881 | if (nsh->pdu_type != NS_PDUT_STATUS) { |
Alexander Couzens | d802f9a | 2021-09-23 16:19:32 +0200 | [diff] [blame] | 882 | rc = ns2_tx_status(nsvc, cause, 0, msg, NULL); |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 883 | goto out; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
Alexander Couzens | 43771df | 2021-01-20 13:03:03 +0100 | [diff] [blame] | 887 | if (TLVP_PRESENT(tp, NS_IE_NSEI)) { |
| 888 | nsei = tlvp_val16be(tp, NS_IE_NSEI); |
| 889 | if (nsei != nsvc->nse->nsei) { |
| 890 | /* 48.016 ยง 7.3.1 send, RESET_ACK to wrong NSVCI + ignore */ |
| 891 | if (nsh->pdu_type == NS_PDUT_RESET) |
| 892 | ns2_tx_reset_ack(nsvc); |
| 893 | |
Alexander Couzens | f8635c7 | 2021-10-12 18:58:31 +0200 | [diff] [blame] | 894 | LOG_NS_SIGNAL(nsvc, "Rx", nsh->pdu_type, LOGL_ERROR, " with wrong NSEI (exp: %05u, got %05u). Ignoring PDU.\n", nsvc->nse->nsei, nsei); |
Alexander Couzens | 43771df | 2021-01-20 13:03:03 +0100 | [diff] [blame] | 895 | goto out; |
| 896 | } |
| 897 | } |
| 898 | |
Alexander Couzens | e787333 | 2021-09-06 18:17:41 +0200 | [diff] [blame] | 899 | if (nsvc->nsvci_is_valid && TLVP_PRESENT(tp, NS_IE_VCI)) { |
Alexander Couzens | 3f576ab | 2021-01-20 14:50:31 +0100 | [diff] [blame] | 900 | nsvci = tlvp_val16be(tp, NS_IE_VCI); |
| 901 | if (nsvci != nsvc->nsvci) { |
| 902 | /* 48.016 ยง 7.3.1 send RESET_ACK to wrong NSVCI + ignore */ |
Alexander Couzens | 69cc4b6 | 2021-09-07 16:33:08 +0200 | [diff] [blame] | 903 | if (nsh->pdu_type == NS_PDUT_RESET) { |
Alexander Couzens | 3f576ab | 2021-01-20 14:50:31 +0100 | [diff] [blame] | 904 | ns2_tx_reset_ack(nsvc); |
Alexander Couzens | 58be427 | 2021-10-12 18:57:06 +0200 | [diff] [blame] | 905 | LOG_NS_SIGNAL(nsvc, "Rx", nsh->pdu_type, LOGL_ERROR, " with wrong NSVCI (exp: %05u, got %05u). Ignoring PDU.\n", nsvc->nsvci, nsvci); |
| 906 | goto out; |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 907 | } else if (nsh->pdu_type == NS_PDUT_BLOCK || nsh->pdu_type == NS_PDUT_STATUS) { |
| 908 | /* this is a PDU received over a NSVC and reports a status/block for another NSVC */ |
Alexander Couzens | 69cc4b6 | 2021-09-07 16:33:08 +0200 | [diff] [blame] | 909 | target_nsvc = gprs_ns2_nsvc_by_nsvci(nsvc->nse->nsi, nsvci); |
| 910 | if (!target_nsvc) { |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 911 | LOGPFSML(fi, LOGL_ERROR, "Received a %s PDU for unknown NSVC (NSVCI %d)\n", |
| 912 | get_value_string(gprs_ns_pdu_strings, nsh->pdu_type), nsvci); |
| 913 | if (nsh->pdu_type == NS_PDUT_BLOCK) |
| 914 | ns2_tx_status(nsvc, NS_CAUSE_NSVC_UNKNOWN, 0, msg, &nsvci); |
Alexander Couzens | 69cc4b6 | 2021-09-07 16:33:08 +0200 | [diff] [blame] | 915 | goto out; |
| 916 | } |
Alexander Couzens | 3f576ab | 2021-01-20 14:50:31 +0100 | [diff] [blame] | 917 | |
Alexander Couzens | 69cc4b6 | 2021-09-07 16:33:08 +0200 | [diff] [blame] | 918 | if (target_nsvc->nse != nsvc->nse) { |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 919 | LOGPFSML(fi, LOGL_ERROR, "Received a %s PDU for a NSVC (NSVCI %d) but it belongs to a different NSE!\n", |
| 920 | get_value_string(gprs_ns_pdu_strings, nsh->pdu_type), nsvci); |
Alexander Couzens | 69cc4b6 | 2021-09-07 16:33:08 +0200 | [diff] [blame] | 921 | goto out; |
| 922 | } |
| 923 | |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 924 | /* the status/block will be passed to the nsvc/target nsvc in the switch */ |
Alexander Couzens | 69cc4b6 | 2021-09-07 16:33:08 +0200 | [diff] [blame] | 925 | } else { |
| 926 | LOG_NS_SIGNAL(nsvc, "Rx", nsh->pdu_type, LOGL_ERROR, " with wrong NSVCI=%05u. Ignoring PDU.\n", nsvci); |
| 927 | goto out; |
| 928 | } |
Alexander Couzens | 3f576ab | 2021-01-20 14:50:31 +0100 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 932 | switch (nsh->pdu_type) { |
| 933 | case NS_PDUT_RESET: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 934 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_RESET, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 935 | break; |
| 936 | case NS_PDUT_RESET_ACK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 937 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_RESET_ACK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 938 | break; |
| 939 | case NS_PDUT_BLOCK: |
Alexander Couzens | 4ef56c0 | 2021-09-07 16:33:30 +0200 | [diff] [blame] | 940 | if (target_nsvc != nsvc) { |
| 941 | osmo_fsm_inst_dispatch(target_nsvc->fi, GPRS_NS2_EV_RX_BLOCK_FOREIGN, tp); |
| 942 | ns2_tx_block_ack(nsvc, &nsvci); |
| 943 | } else { |
| 944 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_BLOCK, tp); |
| 945 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 946 | break; |
| 947 | case NS_PDUT_BLOCK_ACK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 948 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_BLOCK_ACK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 949 | break; |
| 950 | case NS_PDUT_UNBLOCK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 951 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_UNBLOCK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 952 | break; |
| 953 | case NS_PDUT_UNBLOCK_ACK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 954 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_UNBLOCK_ACK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 955 | break; |
| 956 | case NS_PDUT_ALIVE: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 957 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_ALIVE, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 958 | break; |
| 959 | case NS_PDUT_ALIVE_ACK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 960 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_ALIVE_ACK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 961 | break; |
| 962 | case NS_PDUT_UNITDATA: |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 963 | /* UNITDATA have to free msg because it might send the msg layer upwards */ |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 964 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_UNITDATA, msg); |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 965 | return 0; |
Alexander Couzens | a7a757f | 2021-09-07 01:22:53 +0200 | [diff] [blame] | 966 | case NS_PDUT_STATUS: |
Alexander Couzens | 69cc4b6 | 2021-09-07 16:33:08 +0200 | [diff] [blame] | 967 | osmo_fsm_inst_dispatch(target_nsvc->fi, GPRS_NS2_EV_RX_STATUS, tp); |
Alexander Couzens | a7a757f | 2021-09-07 01:22:53 +0200 | [diff] [blame] | 968 | break; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 969 | default: |
Harald Welte | f294974 | 2021-01-20 14:54:14 +0100 | [diff] [blame] | 970 | LOGPFSML(fi, LOGL_ERROR, "NSEI=%u Rx unknown NS PDU type %s\n", nsvc->nse->nsei, |
| 971 | get_value_string(gprs_ns_pdu_strings, nsh->pdu_type)); |
Alexander Couzens | 7619ed4 | 2021-03-24 17:44:03 +0100 | [diff] [blame] | 972 | rc = -EINVAL; |
| 973 | break; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 974 | } |
| 975 | |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 976 | out: |
| 977 | msgb_free(msg); |
| 978 | |
| 979 | return rc; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 980 | } |
| 981 | |
Harald Welte | 5bef2cc | 2020-09-18 22:33:24 +0200 | [diff] [blame] | 982 | /*! is the given NS-VC unblocked? */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 983 | int ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 984 | { |
| 985 | return (nsvc->fi->state == GPRS_NS2_ST_UNBLOCKED); |
| 986 | } |
| 987 | |
| 988 | /* initialize osmo_ctx on main tread */ |
| 989 | static __attribute__((constructor)) void on_dso_load_ctx(void) |
| 990 | { |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 991 | OSMO_ASSERT(osmo_fsm_register(&ns2_vc_fsm) == 0); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 992 | } |