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.*/ |
| 60 | bool initiate_block; |
| 61 | bool initiate_reset; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 62 | |
| 63 | /* the alive counter is present in all states */ |
| 64 | struct { |
| 65 | struct osmo_timer_list timer; |
| 66 | enum ns2_timeout mode; |
| 67 | int N; |
| 68 | struct timeval timer_started; |
| 69 | } alive; |
| 70 | }; |
| 71 | |
| 72 | |
| 73 | /* The FSM covers both the VC with RESET/BLOCK and without RESET/BLOCK procedure.. |
| 74 | * |
| 75 | * With RESET/BLOCK, the state should follow: |
| 76 | * - UNCONFIGURED -> RESET -> BLOCK -> UNBLOCKED |
| 77 | * |
| 78 | * Without RESET/BLOCK, the state should follow: |
| 79 | * - UNCONFIGURED -> ALIVE -> UNBLOCKED |
| 80 | * |
| 81 | * The UNBLOCKED and TEST states are used to send ALIVE PDU using the timeout Tns-test and Tns-alive. |
| 82 | * UNBLOCKED -> TEST: on expire of Tns-Test, send Alive PDU. |
| 83 | * TEST -> UNBLOCKED: on receive of Alive_Ack PDU, go into UNBLOCKED. |
| 84 | * |
| 85 | * The ALIVE state is used as intermediate, because a VC is only valid if it received an Alive ACK when |
| 86 | * not using RESET/BLOCK procedure. |
| 87 | */ |
| 88 | |
| 89 | enum gprs_ns2_vc_state { |
| 90 | GPRS_NS2_ST_UNCONFIGURED, |
| 91 | GPRS_NS2_ST_RESET, |
| 92 | GPRS_NS2_ST_BLOCKED, |
| 93 | GPRS_NS2_ST_UNBLOCKED, /* allows sending NS_UNITDATA */ |
| 94 | |
| 95 | GPRS_NS2_ST_ALIVE, /* only used when not using RESET/BLOCK procedure */ |
| 96 | }; |
| 97 | |
| 98 | enum gprs_ns2_vc_event { |
| 99 | GPRS_NS2_EV_START, |
| 100 | |
| 101 | /* received messages */ |
| 102 | GPRS_NS2_EV_RESET, |
| 103 | GPRS_NS2_EV_RESET_ACK, |
| 104 | GPRS_NS2_EV_UNBLOCK, |
| 105 | GPRS_NS2_EV_UNBLOCK_ACK, |
| 106 | GPRS_NS2_EV_BLOCK, |
| 107 | GPRS_NS2_EV_BLOCK_ACK, |
| 108 | GPRS_NS2_EV_ALIVE, |
| 109 | GPRS_NS2_EV_ALIVE_ACK, |
| 110 | GPRS_NS2_EV_STATUS, |
| 111 | |
| 112 | GPRS_NS2_EV_UNITDATA, |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 113 | |
| 114 | GPRS_NS2_EV_FORCE_UNCONFIGURED, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | static const struct value_string gprs_ns2_vc_event_names[] = { |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 118 | { GPRS_NS2_EV_START, "START" }, |
| 119 | { GPRS_NS2_EV_RESET, "RESET" }, |
| 120 | { GPRS_NS2_EV_RESET_ACK, "RESET_ACK" }, |
| 121 | { GPRS_NS2_EV_UNBLOCK, "UNBLOCK" }, |
| 122 | { GPRS_NS2_EV_UNBLOCK_ACK, "UNBLOCK_ACK" }, |
| 123 | { GPRS_NS2_EV_BLOCK, "BLOCK" }, |
| 124 | { GPRS_NS2_EV_BLOCK_ACK, "BLOCK_ACK" }, |
| 125 | { GPRS_NS2_EV_ALIVE, "ALIVE" }, |
| 126 | { GPRS_NS2_EV_ALIVE_ACK, "ALIVE_ACK" }, |
| 127 | { GPRS_NS2_EV_STATUS, "STATUS" }, |
| 128 | { GPRS_NS2_EV_UNITDATA, "UNITDATA" }, |
| 129 | {GPRS_NS2_EV_FORCE_UNCONFIGURED, "FORCE_UNCONFIGURED"}, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 130 | { 0, NULL } |
| 131 | }; |
| 132 | |
| 133 | static inline struct gprs_ns2_inst *ns_inst_from_fi(struct osmo_fsm_inst *fi) |
| 134 | { |
| 135 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 136 | return priv->nsvc->nse->nsi; |
| 137 | } |
| 138 | |
| 139 | static void start_test_procedure(struct gprs_ns2_vc_priv *priv) |
| 140 | { |
| 141 | struct gprs_ns2_inst *nsi = priv->nsvc->nse->nsi; |
| 142 | |
| 143 | if (osmo_timer_pending(&priv->alive.timer)) |
| 144 | return; |
| 145 | |
| 146 | priv->alive.mode = NS_TOUT_TNS_ALIVE; |
| 147 | priv->alive.N = 0; |
| 148 | |
| 149 | osmo_gettimeofday(&priv->alive.timer_started, NULL); |
| 150 | ns2_tx_alive(priv->nsvc); |
| 151 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0); |
| 152 | } |
| 153 | |
| 154 | static void stop_test_procedure(struct gprs_ns2_vc_priv *priv) |
| 155 | { |
| 156 | osmo_timer_del(&priv->alive.timer); |
| 157 | } |
| 158 | |
| 159 | static int alive_timer_elapsed_ms(struct gprs_ns2_vc_priv *priv) |
| 160 | { |
| 161 | struct timeval now, elapsed; |
| 162 | osmo_gettimeofday(&now, NULL); |
| 163 | timersub(&now, &priv->alive.timer_started, &elapsed); |
| 164 | |
| 165 | return 1000 * elapsed.tv_sec + elapsed.tv_usec / 1000; |
| 166 | } |
| 167 | |
| 168 | static void recv_test_procedure(struct osmo_fsm_inst *fi) |
| 169 | { |
| 170 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 171 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 172 | struct gprs_ns2_vc *nsvc = priv->nsvc; |
| 173 | |
| 174 | /* ignoring ACKs without sending an ALIVE */ |
| 175 | if (priv->alive.mode != NS_TOUT_TNS_ALIVE) |
| 176 | return; |
| 177 | |
| 178 | priv->alive.mode = NS_TOUT_TNS_TEST; |
| 179 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_TEST], 0); |
| 180 | osmo_stat_item_set(nsvc->statg->items[NS_STAT_ALIVE_DELAY], |
| 181 | alive_timer_elapsed_ms(priv)); |
| 182 | } |
| 183 | |
| 184 | |
| 185 | static void alive_timeout_handler(void *data) |
| 186 | { |
| 187 | struct osmo_fsm_inst *fi = data; |
| 188 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 189 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 190 | |
| 191 | switch (priv->alive.mode) { |
| 192 | case NS_TOUT_TNS_TEST: |
| 193 | priv->alive.mode = NS_TOUT_TNS_ALIVE; |
| 194 | ns2_tx_alive(priv->nsvc); |
| 195 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0); |
| 196 | break; |
| 197 | case NS_TOUT_TNS_ALIVE: |
| 198 | priv->alive.N++; |
| 199 | |
| 200 | if (priv->alive.N <= nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) { |
| 201 | /* retransmission */ |
| 202 | ns2_tx_alive(priv->nsvc); |
| 203 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0); |
| 204 | } else { |
| 205 | /* lost connection */ |
| 206 | if (priv->nsvc->mode == NS2_VC_MODE_BLOCKRESET) { |
| 207 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 208 | } else { |
| 209 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_ALIVE, nsi->timeout[NS_TOUT_TNS_ALIVE], 0); |
| 210 | } |
| 211 | } |
| 212 | break; |
| 213 | default: |
| 214 | break; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | static void gprs_ns2_st_unconfigured(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 219 | { |
| 220 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 221 | struct gprs_ns2_inst *nsi = priv->nsvc->nse->nsi; |
| 222 | |
| 223 | switch (event) { |
| 224 | case GPRS_NS2_EV_START: |
| 225 | switch (priv->nsvc->mode) { |
| 226 | case NS2_VC_MODE_ALIVE: |
| 227 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_ALIVE, nsi->timeout[NS_TOUT_TNS_ALIVE], NS_TOUT_TNS_ALIVE); |
| 228 | break; |
| 229 | case NS2_VC_MODE_BLOCKRESET: |
| 230 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], NS_TOUT_TNS_RESET); |
| 231 | break; |
| 232 | } |
| 233 | |
| 234 | break; |
| 235 | default: |
| 236 | OSMO_ASSERT(0); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | |
| 241 | static void gprs_ns2_st_reset_onenter(struct osmo_fsm_inst *fi, uint32_t old_state) |
| 242 | { |
| 243 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 244 | |
| 245 | if (old_state != GPRS_NS2_ST_RESET) |
| 246 | priv->N = 0; |
| 247 | |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 248 | if (priv->initiate_reset) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 249 | ns2_tx_reset(priv->nsvc, NS_CAUSE_OM_INTERVENTION); |
| 250 | |
| 251 | stop_test_procedure(priv); |
| 252 | ns2_nse_notify_unblocked(priv->nsvc, false); |
| 253 | } |
| 254 | |
| 255 | static void gprs_ns2_st_reset(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 256 | { |
| 257 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 258 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 259 | |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 260 | if (priv->initiate_reset) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 261 | switch (event) { |
| 262 | case GPRS_NS2_EV_RESET_ACK: |
| 263 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, |
| 264 | nsi->timeout[NS_TOUT_TNS_BLOCK], NS_TOUT_TNS_BLOCK); |
| 265 | break; |
| 266 | } |
| 267 | } else { |
| 268 | /* we are on the receiving end */ |
| 269 | switch (event) { |
| 270 | case GPRS_NS2_EV_RESET: |
| 271 | ns2_tx_reset_ack(priv->nsvc); |
| 272 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, |
| 273 | 0, 0); |
| 274 | break; |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | static void gprs_ns2_st_blocked_onenter(struct osmo_fsm_inst *fi, uint32_t old_state) |
| 280 | { |
| 281 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 282 | |
| 283 | if (old_state != GPRS_NS2_ST_BLOCKED) |
| 284 | priv->N = 0; |
| 285 | |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 286 | if (priv->initiate_block) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 287 | ns2_tx_unblock(priv->nsvc); |
| 288 | |
| 289 | start_test_procedure(priv); |
| 290 | } |
| 291 | |
| 292 | static void gprs_ns2_st_blocked(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 293 | { |
| 294 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 295 | |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 296 | if (priv->initiate_block) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 297 | switch (event) { |
| 298 | case GPRS_NS2_EV_BLOCK: |
| 299 | /* TODO: BLOCK is a UNBLOCK_NACK */ |
| 300 | ns2_tx_block_ack(priv->nsvc); |
| 301 | break; |
| 302 | case GPRS_NS2_EV_UNBLOCK: |
| 303 | ns2_tx_unblock_ack(priv->nsvc); |
| 304 | /* fall through */ |
| 305 | case GPRS_NS2_EV_UNBLOCK_ACK: |
| 306 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, |
| 307 | 0, NS_TOUT_TNS_TEST); |
| 308 | break; |
| 309 | } |
| 310 | } else { |
| 311 | /* we are on the receiving end. The initiator who sent RESET is responsible to UNBLOCK! */ |
| 312 | switch (event) { |
| 313 | case GPRS_NS2_EV_UNBLOCK: |
| 314 | ns2_tx_unblock_ack(priv->nsvc); |
| 315 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, |
| 316 | 0, 0); |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | static void gprs_ns2_st_unblocked_on_enter(struct osmo_fsm_inst *fi, uint32_t old_state) |
| 323 | { |
| 324 | struct gprs_ns2_vc_priv *priv = fi->priv; |
Daniel Willmann | 15c09a8 | 2020-11-03 23:05:43 +0100 | [diff] [blame] | 325 | struct gprs_ns2_vc *nsvc = priv->nsvc; |
| 326 | struct gprs_ns2_nse *nse = nsvc->nse; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 327 | |
Daniel Willmann | 15c09a8 | 2020-11-03 23:05:43 +0100 | [diff] [blame] | 328 | ns2_nse_notify_unblocked(nsvc, true); |
| 329 | ns2_prim_status_ind(nse, nsvc, 0, NS_AFF_CAUSE_VC_RECOVERY); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static void gprs_ns2_st_unblocked(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 333 | { |
| 334 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 335 | |
| 336 | switch (event) { |
| 337 | case GPRS_NS2_EV_BLOCK: |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 338 | priv->initiate_block = false; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 339 | ns2_tx_block_ack(priv->nsvc); |
| 340 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, |
| 341 | 0, 2); |
| 342 | break; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | static void gprs_ns2_st_alive(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 347 | { |
| 348 | switch (event) { |
| 349 | case GPRS_NS2_EV_ALIVE_ACK: |
| 350 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, 0, 0); |
| 351 | break; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | static void gprs_ns2_st_alive_onenter(struct osmo_fsm_inst *fi, uint32_t old_state) |
| 356 | { |
| 357 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 358 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 359 | |
| 360 | priv->alive.mode = NS_TOUT_TNS_TEST; |
| 361 | osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_TEST], 0); |
| 362 | |
| 363 | if (old_state != GPRS_NS2_ST_ALIVE) |
| 364 | priv->N = 0; |
| 365 | |
| 366 | ns2_tx_alive(priv->nsvc); |
| 367 | ns2_nse_notify_unblocked(priv->nsvc, false); |
| 368 | } |
| 369 | |
| 370 | static void gprs_ns2_st_alive_onleave(struct osmo_fsm_inst *fi, uint32_t next_state) |
| 371 | { |
| 372 | start_test_procedure(fi->priv); |
| 373 | } |
| 374 | |
| 375 | static const struct osmo_fsm_state gprs_ns2_vc_states[] = { |
| 376 | [GPRS_NS2_ST_UNCONFIGURED] = { |
| 377 | .in_event_mask = S(GPRS_NS2_EV_START), |
| 378 | .out_state_mask = S(GPRS_NS2_ST_RESET) | S(GPRS_NS2_ST_ALIVE), |
| 379 | .name = "UNCONFIGURED", |
| 380 | .action = gprs_ns2_st_unconfigured, |
| 381 | }, |
| 382 | [GPRS_NS2_ST_RESET] = { |
| 383 | .in_event_mask = S(GPRS_NS2_EV_RESET_ACK) | S(GPRS_NS2_EV_RESET), |
| 384 | .out_state_mask = S(GPRS_NS2_ST_RESET) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 385 | S(GPRS_NS2_ST_BLOCKED) | |
| 386 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 387 | .name = "RESET", |
| 388 | .action = gprs_ns2_st_reset, |
| 389 | .onenter = gprs_ns2_st_reset_onenter, |
| 390 | }, |
| 391 | [GPRS_NS2_ST_BLOCKED] = { |
| 392 | .in_event_mask = S(GPRS_NS2_EV_BLOCK) | S(GPRS_NS2_EV_BLOCK_ACK) | |
| 393 | S(GPRS_NS2_EV_UNBLOCK) | S(GPRS_NS2_EV_UNBLOCK_ACK), |
| 394 | .out_state_mask = S(GPRS_NS2_ST_RESET) | |
| 395 | S(GPRS_NS2_ST_UNBLOCKED) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 396 | S(GPRS_NS2_ST_BLOCKED) | |
| 397 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 398 | .name = "BLOCKED", |
| 399 | .action = gprs_ns2_st_blocked, |
| 400 | .onenter = gprs_ns2_st_blocked_onenter, |
| 401 | }, |
| 402 | [GPRS_NS2_ST_UNBLOCKED] = { |
Harald Welte | e24a5b5 | 2020-12-07 15:39:13 +0100 | [diff] [blame] | 403 | .in_event_mask = S(GPRS_NS2_EV_BLOCK) | S(GPRS_NS2_EV_UNBLOCK_ACK), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 404 | .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] | 405 | S(GPRS_NS2_ST_BLOCKED) | |
| 406 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 407 | .name = "UNBLOCKED", |
| 408 | .action = gprs_ns2_st_unblocked, |
| 409 | .onenter = gprs_ns2_st_unblocked_on_enter, |
| 410 | }, |
| 411 | |
| 412 | /* ST_ALIVE is only used on VC without RESET/BLOCK */ |
| 413 | [GPRS_NS2_ST_ALIVE] = { |
| 414 | .in_event_mask = S(GPRS_NS2_EV_ALIVE_ACK), |
| 415 | .out_state_mask = S(GPRS_NS2_ST_RESET) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 416 | S(GPRS_NS2_ST_UNBLOCKED) | |
| 417 | S(GPRS_NS2_ST_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 418 | .name = "ALIVE", |
| 419 | .action = gprs_ns2_st_alive, |
| 420 | .onenter = gprs_ns2_st_alive_onenter, |
| 421 | .onleave = gprs_ns2_st_alive_onleave, |
| 422 | }, |
| 423 | }; |
| 424 | |
| 425 | static int gprs_ns2_vc_fsm_timer_cb(struct osmo_fsm_inst *fi) |
| 426 | { |
| 427 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 428 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 429 | |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 430 | /* PCU timeouts */ |
| 431 | switch (fi->state) { |
| 432 | case GPRS_NS2_ST_RESET: |
| 433 | if (priv->initiate_reset) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 434 | priv->N++; |
| 435 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_RESET_RETRIES]) { |
| 436 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 437 | } else { |
| 438 | priv->N = 0; |
| 439 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 440 | } |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 441 | } |
| 442 | break; |
| 443 | case GPRS_NS2_ST_BLOCKED: |
| 444 | if (priv->initiate_block) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 445 | priv->N++; |
| 446 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES]) { |
| 447 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0); |
| 448 | } else { |
| 449 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0); |
| 450 | } |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 451 | } |
| 452 | break; |
| 453 | case GPRS_NS2_ST_ALIVE: |
| 454 | if (priv->initiate_reset) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 455 | priv->N++; |
| 456 | if (priv->N <= nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) { |
| 457 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_ALIVE, 0, 0); |
| 458 | } else { |
| 459 | priv->N = 0; |
| 460 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_ALIVE, 0, 0); |
| 461 | } |
| 462 | break; |
| 463 | } |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 464 | break; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 465 | } |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static void gprs_ns2_recv_unitdata(struct osmo_fsm_inst *fi, |
| 470 | struct msgb *msg) |
| 471 | { |
| 472 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 473 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
| 474 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
| 475 | struct osmo_gprs_ns2_prim nsp = {}; |
| 476 | uint16_t bvci; |
| 477 | |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 478 | if (msgb_l2len(msg) < sizeof(*nsh) + 3) { |
| 479 | msgb_free(msg); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 480 | return; |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 481 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 482 | |
| 483 | /* TODO: 7.1: For an IP sub-network, an NS-UNITDATA PDU |
| 484 | * for a PTP BVC may indicate a request to change the IP endpoint |
| 485 | * and/or a response to a change in the IP endpoint. */ |
| 486 | |
| 487 | /* TODO: nsh->data[0] -> C/R only valid in IP SNS */ |
| 488 | bvci = nsh->data[1] << 8 | nsh->data[2]; |
| 489 | |
Alexander Couzens | 89acdef | 2020-09-23 18:22:31 +0200 | [diff] [blame] | 490 | msg->l3h = &nsh->data[3]; |
| 491 | nsp.bvci = bvci; |
| 492 | nsp.nsei = priv->nsvc->nse->nsei; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 493 | |
Alexander Couzens | c1cd333 | 2020-09-23 23:24:02 +0200 | [diff] [blame] | 494 | /* 10.3.9 NS SDU Control Bits */ |
| 495 | if (nsh->data[0] & 0x1) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 496 | nsp.u.unitdata.change = NS_ENDPOINT_REQUEST_CHANGE; |
| 497 | |
| 498 | osmo_prim_init(&nsp.oph, SAP_NS, PRIM_NS_UNIT_DATA, |
| 499 | PRIM_OP_INDICATION, msg); |
| 500 | nsi->cb(&nsp.oph, nsi->cb_data); |
| 501 | } |
| 502 | |
| 503 | static void gprs_ns2_vc_fsm_allstate_action(struct osmo_fsm_inst *fi, |
| 504 | uint32_t event, |
| 505 | void *data) |
| 506 | { |
| 507 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 508 | struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi); |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 509 | struct msgb *msg = data; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 510 | |
| 511 | switch (event) { |
| 512 | case GPRS_NS2_EV_RESET: |
| 513 | if (priv->nsvc->mode != NS2_VC_MODE_BLOCKRESET) |
| 514 | break; |
| 515 | |
| 516 | /* move the FSM into reset */ |
| 517 | if (fi->state != GPRS_NS2_ST_RESET) { |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 518 | priv->initiate_reset = false; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 519 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], NS_TOUT_TNS_RESET); |
| 520 | } |
| 521 | /* pass the event down into FSM action */ |
| 522 | gprs_ns2_st_reset(fi, event, data); |
| 523 | break; |
| 524 | case GPRS_NS2_EV_ALIVE: |
| 525 | switch (fi->state) { |
| 526 | case GPRS_NS2_ST_UNCONFIGURED: |
| 527 | case GPRS_NS2_ST_RESET: |
| 528 | /* ignore ALIVE */ |
| 529 | break; |
| 530 | default: |
| 531 | ns2_tx_alive_ack(priv->nsvc); |
| 532 | } |
| 533 | break; |
| 534 | case GPRS_NS2_EV_ALIVE_ACK: |
| 535 | /* for VCs without RESET/BLOCK/UNBLOCK, the connections comes after ALIVE_ACK unblocked */ |
| 536 | if (fi->state == GPRS_NS2_ST_ALIVE) |
| 537 | gprs_ns2_st_alive(fi, event, data); |
| 538 | else |
| 539 | recv_test_procedure(fi); |
| 540 | break; |
| 541 | case GPRS_NS2_EV_UNITDATA: |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 542 | /* UNITDATA has to handle the release of msg. |
| 543 | * If send upwards (gprs_ns2_recv_unitdata) it must NOT free |
| 544 | * the msg, the upper layer has to do it. |
| 545 | * Otherwise the msg must be freed. |
| 546 | */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 547 | switch (fi->state) { |
| 548 | case GPRS_NS2_ST_BLOCKED: |
| 549 | /* 7.2.1: the BLOCKED_ACK might be lost */ |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 550 | if (priv->initiate_block) { |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 551 | gprs_ns2_recv_unitdata(fi, msg); |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | ns2_tx_status(priv->nsvc, |
| 556 | NS_CAUSE_NSVC_BLOCKED, |
| 557 | 0, msg); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 558 | break; |
| 559 | /* ALIVE can receive UNITDATA if the ALIVE_ACK is lost */ |
| 560 | case GPRS_NS2_ST_ALIVE: |
| 561 | case GPRS_NS2_ST_UNBLOCKED: |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 562 | gprs_ns2_recv_unitdata(fi, msg); |
| 563 | return; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 564 | } |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 565 | |
| 566 | msgb_free(msg); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 567 | break; |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 568 | case GPRS_NS2_EV_FORCE_UNCONFIGURED: |
| 569 | /* Force the NSVC back to its initial state */ |
| 570 | osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNCONFIGURED, 0, 0); |
| 571 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_START, NULL); |
| 572 | return; |
| 573 | break; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
Alexander Couzens | 0346b64 | 2020-10-27 13:05:56 +0100 | [diff] [blame] | 577 | static void gprs_ns2_vc_fsm_clean(struct osmo_fsm_inst *fi, |
| 578 | enum osmo_fsm_term_cause cause) |
| 579 | { |
| 580 | struct gprs_ns2_vc_priv *priv = fi->priv; |
| 581 | |
| 582 | osmo_timer_del(&priv->alive.timer); |
| 583 | } |
| 584 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 585 | static struct osmo_fsm gprs_ns2_vc_fsm = { |
| 586 | .name = "GPRS-NS2-VC", |
| 587 | .states = gprs_ns2_vc_states, |
| 588 | .num_states = ARRAY_SIZE(gprs_ns2_vc_states), |
| 589 | .allstate_event_mask = S(GPRS_NS2_EV_UNITDATA) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 590 | S(GPRS_NS2_EV_RESET) | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 591 | S(GPRS_NS2_EV_ALIVE) | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 592 | S(GPRS_NS2_EV_ALIVE_ACK) | |
| 593 | S(GPRS_NS2_EV_FORCE_UNCONFIGURED), |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 594 | .allstate_action = gprs_ns2_vc_fsm_allstate_action, |
Alexander Couzens | 0346b64 | 2020-10-27 13:05:56 +0100 | [diff] [blame] | 595 | .cleanup = gprs_ns2_vc_fsm_clean, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 596 | .timer_cb = gprs_ns2_vc_fsm_timer_cb, |
| 597 | /* .log_subsys = DNS, "is not constant" */ |
| 598 | .event_names = gprs_ns2_vc_event_names, |
| 599 | .pre_term = NULL, |
| 600 | .log_subsys = DLNS, |
| 601 | }; |
| 602 | |
| 603 | /*! |
| 604 | * \brief gprs_ns2_vc_fsm_alloc |
| 605 | * \param ctx |
| 606 | * \param vc |
| 607 | * \param id a char representation of the virtual curcuit |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 608 | * \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] | 609 | * \return NULL on error, otherwise the fsm |
| 610 | */ |
| 611 | struct osmo_fsm_inst *gprs_ns2_vc_fsm_alloc(struct gprs_ns2_vc *nsvc, |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 612 | const char *id, bool initiator) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 613 | { |
| 614 | struct osmo_fsm_inst *fi; |
| 615 | struct gprs_ns2_vc_priv *priv; |
| 616 | |
| 617 | fi = osmo_fsm_inst_alloc(&gprs_ns2_vc_fsm, nsvc, NULL, LOGL_DEBUG, id); |
| 618 | if (!fi) |
| 619 | return fi; |
| 620 | |
| 621 | nsvc->fi = fi; |
| 622 | priv = fi->priv = talloc_zero(fi, struct gprs_ns2_vc_priv); |
| 623 | priv->nsvc = nsvc; |
Daniel Willmann | f5b2e28 | 2020-11-18 18:51:25 +0100 | [diff] [blame] | 624 | priv->initiate_reset = initiator; |
| 625 | priv->initiate_block = initiator; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 626 | |
| 627 | osmo_timer_setup(&priv->alive.timer, alive_timeout_handler, fi); |
| 628 | |
| 629 | return fi; |
| 630 | } |
| 631 | |
Harald Welte | 5bef2cc | 2020-09-18 22:33:24 +0200 | [diff] [blame] | 632 | /*! Start a NS-VC FSM. |
| 633 | * \param nsvc the virtual circuit |
| 634 | * \return 0 on success; negative on error */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 635 | int gprs_ns2_vc_fsm_start(struct gprs_ns2_vc *nsvc) |
| 636 | { |
| 637 | /* allows to call this function even for started nsvc by gprs_ns2_start_alive_all_nsvcs */ |
| 638 | if (nsvc->fi->state == GPRS_NS2_ST_UNCONFIGURED) |
| 639 | return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_START, NULL); |
| 640 | return 0; |
| 641 | } |
| 642 | |
Daniel Willmann | ed0c982 | 2020-11-18 14:08:07 +0100 | [diff] [blame] | 643 | /*! Reset a NS-VC FSM. |
| 644 | * \param nsvc the virtual circuit |
| 645 | * \return 0 on success; negative on error */ |
| 646 | int gprs_ns2_vc_force_unconfigured(struct gprs_ns2_vc *nsvc) |
| 647 | { |
| 648 | return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_FORCE_UNCONFIGURED, NULL); |
| 649 | } |
| 650 | |
Harald Welte | 5bef2cc | 2020-09-18 22:33:24 +0200 | [diff] [blame] | 651 | /*! entry point for messages from the driver/VL |
| 652 | * \param nsvc virtual circuit on which the message was received |
| 653 | * \param msg message that was received |
| 654 | * \param tp parsed TLVs of the received message |
| 655 | * \return 0 on success; negative on error */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 656 | int gprs_ns2_vc_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp) |
| 657 | { |
| 658 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
| 659 | struct osmo_fsm_inst *fi = nsvc->fi; |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 660 | int rc = 0; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 661 | uint8_t cause; |
| 662 | |
| 663 | /* TODO: 7.2: on UNBLOCK/BLOCK: check if NS-VCI is correct, |
| 664 | * if not answer STATUS with "NS-VC unknown" */ |
| 665 | /* TODO: handle RESET with different VCI */ |
| 666 | /* TODO: handle BLOCK/UNBLOCK/ALIVE with different VCI */ |
| 667 | |
| 668 | if (gprs_ns2_validate(nsvc, nsh->pdu_type, msg, tp, &cause)) { |
| 669 | if (nsh->pdu_type != NS_PDUT_STATUS) { |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 670 | rc = ns2_tx_status(nsvc, cause, 0, msg); |
| 671 | goto out; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | |
| 675 | switch (nsh->pdu_type) { |
| 676 | case NS_PDUT_RESET: |
| 677 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RESET, tp); |
| 678 | break; |
| 679 | case NS_PDUT_RESET_ACK: |
| 680 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RESET_ACK, tp); |
| 681 | break; |
| 682 | case NS_PDUT_BLOCK: |
| 683 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_BLOCK, tp); |
| 684 | break; |
| 685 | case NS_PDUT_BLOCK_ACK: |
| 686 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_BLOCK_ACK, tp); |
| 687 | break; |
| 688 | case NS_PDUT_UNBLOCK: |
| 689 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_UNBLOCK, tp); |
| 690 | break; |
| 691 | case NS_PDUT_UNBLOCK_ACK: |
| 692 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_UNBLOCK_ACK, tp); |
| 693 | break; |
| 694 | case NS_PDUT_ALIVE: |
| 695 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_ALIVE, tp); |
| 696 | break; |
| 697 | case NS_PDUT_ALIVE_ACK: |
| 698 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_ALIVE_ACK, tp); |
| 699 | break; |
| 700 | case NS_PDUT_UNITDATA: |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 701 | /* UNITDATA have to free msg because it might send the msg layer upwards */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 702 | osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_UNITDATA, msg); |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 703 | return 0; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 704 | default: |
| 705 | LOGP(DLNS, LOGL_ERROR, "NSEI=%u Rx unknown NS PDU type %s\n", nsvc->nse->nsei, |
| 706 | get_value_string(gprs_ns_pdu_strings, nsh->pdu_type)); |
| 707 | return -EINVAL; |
| 708 | } |
| 709 | |
Alexander Couzens | cce8828 | 2020-10-26 00:25:50 +0100 | [diff] [blame] | 710 | out: |
| 711 | msgb_free(msg); |
| 712 | |
| 713 | return rc; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 714 | } |
| 715 | |
Harald Welte | 5bef2cc | 2020-09-18 22:33:24 +0200 | [diff] [blame] | 716 | /*! is the given NS-VC unblocked? */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 717 | int gprs_ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc) |
| 718 | { |
| 719 | return (nsvc->fi->state == GPRS_NS2_ST_UNBLOCKED); |
| 720 | } |
| 721 | |
| 722 | /* initialize osmo_ctx on main tread */ |
| 723 | static __attribute__((constructor)) void on_dso_load_ctx(void) |
| 724 | { |
| 725 | OSMO_ASSERT(osmo_fsm_register(&gprs_ns2_vc_fsm) == 0); |
| 726 | } |