blob: 1db2a8eaf169825452b5e093f318b953f641a23d [file] [log] [blame]
Alexander Couzens6a161492020-07-12 13:45:50 +02001/*! \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 Couzens6a161492020-07-12 13:45:50 +020052struct gprs_ns2_vc_priv {
53 struct gprs_ns2_vc *nsvc;
54 /* how often the timer was triggered */
55 int N;
Daniel Willmannf5b2e282020-11-18 18:51:25 +010056 /* 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 Couzensea01bf22021-01-18 14:01:01 +010058 bool initiator;
Daniel Willmannf5b2e282020-11-18 18:51:25 +010059 bool initiate_block;
60 bool initiate_reset;
Alexander Couzens47afc422021-01-17 20:12:46 +010061 /* if blocked by O&M/vty */
62 bool om_blocked;
63 /* if unitdata is forwarded to the user */
64 bool accept_unitdata;
Alexander Couzens6a161492020-07-12 13:45:50 +020065
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 Couzensab0e8642021-02-12 02:50:44 +010071 struct timespec timer_started;
Alexander Couzens6a161492020-07-12 13:45:50 +020072 } 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 Couzensd3e31102021-02-03 11:15:07 +010082 * - UNCONFIGURED -> RECOVERY -> UNBLOCKED
Alexander Couzens6a161492020-07-12 13:45:50 +020083 *
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 Couzensd3e31102021-02-03 11:15:07 +010088 * The RECOVERY state is used as intermediate, because a VC is only valid if it received an Alive ACK when
Alexander Couzens6a161492020-07-12 13:45:50 +020089 * not using RESET/BLOCK procedure.
90 */
91
92enum 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 Couzensd3e31102021-02-03 11:15:07 +010098 GPRS_NS2_ST_RECOVERING, /* only used when not using RESET/BLOCK procedure */
Alexander Couzens6a161492020-07-12 13:45:50 +020099};
100
101enum gprs_ns2_vc_event {
Alexander Couzensf5775432021-01-18 13:49:00 +0100102 GPRS_NS2_EV_REQ_START,
Alexander Couzens6a161492020-07-12 13:45:50 +0200103
104 /* received messages */
Alexander Couzensf5775432021-01-18 13:49:00 +0100105 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 Couzens6a161492020-07-12 13:45:50 +0200114
Alexander Couzensf5775432021-01-18 13:49:00 +0100115 GPRS_NS2_EV_RX_UNITDATA,
Daniel Willmanned0c9822020-11-18 14:08:07 +0100116
Alexander Couzensf5775432021-01-18 13:49:00 +0100117 GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED, /* called via vty for tests */
Alexander Couzens27e58732021-03-21 17:12:08 +0100118 GPRS_NS2_EV_REQ_OM_RESET, /* vty cmd: reset */
Alexander Couzensf5775432021-01-18 13:49:00 +0100119 GPRS_NS2_EV_REQ_OM_BLOCK, /* vty cmd: block */
120 GPRS_NS2_EV_REQ_OM_UNBLOCK, /* vty cmd: unblock*/
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200121 GPRS_NS2_EV_RX_BLOCK_FOREIGN, /* received a BLOCK over another NSVC */
Alexander Couzens6a161492020-07-12 13:45:50 +0200122};
123
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100124static const struct value_string ns2_vc_event_names[] = {
Harald Welteb339cbb2021-02-05 14:49:21 +0100125 { GPRS_NS2_EV_REQ_START, "REQ-START" },
126 { GPRS_NS2_EV_RX_RESET, "RX-RESET" },
127 { GPRS_NS2_EV_RX_RESET_ACK, "RX-RESET_ACK" },
128 { GPRS_NS2_EV_RX_UNBLOCK, "RX-UNBLOCK" },
129 { GPRS_NS2_EV_RX_UNBLOCK_ACK, "RX-UNBLOCK_ACK" },
130 { GPRS_NS2_EV_RX_BLOCK, "RX-BLOCK" },
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200131 { GPRS_NS2_EV_RX_BLOCK_FOREIGN, "RX-BLOCK_FOREIGN" },
Harald Welteb339cbb2021-02-05 14:49:21 +0100132 { GPRS_NS2_EV_RX_BLOCK_ACK, "RX-BLOCK_ACK" },
133 { GPRS_NS2_EV_RX_ALIVE, "RX-ALIVE" },
134 { GPRS_NS2_EV_RX_ALIVE_ACK, "RX-ALIVE_ACK" },
135 { GPRS_NS2_EV_RX_STATUS, "RX-STATUS" },
136 { GPRS_NS2_EV_RX_UNITDATA, "RX-UNITDATA" },
137 { GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED, "REQ-FORCE_UNCONFIGURED" },
Alexander Couzens27e58732021-03-21 17:12:08 +0100138 { GPRS_NS2_EV_REQ_OM_RESET, "REQ-O&M-RESET"},
Alexander Couzens47afc422021-01-17 20:12:46 +0100139 { GPRS_NS2_EV_REQ_OM_BLOCK, "REQ-O&M-BLOCK"},
140 { GPRS_NS2_EV_REQ_OM_UNBLOCK, "REQ-O&M-UNBLOCK"},
Alexander Couzens6a161492020-07-12 13:45:50 +0200141 { 0, NULL }
142};
143
144static inline struct gprs_ns2_inst *ns_inst_from_fi(struct osmo_fsm_inst *fi)
145{
146 struct gprs_ns2_vc_priv *priv = fi->priv;
147 return priv->nsvc->nse->nsi;
148}
149
Harald Welte5e408312021-03-23 18:16:30 +0100150/* Start the NS-TEST procedure, either with transmitting a tx_alive,
151 * (start_tx_alive==true) or with starting tns-test */
152static void start_test_procedure(struct osmo_fsm_inst *fi, bool start_tx_alive)
Alexander Couzens6a161492020-07-12 13:45:50 +0200153{
Harald Welte5e408312021-03-23 18:16:30 +0100154 struct gprs_ns2_vc_priv *priv = fi->priv;
Alexander Couzens6a161492020-07-12 13:45:50 +0200155 struct gprs_ns2_inst *nsi = priv->nsvc->nse->nsi;
Harald Welte5e408312021-03-23 18:16:30 +0100156 unsigned int tout_idx;
Alexander Couzens6a161492020-07-12 13:45:50 +0200157
Harald Welte5e408312021-03-23 18:16:30 +0100158 if (osmo_timer_pending(&priv->alive.timer)) {
159 if (start_tx_alive) {
160 if (priv->alive.mode == NS_TOUT_TNS_ALIVE)
161 return;
162 } else {
163 if (priv->alive.mode == NS_TOUT_TNS_TEST)
164 return;
165 }
166 }
Alexander Couzens6a161492020-07-12 13:45:50 +0200167
Alexander Couzens6a161492020-07-12 13:45:50 +0200168 priv->alive.N = 0;
169
Harald Welte5e408312021-03-23 18:16:30 +0100170 if (start_tx_alive) {
171 priv->alive.mode = NS_TOUT_TNS_ALIVE;
172 osmo_clock_gettime(CLOCK_MONOTONIC, &priv->alive.timer_started);
173 ns2_tx_alive(priv->nsvc);
174 tout_idx = NS_TOUT_TNS_ALIVE;
175 } else {
176 priv->alive.mode = NS_TOUT_TNS_TEST;
177 tout_idx = NS_TOUT_TNS_TEST;
178 }
179 LOGPFSML(fi, LOGL_DEBUG, "Starting Tns-%s of %u seconds\n",
180 tout_idx == NS_TOUT_TNS_ALIVE ? "alive" : "test", nsi->timeout[tout_idx]);
181 osmo_timer_schedule(&priv->alive.timer, nsi->timeout[tout_idx], 0);
Alexander Couzens6a161492020-07-12 13:45:50 +0200182}
183
184static void stop_test_procedure(struct gprs_ns2_vc_priv *priv)
185{
Alexander Couzens8138c532021-06-15 22:11:40 +0200186 osmo_stat_item_set(osmo_stat_item_group_get_item(priv->nsvc->statg, NS_STAT_ALIVE_DELAY), 0);
Alexander Couzens6a161492020-07-12 13:45:50 +0200187 osmo_timer_del(&priv->alive.timer);
188}
189
Harald Welte5e408312021-03-23 18:16:30 +0100190/* how many milliseconds have expired since the last alive timer start? */
Alexander Couzens6a161492020-07-12 13:45:50 +0200191static int alive_timer_elapsed_ms(struct gprs_ns2_vc_priv *priv)
192{
Alexander Couzensab0e8642021-02-12 02:50:44 +0100193 struct timespec now, elapsed;
Alexander Couzens6a161492020-07-12 13:45:50 +0200194
Alexander Couzensab0e8642021-02-12 02:50:44 +0100195 if (osmo_clock_gettime(CLOCK_MONOTONIC, &now) != 0)
196 return 0;
197
198 timespecsub(&now, &priv->alive.timer_started, &elapsed);
Alexander Couzensab0e8642021-02-12 02:50:44 +0100199 return elapsed.tv_sec * 1000 + (elapsed.tv_nsec / 1000000);
Alexander Couzens6a161492020-07-12 13:45:50 +0200200}
201
Harald Welte5e408312021-03-23 18:16:30 +0100202/* we just received a NS-ALIVE-ACK; re-schedule after Tns-test */
Alexander Couzens6a161492020-07-12 13:45:50 +0200203static void recv_test_procedure(struct osmo_fsm_inst *fi)
204{
205 struct gprs_ns2_vc_priv *priv = fi->priv;
206 struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi);
207 struct gprs_ns2_vc *nsvc = priv->nsvc;
208
209 /* ignoring ACKs without sending an ALIVE */
210 if (priv->alive.mode != NS_TOUT_TNS_ALIVE)
211 return;
212
213 priv->alive.mode = NS_TOUT_TNS_TEST;
214 osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_TEST], 0);
Pau Espin Pedrol7b894a72021-06-04 18:17:12 +0200215 osmo_stat_item_set(osmo_stat_item_group_get_item(nsvc->statg, NS_STAT_ALIVE_DELAY),
Alexander Couzens6a161492020-07-12 13:45:50 +0200216 alive_timer_elapsed_ms(priv));
217}
218
219
220static void alive_timeout_handler(void *data)
221{
222 struct osmo_fsm_inst *fi = data;
223 struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi);
224 struct gprs_ns2_vc_priv *priv = fi->priv;
225
226 switch (priv->alive.mode) {
227 case NS_TOUT_TNS_TEST:
228 priv->alive.mode = NS_TOUT_TNS_ALIVE;
Alexander Couzens2f8f7b62021-02-03 11:04:22 +0100229 priv->alive.N = 0;
Alexander Couzensfa4121d2021-02-12 02:54:46 +0100230 osmo_clock_gettime(CLOCK_MONOTONIC, &priv->alive.timer_started);
Alexander Couzens6a161492020-07-12 13:45:50 +0200231 ns2_tx_alive(priv->nsvc);
232 osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0);
233 break;
234 case NS_TOUT_TNS_ALIVE:
Daniel Willmannefa64f92021-07-09 20:35:00 +0200235 RATE_CTR_INC_NS(priv->nsvc, NS_CTR_LOST_ALIVE);
Alexander Couzens6a161492020-07-12 13:45:50 +0200236 priv->alive.N++;
237
238 if (priv->alive.N <= nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) {
239 /* retransmission */
240 ns2_tx_alive(priv->nsvc);
241 osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0);
242 } else {
243 /* lost connection */
Alexander Couzens138b96f2021-01-25 16:23:29 +0100244 if (priv->nsvc->mode == GPRS_NS2_VC_MODE_BLOCKRESET) {
Alexander Couzens6a161492020-07-12 13:45:50 +0200245 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0);
246 } else {
Alexander Couzensd3e31102021-02-03 11:15:07 +0100247 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, nsi->timeout[NS_TOUT_TNS_ALIVE], 0);
Alexander Couzens6a161492020-07-12 13:45:50 +0200248 }
249 }
250 break;
251 default:
252 break;
253 }
254}
255
Harald Welte6a9ec422021-01-31 18:56:29 +0100256
257static void ns2_st_unconfigured_onenter(struct osmo_fsm_inst *fi, uint32_t old_state)
258{
Alexander Couzensa140d442021-07-12 16:42:32 +0200259 struct gprs_ns2_vc_priv *priv = fi->priv;
260
Harald Welte6a9ec422021-01-31 18:56:29 +0100261 stop_test_procedure(fi->priv);
Alexander Couzensa140d442021-07-12 16:42:32 +0200262 ns2_nse_notify_unblocked(priv->nsvc, false);
Harald Welte6a9ec422021-01-31 18:56:29 +0100263}
264
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100265static void ns2_st_unconfigured(struct osmo_fsm_inst *fi, uint32_t event, void *data)
Alexander Couzens6a161492020-07-12 13:45:50 +0200266{
267 struct gprs_ns2_vc_priv *priv = fi->priv;
268 struct gprs_ns2_inst *nsi = priv->nsvc->nse->nsi;
269
Alexander Couzensea01bf22021-01-18 14:01:01 +0100270 priv->initiate_reset = priv->initiate_block = priv->initiator;
271 priv->om_blocked = false;
272
Alexander Couzens6a161492020-07-12 13:45:50 +0200273 switch (event) {
Alexander Couzensf5775432021-01-18 13:49:00 +0100274 case GPRS_NS2_EV_REQ_START:
Alexander Couzens6a161492020-07-12 13:45:50 +0200275 switch (priv->nsvc->mode) {
Alexander Couzens138b96f2021-01-25 16:23:29 +0100276 case GPRS_NS2_VC_MODE_ALIVE:
Harald Weltec51ddf22021-03-05 09:48:18 +0100277 if (priv->nsvc->nse->dialect == GPRS_NS2_DIALECT_SNS) {
278 /* In IP-SNS, the NS-VC are assumed initially alive, until the alive
279 * procedure should fail at some future point */
280 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, 0, 0);
281 } else {
282 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, nsi->timeout[NS_TOUT_TNS_ALIVE], NS_TOUT_TNS_ALIVE);
283 }
Alexander Couzens6a161492020-07-12 13:45:50 +0200284 break;
Alexander Couzens138b96f2021-01-25 16:23:29 +0100285 case GPRS_NS2_VC_MODE_BLOCKRESET:
Alexander Couzens6a161492020-07-12 13:45:50 +0200286 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], NS_TOUT_TNS_RESET);
287 break;
288 }
Alexander Couzens6a161492020-07-12 13:45:50 +0200289 break;
290 default:
291 OSMO_ASSERT(0);
292 }
293}
294
295
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100296static void ns2_st_reset_onenter(struct osmo_fsm_inst *fi, uint32_t old_state)
Alexander Couzens6a161492020-07-12 13:45:50 +0200297{
298 struct gprs_ns2_vc_priv *priv = fi->priv;
299
300 if (old_state != GPRS_NS2_ST_RESET)
301 priv->N = 0;
302
Alexander Couzens47afc422021-01-17 20:12:46 +0100303 priv->accept_unitdata = false;
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100304 if (priv->initiate_reset)
Alexander Couzens6a161492020-07-12 13:45:50 +0200305 ns2_tx_reset(priv->nsvc, NS_CAUSE_OM_INTERVENTION);
306
307 stop_test_procedure(priv);
308 ns2_nse_notify_unblocked(priv->nsvc, false);
309}
310
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100311static void ns2_st_reset(struct osmo_fsm_inst *fi, uint32_t event, void *data)
Alexander Couzens6a161492020-07-12 13:45:50 +0200312{
313 struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi);
314 struct gprs_ns2_vc_priv *priv = fi->priv;
315
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100316 if (priv->initiate_reset) {
Alexander Couzens6a161492020-07-12 13:45:50 +0200317 switch (event) {
Alexander Couzens273f0632021-01-20 13:11:26 +0100318 case GPRS_NS2_EV_RX_RESET:
319 ns2_tx_reset_ack(priv->nsvc);
320 /* fall-through */
Alexander Couzensf5775432021-01-18 13:49:00 +0100321 case GPRS_NS2_EV_RX_RESET_ACK:
Alexander Couzens6a161492020-07-12 13:45:50 +0200322 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED,
323 nsi->timeout[NS_TOUT_TNS_BLOCK], NS_TOUT_TNS_BLOCK);
324 break;
325 }
326 } else {
327 /* we are on the receiving end */
328 switch (event) {
Alexander Couzensf5775432021-01-18 13:49:00 +0100329 case GPRS_NS2_EV_RX_RESET:
Alexander Couzens6a161492020-07-12 13:45:50 +0200330 ns2_tx_reset_ack(priv->nsvc);
331 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED,
332 0, 0);
333 break;
334 }
335 }
336}
337
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100338static void ns2_st_blocked_onenter(struct osmo_fsm_inst *fi, uint32_t old_state)
Alexander Couzens6a161492020-07-12 13:45:50 +0200339{
340 struct gprs_ns2_vc_priv *priv = fi->priv;
341
Harald Welte4c54f592021-01-30 22:42:15 +0100342 if (old_state != GPRS_NS2_ST_BLOCKED) {
Alexander Couzens6a161492020-07-12 13:45:50 +0200343 priv->N = 0;
Daniel Willmannefa64f92021-07-09 20:35:00 +0200344 RATE_CTR_INC_NS(priv->nsvc, NS_CTR_BLOCKED);
Harald Welte4c54f592021-01-30 22:42:15 +0100345 }
Alexander Couzens6a161492020-07-12 13:45:50 +0200346
Alexander Couzense09deb62021-06-15 21:35:45 +0200347 ns2_nse_notify_unblocked(priv->nsvc, false);
Alexander Couzens47afc422021-01-17 20:12:46 +0100348 if (priv->om_blocked) {
349 /* we are already blocked after a RESET */
350 if (old_state == GPRS_NS2_ST_RESET) {
351 osmo_timer_del(&fi->timer);
352 } else {
Alexander Couzens67cfc5d2021-09-07 01:10:38 +0200353 ns2_tx_block(priv->nsvc, NS_CAUSE_OM_INTERVENTION, NULL);
Alexander Couzens47afc422021-01-17 20:12:46 +0100354 }
355 } else if (priv->initiate_block) {
Alexander Couzens6a161492020-07-12 13:45:50 +0200356 ns2_tx_unblock(priv->nsvc);
Alexander Couzens47afc422021-01-17 20:12:46 +0100357 }
Alexander Couzens6a161492020-07-12 13:45:50 +0200358
Harald Welte5e408312021-03-23 18:16:30 +0100359 start_test_procedure(fi, true);
Alexander Couzens6a161492020-07-12 13:45:50 +0200360}
361
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100362static void ns2_st_blocked(struct osmo_fsm_inst *fi, uint32_t event, void *data)
Alexander Couzens6a161492020-07-12 13:45:50 +0200363{
364 struct gprs_ns2_vc_priv *priv = fi->priv;
365
Alexander Couzens47afc422021-01-17 20:12:46 +0100366 if (priv->om_blocked) {
367 switch (event) {
Alexander Couzensf5775432021-01-18 13:49:00 +0100368 case GPRS_NS2_EV_RX_BLOCK_ACK:
Alexander Couzens47afc422021-01-17 20:12:46 +0100369 priv->accept_unitdata = false;
370 osmo_timer_del(&fi->timer);
371 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100372 case GPRS_NS2_EV_RX_BLOCK:
Alexander Couzens67cfc5d2021-09-07 01:10:38 +0200373 ns2_tx_block_ack(priv->nsvc, NULL);
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200374 /* fall through */
375 case GPRS_NS2_EV_RX_BLOCK_FOREIGN:
376 /* the BLOCK ACK for foreign BLOCK PDUs (rx over another nsvc) will be sent
377 * from the receiving nsvc */
378 priv->accept_unitdata = false;
Alexander Couzens47afc422021-01-17 20:12:46 +0100379 osmo_timer_del(&fi->timer);
380 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100381 case GPRS_NS2_EV_RX_UNBLOCK:
Alexander Couzens47afc422021-01-17 20:12:46 +0100382 priv->accept_unitdata = false;
Alexander Couzens67cfc5d2021-09-07 01:10:38 +0200383 ns2_tx_block(priv->nsvc, NS_CAUSE_OM_INTERVENTION, NULL);
Alexander Couzens47afc422021-01-17 20:12:46 +0100384 osmo_timer_add(&fi->timer);
385 break;
386 }
387 } else if (priv->initiate_block) {
Alexander Couzens6a161492020-07-12 13:45:50 +0200388 switch (event) {
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200389 case GPRS_NS2_EV_RX_BLOCK_FOREIGN:
390 /* the block ack will be sent by the rx NSVC */
391 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100392 case GPRS_NS2_EV_RX_BLOCK:
Alexander Couzens6a161492020-07-12 13:45:50 +0200393 /* TODO: BLOCK is a UNBLOCK_NACK */
Alexander Couzens67cfc5d2021-09-07 01:10:38 +0200394 ns2_tx_block_ack(priv->nsvc, NULL);
Alexander Couzens6a161492020-07-12 13:45:50 +0200395 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100396 case GPRS_NS2_EV_RX_UNBLOCK:
Alexander Couzens6a161492020-07-12 13:45:50 +0200397 ns2_tx_unblock_ack(priv->nsvc);
398 /* fall through */
Alexander Couzensf5775432021-01-18 13:49:00 +0100399 case GPRS_NS2_EV_RX_UNBLOCK_ACK:
Alexander Couzens47afc422021-01-17 20:12:46 +0100400 priv->accept_unitdata = true;
Alexander Couzens6a161492020-07-12 13:45:50 +0200401 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED,
402 0, NS_TOUT_TNS_TEST);
403 break;
404 }
405 } else {
406 /* we are on the receiving end. The initiator who sent RESET is responsible to UNBLOCK! */
407 switch (event) {
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200408 case GPRS_NS2_EV_RX_BLOCK_FOREIGN:
409 /* the block ack will be sent by the rx NSVC */
410 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100411 case GPRS_NS2_EV_RX_BLOCK:
Alexander Couzens67cfc5d2021-09-07 01:10:38 +0200412 ns2_tx_block_ack(priv->nsvc, NULL);
Alexander Couzens856b94c2021-01-19 19:42:17 +0100413 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100414 case GPRS_NS2_EV_RX_UNBLOCK:
Alexander Couzens6a161492020-07-12 13:45:50 +0200415 ns2_tx_unblock_ack(priv->nsvc);
416 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED,
417 0, 0);
418 break;
419 }
420 }
421}
422
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100423static void ns2_st_unblocked_on_enter(struct osmo_fsm_inst *fi, uint32_t old_state)
Alexander Couzens6a161492020-07-12 13:45:50 +0200424{
425 struct gprs_ns2_vc_priv *priv = fi->priv;
Daniel Willmann15c09a82020-11-03 23:05:43 +0100426 struct gprs_ns2_vc *nsvc = priv->nsvc;
427 struct gprs_ns2_nse *nse = nsvc->nse;
Alexander Couzens6a161492020-07-12 13:45:50 +0200428
Alexander Couzensca5ce0d2021-09-05 23:15:56 +0200429 if (old_state != GPRS_NS2_ST_UNBLOCKED) {
Daniel Willmannefa64f92021-07-09 20:35:00 +0200430 RATE_CTR_INC_NS(nsvc, NS_CTR_UNBLOCKED);
Alexander Couzensca5ce0d2021-09-05 23:15:56 +0200431 osmo_clock_gettime(CLOCK_MONOTONIC, &nsvc->ts_alive_change);
432 }
Harald Welteb40bf8b2021-01-30 22:43:01 +0100433
Alexander Couzens47afc422021-01-17 20:12:46 +0100434 priv->accept_unitdata = true;
Daniel Willmann15c09a82020-11-03 23:05:43 +0100435 ns2_nse_notify_unblocked(nsvc, true);
Alexander Couzens138b96f2021-01-25 16:23:29 +0100436 ns2_prim_status_ind(nse, nsvc, 0, GPRS_NS2_AFF_CAUSE_VC_RECOVERY);
Harald Welte5e408312021-03-23 18:16:30 +0100437
438 /* the closest interpretation of the spec would start Tns-test here first,
439 * and only send a NS-ALIVE after Tns-test has expired (i.e. setting the
440 * second argument to 'false'. However, being quick in detecting unavailability
441 * of a NS-VC seems like a good idea */
442 start_test_procedure(fi, true);
Alexander Couzens6a161492020-07-12 13:45:50 +0200443}
444
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100445static void ns2_st_unblocked(struct osmo_fsm_inst *fi, uint32_t event, void *data)
Alexander Couzens6a161492020-07-12 13:45:50 +0200446{
447 struct gprs_ns2_vc_priv *priv = fi->priv;
448
449 switch (event) {
Alexander Couzensf5775432021-01-18 13:49:00 +0100450 case GPRS_NS2_EV_RX_UNBLOCK:
Alexander Couzensc4b74622021-01-10 20:44:26 +0100451 ns2_tx_unblock_ack(priv->nsvc);
452 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100453 case GPRS_NS2_EV_RX_BLOCK:
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200454 ns2_tx_block_ack(priv->nsvc, NULL);
455 /* fall through */
456 case GPRS_NS2_EV_RX_BLOCK_FOREIGN:
457 /* the BLOCK ACK for foreign BLOCK PDUs (rx over another nsvc) will be sent
458 * from the receiving nsvc */
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100459 priv->initiate_block = false;
Alexander Couzensf27fbf62021-09-06 00:19:15 +0200460 priv->accept_unitdata = false;
Alexander Couzens6a161492020-07-12 13:45:50 +0200461 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED,
462 0, 2);
463 break;
464 }
465}
466
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100467static void ns2_st_alive(struct osmo_fsm_inst *fi, uint32_t event, void *data)
Alexander Couzens6a161492020-07-12 13:45:50 +0200468{
469 switch (event) {
Alexander Couzensf5775432021-01-18 13:49:00 +0100470 case GPRS_NS2_EV_RX_ALIVE_ACK:
Alexander Couzens6a161492020-07-12 13:45:50 +0200471 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNBLOCKED, 0, 0);
472 break;
473 }
474}
475
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100476static void ns2_st_alive_onenter(struct osmo_fsm_inst *fi, uint32_t old_state)
Alexander Couzens6a161492020-07-12 13:45:50 +0200477{
478 struct gprs_ns2_vc_priv *priv = fi->priv;
479 struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi);
480
481 priv->alive.mode = NS_TOUT_TNS_TEST;
482 osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_TEST], 0);
483
Alexander Couzensd3e31102021-02-03 11:15:07 +0100484 if (old_state != GPRS_NS2_ST_RECOVERING)
Alexander Couzens6a161492020-07-12 13:45:50 +0200485 priv->N = 0;
486
Harald Welte5e408312021-03-23 18:16:30 +0100487 start_test_procedure(fi, true);
Alexander Couzens5b722472021-04-01 15:36:54 +0200488 ns2_nse_notify_unblocked(priv->nsvc, false);
Alexander Couzens6a161492020-07-12 13:45:50 +0200489}
490
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100491static const struct osmo_fsm_state ns2_vc_states[] = {
Alexander Couzens6a161492020-07-12 13:45:50 +0200492 [GPRS_NS2_ST_UNCONFIGURED] = {
Alexander Couzensf5775432021-01-18 13:49:00 +0100493 .in_event_mask = S(GPRS_NS2_EV_REQ_START),
Harald Weltec51ddf22021-03-05 09:48:18 +0100494 .out_state_mask = S(GPRS_NS2_ST_RESET) |
495 S(GPRS_NS2_ST_RECOVERING) |
496 S(GPRS_NS2_ST_UNBLOCKED),
Alexander Couzens6a161492020-07-12 13:45:50 +0200497 .name = "UNCONFIGURED",
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100498 .action = ns2_st_unconfigured,
Harald Welte6a9ec422021-01-31 18:56:29 +0100499 .onenter = ns2_st_unconfigured_onenter,
Alexander Couzens6a161492020-07-12 13:45:50 +0200500 },
501 [GPRS_NS2_ST_RESET] = {
Alexander Couzensf5775432021-01-18 13:49:00 +0100502 .in_event_mask = S(GPRS_NS2_EV_RX_RESET_ACK) | S(GPRS_NS2_EV_RX_RESET),
Alexander Couzens6a161492020-07-12 13:45:50 +0200503 .out_state_mask = S(GPRS_NS2_ST_RESET) |
Daniel Willmanned0c9822020-11-18 14:08:07 +0100504 S(GPRS_NS2_ST_BLOCKED) |
505 S(GPRS_NS2_ST_UNCONFIGURED),
Alexander Couzens6a161492020-07-12 13:45:50 +0200506 .name = "RESET",
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100507 .action = ns2_st_reset,
508 .onenter = ns2_st_reset_onenter,
Alexander Couzens6a161492020-07-12 13:45:50 +0200509 },
510 [GPRS_NS2_ST_BLOCKED] = {
Alexander Couzensf5775432021-01-18 13:49:00 +0100511 .in_event_mask = S(GPRS_NS2_EV_RX_BLOCK) | S(GPRS_NS2_EV_RX_BLOCK_ACK) |
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200512 S(GPRS_NS2_EV_RX_UNBLOCK) | S(GPRS_NS2_EV_RX_UNBLOCK_ACK) |
513 S(GPRS_NS2_EV_RX_BLOCK_FOREIGN),
Alexander Couzens6a161492020-07-12 13:45:50 +0200514 .out_state_mask = S(GPRS_NS2_ST_RESET) |
515 S(GPRS_NS2_ST_UNBLOCKED) |
Daniel Willmanned0c9822020-11-18 14:08:07 +0100516 S(GPRS_NS2_ST_BLOCKED) |
517 S(GPRS_NS2_ST_UNCONFIGURED),
Alexander Couzens6a161492020-07-12 13:45:50 +0200518 .name = "BLOCKED",
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100519 .action = ns2_st_blocked,
520 .onenter = ns2_st_blocked_onenter,
Alexander Couzens6a161492020-07-12 13:45:50 +0200521 },
522 [GPRS_NS2_ST_UNBLOCKED] = {
Alexander Couzensf5775432021-01-18 13:49:00 +0100523 .in_event_mask = S(GPRS_NS2_EV_RX_BLOCK) | S(GPRS_NS2_EV_RX_UNBLOCK_ACK) |
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200524 S(GPRS_NS2_EV_RX_UNBLOCK) | S(GPRS_NS2_EV_RX_BLOCK_FOREIGN),
Alexander Couzensd3e31102021-02-03 11:15:07 +0100525 .out_state_mask = S(GPRS_NS2_ST_RESET) | S(GPRS_NS2_ST_RECOVERING) |
Daniel Willmanned0c9822020-11-18 14:08:07 +0100526 S(GPRS_NS2_ST_BLOCKED) |
527 S(GPRS_NS2_ST_UNCONFIGURED),
Alexander Couzens6a161492020-07-12 13:45:50 +0200528 .name = "UNBLOCKED",
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100529 .action = ns2_st_unblocked,
530 .onenter = ns2_st_unblocked_on_enter,
Alexander Couzens6a161492020-07-12 13:45:50 +0200531 },
532
Alexander Couzensd3e31102021-02-03 11:15:07 +0100533 /* ST_RECOVERING is only used on VC without RESET/BLOCK */
534 [GPRS_NS2_ST_RECOVERING] = {
Alexander Couzensf5775432021-01-18 13:49:00 +0100535 .in_event_mask = S(GPRS_NS2_EV_RX_ALIVE_ACK),
Alexander Couzensd3e31102021-02-03 11:15:07 +0100536 .out_state_mask = S(GPRS_NS2_ST_RECOVERING) |
Daniel Willmanned0c9822020-11-18 14:08:07 +0100537 S(GPRS_NS2_ST_UNBLOCKED) |
538 S(GPRS_NS2_ST_UNCONFIGURED),
Alexander Couzensd3e31102021-02-03 11:15:07 +0100539 .name = "RECOVERING",
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100540 .action = ns2_st_alive,
541 .onenter = ns2_st_alive_onenter,
Alexander Couzens6a161492020-07-12 13:45:50 +0200542 },
543};
544
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100545static int ns2_vc_fsm_timer_cb(struct osmo_fsm_inst *fi)
Alexander Couzens6a161492020-07-12 13:45:50 +0200546{
547 struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi);
548 struct gprs_ns2_vc_priv *priv = fi->priv;
549
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100550 switch (fi->state) {
551 case GPRS_NS2_ST_RESET:
552 if (priv->initiate_reset) {
Daniel Willmannefa64f92021-07-09 20:35:00 +0200553 RATE_CTR_INC_NS(priv->nsvc, NS_CTR_LOST_RESET);
Alexander Couzens6a161492020-07-12 13:45:50 +0200554 priv->N++;
555 if (priv->N <= nsi->timeout[NS_TOUT_TNS_RESET_RETRIES]) {
556 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0);
557 } else {
558 priv->N = 0;
559 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0);
560 }
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100561 }
562 break;
563 case GPRS_NS2_ST_BLOCKED:
564 if (priv->initiate_block) {
Alexander Couzens6a161492020-07-12 13:45:50 +0200565 priv->N++;
Alexander Couzens47afc422021-01-17 20:12:46 +0100566 if (priv->om_blocked) {
567 if (priv->N <= nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES]) {
568 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
569 } else {
570 /* 7.2 stop accepting data when BLOCK PDU not responded */
571 priv->accept_unitdata = false;
572 }
Alexander Couzens6a161492020-07-12 13:45:50 +0200573 } else {
Alexander Couzens47afc422021-01-17 20:12:46 +0100574 if (priv->N <= nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES]) {
575 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
576 } else {
577 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0);
578 }
Alexander Couzens6a161492020-07-12 13:45:50 +0200579 }
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100580 }
581 break;
Alexander Couzensd3e31102021-02-03 11:15:07 +0100582 case GPRS_NS2_ST_RECOVERING:
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100583 if (priv->initiate_reset) {
Alexander Couzens6a161492020-07-12 13:45:50 +0200584 priv->N++;
585 if (priv->N <= nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) {
Alexander Couzensd3e31102021-02-03 11:15:07 +0100586 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, 0, 0);
Alexander Couzens6a161492020-07-12 13:45:50 +0200587 } else {
588 priv->N = 0;
Alexander Couzensd3e31102021-02-03 11:15:07 +0100589 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RECOVERING, 0, 0);
Alexander Couzens6a161492020-07-12 13:45:50 +0200590 }
591 break;
592 }
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100593 break;
Alexander Couzens6a161492020-07-12 13:45:50 +0200594 }
595 return 0;
596}
597
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100598static void ns2_recv_unitdata(struct osmo_fsm_inst *fi,
Alexander Couzens6a161492020-07-12 13:45:50 +0200599 struct msgb *msg)
600{
601 struct gprs_ns2_vc_priv *priv = fi->priv;
602 struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi);
603 struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h;
604 struct osmo_gprs_ns2_prim nsp = {};
605 uint16_t bvci;
606
Alexander Couzenscce88282020-10-26 00:25:50 +0100607 if (msgb_l2len(msg) < sizeof(*nsh) + 3) {
608 msgb_free(msg);
Alexander Couzens6a161492020-07-12 13:45:50 +0200609 return;
Alexander Couzenscce88282020-10-26 00:25:50 +0100610 }
Alexander Couzens6a161492020-07-12 13:45:50 +0200611
612 /* TODO: 7.1: For an IP sub-network, an NS-UNITDATA PDU
613 * for a PTP BVC may indicate a request to change the IP endpoint
614 * and/or a response to a change in the IP endpoint. */
615
616 /* TODO: nsh->data[0] -> C/R only valid in IP SNS */
617 bvci = nsh->data[1] << 8 | nsh->data[2];
618
Alexander Couzens89acdef2020-09-23 18:22:31 +0200619 msg->l3h = &nsh->data[3];
620 nsp.bvci = bvci;
621 nsp.nsei = priv->nsvc->nse->nsei;
Alexander Couzens6a161492020-07-12 13:45:50 +0200622
Alexander Couzensc1cd3332020-09-23 23:24:02 +0200623 /* 10.3.9 NS SDU Control Bits */
624 if (nsh->data[0] & 0x1)
Alexander Couzens138b96f2021-01-25 16:23:29 +0100625 nsp.u.unitdata.change = GPRS_NS2_ENDPOINT_REQUEST_CHANGE;
Alexander Couzens6a161492020-07-12 13:45:50 +0200626
Alexander Couzens138b96f2021-01-25 16:23:29 +0100627 osmo_prim_init(&nsp.oph, SAP_NS, GPRS_NS2_PRIM_UNIT_DATA,
Alexander Couzens6a161492020-07-12 13:45:50 +0200628 PRIM_OP_INDICATION, msg);
629 nsi->cb(&nsp.oph, nsi->cb_data);
630}
631
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100632static void ns2_vc_fsm_allstate_action(struct osmo_fsm_inst *fi,
Alexander Couzens6a161492020-07-12 13:45:50 +0200633 uint32_t event,
634 void *data)
635{
636 struct gprs_ns2_vc_priv *priv = fi->priv;
637 struct gprs_ns2_inst *nsi = ns_inst_from_fi(fi);
Alexander Couzensa7a757f2021-09-07 01:22:53 +0200638 struct tlv_parsed *tp;
Alexander Couzenscce88282020-10-26 00:25:50 +0100639 struct msgb *msg = data;
Alexander Couzensa7a757f2021-09-07 01:22:53 +0200640 uint8_t cause;
Alexander Couzens6a161492020-07-12 13:45:50 +0200641
642 switch (event) {
Alexander Couzens27e58732021-03-21 17:12:08 +0100643 case GPRS_NS2_EV_REQ_OM_RESET:
644 if (priv->nsvc->mode != GPRS_NS2_VC_MODE_BLOCKRESET)
645 break;
646 /* move the FSM into reset */
647 if (fi->state != GPRS_NS2_ST_RESET) {
648 priv->initiate_reset = true;
649 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], NS_TOUT_TNS_RESET);
650 }
651 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100652 case GPRS_NS2_EV_RX_RESET:
Alexander Couzens138b96f2021-01-25 16:23:29 +0100653 if (priv->nsvc->mode != GPRS_NS2_VC_MODE_BLOCKRESET)
Alexander Couzens6a161492020-07-12 13:45:50 +0200654 break;
655
656 /* move the FSM into reset */
657 if (fi->state != GPRS_NS2_ST_RESET) {
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100658 priv->initiate_reset = false;
Alexander Couzens6a161492020-07-12 13:45:50 +0200659 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], NS_TOUT_TNS_RESET);
660 }
661 /* pass the event down into FSM action */
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100662 ns2_st_reset(fi, event, data);
Alexander Couzens6a161492020-07-12 13:45:50 +0200663 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100664 case GPRS_NS2_EV_RX_ALIVE:
Alexander Couzens6a161492020-07-12 13:45:50 +0200665 switch (fi->state) {
666 case GPRS_NS2_ST_UNCONFIGURED:
667 case GPRS_NS2_ST_RESET:
668 /* ignore ALIVE */
669 break;
670 default:
671 ns2_tx_alive_ack(priv->nsvc);
672 }
673 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100674 case GPRS_NS2_EV_RX_ALIVE_ACK:
Alexander Couzens6a161492020-07-12 13:45:50 +0200675 /* for VCs without RESET/BLOCK/UNBLOCK, the connections comes after ALIVE_ACK unblocked */
Alexander Couzensd3e31102021-02-03 11:15:07 +0100676 if (fi->state == GPRS_NS2_ST_RECOVERING)
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100677 ns2_st_alive(fi, event, data);
Alexander Couzens6a161492020-07-12 13:45:50 +0200678 else
679 recv_test_procedure(fi);
680 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100681 case GPRS_NS2_EV_RX_UNITDATA:
Alexander Couzenscce88282020-10-26 00:25:50 +0100682 /* UNITDATA has to handle the release of msg.
683 * If send upwards (gprs_ns2_recv_unitdata) it must NOT free
684 * the msg, the upper layer has to do it.
685 * Otherwise the msg must be freed.
686 */
Alexander Couzens6cf65d92021-01-18 17:55:35 +0100687
688 LOG_NS_DATA(priv->nsvc, "Rx", NS_PDUT_UNITDATA, LOGL_INFO, "\n");
Alexander Couzens6a161492020-07-12 13:45:50 +0200689 switch (fi->state) {
690 case GPRS_NS2_ST_BLOCKED:
691 /* 7.2.1: the BLOCKED_ACK might be lost */
Alexander Couzens47afc422021-01-17 20:12:46 +0100692 if (priv->accept_unitdata) {
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100693 ns2_recv_unitdata(fi, msg);
Alexander Couzenscce88282020-10-26 00:25:50 +0100694 return;
695 }
696
697 ns2_tx_status(priv->nsvc,
698 NS_CAUSE_NSVC_BLOCKED,
Alexander Couzensd802f9a2021-09-23 16:19:32 +0200699 0, msg, NULL);
Alexander Couzens6a161492020-07-12 13:45:50 +0200700 break;
701 /* ALIVE can receive UNITDATA if the ALIVE_ACK is lost */
Alexander Couzensd3e31102021-02-03 11:15:07 +0100702 case GPRS_NS2_ST_RECOVERING:
Alexander Couzens6a161492020-07-12 13:45:50 +0200703 case GPRS_NS2_ST_UNBLOCKED:
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100704 ns2_recv_unitdata(fi, msg);
Alexander Couzenscce88282020-10-26 00:25:50 +0100705 return;
Alexander Couzens6a161492020-07-12 13:45:50 +0200706 }
Alexander Couzenscce88282020-10-26 00:25:50 +0100707
708 msgb_free(msg);
Alexander Couzens6a161492020-07-12 13:45:50 +0200709 break;
Alexander Couzensf5775432021-01-18 13:49:00 +0100710 case GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED:
Alexander Couzens6f3b7382020-12-21 15:57:04 +0100711 if (fi->state != GPRS_NS2_ST_UNCONFIGURED) {
712 /* Force the NSVC back to its initial state */
713 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_UNCONFIGURED, 0, 0);
Alexander Couzens6f3b7382020-12-21 15:57:04 +0100714 return;
715 }
Daniel Willmanned0c9822020-11-18 14:08:07 +0100716 break;
Alexander Couzens47afc422021-01-17 20:12:46 +0100717 case GPRS_NS2_EV_REQ_OM_BLOCK:
718 /* vty cmd: block */
719 priv->initiate_block = true;
720 priv->om_blocked = true;
721 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
722 break;
723 case GPRS_NS2_EV_REQ_OM_UNBLOCK:
724 /* vty cmd: unblock*/
725 if (!priv->om_blocked)
726 return;
727 priv->om_blocked = false;
728 if (fi->state == GPRS_NS2_ST_BLOCKED)
729 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
730 break;
Alexander Couzensa7a757f2021-09-07 01:22:53 +0200731 case GPRS_NS2_EV_RX_STATUS:
732 tp = data;
733 cause = tlvp_val8(tp, NS_IE_CAUSE, 0);
734 switch (cause) {
735 case NS_CAUSE_NSVC_BLOCKED:
736 if (fi->state != GPRS_NS2_ST_BLOCKED) {
737 LOG_NS_SIGNAL(priv->nsvc, "Rx", NS_PDUT_STATUS, LOGL_ERROR, ": remote side reported blocked state.\n");
738 priv->initiate_block = false;
739 priv->accept_unitdata = false;
740 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED, nsi->timeout[NS_TOUT_TNS_BLOCK], 0);
741 }
742 break;
743 case NS_CAUSE_NSVC_UNKNOWN:
744 if (fi->state != GPRS_NS2_ST_RESET && fi->state != GPRS_NS2_ST_UNCONFIGURED) {
745 LOG_NS_SIGNAL(priv->nsvc, "Rx", NS_PDUT_STATUS, LOGL_ERROR, ": remote side reported unknown nsvc.\n");
746 osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0);
747 }
748 break;
749 }
750
751 break;
Alexander Couzens6a161492020-07-12 13:45:50 +0200752 }
753}
754
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100755static void ns2_vc_fsm_clean(struct osmo_fsm_inst *fi,
Alexander Couzens0346b642020-10-27 13:05:56 +0100756 enum osmo_fsm_term_cause cause)
757{
758 struct gprs_ns2_vc_priv *priv = fi->priv;
759
760 osmo_timer_del(&priv->alive.timer);
761}
762
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100763static struct osmo_fsm ns2_vc_fsm = {
Alexander Couzens6a161492020-07-12 13:45:50 +0200764 .name = "GPRS-NS2-VC",
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100765 .states = ns2_vc_states,
766 .num_states = ARRAY_SIZE(ns2_vc_states),
Alexander Couzensf5775432021-01-18 13:49:00 +0100767 .allstate_event_mask = S(GPRS_NS2_EV_RX_UNITDATA) |
768 S(GPRS_NS2_EV_RX_RESET) |
769 S(GPRS_NS2_EV_RX_ALIVE) |
770 S(GPRS_NS2_EV_RX_ALIVE_ACK) |
Alexander Couzensa7a757f2021-09-07 01:22:53 +0200771 S(GPRS_NS2_EV_RX_STATUS) |
Alexander Couzensf5775432021-01-18 13:49:00 +0100772 S(GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED) |
Alexander Couzens27e58732021-03-21 17:12:08 +0100773 S(GPRS_NS2_EV_REQ_OM_RESET) |
Alexander Couzens47afc422021-01-17 20:12:46 +0100774 S(GPRS_NS2_EV_REQ_OM_BLOCK) |
775 S(GPRS_NS2_EV_REQ_OM_UNBLOCK),
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100776 .allstate_action = ns2_vc_fsm_allstate_action,
777 .cleanup = ns2_vc_fsm_clean,
778 .timer_cb = ns2_vc_fsm_timer_cb,
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100779 .event_names = ns2_vc_event_names,
Alexander Couzens6a161492020-07-12 13:45:50 +0200780 .pre_term = NULL,
781 .log_subsys = DLNS,
782};
783
784/*!
785 * \brief gprs_ns2_vc_fsm_alloc
786 * \param ctx
787 * \param vc
788 * \param id a char representation of the virtual curcuit
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100789 * \param initiator initiator is the site which starts the connection. Usually the BSS.
Alexander Couzens6a161492020-07-12 13:45:50 +0200790 * \return NULL on error, otherwise the fsm
791 */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100792struct osmo_fsm_inst *ns2_vc_fsm_alloc(struct gprs_ns2_vc *nsvc,
Daniel Willmannf5b2e282020-11-18 18:51:25 +0100793 const char *id, bool initiator)
Alexander Couzens6a161492020-07-12 13:45:50 +0200794{
795 struct osmo_fsm_inst *fi;
796 struct gprs_ns2_vc_priv *priv;
797
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100798 fi = osmo_fsm_inst_alloc(&ns2_vc_fsm, nsvc, NULL, LOGL_DEBUG, id);
Alexander Couzens6a161492020-07-12 13:45:50 +0200799 if (!fi)
800 return fi;
801
802 nsvc->fi = fi;
803 priv = fi->priv = talloc_zero(fi, struct gprs_ns2_vc_priv);
804 priv->nsvc = nsvc;
Alexander Couzensea01bf22021-01-18 14:01:01 +0100805 priv->initiator = initiator;
Alexander Couzens6a161492020-07-12 13:45:50 +0200806
807 osmo_timer_setup(&priv->alive.timer, alive_timeout_handler, fi);
808
809 return fi;
810}
811
Harald Welte5bef2cc2020-09-18 22:33:24 +0200812/*! Start a NS-VC FSM.
813 * \param nsvc the virtual circuit
814 * \return 0 on success; negative on error */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100815int ns2_vc_fsm_start(struct gprs_ns2_vc *nsvc)
Alexander Couzens6a161492020-07-12 13:45:50 +0200816{
817 /* allows to call this function even for started nsvc by gprs_ns2_start_alive_all_nsvcs */
818 if (nsvc->fi->state == GPRS_NS2_ST_UNCONFIGURED)
Alexander Couzensf5775432021-01-18 13:49:00 +0100819 return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_START, NULL);
Alexander Couzens6a161492020-07-12 13:45:50 +0200820 return 0;
821}
822
Daniel Willmanned0c9822020-11-18 14:08:07 +0100823/*! Reset a NS-VC FSM.
824 * \param nsvc the virtual circuit
825 * \return 0 on success; negative on error */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100826int ns2_vc_force_unconfigured(struct gprs_ns2_vc *nsvc)
Daniel Willmanned0c9822020-11-18 14:08:07 +0100827{
Alexander Couzensf5775432021-01-18 13:49:00 +0100828 return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_FORCE_UNCONFIGURED, NULL);
Daniel Willmanned0c9822020-11-18 14:08:07 +0100829}
830
Alexander Couzens47afc422021-01-17 20:12:46 +0100831/*! Block a NS-VC.
832 * \param nsvc the virtual circuit
833 * \return 0 on success; negative on error */
834int ns2_vc_block(struct gprs_ns2_vc *nsvc)
835{
Alexander Couzense7dfeac2021-03-21 17:28:36 +0100836 struct gprs_ns2_vc_priv *priv = nsvc->fi->priv;
Alexander Couzens79a3a842021-04-13 12:26:57 +0200837 if (priv->om_blocked)
Alexander Couzense7dfeac2021-03-21 17:28:36 +0100838 return -EALREADY;
839
Alexander Couzens47afc422021-01-17 20:12:46 +0100840 return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_OM_BLOCK, NULL);
841}
842
843/*! Unblock a NS-VC.
844 * \param nsvc the virtual circuit
845 * \return 0 on success; negative on error */
846int ns2_vc_unblock(struct gprs_ns2_vc *nsvc)
847{
Alexander Couzense7dfeac2021-03-21 17:28:36 +0100848 struct gprs_ns2_vc_priv *priv = nsvc->fi->priv;
Alexander Couzens79a3a842021-04-13 12:26:57 +0200849 if (!priv->om_blocked)
Alexander Couzense7dfeac2021-03-21 17:28:36 +0100850 return -EALREADY;
851
Alexander Couzens47afc422021-01-17 20:12:46 +0100852 return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_OM_UNBLOCK, NULL);
853}
854
Alexander Couzens27e58732021-03-21 17:12:08 +0100855/*! Reset a NS-VC.
856 * \param nsvc the virtual circuit
857 * \return 0 on success; negative on error */
858int ns2_vc_reset(struct gprs_ns2_vc *nsvc)
859{
860 return osmo_fsm_inst_dispatch(nsvc->fi, GPRS_NS2_EV_REQ_OM_RESET, NULL);
861}
862
Harald Welte5bef2cc2020-09-18 22:33:24 +0200863/*! entry point for messages from the driver/VL
864 * \param nsvc virtual circuit on which the message was received
865 * \param msg message that was received
866 * \param tp parsed TLVs of the received message
867 * \return 0 on success; negative on error */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100868int ns2_vc_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp)
Alexander Couzens6a161492020-07-12 13:45:50 +0200869{
870 struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h;
Alexander Couzens69cc4b62021-09-07 16:33:08 +0200871 struct gprs_ns2_vc *target_nsvc = nsvc;
Alexander Couzens6a161492020-07-12 13:45:50 +0200872 struct osmo_fsm_inst *fi = nsvc->fi;
Alexander Couzenscce88282020-10-26 00:25:50 +0100873 int rc = 0;
Alexander Couzens6a161492020-07-12 13:45:50 +0200874 uint8_t cause;
Alexander Couzens3f576ab2021-01-20 14:50:31 +0100875 uint16_t nsei, nsvci;
Alexander Couzens6a161492020-07-12 13:45:50 +0200876
877 /* TODO: 7.2: on UNBLOCK/BLOCK: check if NS-VCI is correct,
878 * if not answer STATUS with "NS-VC unknown" */
Alexander Couzens6a161492020-07-12 13:45:50 +0200879 /* TODO: handle BLOCK/UNBLOCK/ALIVE with different VCI */
880
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100881 if (ns2_validate(nsvc, nsh->pdu_type, msg, tp, &cause)) {
Alexander Couzenscc1621e2021-09-07 15:30:26 +0200882 /* don't answer on a STATUS with a STATUS */
Alexander Couzens6a161492020-07-12 13:45:50 +0200883 if (nsh->pdu_type != NS_PDUT_STATUS) {
Alexander Couzensd802f9a2021-09-23 16:19:32 +0200884 rc = ns2_tx_status(nsvc, cause, 0, msg, NULL);
Alexander Couzenscce88282020-10-26 00:25:50 +0100885 goto out;
Alexander Couzens6a161492020-07-12 13:45:50 +0200886 }
887 }
888
Alexander Couzens43771df2021-01-20 13:03:03 +0100889 if (TLVP_PRESENT(tp, NS_IE_NSEI)) {
890 nsei = tlvp_val16be(tp, NS_IE_NSEI);
891 if (nsei != nsvc->nse->nsei) {
892 /* 48.016 ยง 7.3.1 send, RESET_ACK to wrong NSVCI + ignore */
893 if (nsh->pdu_type == NS_PDUT_RESET)
894 ns2_tx_reset_ack(nsvc);
895
Alexander Couzensf8635c72021-10-12 18:58:31 +0200896 LOG_NS_SIGNAL(nsvc, "Rx", nsh->pdu_type, LOGL_ERROR, " with wrong NSEI (exp: %05u, got %05u). Ignoring PDU.\n", nsvc->nse->nsei, nsei);
Alexander Couzens43771df2021-01-20 13:03:03 +0100897 goto out;
898 }
899 }
900
Alexander Couzense7873332021-09-06 18:17:41 +0200901 if (nsvc->nsvci_is_valid && TLVP_PRESENT(tp, NS_IE_VCI)) {
Alexander Couzens3f576ab2021-01-20 14:50:31 +0100902 nsvci = tlvp_val16be(tp, NS_IE_VCI);
903 if (nsvci != nsvc->nsvci) {
904 /* 48.016 ยง 7.3.1 send RESET_ACK to wrong NSVCI + ignore */
Alexander Couzens69cc4b62021-09-07 16:33:08 +0200905 if (nsh->pdu_type == NS_PDUT_RESET) {
Alexander Couzens3f576ab2021-01-20 14:50:31 +0100906 ns2_tx_reset_ack(nsvc);
Alexander Couzens58be4272021-10-12 18:57:06 +0200907 LOG_NS_SIGNAL(nsvc, "Rx", nsh->pdu_type, LOGL_ERROR, " with wrong NSVCI (exp: %05u, got %05u). Ignoring PDU.\n", nsvc->nsvci, nsvci);
908 goto out;
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200909 } else if (nsh->pdu_type == NS_PDUT_BLOCK || nsh->pdu_type == NS_PDUT_STATUS) {
910 /* this is a PDU received over a NSVC and reports a status/block for another NSVC */
Alexander Couzens69cc4b62021-09-07 16:33:08 +0200911 target_nsvc = gprs_ns2_nsvc_by_nsvci(nsvc->nse->nsi, nsvci);
912 if (!target_nsvc) {
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200913 LOGPFSML(fi, LOGL_ERROR, "Received a %s PDU for unknown NSVC (NSVCI %d)\n",
914 get_value_string(gprs_ns_pdu_strings, nsh->pdu_type), nsvci);
915 if (nsh->pdu_type == NS_PDUT_BLOCK)
916 ns2_tx_status(nsvc, NS_CAUSE_NSVC_UNKNOWN, 0, msg, &nsvci);
Alexander Couzens69cc4b62021-09-07 16:33:08 +0200917 goto out;
918 }
Alexander Couzens3f576ab2021-01-20 14:50:31 +0100919
Alexander Couzens69cc4b62021-09-07 16:33:08 +0200920 if (target_nsvc->nse != nsvc->nse) {
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200921 LOGPFSML(fi, LOGL_ERROR, "Received a %s PDU for a NSVC (NSVCI %d) but it belongs to a different NSE!\n",
922 get_value_string(gprs_ns_pdu_strings, nsh->pdu_type), nsvci);
Alexander Couzens69cc4b62021-09-07 16:33:08 +0200923 goto out;
924 }
925
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200926 /* the status/block will be passed to the nsvc/target nsvc in the switch */
Alexander Couzens69cc4b62021-09-07 16:33:08 +0200927 } else {
928 LOG_NS_SIGNAL(nsvc, "Rx", nsh->pdu_type, LOGL_ERROR, " with wrong NSVCI=%05u. Ignoring PDU.\n", nsvci);
929 goto out;
930 }
Alexander Couzens3f576ab2021-01-20 14:50:31 +0100931 }
932 }
933
Alexander Couzens6a161492020-07-12 13:45:50 +0200934 switch (nsh->pdu_type) {
935 case NS_PDUT_RESET:
Alexander Couzensf5775432021-01-18 13:49:00 +0100936 osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_RESET, tp);
Alexander Couzens6a161492020-07-12 13:45:50 +0200937 break;
938 case NS_PDUT_RESET_ACK:
Alexander Couzensf5775432021-01-18 13:49:00 +0100939 osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_RESET_ACK, tp);
Alexander Couzens6a161492020-07-12 13:45:50 +0200940 break;
941 case NS_PDUT_BLOCK:
Alexander Couzens4ef56c02021-09-07 16:33:30 +0200942 if (target_nsvc != nsvc) {
943 osmo_fsm_inst_dispatch(target_nsvc->fi, GPRS_NS2_EV_RX_BLOCK_FOREIGN, tp);
944 ns2_tx_block_ack(nsvc, &nsvci);
945 } else {
946 osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_BLOCK, tp);
947 }
Alexander Couzens6a161492020-07-12 13:45:50 +0200948 break;
949 case NS_PDUT_BLOCK_ACK:
Alexander Couzensf5775432021-01-18 13:49:00 +0100950 osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_BLOCK_ACK, tp);
Alexander Couzens6a161492020-07-12 13:45:50 +0200951 break;
952 case NS_PDUT_UNBLOCK:
Alexander Couzensf5775432021-01-18 13:49:00 +0100953 osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_UNBLOCK, tp);
Alexander Couzens6a161492020-07-12 13:45:50 +0200954 break;
955 case NS_PDUT_UNBLOCK_ACK:
Alexander Couzensf5775432021-01-18 13:49:00 +0100956 osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_UNBLOCK_ACK, tp);
Alexander Couzens6a161492020-07-12 13:45:50 +0200957 break;
958 case NS_PDUT_ALIVE:
Alexander Couzensf5775432021-01-18 13:49:00 +0100959 osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_ALIVE, tp);
Alexander Couzens6a161492020-07-12 13:45:50 +0200960 break;
961 case NS_PDUT_ALIVE_ACK:
Alexander Couzensf5775432021-01-18 13:49:00 +0100962 osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_ALIVE_ACK, tp);
Alexander Couzens6a161492020-07-12 13:45:50 +0200963 break;
964 case NS_PDUT_UNITDATA:
Alexander Couzenscce88282020-10-26 00:25:50 +0100965 /* UNITDATA have to free msg because it might send the msg layer upwards */
Alexander Couzensf5775432021-01-18 13:49:00 +0100966 osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_UNITDATA, msg);
Alexander Couzenscce88282020-10-26 00:25:50 +0100967 return 0;
Alexander Couzensa7a757f2021-09-07 01:22:53 +0200968 case NS_PDUT_STATUS:
Alexander Couzens69cc4b62021-09-07 16:33:08 +0200969 osmo_fsm_inst_dispatch(target_nsvc->fi, GPRS_NS2_EV_RX_STATUS, tp);
Alexander Couzensa7a757f2021-09-07 01:22:53 +0200970 break;
Alexander Couzens6a161492020-07-12 13:45:50 +0200971 default:
Harald Weltef2949742021-01-20 14:54:14 +0100972 LOGPFSML(fi, LOGL_ERROR, "NSEI=%u Rx unknown NS PDU type %s\n", nsvc->nse->nsei,
973 get_value_string(gprs_ns_pdu_strings, nsh->pdu_type));
Alexander Couzens7619ed42021-03-24 17:44:03 +0100974 rc = -EINVAL;
975 break;
Alexander Couzens6a161492020-07-12 13:45:50 +0200976 }
977
Alexander Couzenscce88282020-10-26 00:25:50 +0100978out:
979 msgb_free(msg);
980
981 return rc;
Alexander Couzens6a161492020-07-12 13:45:50 +0200982}
983
Harald Welte5bef2cc2020-09-18 22:33:24 +0200984/*! is the given NS-VC unblocked? */
Alexander Couzens8dfc24c2021-01-25 16:09:23 +0100985int ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc)
Alexander Couzens6a161492020-07-12 13:45:50 +0200986{
987 return (nsvc->fi->state == GPRS_NS2_ST_UNBLOCKED);
988}
989
990/* initialize osmo_ctx on main tread */
991static __attribute__((constructor)) void on_dso_load_ctx(void)
992{
Alexander Couzensf7e2cac2021-01-25 16:18:21 +0100993 OSMO_ASSERT(osmo_fsm_register(&ns2_vc_fsm) == 0);
Alexander Couzens6a161492020-07-12 13:45:50 +0200994}