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 blocked by O&M/vty */ |
| 62 | bool om_blocked; |
| 63 | /* if unitdata is forwarded to the user */ |
| 64 | bool accept_unitdata; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 65 | |
| 66 | /* the alive counter is present in all states */ |
| 67 | struct { |
| 68 | struct osmo_timer_list timer; |
| 69 | enum ns2_timeout mode; |
| 70 | int N; |
Alexander Couzens | ab0e864 | 2021-02-12 02:50:44 +0100 | [diff] [blame] | 71 | struct timespec timer_started; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 72 | } alive; |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | /* The FSM covers both the VC with RESET/BLOCK and without RESET/BLOCK procedure.. |
| 77 | * |
| 78 | * With RESET/BLOCK, the state should follow: |
| 79 | * - UNCONFIGURED -> RESET -> BLOCK -> UNBLOCKED |
| 80 | * |
| 81 | * Without RESET/BLOCK, the state should follow: |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 82 | * - UNCONFIGURED -> RECOVERY -> UNBLOCKED |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 83 | * |
| 84 | * The UNBLOCKED and TEST states are used to send ALIVE PDU using the timeout Tns-test and Tns-alive. |
| 85 | * UNBLOCKED -> TEST: on expire of Tns-Test, send Alive PDU. |
| 86 | * TEST -> UNBLOCKED: on receive of Alive_Ack PDU, go into UNBLOCKED. |
| 87 | * |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 88 | * 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] | 89 | * not using RESET/BLOCK procedure. |
| 90 | */ |
| 91 | |
| 92 | enum gprs_ns2_vc_state { |
| 93 | GPRS_NS2_ST_UNCONFIGURED, |
| 94 | GPRS_NS2_ST_RESET, |
| 95 | GPRS_NS2_ST_BLOCKED, |
| 96 | GPRS_NS2_ST_UNBLOCKED, /* allows sending NS_UNITDATA */ |
| 97 | |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 98 | GPRS_NS2_ST_RECOVERING, /* only used when not using RESET/BLOCK procedure */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | enum gprs_ns2_vc_event { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 102 | GPRS_NS2_EV_REQ_START, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 103 | |
| 104 | /* received messages */ |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 105 | GPRS_NS2_EV_RX_RESET, |
| 106 | GPRS_NS2_EV_RX_RESET_ACK, |
| 107 | GPRS_NS2_EV_RX_UNBLOCK, |
| 108 | GPRS_NS2_EV_RX_UNBLOCK_ACK, |
| 109 | GPRS_NS2_EV_RX_BLOCK, |
| 110 | GPRS_NS2_EV_RX_BLOCK_ACK, |
| 111 | GPRS_NS2_EV_RX_ALIVE, |
| 112 | GPRS_NS2_EV_RX_ALIVE_ACK, |
| 113 | GPRS_NS2_EV_RX_STATUS, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 114 | |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 115 | GPRS_NS2_EV_RX_UNITDATA, |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 116 | |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 117 | GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED, /* called via vty for tests */ |
| 118 | GPRS_NS2_EV_REQ_OM_BLOCK, /* vty cmd: block */ |
| 119 | GPRS_NS2_EV_REQ_OM_UNBLOCK, /* vty cmd: unblock*/ |
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" }, |
| 129 | { GPRS_NS2_EV_RX_BLOCK_ACK, "RX-BLOCK_ACK" }, |
| 130 | { GPRS_NS2_EV_RX_ALIVE, "RX-ALIVE" }, |
| 131 | { GPRS_NS2_EV_RX_ALIVE_ACK, "RX-ALIVE_ACK" }, |
| 132 | { GPRS_NS2_EV_RX_STATUS, "RX-STATUS" }, |
| 133 | { GPRS_NS2_EV_RX_UNITDATA, "RX-UNITDATA" }, |
| 134 | { GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED, "REQ-FORCE_UNCONFIGURED" }, |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 135 | { GPRS_NS2_EV_REQ_OM_BLOCK, "REQ-O&M-BLOCK"}, |
| 136 | { GPRS_NS2_EV_REQ_OM_UNBLOCK, "REQ-O&M-UNBLOCK"}, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 137 | { 0, NULL } |
| 138 | }; |
| 139 | |
| 140 | static inline struct gprs_ns2_inst *ns_inst_from_fi(struct osmo_fsm_inst *fi) |
| 141 | { |
| 142 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 143 | return priv->nsvc->nse->nsi; |
| 144 | } |
| 145 | |
| 146 | static void start_test_procedure(struct gprs_ns2_vc_priv *priv) |
| 147 | { |
| 148 | struct gprs_ns2_inst *nsi = priv->nsvc->nse->nsi; |
| 149 | |
| 150 | if (osmo_timer_pending(&priv->alive.timer)) |
| 151 | return; |
| 152 | |
| 153 | priv->alive.mode = NS_TOUT_TNS_ALIVE; |
| 154 | priv->alive.N = 0; |
| 155 | |
Alexander Couzens | ab0e864 | 2021-02-12 02:50:44 +0100 | [diff] [blame] | 156 | osmo_clock_gettime(CLOCK_MONOTONIC, &priv->alive.timer_started); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 157 | ns2_tx_alive(priv->nsvc); |
| 158 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0); |
| 159 | } |
| 160 | |
| 161 | static void stop_test_procedure(struct gprs_ns2_vc_priv *priv) |
| 162 | { |
| 163 | osmo_timer_del(&priv->alive.timer); |
| 164 | } |
| 165 | |
| 166 | static int alive_timer_elapsed_ms(struct gprs_ns2_vc_priv *priv) |
| 167 | { |
Alexander Couzens | ab0e864 | 2021-02-12 02:50:44 +0100 | [diff] [blame] | 168 | struct timespec now, elapsed; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 169 | |
Alexander Couzens | ab0e864 | 2021-02-12 02:50:44 +0100 | [diff] [blame] | 170 | if (osmo_clock_gettime(CLOCK_MONOTONIC, &now) != 0) |
| 171 | return 0; |
| 172 | |
| 173 | timespecsub(&now, &priv->alive.timer_started, &elapsed); |
Alexander Couzens | ab0e864 | 2021-02-12 02:50:44 +0100 | [diff] [blame] | 174 | return elapsed.tv_sec * 1000 + (elapsed.tv_nsec / 1000000); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void recv_test_procedure(struct osmo_fsm_inst *fi) |
| 178 | { |
| 179 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 180 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 181 | struct gprs_ns2_vc *nsvc = priv->nsvc; |
| 182 | |
| 183 | /* ignoring ACKs without sending an ALIVE */ |
| 184 | if (priv->alive.mode != NS_TOUT_TNS_ALIVE) |
| 185 | return; |
| 186 | |
| 187 | priv->alive.mode = NS_TOUT_TNS_TEST; |
| 188 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_TEST], 0); |
| 189 | osmo_stat_item_set(nsvc->statg->items[NS_STAT_ALIVE_DELAY], |
| 190 | alive_timer_elapsed_ms(priv)); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | static void alive_timeout_handler(void *data) |
| 195 | { |
| 196 | struct osmo_fsm_inst *fi = data; |
| 197 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 198 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 199 | |
| 200 | switch (priv->alive.mode) { |
| 201 | case NS_TOUT_TNS_TEST: |
| 202 | priv->alive.mode = NS_TOUT_TNS_ALIVE; |
Alexander Couzens | 2f8f7b6 | 2021-02-03 11:04:22 +0100 | [diff] [blame] | 203 | priv->alive.N = 0; |
Alexander Couzens | fa4121d | 2021-02-12 02:54:46 +0100 | [diff] [blame] | 204 | osmo_clock_gettime(CLOCK_MONOTONIC, &priv->alive.timer_started); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 205 | ns2_tx_alive(priv->nsvc); |
| 206 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0); |
| 207 | break; |
| 208 | case NS_TOUT_TNS_ALIVE: |
Harald Welte | 4c54f59 | 2021-01-30 22:42:15 +0100 | [diff] [blame] | 209 | rate_ctr_inc(&priv->nsvc->ctrg->ctr[NS_CTR_LOST_ALIVE]); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 210 | priv->alive.N++; |
| 211 | |
| 212 | if (priv->alive.N <= nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) { |
| 213 | /* retransmission */ |
| 214 | ns2_tx_alive(priv->nsvc); |
| 215 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0); |
| 216 | } else { |
| 217 | /* lost connection */ |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 218 | if (priv->nsvc->mode == GPRS_NS2_VC_MODE_BLOCKRESET) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 219 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 220 | } else { |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 221 | 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] | 222 | } |
| 223 | } |
| 224 | break; |
| 225 | default: |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | |
Harald Welte | 6a9ec42 | 2021-01-31 18:56:29 +0100 | [diff] [blame] | 230 | |
| 231 | static void ns2_st_unconfigured_onenter(struct osmo_fsm_inst *fi, uint32_t old_state) |
| 232 | { |
| 233 | stop_test_procedure(fi->priv); |
| 234 | } |
| 235 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 236 | 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] | 237 | { |
| 238 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 239 | struct gprs_ns2_inst *nsi = priv->nsvc->nse->nsi; |
| 240 | |
Alexander Couzens | ea01bf2 | 2021-01-18 14:01:01 +0100 | [diff] [blame] | 241 | priv->initiate_reset = priv->initiate_block = priv->initiator; |
| 242 | priv->om_blocked = false; |
| 243 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 244 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 245 | case GPRS_NS2_EV_REQ_START: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 246 | switch (priv->nsvc->mode) { |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 247 | case GPRS_NS2_VC_MODE_ALIVE: |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 248 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, nsi->timeout[NS_TOUT_TNS_ALIVE], NS_TOUT_TNS_ALIVE); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 249 | break; |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 250 | case GPRS_NS2_VC_MODE_BLOCKRESET: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 251 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], NS_TOUT_TNS_RESET); |
| 252 | break; |
| 253 | } |
| 254 | |
| 255 | break; |
| 256 | default: |
| 257 | OSMO_ASSERT(0); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 262 | 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] | 263 | { |
| 264 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 265 | |
| 266 | if (old_state != GPRS_NS2_ST_RESET) |
| 267 | priv->N = 0; |
| 268 | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 269 | priv->accept_unitdata = false; |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 270 | if (priv->initiate_reset) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 271 | ns2_tx_reset(priv->nsvc, NS_CAUSE_OM_INTERVENTION); |
| 272 | |
| 273 | stop_test_procedure(priv); |
| 274 | ns2_nse_notify_unblocked(priv->nsvc, false); |
| 275 | } |
| 276 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 277 | 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] | 278 | { |
| 279 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 280 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 281 | |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 282 | if (priv->initiate_reset) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 283 | switch (event) { |
Alexander Couzens | 273f063 | 2021-01-20 13:11:26 +0100 | [diff] [blame] | 284 | case GPRS_NS2_EV_RX_RESET: |
| 285 | ns2_tx_reset_ack(priv->nsvc); |
| 286 | /* fall-through */ |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 287 | case GPRS_NS2_EV_RX_RESET_ACK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 288 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, |
| 289 | nsi->timeout[NS_TOUT_TNS_BLOCK], NS_TOUT_TNS_BLOCK); |
| 290 | break; |
| 291 | } |
| 292 | } else { |
| 293 | /* we are on the receiving end */ |
| 294 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 295 | case GPRS_NS2_EV_RX_RESET: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 296 | ns2_tx_reset_ack(priv->nsvc); |
| 297 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, |
| 298 | 0, 0); |
| 299 | break; |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 304 | 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] | 305 | { |
| 306 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 307 | |
Harald Welte | 4c54f59 | 2021-01-30 22:42:15 +0100 | [diff] [blame] | 308 | if (old_state != GPRS_NS2_ST_BLOCKED) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 309 | priv->N = 0; |
Harald Welte | 4c54f59 | 2021-01-30 22:42:15 +0100 | [diff] [blame] | 310 | rate_ctr_inc(&priv->nsvc->ctrg->ctr[NS_CTR_BLOCKED]); |
| 311 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 312 | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 313 | if (priv->om_blocked) { |
| 314 | /* we are already blocked after a RESET */ |
| 315 | if (old_state == GPRS_NS2_ST_RESET) { |
| 316 | osmo_timer_del(&fi->timer); |
| 317 | } else { |
| 318 | ns2_tx_block(priv->nsvc, NS_CAUSE_OM_INTERVENTION); |
| 319 | } |
| 320 | } else if (priv->initiate_block) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 321 | ns2_tx_unblock(priv->nsvc); |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 322 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 323 | |
| 324 | start_test_procedure(priv); |
| 325 | } |
| 326 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 327 | 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] | 328 | { |
| 329 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 330 | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 331 | if (priv->om_blocked) { |
| 332 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 333 | case GPRS_NS2_EV_RX_BLOCK_ACK: |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 334 | priv->accept_unitdata = false; |
| 335 | osmo_timer_del(&fi->timer); |
| 336 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 337 | case GPRS_NS2_EV_RX_BLOCK: |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 338 | priv->accept_unitdata = false; |
| 339 | ns2_tx_block_ack(priv->nsvc); |
| 340 | osmo_timer_del(&fi->timer); |
| 341 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 342 | case GPRS_NS2_EV_RX_UNBLOCK: |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 343 | priv->accept_unitdata = false; |
| 344 | ns2_tx_block(priv->nsvc, NS_CAUSE_OM_INTERVENTION); |
| 345 | osmo_timer_add(&fi->timer); |
| 346 | break; |
| 347 | } |
| 348 | } else if (priv->initiate_block) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 349 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 350 | case GPRS_NS2_EV_RX_BLOCK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 351 | /* TODO: BLOCK is a UNBLOCK_NACK */ |
| 352 | ns2_tx_block_ack(priv->nsvc); |
| 353 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 354 | case GPRS_NS2_EV_RX_UNBLOCK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 355 | ns2_tx_unblock_ack(priv->nsvc); |
| 356 | /* fall through */ |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 357 | case GPRS_NS2_EV_RX_UNBLOCK_ACK: |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 358 | priv->accept_unitdata = true; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 359 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, |
| 360 | 0, NS_TOUT_TNS_TEST); |
| 361 | break; |
| 362 | } |
| 363 | } else { |
| 364 | /* we are on the receiving end. The initiator who sent RESET is responsible to UNBLOCK! */ |
| 365 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 366 | case GPRS_NS2_EV_RX_BLOCK: |
Alexander Couzens | 856b94c | 2021-01-19 19:42:17 +0100 | [diff] [blame] | 367 | ns2_tx_block_ack(priv->nsvc); |
| 368 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 369 | case GPRS_NS2_EV_RX_UNBLOCK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 370 | ns2_tx_unblock_ack(priv->nsvc); |
| 371 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, |
| 372 | 0, 0); |
| 373 | break; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 378 | 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] | 379 | { |
| 380 | struct gprs_ns2_vc_priv *priv = fi->priv; |
Daniel Willmann | 15c09a8 | 2020-11-03 23:05:43 +0100 | [diff] [blame] | 381 | struct gprs_ns2_vc *nsvc = priv->nsvc; |
| 382 | struct gprs_ns2_nse *nse = nsvc->nse; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 383 | |
Harald Welte | b40bf8b | 2021-01-30 22:43:01 +0100 | [diff] [blame] | 384 | if (old_state != GPRS_NS2_ST_UNBLOCKED) |
| 385 | rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_UNBLOCKED]); |
| 386 | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 387 | priv->accept_unitdata = true; |
Daniel Willmann | 15c09a8 | 2020-11-03 23:05:43 +0100 | [diff] [blame] | 388 | ns2_nse_notify_unblocked(nsvc, true); |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 389 | ns2_prim_status_ind(nse, nsvc, 0, GPRS_NS2_AFF_CAUSE_VC_RECOVERY); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 390 | } |
| 391 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 392 | 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] | 393 | { |
| 394 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 395 | |
| 396 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 397 | case GPRS_NS2_EV_RX_UNBLOCK: |
Alexander Couzens | c4b7462 | 2021-01-10 20:44:26 +0100 | [diff] [blame] | 398 | ns2_tx_unblock_ack(priv->nsvc); |
| 399 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 400 | case GPRS_NS2_EV_RX_BLOCK: |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 401 | priv->initiate_block = false; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 402 | ns2_tx_block_ack(priv->nsvc); |
| 403 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, |
| 404 | 0, 2); |
| 405 | break; |
| 406 | } |
| 407 | } |
| 408 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 409 | 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] | 410 | { |
| 411 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 412 | case GPRS_NS2_EV_RX_ALIVE_ACK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 413 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, 0, 0); |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 418 | 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] | 419 | { |
| 420 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 421 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 422 | |
| 423 | priv->alive.mode = NS_TOUT_TNS_TEST; |
| 424 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_TEST], 0); |
| 425 | |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 426 | if (old_state != GPRS_NS2_ST_RECOVERING) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 427 | priv->N = 0; |
| 428 | |
| 429 | ns2_tx_alive(priv->nsvc); |
| 430 | ns2_nse_notify_unblocked(priv->nsvc, false); |
| 431 | } |
| 432 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 433 | static void ns2_st_alive_onleave(struct osmo_fsm_inst *fi, uint32_t next_state) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 434 | { |
| 435 | start_test_procedure(fi->priv); |
| 436 | } |
| 437 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 438 | static const struct osmo_fsm_state ns2_vc_states[] = { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 439 | [GPRS_NS2_ST_UNCONFIGURED] = { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 440 | .in_event_mask = S(GPRS_NS2_EV_REQ_START), |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 441 | .out_state_mask = S(GPRS_NS2_ST_RESET) | S(GPRS_NS2_ST_RECOVERING), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 442 | .name = "UNCONFIGURED", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 443 | .action = ns2_st_unconfigured, |
Harald Welte | 6a9ec42 | 2021-01-31 18:56:29 +0100 | [diff] [blame] | 444 | .onenter = ns2_st_unconfigured_onenter, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 445 | }, |
| 446 | [GPRS_NS2_ST_RESET] = { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 447 | .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] | 448 | .out_state_mask = S(GPRS_NS2_ST_RESET) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 449 | S(GPRS_NS2_ST_BLOCKED) | |
| 450 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 451 | .name = "RESET", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 452 | .action = ns2_st_reset, |
| 453 | .onenter = ns2_st_reset_onenter, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 454 | }, |
| 455 | [GPRS_NS2_ST_BLOCKED] = { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 456 | .in_event_mask = S(GPRS_NS2_EV_RX_BLOCK) | S(GPRS_NS2_EV_RX_BLOCK_ACK) | |
| 457 | S(GPRS_NS2_EV_RX_UNBLOCK) | S(GPRS_NS2_EV_RX_UNBLOCK_ACK), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 458 | .out_state_mask = S(GPRS_NS2_ST_RESET) | |
| 459 | S(GPRS_NS2_ST_UNBLOCKED) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 460 | S(GPRS_NS2_ST_BLOCKED) | |
| 461 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 462 | .name = "BLOCKED", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 463 | .action = ns2_st_blocked, |
| 464 | .onenter = ns2_st_blocked_onenter, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 465 | }, |
| 466 | [GPRS_NS2_ST_UNBLOCKED] = { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 467 | .in_event_mask = S(GPRS_NS2_EV_RX_BLOCK) | S(GPRS_NS2_EV_RX_UNBLOCK_ACK) | |
| 468 | S(GPRS_NS2_EV_RX_UNBLOCK), |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 469 | .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] | 470 | S(GPRS_NS2_ST_BLOCKED) | |
| 471 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 472 | .name = "UNBLOCKED", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 473 | .action = ns2_st_unblocked, |
| 474 | .onenter = ns2_st_unblocked_on_enter, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 475 | }, |
| 476 | |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 477 | /* ST_RECOVERING is only used on VC without RESET/BLOCK */ |
| 478 | [GPRS_NS2_ST_RECOVERING] = { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 479 | .in_event_mask = S(GPRS_NS2_EV_RX_ALIVE_ACK), |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 480 | .out_state_mask = S(GPRS_NS2_ST_RECOVERING) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 481 | S(GPRS_NS2_ST_UNBLOCKED) | |
| 482 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 483 | .name = "RECOVERING", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 484 | .action = ns2_st_alive, |
| 485 | .onenter = ns2_st_alive_onenter, |
| 486 | .onleave = ns2_st_alive_onleave, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 487 | }, |
| 488 | }; |
| 489 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 490 | static int ns2_vc_fsm_timer_cb(struct osmo_fsm_inst *fi) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 491 | { |
| 492 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 493 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 494 | |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 495 | switch (fi->state) { |
| 496 | case GPRS_NS2_ST_RESET: |
| 497 | if (priv->initiate_reset) { |
Harald Welte | 4c54f59 | 2021-01-30 22:42:15 +0100 | [diff] [blame] | 498 | rate_ctr_inc(&priv->nsvc->ctrg->ctr[NS_CTR_LOST_RESET]); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 499 | priv->N++; |
| 500 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_RESET_RETRIES]) { |
| 501 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 502 | } else { |
| 503 | priv->N = 0; |
| 504 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 505 | } |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 506 | } |
| 507 | break; |
| 508 | case GPRS_NS2_ST_BLOCKED: |
| 509 | if (priv->initiate_block) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 510 | priv->N++; |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 511 | if (priv->om_blocked) { |
| 512 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES]) { |
| 513 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0); |
| 514 | } else { |
| 515 | /* 7.2 stop accepting data when BLOCK PDU not responded */ |
| 516 | priv->accept_unitdata = false; |
| 517 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 518 | } else { |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 519 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES]) { |
| 520 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0); |
| 521 | } else { |
| 522 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 523 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 524 | } |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 525 | } |
| 526 | break; |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 527 | case GPRS_NS2_ST_RECOVERING: |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 528 | if (priv->initiate_reset) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 529 | priv->N++; |
| 530 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) { |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 531 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, 0, 0); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 532 | } else { |
| 533 | priv->N = 0; |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 534 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, 0, 0); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 535 | } |
| 536 | break; |
| 537 | } |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 538 | break; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 539 | } |
| 540 | return 0; |
| 541 | } |
| 542 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 543 | static void ns2_recv_unitdata(struct osmo_fsm_inst *fi, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 544 | struct msgb *msg) |
| 545 | { |
| 546 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 547 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 548 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
| 549 | struct osmo_gprs_ns2_prim nsp = {}; |
| 550 | uint16_t bvci; |
| 551 | |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 552 | if (msgb_l2len(msg) < sizeof(*nsh) + 3) { |
| 553 | msgb_free(msg); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 554 | return; |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 555 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 556 | |
| 557 | /* TODO: 7.1: For an IP sub-network, an NS-UNITDATA PDU |
| 558 | * for a PTP BVC may indicate a request to change the IP endpoint |
| 559 | * and/or a response to a change in the IP endpoint. */ |
| 560 | |
| 561 | /* TODO: nsh->data[0] -> C/R only valid in IP SNS */ |
| 562 | bvci = nsh->data[1] << 8 | nsh->data[2]; |
| 563 | |
Alexander Couzens | 89acdef | 2020-09-23 18:22:31 +0200 | [diff] [blame] | 564 | msg->l3h = &nsh->data[3]; |
| 565 | nsp.bvci = bvci; |
| 566 | nsp.nsei = priv->nsvc->nse->nsei; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 567 | |
Alexander Couzens | c1cd333 | 2020-09-23 23:24:02 +0200 | [diff] [blame] | 568 | /* 10.3.9 NS SDU Control Bits */ |
| 569 | if (nsh->data[0] & 0x1) |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 570 | nsp.u.unitdata.change = GPRS_NS2_ENDPOINT_REQUEST_CHANGE; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 571 | |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 572 | osmo_prim_init(&nsp.oph, SAP_NS, GPRS_NS2_PRIM_UNIT_DATA, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 573 | PRIM_OP_INDICATION, msg); |
| 574 | nsi->cb(&nsp.oph, nsi->cb_data); |
| 575 | } |
| 576 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 577 | static void ns2_vc_fsm_allstate_action(struct osmo_fsm_inst *fi, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 578 | uint32_t event, |
| 579 | void *data) |
| 580 | { |
| 581 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 582 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 583 | struct msgb *msg = data; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 584 | |
| 585 | switch (event) { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 586 | case GPRS_NS2_EV_RX_RESET: |
Alexander Couzens | 138b96f | 2021-01-25 16:23:29 +0100 | [diff] [blame] | 587 | if (priv->nsvc->mode != GPRS_NS2_VC_MODE_BLOCKRESET) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 588 | break; |
| 589 | |
| 590 | /* move the FSM into reset */ |
| 591 | if (fi->state != GPRS_NS2_ST_RESET) { |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 592 | priv->initiate_reset = false; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 593 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], NS_TOUT_TNS_RESET); |
| 594 | } |
| 595 | /* pass the event down into FSM action */ |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 596 | ns2_st_reset(fi, event, data); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 597 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 598 | case GPRS_NS2_EV_RX_ALIVE: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 599 | switch (fi->state) { |
| 600 | case GPRS_NS2_ST_UNCONFIGURED: |
| 601 | case GPRS_NS2_ST_RESET: |
| 602 | /* ignore ALIVE */ |
| 603 | break; |
| 604 | default: |
| 605 | ns2_tx_alive_ack(priv->nsvc); |
| 606 | } |
| 607 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 608 | case GPRS_NS2_EV_RX_ALIVE_ACK: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 609 | /* 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] | 610 | if (fi->state == GPRS_NS2_ST_RECOVERING) |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 611 | ns2_st_alive(fi, event, data); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 612 | else |
| 613 | recv_test_procedure(fi); |
| 614 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 615 | case GPRS_NS2_EV_RX_UNITDATA: |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 616 | /* UNITDATA has to handle the release of msg. |
| 617 | * If send upwards (gprs_ns2_recv_unitdata) it must NOT free |
| 618 | * the msg, the upper layer has to do it. |
| 619 | * Otherwise the msg must be freed. |
| 620 | */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 621 | switch (fi->state) { |
| 622 | case GPRS_NS2_ST_BLOCKED: |
| 623 | /* 7.2.1: the BLOCKED_ACK might be lost */ |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 624 | if (priv->accept_unitdata) { |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 625 | ns2_recv_unitdata(fi, msg); |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 626 | return; |
| 627 | } |
| 628 | |
| 629 | ns2_tx_status(priv->nsvc, |
| 630 | NS_CAUSE_NSVC_BLOCKED, |
| 631 | 0, msg); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 632 | break; |
| 633 | /* ALIVE can receive UNITDATA if the ALIVE_ACK is lost */ |
Alexander Couzens | d3e3110 | 2021-02-03 11:15:07 +0100 | [diff] [blame] | 634 | case GPRS_NS2_ST_RECOVERING: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 635 | case GPRS_NS2_ST_UNBLOCKED: |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 636 | ns2_recv_unitdata(fi, msg); |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 637 | return; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 638 | } |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 639 | |
| 640 | msgb_free(msg); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 641 | break; |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 642 | case GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED: |
Alexander Couzens | 6f3b738 | 2020-12-21 15:57:04 +0100 | [diff] [blame] | 643 | if (fi->state != GPRS_NS2_ST_UNCONFIGURED) { |
| 644 | /* Force the NSVC back to its initial state */ |
| 645 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNCONFIGURED, 0, 0); |
Alexander Couzens | 6f3b738 | 2020-12-21 15:57:04 +0100 | [diff] [blame] | 646 | return; |
| 647 | } |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 648 | break; |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 649 | case GPRS_NS2_EV_REQ_OM_BLOCK: |
| 650 | /* vty cmd: block */ |
| 651 | priv->initiate_block = true; |
| 652 | priv->om_blocked = true; |
| 653 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0); |
| 654 | break; |
| 655 | case GPRS_NS2_EV_REQ_OM_UNBLOCK: |
| 656 | /* vty cmd: unblock*/ |
| 657 | if (!priv->om_blocked) |
| 658 | return; |
| 659 | priv->om_blocked = false; |
| 660 | if (fi->state == GPRS_NS2_ST_BLOCKED) |
| 661 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0); |
| 662 | break; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 666 | static void ns2_vc_fsm_clean(struct osmo_fsm_inst *fi, |
Alexander Couzens | 0346b64 | 2020-10-27 13:05:56 +0100 | [diff] [blame] | 667 | enum osmo_fsm_term_cause cause) |
| 668 | { |
| 669 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 670 | |
| 671 | osmo_timer_del(&priv->alive.timer); |
| 672 | } |
| 673 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 674 | static struct osmo_fsm ns2_vc_fsm = { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 675 | .name = "GPRS-NS2-VC", |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 676 | .states = ns2_vc_states, |
| 677 | .num_states = ARRAY_SIZE(ns2_vc_states), |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 678 | .allstate_event_mask = S(GPRS_NS2_EV_RX_UNITDATA) | |
| 679 | S(GPRS_NS2_EV_RX_RESET) | |
| 680 | S(GPRS_NS2_EV_RX_ALIVE) | |
| 681 | S(GPRS_NS2_EV_RX_ALIVE_ACK) | |
| 682 | S(GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED) | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 683 | S(GPRS_NS2_EV_REQ_OM_BLOCK) | |
| 684 | S(GPRS_NS2_EV_REQ_OM_UNBLOCK), |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 685 | .allstate_action = ns2_vc_fsm_allstate_action, |
| 686 | .cleanup = ns2_vc_fsm_clean, |
| 687 | .timer_cb = ns2_vc_fsm_timer_cb, |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 688 | .event_names = ns2_vc_event_names, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 689 | .pre_term = NULL, |
| 690 | .log_subsys = DLNS, |
| 691 | }; |
| 692 | |
| 693 | /*! |
| 694 | * \brief gprs_ns2_vc_fsm_alloc |
| 695 | * \param ctx |
| 696 | * \param vc |
| 697 | * \param id a char representation of the virtual curcuit |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 698 | * \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] | 699 | * \return NULL on error, otherwise the fsm |
| 700 | */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 701 | 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] | 702 | const char *id, bool initiator) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 703 | { |
| 704 | struct osmo_fsm_inst *fi; |
| 705 | struct gprs_ns2_vc_priv *priv; |
| 706 | |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 707 | 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] | 708 | if (!fi) |
| 709 | return fi; |
| 710 | |
| 711 | nsvc->fi = fi; |
| 712 | priv = fi->priv = talloc_zero(fi, struct gprs_ns2_vc_priv); |
| 713 | priv->nsvc = nsvc; |
Alexander Couzens | ea01bf2 | 2021-01-18 14:01:01 +0100 | [diff] [blame] | 714 | priv->initiator = initiator; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 715 | |
| 716 | osmo_timer_setup(&priv->alive.timer, alive_timeout_handler, fi); |
| 717 | |
| 718 | return fi; |
| 719 | } |
| 720 | |
Harald Welte | 5bef2cc | 2020-09-18 22:33:24 +0200 | [diff] [blame] | 721 | /*! Start a NS-VC FSM. |
| 722 | * \param nsvc the virtual circuit |
| 723 | * \return 0 on success; negative on error */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 724 | int ns2_vc_fsm_start(struct gprs_ns2_vc *nsvc) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 725 | { |
| 726 | /* allows to call this function even for started nsvc by gprs_ns2_start_alive_all_nsvcs */ |
| 727 | if (nsvc->fi->state == GPRS_NS2_ST_UNCONFIGURED) |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 728 | 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] | 729 | return 0; |
| 730 | } |
| 731 | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 732 | /*! Reset a NS-VC FSM. |
| 733 | * \param nsvc the virtual circuit |
| 734 | * \return 0 on success; negative on error */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 735 | int ns2_vc_force_unconfigured(struct gprs_ns2_vc *nsvc) |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 736 | { |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 737 | 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] | 738 | } |
| 739 | |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 740 | /*! Block a NS-VC. |
| 741 | * \param nsvc the virtual circuit |
| 742 | * \return 0 on success; negative on error */ |
| 743 | int ns2_vc_block(struct gprs_ns2_vc *nsvc) |
| 744 | { |
| 745 | return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_OM_BLOCK, NULL); |
| 746 | } |
| 747 | |
| 748 | /*! Unblock a NS-VC. |
| 749 | * \param nsvc the virtual circuit |
| 750 | * \return 0 on success; negative on error */ |
| 751 | int ns2_vc_unblock(struct gprs_ns2_vc *nsvc) |
| 752 | { |
| 753 | return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_OM_UNBLOCK, NULL); |
| 754 | } |
| 755 | |
Harald Welte | 5bef2cc | 2020-09-18 22:33:24 +0200 | [diff] [blame] | 756 | /*! entry point for messages from the driver/VL |
| 757 | * \param nsvc virtual circuit on which the message was received |
| 758 | * \param msg message that was received |
| 759 | * \param tp parsed TLVs of the received message |
| 760 | * \return 0 on success; negative on error */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 761 | 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] | 762 | { |
| 763 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
| 764 | struct osmo_fsm_inst *fi = nsvc->fi; |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 765 | int rc = 0; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 766 | uint8_t cause; |
Alexander Couzens | 3f576ab | 2021-01-20 14:50:31 +0100 | [diff] [blame] | 767 | uint16_t nsei, nsvci; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 768 | |
| 769 | /* TODO: 7.2: on UNBLOCK/BLOCK: check if NS-VCI is correct, |
| 770 | * if not answer STATUS with "NS-VC unknown" */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 771 | /* TODO: handle BLOCK/UNBLOCK/ALIVE with different VCI */ |
| 772 | |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 773 | if (ns2_validate(nsvc, nsh->pdu_type, msg, tp, &cause)) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 774 | if (nsh->pdu_type != NS_PDUT_STATUS) { |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 775 | rc = ns2_tx_status(nsvc, cause, 0, msg); |
| 776 | goto out; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
Alexander Couzens | 43771df | 2021-01-20 13:03:03 +0100 | [diff] [blame] | 780 | if (TLVP_PRESENT(tp, NS_IE_NSEI)) { |
| 781 | nsei = tlvp_val16be(tp, NS_IE_NSEI); |
| 782 | if (nsei != nsvc->nse->nsei) { |
| 783 | /* 48.016 § 7.3.1 send, RESET_ACK to wrong NSVCI + ignore */ |
| 784 | if (nsh->pdu_type == NS_PDUT_RESET) |
| 785 | ns2_tx_reset_ack(nsvc); |
| 786 | |
| 787 | LOGNSVC(nsvc, LOGL_ERROR, "Rx %s with wrong NSEI=%05u. Ignoring PDU.\n", |
| 788 | get_value_string(gprs_ns_pdu_strings, nsh->pdu_type), nsei); |
| 789 | goto out; |
| 790 | } |
| 791 | } |
| 792 | |
Alexander Couzens | 3f576ab | 2021-01-20 14:50:31 +0100 | [diff] [blame] | 793 | if (nsvc->nsvci_is_valid && TLVP_PRESENT(tp, NS_IE_VCI)) { |
| 794 | nsvci = tlvp_val16be(tp, NS_IE_VCI); |
| 795 | if (nsvci != nsvc->nsvci) { |
| 796 | /* 48.016 § 7.3.1 send RESET_ACK to wrong NSVCI + ignore */ |
| 797 | if (nsh->pdu_type == NS_PDUT_RESET) |
| 798 | ns2_tx_reset_ack(nsvc); |
| 799 | |
| 800 | LOGNSVC(nsvc, LOGL_ERROR, "Rx %s with wrong NSVCI=%05u. Ignoring PDU.\n", |
| 801 | get_value_string(gprs_ns_pdu_strings, nsh->pdu_type), nsvci); |
| 802 | goto out; |
| 803 | } |
| 804 | } |
| 805 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 806 | switch (nsh->pdu_type) { |
| 807 | case NS_PDUT_RESET: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 808 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_RESET, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 809 | break; |
| 810 | case NS_PDUT_RESET_ACK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 811 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_RESET_ACK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 812 | break; |
| 813 | case NS_PDUT_BLOCK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 814 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_BLOCK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 815 | break; |
| 816 | case NS_PDUT_BLOCK_ACK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 817 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_BLOCK_ACK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 818 | break; |
| 819 | case NS_PDUT_UNBLOCK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 820 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_UNBLOCK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 821 | break; |
| 822 | case NS_PDUT_UNBLOCK_ACK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 823 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_UNBLOCK_ACK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 824 | break; |
| 825 | case NS_PDUT_ALIVE: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 826 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_ALIVE, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 827 | break; |
| 828 | case NS_PDUT_ALIVE_ACK: |
Alexander Couzens | f577543 | 2021-01-18 13:49:00 +0100 | [diff] [blame] | 829 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_ALIVE_ACK, tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 830 | break; |
| 831 | case NS_PDUT_UNITDATA: |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 832 | /* 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] | 833 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_UNITDATA, msg); |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 834 | return 0; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 835 | default: |
Harald Welte | f294974 | 2021-01-20 14:54:14 +0100 | [diff] [blame] | 836 | LOGPFSML(fi, LOGL_ERROR, "NSEI=%u Rx unknown NS PDU type %s\n", nsvc->nse->nsei, |
| 837 | get_value_string(gprs_ns_pdu_strings, nsh->pdu_type)); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 838 | return -EINVAL; |
| 839 | } |
| 840 | |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 841 | out: |
| 842 | msgb_free(msg); |
| 843 | |
| 844 | return rc; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 845 | } |
| 846 | |
Harald Welte | 5bef2cc | 2020-09-18 22:33:24 +0200 | [diff] [blame] | 847 | /*! is the given NS-VC unblocked? */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 848 | int ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 849 | { |
| 850 | return (nsvc->fi->state == GPRS_NS2_ST_UNBLOCKED); |
| 851 | } |
| 852 | |
| 853 | /* initialize osmo_ctx on main tread */ |
| 854 | static __attribute__((constructor)) void on_dso_load_ctx(void) |
| 855 | { |
Alexander Couzens | f7e2cac | 2021-01-25 16:18:21 +0100 | [diff] [blame] | 856 | OSMO_ASSERT(osmo_fsm_register(&ns2_vc_fsm) == 0); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 857 | } |