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